NULL terminate string bulk list
[nedit-bw.git] / abstract-access-to-PC.patch
blob7f38284311e4ec97000967699bd8bf7ce7664b71
1 ---
3 source/interpret.c | 175 +++++++++++++++++++++++++----------------------------
4 1 file changed, 85 insertions(+), 90 deletions(-)
6 diff --quilt old/source/interpret.c new/source/interpret.c
7 --- old/source/interpret.c
8 +++ new/source/interpret.c
9 @@ -1320,6 +1320,40 @@ static void addToGlobalSymTab(Symbol *sy
10 GlobalSymTab[idx] = sym;
13 +#define GET_SYM(s) \
14 + do { \
15 + s = PC->sym; \
16 + PC++; \
17 + } while (0)
19 +#define GET_IMMED(i) \
20 + do { \
21 + i = PC->value; \
22 + PC++; \
23 + } while (0)
25 +#define GET_BRANCH(a) \
26 + do { \
27 + a = PC + PC->value; \
28 + PC++; \
29 + } while (0)
31 +#define JUMP(a) \
32 + do { \
33 + PC = (a); \
34 + } while (0)
36 +#define PUSH_RET_VAL(dv) \
37 + do { \
38 + if (PC == NULL) { \
39 + PUSH(dv); \
40 + } \
41 + else if (PC->op == OP_FETCH_RET_VAL) { \
42 + PUSH(dv); \
43 + PC++; \
44 + } \
45 + } while (0)
47 /* true, if you can pop n values */
48 #define OK_TO_POP(n) \
49 ((StackP - (n)) >= TheStack)
50 @@ -1482,8 +1516,7 @@ static int pushSymVal(void)
51 DISASM_RT(PC-1, 2);
52 STACKDUMP(0, 3);
54 - s = PC->sym;
55 - PC++;
56 + GET_SYM(s);
58 if (s->type == LOCAL_SYM) {
59 symVal = FP_GET_SYM_VAL(FrameP, s);
60 @@ -1538,8 +1571,7 @@ static int pushImmed(void)
61 DISASM_RT(PC-1, 2);
62 STACKDUMP(0, 3);
64 - immed = PC->value;
65 - PC++;
66 + GET_IMMED(immed);
68 PUSH_INT(immed);
70 @@ -1623,10 +1655,8 @@ static int pushArraySymVal(void)
71 DISASM_RT(PC-1, 3);
72 STACKDUMP(0, 3);
74 - sym = PC->sym;
75 - PC++;
76 - initEmpty = PC->value;
77 - PC++;
78 + GET_SYM(sym);
79 + GET_IMMED(initEmpty);
81 if (sym->type == LOCAL_SYM) {
82 dataPtr = &FP_GET_SYM_VAL(FrameP, sym);
83 @@ -1765,8 +1795,7 @@ static int anonArrayIndexVal(void)
84 int nextIndex, index;
85 int nDim;
87 - nDim = PC->value;
88 - PC++;
89 + GET_IMMED(nDim);
91 DISASM_RT(PC-2, 2);
92 STACKDUMP(nDim+3, 3);
93 @@ -1863,7 +1892,7 @@ static int namedArg1orN(Boolean isFirst)
94 DataValue exprVal, argsArray;
95 int nDim, index;
97 - nDim = (PC++)->value;
98 + GET_IMMED(nDim);
100 DISASM_RT(PC-2, 2);
101 STACKDUMP(nDim + (isFirst ? 2 : 1), 3);
102 @@ -1937,8 +1966,7 @@ static int assign(void)
103 DISASM_RT(PC-1, 2);
104 STACKDUMP(1, 3);
106 - sym = PC->sym;
107 - PC++;
108 + GET_SYM(sym);
110 if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) {
111 if (sym->type == ARG_SYM) {
112 @@ -2559,8 +2587,7 @@ static int concat(void)
114 int nExpr;
116 - nExpr = PC->value;
117 - PC++;
118 + GET_IMMED(nExpr);
120 DISASM_RT(PC-2, 2);
121 STACKDUMP(nExpr, 3);
122 @@ -2644,10 +2671,7 @@ static int callSubroutineFromSymbol(Symb
123 if (!sym->value.val.subr(FocusWindow, StackP,
124 nArgs, &result, &errMsg))
125 return execError(errMsg, sym->name);
126 - if (PC->op == OP_FETCH_RET_VAL) {
127 - PUSH(result);
128 - PC++;
130 + PUSH_RET_VAL(result);
131 return PreemptRequest ? STAT_PREEMPT : STAT_OK;
134 @@ -2710,10 +2734,7 @@ static int callSubroutineFromSymbol(Symb
135 sym->value.val.xtproc(FocusWindow->lastFocus,
136 (XEvent *)&key_event, argList, &numArgs);
137 XtFree((char *)argList);
138 - if (PC->op == OP_FETCH_RET_VAL) {
139 - PUSH(noValue);
140 - PC++;
142 + PUSH_RET_VAL(noValue);
143 return PreemptRequest ? STAT_PREEMPT : STAT_OK;
146 @@ -2735,8 +2756,8 @@ static int callSubroutine(void)
147 Symbol *sym;
148 int nArgs;
150 - sym = PC++->sym;
151 - nArgs = PC++->value;
152 + GET_SYM(sym);
153 + GET_IMMED(nArgs);
155 DISASM_RT(PC-3, 3);
156 STACKDUMP(nArgs > 0 ? nArgs : -nArgs, 3);
157 @@ -2760,7 +2781,7 @@ static int callSubroutineStackedN(void)
158 /* this is much like callSubroutine, but we get nArgs off the stack
159 and it will always be negative since there is always an argArray */
161 - sym = PC++->sym;
162 + GET_SYM(sym);
164 PEEK_INT(nArgs, 0);
165 DISASM_RT(PC-2, 2);
166 @@ -2875,7 +2896,7 @@ static int unpackArrayToArgs(void)
167 DISASM_RT(PC-1, 1);
168 STACKDUMP(1, 3);
170 - nArgs = PC++->value;
171 + GET_IMMED(nArgs);
172 haveNamedArgs = (nArgs < 0);
174 POP(argArray);
175 @@ -2967,24 +2988,14 @@ static int returnValOrNone(int valOnStac
176 if (valOnStack) {
177 POP(retVal);
179 + else {
180 + retVal = noValue;
183 PC = rewindFrame(&FrameP, &StackP);
185 /* push returned value, if requsted */
186 - if (PC == NULL) {
187 - if (valOnStack) {
188 - PUSH(retVal);
189 - } else {
190 - PUSH(noValue);
192 - } else if (PC->op == OP_FETCH_RET_VAL) {
193 - if (valOnStack) {
194 - PUSH(retVal);
195 - } else {
196 - PUSH(noValue);
198 - PC++;
200 + PUSH_RET_VAL(retVal);
202 /* NULL return PC indicates end of program */
203 return PC == NULL ? STAT_DONE : STAT_OK;
204 @@ -2998,10 +3009,14 @@ static int returnValOrNone(int valOnStac
206 static int branch(void)
208 + Inst *addr;
210 DISASM_RT(PC-1, 2);
211 STACKDUMP(0, 3);
213 - PC += PC->value;
214 + GET_BRANCH(addr);
215 + JUMP(addr);
217 return STAT_OK;
220 @@ -3029,12 +3044,12 @@ static int branchIf(Boolean trueOrFalse)
221 DISASM_RT(PC-1, 2);
222 STACKDUMP(1, 3);
224 + GET_BRANCH(addr);
226 POP_INT(value);
227 - addr = PC + PC->value;
228 - PC++;
230 if (!value == !trueOrFalse)
231 - PC = addr;
232 + JUMP(addr);
233 return STAT_OK;
236 @@ -3048,10 +3063,13 @@ static int branchIf(Boolean trueOrFalse)
238 static int branchNever(void)
240 + Inst *addr;
242 DISASM_RT(PC-1, 2);
243 STACKDUMP(0, 3);
245 - PC++;
246 + GET_BRANCH(addr);
248 return STAT_OK;
251 @@ -3412,8 +3430,7 @@ static int arrayRef(void)
252 char *keyString = NULL;
253 int nDim;
255 - nDim = PC->value;
256 - PC++;
257 + GET_IMMED(nDim);
259 DISASM_RT(PC-2, 2);
260 STACKDUMP(nDim+1, 3);
261 @@ -3463,8 +3480,7 @@ static int arrayAssign(void)
262 int errNum;
263 int nDim;
265 - nDim = PC->value;
266 - PC++;
267 + GET_IMMED(nDim);
269 DISASM_RT(PC-2, 1);
270 STACKDUMP(nDim+2, 3);
271 @@ -3516,10 +3532,8 @@ static int arrayRefAndAssignSetup(void)
272 char *keyString = NULL;
273 int binaryOp, nDim;
275 - binaryOp = PC->value;
276 - PC++;
277 - nDim = PC->value;
278 - PC++;
279 + GET_IMMED(binaryOp);
280 + GET_IMMED(nDim);
282 DISASM_RT(PC-3, 3);
283 STACKDUMP(nDim + (binaryOp ? 2 : 1), 3);
284 @@ -3575,8 +3589,7 @@ static int beginArrayIter(void)
285 DISASM_RT(PC-1, 2);
286 STACKDUMP(1, 3);
288 - iterator = PC->sym;
289 - PC++;
290 + GET_SYM(iterator);
292 POP(arrayVal);
294 @@ -3635,18 +3648,13 @@ static int arrayIter(void)
295 DISASM_RT(PC-1, 4);
296 STACKDUMP(0, 4);
298 - withVal = PC->value;
299 - PC++;
300 - keySym = PC->sym;
301 - PC++;
302 + GET_IMMED(withVal);
303 + GET_SYM(keySym);
304 if (withVal) {
305 - valSym = PC->sym;
306 - PC++;
307 + GET_SYM(valSym);
309 - iterator = PC->sym;
310 - PC++;
311 - branchAddr = PC + PC->value;
312 - PC++;
313 + GET_SYM(iterator);
314 + GET_BRANCH(branchAddr);
316 if (keySym->type == LOCAL_SYM) {
317 keyValPtr = &FP_GET_SYM_VAL(FrameP, keySym);
318 @@ -3695,7 +3703,7 @@ static int arrayIter(void)
319 iteratorValPtr->val.arrayPtr = arrayIterateNext(thisEntry);
321 else {
322 - PC = branchAddr;
323 + JUMP(branchAddr);
325 return(STAT_OK);
327 @@ -3716,8 +3724,7 @@ static int beginArrayIterArray(void)
328 DISASM_RT(PC-1, 2);
329 STACKDUMP(2, 3);
331 - iterator = PC->sym;
332 - PC++;
333 + GET_SYM(iterator);
335 POP(arrayVal);
336 PEEK_INT(nDims, 0);
337 @@ -3819,23 +3826,15 @@ static int arrayIterArray(void)
338 DISASM_RT(PC-1, 4);
339 STACKDUMP(1, 4);
341 - withVal = PC->value;
342 - PC++;
344 - PEEK_INT(nDims, 0);
346 - keyArraySym = PC->sym;
347 - PC++;
349 + GET_IMMED(withVal);
350 + GET_SYM(keyArraySym);
351 if (withVal) {
352 - valSym = PC->sym;
353 - PC++;
354 + GET_SYM(valSym);
356 + GET_SYM(iterator);
357 + GET_BRANCH(branchAddr);
359 - iterator = PC->sym;
360 - PC++;
361 - branchAddr = PC + PC->value;
362 - PC++;
363 + PEEK_INT(nDims, 0);
365 if (keyArraySym->type == LOCAL_SYM) {
366 keyArrayPtr = &FP_GET_SYM_VAL(FrameP, keyArraySym);
367 @@ -3902,7 +3901,7 @@ static int arrayIterArray(void)
368 iteratorValPtr->val.arrayPtr = thisEntry;
370 if (!keyFound && (!thisEntry || thisEntry->nodePtrs.color == -1)) {
371 - PC = branchAddr;
372 + JUMP(branchAddr);
375 return STAT_OK;
376 @@ -3970,8 +3969,7 @@ static int deleteArrayElement(void)
377 char *keyString = NULL;
378 int nDim;
380 - nDim = PC->value;
381 - PC++;
382 + GET_IMMED(nDim);
384 DISASM_RT(PC-2, 2);
385 STACKDUMP(nDim + 1, 3);
386 @@ -4044,10 +4042,7 @@ static int typeOfOut(void)
388 retVal.val.str.len = strlen(retVal.val.str.rep);
390 - if (PC->op == OP_FETCH_RET_VAL) {
391 - PUSH(retVal);
392 - PC++;
394 + PUSH_RET_VAL(retVal);
396 return STAT_OK;