home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / icon / dos / src / h / rstructs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-10  |  14.8 KB  |  488 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.    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.  
  103.    struct descrip pname;    /*   procedure name (string qualifier) */
  104.    struct descrip lnames[1];    /*   list of local names (qualifiers) */
  105.    };
  106.  
  107. struct b_record {        /* record block */
  108.    word title;            /*   T_Record */
  109.    word blksize;        /*   size of block */
  110.    word id;            /*   identification number */
  111.    union block *recdesc;    /*   pointer to record constructor */
  112.    struct descrip fields[1];    /*   fields */
  113.    };
  114.  
  115. /*
  116.  * Alternate uses for procedure block fields, applied to records.
  117.  */
  118. #define nfields    nparam        /* number of fields */
  119. #define recnum nstatic        /* record number */
  120. #define recid fstatic        /* record serial number */
  121. #define recname    pname        /* record name */
  122.  
  123. struct b_selem {        /* set-element block */
  124.    word title;            /*   T_Selem */
  125.    union block *clink;        /*   hash chain link */
  126.    uword hashnum;        /*   hash number */
  127.    struct descrip setmem;    /*   the element */
  128.    };
  129.  
  130. /*
  131.  * A set header must be a proper prefix of a table header,
  132.  *  and a set element must be a proper prefix of a table element.
  133.  */
  134. struct b_set {            /* set-header block */
  135.    word title;            /*   T_Set */
  136.    word size;            /*   size of the set */
  137.    word id;            /*   identification number */
  138.    word mask;            /*   mask for slot num, equals n slots - 1 */
  139.    struct b_slots *hdir[HSegs];    /*   directory of hash slot segments */
  140.    };
  141.  
  142. struct b_table {        /* table-header block */
  143.    word title;            /*   T_Table */
  144.    word size;            /*   current table size */
  145.    word id;            /*   identification number */
  146.    word mask;            /*   mask for slot num, equals n slots - 1 */
  147.    struct b_slots *hdir[HSegs];    /*   directory of hash slot segments */
  148.    struct descrip defvalue;    /*   default table element value */
  149.    };
  150.  
  151. struct b_slots {        /* set/table hash slots */
  152.    word title;            /*   T_Slots */
  153.    word blksize;        /*   size of block */
  154.    union block *hslots[HSlots];    /*   array of slots (HSlots * 2^n entries) */
  155.    };
  156.  
  157. struct b_telem {        /* table-element block */
  158.    word title;            /*   T_Telem */
  159.    union block *clink;        /*   hash chain link */
  160.    uword hashnum;        /*   for ordering chain */
  161.    struct descrip tref;        /*   entry value */
  162.    struct descrip tval;        /*   assigned value */
  163.    };
  164.  
  165. struct b_tvsubs {        /* substring trapped variable block */
  166.    word title;            /*   T_Tvsubs */
  167.    word sslen;            /*   length of substring */
  168.    word sspos;            /*   position of substring */
  169.    struct descrip ssvar;    /*   variable that substring is from */
  170.    };
  171.  
  172. struct b_tvtbl {        /* table element trapped variable block */
  173.    word title;            /*   T_Tvtbl */
  174.    union block *clink;        /*   pointer to table header block */
  175.    uword hashnum;        /*   hash number */
  176.    struct descrip tref;        /*   entry value */
  177.    struct descrip tval;        /*   reserved for assigned value */
  178.    };
  179.  
  180. struct b_external {        /* external block */
  181.    word title;            /*   T_External */
  182.    word blksize;        /*   size of block */
  183.    word exdata[1];        /*   words of external data */
  184.    };
  185.  
  186. struct astkblk {          /* co-expression activator-stack block */
  187.    int nactivators;          /*   number of valid activator entries in
  188.                    *    this block */
  189.    struct astkblk *astk_nxt;      /*   next activator block */
  190.    struct actrec {          /*   activator record */
  191.       word acount;          /*     number of calls by this activator */
  192.       struct b_coexpr *activator; /*     the activator itself */
  193.       } arec[ActStkBlkEnts];
  194.    };
  195.  
  196. /*
  197.  * Structure for keeping set/table generator state across a suspension.
  198.  */
  199. struct hgstate {        /* hashed-structure generator state */
  200.    int segnum;            /* current segment number */
  201.    word slotnum;        /* current slot number */
  202.    word tmask;            /* structure mask before suspension */
  203.    word sgmask[HSegs];        /* mask in use when the segment was created */
  204.    uword sghash[HSegs];        /* hashnum in process when seg was created */
  205.    };
  206.  
  207.  
  208. #ifndef FixedRegions
  209.  
  210. /*
  211.  * Information used with Icon's allocation routines with expandable-regions
  212.  *  memory management.
  213.  */
  214.  
  215. union bhead {            /* header of free block */
  216.    struct {
  217.       union bhead *ptr;     /* pointer to next free block */
  218.       uword bsize;        /* free block size */
  219.       } s;
  220.    ALIGN x;            /* force block alignment */
  221.    };
  222.  
  223. #define NALLOC 64        /* units to request at one time */
  224.  
  225. #define FREEMAGIC 0x807F    /* magic flag for free blocks (MemMon only) */
  226.  
  227. #endif                    /* FixedRegions */
  228.  
  229. /*
  230.  * Structure for chaining tended descriptors.
  231.  */
  232. struct tend_desc {
  233.    struct tend_desc *previous;
  234.    int num;
  235.    struct descrip d[1]; /* actual size of array indicated by num */
  236.    };
  237.  
  238. /*
  239.  * Structure for mapping string names of functions and operators to block
  240.  * addresses.
  241.  */
  242. struct pstrnm {
  243.    char *pstrep;
  244.    struct b_proc *pblock;
  245.    };
  246.  
  247. struct dpair {
  248.    struct descrip dr;
  249.    struct descrip dv;
  250.    };
  251.  
  252. #ifdef MultiRegion
  253. /*
  254.  * Allocated memory region structure.  Each program has linked lists of
  255.  * string and block regions.
  256.  */
  257. struct region {
  258.    word  size;                /* allocated region size in bytes */
  259.    char *base;                /* start of region */
  260.    char *end;                /* end of region */
  261.    char *free;                /* free pointer */
  262.    struct region *prev, *next;        /* forms a linked list of regions */
  263.    struct region *Gprev, *Gnext;    /* global (all programs) lists */
  264.    };
  265. #endif                    /* MultiRegion */
  266.  
  267.  
  268. #if COMPILER
  269.  
  270. /*
  271.  * Structures for the compiler.
  272.  */
  273.  
  274. struct p_frame {
  275.    struct p_frame *old_pfp;
  276.    struct descrip *old_argp;
  277.    struct descrip *rslt;
  278.    continuation succ_cont;
  279.    struct tend_desc tend;
  280.    };
  281. #endif                    /* COMPILER */
  282.  
  283. /*
  284.  * when debugging is enabled a debug struct is placed after the tended
  285.  *  descriptors in the procedure frame.
  286.  */
  287. struct debug {
  288.    struct b_proc *proc;
  289.    char *old_fname;
  290.    int old_line;
  291.    };
  292.  
  293. union numeric {            /* long integers or real numbers */
  294.    long integer;
  295.    double real;
  296.  
  297. #ifdef LargeInts
  298.    struct b_bignum *big;
  299. #endif                /* LargeInts */
  300.  
  301.    };
  302.  
  303. #if COMPILER
  304. struct b_coexpr {        /* co-expression stack block */
  305.    word title;            /*   T_Coexpr */
  306.    word size;            /*   number of results produced */
  307.    word id;            /*   identification number */
  308.    struct b_coexpr *nextstk;    /*   pointer to next allocated stack */
  309.    continuation fnc;        /*   function containing co-expression code */
  310.    struct p_frame *es_pfp;    /*   current procedure frame pointer */
  311.    dptr es_argp;        /*   current argument pointer */
  312.    struct tend_desc *es_tend;    /*   current tended pointer */
  313.    char *file_name;        /*   current file name */
  314.    word line_num;        /*   current line_number */
  315.    dptr tvalloc;        /*   where to place transmitted value */
  316.    struct descrip freshblk;    /*   refresh block pointer */
  317.    struct astkblk *es_actstk;    /*   pointer to activation stack structure */
  318.    word cstate[CStateSize];    /*   C state information */
  319.    struct p_frame pf;           /*   initial procedure frame */
  320.    };
  321.  
  322. struct b_refresh {        /* co-expression block */
  323.    word title;            /*   T_Refresh */
  324.    word blksize;        /*   size of block */
  325.    word nlocals;        /*   number of local variables */
  326.    word nargs;            /*   number of arguments */
  327.    word ntemps;                 /*   number of temporary descriptors */
  328.    word wrk_size;        /*   size of non-descriptor work area */
  329.    struct descrip elems[1];    /*   locals and arguments */
  330.    };
  331.  
  332. #else                    /* COMPILER */
  333.  
  334. /*
  335.  * Structures for the interpreter.
  336.  */
  337.  
  338. /*
  339.  * Declarations for entries in tables associating icode location with
  340.  *  source program location.
  341.  */
  342. struct ipc_fname {
  343.    word ipc;        /* offset of instruction into code region */
  344.    word fname;        /* offset of file name into string region */
  345.    };
  346.  
  347. struct ipc_line {
  348.    word ipc;        /* offset of instruction into code region */
  349.    int line;        /* line number */
  350.    };
  351.  
  352.  
  353. /*
  354.  * Frame markers
  355.  */
  356. struct ef_marker {        /* expression frame marker */
  357.    inst ef_failure;        /*   failure ipc */
  358.    struct ef_marker *ef_efp;    /*   efp */
  359.    struct gf_marker *ef_gfp;    /*   gfp */
  360.    word ef_ilevel;        /*   ilevel */
  361.    };
  362.  
  363. struct pf_marker {        /* procedure frame marker */
  364.    word pf_nargs;        /*   number of arguments */
  365.    struct pf_marker *pf_pfp;    /*   saved pfp */
  366.    struct ef_marker *pf_efp;    /*   saved efp */
  367.    struct gf_marker *pf_gfp;    /*   saved gfp */
  368.    dptr pf_argp;        /*   saved argp */
  369.    inst pf_ipc;            /*   saved ipc */
  370.    word pf_ilevel;        /*   saved ilevel */
  371.    dptr pf_scan;        /*   saved scanning environment */
  372.  
  373.  
  374.    struct descrip pf_locals[1];    /*   descriptors for locals */
  375.    };
  376.  
  377. struct gf_marker {        /* generator frame marker */
  378.    word gf_gentype;        /*   type */
  379.    struct ef_marker *gf_efp;    /*   efp */
  380.    struct gf_marker *gf_gfp;    /*   gfp */
  381.    inst gf_ipc;            /*   ipc */
  382.    struct pf_marker *gf_pfp;    /*   pfp */
  383.    dptr gf_argp;        /*   argp */
  384.    };
  385.  
  386. /*
  387.  * Generator frame marker dummy -- used only for sizing "small"
  388.  *  generator frames where procedure infomation need not be saved.
  389.  *  The first five members here *must* be identical to those for
  390.  *  gf_marker.
  391.  */
  392. struct gf_smallmarker {        /* generator frame marker */
  393.    word gf_gentype;        /*   type */
  394.    struct ef_marker *gf_efp;    /*   efp */
  395.    struct gf_marker *gf_gfp;    /*   gfp */
  396.    inst gf_ipc;            /*   ipc */
  397.    };
  398.  
  399. /*
  400.  * b_iproc blocks are used to statically initialize information about
  401.  *  functions.    They are identical to b_proc blocks except for
  402.  *  the pname field which is a sdecrip (simple/string descriptor) instead
  403.  *  of a descrip.  This is done because unions cannot be initialized.
  404.  */
  405.     
  406. struct b_iproc {        /* procedure block */
  407.    word ip_title;        /*   T_Proc */
  408.    word ip_blksize;        /*   size of block */
  409.    int (*ip_entryp)();        /*   entry point (code) */
  410.    word ip_nparam;        /*   number of parameters */
  411.    word ip_ndynam;        /*   number of dynamic locals */
  412.    word ip_nstatic;        /*   number of static locals */
  413.    word ip_fstatic;        /*   index (in global table) of first static */
  414.  
  415.  
  416.    struct sdescrip ip_pname;    /*   procedure name (string qualifier) */
  417.    struct descrip ip_lnames[1];    /*   list of local names (qualifiers) */
  418.    };
  419.  
  420. struct b_tvkywd {        /* keyword trapped variable block */
  421.    word title;            /*   T_Tvkywd */
  422.    int (*putval)();        /*   assignment function for keyword */
  423.    struct descrip kyval;    /*   keyword value */
  424.    struct descrip kyname;    /*   keyword name */
  425.    };
  426.  
  427. struct b_coexpr {        /* co-expression stack block */
  428.    word title;            /*   T_Coexpr */
  429.    word size;            /*   number of results produced */
  430.    word id;            /*   identification number */
  431.    struct b_coexpr *nextstk;    /*   pointer to next allocated stack */
  432.    struct pf_marker *es_pfp;    /*   current pfp */
  433.    struct ef_marker *es_efp;    /*   efp */
  434.    struct gf_marker *es_gfp;    /*   gfp */
  435.    struct tend_desc *es_tend;    /*   current tended pointer */
  436.    dptr es_argp;        /*   argp */
  437.    inst es_ipc;            /*   ipc */
  438.    word es_ilevel;        /*   interpreter level */
  439.    word *es_sp;            /*   sp */
  440.    dptr tvalloc;        /*   where to place transmitted value */
  441.    struct descrip freshblk;    /*   refresh block pointer */
  442.    struct astkblk *es_actstk;    /*   pointer to activation stack structure */
  443.  
  444.  
  445.    word cstate[CStateSize];    /*   C state information */
  446.    };
  447.  
  448. struct b_refresh {        /* co-expression block */
  449.    word title;            /*   T_Refresh */
  450.    word blksize;        /*   size of block */
  451.    word *ep;            /*   entry point */
  452.    word numlocals;        /*   number of locals */
  453.    struct pf_marker pfmkr;    /*   marker for enclosing procedure */
  454.    struct descrip elems[1];    /*   arguments and locals, including Arg0 */
  455.    };
  456.  
  457. #endif                    /* COMPILER */
  458.  
  459. union block {            /* general block */
  460.  
  461. #ifdef LargeInts
  462.    struct b_bignum bignumblk;
  463. #endif                    /* LargeInts */
  464.  
  465.    struct b_real realblk;
  466.    struct b_cset cset;
  467.    struct b_file file;
  468.    struct b_proc proc;
  469.    struct b_list list;
  470.    struct b_lelem lelem;
  471.    struct b_table table;
  472.    struct b_telem telem;
  473.    struct b_set set;
  474.    struct b_selem selem;
  475.    struct b_record record;
  476.  
  477. #if !COMPILER
  478.    struct b_tvkywd tvkywd;
  479. #endif                    /* COMPILER */
  480.  
  481.    struct b_tvsubs tvsubs;
  482.    struct b_tvtbl tvtbl;
  483.    struct b_refresh refresh;
  484.    struct b_coexpr coexpr;
  485.    struct b_external externl;
  486.    struct b_slots slots;
  487.    };
  488.