Annotation of researchv10no/cmd/basic/bite/src/variable.c, revision 1.1.1.1

1.1       root        1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
                      2: 
                      3:  *     /////////////////////////////////////
                      4:  *     /////////////////////////////////////
                      5:  *     //////////// variable.c /////////////
                      6:  *     /// J. P. Hawkins WH X4610 8C-001 ///
                      7:  *     ///// Fri Aug 24 17:00:44 1979 //////
                      8:  *     /////////////////////////////////////
                      9:  *     /////////////////////////////////////
                     10: 
                     11:  *
                     12:  * Variable Allocation and Fetch routines
                     13:  * For BITE
                     14:  *
                     15:  */
                     16: /*   "@(#) variable.c:  V 1.2  3/4/81" */
                     17: #include       "bas.h"
                     18: union VARIABLE varbyts;
                     19: /*
                     20:  * this is the symbol table (table of pointers) for numerical
                     21:  * variables. The first subscript 'j' is calculated by the
                     22:  * alpha name, the second subscript 'k' is calculated by the
                     23:  * numeric part + 1. If no numeric is specified, k = 0
                     24:  */
                     25: char   *hicore;        /* pointer lowest used corespace from
                     26:                                    top of user area */
                     27: 
                     28: 
                     29: /*
                     30:  * //////// FETCH VALUE OF VARIABLE ////////
                     31:  *
                     32:  * calling format:
                     33:  *
                     34:  *     getvar(vstr, &value);
                     35:  *
                     36:  *     where: vstr = string containing VALID variable name
                     37:  *                     i.e. [a-z] or a[0-9] - z[0-9]
                     38:  *            float value = where actual value is returned to
                     39:  */
                     40: getvar(vstr,valptr)
                     41: char   vstr[];
                     42: double *valptr;
                     43: {
                     44:        int     j,k;    /* symbol table indicies */
                     45:        register char i;        /* index to float bytes */
                     46:        register char *ptr;     /* pointer register used to copy bytes */
                     47: 
                     48:        j = vstr[0] - 'a';      /* compute j subscript */
                     49: 
                     50:        /*
                     51:         * compute k subscript
                     52:         */
                     53:        if(vstr[1] == '\0')     /* if no numeric part */
                     54:                k = 0;          /* then k = 0th column */
                     55:        else
                     56:                k = vstr[1] - '0' + 1; /* use numeric + 1th column */
                     57: 
                     58:        if(symtab[j][k] == 0)   /*if no pointer for this variable */
                     59:                                /*  (not allocated, yet) */
                     60:        {
                     61:                error2(inst.thing.linno,7,' '); /* UNNASSIGNED VARIABLE */
                     62:                printf("- '%s'\n",vstr); /* print variable name */
                     63:                *valptr = 0.0;          /* return zero anyway */
                     64:                return(-1);
                     65:        }
                     66:        else
                     67:        {
                     68:                ptr = symtab[j][k]; /* set byte copy ptr to data location */
                     69: 
                     70:                for(i=PREC-1; i >= 0; --i) /* copy the float byte-by byte */
                     71:                        varbyts.var4th[i] = *--ptr;
                     72: 
                     73:                *valptr = varbyts.var;  /* now pass the value back to
                     74:                                            the calling routine */
                     75:        }
                     76:        return(0);
                     77: }
                     78: /*
                     79:  *
                     80:  * //// ASSIGN A VALUE TO A VARIABLE ////
                     81:  * /////// ALLOCATE SPACE IF NEC. ///////
                     82:  *
                     83:  * put the value into the allocated location.
                     84:  * allocate a location if not already allocated
                     85:  * calling format:
                     86:  *
                     87:  *     putvar(vstr, value);
                     88:  *
                     89:  *     where: vstr = string pointer to VALID variable name
                     90:  *            value = value to be assigned
                     91:  */
                     92: putvar(vstr,value)
                     93: char   vstr[];         /* valid variable string (name) */
                     94: double value;          /* value to be assigned */
                     95: {
                     96:        register char *ptr;     /* pointer register used to copy bytes */
                     97:        register char i;        /* index to float bytes */
                     98:        int     j,k;    /* symbol table indicies */
                     99: 
                    100:        j = vstr[0] - 'a';      /* compute j subscript */
                    101: 
                    102:        /*
                    103:         * compute k subscript
                    104:         */
                    105:        if(vstr[1] == '\0')     /* if no numeric part */
                    106:                k = 0;          /* then k = 0th column */
                    107:        else
                    108:                k = vstr[1] - '0' + 1;
                    109: 
                    110:        varbyts.var = value;    /* stuff the float number (2 words)
                    111:                                    in the float template to be copied
                    112:                                     into data area byte-by-byte */
                    113:        if(symtab[j][k] == 0)   /* if no space yet allocated */
                    114:                alloc(&symtab[j][k], PREC); /* then allocate space and
                    115:                                             return pointer to symbol tab */
                    116:        ptr = symtab[j][k];     /* set copy register to data address */
                    117: 
                    118:        for(i=PREC-1; i>=0; --i)        /* copy into storage byte-by-byte */
                    119:                *--ptr = varbyts.var4th[i];
                    120: }
                    121: /*
                    122:  *
                    123:  * //// INITIALIZE VARIABLES ////
                    124:  */
                    125: initvar()
                    126: {
                    127:        extern char     txtbuf[];
                    128:        hicore = &txtbuf[PGSIZ*NMPAG];  /* init pointer to top of user
                    129:                                            data space */
                    130: }
                    131: /*
                    132:  *
                    133:  * //// ALLOCATE STORAGE FOR SPECIFIED BYTES ////
                    134:  * return starting address of allocated space
                    135:  *
                    136:  * The data area is a TOP-DOWN allocation technique which follows
                    137:  * rules that are inverse to BOTTOM-UP allocation or storage.
                    138:  * The address of a datum is actually the address of the next higher
                    139:  * core byte. When data is retrieved or stored, a pointer to that address
                    140:  * is obtained, then each byte is retrieved or stored by first
                    141:  * decrementing the pointer, THEN retrieving or inserting the byte in
                    142:  * quiestion. Unlike bottom-up storage, the beginning of the area
                    143:  * is always one address above-it and the end of the area is the last
                    144:  * byte stored.
                    145:  * In a bottom-up storage the beginning of data IS the first byte
                    146:  * and the end of the area or piece of data or entire data area is
                    147:  * AFTER the end of the data area or datum.
                    148:  * These rules are consistant with the hardware of the PDP-11
                    149:  * albeit auto-increment/decrement data retrieval and takes maximum
                    150:  * advantage of the harware, thus producing the least amount of code.
                    151:  *
                    152:  * If these rules are adhered to at all times, there will be no error
                    153:  * in data storage or retrieval.
                    154:  *
                    155:  * In light of the above, the value 'hicore' reflects the last byte
                    156:  * occupied by the top-down storage area/txtbuf/stack or whatever.
                    157:  */
                    158: alloc(datadr, numbyts)
                    159: char   **datadr;       /* pointer to symbol table entry */
                    160: int    numbyts;        /* number of bytes to be allocated */
                    161: {
                    162:                *datadr = hicore; /* set symtab entry to loc of data */
                    163:                hicore -= numbyts; /* bump down pointer to point to
                    164:                                       lowest occupied data space */
                    165: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.