home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / msm-1 / icont.sit / tmem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-19  |  2.2 KB  |  94 lines  |  [TEXT/MPS ]

  1. /*
  2.  * tmem.c -- memory initialization and allocation for the translator.
  3.  */
  4.  
  5. #include "::h:gsupport.h"
  6. #include "tproto.h"
  7. #include "globals.h"
  8. #include "trans.h"
  9. #include "tsym.h"
  10. #include "tree.h"
  11.  
  12. struct tlentry **lhash;        /* hash area for local table */
  13. struct tgentry **ghash;        /* hash area for global table */
  14. struct tcentry **chash;        /* hash area for constant table */
  15.  
  16. struct tlentry *lfirst;        /* first local table entry */
  17. struct tlentry *llast;        /* last local table entry */
  18. struct tcentry *cfirst;        /* first constant table entry */
  19. struct tcentry *clast;        /* last constant table entry */
  20. struct tgentry *gfirst;        /* first global table entry */
  21. struct tgentry *glast;        /* last global table entry */
  22.  
  23. extern struct str_buf lex_sbuf;
  24.  
  25.  
  26. /*
  27.  * tmalloc - allocate memory for the translator
  28.  */
  29.  
  30. novalue tmalloc()
  31. {
  32.    chash = (struct tcentry **) tcalloc(chsize, sizeof (struct tcentry *));
  33.    ghash = (struct tgentry **) tcalloc(ghsize, sizeof (struct tgentry *));
  34.    lhash = (struct tlentry **) tcalloc(lhsize, sizeof (struct tlentry *));
  35.    init_str();
  36.    init_sbuf(&lex_sbuf);
  37.    }
  38.  
  39. /*
  40.  * meminit - clear tables for use in translating the next file
  41.  */
  42. novalue tminit()
  43.    {
  44.    register struct tlentry **lp;
  45.    register struct tgentry **gp;
  46.    register struct tcentry **cp;
  47.  
  48.    lfirst = NULL;
  49.    llast = NULL;
  50.    cfirst = NULL;
  51.    clast = NULL;
  52.    gfirst = NULL;
  53.    glast = NULL;
  54.  
  55.    /*
  56.     * Zero out the hash tables.
  57.     */
  58.    for (lp = lhash; lp < &lhash[lhsize]; lp++)
  59.       *lp = NULL;
  60.    for (gp = ghash; gp < &ghash[ghsize]; gp++)
  61.       *gp = NULL;
  62.    for (cp = chash; cp < &chash[chsize]; cp++)
  63.       *cp = NULL;
  64.    }
  65.  
  66. /*
  67.  * tmfree - free memory used by the translator
  68.  */
  69. novalue tmfree()
  70.    {
  71.    struct tgentry *gp, *gp1;
  72.  
  73. #ifndef VarTran
  74.    loc_init();            /* free constant and local table entries */
  75.  
  76.    /*
  77.     * Free global table entries.
  78.     */
  79.    for (gp = gfirst; gp != NULL; gp = gp1) {
  80.       gp1 = gp->g_next;
  81.       free((char *)gp);
  82.       }
  83.    gfirst = NULL;
  84.    glast = NULL;
  85. #endif                    /* VarTran */
  86.  
  87.    free((char *) chash);   chash = NULL;
  88.    free((char *) ghash);   ghash = NULL;
  89.    free((char *) lhash);   lhash = NULL;
  90.  
  91.    free_stbl();           /* free string table */
  92.    clear_sbuf(&lex_sbuf); /* free buffer store for strings */
  93.    }
  94.