3 source/interpret.c | 244 +++++++++++++++++++++++++++++------------------------
5 2 files changed, 139 insertions(+), 107 deletions(-)
7 diff --quilt old/source/interpret.c new/source/interpret.c
8 --- old/source/interpret.c
9 +++ new/source/interpret.c
10 @@ -338,7 +338,7 @@ int AddOp(int op, char **msg)
11 *msg = "macro too large";
14 - ProgP->func = OpFns[op];
19 @@ -639,7 +639,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 %p", (char *)inst);
34 /* If error return was not STAT_OK, return to caller */
35 if (status != STAT_OK) {
36 @@ -714,7 +722,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 @@ -2598,7 +2606,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 @@ -2664,7 +2672,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 @@ -2892,7 +2900,7 @@ static int returnValOrNone(int valOnStac
67 - } else if (PC->func == fetchRetVal) {
68 + } else if (PC->op == OP_FETCH_RET_VAL) {
72 @@ -3954,7 +3962,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 @@ -4361,46 +4369,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 %10p", &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(" <immediate %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) %p", 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(" <immediate %d>", inst[i+1].value);
152 + case OP_BRANCH_TRUE:
153 + case OP_BRANCH_FALSE:
154 + case OP_BRANCH_NEVER:
155 + printd(" to=(%+d) %p",
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 @@ -4411,7 +4430,9 @@ static void disasmInternal(Inst *inst, i
173 - else if (j == OP_SUBR_CALL_UNPACK_ARRAY) {
176 + case OP_SUBR_CALL_UNPACK_ARRAY: {
177 int args = inst[i+2].value;
178 printd(" %s", inst[i+1].sym->name);
180 @@ -4422,81 +4443,92 @@ static void disasmInternal(Inst *inst, i
184 - else if (j == OP_BEGIN_ARRAY_ITER ||
185 - j == OP_BEGIN_ARRAY_ITER_ARRAY) {
186 - printd(" %s in", inst[i+1].sym->name);
189 - else if (j == OP_ARRAY_ITER) {
190 - if (!inst[i+1].value) {
192 - printd(" %s = %s++ end-loop=(%+d) %p",
193 - inst[i+2].sym->name,
194 - inst[i+3].sym->name,
196 - &inst[i+4] + inst[i+4].value);
201 - printd(" %s=%s = %s++ end-loop=(%+d) %p",
202 - inst[i+2].sym->name,
203 - inst[i+3].sym->name,
204 - inst[i+4].sym->name,
206 - &inst[i+5] + inst[i+5].value);
210 - else if (j == OP_ARRAY_ITER_ARRAY) {
211 - if (!inst[i+1].value) {
213 - printd(" %s[] = %s++ end-loop=(%+d) %p",
214 - inst[i+2].sym->name,
215 - inst[i+3].sym->name,
217 - &inst[i+4] + inst[i+4].value);
222 - printd(" %s[]=%s = %s++ end-loop=(%+d) %p",
223 - inst[i+2].sym->name,
224 - inst[i+3].sym->name,
225 - inst[i+4].sym->name,
227 - &inst[i+5] + inst[i+5].value);
232 + case OP_BEGIN_ARRAY_ITER:
233 + case OP_BEGIN_ARRAY_ITER_ARRAY:
234 + printd(" %s in", inst[i+1].sym->name);
238 + case OP_ARRAY_ITER:
239 + if (!inst[i+1].value) {
241 + printd(" %s = %s++ end-loop=(%+d) %p",
242 + inst[i+2].sym->name,
243 + inst[i+3].sym->name,
245 + &inst[i+4] + inst[i+4].value);
248 - else if (j == OP_ARRAY_REF ||
249 - j == OP_ARRAY_DELETE ||
250 - j == OP_ARRAY_ASSIGN ||
251 - j == OP_ANONARRAY_INDEX_VAL ||
252 - j == OP_NAMED_ARG1 ||
253 - j == OP_NAMED_ARGN) {
254 - printd(" nDim=%d", inst[i+1].value);
258 + printd(" %s=%s = %s++ end-loop=(%+d) %p",
259 + inst[i+2].sym->name,
260 + inst[i+3].sym->name,
261 + inst[i+4].sym->name,
263 + &inst[i+5] + inst[i+5].value);
266 - else if (j == OP_ARRAY_REF_ASSIGN_SETUP) {
267 - printd(" binOp=%s nDim=%d",
268 - inst[i+1].value ? "true" : "false",
273 + case OP_ARRAY_ITER_ARRAY:
274 + if (!inst[i+1].value) {
276 + printd(" %s[] = %s++ end-loop=(%+d) %p",
277 + inst[i+2].sym->name,
278 + inst[i+3].sym->name,
280 + &inst[i+4] + inst[i+4].value);
283 - else if (j == OP_PUSH_ARRAY_SYM) {
285 - inst[i+1].sym->name,
286 - inst[i+2].value ? "createAndRef" : "refOnly");
290 + printd(" %s[]=%s = %s++ end-loop=(%+d) %p",
291 + inst[i+2].sym->name,
292 + inst[i+3].sym->name,
293 + inst[i+4].sym->name,
295 + &inst[i+5] + inst[i+5].value);
301 + case OP_ARRAY_DELETE:
302 + case OP_ARRAY_ASSIGN:
303 + case OP_ANONARRAY_INDEX_VAL:
304 + case OP_NAMED_ARG1:
305 + case OP_NAMED_ARGN:
306 + printd(" nDim=%d", inst[i+1].value);
310 + case OP_ARRAY_REF_ASSIGN_SETUP:
311 + printd(" binOp=%s nDim=%d",
312 + inst[i+1].value ? "true" : "false",
317 + case OP_PUSH_ARRAY_SYM:
319 + inst[i+1].sym->name,
320 + inst[i+2].value ? "createAndRef" : "refOnly");
330 - printd(" %x\n", inst[i].value);
336 + printd(" <unknown op %d>\n", inst[i].op);
341 diff --quilt old/source/interpret.h new/source/interpret.h
342 --- old/source/interpret.h
343 +++ new/source/interpret.h
344 @@ -62,7 +62,7 @@ struct ProgramTag;
347 typedef union InstTag {
349 + enum operations op;
351 struct SymbolRec *sym;