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 / iconc / cmem.c < prev    next >
C/C++ Source or Header  |  1996-03-22  |  3KB  |  115 lines

  1. /*
  2.  * cmem.c -- memory initialization and allocation for the translator.
  3.  */
  4. #include "::h:gsupport.h"
  5. #include "cglobals.h"
  6. #include "ctrans.h"
  7. #include "csym.h"
  8. #include "ctree.h"
  9. #include "ccode.h"
  10. #include "cproto.h"
  11.  
  12. struct centry *chash[CHSize];        /* hash area for constant table */
  13. struct fentry *fhash[FHSize];        /* hash area for field table */
  14. struct gentry *ghash[GHSize];        /* hash area for global table */
  15.  
  16. struct implement *bhash[IHSize];    /* hash area for built-in functions */
  17. struct implement *khash[IHSize];    /* hash area for keywords */
  18. struct implement *ohash[IHSize];    /* hash area for operators */
  19.  
  20. struct implement *spec_op[NumSpecOp];    /* table of ops with special syntax */
  21.  
  22. char pre[PrfxSz] = {'0', '0', '0'};     /* initial function name prefix */
  23.  
  24. extern struct str_buf lex_sbuf;
  25.  
  26.  
  27. /*
  28.  * init - initialize memory for the translator
  29.  */
  30.  
  31. novalue init()
  32. {
  33.    int i;
  34.  
  35.    init_str();
  36.    init_sbuf(&lex_sbuf);
  37.  
  38.    /*
  39.     * Zero out the hash tables.
  40.     */
  41.    for (i = 0; i < CHSize; i++)
  42.       chash[i] = NULL;
  43.    for (i = 0; i < FHSize; i++)
  44.       fhash[i] = NULL;
  45.    for (i = 0; i < GHSize; i++)
  46.       ghash[i] = NULL;
  47.    for (i = 0; i < IHSize; i++) {
  48.       bhash[i] = NULL;
  49.       khash[i] = NULL;
  50.       ohash[i] = NULL;
  51.       }
  52.  
  53.    /*
  54.     * Clear table of operators with non-standard operator syntax.
  55.     */
  56.    for (i = 0; i < NumSpecOp; ++i)
  57.       spec_op[i] = NULL;
  58.    }
  59.  
  60. /*
  61.  * init_proc - add a new entry on front of procedure list.
  62.  */
  63. novalue init_proc(name)
  64. char *name;
  65.    {
  66.    register struct pentry *p;
  67.    int i;
  68.    struct gentry *sym_ent;
  69.  
  70.    p = NewStruct(pentry);
  71.    p->name = name;
  72.    nxt_pre(p->prefix, pre, PrfxSz);
  73.    p->prefix[PrfxSz] = '\0';
  74.    p->nargs = 0;
  75.    p->args = NULL;
  76.    p->ndynam = 0;
  77.    p->dynams = NULL;
  78.    p->nstatic = 0;
  79.    p->has_coexpr = 0;
  80.    p->statics = NULL;
  81.    p->ret_flag = DoesRet | DoesFail | DoesSusp; /* start out pessimistic */
  82.    p->arg_lst = 0;
  83.    p->lhash = 
  84.      (struct lentry **)alloc((unsigned int)((LHSize)*sizeof(struct lentry *)));
  85.    for (i = 0; i < LHSize; i++)
  86.       p->lhash[i] = NULL;
  87.    p->next = proc_lst;
  88.    proc_lst = p;
  89.    sym_ent = instl_p(name, F_Proc);
  90.    sym_ent->val.proc = proc_lst;
  91.    }
  92.  
  93. /*
  94.  * init_rec - add a new entry on the front of the record list.
  95.  */
  96. novalue init_rec(name)
  97. char *name;
  98.    {
  99.    register struct rentry *r;
  100.    struct gentry *sym_ent;
  101.    static int rec_num = 0;
  102.  
  103.    r = NewStruct(rentry);
  104.    r->name = name;
  105.    nxt_pre(r->prefix, pre, PrfxSz);
  106.    r->prefix[PrfxSz] = '\0';
  107.    r->rec_num = rec_num++;
  108.    r->nfields = 0;
  109.    r->fields = NULL;
  110.    r->next = rec_lst;
  111.    rec_lst = r;
  112.    sym_ent= instl_p(name, F_Record);
  113.    sym_ent->val.rec = r;
  114.    }
  115.