home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / fp / ifp_unix.lzh / ifp / interp / alloc.c next >
Encoding:
C/C++ Source or Header  |  1989-05-23  |  5.2 KB  |  195 lines

  1.  
  2. /****** alloc.c *******************************************************/
  3. /**                                                                  **/
  4. /**                    University of Illinois                        **/
  5. /**                                                                  **/
  6. /**                Department of Computer Science                    **/
  7. /**                                                                  **/
  8. /**   Tool: IFP                         Version: 0.5                 **/
  9. /**                                                                  **/
  10. /**   Author:  Arch D. Robison          Date:   May 1, 1985          **/
  11. /**                                                                  **/
  12. /**   Revised by: Arch D. Robison       Date:   Dec 2, 1985          **/
  13. /**                                                                  **/
  14. /**   Principal Investigators: Prof. R. H. Campbell                  **/
  15. /**                            Prof. W. J. Kubitz                    **/
  16. /**                                                                  **/
  17. /**                                                                  **/
  18. /**------------------------------------------------------------------**/
  19. /**   (C) Copyright 1987  University of Illinois Board of Trustees   **/
  20. /**                       All Rights Reserved.                       **/
  21. /**********************************************************************/
  22.  
  23. #include <stdio.h>
  24. #include "struct.h"
  25. #include "node.h"
  26. #include "umax.h"
  27.  
  28. /*
  29.  * Storage is divided into 4 classes:
  30.  *
  31.  *      free storage
  32.  *      list cells
  33.  *      strings
  34.  *      nodes descriptors 
  35.  *  
  36.  * Storage is allocated by pages.
  37.  */
  38.  
  39. /*
  40.  * Currently, the page table and descriptors don't do anything,
  41.  * so we define them out of existence.  Their intended use t is to allow
  42.  * reclamation of pages.
  43.  */
  44.  
  45. #define PAGETABLE 0
  46.  
  47. #if PAGETABLE
  48.  
  49. #define FreePage 0     /* Defines for PageType field of PageDesc structure */
  50. #define ListPage 1
  51. #define StrPage 2
  52. #define NodePage 3
  53.  
  54. typedef struct {
  55.    char PageType;       /* Type of page.  See defines above */
  56.    char *PageBase;      /* Base address of page             */
  57.    unsigned PageLen;    /* Length of page in bytes          */
  58. } PageDesc;
  59.  
  60. PageDesc PageTable [MaxPages];
  61.  
  62. int PageCount=0;
  63.  
  64. #endif /* PAGETABLE */
  65.  
  66. #if (OPSYS==UNIX || OPSYS==CTSS) 
  67. #define MaxPages 256
  68. #define SizeListPage (512 * sizeof (ListCell))
  69. #define SizeStrPage  (512 * sizeof (StrCell))
  70. #define SizeNodePage (256 * sizeof (NodeDesc))
  71. #endif                   
  72.  
  73. #if OPSYS==MSDOS || OPSYS==APPLE
  74. #define MaxPages 128
  75. #define SizeListPage (256 * sizeof (ListCell))
  76. #define SizeStrPage  (256 * sizeof (StrCell))
  77. #define SizeNodePage (128 * sizeof (NodeDesc))
  78. #endif
  79.  
  80. /*
  81.  * AllocListPage
  82.  *
  83.  * Returns pointer to list of cells in new list page.
  84.  * Each cell's value is initialized to NULL.
  85.  *
  86.  * NULL is returned if there are no more list pages available.
  87.  */
  88. ListPtr AllocListPage ()
  89.    {
  90. #if PAGETABLE
  91.       register PageDesc *PDp;
  92. #endif
  93.       register ListPtr P;
  94.       register int K;
  95.  
  96.       if (Debug & DebugAlloc) {
  97.          LineWait ();
  98.          printf ("AllocListPage ()\n");
  99.          LineSignal ();
  100.       }
  101. #if PAGETABLE
  102.       if (PageCount >= MaxPages) return NULL;
  103. #endif
  104.       P = (ListPtr) malloc (SizeListPage);
  105.       if (P == NULL) return NULL;
  106. #if PAGETABLE
  107.       PDp = PageTable + PageCount++;
  108.       PDp->PageType = ListPage;
  109.       PDp->PageLen = SizeListPage;
  110.       PDp->PageBase = (char *) P;
  111. #endif
  112.       P->Next = NULL;
  113.       for (K = SizeListPage/(sizeof (ListCell));;) {
  114.      P->LRef = LRefOne;
  115.      P->Val.Tag = BOTTOM;
  116.      if (!--K) break;
  117.      P++;
  118.      P->Next = P-1;
  119.       }
  120.       return P; 
  121.    }
  122.  
  123.  
  124. StrPtr AllocStrPage ()
  125.    {
  126. #if PAGETABLE
  127.       register PageDesc *PDp;
  128. #endif
  129.       register StrPtr P;
  130.       register int K;
  131.  
  132.       if (Debug & DebugAlloc) printf ("AllocStrPage ()\n");
  133. #if PAGETABLE
  134.       if (PageCount >= MaxPages) return NULL;
  135. #endif
  136.       P = (StrPtr) malloc (SizeStrPage);
  137.       if (P == NULL) return NULL;
  138. #if PAGETABLE
  139.       PDp = PageTable + PageCount++;
  140.       PDp->PageType = StrPage;
  141.       PDp->PageLen = SizeStrPage;
  142.       PDp->PageBase = (char *) P;
  143.       PDp = PageTable + PageCount++;
  144. #endif
  145.       P->StrNext = NULL;
  146.       for (K = SizeStrPage/(sizeof (StrCell));;) {
  147.      P->StrChar [0] = '\0';
  148.      P->SRef = 1;
  149.      if (!--K) break;
  150.      P++;
  151.      P->StrNext = P-1;
  152.       }
  153.       return P;
  154.    }
  155.  
  156.  
  157. /*
  158.  * AllocNodePage
  159.  *
  160.  * Returns pointer to list of nodes in new node page.
  161.  */
  162. NodePtr AllocNodePage ()
  163.    {
  164. #if PAGETABLE
  165.       register PageDesc *PDp;
  166. #endif
  167.       register NodePtr P;
  168.       register int K;
  169.  
  170.       if (Debug & DebugAlloc) printf ("AllocNodePage ()\n");
  171. #if PAGETABLE
  172.       if (PageCount >= MaxPages) return NULL;
  173. #endif
  174.       P = (NodePtr) malloc (SizeNodePage);
  175.       if (P == NULL) return NULL;
  176. #if PAGETABLE
  177.       PDp = PageTable + PageCount++;
  178.       PDp->PageType = NodePage;
  179.       PDp->PageLen = SizeNodePage;
  180.       PDp->PageBase = (char *) P;
  181.       PDp = PageTable + PageCount++;
  182. #endif
  183.       P->NodeSib = NULL;
  184.       for (K = SizeNodePage/(sizeof (NodeDesc));;) {
  185.      P->NRef = 1;
  186.      if (!--K) break;
  187.      P++;
  188.      P->NodeSib = P-1;
  189.       };
  190.       return P; 
  191.    }
  192.  
  193. /************************** end of alloc.c **************************/
  194.  
  195.