58 |
|
static EPNODE *ochpos; /* ...dnext */ |
59 |
|
static EPNODE *outchan; |
60 |
|
|
61 |
< |
EPNODE *curfunc = NULL; |
61 |
> |
static int optimized = 0; /* are we optimized? */ |
62 |
|
|
63 |
+ |
EPNODE *ecurfunc = NULL; |
64 |
|
|
65 |
+ |
|
66 |
|
void |
67 |
|
fcompile( /* get definitions from a file */ |
68 |
|
char *fname |
82 |
|
#endif |
83 |
|
initfile(fp, fname, 0); |
84 |
|
while (nextc != EOF) |
85 |
< |
getstatement(); |
85 |
> |
egetstatement(); |
86 |
|
if (fname != NULL) |
87 |
|
fclose(fp); |
88 |
|
#ifdef getc_unlocked |
101 |
|
{ |
102 |
|
initstr(str, fn, ln); |
103 |
|
while (nextc != EOF) |
104 |
< |
getstatement(); |
104 |
> |
egetstatement(); |
105 |
|
} |
106 |
|
|
107 |
|
|
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 |
< |
} |
185 |
< |
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 |
|
|
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 |
|
) |
394 |
|
while (outchan != NULL) { |
395 |
|
ep = outchan; |
396 |
|
outchan = ep->sibling; |
397 |
< |
ep->sibling = NULL; |
380 |
< |
epfree(ep); |
397 |
> |
epfree(ep,1); |
398 |
|
} |
399 |
|
} |
400 |
|
|
442 |
|
return(vp); |
443 |
|
} |
444 |
|
vp = (VARDEF *)emalloc(sizeof(VARDEF)); |
445 |
< |
vp->lib = liblookup(name); |
445 |
> |
vp->lib = eliblookup(name); |
446 |
|
if (vp->lib == NULL) /* if name not in library */ |
447 |
|
name = qualname(name, 0); /* use fully qualified version */ |
448 |
|
hv = hash(name); |
456 |
|
|
457 |
|
|
458 |
|
void |
459 |
< |
libupdate( /* update library links */ |
459 |
> |
elibupdate( /* update library links */ |
460 |
|
char *fn |
461 |
|
) |
462 |
|
{ |
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)) |
469 |
< |
vp->lib = liblookup(vp->name); |
469 |
> |
vp->lib = eliblookup(vp->name); |
470 |
|
} |
471 |
|
|
472 |
|
|
560 |
|
|
561 |
|
|
562 |
|
void |
563 |
< |
addchan( /* add an output channel assignment */ |
563 |
> |
eaddchan( /* add an output channel assignment */ |
564 |
|
EPNODE *sp |
565 |
|
) |
566 |
|
{ |
577 |
|
sp->sibling = ep; |
578 |
|
else { |
579 |
|
sp->sibling = ep->sibling; |
580 |
< |
epfree(ep); |
580 |
> |
epfree(ep,1); |
581 |
|
} |
582 |
|
return; |
583 |
|
} |
591 |
|
|
592 |
|
|
593 |
|
void |
594 |
< |
getstatement(void) /* get next statement */ |
594 |
> |
egetstatement(void) /* get next statement */ |
595 |
|
{ |
596 |
|
EPNODE *ep; |
597 |
|
char *qname; |
598 |
|
VARDEF *vdef; |
599 |
|
|
600 |
|
if (nextc == ';') { /* empty statement */ |
601 |
< |
scan(); |
601 |
> |
escan(); |
602 |
|
return; |
603 |
|
} |
604 |
|
if (esupport&E_OUTCHAN && |
605 |
|
nextc == '$') { /* channel assignment */ |
606 |
< |
ep = getchan(); |
607 |
< |
addchan(ep); |
606 |
> |
ep = egetchan(); |
607 |
> |
if (optimized) |
608 |
> |
epoptimize(ep); /* optimize new chan expr */ |
609 |
> |
eaddchan(ep); |
610 |
|
} else { /* ordinary definition */ |
611 |
< |
ep = getdefn(); |
611 |
> |
ep = egetdefn(); |
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)) { |
632 |
|
} |
633 |
|
if (nextc != EOF) { |
634 |
|
if (nextc != ';') |
635 |
< |
syntax("';' expected"); |
636 |
< |
scan(); |
635 |
> |
esyntax("';' expected"); |
636 |
> |
escan(); |
637 |
|
} |
638 |
|
} |
639 |
|
|
640 |
|
|
641 |
|
EPNODE * |
642 |
< |
getdefn(void) |
642 |
> |
egetdefn(void) |
643 |
|
/* A -> SYM = E1 */ |
644 |
|
/* SYM : E1 */ |
645 |
|
/* FUNC(SYM,..) = E1 */ |
648 |
|
EPNODE *ep1, *ep2; |
649 |
|
|
650 |
|
if (!isalpha(nextc) & (nextc != CNTXMARK)) |
651 |
< |
syntax("illegal variable name"); |
651 |
> |
esyntax("illegal variable name"); |
652 |
|
|
653 |
|
ep1 = newnode(); |
654 |
|
ep1->type = SYM; |
660 |
|
addekid(ep2, ep1); |
661 |
|
ep1 = ep2; |
662 |
|
do { |
663 |
< |
scan(); |
663 |
> |
escan(); |
664 |
|
if (!isalpha(nextc)) |
665 |
< |
syntax("illegal parameter name"); |
665 |
> |
esyntax("illegal parameter name"); |
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"); |
670 |
> |
esyntax("illegal parameter name"); |
671 |
|
addekid(ep1, ep2); |
672 |
|
} while (nextc == ','); |
673 |
|
if (nextc != ')') |
674 |
< |
syntax("')' expected"); |
675 |
< |
scan(); |
676 |
< |
curfunc = ep1; |
674 |
> |
esyntax("')' expected"); |
675 |
> |
escan(); |
676 |
> |
ecurfunc = ep1; |
677 |
|
} |
678 |
|
|
679 |
|
if ((nextc != '=') & (nextc != ':')) |
680 |
< |
syntax("'=' or ':' expected"); |
680 |
> |
esyntax("'=' or ':' expected"); |
681 |
|
|
682 |
|
ep2 = newnode(); |
683 |
|
ep2->type = nextc; |
684 |
< |
scan(); |
684 |
> |
escan(); |
685 |
|
addekid(ep2, ep1); |
686 |
|
addekid(ep2, getE1()); |
687 |
|
|
694 |
|
ep1->type = NUM; |
695 |
|
addekid(ep2, ep1); |
696 |
|
} |
697 |
< |
curfunc = NULL; |
697 |
> |
ecurfunc = NULL; |
698 |
|
|
699 |
|
return(ep2); |
700 |
|
} |
701 |
|
|
702 |
|
|
703 |
|
EPNODE * |
704 |
< |
getchan(void) /* A -> $N = E1 */ |
704 |
> |
egetchan(void) /* A -> $N = E1 */ |
705 |
|
{ |
706 |
|
EPNODE *ep1, *ep2; |
707 |
|
|
708 |
|
if (nextc != '$') |
709 |
< |
syntax("missing '$'"); |
710 |
< |
scan(); |
709 |
> |
esyntax("missing '$'"); |
710 |
> |
escan(); |
711 |
|
|
712 |
|
ep1 = newnode(); |
713 |
|
ep1->type = CHAN; |
714 |
|
ep1->v.chan = getinum(); |
715 |
|
|
716 |
|
if (nextc != '=') |
717 |
< |
syntax("'=' expected"); |
718 |
< |
scan(); |
717 |
> |
esyntax("'=' expected"); |
718 |
> |
escan(); |
719 |
|
|
720 |
|
ep2 = newnode(); |
721 |
|
ep2->type = '='; |