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 @@ -2615,7 +2623,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 @@ -2681,7 +2689,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 @@ -2948,7 +2956,7 @@ static int returnValOrNone(int valOnStac
67 - } else if (PC->func == fetchRetVal) {
68 + } else if (PC->op == OP_FETCH_RET_VAL) {
72 @@ -4015,7 +4023,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 @@ -4442,47 +4450,58 @@ 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) {
111 - dumpVal(sym->value);
115 - else if (j == OP_PUSH_IMMED) {
116 - printd(" %d", inst[i+1].value);
119 - else if (j == OP_BRANCH || j == OP_BRANCH_FALSE ||
120 - j == OP_BRANCH_NEVER || j == OP_BRANCH_TRUE) {
121 - printd(" to=(%+d) %8p", inst[i+1].value,
122 - &inst[i+1] + inst[i+1].value);
125 - else if (j == OP_CONCAT) {
126 - printd(" nExpr=%d", inst[i+1].value);
129 + switch (inst[i].op) {
130 +#define OP(name, fn) case OP_##name:
133 + printd(" %*s", (int)opLen, opNames[inst[i].op]);
135 + switch (inst[i].op) {
138 + printd(" %s", inst[i+1].sym->name);
139 + if (inst[i+1].sym->type == CONST_SYM
140 + && inst[i+1].sym->value.tag == STRING_TAG) {
142 + dumpVal(inst[i+1].sym->value);
144 - else if (j == OP_SUBR_CALL) {
148 + case OP_PUSH_IMMED:
149 + printd(" %d", inst[i+1].value);
154 + case OP_BRANCH_TRUE:
155 + case OP_BRANCH_FALSE:
156 + case OP_BRANCH_NEVER:
157 + printd(" to=(%+d) %8p",
158 + inst[i+1].value, &inst[i+1] + inst[i+1].value);
163 + printd(" nExpr=%d", inst[i+1].value);
167 + case OP_SUBR_CALL: {
168 int args = inst[i+2].value;
169 printd(" %s", inst[i+1].sym->name);
171 @@ -4493,7 +4512,9 @@ static void disasmInternal(Inst *inst, i
175 - else if (j == OP_UNPACKTOARGS) {
178 + case OP_UNPACKTOARGS: {
179 int args = inst[i+2].value;
181 printd(" %d+args[] (%d)", -args - 1, args);
182 @@ -4503,85 +4524,95 @@ static void disasmInternal(Inst *inst, i
186 - else if (j == OP_SUBR_CALL_STACKED_N) {
187 - printd(" %s =args[] (?)", inst[i+1].sym->name);
190 - else if (j == OP_BEGIN_ARRAY_ITER ||
191 - j == OP_BEGIN_ARRAY_MULTI_ITER_ARRAY) {
192 - printd(" %s in", inst[i+1].sym->name);
195 - else if (j == OP_ARRAY_ITER) {
196 - if (!inst[i+1].value) {
198 - printd(" %s = %s++ end-loop=(%+d) %8p",
199 - inst[i+2].sym->name,
200 - inst[i+3].sym->name,
202 - &inst[i+4] + inst[i+4].value);
207 - printd(" %s=%s = %s++ end-loop=(%+d) %8p",
208 - inst[i+2].sym->name,
209 - inst[i+3].sym->name,
210 - inst[i+4].sym->name,
212 - &inst[i+5] + inst[i+5].value);
216 - else if (j == OP_ARRAY_MULTI_ITER_ARRAY) {
217 - if (!inst[i+1].value) {
219 - printd(" %s[] = %s++ end-loop=(%+d) %8p",
220 - inst[i+2].sym->name,
221 - inst[i+3].sym->name,
223 - &inst[i+4] + inst[i+4].value);
228 - printd(" %s[]=%s = %s++ end-loop=(%+d) %8p",
229 - inst[i+2].sym->name,
230 - inst[i+3].sym->name,
231 - inst[i+4].sym->name,
233 - &inst[i+5] + inst[i+5].value);
238 + case OP_SUBR_CALL_STACKED_N:
239 + printd(" %s =args[] (?)", inst[i+1].sym->name);
243 + case OP_BEGIN_ARRAY_ITER:
244 + case OP_BEGIN_ARRAY_MULTI_ITER_ARRAY:
245 + printd(" %s in", inst[i+1].sym->name);
249 + case OP_ARRAY_ITER:
250 + if (!inst[i+1].value) {
252 + printd(" %s = %s++ end-loop=(%+d) %8p",
253 + inst[i+2].sym->name,
254 + inst[i+3].sym->name,
256 + &inst[i+4] + inst[i+4].value);
259 - else if (j == OP_ARRAY_REF ||
260 - j == OP_ARRAY_DELETE ||
261 - j == OP_ARRAY_ASSIGN ||
262 - j == OP_ANONARRAY_INDEX_VAL ||
263 - j == OP_NAMED_ARG1 ||
264 - j == OP_NAMED_ARGN) {
265 - printd(" nDim=%d", inst[i+1].value);
269 + printd(" %s=%s = %s++ end-loop=(%+d) %8p",
270 + inst[i+2].sym->name,
271 + inst[i+3].sym->name,
272 + inst[i+4].sym->name,
274 + &inst[i+5] + inst[i+5].value);
277 - else if (j == OP_ARRAY_REF_ASSIGN_SETUP) {
278 - printd(" binOp=%s nDim=%d",
279 - inst[i+1].value ? "true" : "false",
284 + case OP_ARRAY_MULTI_ITER_ARRAY:
285 + if (!inst[i+1].value) {
287 + printd(" %s[] = %s++ end-loop=(%+d) %8p",
288 + inst[i+2].sym->name,
289 + inst[i+3].sym->name,
291 + &inst[i+4] + inst[i+4].value);
294 - else if (j == OP_PUSH_ARRAY_SYM) {
296 - inst[i+1].sym->name,
297 - inst[i+2].value ? "createAndRef" : "refOnly");
301 + printd(" %s[]=%s = %s++ end-loop=(%+d) %8p",
302 + inst[i+2].sym->name,
303 + inst[i+3].sym->name,
304 + inst[i+4].sym->name,
306 + &inst[i+5] + inst[i+5].value);
312 + case OP_ARRAY_DELETE:
313 + case OP_ARRAY_ASSIGN:
314 + case OP_ANONARRAY_INDEX_VAL:
315 + case OP_NAMED_ARG1:
316 + case OP_NAMED_ARGN:
317 + printd(" nDim=%d", inst[i+1].value);
321 + case OP_ARRAY_REF_ASSIGN_SETUP:
322 + printd(" binOp=%s nDim=%d",
323 + inst[i+1].value ? "true" : "false",
329 + case OP_PUSH_ARRAY_SYM:
331 + inst[i+1].sym->name,
332 + inst[i+2].value ? "createAndRef" : "refOnly");
344 printd(" %x\n", inst[i].value);
349 diff --quilt old/source/interpret.h new/source/interpret.h
350 --- old/source/interpret.h
351 +++ new/source/interpret.h
352 @@ -62,7 +62,7 @@ struct ProgramTag;
355 typedef union InstTag {
357 + enum operations op;
359 struct SymbolRec *sym;