makefile_bertw: always compile with -g
[nedit-bw.git] / op-not-func-in-Inst.patch
blob0067d0c61af5ead98288472af31aa7351bfcd6e6
1 ---
3 source/interpret.c | 244 +++++++++++++++++++++++++++++------------------------
4 source/interpret.h | 2
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";
12 return 0;
14 - ProgP->func = OpFns[op];
15 + ProgP->op = op;
16 ProgP++;
17 return 1;
19 @@ -639,7 +639,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 %p", (char *)inst);
32 + }
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) {
51 PUSH(result);
52 PC++;
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) {
60 PUSH(noValue);
61 PC++;
63 @@ -2892,7 +2900,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 @@ -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) {
78 PUSH(retVal);
79 PC++;
81 @@ -4361,46 +4369,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 %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);
112 - ++i;
114 - else if (j == OP_PUSH_IMMED) {
115 - printd(" <immediate %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) %p", 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(" <immediate %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) %p",
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 @@ -4411,7 +4430,9 @@ static void disasmInternal(Inst *inst, i
171 i += 2;
173 - else if (j == OP_SUBR_CALL_UNPACK_ARRAY) {
174 + break;
176 + case OP_SUBR_CALL_UNPACK_ARRAY: {
177 int args = inst[i+2].value;
178 printd(" %s", inst[i+1].sym->name);
179 if (args < 0) {
180 @@ -4422,81 +4443,92 @@ static void disasmInternal(Inst *inst, i
182 i += 2;
184 - else if (j == OP_BEGIN_ARRAY_ITER ||
185 - j == OP_BEGIN_ARRAY_ITER_ARRAY) {
186 - printd(" %s in", inst[i+1].sym->name);
187 - ++i;
189 - else if (j == OP_ARRAY_ITER) {
190 - if (!inst[i+1].value) {
191 - /* without val */
192 - printd(" %s = %s++ end-loop=(%+d) %p",
193 - inst[i+2].sym->name,
194 - inst[i+3].sym->name,
195 - inst[i+4].value,
196 - &inst[i+4] + inst[i+4].value);
197 - i += 4;
199 - else {
200 - /* with val */
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,
205 - inst[i+5].value,
206 - &inst[i+5] + inst[i+5].value);
207 - i += 5;
210 - else if (j == OP_ARRAY_ITER_ARRAY) {
211 - if (!inst[i+1].value) {
212 - /* without val */
213 - printd(" %s[] = %s++ end-loop=(%+d) %p",
214 - inst[i+2].sym->name,
215 - inst[i+3].sym->name,
216 - inst[i+4].value,
217 - &inst[i+4] + inst[i+4].value);
218 - i += 4;
220 - else {
221 - /* with val */
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,
226 - inst[i+5].value,
227 - &inst[i+5] + inst[i+5].value);
228 - i += 5;
230 + break;
232 + case OP_BEGIN_ARRAY_ITER:
233 + case OP_BEGIN_ARRAY_ITER_ARRAY:
234 + printd(" %s in", inst[i+1].sym->name);
235 + ++i;
236 + break;
238 + case OP_ARRAY_ITER:
239 + if (!inst[i+1].value) {
240 + /* without val */
241 + printd(" %s = %s++ end-loop=(%+d) %p",
242 + inst[i+2].sym->name,
243 + inst[i+3].sym->name,
244 + inst[i+4].value,
245 + &inst[i+4] + inst[i+4].value);
246 + i += 4;
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);
255 - ++i;
256 + else {
257 + /* with val */
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,
262 + inst[i+5].value,
263 + &inst[i+5] + inst[i+5].value);
264 + i += 5;
266 - else if (j == OP_ARRAY_REF_ASSIGN_SETUP) {
267 - printd(" binOp=%s nDim=%d",
268 - inst[i+1].value ? "true" : "false",
269 - inst[i+2].value);
270 - i += 2;
271 + break;
273 + case OP_ARRAY_ITER_ARRAY:
274 + if (!inst[i+1].value) {
275 + /* without val */
276 + printd(" %s[] = %s++ end-loop=(%+d) %p",
277 + inst[i+2].sym->name,
278 + inst[i+3].sym->name,
279 + inst[i+4].value,
280 + &inst[i+4] + inst[i+4].value);
281 + i += 4;
283 - else if (j == OP_PUSH_ARRAY_SYM) {
284 - printd(" %s %s",
285 - inst[i+1].sym->name,
286 - inst[i+2].value ? "createAndRef" : "refOnly");
287 - i += 2;
288 + else {
289 + /* with val */
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,
294 + inst[i+5].value,
295 + &inst[i+5] + inst[i+5].value);
296 + i += 5;
298 + break;
300 + case OP_ARRAY_REF:
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);
307 + ++i;
308 + break;
310 + case OP_ARRAY_REF_ASSIGN_SETUP:
311 + printd(" binOp=%s nDim=%d",
312 + inst[i+1].value ? "true" : "false",
313 + inst[i+2].value);
314 + i += 2;
315 + break;
317 + case OP_PUSH_ARRAY_SYM:
318 + printd(" %s %s",
319 + inst[i+1].sym->name,
320 + inst[i+2].value ? "createAndRef" : "refOnly");
321 + i += 2;
322 + break;
324 - printd("\n");
325 + default:
326 break;
329 - if (j == N_OPS) {
330 - printd(" %x\n", inst[i].value);
332 + printd("\n");
333 + break;
335 + default:
336 + printd(" <unknown op %d>\n", inst[i].op);
337 + break;
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;
345 struct SymbolRec;
347 typedef union InstTag {
348 - int (*func)(void);
349 + enum operations op;
350 int value;
351 struct SymbolRec *sym;
352 } Inst;