home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / SOURCE / SYS.H < prev    next >
C/C++ Source or Header  |  1996-06-04  |  3KB  |  80 lines

  1. /* Copyright by Denys Duchier, Dec 1994
  2.    Simon Fraser University
  3.  
  4.    All new system utilities and extensions to Wild LIFE 1.02
  5.    are implemented using the new call_primitive interface
  6.    */
  7. /*    $Id: sys.h,v 1.2 1995/07/27 20:16:30 duchier Exp $    */
  8. #ifndef _LIFE_SYS_H_
  9. #define _LIFE_SYS_H_
  10. #include "extern.h"
  11.  
  12. /********************************************************************
  13.   When calling a primitive, you always need to process the arguments
  14.   according to the same protocol.  The call_primitive procedure does
  15.   all this work for you.  It should be called as follows:
  16.  
  17.                call_primitive(f,n,args,info)
  18.  
  19.   where f is the primitive implementing the actual functionality, n
  20.   is the number of arguments described in args, and args is an array
  21.   of argument descriptions, and info is a pointer to extra info to be
  22.   passed to f.  Each argument is described by a psi_arg structure
  23.   whose 1st field is a string naming the feature, 2nd field is a type
  24.   restriction, and 3rd field describes processing options, e.g.:
  25.  
  26.           { "1" , quoted_string , REQUIRED }
  27.  
  28.   describes a required argument on feature 1, that must be a string.
  29.   The 3rd field is a mask of boolean flags and is constructed by
  30.   ORing some constants chosen from the set:
  31.  
  32.   OPTIONAL    for an optional argument
  33.   REQUIRED    for a required argument (i.e. residuate on it if not
  34.           present
  35.   UNEVALED    if the argument should not be evaluated
  36.   JUSTFAIL    to just fail is the argument does not meet its type
  37.         restriction
  38.   POLYTYPE    sometimes you want to permit several particular sorts
  39.         in that case the 2nd psi_arg field is interpreted as
  40.         a pointer to a NULL terminated array of ptr_definitions
  41.   MANDATORY    like REQUIRED, but it is an error for it not to be
  42.           present; don't residuate.  This is useful for
  43.         predicates since it doesn't make sense for them to
  44.         residuate.
  45.   NOVALUE    no value required for this argument.
  46.  
  47.   The primitive must be defined to take the following arguments
  48.           f(argl,result,funct[,info])
  49.   where argl is an array containing the arguments obtained by call_
  50.   primitive, result is the result in case we are implementing a
  51.   function, and info (optional) is extra information, typically a
  52.   pointer to a structure.
  53.   *******************************************************************/
  54.  
  55. #define OPTIONAL  0
  56. #define REQUIRED  1
  57. #define UNEVALED  (1<<1)
  58. #define JUSTFAIL  (1<<2)
  59. #define POLYTYPE  (1<<3)
  60. #define MANDATORY (1<<4)
  61. #define NOVALUE   (1<<5)
  62.  
  63. typedef struct {
  64.   char *feature;
  65.   ptr_definition type;
  66.   unsigned int options;
  67. } psi_arg;
  68.  
  69. #define SETARG(args,i,the_feature,the_type,the_options) \
  70.   { int j = i; \
  71.     args[j].feature = the_feature; \
  72.     args[j].type    = the_type; \
  73.     args[j].options = the_options; }
  74.  
  75. #define NARGS(args) (sizeof(args)/sizeof(psi_arg))
  76.  
  77. extern long call_primitive();
  78.  
  79. #endif /* _LIFE_SYS_H_ */
  80.