home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / h / rstructs.h < prev    next >
C/C++ Source or Header  |  2001-12-12  |  17KB  |  556 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.    struct descrip pname;    /*   procedure name (string qualifier) */
  103.    struct descrip lnames[1];    /*   list of local names (qualifiers) */
  104.    };
  105.  
  106. struct b_record {        /* record block */
  107.    word title;            /*   T_Record */
  108.    word blksize;        /*   size of block */
  109.    word id;            /*   identification number */
  110.    union block *recdesc;    /*   pointer to record constructor */
  111.    struct descrip fields[1];    /*   fields */
  112.    };
  113.  
  114. /*
  115.  * Alternate uses for procedure block fields, applied to records.
  116.  */
  117. #define nfields    nparam        /* number of fields */
  118. #define recnum nstatic        /* record number */
  119. #define recid fstatic        /* record serial number */
  120. #define recname    pname        /* record name */
  121.  
  122. struct b_selem {        /* set-element block */
  123.    word title;            /*   T_Selem */
  124.    union block *clink;        /*   hash chain link */
  125.    uword hashnum;        /*   hash number */
  126.    struct descrip setmem;    /*   the element */
  127.    };
  128.  
  129. /*
  130.  * A set header must be a proper prefix of a table header,
  131.  *  and a set element must be a proper prefix of a table element.
  132.  */
  133. struct b_set {            /* set-header block */
  134.    word title;            /*   T_Set */
  135.    word size;            /*   size of the set */
  136.    word id;            /*   identification number */
  137.    word mask;            /*   mask for slot num, equals n slots - 1 */
  138.    struct b_slots *hdir[HSegs];    /*   directory of hash slot segments */
  139.    };
  140.  
  141. struct b_table {        /* table-header block */
  142.    word title;            /*   T_Table */
  143.    word size;            /*   current table size */
  144.    word id;            /*   identification number */
  145.    word mask;            /*   mask for slot num, equals n slots - 1 */
  146.    struct b_slots *hdir[HSegs];    /*   directory of hash slot segments */
  147.    struct descrip defvalue;    /*   default table element value */
  148.    };
  149.  
  150. struct b_slots {        /* set/table hash slots */
  151.    word title;            /*   T_Slots */
  152.    word blksize;        /*   size of block */
  153.    union block *hslots[HSlots];    /*   array of slots (HSlots * 2^n entries) */
  154.    };
  155.  
  156. struct b_telem {        /* table-element block */
  157.    word title;            /*   T_Telem */
  158.    union block *clink;        /*   hash chain link */
  159.    uword hashnum;        /*   for ordering chain */
  160.    struct descrip tref;        /*   entry value */
  161.    struct descrip tval;        /*   assigned value */
  162.    };
  163.  
  164. struct b_tvsubs {        /* substring trapped variable block */
  165.    word title;            /*   T_Tvsubs */
  166.    word sslen;            /*   length of substring */
  167.    word sspos;            /*   position of substring */
  168.    struct descrip ssvar;    /*   variable that substring is from */
  169.    };
  170.  
  171. struct b_tvtbl {        /* table element trapped variable block */
  172.    word title;            /*   T_Tvtbl */
  173.    union block *clink;        /*   pointer to table header block */
  174.    uword hashnum;        /*   hash number */
  175.    struct descrip tref;        /*   entry value */
  176.    };
  177.  
  178. struct b_external {        /* external block */
  179.    word title;            /*   T_External */
  180.    word blksize;        /*   size of block */
  181.    word exdata[1];        /*   words of external data */
  182.    };
  183.  
  184. struct astkblk {          /* co-expression activator-stack block */
  185.    int nactivators;          /*   valid activator entries in this block */
  186.    struct astkblk *astk_nxt;      /*   next activator block */
  187.    struct actrec {          /*   activator record */
  188.       word acount;          /*     number of calls by this activator */
  189.       struct b_coexpr *activator; /*     the activator itself */
  190.       } arec[ActStkBlkEnts];
  191.    };
  192.  
  193. /*
  194.  * Structure for keeping set/table generator state across a suspension.
  195.  */
  196. struct hgstate {        /* hashed-structure generator state */
  197.    int segnum;            /* current segment number */
  198.    word slotnum;        /* current slot number */
  199.    word tmask;            /* structure mask before suspension */
  200.    word sgmask[HSegs];        /* mask in use when the segment was created */
  201.    uword sghash[HSegs];        /* hashnum in process when seg was created */
  202.    };
  203.  
  204. /*
  205.  * Structure for chaining tended descriptors.
  206.  */
  207. struct tend_desc {
  208.    struct tend_desc *previous;
  209.    int num;
  210.    struct descrip d[1]; /* actual size of array indicated by num */
  211.    };
  212.  
  213. /*
  214.  * Structure for mapping string names of functions and operators to block
  215.  * addresses.
  216.  */
  217. struct pstrnm {
  218.    char *pstrep;
  219.    struct b_proc *pblock;
  220.    };
  221.  
  222. struct dpair {
  223.    struct descrip dr;
  224.    struct descrip dv;
  225.    };
  226.  
  227. /*
  228.  * Allocated memory region structure.  Each program has linked lists of
  229.  * string and block regions.
  230.  */
  231. struct region {
  232.    word  size;                /* allocated region size in bytes */
  233.    char *base;                /* start of region */
  234.    char *end;                /* end of region */
  235.    char *free;                /* free pointer */
  236.    struct region *prev, *next;        /* forms a linked list of regions */
  237.    struct region *Gprev, *Gnext;    /* global (all programs) lists */
  238.    };
  239.  
  240. #ifdef Double
  241.    /*
  242.     * Data type the same size as a double but without alignment requirements.
  243.     */
  244.    struct size_dbl {
  245.       char s[sizeof(double)];
  246.       };
  247. #endif                    /* Double */
  248.  
  249. #if COMPILER
  250.  
  251. /*
  252.  * Structures for the compiler.
  253.  */
  254.    struct p_frame {
  255.       struct p_frame *old_pfp;
  256.       struct descrip *old_argp;
  257.       struct descrip *rslt;
  258.       continuation succ_cont;
  259.       struct tend_desc tend;
  260.       };
  261.    #endif                /* COMPILER */
  262.  
  263. /*
  264.  * when debugging is enabled a debug struct is placed after the tended
  265.  *  descriptors in the procedure frame.
  266.  */
  267. struct debug {
  268.    struct b_proc *proc;
  269.    char *old_fname;
  270.    int old_line;
  271.    };
  272.  
  273. union numeric {            /* long integers or real numbers */
  274.    long integer;
  275.    double real;
  276.    #ifdef LargeInts
  277.       struct b_bignum *big;
  278.    #endif                /* LargeInts */
  279.    };
  280.  
  281. #if COMPILER
  282. struct b_coexpr {        /* co-expression stack block */
  283.    word title;            /*   T_Coexpr */
  284.    word size;            /*   number of results produced */
  285.    word id;            /*   identification number */
  286.    struct b_coexpr *nextstk;    /*   pointer to next allocated stack */
  287.    continuation fnc;        /*   function containing co-expression code */
  288.    struct p_frame *es_pfp;    /*   current procedure frame pointer */
  289.    dptr es_argp;        /*   current argument pointer */
  290.    struct tend_desc *es_tend;    /*   current tended pointer */
  291.    char *file_name;        /*   current file name */
  292.    word line_num;        /*   current line_number */
  293.    dptr tvalloc;        /*   where to place transmitted value */
  294.    struct descrip freshblk;    /*   refresh block pointer */
  295.    struct astkblk *es_actstk;    /*   pointer to activation stack structure */
  296.    word cstate[CStateSize];    /*   C state information */
  297.    struct p_frame pf;           /*   initial procedure frame */
  298.    };
  299.  
  300. struct b_refresh {        /* co-expression block */
  301.    word title;            /*   T_Refresh */
  302.    word blksize;        /*   size of block */
  303.    word nlocals;        /*   number of local variables */
  304.    word nargs;            /*   number of arguments */
  305.    word ntemps;                 /*   number of temporary descriptors */
  306.    word wrk_size;        /*   size of non-descriptor work area */
  307.    struct descrip elems[1];    /*   locals and arguments */
  308.    };
  309.  
  310. #else                    /* COMPILER */
  311.  
  312. /*
  313.  * Structures for the interpreter.
  314.  */
  315.  
  316. /*
  317.  * Declarations for entries in tables associating icode location with
  318.  *  source program location.
  319.  */
  320. struct ipc_fname {
  321.    word ipc;        /* offset of instruction into code region */
  322.    word fname;        /* offset of file name into string region */
  323.    };
  324.  
  325. struct ipc_line {
  326.    word ipc;        /* offset of instruction into code region */
  327.    int line;        /* line number */
  328.    };
  329.  
  330. #ifdef MultiThread
  331. /*
  332.  * Program state encapsulation.  This consists of the VARIABLE parts of
  333.  * many global structures.
  334.  */
  335. struct progstate {
  336.    long hsize;                /* size of the icode */
  337.    struct progstate *parent;
  338.    struct descrip parentdesc;        /* implicit "&parent" */
  339.    struct descrip eventmask;        /* implicit "&eventmask" */
  340.    struct descrip opcodemask;        /* implicit "&opcodemask" */
  341.    struct descrip eventcode;        /* &eventcode */
  342.    struct descrip eventval;        /* &eventval */
  343.    struct descrip eventsource;        /* &eventsource */
  344.    dptr Glbl_argp;            /* global argp */
  345.  
  346.    /*
  347.     * trapped variable keywords' values
  348.     */
  349.    struct descrip Kywd_err;
  350.    struct descrip Kywd_pos;
  351.    struct descrip ksub;
  352.    struct descrip Kywd_prog;
  353.    struct descrip Kywd_ran;
  354.    struct descrip Kywd_trc;
  355.    struct b_coexpr *Mainhead;
  356.    char *Code;
  357.    char *Ecode;
  358.    word *Records;
  359.    int *Ftabp;
  360.    #ifdef FieldTableCompression
  361.       short Ftabwidth, Foffwidth;
  362.       unsigned char *Ftabcp, *Focp;
  363.       short *Ftabsp, *Fosp;
  364.       int *Fo;
  365.       char *Bm;
  366.    #endif                /* FieldTableCompression */
  367.    dptr Fnames, Efnames;
  368.    dptr Globals, Eglobals;
  369.    dptr Gnames, Egnames;
  370.    dptr Statics, Estatics;
  371.    int NGlobals, NStatics;
  372.    char *Strcons;
  373.    struct ipc_fname *Filenms, *Efilenms;
  374.    struct ipc_line *Ilines, *Elines;
  375.    struct ipc_line * Current_line_ptr;
  376.  
  377.    #ifdef Graphics
  378.       struct descrip AmperX, AmperY, AmperRow, AmperCol;/* &x, &y, &row, &col */
  379.       struct descrip AmperInterval;            /* &interval */
  380.       struct descrip LastEventWin;            /* last Event() win */
  381.       int LastEvFWidth;
  382.       int LastEvLeading;
  383.       int LastEvAscent;
  384.       uword PrevTimeStamp;                /* previous timestamp */
  385.       uword Xmod_Control, Xmod_Shift, Xmod_Meta;    /* control,shift,meta */
  386.       struct descrip Kywd_xwin[2];            /* &window + ... */
  387.    #endif                /* Graphics */
  388.  
  389.    #ifdef EventMon
  390.       word Linenum, Column, Lastline, Lastcol;
  391.    #endif                /* EventMon */
  392.  
  393.    word Coexp_ser;            /* this program's serial numbers */
  394.    word List_ser;
  395.    word Set_ser;
  396.    word Table_ser;
  397.  
  398.    uword stringtotal;            /* cumulative total allocation */
  399.    uword blocktotal;            /* cumulative total allocation */
  400.    word colltot;            /* total number of collections */
  401.    word collstat;            /* number of static collect requests */
  402.    word collstr;            /* number of string collect requests */
  403.    word collblk;            /* number of block collect requests */
  404.    struct region *stringregion;
  405.    struct region *blockregion;
  406.  
  407.    word Lastop;
  408.  
  409.    dptr Xargp;
  410.    word Xnargs;
  411.  
  412.    struct descrip K_current;
  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.    struct sdescrip ip_pname;    /*   procedure name (string qualifier) */
  495.    struct descrip ip_lnames[1];    /*   list of local names (qualifiers) */
  496.    };
  497.  
  498. struct b_coexpr {        /* co-expression stack block */
  499.    word title;            /*   T_Coexpr */
  500.    word size;            /*   number of results produced */
  501.    word id;            /*   identification number */
  502.    struct b_coexpr *nextstk;    /*   pointer to next allocated stack */
  503.    struct pf_marker *es_pfp;    /*   current pfp */
  504.    struct ef_marker *es_efp;    /*   efp */
  505.    struct gf_marker *es_gfp;    /*   gfp */
  506.    struct tend_desc *es_tend;    /*   current tended pointer */
  507.    dptr es_argp;        /*   argp */
  508.    inst es_ipc;            /*   ipc */
  509.    word es_ilevel;        /*   interpreter level */
  510.    word *es_sp;            /*   sp */
  511.    dptr tvalloc;        /*   where to place transmitted value */
  512.    struct descrip freshblk;    /*   refresh block pointer */
  513.    struct astkblk *es_actstk;    /*   pointer to activation stack structure */
  514.  
  515.    #ifdef MultiThread
  516.       struct progstate *program;
  517.    #endif                /* MultiThread */
  518.  
  519.    word cstate[CStateSize];    /*   C state information */
  520.    };
  521.  
  522. struct b_refresh {        /* co-expression block */
  523.    word title;            /*   T_Refresh */
  524.    word blksize;        /*   size of block */
  525.    word *ep;            /*   entry point */
  526.    word numlocals;        /*   number of locals */
  527.    struct pf_marker pfmkr;    /*   marker for enclosing procedure */
  528.    struct descrip elems[1];    /*   arguments and locals, including Arg0 */
  529.    };
  530.  
  531. #endif                    /* COMPILER */
  532.  
  533. union block {            /* general block */
  534.    struct b_real realblk;
  535.    struct b_cset cset;
  536.    struct b_file file;
  537.    struct b_proc proc;
  538.    struct b_list list;
  539.    struct b_lelem lelem;
  540.    struct b_table table;
  541.    struct b_telem telem;
  542.    struct b_set set;
  543.    struct b_selem selem;
  544.    struct b_record record;
  545.    struct b_tvsubs tvsubs;
  546.    struct b_tvtbl tvtbl;
  547.    struct b_refresh refresh;
  548.    struct b_coexpr coexpr;
  549.    struct b_external externl;
  550.    struct b_slots slots;
  551.  
  552.    #ifdef LargeInts
  553.       struct b_bignum bignumblk;
  554.    #endif                /* LargeInts */
  555.    };
  556.