58 |
|
static EPNODE *ochpos; /* ...dnext */ |
59 |
|
static EPNODE *outchan; |
60 |
|
|
61 |
+ |
static int optimized = 0; /* are we optimized? */ |
62 |
+ |
|
63 |
|
EPNODE *curfunc = NULL; |
62 |
– |
#define dname(ep) ((ep)->v.kid->type == SYM ? \ |
63 |
– |
(ep)->v.kid->v.name : \ |
64 |
– |
(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 |
< |
} |
181 |
< |
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 |
|
|
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++; |
296 |
< |
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 |
|
|
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); |