use StringToNumEnd() for check of numeric keys
[nedit-bw.git] / abstract-access-to-PC.patch
blob82835dbea3209cfd3b8f5bbb2cef3ad01dea7259
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 @@ -2561,8 +2589,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 @@ -2647,10 +2674,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 @@ -2713,10 +2737,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 @@ -2738,8 +2759,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 @@ -2777,8 +2798,8 @@ static int callSubroutineUnpackArray(voi
159 DISASM_RT(PC-1, 1);
161 - sym = PC++->sym;
162 - nArgs = PC++->value;
163 + GET_SYM(sym);
164 + GET_IMMED(nArgs);
166 if (nArgs < 0) {
167 haveNamedArgs = 1;
168 @@ -2942,24 +2963,14 @@ static int returnValOrNone(int valOnStac
169 if (valOnStack) {
170 POP(retVal);
172 + else {
173 + retVal = noValue;
176 PC = rewindFrame(&FrameP, &StackP);
178 /* push returned value, if requsted */
179 - if (PC == NULL) {
180 - if (valOnStack) {
181 - PUSH(retVal);
182 - } else {
183 - PUSH(noValue);
185 - } else if (PC->op == OP_FETCH_RET_VAL) {
186 - if (valOnStack) {
187 - PUSH(retVal);
188 - } else {
189 - PUSH(noValue);
191 - PC++;
193 + PUSH_RET_VAL(retVal);
195 /* NULL return PC indicates end of program */
196 return PC == NULL ? STAT_DONE : STAT_OK;
197 @@ -2973,10 +2984,14 @@ static int returnValOrNone(int valOnStac
199 static int branch(void)
201 + Inst *addr;
203 DISASM_RT(PC-1, 2);
204 STACKDUMP(0, 3);
206 - PC += PC->value;
207 + GET_BRANCH(addr);
208 + JUMP(addr);
210 return STAT_OK;
213 @@ -3004,12 +3019,12 @@ static int branchIf(Boolean trueOrFalse)
214 DISASM_RT(PC-1, 2);
215 STACKDUMP(1, 3);
217 + GET_BRANCH(addr);
219 POP_INT(value);
220 - addr = PC + PC->value;
221 - PC++;
223 if (!value == !trueOrFalse)
224 - PC = addr;
225 + JUMP(addr);
226 return STAT_OK;
229 @@ -3023,10 +3038,13 @@ static int branchIf(Boolean trueOrFalse)
231 static int branchNever(void)
233 + Inst *addr;
235 DISASM_RT(PC-1, 2);
236 STACKDUMP(0, 3);
238 - PC++;
239 + GET_BRANCH(addr);
241 return STAT_OK;
244 @@ -3387,8 +3405,7 @@ static int arrayRef(void)
245 char *keyString = NULL;
246 int nDim;
248 - nDim = PC->value;
249 - PC++;
250 + GET_IMMED(nDim);
252 DISASM_RT(PC-2, 2);
253 STACKDUMP(nDim+1, 3);
254 @@ -3438,8 +3455,7 @@ static int arrayAssign(void)
255 int errNum;
256 int nDim;
258 - nDim = PC->value;
259 - PC++;
260 + GET_IMMED(nDim);
262 DISASM_RT(PC-2, 1);
263 STACKDUMP(nDim+2, 3);
264 @@ -3491,10 +3507,8 @@ static int arrayRefAndAssignSetup(void)
265 char *keyString = NULL;
266 int binaryOp, nDim;
268 - binaryOp = PC->value;
269 - PC++;
270 - nDim = PC->value;
271 - PC++;
272 + GET_IMMED(binaryOp);
273 + GET_IMMED(nDim);
275 DISASM_RT(PC-3, 3);
276 STACKDUMP(nDim + (binaryOp ? 2 : 1), 3);
277 @@ -3550,8 +3564,7 @@ static int beginArrayIter(void)
278 DISASM_RT(PC-1, 2);
279 STACKDUMP(1, 3);
281 - iterator = PC->sym;
282 - PC++;
283 + GET_SYM(iterator);
285 POP(arrayVal);
287 @@ -3610,18 +3623,13 @@ static int arrayIter(void)
288 DISASM_RT(PC-1, 4);
289 STACKDUMP(0, 4);
291 - withVal = PC->value;
292 - PC++;
293 - keySym = PC->sym;
294 - PC++;
295 + GET_IMMED(withVal);
296 + GET_SYM(keySym);
297 if (withVal) {
298 - valSym = PC->sym;
299 - PC++;
300 + GET_SYM(valSym);
302 - iterator = PC->sym;
303 - PC++;
304 - branchAddr = PC + PC->value;
305 - PC++;
306 + GET_SYM(iterator);
307 + GET_BRANCH(branchAddr);
309 if (keySym->type == LOCAL_SYM) {
310 keyValPtr = &FP_GET_SYM_VAL(FrameP, keySym);
311 @@ -3670,7 +3678,7 @@ static int arrayIter(void)
312 iteratorValPtr->val.arrayPtr = arrayIterateNext(thisEntry);
314 else {
315 - PC = branchAddr;
316 + JUMP(branchAddr);
318 return(STAT_OK);
320 @@ -3691,8 +3699,7 @@ static int beginArrayIterArray(void)
321 DISASM_RT(PC-1, 2);
322 STACKDUMP(2, 3);
324 - iterator = PC->sym;
325 - PC++;
326 + GET_SYM(iterator);
328 POP(arrayVal);
329 PEEK_INT(nDims, 0);
330 @@ -3794,23 +3801,15 @@ static int arrayIterArray(void)
331 DISASM_RT(PC-1, 4);
332 STACKDUMP(1, 4);
334 - withVal = PC->value;
335 - PC++;
337 - PEEK_INT(nDims, 0);
339 - keyArraySym = PC->sym;
340 - PC++;
342 + GET_IMMED(withVal);
343 + GET_SYM(keyArraySym);
344 if (withVal) {
345 - valSym = PC->sym;
346 - PC++;
347 + GET_SYM(valSym);
349 + GET_SYM(iterator);
350 + GET_BRANCH(branchAddr);
352 - iterator = PC->sym;
353 - PC++;
354 - branchAddr = PC + PC->value;
355 - PC++;
356 + PEEK_INT(nDims, 0);
358 if (keyArraySym->type == LOCAL_SYM) {
359 keyArrayPtr = &FP_GET_SYM_VAL(FrameP, keyArraySym);
360 @@ -3877,7 +3876,7 @@ static int arrayIterArray(void)
361 iteratorValPtr->val.arrayPtr = thisEntry;
363 if (!keyFound && (!thisEntry || thisEntry->nodePtrs.color == -1)) {
364 - PC = branchAddr;
365 + JUMP(branchAddr);
368 return STAT_OK;
369 @@ -3945,8 +3944,7 @@ static int deleteArrayElement(void)
370 char *keyString = NULL;
371 int nDim;
373 - nDim = PC->value;
374 - PC++;
375 + GET_IMMED(nDim);
377 DISASM_RT(PC-2, 2);
378 STACKDUMP(nDim + 1, 3);
379 @@ -4019,10 +4017,7 @@ static int typeOfOut(void)
381 retVal.val.str.len = strlen(retVal.val.str.rep);
383 - if (PC->op == OP_FETCH_RET_VAL) {
384 - PUSH(retVal);
385 - PC++;
387 + PUSH_RET_VAL(retVal);
389 return STAT_OK;