home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / h / rstructs.h < prev    next >
C/C++ Source or Header  |  1996-03-22  |  17KB  |  561 lines

  1. /*
  2.  * Run-time data structures.
  3.  */
  4.  
  5. /*
  6.  * Structures common to the compiler and interpreter.
  7.  */
  8.  
  9. /*
  10.  * Run-time error numbers and text.
  11.  */
  12. struct errtab {
  13.    int err_no;            /* error number */
  14.    char *errmsg;        /* error message */
  15.    };
  16.  
  17. /*
  18.  * Descriptor
  19.  */
  20.  
  21. struct descrip {        /* descriptor */
  22.    word dword;            /*   type field */
  23.    union {
  24.       word integr;        /*   integer value */
  25.       char *sptr;        /*   pointer to character string */
  26.       union block *bptr;    /*   pointer to a block */
  27.       dptr descptr;        /*   pointer to a descriptor */
  28.       } vword;
  29.    };
  30.  
  31. struct sdescrip {
  32.    word length;            /*   length of string */
  33.    char *string;        /*   pointer to string */
  34.    };
  35.  
  36. #ifdef LargeInts
  37. struct b_bignum {        /* large integer block */
  38.    word title;            /*   T_Lrgint */
  39.    word blksize;        /*   block size */
  40.    word msd, lsd;        /*   most and least significant digits */
  41.    int sign;            /*   sign; 0 positive, 1 negative */
  42.    DIGIT digits[1];        /*   digits */
  43.    };
  44. #endif                    /* LargeInts */
  45.  
  46. struct b_real {            /* real block */
  47.    word title;            /*   T_Real */
  48.    double realval;        /*   value */
  49.    };
  50.  
  51. struct b_cset {            /* cset block */
  52.    word title;            /*   T_Cset */
  53.    word size;            /*   size of cset */
  54.    unsigned int bits[CsetSize];        /*   array of bits */
  55.    };
  56.  
  57. struct b_file {            /* file block */
  58.    word title;            /*   T_File */
  59.    FILE *fd;            /*   Unix file descriptor */
  60.    word status;            /*   file status */
  61.    struct descrip fname;    /*   file name (string qualifier) */
  62.    };
  63.  
  64. struct b_lelem {        /* list-element block */
  65.    word title;            /*   T_Lelem */
  66.    word blksize;        /*   size of block */
  67.    union block *listprev;    /*   previous list-element block */
  68.    union block *listnext;    /*   next list-element block */
  69.    word nslots;            /*   total number of slots */
  70.    word first;            /*   index of first used slot */
  71.    word nused;            /*   number of used slots */
  72.    struct descrip lslots[1];    /*   array of slots */
  73.    };
  74.  
  75. struct b_list {            /* list-header block */
  76.    word title;            /*   T_List */
  77.    word size;            /*   current list size */
  78.    word id;            /*   identification number */
  79.    union block *listhead;    /*   pointer to first list-element block */
  80.    union block *listtail;    /*   pointer to last list-element block */
  81.    };
  82.  
  83. struct b_proc {            /* procedure block */
  84.    word title;            /*   T_Proc */
  85.    word blksize;        /*   size of block */
  86.  
  87. #if COMPILER
  88.    int (*ccode)();
  89. #else                    /* COMPILER */
  90.    union {            /*   entry points for */
  91.       int (*ccode)();        /*     C routines */
  92.       uword ioff;        /*     and icode as offset */
  93.       pointer icode;        /*     and icode as absolute pointer */
  94.       } entryp;
  95. #endif                    /* COMPILER */
  96.  
  97.    word nparam;            /*   number of parameters */
  98.    word ndynam;            /*   number of dynamic locals */
  99.    word nstatic;        /*   number of static locals */
  100.    word fstatic;        /*   index (in global table) of first static */
  101.  
  102. #ifdef MultiThread
  103.    struct progstate *program;
  104. #endif                /* MultiThread */
  105.  
  106.    struct descrip pname;    /*   procedure name (string qualifier) */
  107.    struct descrip lnames[1];    /*   list of local names (qualifiers) */
  108.    };
  109.  
  110. struct b_record {        /* record block */
  111.    word title;            /*   T_Record */
  112.    word blksize;        /*   size of block */
  113.    word id;            /*   identification number */
  114.    union block *recdesc;    /*   pointer to record constructor */
  115.    struct descrip fields[1];    /*   fields */
  116.    };
  117.  
  118. /*
  119.  * Alternate uses for procedure block fields, applied to records.
  120.  */
  121. #define nfields    nparam        /* number of fields */
  122. #define recnum nstatic        /* record number */
  123. #define recid fstatic        /* record serial number */
  124. #define recname    pname        /* record name */
  125.  
  126. struct b_selem {        /* set-element block */
  127.    word title;            /*   T_Selem */
  128.    union block *clink;        /*   hash chain link */
  129.    uword hashnum;        /*   hash number */
  130.    struct descrip setmem;    /*   the element */
  131.    };
  132.  
  133. /*
  134.  * A set header must be a proper prefix of a table header,
  135.  *  and a set element must be a proper prefix of a table element.
  136.  */
  137. struct b_set {            /* set-header block */
  138.    word title;            /*   T_Set */
  139.    word size;            /*   size of the set */
  140.    word id;            /*   identification number */
  141.    word mask;            /*   mask for slot num, equals n slots - 1 */
  142.    struct b_slots *hdir[HSegs];    /*   directory of hash slot segments */
  143.    };
  144.  
  145. struct b_table {        /* table-header block */
  146.    word title;            /*   T_Table */
  147.    word size;            /*   current table size */
  148.    word id;            /*   identification number */
  149.    word mask;            /*   mask for slot num, equals n slots - 1 */
  150.    struct b_slots *hdir[HSegs];    /*   directory of hash slot segments */
  151.    struct descrip defvalue;    /*   default table element value */
  152.    };
  153.  
  154. struct b_slots {        /* set/table hash slots */
  155.    word title;            /*   T_Slots */
  156.    word blksize;        /*   size of block */
  157.    union block *hslots[HSlots];    /*   array of slots (HSlots * 2^n entries) */
  158.    };
  159.  
  160. struct b_telem {        /* table-element block */
  161.    word title;            /*   T_Telem */
  162.    union block *clink;        /*   hash chain link */
  163.    uword hashnum;        /*   for ordering chain */
  164.    struct descrip tref;        /*   entry value */
  165.    struct descrip tval;        /*   assigned value */
  166.    };
  167.  
  168. struct b_tvsubs {        /* substring trapped variable block */
  169.    word title;            /*   T_Tvsubs */
  170.    word sslen;            /*   length of substring */
  171.    word sspos;            /*   position of substring */
  172.    struct descrip ssvar;    /*   variable that substring is from */
  173.    };
  174.  
  175. struct b_tvtbl {        /* table element trapped variable block */
  176.    word title;            /*   T_Tvtbl */
  177.    union block *clink;        /*   pointer to table header block */
  178.    uword hashnum;        /*   hash number */
  179.    struct descrip tref;        /*   entry value */
  180.    };
  181.  
  182. struct b_external {        /* external block */
  183.    word title;            /*   T_External */
  184.    word blksize;        /*   size of block */
  185.    word exdata[1];        /*   words of external data */
  186.    };
  187.  
  188. struct astkblk {          /* co-expression activator-stack block */
  189.    int nactivators;          /*   number of valid activator entries in
  190.                    *    this block */
  191.    struct astkblk *astk_nxt;      /*   next activator block */
  192.    struct actrec {          /*   activator record */
  193.       word acount;          /*     number of calls by this activator */
  194.       struct b_coexpr *activator; /*     the activator itself */
  195.       } arec[ActStkBlkEnts];
  196.    };
  197.  
  198. /*
  199.  * Structure for keeping set/table generator state across a suspension.
  200.  */
  201. struct hgstate {        /* hashed-structure generator state */
  202.    int segnum;            /* current segment number */
  203.    word slotnum;        /* current slot number */
  204.    word tmask;            /* structure mask before suspension */
  205.    word sgmask[HSegs];        /* mask in use when the segment was created */
  206.    uword sghash[HSegs];        /* hashnum in process when seg was created */
  207.    };
  208.  
  209.  
  210. /*
  211.  * Structure for chaining tended descriptors.
  212.  */
  213. struct tend_desc {
  214.    struct tend_desc *previous;
  215.    int num;
  216.    struct descrip d[1]; /* actual size of array indicated by num */
  217.    };
  218.  
  219. /*
  220.  * Structure for mapping string names of functions and operators to block
  221.  * addresses.
  222.  */
  223. struct pstrnm {
  224.    char *pstrep;
  225.    struct b_proc *pblock;
  226.    };
  227.  
  228. struct dpair {
  229.    struct descrip dr;
  230.    struct descrip dv;
  231.    };
  232.  
  233. /*
  234.  * Allocated memory region structure.  Each program has linked lists of
  235.  * string and block regions.
  236.  */
  237. struct region {
  238.    word  size;                /* allocated region size in bytes */
  239.    char *base;                /* start of region */
  240.    char *end;                /* end of region */
  241.    char *free;                /* free pointer */
  242.    struct region *prev, *next;        /* forms a linked list of regions */
  243.    struct region *Gprev, *Gnext;    /* global (all programs) lists */
  244.    };
  245.  
  246. #ifdef Double
  247. /*
  248.  * Data type the same size as a double but without alignment requirements.
  249.  */
  250.    struct size_dbl {
  251.        char s[sizeof(double)];
  252.        };
  253. #endif                    /* Double */
  254.  
  255.  
  256. #if COMPILER
  257.  
  258. /*
  259.  * Structures for the compiler.
  260.  */
  261.  
  262. struct p_frame {
  263.    struct p_frame *old_pfp;
  264.    struct descrip *old_argp;
  265.    struct descrip *rslt;
  266.    continuation succ_cont;
  267.    struct tend_desc tend;
  268.    };
  269. #endif                    /* COMPILER */
  270.  
  271. /*
  272.  * when debugging is enabled a debug struct is placed after the tended
  273.  *  descriptors in the procedure frame.
  274.  */
  275. struct debug {
  276.    struct b_proc *proc;
  277.    char *old_fname;
  278.    int old_line;
  279.    };
  280.  
  281. union numeric {            /* long integers or real numbers */
  282.    long integer;
  283.    double real;
  284.  
  285. #ifdef LargeInts
  286.    struct b_bignum *big;
  287. #endif                /* LargeInts */
  288.  
  289.    };
  290.  
  291. #if COMPILER
  292. struct b_coexpr {        /* co-expression stack block */
  293.    word title;            /*   T_Coexpr */
  294.    word size;            /*   number of results produced */
  295.    word id;            /*   identification number */
  296.    struct b_coexpr *nextstk;    /*   pointer to next allocated stack */
  297.    continuation fnc;        /*   function containing co-expression code */
  298.    struct p_frame *es_pfp;    /*   current procedure frame pointer */
  299.    dptr es_argp;        /*   current argument pointer */
  300.    struct tend_desc *es_tend;    /*   current tended pointer */
  301.    char *file_name;        /*   current file name */
  302.    word line_num;        /*   current line_number */
  303.    dptr tvalloc;        /*   where to place transmitted value */
  304.    struct descrip freshblk;    /*   refresh block pointer */
  305.    struct astkblk *es_actstk;    /*   pointer to activation stack structure */
  306.    word cstate[CStateSize];    /*   C state information */
  307.    struct p_frame pf;           /*   initial procedure frame */
  308.    };
  309.  
  310. struct b_refresh {        /* co-expression block */
  311.    word title;            /*   T_Refresh */
  312.    word blksize;        /*   size of block */
  313.    word nlocals;        /*   number of local variables */
  314.    word nargs;            /*   number of arguments */
  315.    word ntemps;                 /*   number of temporary descriptors */
  316.    word wrk_size;        /*   size of non-descriptor work area */
  317.    struct descrip elems[1];    /*   locals and arguments */
  318.    };
  319.  
  320. #else                    /* COMPILER */
  321.  
  322. /*
  323.  * Structures for the interpreter.
  324.  */
  325.  
  326. /*
  327.  * Declarations for entries in tables associating icode location with
  328.  *  source program location.
  329.  */
  330. struct ipc_fname {
  331.    word ipc;        /* offset of instruction into code region */
  332.    word fname;        /* offset of file name into string region */
  333.    };
  334.  
  335. struct ipc_line {
  336.    word ipc;        /* offset of instruction into code region */
  337.    int line;        /* line number */
  338.    };
  339.  
  340. #ifdef MultiThread
  341. /*
  342.  * Program state encapsulation.  This consists of the VARIABLE parts of
  343.  * many global structures.
  344.  */
  345. struct progstate {
  346.    long hsize;                /* size of the icode */
  347.    struct progstate *parent;
  348.    struct descrip parentdesc;        /* implicit "&parent" */
  349.    struct descrip eventmask;        /* implicit "&eventmask" */
  350.    struct descrip opcodemask;        /* implicit "&opcodemask" */
  351.    struct descrip eventcode;        /* &eventcode */
  352.    struct descrip eventval;        /* &eventval */
  353.    struct descrip eventsource;        /* &eventsource */
  354.  
  355.    /*
  356.     * trapped variable keywords' values
  357.     */
  358.    struct descrip Kywd_err;
  359.    struct descrip Kywd_pos;
  360.    struct descrip ksub;
  361.    struct descrip Kywd_prog;
  362.    struct descrip Kywd_ran;
  363.    struct descrip Kywd_trc;
  364.    struct b_coexpr *Mainhead;
  365.    char *Code;
  366.    word *Records;
  367.    int *Ftabp;
  368.    dptr Fnames, Efnames;
  369.    dptr Globals, Eglobals;
  370.    dptr Gnames, Egnames;
  371.    dptr Statics, Estatics;
  372.    int NGlobals, NStatics;
  373.    char *Strcons;
  374.    struct ipc_fname *Filenms, *Efilenms;
  375.    struct ipc_line *Ilines, *Elines;
  376.    struct ipc_line * Current_line_ptr;
  377.  
  378. #ifdef Graphics
  379.    struct descrip AmperX, AmperY, AmperRow, AmperCol;    /* &x, &y, &row, &col */
  380.    struct descrip AmperInterval;            /* &interval */
  381.    struct descrip LastEventWin;                /* last Event() win */
  382.    int LastEvFWidth;
  383.    int LastEvLeading;
  384.    int LastEvAscent;
  385.    uword PrevTimeStamp;                    /* previous timestamp */
  386.    uword Xmod_Control, Xmod_Shift, Xmod_Meta;        /* control,shift,meta */
  387.    struct descrip Kywd_xwin[2];                /* &window + ... */
  388. #endif                    /* Graphics */
  389.  
  390. #ifdef EventMon
  391.    word Linenum, Column, Lastline, Lastcol;
  392. #endif                    /* EventMon */
  393.  
  394.    word Coexp_ser;            /* this program's serial numbers */
  395.    word List_ser;
  396.    word Set_ser;
  397.    word Table_ser;
  398.  
  399.    uword stringtotal;            /* cumulative total allocation */
  400.    uword blocktotal;            /* cumulative total allocation */
  401.    word colltot;            /* total number of collections */
  402.    word collstat;            /* number of static collect requests */
  403.    word collstr;            /* number of string collect requests */
  404.    word collblk;            /* number of block collect requests */
  405.    struct region *stringregion;
  406.    struct region *blockregion;
  407.  
  408.    word Lastop;
  409.  
  410.    dptr Xargp;
  411.    word Xnargs;
  412.  
  413.    int K_errornumber;
  414.    char *K_errortext;
  415.    struct descrip K_errorvalue;
  416.    int Have_errval;
  417.    int T_errornumber;
  418.    int T_have_val;
  419.    struct descrip T_errorvalue;
  420.  
  421.    struct descrip K_main;
  422.    struct b_file K_errout;
  423.    struct b_file K_input;
  424.    struct b_file K_output;
  425.    };
  426.  
  427. #endif                /* MultiThread */
  428.  
  429. /*
  430.  * Frame markers
  431.  */
  432. struct ef_marker {        /* expression frame marker */
  433.    inst ef_failure;        /*   failure ipc */
  434.    struct ef_marker *ef_efp;    /*   efp */
  435.    struct gf_marker *ef_gfp;    /*   gfp */
  436.    word ef_ilevel;        /*   ilevel */
  437.    };
  438.  
  439. struct pf_marker {        /* procedure frame marker */
  440.    word pf_nargs;        /*   number of arguments */
  441.    struct pf_marker *pf_pfp;    /*   saved pfp */
  442.    struct ef_marker *pf_efp;    /*   saved efp */
  443.    struct gf_marker *pf_gfp;    /*   saved gfp */
  444.    dptr pf_argp;        /*   saved argp */
  445.    inst pf_ipc;            /*   saved ipc */
  446.    word pf_ilevel;        /*   saved ilevel */
  447.    dptr pf_scan;        /*   saved scanning environment */
  448.  
  449. #ifdef MultiThread
  450.    struct progstate *pf_prog;    /*   saved program state pointer */
  451. #endif                /* MultiThread */
  452.  
  453.    struct descrip pf_locals[1];    /*   descriptors for locals */
  454.    };
  455.  
  456. struct gf_marker {        /* generator frame marker */
  457.    word gf_gentype;        /*   type */
  458.    struct ef_marker *gf_efp;    /*   efp */
  459.    struct gf_marker *gf_gfp;    /*   gfp */
  460.    inst gf_ipc;            /*   ipc */
  461.    struct pf_marker *gf_pfp;    /*   pfp */
  462.    dptr gf_argp;        /*   argp */
  463.    };
  464.  
  465. /*
  466.  * Generator frame marker dummy -- used only for sizing "small"
  467.  *  generator frames where procedure information need not be saved.
  468.  *  The first five members here *must* be identical to those for
  469.  *  gf_marker.
  470.  */
  471. struct gf_smallmarker {        /* generator frame marker */
  472.    word gf_gentype;        /*   type */
  473.    struct ef_marker *gf_efp;    /*   efp */
  474.    struct gf_marker *gf_gfp;    /*   gfp */
  475.    inst gf_ipc;            /*   ipc */
  476.    };
  477.  
  478. /*
  479.  * b_iproc blocks are used to statically initialize information about
  480.  *  functions.    They are identical to b_proc blocks except for
  481.  *  the pname field which is a sdescrip (simple/string descriptor) instead
  482.  *  of a descrip.  This is done because unions cannot be initialized.
  483.  */
  484.     
  485. struct b_iproc {        /* procedure block */
  486.    word ip_title;        /*   T_Proc */
  487.    word ip_blksize;        /*   size of block */
  488.    int (*ip_entryp)();        /*   entry point (code) */
  489.    word ip_nparam;        /*   number of parameters */
  490.    word ip_ndynam;        /*   number of dynamic locals */
  491.    word ip_nstatic;        /*   number of static locals */
  492.    word ip_fstatic;        /*   index (in global table) of first static */
  493.  
  494. #ifdef MultiThread
  495.    struct progstate *ip_program;
  496. #endif                /* MultiThread */
  497.  
  498.    struct sdescrip ip_pname;    /*   procedure name (string qualifier) */
  499.    struct descrip ip_lnames[1];    /*   list of local names (qualifiers) */
  500.    };
  501.  
  502. struct b_coexpr {        /* co-expression stack block */
  503.    word title;            /*   T_Coexpr */
  504.    word size;            /*   number of results produced */
  505.    word id;            /*   identification number */
  506.    struct b_coexpr *nextstk;    /*   pointer to next allocated stack */
  507.    struct pf_marker *es_pfp;    /*   current pfp */
  508.    struct ef_marker *es_efp;    /*   efp */
  509.    struct gf_marker *es_gfp;    /*   gfp */
  510.    struct tend_desc *es_tend;    /*   current tended pointer */
  511.    dptr es_argp;        /*   argp */
  512.    inst es_ipc;            /*   ipc */
  513.    word es_ilevel;        /*   interpreter level */
  514.    word *es_sp;            /*   sp */
  515.    dptr tvalloc;        /*   where to place transmitted value */
  516.    struct descrip freshblk;    /*   refresh block pointer */
  517.    struct astkblk *es_actstk;    /*   pointer to activation stack structure */
  518.  
  519. #ifdef MultiThread
  520.    struct progstate *program;
  521. #endif                /* MultiThread */
  522.  
  523.    word cstate[CStateSize];    /*   C state information */
  524.    };
  525.  
  526. struct b_refresh {        /* co-expression block */
  527.    word title;            /*   T_Refresh */
  528.    word blksize;        /*   size of block */
  529.    word *ep;            /*   entry point */
  530.    word numlocals;        /*   number of locals */
  531.    struct pf_marker pfmkr;    /*   marker for enclosing procedure */
  532.    struct descrip elems[1];    /*   arguments and locals, including Arg0 */
  533.    };
  534.  
  535. #endif                    /* COMPILER */
  536.  
  537. union block {            /* general block */
  538.  
  539. #ifdef LargeInts
  540.    struct b_bignum bignumblk;
  541. #endif                    /* LargeInts */
  542.  
  543.    struct b_real realblk;
  544.    struct b_cset cset;
  545.    struct b_file file;
  546.    struct b_proc proc;
  547.    struct b_list list;
  548.    struct b_lelem lelem;
  549.    struct b_table table;
  550.    struct b_telem telem;
  551.    struct b_set set;
  552.    struct b_selem selem;
  553.    struct b_record record;
  554.    struct b_tvsubs tvsubs;
  555.    struct b_tvtbl tvtbl;
  556.    struct b_refresh refresh;
  557.    struct b_coexpr coexpr;
  558.    struct b_external externl;
  559.    struct b_slots slots;
  560.    };
  561.