1: #include "../h/rt.h"
   2: #include "../h/gc.h"
   3: #include "../h/record.h"
   4: 
   5: /*
   6:  * allocate - returns pointer to nbytes of free storage in heap.
   7:  */
   8: 
   9: union block *allocate(nbytes)
  10: int nbytes;
  11:    {
  12:    register unsigned fspace, *sloc;
  13: 
  14:    /*
  15:     * See if there is enough room in the heap.
  16:     */
  17:    fspace = maxheap - hpfree;
  18:    if (fspace < nbytes)
  19:       runerr(301, NULL);
  20: 
  21:    /*
  22:     * Decrement the free space in the heap by the number of bytes allocated
  23:     *  and return the address of the first byte of the allocated block.
  24:     */
  25:    sloc = (unsigned *) hpfree;
  26:    heapneed -= nbytes;
  27:    hpfree = hpfree + nbytes;
  28:    return (union block *) (sloc);
  29:    }
  30: 
  31: #ifdef LONGS
  32: /*
  33:  * alclint - allocate a long integer block in the heap.
  34:  */
  35: 
  36: struct b_int *alclint(val)
  37: long val;
  38:    {
  39:    register struct b_int *blk;
  40:    extern union block *allocate();
  41: 
  42:    blk = allocate(sizeof(struct b_int));
  43:    blk->type = T_LONGINT;
  44:    blk->intval = val;
  45:    return (blk);
  46:    }
  47: #endif LONGS
  48: /*
  49:  * alcreal - allocate a real value in the heap.
  50:  */
  51: 
  52: struct b_real *alcreal(val)
  53: double val;
  54:    {
  55:    register struct b_real *blk;
  56:    extern union block *allocate();
  57: 
  58:    blk = (struct b_real *) allocate(sizeof(struct b_real));
  59:    blk->type = T_REAL;
  60:    blk->realval = val;
  61:    return (blk);
  62:    }
  63: 
  64: /*
  65:  * alccset - allocate a cset in the heap.
  66:  */
  67: 
  68: struct b_cset *alccset()
  69:    {
  70:    register struct b_cset *blk;
  71:    register i;
  72:    extern union block *allocate();
  73: 
  74:    blk = (struct b_cset *) allocate(sizeof(struct b_cset));
  75:    blk->type = T_CSET;
  76:    /*
  77:     * Zero out the bit array.
  78:     */
  79:    for (i = 0; i < CSETSIZE; i++)
  80:      blk->bits[i] = 0;
  81:    return (blk);
  82:    }
  83: 
  84: 
  85: /*
  86:  * alcfile - allocate a file block in the heap.
  87:  */
  88: 
  89: struct b_file *alcfile(fd, status, name)
  90: FILE *fd;
  91: int status;
  92: struct descrip *name;
  93:    {
  94:    register struct b_file *blk;
  95:    extern union block *allocate();
  96: 
  97:    blk = (struct b_file *) allocate(sizeof(struct b_file));
  98:    blk->type = T_FILE;
  99:    blk->fd = fd;
 100:    blk->status = status;
 101:    blk->fname = *name;
 102:    return (blk);
 103:    }
 104: 
 105: /*
 106:  * alcrecd - allocate record with nfield fields in the heap.
 107:  */
 108: 
 109: struct b_record *alcrecd(nfields, recptr)
 110: int nfields;
 111: struct b_proc *recptr;
 112:    {
 113:    register struct b_record *blk;
 114:    register i, size;
 115:    extern union block *allocate();
 116: 
 117:    size = vsizeof(struct b_record) + nfields*sizeof(struct descrip);
 118:    blk = (struct b_record *) allocate(size);
 119:    blk->type = T_RECORD;
 120:    blk->size = size;
 121:    blk->recptr = recptr;
 122:    /*
 123:     * Assign &null to each field in the record.
 124:     */
 125:    for (i = 0; i < nfields; i++)
 126:        blk->fields[i] = nulldesc;
 127:    return (blk);
 128:    }
 129: 
 130: /*
 131:  * alclist - allocate a list header block in the heap.
 132:  */
 133: 
 134: struct b_list *alclist(size)
 135: int size;
 136:    {
 137:    register struct b_list *blk;
 138:    extern union block *allocate();
 139: 
 140:    blk = (struct b_list *) allocate(sizeof(struct b_list));
 141:    blk->type = T_LIST;
 142:    blk->cursize = size;
 143:    blk->listhead = nulldesc;
 144:    return (blk);
 145:    }
 146: 
 147: /*
 148:  * alclstb - allocate a list element block in the heap.
 149:  */
 150: 
 151: struct b_lelem *alclstb(nelem, first, nused)
 152: int nelem, first, nused;
 153:    {
 154:    register struct b_lelem *blk;
 155:    register int i, size;
 156:    extern union block *allocate();
 157: 
 158: #ifdef MAXLISTSIZE
 159:    if (nelem >= MAXLISTSIZE)
 160:       runerr(205, NULL);
 161: #endif MAXLISTSIZE
 162:    size = vsizeof(struct b_lelem)+nelem*sizeof(struct descrip);
 163:    blk = (struct b_lelem *) allocate(size);
 164:    blk->type = T_LELEM;
 165:    blk->size = size;
 166:    blk->nelem = nelem;
 167:    blk->first = first;
 168:    blk->nused = nused;
 169:    blk->listprev = nulldesc;
 170:    blk->listnext = nulldesc;
 171:    /*
 172:     * Set all elements to &null.
 173:     */
 174:    for (i = 0; i < nelem; i++)
 175:       blk->lslots[i] = nulldesc;
 176:    return (blk);
 177:    }
 178: 
 179: /*
 180:  * alctable - allocate a table header block in the heap.
 181:  */
 182: 
 183: struct b_table *alctable(def)
 184: struct descrip *def;
 185:    {
 186:    register int i;
 187:    register struct b_table *blk;
 188:    extern union block *allocate();
 189: 
 190:    blk = (struct b_table *) allocate(sizeof(struct b_table));
 191:    blk->type = T_TABLE;
 192:    blk->cursize = 0;
 193:    blk->defvalue = *def;
 194:    /*
 195:     * Zero out the buckets.
 196:     */
 197:    for (i = 0; i < NBUCKETS; i++)
 198:       blk->buckets[i] = nulldesc;
 199:    return (blk);
 200:    }
 201: /*
 202:  *  alctelem - allocate a table element block in the heap.
 203:  */
 204: 
 205: struct b_telem *alctelem()
 206:    {
 207:    register struct b_telem *blk;
 208:    extern union block *allocate();
 209: 
 210:    blk = (struct b_telem *) allocate(sizeof(struct b_telem));
 211:    blk->type = T_TELEM;
 212:    blk->hashnum = 0;
 213:    blk->blink = nulldesc;
 214:    blk->tref = nulldesc;
 215:    blk->tval = nulldesc;
 216:    return (blk);
 217:    }
 218: #ifdef SETS
 219: 
 220: /*
 221:  * alcset - allocate a set header heap block.
 222:  */
 223: 
 224: struct b_set *alcset()
 225:    {
 226:      register int i;
 227:      register struct b_set *blk;
 228:      extern union block *allocate();
 229: 
 230:      blk = (struct b_set *) allocate(sizeof(struct b_set));
 231:      blk->type = T_SET;
 232:      blk->setsize = 0;
 233:      /*
 234:       *  Zero out the buckets.
 235:       */
 236:      for (i = 0; i < NBUCKETS; i++)
 237:         blk->sbucks[i] = nulldesc;
 238:      return (blk);
 239:      }
 240: 
 241: /*
 242:  *   alcselem - allocate a set element heap block.
 243:  */
 244: 
 245: struct b_selem *alcselem(mbr,hn)
 246: int hn;
 247: struct descrip *mbr;
 248: 
 249:    { register struct b_selem *blk;
 250:      extern union block *allocate();
 251: 
 252:      blk = (struct b_selem *) allocate(sizeof(struct b_selem));
 253:      blk->type = T_SELEM;
 254:      blk->sblink = nulldesc;
 255:      blk->setmem = *mbr;
 256:      blk->hnum = hn;
 257:      return (blk);
 258:      }
 259: #endif SETS
 260: 
 261: /*
 262:  * alcsubs - allocate a substring trapped variable in heap.
 263:  */
 264: 
 265: struct b_tvsubs *alcsubs(len, pos, var)
 266: int len, pos;
 267: struct descrip *var;
 268:    {
 269:    register struct b_tvsubs *blk;
 270:    extern union block *allocate();
 271: 
 272:    blk = (struct b_tvsubs *) allocate(sizeof(struct b_tvsubs));
 273:    blk->type = T_TVSUBS;
 274:    blk->sslen = len;
 275:    blk->sspos = pos;
 276:    blk->ssvar = *var;
 277:    return (blk);
 278:    }
 279: 
 280: /*
 281:  * alctvtbl - allocate a table element trapped variable block in the heap.
 282:  */
 283: 
 284: struct b_tvtbl *alctvtbl(tbl, ref, hnum)
 285: register struct descrip *tbl, *ref;
 286: int hnum;
 287:    {
 288:    register struct b_tvtbl *blk;
 289:    extern union block *allocate();
 290: 
 291:    blk = (struct b_tvtbl *) allocate(sizeof(struct b_tvtbl));
 292:    blk->type = T_TVTBL;
 293:    blk->hashnum = hnum;
 294:    blk->tvtable = *tbl;
 295:    blk->tvtref = *ref;
 296:    blk->tvtval = nulldesc;
 297:    return (blk);
 298:    }
 299: 
 300: /*
 301:  * alcstr - allocate a string in the string space.
 302:  */
 303: 
 304: char *alcstr(s, slen)
 305: register char *s;
 306: register int slen;
 307:    {
 308:    register char *d;
 309:    char *ofree;
 310: 
 311:    /*
 312:     * See if there is enough room in the string space.
 313:     */
 314:    if (sfree + slen > estrings)
 315:       runerr(302, NULL);
 316:    strneed -= slen;
 317:    /*
 318:     * Copy the string into the string space, saving a pointer to its
 319:     *  beginning.  Note that s may be null, in which case the space is
 320:     *  still to be allocated, but nothing is to be copied into it.
 321:     */
 322:    ofree = d = sfree;
 323:    if (s != NULL) {
 324:       while (slen-- > 0)
 325:          *d++ = *s++;
 326:       }
 327:    else
 328:       d += slen;
 329:    sfree = d;
 330:    return (ofree);
 331:    }
 332: 
 333: /*
 334:  * alcestk - allocate a co-expression stack block.
 335:  */
 336: 
 337: struct b_estack *alcestk()
 338:    {
 339:    struct b_estack *ep;
 340: 
 341:    if (esfree == NULL)
 342:       syserr("no expression stack space");
 343:    /*
 344:     * Locate the start of the block.
 345:     */
 346:    ep = (struct b_estack *) (esfree +
 347:       (stksize-sizeof(struct b_estack)/WORDSIZE));
 348:    /*
 349:     * Move co-expression stack free-list pointer to next stack.
 350:     */
 351:    esfree = (int *) *esfree;
 352:    ep->type = T_ESTACK;
 353:    return (ep);
 354:    }
 355: 
 356: /*
 357:  * alceblk - allocate a co-expression heap block.
 358:  */
 359: 
 360: struct b_eblock *alceblk(entry, na, nl)
 361: int *entry, na, nl;
 362:    {
 363:    int size;
 364:    struct b_eblock *blk;
 365:    extern union block *allocate();
 366: 
 367:    size = vsizeof(struct b_eblock)+(na+nl+1)*sizeof(struct descrip);
 368:    blk = (struct b_eblock *) allocate(size);
 369:    blk->type = T_EBLOCK;
 370:    blk->size = size;
 371:    blk->ep = entry;
 372:    blk->numargs = na;
 373:    blk->numlocals = nl;
 374:    return (blk);
 375:    }

Defined functions

alccset defined in line 68; never used
alceblk defined in line 360; never used
alcestk defined in line 337; never used
alcfile defined in line 89; never used
alclint defined in line 36; used 2 times
alclist defined in line 134; used 1 times
alclstb defined in line 151; used 2 times
alcreal defined in line 52; used 2 times
alcrecd defined in line 109; never used
alcselem defined in line 245; never used
alcset defined in line 224; never used
alcstr defined in line 304; used 7 times
alcsubs defined in line 265; used 2 times
alctable defined in line 183; never used
alctelem defined in line 205; never used
alctvtbl defined in line 284; never used
allocate defined in line 9; used 28 times
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1517
Valid CSS Valid XHTML 1.0 Strict