Allow '>' and '@' to appear in menu items
[nedit-bw.git] / abstract-access-to-PC.patch
blob19d23441539381f7f2231576b52d78066aeb7799
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 @@ -1322,6 +1322,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 @@ -1484,8 +1518,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 @@ -1535,8 +1568,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 @@ -1620,10 +1652,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 @@ -1762,8 +1792,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 @@ -1860,7 +1889,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 @@ -1934,8 +1963,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 @@ -2558,8 +2586,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 @@ -2630,10 +2657,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 @@ -2696,10 +2720,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 @@ -2721,8 +2742,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,8 +2781,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 @@ -2914,24 +2935,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 @@ -2945,10 +2956,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 @@ -2976,12 +2991,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 @@ -2995,10 +3010,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 @@ -3357,8 +3375,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 @@ -3408,8 +3425,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 @@ -3461,10 +3477,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 @@ -3520,8 +3534,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 @@ -3580,18 +3593,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 @@ -3640,7 +3648,7 @@ static int arrayIter(void)
312 iteratorValPtr->val.arrayPtr = arrayIterateNext(thisEntry);
314 else {
315 - PC = branchAddr;
316 + JUMP(branchAddr);
318 return(STAT_OK);
320 @@ -3661,8 +3669,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 @@ -3764,23 +3771,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 @@ -3847,7 +3846,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 @@ -3915,8 +3914,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 @@ -3986,10 +3984,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;