NULL terminate string bulk list
[nedit-bw.git] / op-not-func-in-Inst.patch
blob41c7f5a8ba1122173ea171f1500a147fbb19e4ba
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 @@ -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) {
51 PUSH(result);
52 PC++;
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) {
60 PUSH(noValue);
61 PC++;
63 @@ -2948,7 +2956,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 @@ -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) {
78 PUSH(retVal);
79 PC++;
81 @@ -4442,47 +4450,58 @@ 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 - printd(" ");
111 - dumpVal(sym->value);
113 - ++i;
115 - else if (j == OP_PUSH_IMMED) {
116 - printd(" %d", inst[i+1].value);
117 - ++i;
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);
123 - ++i;
125 - else if (j == OP_CONCAT) {
126 - printd(" nExpr=%d", inst[i+1].value);
127 - ++i;
129 + switch (inst[i].op) {
130 +#define OP(name, fn) case OP_##name:
131 +#include "ops.h"
132 +#undef OP
133 + printd(" %*s", (int)opLen, opNames[inst[i].op]);
135 + switch (inst[i].op) {
136 + case OP_PUSH_SYM:
137 + case OP_ASSIGN:
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) {
141 + printd(" ");
142 + dumpVal(inst[i+1].sym->value);
144 - else if (j == OP_SUBR_CALL) {
145 + ++i;
146 + break;
148 + case OP_PUSH_IMMED:
149 + printd(" %d", inst[i+1].value);
150 + ++i;
151 + break;
153 + case OP_BRANCH:
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);
159 + ++i;
160 + break;
162 + case OP_CONCAT:
163 + printd(" nExpr=%d", inst[i+1].value);
164 + ++i;
165 + break;
167 + case OP_SUBR_CALL: {
168 int args = inst[i+2].value;
169 printd(" %s", inst[i+1].sym->name);
170 if (args < 0) {
171 @@ -4493,7 +4512,9 @@ static void disasmInternal(Inst *inst, i
173 i += 2;
175 - else if (j == OP_UNPACKTOARGS) {
176 + break;
178 + case OP_UNPACKTOARGS: {
179 int args = inst[i+2].value;
180 if (args < 0) {
181 printd(" %d+args[] (%d)", -args - 1, args);
182 @@ -4503,85 +4524,95 @@ static void disasmInternal(Inst *inst, i
184 ++i;
186 - else if (j == OP_SUBR_CALL_STACKED_N) {
187 - printd(" %s =args[] (?)", inst[i+1].sym->name);
188 - ++i;
190 - else if (j == OP_BEGIN_ARRAY_ITER ||
191 - j == OP_BEGIN_ARRAY_ITER_ARRAY) {
192 - printd(" %s in", inst[i+1].sym->name);
193 - ++i;
195 - else if (j == OP_ARRAY_ITER) {
196 - if (!inst[i+1].value) {
197 - /* without val */
198 - printd(" %s = %s++ end-loop=(%+d) %8p",
199 - inst[i+2].sym->name,
200 - inst[i+3].sym->name,
201 - inst[i+4].value,
202 - &inst[i+4] + inst[i+4].value);
203 - i += 4;
205 - else {
206 - /* with val */
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,
211 - inst[i+5].value,
212 - &inst[i+5] + inst[i+5].value);
213 - i += 5;
216 - else if (j == OP_ARRAY_ITER_ARRAY) {
217 - if (!inst[i+1].value) {
218 - /* without val */
219 - printd(" %s[] = %s++ end-loop=(%+d) %8p",
220 - inst[i+2].sym->name,
221 - inst[i+3].sym->name,
222 - inst[i+4].value,
223 - &inst[i+4] + inst[i+4].value);
224 - i += 4;
226 - else {
227 - /* with val */
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,
232 - inst[i+5].value,
233 - &inst[i+5] + inst[i+5].value);
234 - i += 5;
236 + break;
238 + case OP_SUBR_CALL_STACKED_N:
239 + printd(" %s =args[] (?)", inst[i+1].sym->name);
240 + ++i;
241 + break;
243 + case OP_BEGIN_ARRAY_ITER:
244 + case OP_BEGIN_ARRAY_ITER_ARRAY:
245 + printd(" %s in", inst[i+1].sym->name);
246 + ++i;
247 + break;
249 + case OP_ARRAY_ITER:
250 + if (!inst[i+1].value) {
251 + /* without val */
252 + printd(" %s = %s++ end-loop=(%+d) %8p",
253 + inst[i+2].sym->name,
254 + inst[i+3].sym->name,
255 + inst[i+4].value,
256 + &inst[i+4] + inst[i+4].value);
257 + i += 4;
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);
266 - ++i;
267 + else {
268 + /* with val */
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,
273 + inst[i+5].value,
274 + &inst[i+5] + inst[i+5].value);
275 + i += 5;
277 - else if (j == OP_ARRAY_REF_ASSIGN_SETUP) {
278 - printd(" binOp=%s nDim=%d",
279 - inst[i+1].value ? "true" : "false",
280 - inst[i+2].value);
281 - i += 2;
282 + break;
284 + case OP_ARRAY_ITER_ARRAY:
285 + if (!inst[i+1].value) {
286 + /* without val */
287 + printd(" %s[] = %s++ end-loop=(%+d) %8p",
288 + inst[i+2].sym->name,
289 + inst[i+3].sym->name,
290 + inst[i+4].value,
291 + &inst[i+4] + inst[i+4].value);
292 + i += 4;
294 - else if (j == OP_PUSH_ARRAY_SYM) {
295 - printd(" %s %s",
296 - inst[i+1].sym->name,
297 - inst[i+2].value ? "createAndRef" : "refOnly");
298 - i += 2;
299 + else {
300 + /* with val */
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,
305 + inst[i+5].value,
306 + &inst[i+5] + inst[i+5].value);
307 + i += 5;
309 + break;
311 + case OP_ARRAY_REF:
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);
318 + ++i;
319 + break;
321 + case OP_ARRAY_REF_ASSIGN_SETUP:
322 + printd(" binOp=%s nDim=%d",
323 + inst[i+1].value ? "true" : "false",
324 + inst[i+2].value);
325 + i += 2;
326 + break;
328 - printd("\n");
329 + case OP_PUSH_ARRAY_SYM:
330 + printd(" %s %s",
331 + inst[i+1].sym->name,
332 + inst[i+2].value ? "createAndRef" : "refOnly");
333 + i += 2;
334 break;
338 - if (j == N_OPS) {
340 + printd("\n");
341 + break;
343 + default:
344 printd(" %x\n", inst[i].value);
345 + break;
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;
353 struct SymbolRec;
355 typedef union InstTag {
356 - int (*func)(void);
357 + enum operations op;
358 int value;
359 struct SymbolRec *sym;
360 } Inst;