2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
9 static char rcs_id[] = "$Id: symbols.c,v 1.3 1994/06/24 11:31:09 ceriel Exp $" ;
12 /* Symboltable management module */
14 int deftype[128]; /* default type declarer */
15 /* which may be set by OPTION BASE */
22 for(i='a';i<='z';i++) deftype[i]= DOUBLETYPE;
23 for(i='A';i<='Z';i++) deftype[i]= DOUBLETYPE;
27 int indexbase=0; /* start of array subscripting */
29 Symbol *firstsym = NIL;
30 Symbol *alternate = NIL;
34 Symbol *srchsymbol(str)
39 /* search symbol table entry or create it */
40 if (debug) print("srchsymbol %s\n",str);
45 if ( strcmp(s->symname,str)==0) return(s);
49 /* search alternate list */
54 if ( strcmp(s->symname,str)==0) return(s);
58 /* not found, create an empty slot */
59 s = (Symbol *) salloc(sizeof(Symbol));
60 s->symtype= DEFAULTTYPE;
62 s->symname= (char *) salloc((unsigned) strlen(str)+1);
63 strcpy(s->symname,str);
65 if (debug) print("%s allocated\n",str);
77 if ( s->isparam) return;
79 if (type==DEFAULTTYPE)
80 /* use the default rule */
81 type= deftype[*s->symname];
82 /* generate the emlabel too */
84 s->symalias= dclspace(type);
86 if (debug) print("symbol set to %d\n",type);
96 if ( s->symtype==DEFAULTTYPE) s->symtype= DOUBLETYPE;
97 if (debug) print("generate space and descriptors for %d\n",s->symtype);
98 if (debug) print("dim %d\n",s->dimensions);
99 s->symalias= genlabel();
100 /* generate descriptors */
103 for(i=0;i<s->dimensions;i++) {
104 s->dimalias[i]= genlabel();
107 for(i=s->dimensions-1;i>=0;i--)
109 C_df_dlb((label)(s->dimalias[i]));
110 C_rom_cst((arith)indexbase);
111 C_rom_cst((arith)(s->dimlimit[i]-indexbase));
112 C_rom_cst((arith)(size*typesize(s->symtype)));
113 size = size* (s->dimlimit[i]+1-indexbase);
116 if (debug) print("size=%d\n",size);
118 C_df_dlb((label)s->symalias);
119 get_space(s->symtype,size); /* Van ons. */
130 C_bss_cst((arith)BEMINTSIZE*size,
136 C_bss_fcon((arith)BEMFLTSIZE*size,
141 case STRINGTYPE: /* Note: this is ugly. Gertjan */
142 C_bss_icon((arith)BEMPTRSIZE*size,
148 error("Space allocated for unknown type. Coredump.");
149 abort(); /* For debugging purposes */
158 /* array is used without dim statement, set default limits */
160 for(i=0;i<s->dimensions;i++) s->dimlimit[i]=10;
175 C_bss_icon((arith)BEMPTRSIZE,"0",(arith)BEMPTRSIZE,1);
178 C_bss_cst((arith)BEMINTSIZE,(arith)0,1);
182 C_bss_fcon((arith)BEMFLTSIZE,"0.0",(arith)BEMFLTSIZE,1);
190 /* SOME COMPILE TIME OPTIONS */
194 if ( ival<0 || ival>1)
195 error("illegal option base value");
207 /* handcrafted parser for letter ranges */
208 if (debug) print("deftype:%s\n",cptr);
209 while ( isspace(*cptr)) cptr++;
210 if ( !isalpha(*cptr))
211 error("letter expected");
219 error("letter expected");
220 else for(i=first;i<=last;i++) deftype[i]= type;
222 } else deftype[first]=type;
226 setdefaulttype(type); /* try again */
238 if (debug) print("new scope for %s\n",s->symname);
243 if ( fcn->dimensions)
244 error("Array redeclared");
245 if ( fcn->symtype== DEFAULTTYPE)
246 fcn->symtype=DOUBLETYPE;
251 /* User defined functions */
259 (void) sprint(procname,"_%s",fcn->symname);
260 C_pro_narg(procname);
261 if ( fcn->symtype== DEFAULTTYPE)
262 fcn->symtype= DOUBLETYPE;
269 /* generate portable function size */
270 int i,sum; /* sum is NEW */
273 for(i=0;i<fcn->dimensions;i++)
274 sum += typesize(fcn->dimlimit[i]);
285 if ( debug) print("endscope");
286 conversion(type,fcn->symtype);
287 C_ret((arith) typestring(fcn->symtype));
288 /* generate portable EM code */
289 C_end( (arith)fcnsize() );
294 firstsym = s->nextsym;
295 (void) free((char *)s);
311 if ( s->symtype== DEFAULTTYPE)
312 s->symtype= DOUBLETYPE;
314 fcn->dimlimit[fcn->dimensions]= s->symtype;
316 s->symalias= -fcn->dimensions;
317 if ( debug) print("parameter %d offset %d\n",fcn->dimensions-1,-size);
322 /* unfortunately function calls have to be stacked as well */
323 #define MAXNESTING 50
324 Symbol *fcntable[MAXNESTING];
333 error("Function not declared");
337 fcntable[fcnindex]=s;
348 static char concatbuf[50]; /* NEW */
350 /* check number of arguments */
351 if ( parmcount <fcn->dimensions)
352 error("not enough parameters");
353 if ( parmcount >fcn->dimensions)
354 error("too many parameters");
355 (void) sprint(concatbuf,"_%s",fcn->symname);
357 C_asp((arith)fcnsize());
358 C_lfr((arith) typestring(fcn->symtype));
362 fcn= fcntable[fcnindex];
371 if ( fcnindex<0) error("unexpected parameter");
372 if ( ind >= fcn->dimensions)
373 error("too many parameters");
375 conversion(type,fcn->dimlimit[ind]);