MultipleAssignment redux
[nedit-bw.git] / op-not-func-in-Inst.patch
blob10de538feb59ccb61fff50a1f459de37f346f8b6
1 ---
3 source/interpret.c | 251 +++++++++++++++++++++++++++++------------------------
4 source/interpret.h | 2
5 2 files changed, 142 insertions(+), 111 deletions(-)
7 diff --quilt old/source/interpret.c new/source/interpret.c
8 --- old/source/interpret.c
9 +++ new/source/interpret.c
10 @@ -336,7 +336,7 @@ int AddOp(int op, char **msg)
11 *msg = "macro too large";
12 return 0;
14 - ProgP->func = OpFns[op];
15 + ProgP->op = op;
16 ProgP++;
17 return 1;
19 @@ -638,7 +638,15 @@ int ContinueMacro(RestartData *continuat
21 /* Execute an instruction */
22 inst = PC++;
23 - status = (inst->func)();
24 + switch (inst->op) {
25 +#define OP(name, fn) case OP_##name:
26 +#include "ops.h"
27 +#undef OP
28 + status = (OpFns[inst->op])();
29 + break;
30 + default:
31 + status = execError("Illegal instruction at %8p", (char *)inst);
32 + }
34 /* If error return was not STAT_OK, return to caller */
35 if (status != STAT_OK) {
36 @@ -713,7 +721,7 @@ void PreemptMacro(void)
38 void ModifyReturnedValue(RestartData *context, DataValue dv)
40 - if ((context->pc-1)->func == fetchRetVal)
41 + if ((context->pc-1)->op == OP_FETCH_RET_VAL)
42 *(context->stackP-1) = dv;
45 @@ -2618,7 +2626,7 @@ static int callSubroutineFromSymbol(Symb
46 if (!sym->value.val.subr(FocusWindow, StackP,
47 nArgs, &result, &errMsg))
48 return execError(errMsg, sym->name);
49 - if (PC->func == fetchRetVal) {
50 + if (PC->op == OP_FETCH_RET_VAL) {
51 PUSH(result);
52 PC++;
54 @@ -2684,7 +2692,7 @@ static int callSubroutineFromSymbol(Symb
55 sym->value.val.xtproc(FocusWindow->lastFocus,
56 (XEvent *)&key_event, argList, &numArgs);
57 XtFree((char *)argList);
58 - if (PC->func == fetchRetVal) {
59 + if (PC->op == OP_FETCH_RET_VAL) {
60 PUSH(noValue);
61 PC++;
63 @@ -2951,7 +2959,7 @@ static int returnValOrNone(int valOnStac
64 } else {
65 PUSH(noValue);
67 - } else if (PC->func == fetchRetVal) {
68 + } else if (PC->op == OP_FETCH_RET_VAL) {
69 if (valOnStack) {
70 PUSH(retVal);
71 } else {
72 @@ -4019,7 +4027,7 @@ static int typeOfOut(void)
74 retVal.val.str.len = strlen(retVal.val.str.rep);
76 - if (PC->func == fetchRetVal) {
77 + if (PC->op == OP_FETCH_RET_VAL) {
78 PUSH(retVal);
79 PC++;
81 @@ -4423,46 +4431,57 @@ static void disasmInternal(Inst *inst, i
82 #include "ops.h"
83 #undef OP
85 - int i, j;
86 + int i;
87 static size_t opLen;
89 if (!opLen) {
90 - for (j = 0; j < N_OPS; ++j) {
91 - if (opLen < strlen(opNames[j])) {
92 - opLen = strlen(opNames[j]);
93 + for (i = 0; i < N_OPS; ++i) {
94 + if (opLen < strlen(opNames[i])) {
95 + opLen = strlen(opNames[i]);
100 for (i = 0; i < nInstr; ++i) {
101 printd("Prog %8p", &inst[i]);
102 - for (j = 0; j < N_OPS; ++j) {
103 - if (inst[i].func == OpFns[j]) {
104 - printd(" %*s", (int)opLen, opNames[j]);
105 - if (j == OP_PUSH_SYM || j == OP_ASSIGN) {
106 - Symbol *sym = inst[i+1].sym;
107 - printd(" %s", sym->name);
108 - if (sym->type == CONST_SYM
109 - && sym->value.tag == STRING_TAG) {
110 - dumpVal(sym->value);
112 - ++i;
114 - else if (j == OP_PUSH_IMMED) {
115 - printd(" %d", inst[i+1].value);
116 - ++i;
118 - else if (j == OP_BRANCH || j == OP_BRANCH_FALSE ||
119 - j == OP_BRANCH_NEVER || j == OP_BRANCH_TRUE) {
120 - printd(" to=(%+d) %8p", inst[i+1].value,
121 - &inst[i+1] + inst[i+1].value);
122 - ++i;
124 - else if (j == OP_CONCAT) {
125 - printd(" nExpr=%d", inst[i+1].value);
126 - ++i;
128 + switch (inst[i].op) {
129 +#define OP(name, fn) case OP_##name:
130 +#include "ops.h"
131 +#undef OP
132 + printd(" %*s", (int)opLen, opNames[inst[i].op]);
134 + switch (inst[i].op) {
135 + case OP_PUSH_SYM:
136 + case OP_ASSIGN:
137 + printd(" %s", inst[i+1].sym->name);
138 + if (inst[i+1].sym->type == CONST_SYM
139 + && inst[i+1].sym->value.tag == STRING_TAG) {
140 + dumpVal(inst[i+1].sym->value);
142 - else if (j == OP_SUBR_CALL) {
143 + ++i;
144 + break;
146 + case OP_PUSH_IMMED:
147 + printd(" %d", inst[i+1].value);
148 + ++i;
149 + break;
151 + case OP_BRANCH:
152 + case OP_BRANCH_TRUE:
153 + case OP_BRANCH_FALSE:
154 + case OP_BRANCH_NEVER:
155 + printd(" to=(%+d) %8p",
156 + inst[i+1].value, &inst[i+1] + inst[i+1].value);
157 + ++i;
158 + break;
160 + case OP_CONCAT:
161 + printd(" nExpr=%d", inst[i+1].value);
162 + ++i;
163 + break;
165 + case OP_SUBR_CALL: {
166 int args = inst[i+2].value;
167 printd(" %s", inst[i+1].sym->name);
168 if (args < 0) {
169 @@ -4473,7 +4492,9 @@ static void disasmInternal(Inst *inst, i
171 i += 2;
173 - else if (j == OP_UNPACKTOARGS) {
174 + break;
176 + case OP_UNPACKTOARGS: {
177 int args = inst[i+2].value;
178 if (args < 0) {
179 printd(" %d+args[] (%d)", -args - 1, args);
180 @@ -4483,85 +4504,95 @@ static void disasmInternal(Inst *inst, i
182 ++i;
184 - else if (j == OP_SUBR_CALL_STACKED_N) {
185 - printd(" %s =args[] (?)", inst[i+1].sym->name);
186 - ++i;
188 - else if (j == OP_BEGIN_ARRAY_ITER ||
189 - j == OP_BEGIN_ARRAY_ITER_ARRAY) {
190 - printd(" %s in", inst[i+1].sym->name);
191 - ++i;
193 - else if (j == OP_ARRAY_ITER) {
194 - if (!inst[i+1].value) {
195 - /* without val */
196 - printd(" %s = %s++ end-loop=(%+d) %8p",
197 - inst[i+2].sym->name,
198 - inst[i+3].sym->name,
199 - inst[i+4].value,
200 - &inst[i+4] + inst[i+4].value);
201 - i += 4;
203 - else {
204 - /* with val */
205 - printd(" %s=%s = %s++ end-loop=(%+d) %8p",
206 - inst[i+2].sym->name,
207 - inst[i+3].sym->name,
208 - inst[i+4].sym->name,
209 - inst[i+5].value,
210 - &inst[i+5] + inst[i+5].value);
211 - i += 5;
214 - else if (j == OP_ARRAY_ITER_ARRAY) {
215 - if (!inst[i+1].value) {
216 - /* without val */
217 - printd(" %s[] = %s++ end-loop=(%+d) %8p",
218 - inst[i+2].sym->name,
219 - inst[i+3].sym->name,
220 - inst[i+4].value,
221 - &inst[i+4] + inst[i+4].value);
222 - i += 4;
224 - else {
225 - /* with val */
226 - printd(" %s[]=%s = %s++ end-loop=(%+d) %8p",
227 - inst[i+2].sym->name,
228 - inst[i+3].sym->name,
229 - inst[i+4].sym->name,
230 - inst[i+5].value,
231 - &inst[i+5] + inst[i+5].value);
232 - i += 5;
234 + break;
236 + case OP_SUBR_CALL_STACKED_N:
237 + printd(" %s =args[] (?)", inst[i+1].sym->name);
238 + ++i;
239 + break;
241 + case OP_BEGIN_ARRAY_ITER:
242 + case OP_BEGIN_ARRAY_ITER_ARRAY:
243 + printd(" %s in", inst[i+1].sym->name);
244 + ++i;
245 + break;
247 + case OP_ARRAY_ITER:
248 + if (!inst[i+1].value) {
249 + /* without val */
250 + printd(" %s = %s++ end-loop=(%+d) %8p",
251 + inst[i+2].sym->name,
252 + inst[i+3].sym->name,
253 + inst[i+4].value,
254 + &inst[i+4] + inst[i+4].value);
255 + i += 4;
257 - else if (j == OP_ARRAY_REF ||
258 - j == OP_ARRAY_DELETE ||
259 - j == OP_ARRAY_ASSIGN ||
260 - j == OP_ANONARRAY_INDEX_VAL ||
261 - j == OP_NAMED_ARG1 ||
262 - j == OP_NAMED_ARGN) {
263 - printd(" nDim=%d", inst[i+1].value);
264 - ++i;
265 + else {
266 + /* with val */
267 + printd(" %s=%s = %s++ end-loop=(%+d) %8p",
268 + inst[i+2].sym->name,
269 + inst[i+3].sym->name,
270 + inst[i+4].sym->name,
271 + inst[i+5].value,
272 + &inst[i+5] + inst[i+5].value);
273 + i += 5;
275 - else if (j == OP_ARRAY_REF_ASSIGN_SETUP) {
276 - printd(" binOp=%s nDim=%d",
277 - inst[i+1].value ? "true" : "false",
278 - inst[i+2].value);
279 - i += 2;
280 + break;
282 + case OP_ARRAY_ITER_ARRAY:
283 + if (!inst[i+1].value) {
284 + /* without val */
285 + printd(" %s[] = %s++ end-loop=(%+d) %8p",
286 + inst[i+2].sym->name,
287 + inst[i+3].sym->name,
288 + inst[i+4].value,
289 + &inst[i+4] + inst[i+4].value);
290 + i += 4;
292 - else if (j == OP_PUSH_ARRAY_SYM) {
293 - printd(" %s %s",
294 - inst[i+1].sym->name,
295 - inst[i+2].value ? "createAndRef" : "refOnly");
296 - i += 2;
297 + else {
298 + /* with val */
299 + printd(" %s[]=%s = %s++ end-loop=(%+d) %8p",
300 + inst[i+2].sym->name,
301 + inst[i+3].sym->name,
302 + inst[i+4].sym->name,
303 + inst[i+5].value,
304 + &inst[i+5] + inst[i+5].value);
305 + i += 5;
307 + break;
309 + case OP_ARRAY_REF:
310 + case OP_ARRAY_DELETE:
311 + case OP_ARRAY_ASSIGN:
312 + case OP_ANONARRAY_INDEX_VAL:
313 + case OP_NAMED_ARG1:
314 + case OP_NAMED_ARGN:
315 + printd(" nDim=%d", inst[i+1].value);
316 + ++i;
317 + break;
319 + case OP_ARRAY_REF_ASSIGN_SETUP:
320 + printd(" binOp=%s nDim=%d",
321 + inst[i+1].value ? "true" : "false",
322 + inst[i+2].value);
323 + i += 2;
324 + break;
326 - printd("\n");
327 + case OP_PUSH_ARRAY_SYM:
328 + printd(" %s %s",
329 + inst[i+1].sym->name,
330 + inst[i+2].value ? "createAndRef" : "refOnly");
331 + i += 2;
332 break;
336 - if (j == N_OPS) {
337 - printd(" %x\n", inst[i].value);
339 + printd("\n");
340 + break;
342 + default:
343 + printd(" <unknown op %d>\n", inst[i].op);
344 + break;
348 diff --quilt old/source/interpret.h new/source/interpret.h
349 --- old/source/interpret.h
350 +++ new/source/interpret.h
351 @@ -62,7 +62,7 @@ struct ProgramTag;
352 struct SymbolRec;
354 typedef union InstTag {
355 - int (*func)(void);
356 + enum operations op;
357 int value;
358 struct SymbolRec *sym;
359 } Inst;