refresh InterpretDebug5.diff
[nedit-bw.git] / symbol-lookup.patch
blob8d3f6420ae89f52e4c6bb9148577db99a9d72051
1 ---
3 source/interpret.c | 251 +++++++++++++----------------------------------------
4 source/interpret.h | 8 -
5 source/macro.c | 6 -
6 source/parse.y | 55 ++++-------
7 4 files changed, 91 insertions(+), 229 deletions(-)
9 diff --quilt old/source/interpret.c new/source/interpret.c
10 --- old/source/interpret.c
11 +++ new/source/interpret.c
12 @@ -170,7 +170,6 @@ static AccumulatorData *Accumulator;
13 #define ProgP (Accumulator->progP)
14 #define LoopStack (Accumulator->loopStack)
15 #define LoopStackPtr (Accumulator->loopStackPtr)
16 -#define LocalSymList (Accumulator->localSymList)
17 #define ProgramName (Accumulator->name)
19 /* Global data for the interpreter */
20 @@ -212,8 +211,8 @@ static int (*OpFns[])() = {
21 #define FP_GET_PROG(xFrameP) ((FP_GET_ITEM(xFrameP, FP_PROG_INDEX)).val.prog)
22 #define FP_ARG_START_INDEX(xFrameP) (-(FP_GET_ARG_COUNT(xFrameP) + FP_TO_ARGS_DIST))
23 #define FP_GET_ARG_N(xFrameP,xN) (FP_GET_ITEM(xFrameP, xN + FP_ARG_START_INDEX(xFrameP)))
24 -#define FP_GET_SYM_N(xFrameP,xN) (FP_GET_ITEM(xFrameP, xN))
25 -#define FP_GET_SYM_VAL(xFrameP,xSym) (FP_GET_SYM_N(xFrameP, xSym->value.val.n))
26 +#define FP_GET_SYM_TAB(xFrameP) (FP_GET_ITEM(xFrameP, FP_SYMBOL_TABLE).val.sym)
27 +#define LocalSymList FP_GET_SYM_TAB(Interpreter->frameP)
30 ** Initialize macro language global variables. Must be called before
31 @@ -268,7 +267,6 @@ AccumulatorData *BeginCreatingProgram(co
32 AccumulatorData *old = Accumulator;
33 Accumulator = XtNew(AccumulatorData);
35 - LocalSymList = NULL;
36 ProgP = Prog;
37 LoopStackPtr = LoopStack;
38 ProgramName = name;
39 @@ -284,22 +282,15 @@ AccumulatorData *BeginCreatingProgram(co
40 Program *FinishCreatingProgram(AccumulatorData *old)
42 Program *newProg;
43 - int progLen, fpOffset = 0;
44 - Symbol *s;
45 + int progLen;
47 newProg = XtNew(Program);
48 newProg->name = LookupString(ProgramName, True);
49 progLen = ProgP - Prog;
50 newProg->code = (Inst *)XtCalloc(progLen, sizeof(Inst));
51 memcpy(newProg->code, Prog, progLen * sizeof(Inst));
52 - newProg->localSymList = LocalSymList;
53 newProg->refcount = 1;
55 - /* Local variables' values are stored on the stack. Here we assign
56 - frame pointer offsets to them. */
57 - for (s = newProg->localSymList; s != NULL; s = s->next)
58 - s->value.val.n = fpOffset++;
60 DISASM(newProg->name, newProg->code, ProgP - Prog);
62 XtFree((char *)Accumulator);
63 @@ -311,7 +302,6 @@ Program *FinishCreatingProgram(Accumulat
64 void FreeProgram(Program *prog)
66 if (--prog->refcount == 0) {
67 - freeSymbolList(prog->localSymList);
68 XtFree((char *)prog->code);
69 XtFree((char *)prog);
71 @@ -335,14 +325,14 @@ int AddOp(int op, char **msg)
73 ** Add a symbol operand to the current program
75 -int AddSym(Symbol *sym, char **msg)
76 +int AddSym(const char *sym, char **msg)
78 if (ProgP >= &Prog[PROGRAM_SIZE]) {
79 *msg = "macro too large";
80 return 0;
82 ProgP->type = SYM_INST;
83 - ProgP->val.sym = sym;
84 + ProgP->val.str = sym;
85 ProgP++;
86 return 1;
88 @@ -521,7 +511,6 @@ static int setupFrame(RestartData *conte
90 static DataValue noValue = {NO_TAG, {0}};
91 int i, totalPushs = 7;
92 - Symbol *s;
95 ** we push only if we have room for the whole frame, so pre-calc the
96 @@ -530,9 +519,6 @@ static int setupFrame(RestartData *conte
97 if (nArgs >= 0) {
98 totalPushs += nArgs;
100 - for (s = prog->localSymList; s != NULL; s = s->next) {
101 - totalPushs++;
104 /* !OK_TO_PUSH(totalPushs) */
105 if (!((context->stackP + totalPushs) <= (context->stack + STACK_SIZE))) {
106 @@ -570,9 +556,9 @@ static int setupFrame(RestartData *conte
107 context->stackP->val.dataval = context->frameP;
108 context->stackP++;
110 - /* symbol table */
111 + /* start a new local symbol list */
112 context->stackP->tag = NO_TAG;
113 - context->stackP->val.sym = prog->localSymList;
114 + context->stackP->val.sym = NULL;
115 context->stackP++;
117 /* macro name */
118 @@ -588,12 +574,6 @@ static int setupFrame(RestartData *conte
120 context->frameP = context->stackP;
122 - /* Initialize and make room on the stack for local variables */
123 - for (s = prog->localSymList; s != NULL; s = s->next) {
124 - FP_GET_SYM_VAL(context->frameP, s) = noValue;
125 - context->stackP++;
128 context->pc = prog->code;
130 return STAT_OK;
131 @@ -606,6 +586,9 @@ static void rewindFrame(RestartData *con
132 DataValue *newFrameP = FP_GET_OLD_FP(context->frameP);
133 Inst *newPC = FP_GET_RET_PC(context->frameP);
134 Program *prog = FP_GET_PROG(context->frameP);
135 + Symbol *symList = FP_GET_SYM_TAB(context->frameP);
137 + freeSymbolList(symList);
139 /* pop past local variables */
140 context->stackP = context->frameP;
141 @@ -844,17 +827,20 @@ static Symbol *lookupSymbol(Symbol *syml
144 ** find a symbol in the symbol table
146 +** will create only LOCAL_SYM and GLOBAL_SYM (depending on first character)
147 +** with a NO_TAG value
149 -Symbol *LookupSymbol(const char *name)
150 +Symbol *LookupSymbol(const char *name, int create)
152 unsigned int hash;
153 - Symbol *s;
154 + Symbol *s = NULL;
156 /* calculate hash for name */
157 hash = hashName(name);
159 /* search in local symbols */
160 - if (Accumulator) {
161 + if (Interpreter) {
162 s = lookupSymbol(LocalSymList, name, hash);
163 if (NULL != s)
164 return s;
165 @@ -865,7 +851,13 @@ Symbol *LookupSymbol(const char *name)
166 if (NULL != s)
167 return s;
169 - return NULL;
170 + if (create) {
171 + DataValue noValue = {NO_TAG, {0}};
172 + s = InstallSymbol(name, name[0] == '$' ? GLOBAL_SYM : LOCAL_SYM,
173 + noValue);
176 + return s;
180 @@ -881,8 +873,17 @@ Symbol *InstallSymbol(const char *name,
181 s->value = value;
182 s->hash = hashName(s->name);
183 if (type == LOCAL_SYM) {
184 - s->next = LocalSymList;
185 - LocalSymList = s;
186 + if (Interpreter) {
187 + s->next = LocalSymList;
188 + LocalSymList = s;
190 + else {
191 + fprintf(stderr,
192 + "NEdit: try to install local symbol without "
193 + "macro context: %s\n", name);
194 + XtFree((char *)s);
195 + s = NULL;
197 } else {
198 addToGlobalSymTab(s);
200 @@ -890,70 +891,6 @@ Symbol *InstallSymbol(const char *name,
204 -** Promote a symbol from local to global, removing it from the local symbol
205 -** list.
207 -** This is used as a forward declaration feature for macro functions.
208 -** If a function is called (ie while parsing the macro) where the
209 -** function isn't defined yet, the symbol is put into the GlobalSymList
210 -** so that the function definition uses the same symbol.
213 -Symbol *PromoteToGlobal(Symbol *sym)
215 - Symbol *s;
217 - if (sym->type != LOCAL_SYM)
218 - return sym;
220 - /* Remove sym from the local symbol list */
221 - if (sym == LocalSymList)
222 - LocalSymList = sym->next;
223 - else {
224 - for (s = LocalSymList; s != NULL; s = s->next) {
225 - if (s->next == sym) {
226 - s->next = sym->next;
227 - break;
232 - /* There are two scenarios which could make this check succeed:
233 - a) this sym is in the GlobalSymList as a LOCAL_SYM symbol
234 - b) there is another symbol as a non-LOCAL_SYM in the GlobalSymList
235 - Both are errors, without question.
236 - We currently just print this warning, but we should error out the
237 - parsing process. */
238 - s = LookupSymbol(sym->name);
239 - if (sym == s) {
240 - /* case a)
241 - just make this symbol a GLOBAL_SYM symbol and return */
242 - fprintf(stderr,
243 - "nedit: To boldly go where no local sym has gone before: %s\n",
244 - sym->name);
245 - sym->type = GLOBAL_SYM;
246 - return sym;
247 - } else if (NULL != s) {
248 - /* case b)
249 - sym will shadow the old symbol from the GlobalSymList */
250 - fprintf(stderr,
251 - "nedit: duplicate symbol in LocalSymList and GlobalSymList: %s\n",
252 - sym->name);
255 - /* Add the symbol directly to the GlobalSymList, because InstallSymbol()
256 - will allocate a new Symbol, which results in a memory leak of sym.
257 - Don't use MACRO_FUNCTION_SYM as type, because in
258 - macro.c:readCheckMacroString() we use ProgramFree() for the .val.prog,
259 - but this symbol has no program attached and ProgramFree() is not NULL
260 - pointer safe */
261 - sym->type = GLOBAL_SYM;
262 - addToGlobalSymTab(sym);
264 - return sym;
268 ** Convert a long value to its decimal string representation, returned in a
269 ** static string.
271 @@ -1123,7 +1060,7 @@ static SparseArrayEntry *allocateSparseA
273 SparseArrayEntryWrapper *mem;
275 - mem = (SparseArrayEntryWrapper *)XtMalloc(sizeof(SparseArrayEntryWrapper));
276 + mem = XtNew(SparseArrayEntryWrapper);
277 mem->next = AllocatedSparseArrayEntries;
278 AllocatedSparseArrayEntries = mem;
279 #ifdef TRACK_GARBAGE_LEAKS
280 @@ -1287,14 +1224,19 @@ static void addToGlobalSymTab(Symbol *sy
282 #define EXEC_ERROR(s1, s2) return execError(s1, s2)
284 -#define GET_SYM(s) \
285 +#define GET_SYM(s, create) \
286 do { \
287 + const char *_n; \
288 if (PC->type != SYM_INST) { \
289 EXEC_ERROR("Unexpected instruction, expected <symbol>: <%s>", \
290 instTypeToStr(PC->type)); \
292 - s = PC->val.sym; \
293 + _n = PC->val.str; \
294 + s = LookupSymbol(_n, create); \
295 PC++; \
296 + if (!s) { \
297 + EXEC_ERROR("No such symbol: %s", _n); \
298 + } \
299 } while (0)
301 #define GET_IMMED(i) \
302 @@ -1505,11 +1447,9 @@ static int pushSymVal(void)
303 DISASM_RT();
304 STACKDUMP(0, 3);
306 - GET_SYM(s);
307 + GET_SYM(s, False);
309 - if (s->type == LOCAL_SYM) {
310 - symVal = FP_GET_SYM_VAL(FrameP, s);
311 - } else if (s->type == GLOBAL_SYM) {
312 + if (s->type == LOCAL_SYM || s->type == GLOBAL_SYM) {
313 symVal = s->value;
314 } else if (s->type == ARG_SYM) {
315 nArgs = FP_GET_ARG_COUNT(FrameP);
316 @@ -1659,18 +1599,13 @@ static int pushArraySymVal(void)
317 DISASM_RT();
318 STACKDUMP(0, 3);
320 - GET_SYM(sym);
321 + GET_SYM(sym, True);
322 GET_IMMED(initEmpty);
324 - if (sym->type == LOCAL_SYM) {
325 - dataPtr = &FP_GET_SYM_VAL(FrameP, sym);
327 - else if (sym->type == GLOBAL_SYM) {
328 - dataPtr = &sym->value;
330 - else {
331 + if (sym->type != LOCAL_SYM && sym->type != GLOBAL_SYM) {
332 EXEC_ERROR("assigning to non-lvalue array or non-array: %s", sym->name);
334 + dataPtr = &sym->value;
336 if (initEmpty && dataPtr->tag == NO_TAG) {
337 dataPtr->tag = ARRAY_TAG;
338 @@ -1972,7 +1907,7 @@ static int assign(void)
339 DISASM_RT();
340 STACKDUMP(1, 3);
342 - GET_SYM(sym);
343 + GET_SYM(sym, True);
345 if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) {
346 if (sym->type == ARG_SYM) {
347 @@ -1985,13 +1920,7 @@ static int assign(void)
348 EXEC_ERROR("assignment to non-variable: %s", sym->name);
352 - if (sym->type == LOCAL_SYM) {
353 - dataPtr = &FP_GET_SYM_VAL(FrameP, sym);
355 - else {
356 - dataPtr = &sym->value;
358 + dataPtr = &sym->value;
360 POP(value);
362 @@ -2775,7 +2704,7 @@ static int callSubroutine(void)
364 DISASM_RT();
366 - GET_SYM(sym);
367 + GET_SYM(sym, False);
368 GET_IMMED(nArgs);
370 STACKDUMP(nArgs > 0 ? nArgs : -nArgs, 3);
371 @@ -2813,7 +2742,7 @@ static int callSubroutineUnpackArray(voi
373 DISASM_RT();
375 - GET_SYM(sym);
376 + GET_SYM(sym, False);
377 GET_IMMED(nArgs);
379 if (nArgs < 0) {
380 @@ -3624,35 +3553,25 @@ static int arrayIter(void)
381 STACKDUMP(1, 4);
383 GET_IMMED(withVal);
384 - GET_SYM(keySym);
385 + GET_SYM(keySym, True);
386 if (withVal) {
387 - GET_SYM(valSym);
388 + GET_SYM(valSym, True);
390 GET_BRANCH(branchAddr);
392 POP(iterator);
394 - if (keySym->type == LOCAL_SYM) {
395 - keyValPtr = &FP_GET_SYM_VAL(FrameP, keySym);
397 - else if (keySym->type == GLOBAL_SYM) {
398 - keyValPtr = &(keySym->value);
400 - else {
401 + if (keySym->type != LOCAL_SYM && keySym->type != GLOBAL_SYM) {
402 EXEC_ERROR("can't assign to: %s", keySym->name);
404 + keyValPtr = &keySym->value;
405 keyValPtr->tag = NO_TAG;
407 if (withVal) {
408 - if (valSym->type == LOCAL_SYM) {
409 - valPtr = &FP_GET_SYM_VAL(FrameP, valSym);
411 - else if (valSym->type == GLOBAL_SYM) {
412 - valPtr = &(valSym->value);
414 - else {
415 + if (valSym->type != LOCAL_SYM && valSym->type != GLOBAL_SYM) {
416 EXEC_ERROR("can't assign to: %s", valSym->name);
418 + valPtr = &valSym->value;
419 valPtr->tag = NO_TAG;
422 @@ -3791,37 +3710,27 @@ static int arrayIterArray(void)
423 STACKDUMP(2, 4);
425 GET_IMMED(withVal);
426 - GET_SYM(keyArraySym);
427 + GET_SYM(keyArraySym, True);
428 if (withVal) {
429 - GET_SYM(valSym);
430 + GET_SYM(valSym, True);
432 GET_BRANCH(branchAddr);
434 POP(iterator);
435 PEEK_INT(nDims, 0);
437 - if (keyArraySym->type == LOCAL_SYM) {
438 - keyArrayPtr = &FP_GET_SYM_VAL(FrameP, keyArraySym);
440 - else if (keyArraySym->type == GLOBAL_SYM) {
441 - keyArrayPtr = &(keyArraySym->value);
443 - else {
444 + if (keyArraySym->type != LOCAL_SYM && keyArraySym->type != GLOBAL_SYM) {
445 EXEC_ERROR("can't assign to: %s", keyArraySym->name);
447 + keyArrayPtr = &keyArraySym->value;
448 keyArrayPtr->tag = ARRAY_TAG;
449 keyArrayPtr->val.arrayPtr = NULL;
451 if (withVal) {
452 - if (valSym->type == LOCAL_SYM) {
453 - valPtr = &FP_GET_SYM_VAL(FrameP, valSym);
455 - else if (valSym->type == GLOBAL_SYM) {
456 - valPtr = &valSym->value;
458 - else {
459 + if (valSym->type != LOCAL_SYM && valSym->type != GLOBAL_SYM) {
460 EXEC_ERROR("can't assign to: %s", valSym->name);
462 + valPtr = &valSym->value;
463 valPtr->tag = NO_TAG;
466 @@ -4586,7 +4495,7 @@ static void dumpInst(Inst *inst, const c
467 break;
469 case SYM_INST:
470 - printd(" <%s %s>", name, inst->val.sym->name);
471 + printd(" <%s %s>", name, inst->val.str);
472 break;
474 default:
475 @@ -4809,11 +4718,6 @@ static void stackdumpframe(DataValue *ar
476 DataValue *endDv = (arg1 > outpt) ? arg1 : outpt;
477 int nArgs = FP_GET_ARG_COUNT(fp);
479 - int nSyms;
480 - static int symLen = 0;
481 - Symbol *syms = FP_GET_ITEM(fp, FP_SYMBOL_TABLE).val.sym;
482 - Symbol *sym;
484 #ifdef DEBUG_STACK_HEADFIRST
485 #else
486 /* do caller's frame */
487 @@ -4822,17 +4726,6 @@ static void stackdumpframe(DataValue *ar
488 #endif /* #ifdef DEBUG_STACK_HEADFIRST */
490 /* do current frame */
491 - /* how many symbols are there? */
492 - for (sym = syms, nSyms = 0; sym != NULL; sym = sym->next) {
493 - nSyms++;
494 - if (symLen < 27) {
495 - int len = strlen(sym->name);
496 - if (len > 27)
497 - len = 27;
498 - if (len > symLen)
499 - symLen = len;
503 /* output instructions between endDv and sp - 1 inclusive */
504 #ifdef DEBUG_STACK_HEADFIRST
505 @@ -4843,7 +4736,6 @@ static void stackdumpframe(DataValue *ar
506 #endif /* #ifdef DEBUG_STACK_HEADFIRST */
508 const char *posFmt = "%-6s";
509 - const char *symName = "";
511 char *pos = "";
512 char buffer[sizeof(STACK_DUMP_ARG_PREFIX) + TYPE_INT_STR_SIZE(int)];
513 @@ -4867,10 +4759,6 @@ static void stackdumpframe(DataValue *ar
514 sprintf(pos = buffer, STACK_DUMP_ARG_PREFIX "%d",
515 offset + FP_TO_ARGS_DIST + nArgs + 1);
517 - else if (0 <= offset && offset < nSyms) {
518 - sprintf(pos = buffer, offset ? "[%d]" : "FP[%d]", offset);
519 - posFmt = "%6s";
521 else if (offset == 0) {
522 pos = "FrameP";
524 @@ -4878,17 +4766,6 @@ static void stackdumpframe(DataValue *ar
526 printd(posFmt, pos);
528 - /* local symbol names? */
529 - if (0 <= offset && offset < nSyms) {
530 - for (sym = syms; sym != NULL; sym = sym->next) {
531 - if (sym->value.val.n == offset) {
532 - symName = sym->name;
533 - break;
537 - printd(" %-*.*s", symLen, symLen, symName);
539 if (dv == fnNm && dv->tag == STRING_TAG && dv->val.str.rep)
540 printd(" %s", dv->val.str.rep);
541 else
542 diff --quilt old/source/interpret.h new/source/interpret.h
543 --- old/source/interpret.h
544 +++ new/source/interpret.h
545 @@ -70,7 +70,6 @@ typedef struct InstTag {
546 int immed;
547 const char *str;
548 ptrdiff_t branch;
549 - struct SymbolRec *sym;
550 } val;
551 } Inst;
553 @@ -114,7 +113,6 @@ typedef struct SymbolRec {
555 typedef struct ProgramTag {
556 const char *name;
557 - Symbol *localSymList;
558 Inst *code;
559 unsigned refcount;
560 } Program;
561 @@ -132,7 +130,6 @@ typedef struct {
563 /* state of the accumulator (aka compiler) */
564 typedef struct AccumulatorDataTag {
565 - Symbol *localSymList;
566 Inst prog[PROGRAM_SIZE];
567 Inst *progP;
568 Inst *loopStack[LOOP_STACK_SIZE];
569 @@ -157,13 +154,13 @@ int ArrayCopy(DataValue *dstArray, DataV
570 AccumulatorData *BeginCreatingProgram(const char *name);
571 Program *FinishCreatingProgram(AccumulatorData *old);
572 int AddOp(int op, char **msg);
573 -int AddSym(Symbol *sym, char **msg);
574 +int AddSym(const char *str, char **msg);
575 int AddImmediate(int immed, char **msg);
576 int AddString(const char *str, char **msg);
577 int AddBranchOffset(Inst *to, char **msg);
578 int SetBranchOffset(Inst *from, Inst *to, char **msg);
579 Inst *GetPC(void);
580 -Symbol *LookupSymbol(const char *name);
581 +Symbol *LookupSymbol(const char *name, int create);
582 Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value);
583 const char *LookupString(const char *str, int create);
584 Inst *SwapCode(Inst *start, Inst *boundary, Inst *end);
585 @@ -194,7 +191,6 @@ int AllocNStringNCpy(NString *string, co
586 int AllocNStringCpy(NString *string, const char *s);
587 void GarbageCollectStrings(void);
588 void FreeRestartData(RestartData *context);
589 -Symbol *PromoteToGlobal(Symbol *sym);
590 void FreeProgram(Program *prog);
591 void ModifyReturnedValue(RestartData *context, DataValue dv);
592 WindowInfo *MacroRunWindow(void);
593 diff --quilt old/source/parse.y new/source/parse.y
594 --- old/source/parse.y
595 +++ new/source/parse.y
596 @@ -111,7 +111,6 @@ static int nextSymIsField = 0;
599 %union {
600 - Symbol *sym;
601 Inst *inst;
602 int num;
603 const char *str;
604 @@ -121,14 +120,13 @@ static int nextSymIsField = 0;
605 Symbol *sym;
606 } define;
608 -%token <sym> SYMBOL
609 -%token <str> STRING FIELD
610 +%token <str> SYMBOL STRING FIELD
611 %token <num> NUMBER
612 %token DELETE ARG_LOOKUP
613 %token IF WHILE DO ELSE FOR BREAK CONTINUE RETURN DEFINE TYPEOF KEYVAL
614 %type <num> arglistopt arglist catlist fnarglsopt fnarglist fnarg
615 %type <inst> cond comastmts comastmtlst for while do else and or arrayexpr mark
616 -%type <sym> evalsym
617 +%type <str> evalsym
618 %type <define> definesym
619 %type <oper> operassign incrdecr
620 %token <oper> '=' ADDEQ SUBEQ MULEQ DIVEQ MODEQ ANDEQ OREQ
621 @@ -199,31 +197,24 @@ definekw: DEFINE {
624 definesym: SYMBOL {
625 - /* we can't really be sure, that we not overwrite any
626 - ** wrong symbol
627 - **
628 - ** we should only overwrite installed MACRO_FUNCTION_SYM
629 - ** and this is questionable.
630 - */
631 - if ($1->type == MACRO_FUNCTION_SYM) {
632 - FreeProgram($1->value.val.prog);
633 + $$.sym = LookupSymbol($1, False);
634 + if ($$.sym) {
635 + if ($$.sym->type != MACRO_FUNCTION_SYM) {
636 + yyerror("try to override built-in subroutine"); YYERROR;
639 - else if ($1->type == LOCAL_SYM ||
640 - $1->type == GLOBAL_SYM) {
641 - /* newly created sym, or we overwrite a local sym */;
642 - } else {
643 - yyerror("try to override built-in subroutine"); YYERROR;
644 + else {
645 + DataValue subrPtr;
646 + subrPtr.tag = NO_TAG;
647 + subrPtr.val.prog = NULL;
648 + $$.sym = InstallSymbol($1, MACRO_FUNCTION_SYM, subrPtr);
650 - $$.sym = PromoteToGlobal($1);
651 $$.acc = BeginCreatingProgram($$.sym->name);
654 define: definekw blank definesym blank blockwb {
655 ADD_OP(OP_RETURN_NO_VAL);
656 - Program *prog = FinishCreatingProgram($3.acc);
657 - $3.sym->type = MACRO_FUNCTION_SYM;
658 - $3.sym->value.tag = NO_TAG;
659 - $3.sym->value.val.prog = prog;
660 + $3.sym->value.val.prog = FinishCreatingProgram($3.acc);
664 @@ -532,18 +523,18 @@ funccall: TYPEOF '(' {
666 | SYMBOL '(' fnarglsopt ')' {
667 ADD_OP(OP_SUBR_CALL);
668 - ADD_SYM(PromoteToGlobal($1)); ADD_IMMED($3);
669 + ADD_SYM($1); ADD_IMMED($3);
671 | SYMBOL '(' blank '=' blank expr blank ')' {
672 /* a single array replaces the argument list */
673 ADD_OP(OP_SUBR_CALL_UNPACK_ARRAY);
674 - ADD_SYM(PromoteToGlobal($1));
675 + ADD_SYM($1);
676 ADD_IMMED(0); /* zero arguments */
678 | SYMBOL '(' fnarglist ARGSEP blank '=' blank expr blank ')' {
679 /* a single array replaces the argument list */
680 ADD_OP(OP_SUBR_CALL_UNPACK_ARRAY);
681 - ADD_SYM(PromoteToGlobal($1));
682 + ADD_SYM($1);
683 ADD_IMMED($3);
686 @@ -931,19 +922,17 @@ static int yylex(void)
687 if (!strcmp(symName, "delete") && follow_non_whitespace('(', SYMBOL, DELETE) == DELETE) return DELETE;
688 if (!strcmp(symName, "define") && follow_non_whitespace('(', SYMBOL, DEFINE) == DEFINE) return DEFINE;
689 if (!strcmp(symName, "typeof")) return TYPEOF;
691 + yylval.str = LookupString(symName, True);
692 if (nextSymIsField) {
693 nextSymIsField = 0;
694 - yylval.str = LookupString(symName, True);
695 return FIELD;
697 - if ((s=LookupSymbol(symName)) == NULL) {
698 - s = InstallSymbol(symName, symName[0]=='$' ?
699 - (((symName[1] > '0' && symName[1] <= '9') && symName[2] == 0) ?
700 - ARG_SYM : GLOBAL_SYM) : LOCAL_SYM, value);
701 - s->value.tag = NO_TAG;
702 + else {
703 + return SYMBOL;
706 - yylval.sym = s;
707 + yylval.str = LookupString(s->name, True);
708 return SYMBOL;
710 nextSymIsField = 0;
711 @@ -1105,7 +1094,7 @@ static Symbol *matchesActionRoutine(char
712 if (!hasDash)
713 return NULL;
714 *symPtr = '\0';
715 - s = LookupSymbol(symbolName);
716 + s = LookupSymbol(symbolName, False);
717 if (s != NULL)
718 *inPtr = c;
719 return s;
720 diff --quilt old/source/macro.c new/source/macro.c
721 --- old/source/macro.c
722 +++ new/source/macro.c
723 @@ -3826,7 +3826,7 @@ static int callMS(WindowInfo *window, Da
724 if (!readStringArg(argList[0], &fnname, stringStorage, errMsg)) {
725 return False;
727 - sym = LookupSymbol(fnname);
728 + sym = LookupSymbol(fnname, False);
729 if (!sym) {
730 *errMsg = "subroutine name invalid";
731 return False;
732 @@ -3902,7 +3902,7 @@ static int defineMS(WindowInfo *window,
734 XtFree(bodysave);
736 - sym = LookupSymbol(name);
737 + sym = LookupSymbol(name, False);
738 if (sym) {
739 if (!override) {
740 FreeProgram(prog);
741 @@ -7313,7 +7313,7 @@ Boolean MacroApplyHook(WindowInfo *docum
742 Symbol *hookSymbol;
743 Boolean succ = False;
745 - hookSymbol = LookupSymbol(hook);
746 + hookSymbol = LookupSymbol(hook, False);
747 if (NULL != hookSymbol && MACRO_FUNCTION_SYM == hookSymbol->type) {
748 Program *hookProg = hookSymbol->value.val.prog;
749 RestartData *restartData;