27 |
|
|
28 |
|
#include "copyright.h" |
29 |
|
|
30 |
– |
#include <stdio.h> |
31 |
– |
#include <string.h> |
30 |
|
#include <ctype.h> |
31 |
|
|
32 |
|
#include "rterror.h" |
58 |
|
static EPNODE *ochpos; /* ...dnext */ |
59 |
|
static EPNODE *outchan; |
60 |
|
|
61 |
+ |
static int optimized = 0; /* are we optimized? */ |
62 |
+ |
|
63 |
|
EPNODE *curfunc = NULL; |
64 |
– |
#define dname(ep) ((ep)->v.kid->type == SYM ? \ |
65 |
– |
(ep)->v.kid->v.name : \ |
66 |
– |
(ep)->v.kid->v.kid->v.name) |
64 |
|
|
65 |
|
|
66 |
|
void |
77 |
|
eputs(": cannot open\n"); |
78 |
|
quit(1); |
79 |
|
} |
80 |
< |
initfile(fp, fname, 0); |
80 |
> |
#ifdef getc_unlocked /* avoid stupid semaphores */ |
81 |
> |
flockfile(fp); |
82 |
> |
#endif |
83 |
> |
initfile(fp, fname, 0); |
84 |
|
while (nextc != EOF) |
85 |
|
getstatement(); |
86 |
|
if (fname != NULL) |
87 |
|
fclose(fp); |
88 |
+ |
#ifdef getc_unlocked |
89 |
+ |
else |
90 |
+ |
funlockfile(fp); |
91 |
+ |
#endif |
92 |
|
} |
93 |
|
|
94 |
|
|
177 |
|
char *name |
178 |
|
) |
179 |
|
{ |
180 |
< |
EPNODE *ep; |
180 |
> |
VARDEF *vp; |
181 |
> |
EPNODE *dp; |
182 |
|
|
183 |
< |
while ((ep = dpop(name)) != NULL) { |
184 |
< |
if (ep->type == ':') { |
185 |
< |
dpush(name, ep); /* don't clear constants */ |
186 |
< |
return; |
187 |
< |
} |
183 |
< |
epfree(ep); |
183 |
> |
while ((vp = varlookup(name)) != NULL && |
184 |
> |
(dp = vp->def) != NULL && dp->type == '=') { |
185 |
> |
vp->def = dp->sibling; |
186 |
> |
epfree(dp,1); |
187 |
> |
varfree(vp); |
188 |
|
} |
189 |
|
} |
190 |
|
|
197 |
|
EPNODE *ep; |
198 |
|
|
199 |
|
while ((ep = dpop(name)) != NULL) |
200 |
< |
epfree(ep); |
200 |
> |
epfree(ep,1); |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
|
int |
205 |
< |
vardefined( /* return non-zero if variable defined */ |
205 |
> |
vardefined( /* return '=' or ':' if variable/constant defined */ |
206 |
|
char *name |
207 |
|
) |
208 |
|
{ |
209 |
< |
EPNODE *dp; |
209 |
> |
EPNODE *dp = dlookup(name); |
210 |
|
|
211 |
< |
return((dp = dlookup(name)) != NULL && dp->v.kid->type == SYM); |
211 |
> |
if (dp == NULL || dp->v.kid->type != SYM) |
212 |
> |
return(0); |
213 |
> |
|
214 |
> |
return(dp->type); |
215 |
|
} |
216 |
|
|
217 |
|
|
218 |
|
char * |
219 |
< |
setcontext( /* set a new context path */ |
219 |
> |
calcontext( /* set a new context path */ |
220 |
|
char *ctx |
221 |
|
) |
222 |
|
{ |
257 |
|
int n; |
258 |
|
|
259 |
|
strcpy(oldcontext, context); /* save old context */ |
260 |
< |
setcontext(ctx); /* set new context */ |
260 |
> |
calcontext(ctx); /* set new context */ |
261 |
|
n = strlen(context); /* tack on old */ |
262 |
|
if (n+strlen(oldcontext) > MAXCNTX) { |
263 |
|
strncpy(context+n, oldcontext, MAXCNTX-n); |
294 |
|
static char nambuf[RMAXWORD+1]; |
295 |
|
char *cp = nambuf, *cpp; |
296 |
|
/* check for explicit local */ |
297 |
< |
if (*nam == CNTXMARK) |
297 |
> |
if (*nam == CNTXMARK) { |
298 |
|
if (lvl > 0) /* only action is to refuse search */ |
299 |
|
return(NULL); |
300 |
< |
else |
301 |
< |
nam++; |
295 |
< |
else if (nam == nambuf) /* check for repeat call */ |
300 |
> |
nam++; |
301 |
> |
} else if (nam == nambuf) /* check for repeat call */ |
302 |
|
return(lvl > 0 ? NULL : nam); |
303 |
|
/* copy name to static buffer */ |
304 |
|
while (*nam) { |
320 |
|
while (*++cpp && *cpp != CNTXMARK) |
321 |
|
; |
322 |
|
} |
323 |
< |
while (*cpp) { /* copy context to static buffer */ |
323 |
> |
while (*cpp) { /* add remaining context to name */ |
324 |
|
if (cp >= nambuf+RMAXWORD) |
325 |
|
goto toolong; |
326 |
|
*cp++ = *cpp++; |
358 |
|
|
359 |
|
|
360 |
|
void |
361 |
+ |
doptimize(int activate) /* optimize current and future definitions? */ |
362 |
+ |
{ |
363 |
+ |
EPNODE *ep; |
364 |
+ |
|
365 |
+ |
if (activate && optimized) |
366 |
+ |
return; /* already going */ |
367 |
+ |
|
368 |
+ |
if (!(optimized = activate)) |
369 |
+ |
return; /* switching off */ |
370 |
+ |
|
371 |
+ |
for (ep = dfirst(); ep != NULL; ep = dnext()) |
372 |
+ |
epoptimize(ep); |
373 |
+ |
} |
374 |
+ |
|
375 |
+ |
|
376 |
+ |
void |
377 |
|
dcleanup( /* clear definitions (0->vars,1->output,2->consts) */ |
378 |
|
int lvl |
379 |
|
) |
390 |
|
else |
391 |
|
dclear(vp->name); |
392 |
|
} |
393 |
< |
if (lvl >= 1) { |
394 |
< |
for (ep = outchan; ep != NULL; ep = ep->sibling) |
395 |
< |
epfree(ep); |
396 |
< |
outchan = NULL; |
397 |
< |
} |
393 |
> |
if (lvl >= 1) |
394 |
> |
while (outchan != NULL) { |
395 |
> |
ep = outchan; |
396 |
> |
outchan = ep->sibling; |
397 |
> |
epfree(ep,1); |
398 |
> |
} |
399 |
|
} |
400 |
|
|
401 |
|
|
465 |
|
/* if fn is NULL then relink all */ |
466 |
|
for (i = 0; i < NHASH; i++) |
467 |
|
for (vp = hashtbl[i]; vp != NULL; vp = vp->next) |
468 |
< |
if (vp->lib != NULL || fn == NULL || !strcmp(fn, vp->name)) |
468 |
> |
if ((vp->lib != NULL) | (fn == NULL) || !strcmp(fn, vp->name)) |
469 |
|
vp->lib = liblookup(vp->name); |
470 |
|
} |
471 |
|
|
491 |
|
vp->next = ln->next; |
492 |
|
} |
493 |
|
freestr(ln->name); |
494 |
< |
efree((char *)ln); |
494 |
> |
efree(ln); |
495 |
|
} |
496 |
|
|
497 |
|
|
577 |
|
sp->sibling = ep; |
578 |
|
else { |
579 |
|
sp->sibling = ep->sibling; |
580 |
< |
epfree(ep); |
580 |
> |
epfree(ep,1); |
581 |
|
} |
582 |
|
return; |
583 |
|
} |
604 |
|
if (esupport&E_OUTCHAN && |
605 |
|
nextc == '$') { /* channel assignment */ |
606 |
|
ep = getchan(); |
607 |
+ |
if (optimized) |
608 |
+ |
epoptimize(ep); /* optimize new chan expr */ |
609 |
|
addchan(ep); |
610 |
|
} else { /* ordinary definition */ |
611 |
|
ep = getdefn(); |
612 |
< |
qname = qualname(dname(ep), 0); |
612 |
> |
if (optimized) |
613 |
> |
epoptimize(ep); /* optimize new statement */ |
614 |
> |
qname = qualname(dfn_name(ep), 0); |
615 |
|
if (esupport&E_REDEFW && (vdef = varlookup(qname)) != NULL) { |
616 |
|
if (vdef->def != NULL && epcmp(ep, vdef->def)) { |
617 |
|
wputs(qname); |
647 |
|
{ |
648 |
|
EPNODE *ep1, *ep2; |
649 |
|
|
650 |
< |
if (!isalpha(nextc) && nextc != CNTXMARK) |
650 |
> |
if (!isalpha(nextc) & (nextc != CNTXMARK)) |
651 |
|
syntax("illegal variable name"); |
652 |
|
|
653 |
|
ep1 = newnode(); |
666 |
|
ep2 = newnode(); |
667 |
|
ep2->type = SYM; |
668 |
|
ep2->v.name = savestr(getname()); |
669 |
+ |
if (strchr(ep2->v.name, CNTXMARK) != NULL) |
670 |
+ |
syntax("illegal parameter name"); |
671 |
|
addekid(ep1, ep2); |
672 |
|
} while (nextc == ','); |
673 |
|
if (nextc != ')') |
676 |
|
curfunc = ep1; |
677 |
|
} |
678 |
|
|
679 |
< |
if (nextc != '=' && nextc != ':') |
679 |
> |
if ((nextc != '=') & (nextc != ':')) |
680 |
|
syntax("'=' or ':' expected"); |
681 |
|
|
682 |
|
ep2 = newnode(); |
733 |
|
|
734 |
|
|
735 |
|
static double /* evaluate a variable */ |
736 |
< |
dvalue(char *name, EPNODE *d) |
736 |
> |
dvalue(char *name, EPNODE *d) |
737 |
|
{ |
738 |
|
EPNODE *ep1, *ep2; |
739 |
|
|
745 |
|
ep1 = d->v.kid->sibling; /* get expression */ |
746 |
|
if (ep1->type == NUM) |
747 |
|
return(ep1->v.num); /* return if number */ |
748 |
+ |
if (esupport&E_RCONST && d->type == ':') { |
749 |
+ |
wputs(name); |
750 |
+ |
wputs(": assigned non-constant value\n"); |
751 |
+ |
} |
752 |
|
ep2 = ep1->sibling; /* check time */ |
753 |
|
if (eclock >= MAXCLOCK) |
754 |
|
eclock = 1; /* wrap clock counter */ |