3 source/interpret.c | 251 +++++++++++++++++++++++++++++------------------------
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";
14 - ProgP->func = OpFns[op];
19 @@ -638,7 +638,15 @@ int ContinueMacro(RestartData *continuat
21 /* Execute an instruction */
23 - status = (inst->func)();
25 +#define OP(name, fn) case OP_##name:
28 + status = (OpFns[inst->op])();
31 + status = execError("Illegal instruction at %8p", (char *)inst);
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) {
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) {
63 @@ -2951,7 +2959,7 @@ static int returnValOrNone(int valOnStac
67 - } else if (PC->func == fetchRetVal) {
68 + } else if (PC->op == OP_FETCH_RET_VAL) {
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) {
81 @@ -4423,46 +4431,57 @@ static void disasmInternal(Inst *inst, i
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);
114 - else if (j == OP_PUSH_IMMED) {
115 - printd(" %d", inst[i+1].value);
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);
124 - else if (j == OP_CONCAT) {
125 - printd(" nExpr=%d", inst[i+1].value);
128 + switch (inst[i].op) {
129 +#define OP(name, fn) case OP_##name:
132 + printd(" %*s", (int)opLen, opNames[inst[i].op]);
134 + switch (inst[i].op) {
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) {
146 + case OP_PUSH_IMMED:
147 + printd(" %d", inst[i+1].value);
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);
161 + printd(" nExpr=%d", inst[i+1].value);
165 + case OP_SUBR_CALL: {
166 int args = inst[i+2].value;
167 printd(" %s", inst[i+1].sym->name);
169 @@ -4473,7 +4492,9 @@ static void disasmInternal(Inst *inst, i
173 - else if (j == OP_UNPACKTOARGS) {
176 + case OP_UNPACKTOARGS: {
177 int args = inst[i+2].value;
179 printd(" %d+args[] (%d)", -args - 1, args);
180 @@ -4483,85 +4504,95 @@ static void disasmInternal(Inst *inst, i
184 - else if (j == OP_SUBR_CALL_STACKED_N) {
185 - printd(" %s =args[] (?)", inst[i+1].sym->name);
188 - else if (j == OP_BEGIN_ARRAY_ITER ||
189 - j == OP_BEGIN_ARRAY_ITER_ARRAY) {
190 - printd(" %s in", inst[i+1].sym->name);
193 - else if (j == OP_ARRAY_ITER) {
194 - if (!inst[i+1].value) {
196 - printd(" %s = %s++ end-loop=(%+d) %8p",
197 - inst[i+2].sym->name,
198 - inst[i+3].sym->name,
200 - &inst[i+4] + inst[i+4].value);
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,
210 - &inst[i+5] + inst[i+5].value);
214 - else if (j == OP_ARRAY_ITER_ARRAY) {
215 - if (!inst[i+1].value) {
217 - printd(" %s[] = %s++ end-loop=(%+d) %8p",
218 - inst[i+2].sym->name,
219 - inst[i+3].sym->name,
221 - &inst[i+4] + inst[i+4].value);
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,
231 - &inst[i+5] + inst[i+5].value);
236 + case OP_SUBR_CALL_STACKED_N:
237 + printd(" %s =args[] (?)", inst[i+1].sym->name);
241 + case OP_BEGIN_ARRAY_ITER:
242 + case OP_BEGIN_ARRAY_ITER_ARRAY:
243 + printd(" %s in", inst[i+1].sym->name);
247 + case OP_ARRAY_ITER:
248 + if (!inst[i+1].value) {
250 + printd(" %s = %s++ end-loop=(%+d) %8p",
251 + inst[i+2].sym->name,
252 + inst[i+3].sym->name,
254 + &inst[i+4] + inst[i+4].value);
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);
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,
272 + &inst[i+5] + inst[i+5].value);
275 - else if (j == OP_ARRAY_REF_ASSIGN_SETUP) {
276 - printd(" binOp=%s nDim=%d",
277 - inst[i+1].value ? "true" : "false",
282 + case OP_ARRAY_ITER_ARRAY:
283 + if (!inst[i+1].value) {
285 + printd(" %s[] = %s++ end-loop=(%+d) %8p",
286 + inst[i+2].sym->name,
287 + inst[i+3].sym->name,
289 + &inst[i+4] + inst[i+4].value);
292 - else if (j == OP_PUSH_ARRAY_SYM) {
294 - inst[i+1].sym->name,
295 - inst[i+2].value ? "createAndRef" : "refOnly");
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,
304 + &inst[i+5] + inst[i+5].value);
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);
319 + case OP_ARRAY_REF_ASSIGN_SETUP:
320 + printd(" binOp=%s nDim=%d",
321 + inst[i+1].value ? "true" : "false",
327 + case OP_PUSH_ARRAY_SYM:
329 + inst[i+1].sym->name,
330 + inst[i+2].value ? "createAndRef" : "refOnly");
337 - printd(" %x\n", inst[i].value);
343 + printd(" <unknown op %d>\n", inst[i].op);
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;
354 typedef union InstTag {
356 + enum operations op;
358 struct SymbolRec *sym;