home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / ifp / part07 / interp / struct.h < prev    next >
Encoding:
C/C++ Source or Header  |  1987-07-06  |  14.4 KB  |  483 lines

  1.  
  2. /****** struct.h ******************************************************/
  3. /**                                                                  **/
  4. /**                    University of Illinois                        **/
  5. /**                                                                  **/
  6. /**                Department of Computer Science                    **/
  7. /**                                                                  **/
  8. /**   Tool: IFP                         Version: 0.5                 **/
  9. /**                                                                  **/
  10. /**   Author:  Arch D. Robison          Date:   May 1, 1985          **/
  11. /**                                                                  **/
  12. /**   Revised by: Arch D. Robison       Date:   Aug 4, 1986          **/
  13. /**                                                                  **/
  14. /**   Principal Investigators: Prof. R. H. Campbell                  **/
  15. /**                            Prof. W. J. Kubitz                    **/
  16. /**                                                                  **/
  17. /**                                                                  **/
  18. /**------------------------------------------------------------------**/
  19. /**   (C) Copyright 1987  University of Illinois Board of Trustees   **/
  20. /**                       All Rights Reserved.                       **/
  21. /**********************************************************************/
  22.  
  23. /*
  24.  * There are some preprocessor variables which must be defined either
  25.  * here or in the cc command.  The following options are not available
  26.  * in the public domain release:
  27.  *
  28.  *     ARRAYS, COMPILE, UMAX, VECTOR, OUTBERKELEY
  29.  *
  30.  * Some of the code for these options are removed from the source by 
  31.  * unifdef(1), so the source may look strange in places.  (E.g. degenerate 
  32.  * switch statements).
  33.  *
  34.  * The preprocessor variables are listed below.
  35.  *
  36.  * OPSYS (UNIX, MSDOS, CTSS) - specifies operating system
  37.  * PCAT - for compiling on PC/ATs
  38.  * SQUEEZE - put space at a premium
  39.  * DEBUG - incorporate interpreter debugging spy points
  40.  * DUMP - incoporate dump command for debugging (see debug.c)
  41.  * REFCHECK - incorporate reference checking command (see apply.c)
  42.  * COMPILE - incorporate IFP compiler (see C_comp.h)
  43.  * ARRAYS - incorporate array representation of sequences
  44.  * VECTOR - define APL-style vector operations (must define ARRAYS also)
  45.  * UMAX - make parallel version for Encore Multimax
  46.  *
  47.  * There are also preprocessor variables which may be turned on or off
  48.  * in the following files:
  49.  *
  50.  *      ECACHE in cache.h - implement expression cache
  51.  *      STATS in stats.h - collect run time statistics
  52.  *      FETCH in node.h - implement "fetch" functional form
  53.  *    OUTBERKELEY in outberkely.h - implement routine to print functions in
  54.  *                      Berkeley FP format.
  55.  *
  56.  * WARNING: Some of the compiling options may interfere with each other.
  57.  *          Some options have not been tested for many revisions, so
  58.  *        new bugs may creep out of the woodwork!
  59.  */
  60.  
  61. #define UMAX 0        /* Must not enable ARRAYS, ECACHE, or STATS if set */
  62. #define DUMP 0
  63. #define ARRAYS 0    /* Must also define VECTOR=1 if set */
  64. #define VECTOR 0
  65. #define DEBUG 0
  66. #define REFCHECK 0
  67.  
  68. /*
  69.  * Possible values for OPSYS preprocessor variable.
  70.  */
  71. #define UNIX  10
  72. #define MSDOS 11
  73. #define CTSS  12
  74.  
  75. #define OPSYS UNIX
  76.  
  77. #if OPSYS==CTSS
  78. /*
  79.  * PARAMBUG is defined to indicate that the C compiler can not
  80.  * take the address (&) of parameter variables correctly.
  81.  * When this bug is removed from the CRAY C compiler, this define
  82.  * and dependent code should be removed.
  83.  */
  84. #define PARAMBUG 1
  85. #endif
  86.  
  87. #if OPSYS==MSDOS || OPSYS==CTSS 
  88. #define MAXPATH 65     /* Maximum pathname length allowed (in characters) */
  89. #endif
  90.  
  91. #if OPSYS==UNIX
  92. #define MAXPATH 256    /* Maximum pathname length allowed (in characters) */
  93. #endif
  94.  
  95. #if OPSYS==CTSS
  96. #define index strchr
  97. #endif
  98.  
  99. #ifdef PCAT
  100. #define index strchr
  101. #endif
  102.  
  103. /********** Fundamental Data Structures and Constants **********/
  104.  
  105.  
  106. #define private static
  107. #define forward extern  /* for forward definitions which are not external */
  108. typedef int boolean;
  109. typedef long FPint;
  110. typedef int FPboolean;
  111.  
  112. typedef short ushort;
  113.  
  114. /********************** MACHINE DEPENDENT CONSTANTS **********************/
  115.  
  116. /* These two definitions assume two's complement arithmetic! */
  117. #define FPMaxInt (((FPint) 1 << 8 * sizeof(FPint) - 1) - 1)
  118. #define MaxInt   (((  int) 1 << 8 * sizeof(  int) - 1) - 1)
  119.  
  120. #ifdef SQUEEZE
  121.  
  122. /* Maximum floating point value representable by an FPfloat */
  123. typedef float FPfloat;
  124.  
  125. #define MAXFLOAT 1e38
  126. #define LNMAXFLOAT 88.7
  127.  
  128. #define CompTol (1e-6)
  129.  
  130. #else
  131.  
  132. typedef double FPfloat;
  133.  
  134. /* Maximum floating point value representable by an FPfloat */
  135. #define MAXFLOAT 1.8e308
  136. #define LNMAXFLOAT 710.37     /* ln (MAXFLOAT) */
  137.  
  138. #define CompTol (1e-8)
  139.  
  140. #endif
  141.  
  142. /* if abs(A),abs(B) are both < MAXFACTOR then A*B will fit in FPInt */
  143. #define MAXFACTOR 0xB504L
  144.  
  145. /****************** end of machine dependent constants *********************/
  146.  
  147. /********************************* Strings *********************************/
  148.  
  149. /*
  150.  * StrCell
  151.  *
  152.  * Each string is segmented into a linked list.  The first record of the
  153.  * linked list contains the reference count for the string.
  154.  * The string is terminated by a segment with a null StrNext field or
  155.  * a '\0', whichever comes first.  The empty string is represented
  156.  * by a null pointer.  Segments have '\0' as their first character iff
  157.  * they are in the free string list.
  158.  */
  159.  
  160. /*
  161.  * StrHeadLen is the maximum number of characters which can be contained in
  162.  * the first segment of a string list.  
  163.  */
  164. #if OPSYS==CTSS
  165. #define StrHeadLen 8    /* For 64-bit ushort and 64-bit pointer */
  166. #else 
  167. #define StrHeadLen 10    /* For 16-bit ushort and 32-bit pointer */
  168. #endif
  169.  
  170. #define StrTailLen (StrHeadLen + sizeof (ushort))
  171.  
  172. typedef struct StrCell {
  173.    struct StrCell *StrNext;
  174.    union {
  175.       char StrVar1 [StrTailLen];
  176.       struct {
  177.      char StrV1F1 [StrHeadLen];
  178.      ushort StrV1F2;
  179.       } StrVar2;
  180.    } StrUni1;
  181. } StrCell;
  182.  
  183. typedef StrCell *StrPtr;
  184.  
  185. #define StrChar StrUni1.StrVar1
  186. #define SRef StrUni1.StrVar2.StrV1F2
  187.  
  188. /****************************** Sequences ******************************/
  189.  
  190. /*
  191.  * Sequences are guaranteed not to have cycles by the definition of FP.
  192.  * Note that function representation lists may have a cycle, but the cycle
  193.  * will always contain a function name as a member.  Cycle will be broken
  194.  * when the function definition is deleted.
  195.  */
  196.  
  197. /* Object Tags */
  198. #define BOTTOM  0
  199. #define BOOLEAN 1
  200. #define INT     2
  201. #define FLOAT   3
  202. #define LIST    4
  203. #define STRING  5
  204. #define NODE    6
  205. #define CODE    7
  206. #define JOIN    8
  207.  
  208. /* Bitmasks for PairTest */
  209. #define NUMERIC ((1<<FLOAT)|(1<<INT))
  210. #define ATOMIC (NUMERIC | (1<<BOOLEAN) | (1<<STRING))
  211.  
  212.  
  213. #define MAXTAG  7
  214. #define SEQUENCE (1<<LIST)
  215.  
  216.  
  217. /* Tag checking expressions dependent upon tag value assignments above */
  218. #define Scalar(Tag) ((Tag) < 4)
  219. #define Numeric(Tag) (((Tag)&~1)^2==0)
  220. #define NotNumPair(Tag1,Tag2) ((((Tag1)^2)|((Tag2)^2))&~1) 
  221. #define IntPair(Tag1,Tag2) ((Tag1+Tag2) == 4)
  222.  
  223. typedef struct CodeCell {
  224.    int (*CodePtr) ();           /* (*CodePtr) (InOut,CodeParam) */
  225.    int CodeParam;
  226. } CodeCell;
  227.  
  228. typedef union {
  229.    FPfloat _Float;
  230.    FPint _Int;
  231.    FPboolean _Bool;
  232.    struct ListCell *_List;
  233.    StrPtr _String;
  234.    struct NodeDesc *_Node;
  235.    CodeCell _Code;
  236. } ObUnion;              
  237.  
  238. #define Float Data._Float
  239. #define Int Data._Int
  240. #define Bool Data._Bool
  241. #define List Data._List
  242. #define String Data._String
  243. #define Node Data._Node
  244. #define Code Data._Code
  245.  
  246. /*
  247.  * Note on ARRAYS structures.  Cells with the ARRAY tag use the List field
  248.  * to point to an array descriptor list.  The first element of the list
  249.  * uses the APtr field, subsequent elements use the ADim field.
  250.  */
  251.  
  252. /*
  253.  * Object 
  254.  *
  255.  * An Object is a union which stores an IFP object.  The _LRef field is not 
  256.  * logically part of an * object, but rather part of a ListCell.  We get much 
  257.  * better packing by including it in Object, since it fits in a 32-bit word 
  258.  * along with the Tag field.
  259.  *
  260.  * Likewise, for the UMAX version the _LRefLock field is physically part
  261.  * of Object though it should be part of ListCell.
  262.  *
  263.  * Note that P->Val = Q->Val will transfer the reference count!
  264.  */  
  265. typedef struct {
  266.    ObUnion Data;
  267.    ushort _LRef;
  268.    char Tag;   /* BOTTOM,BOOLEAN,INT,FLOAT,LIST,STRING,NODE,CODE,ARRAY */
  269. } Object;
  270.  
  271. /*
  272.  * ListCell
  273.  *
  274.  * Sequences are represented as linked lists of objects.  Each ListCell
  275.  * also contains a reference count (hidden in the Object field).  The
  276.  * value stored in the reference count is offset by -1.  The rationale is
  277.  * that reference counts are always compared against one, and comparing
  278.  * against zero is faster on some machines.  
  279.  */ 
  280. typedef struct ListCell {
  281.    Object Val;            /* Value of first element of sequence (CAR) */
  282.    struct ListCell *Next;    /* Pointer tail of sequence (CDR)         */
  283. } ListCell;
  284.  
  285. #define LRef Val._LRef
  286. #define LRefOne 0           /* value of LRef for reference count of 1 */
  287.  
  288.  
  289. /*
  290.  * Most of the code uses subsets of the alphabet for certain types.
  291.  * For example, P,Q, and R are usually ListPtr.
  292.  */
  293. typedef ListCell *ListPtr;    /* e.g. P,Q,R */
  294. typedef ListPtr *MetaPtr;    /* e.g. A,B,C */
  295. typedef Object *ObjectPtr;    /* e.g. X,Y,Z */
  296.  
  297. #define NIL ((ListPtr) NULL)    /* empty list */
  298.  
  299. /******************************* Definitions ******************************/
  300.  
  301. /*
  302.  * DefDesc
  303.  *
  304.  * DefFlags = subset of {TRACE,RESOLVED}.
  305.  * DefCode = code for definition - BOTTOM if not resident.
  306.  */
  307. typedef struct DefDesc {
  308.    char DefFlags;
  309.    Object DefCode;
  310. } DefDesc;
  311.  
  312. typedef DefDesc *DefPtr;
  313.  
  314. #define TRACE  1       /* Print input and output.                      */
  315. #define RESOLVED 4     /* Mark bit used by reference checker           */
  316.  
  317. /*
  318.  * All compiled FP functions have the following form:
  319.  *
  320.  *   void F (InOut,CodeParam)
  321.  *      ObjectPtr InOut;
  322.  *      int CodeParam;
  323.  *      {...};
  324.  *
  325.  * F replaces *InOut with the result of applying F to *InOut.
  326.  * CodeParam  is optional.
  327.  */
  328.  
  329.  
  330. /******************************* Modules *******************************/
  331.  
  332. /*
  333.  * Modules are stored as lists of nodes.  Each node has a pointer to
  334.  * its next sibling and its parent node.
  335.  */
  336. typedef struct {                /* Module node descriptor */
  337.    struct NodeDesc *FirstChild;
  338. } ModDesc;
  339.  
  340. /******************************** Imports ******************************/
  341.  
  342. /*
  343.  * Definition nodes are imported with IMPORT nodes.  An import node in a
  344.  * module points to a definition node elsewhere.
  345.  */
  346. typedef struct {
  347.    Object ImpDef;     /* Can be path list or node */
  348. } ImpDesc;
  349.  
  350. /******************************** Nodes ********************************/
  351.  
  352. #define NEWNODE 0 /* Values for NodeType */
  353. #define MODULE 1
  354. #define DEF 2
  355. #define IMPORT 3
  356.  
  357. /*
  358.  * NodeDesc
  359.  *
  360.  * See the top of node.c for the description of how these are linked together
  361.  * to form the function/module tree.
  362.  *
  363.  * NRef = reference count (references by objects)
  364.  * NodeNext = pointer to next sibling (or parent).
  365.  * NodeType = type of node (DEF, MODULE, IMPORT)
  366.  * NodeName = print name of node.
  367.  */
  368. typedef union {
  369.    DefDesc NodeDef;     /* if DEF    */
  370.    ModDesc NodeMod;     /* if MODULE */
  371.    ImpDesc NodeImp;     /* if IMPORT */
  372. } NDunion;
  373.  
  374. typedef struct NodeDesc {
  375.    struct NodeDesc *NodeSib;
  376.    struct NodeDesc *NodeParent;
  377.    StrPtr NodeName;
  378.    short NRef;
  379.    char NodeType;
  380.    NDunion NodeData;
  381. } NodeDesc;
  382.  
  383. typedef struct NodeDesc *NodePtr;
  384.  
  385. /*----------------- exception handling: see except.c -----------------*/
  386.  
  387. /* values for SysError, 0 == no error */
  388.  
  389. #define INTERNAL     1     /* Inexplicable internal error  */
  390. #define NO_LIST_FREE 2       /* Ran out of list cell storage */
  391. #define NO_STR_FREE  3       /*  "   "  " string  "     "    */
  392. #define NO_NODE_FREE 4       /*  "   "  "  node   "      "   */
  393.  
  394. extern short SysError;     /* An error occurred if SysError != 0 */
  395. extern short SysStop;      /* Stop evaluation if != 0            */
  396.  
  397. /*------------ debugging the interpreter: see debug.c ----------------*/
  398.  
  399. /*
  400.  * The interpreter may be compiled with internal spy points.  These spy 
  401.  * points print internal information on stdout.  To include the spy * points, 
  402.  * the interpreter must be compiled with #define DEBUG 1.  To turn on a spy 
  403.  * point when running ifp, use the command line option '-d' followed by the 
  404.  * appropriate letters.  The letters are defined by ``DebugOpt'' below.  
  405.  * For example,
  406.  *
  407.  *    ifp -dar
  408.  *
  409.  * will turn on spy points related to memory allocation (a) and 
  410.  * reference counts (r).
  411.  */
  412. #define DebugParse       (1<<0)    /* parser        */
  413. #define DebugAlloc     (1<<1)    /* memory allocation     */
  414. #define DebugFile    (1<<2)    /* file io         */
  415. #define DebugRef    (1<<3)    /* reference counts     */
  416. #define DebugInit    (1<<4)    /* initialization    */
  417. #define DebugCache    (1<<5)    /* expression cache    */
  418. #define DebugXDef    (1<<6)    /* extended definitions */
  419. #define DebugHyper    (1<<7)    /* hypercube        */
  420. #define DebugUMax    (1<<8)  /* multimax        */
  421. #define DebugSemaphore  (1<<9)  /* semaphores        */
  422. #define DebugFreeList   (1<<10) /* free list        */
  423. #define DebugExpQueue   (1<<11) /* expression queue    */
  424.  
  425. #define DebugOpt "pafricxhusle"    /* option letters for above */
  426.  
  427. #if DEBUG
  428. extern int Debug;    /* Bit-set of enabled spy points */
  429. #else
  430. #define Debug 0        /* Turn spy points into dead code */
  431. #endif
  432.  
  433. /*--------------------------------------------------------------------*/
  434.  
  435. extern NodePtr CurWorkDir;     /* Current working directory */
  436. extern NodePtr SysDef ();
  437.  
  438. extern void DelLPtr ();         /* Delete a list pointer */
  439. extern ListPtr CopyLPtr ();     /* Copy a list pointer */
  440.  
  441. extern void Rot3 ();            /* list pointer rotation */
  442.  
  443. extern long ListLength ();              /* from list.c */
  444. extern void CopyObject ();
  445. extern ListPtr Repeat ();
  446. extern void NewList ();
  447. extern void RepTag ();
  448. extern boolean RepObject ();
  449. extern void RepLPtr ();
  450. extern void CopyTop ();
  451. extern void Copy2Top ();
  452. extern void RepBool ();
  453.  
  454. extern void Apply ();                   /* from apply.c */
  455. extern NodePtr ApplyFun;
  456.  
  457. extern void NodeExpand ();
  458.  
  459. extern void ExecEdit (), ReadImport (); /* from file.c */
  460.  
  461. extern void OutObject (), OutList ();   /* from outob.c */
  462. extern void OutString (), OutNode ();
  463. extern void OutForm (), OutFun ();      /* from outfun.c */
  464. extern void OutPretty ();
  465.  
  466. extern void InitIn (), InBlanks ();    /* from inob.c */
  467.  
  468. extern void ReadDef (), DelImport ();
  469. extern void InImport (); 
  470.  
  471. extern int InError();            /* from error.c */
  472. extern void DefError (), IntError ();
  473. extern void FunError (), FormError ();
  474. extern char ArgNotSeq[], ArgObSeq[], ArgSeqOb[], ArgNull[], ArgBottom[];
  475.  
  476. extern NodePtr PrimDef ();
  477. extern char *malloc();
  478.  
  479. #define ArrayEnd(A) (A+(sizeof(A)/sizeof A[0])) 
  480.  
  481.  
  482. /************************** end of struct.h **************************/
  483.