18 |
|
* 11/16/88 Added VARDEF structure for hard linking. |
19 |
|
* |
20 |
|
* 5/31/90 Added conditional compile (REDEFW) for redefinition warning. |
21 |
+ |
* |
22 |
+ |
* 4/23/91 Added ':' defines for constant expressions (RCONST) |
23 |
|
*/ |
24 |
|
|
25 |
|
#include <stdio.h> |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
< |
varset(vname, val) /* set a variable's value */ |
110 |
> |
varset(vname, assign, val) /* set a variable's value */ |
111 |
|
char *vname; |
112 |
+ |
int assign; |
113 |
|
double val; |
114 |
|
{ |
115 |
|
register EPNODE *ep1, *ep2; |
118 |
|
ep2 = ep1->v.kid->sibling; |
119 |
|
if (ep2->type == NUM) { |
120 |
|
ep2->v.num = val; |
121 |
+ |
ep1->type = assign; |
122 |
|
return; |
123 |
|
} |
124 |
|
} |
125 |
|
/* hand build definition */ |
126 |
|
ep1 = newnode(); |
127 |
< |
ep1->type = '='; |
127 |
> |
ep1->type = assign; |
128 |
|
ep2 = newnode(); |
129 |
|
ep2->type = SYM; |
130 |
|
ep2->v.name = savestr(vname); |
133 |
|
ep2->type = NUM; |
134 |
|
ep2->v.num = val; |
135 |
|
addekid(ep1, ep2); |
136 |
< |
dclear(vname); |
136 |
> |
dremove(vname); |
137 |
|
dpush(ep1); |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
< |
dclear(name) /* delete all definitions of name */ |
141 |
> |
dclear(name) /* delete variable definitions of name */ |
142 |
|
char *name; |
143 |
|
{ |
144 |
|
register EPNODE *ep; |
145 |
|
|
146 |
+ |
while ((ep = dpop(name)) != NULL) { |
147 |
+ |
if (ep->type == ':') { |
148 |
+ |
dpush(ep); /* don't clear constants */ |
149 |
+ |
return; |
150 |
+ |
} |
151 |
+ |
epfree(ep); |
152 |
+ |
} |
153 |
+ |
} |
154 |
+ |
|
155 |
+ |
|
156 |
+ |
dremove(name) /* delete all definitions of name */ |
157 |
+ |
char *name; |
158 |
+ |
{ |
159 |
+ |
register EPNODE *ep; |
160 |
+ |
|
161 |
|
while ((ep = dpop(name)) != NULL) |
162 |
|
epfree(ep); |
163 |
|
} |
193 |
|
|
194 |
|
for (i = 0; i < NHASH; i++) |
195 |
|
for (vp = hashtbl[i]; vp != NULL; vp = vp->next) |
196 |
< |
dclear(vp->name); |
196 |
> |
dremove(vp->name); |
197 |
|
#ifdef OUTCHAN |
198 |
|
for (ep = outchan; ep != NULL; ep = ep->sibling) |
199 |
|
epfree(ep); |
387 |
|
ep = getdefn(); |
388 |
|
#ifdef REDEFW |
389 |
|
if (dlookup(dname(ep)) != NULL) { |
390 |
< |
dclear(dname(ep)); |
391 |
< |
wputs(dname(ep)); |
390 |
> |
dclear(dname(ep)); |
391 |
> |
wputs(dname(ep)); |
392 |
> |
if (dlookup(dname(ep)) == NULL) |
393 |
|
wputs(": redefined\n"); |
394 |
+ |
else |
395 |
+ |
wputs(": redefined constant expression\n"); |
396 |
|
} |
397 |
+ |
#ifdef FUNCTION |
398 |
+ |
else if (ep->v.kid->type == FUNC && |
399 |
+ |
liblookup(ep->v.kid->v.kid->v.name) != NULL) { |
400 |
+ |
wputs(ep->v.kid->v.kid->v.name); |
401 |
+ |
wputs(": redefined library function\n"); |
402 |
+ |
} |
403 |
+ |
#endif |
404 |
|
#else |
405 |
|
dclear(dname(ep)); |
406 |
|
#endif |
416 |
|
|
417 |
|
EPNODE * |
418 |
|
getdefn() /* A -> SYM = E1 */ |
419 |
+ |
/* SYM : E1 */ |
420 |
|
/* FUNC(SYM,..) = E1 */ |
421 |
+ |
/* FUNC(SYM,..) : E1 */ |
422 |
|
{ |
423 |
|
register EPNODE *ep1, *ep2; |
424 |
|
|
452 |
|
curfunc = NULL; |
453 |
|
#endif |
454 |
|
|
455 |
< |
if (nextc != '=') |
456 |
< |
syntax("'=' expected"); |
426 |
< |
scan(); |
455 |
> |
if (nextc != '=' && nextc != ':') |
456 |
> |
syntax("'=' or ':' expected"); |
457 |
|
|
458 |
|
ep2 = newnode(); |
459 |
< |
ep2->type = '='; |
459 |
> |
ep2->type = nextc; |
460 |
> |
scan(); |
461 |
|
addekid(ep2, ep1); |
462 |
+ |
#ifdef RCONST |
463 |
+ |
if ( |
464 |
+ |
#ifdef FUNCTION |
465 |
+ |
ep1->type == SYM && |
466 |
+ |
#endif |
467 |
+ |
ep2->type == ':') |
468 |
+ |
addekid(ep2, rconst(getE1())); |
469 |
+ |
else |
470 |
+ |
#endif |
471 |
|
addekid(ep2, getE1()); |
472 |
|
|
473 |
|
if ( |
539 |
|
return(ep1->v.num); /* return if number */ |
540 |
|
ep2 = ep1->sibling; /* check time */ |
541 |
|
if (ep2->v.tick < 0 || ep2->v.tick < eclock) { |
542 |
< |
ep2->v.tick = eclock; |
542 |
> |
ep2->v.tick = d->type == ':' ? 1L<<30 : eclock; |
543 |
|
ep2 = ep2->sibling; |
544 |
|
ep2->v.num = evalue(ep1); /* needs new value */ |
545 |
|
} else |