comment reduxed MultipleAssignment
[nedit-bw.git] / global-AccumulatorData.patch
blobfceb7a80830b60ada2f831854a95a26a2c7286f1
1 ---
3 source/interpret.c | 53 ++++++++++++++++++++++++-----------------------------
4 source/interpret.h | 4 ++--
5 source/parse.y | 16 +++++-----------
6 3 files changed, 31 insertions(+), 42 deletions(-)
8 diff --quilt old/source/interpret.h new/source/interpret.h
9 --- old/source/interpret.h
10 +++ new/source/interpret.h
11 @@ -154,7 +154,8 @@ int ArrayCopy(DataValue *dstArray, DataV
13 /* Routines for creating a program, (accumulated beginning with
14 BeginCreatingProgram and returned via FinishCreatingProgram) */
15 -void BeginCreatingProgram(const char *name, AccumulatorData *acc);
16 +AccumulatorData *BeginCreatingProgram(const char *name);
17 +Program *FinishCreatingProgram(AccumulatorData *old);
18 int AddOp(int op, char **msg);
19 int AddSym(Symbol *sym, char **msg);
20 int AddImmediate(int immed, char **msg);
21 @@ -167,7 +168,6 @@ Symbol *InstallStringConstSymbol(const c
22 Symbol *LookupSymbol(const char *name);
23 Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value);
24 Symbol *InstallMultiAssignExpr(void);
25 -Program *FinishCreatingProgram(AccumulatorData *acc);
26 Inst *SwapCode(Inst *start, Inst *boundary, Inst *end);
27 int StartLoopAddrList(char **msg);
28 int AddBreakAddr(Inst *addr, char **msg);
29 diff --quilt old/source/parse.y new/source/parse.y
30 --- old/source/parse.y
31 +++ new/source/parse.y
32 @@ -95,8 +95,6 @@ static int scanString(void);
34 static char *ErrMsg;
35 static char *InPtr;
36 -extern Inst *LoopStack[]; /* addresses of break, cont stmts */
37 -extern Inst **LoopStackPtr; /* to fill at the end of a loop */
39 static int AllowDefine;
41 @@ -202,7 +200,6 @@ definekw: DEFINE {
44 definesym: SYMBOL {
45 - $$.acc = (AccumulatorData *)XtMalloc(sizeof(AccumulatorData));
46 /* we can't really be sure, that we not overwrite any
47 ** wrong symbol
49 @@ -219,13 +216,12 @@ definesym: SYMBOL {
50 yyerror("try to override built-in subroutine"); YYERROR;
52 $$.sym = PromoteToGlobal($1);
53 - BeginCreatingProgram($$.sym->name, $$.acc);
54 + $$.acc = BeginCreatingProgram($$.sym->name);
57 define: definekw blank definesym blank blockwb {
58 ADD_OP(OP_RETURN_NO_VAL);
59 Program *prog = FinishCreatingProgram($3.acc);
60 - XtFree((char *)$3.acc);
61 $3.sym->type = MACRO_FUNCTION_SYM;
62 $3.sym->value.tag = NO_TAG;
63 $3.sym->value.val.prog = prog;
64 @@ -849,7 +845,7 @@ Program *ParseMacro(char *expr, char **m
65 const char *name)
67 Program *prog;
68 - AccumulatorData *acc = (AccumulatorData *)XtMalloc(sizeof(*acc));
69 + AccumulatorData *old;
71 #if YYDEBUG
72 int oldyydebug = yydebug;
73 @@ -859,7 +855,7 @@ Program *ParseMacro(char *expr, char **m
74 if (!name)
75 name = "--unknown--";
77 - BeginCreatingProgram(name, acc);
78 + old = BeginCreatingProgram(name);
80 /* whether we allow the "define" keyword */
81 AllowDefine = allowDefine;
82 @@ -873,8 +869,7 @@ Program *ParseMacro(char *expr, char **m
83 if (yyparse()) {
84 *msg = ErrMsg;
85 *stoppedAt = InPtr;
86 - FreeProgram(FinishCreatingProgram(acc));
87 - XtFree((char *)acc);
88 + FreeProgram(FinishCreatingProgram(old));
90 #if YYDEBUG
91 yydebug = oldyydebug;
92 @@ -884,8 +879,7 @@ Program *ParseMacro(char *expr, char **m
95 /* get the newly created program */
96 - prog = FinishCreatingProgram(acc);
97 - XtFree((char *)acc);
98 + prog = FinishCreatingProgram(old);
100 /* parse succeeded */
101 *msg = "";
102 diff --quilt old/source/interpret.c new/source/interpret.c
103 --- old/source/interpret.c
104 +++ new/source/interpret.c
105 @@ -165,13 +165,13 @@ static const char *StackUnderflowMsg = "
106 static const char *StringToNumberMsg = "string '%s' could not be converted to number";
108 /* Temporary global data for use while accumulating programs */
109 -static Symbol *LocalSymList = NULL; /* symbols local to the program */
110 -static Inst Prog[PROGRAM_SIZE]; /* the program */
111 -static Inst *ProgP; /* next free spot for code gen. */
112 -static Inst *LoopStack[LOOP_STACK_SIZE]; /* addresses of break, cont stmts */
113 -static Inst **LoopStackPtr = LoopStack; /* to fill at the end of a loop */
115 -static const char *ProgramName = "";
116 +static AccumulatorData *Accumulator;
117 +#define Prog (Accumulator->prog)
118 +#define ProgP (Accumulator->progP)
119 +#define LoopStack (Accumulator->loopStack)
120 +#define LoopStackPtr (Accumulator->loopStackPtr)
121 +#define LocalSymList (Accumulator->localSymList)
122 +#define ProgramName (Accumulator->name)
124 /* Global data for the interpreter */
125 static RestartData *Interpreter;
126 @@ -263,20 +263,18 @@ void InitMacroGlobals(void)
127 ** Start collecting instructions for a program. Clears the program
128 ** and the symbol table.
130 -void BeginCreatingProgram(const char *name, AccumulatorData *acc)
131 +AccumulatorData *BeginCreatingProgram(const char *name)
133 - /* save state */
134 - acc->localSymList = LocalSymList;
135 - memcpy(acc->prog, Prog, sizeof(*Prog) * PROGRAM_SIZE);
136 - acc->progP = ProgP;
137 - memcpy(acc->loopStack, LoopStack, sizeof(*LoopStack) * LOOP_STACK_SIZE);
138 - acc->loopStackPtr = LoopStackPtr;
139 - acc->name = ProgramName;
140 + AccumulatorData *old = Accumulator;
141 + Accumulator = (AccumulatorData *)XtMalloc(sizeof(*Accumulator));
142 + memset(Accumulator, 0, sizeof(*Accumulator));
144 LocalSymList = NULL;
145 ProgP = Prog;
146 LoopStackPtr = LoopStack;
147 ProgramName = name;
149 + return old;
153 @@ -284,16 +282,16 @@ void BeginCreatingProgram(const char *na
154 ** symbol table) as a package that ExecuteMacro can execute. This
155 ** program must be freed with FreeProgram.
157 -Program *FinishCreatingProgram(AccumulatorData *acc)
158 +Program *FinishCreatingProgram(AccumulatorData *old)
160 Program *newProg;
161 int progLen, fpOffset = 0;
162 Symbol *s;
164 newProg = (Program *)XtMalloc(sizeof(Program) + strlen(ProgramName));
165 - progLen = ((char *)ProgP) - ((char *)Prog);
166 - newProg->code = (Inst *)XtMalloc(progLen);
167 - memcpy(newProg->code, Prog, progLen);
168 + progLen = ProgP - Prog;
169 + newProg->code = (Inst *)XtMalloc(progLen * sizeof(Inst));
170 + memcpy(newProg->code, Prog, progLen * sizeof(Inst));
171 newProg->localSymList = LocalSymList;
172 strcpy(newProg->name, ProgramName);
173 newProg->refcount = 1;
174 @@ -305,13 +303,8 @@ Program *FinishCreatingProgram(Accumulat
176 DISASM(newProg->name, newProg->code, ProgP - Prog);
178 - /* restore state */
179 - LocalSymList = acc->localSymList;
180 - memcpy(Prog, acc->prog, sizeof(*Prog) * PROGRAM_SIZE);
181 - ProgP = acc->progP;
182 - memcpy(LoopStack, acc->loopStack, sizeof(*LoopStack) * LOOP_STACK_SIZE);
183 - LoopStackPtr = acc->loopStackPtr;
184 - ProgramName = acc->name;
185 + XtFree((char *)Accumulator);
186 + Accumulator = old;
188 return newProg;
190 @@ -927,9 +920,11 @@ Symbol *LookupSymbol(const char *name)
191 hash = hashName(name);
193 /* search in local symbols */
194 - s = lookupSymbol(LocalSymList, name, hash);
195 - if (NULL != s)
196 - return s;
197 + if (Accumulator) {
198 + s = lookupSymbol(LocalSymList, name, hash);
199 + if (NULL != s)
200 + return s;
203 /* search in global symbols */
204 s = lookupSymbol(GlobalSymTab[hash & GLOBAL_SYMTAB_MASK], name, hash);