import consolidate-ops.patch
[nedit-bw.git] / consolidate-ops.patch
blob8f1672d598f1e0ecdc74e11aa1c42cd1e40a6e21
1 ---
3 source/Makefile.dependencies | 18 +++----
4 source/interpret.c | 108 +++++--------------------------------------
5 source/interpret.h | 16 ++----
6 source/ops.h | 48 +++++++++++++++++++
7 4 files changed, 78 insertions(+), 112 deletions(-)
9 diff --quilt old/source/Makefile.dependencies new/source/Makefile.dependencies
10 --- old/source/Makefile.dependencies
11 +++ new/source/Makefile.dependencies
12 @@ -12,30 +12,30 @@ highlight.o: highlight.c highlight.h ned
13 textP.h regularExp.h highlightData.h preferences.h window.h \
14 ../util/misc.h ../util/DialogF.h
15 highlightData.o: highlightData.c highlightData.h nedit.h textBuf.h \
16 highlight.h regularExp.h preferences.h help.h help_topic.h window.h \
17 regexConvert.h ../util/misc.h ../util/DialogF.h ../util/managedList.h
18 -interpret.o: interpret.c interpret.h nedit.h textBuf.h rbTree.h menu.h \
19 +interpret.o: interpret.c interpret.h ops.h nedit.h textBuf.h rbTree.h menu.h \
20 text.h
21 linkdate.o: linkdate.c
22 macro.o: macro.c macro.h nedit.h textBuf.h text.h window.h preferences.h \
23 - interpret.h rbTree.h parse.h search.h server.h shell.h smartIndent.h \
24 + interpret.h ops.h rbTree.h parse.h search.h server.h shell.h smartIndent.h \
25 userCmds.h selection.h tags.h calltips.h textDisp.h ../util/DialogF.h \
26 ../util/misc.h ../util/fileUtils.h ../util/utils.h highlight.h \
27 highlightData.h rangeset.h
28 menu.o: menu.c menu.h nedit.h textBuf.h text.h file.h window.h search.h \
29 selection.h undo.h shift.h help.h help_topic.h preferences.h tags.h \
30 - userCmds.h shell.h macro.h highlight.h highlightData.h interpret.h \
31 + userCmds.h shell.h macro.h highlight.h highlightData.h interpret.h ops.h \
32 rbTree.h smartIndent.h windowTitle.h ../util/getfiles.h \
33 ../util/DialogF.h ../util/misc.h ../util/fileUtils.h ../util/utils.h
34 nc.o: nc.c server_common.h ../util/fileUtils.h ../util/utils.h \
35 ../util/prefFile.h ../util/system.h ../util/clearcase.h
36 nedit.o: nedit.c nedit.h textBuf.h file.h preferences.h regularExp.h \
37 - selection.h tags.h menu.h macro.h server.h window.h interpret.h \
38 + selection.h tags.h menu.h macro.h server.h window.h interpret.h ops.h \
39 rbTree.h parse.h help.h help_topic.h ../util/misc.h \
40 ../util/printUtils.h ../util/fileUtils.h ../util/getfiles.h
41 -parse_noyacc.o: parse_noyacc.c parse.h interpret.h nedit.h textBuf.h \
42 +parse_noyacc.o: parse_noyacc.c parse.h interpret.h ops.h nedit.h textBuf.h \
43 rbTree.h
44 preferences.o: preferences.c preferences.h nedit.h textBuf.h text.h \
45 search.h window.h userCmds.h highlight.h highlightData.h help.h \
46 help_topic.h regularExp.h smartIndent.h windowTitle.h server.h tags.h \
47 ../util/prefFile.h ../util/misc.h ../util/DialogF.h \
48 @@ -54,14 +54,14 @@ server.o: server.c server.h window.h ned
49 macro.h menu.h preferences.h server_common.h ../util/fileUtils.h \
50 ../util/utils.h
51 server_common.o: server_common.c textBuf.h nedit.h server_common.h \
52 ../util/utils.h
53 shell.o: shell.c shell.h nedit.h textBuf.h text.h window.h preferences.h \
54 - file.h macro.h interpret.h rbTree.h ../util/DialogF.h ../util/misc.h
55 + file.h macro.h interpret.h ops.h rbTree.h ../util/DialogF.h ../util/misc.h
56 shift.o: shift.c shift.h nedit.h textBuf.h text.h window.h
57 smartIndent.o: smartIndent.c smartIndent.h nedit.h textBuf.h text.h \
58 - preferences.h interpret.h rbTree.h macro.h window.h parse.h shift.h \
59 + preferences.h interpret.h ops.h rbTree.h macro.h window.h parse.h shift.h \
60 help.h help_topic.h ../util/DialogF.h ../util/misc.h
61 tags.o: tags.c tags.h nedit.h textBuf.h text.h window.h file.h \
62 preferences.h search.h selection.h calltips.h textDisp.h \
63 ../util/DialogF.h ../util/fileUtils.h ../util/misc.h ../util/utils.h
64 text.o: text.c text.h textBuf.h textP.h textDisp.h textSel.h textDrag.h \
65 @@ -72,17 +72,17 @@ textDisp.o: textDisp.c textDisp.h textBu
66 textDrag.o: textDrag.c textDrag.h text.h textBuf.h textDisp.h textP.h
67 textSel.o: textSel.c textSel.h textP.h textBuf.h textDisp.h text.h
68 undo.o: undo.c undo.h nedit.h textBuf.h text.h search.h window.h file.h \
69 userCmds.h preferences.h
70 userCmds.o: userCmds.c userCmds.h nedit.h textBuf.h text.h preferences.h \
71 - window.h menu.h shell.h macro.h file.h interpret.h rbTree.h parse.h \
72 + window.h menu.h shell.h macro.h file.h interpret.h ops.h rbTree.h parse.h \
73 ../util/DialogF.h ../util/misc.h ../util/managedList.h
74 window.o: window.c window.h nedit.h textBuf.h textSel.h text.h textDisp.h \
75 textP.h menu.h file.h search.h undo.h preferences.h selection.h \
76 server.h shell.h macro.h highlight.h smartIndent.h userCmds.h nedit.bm \
77 n.bm windowTitle.h ../util/clearcase.h ../util/misc.h \
78 ../util/fileUtils.h ../util/utils.h
79 windowTitle.o: windowTitle.c windowTitle.h nedit.h textBuf.h \
80 preferences.h help.h help_topic.h ../util/prefFile.h ../util/misc.h \
81 ../util/DialogF.h ../util/utils.h ../util/fileUtils.h \
82 ../util/clearcase.h
83 -parse.c: parse.h textBuf.h nedit.h rbTree.h interpret.h
84 +parse.c: parse.h textBuf.h nedit.h rbTree.h interpret.h ops.h
85 diff --quilt old/source/interpret.c new/source/interpret.c
86 --- old/source/interpret.c
87 +++ new/source/interpret.c
88 @@ -80,54 +80,16 @@ static const char CVSID[] = "$Id: interp
89 enum opStatusCodes {STAT_OK=2, STAT_DONE, STAT_ERROR, STAT_PREEMPT};
91 static void addLoopAddr(Inst *addr);
92 static void saveContext(RestartData *context);
93 static void restoreContext(RestartData *context);
94 -static int returnNoVal(void);
95 -static int returnVal(void);
97 +#define OP(name, fn) static int fn(void);
98 +#include "ops.h"
99 +#undef OP
100 static int returnValOrNone(int valOnStack);
101 -static int pushSymVal(void);
102 -static int pushArgVal(void);
103 -static int pushArgCount(void);
104 -static int pushArgArray(void);
105 -static int pushArraySymVal(void);
106 -static int dupStack(void);
107 -static int add(void);
108 -static int subtract(void);
109 -static int multiply(void);
110 -static int divide(void);
111 -static int modulo(void);
112 -static int negate(void);
113 -static int increment(void);
114 -static int decrement(void);
115 -static int gt(void);
116 -static int lt(void);
117 -static int ge(void);
118 -static int le(void);
119 -static int eq(void);
120 -static int ne(void);
121 -static int bitAnd(void);
122 -static int bitOr(void);
123 -static int and(void);
124 -static int or(void);
125 -static int not(void);
126 -static int power(void);
127 -static int concat(void);
128 -static int assign(void);
129 -static int callSubroutine(void);
130 -static int fetchRetVal(void);
131 -static int branch(void);
132 -static int branchTrue(void);
133 -static int branchFalse(void);
134 -static int branchNever(void);
135 -static int arrayRef(void);
136 -static int arrayAssign(void);
137 -static int arrayRefAndAssignSetup(void);
138 -static int beginArrayIter(void);
139 -static int arrayIter(void);
140 -static int inArray(void);
141 -static int deleteArrayElement(void);
143 static void freeSymbolTable(Symbol *symTab);
144 static int errCheck(const char *s);
145 static int execError(const char *s1, const char *s2);
146 static rbTreeNode *arrayEmptyAllocator(void);
147 static rbTreeNode *arrayAllocateNode(rbTreeNode *src);
148 @@ -202,17 +164,15 @@ static WindowInfo *FocusWindow; /* w
149 static int PreemptRequest; /* passes preemption requests from called
150 routines back up to the interpreter */
152 /* Array for mapping operations to functions for performing the operations
153 Must correspond to the enum called "operations" in interpret.h */
154 -static int (*OpFns[N_OPS])() = {returnNoVal, returnVal, pushSymVal, dupStack,
155 - add, subtract, multiply, divide, modulo, negate, increment, decrement,
156 - gt, lt, ge, le, eq, ne, bitAnd, bitOr, and, or, not, power, concat,
157 - assign, callSubroutine, fetchRetVal, branch, branchTrue, branchFalse,
158 - branchNever, arrayRef, arrayAssign, beginArrayIter, arrayIter, inArray,
159 - deleteArrayElement, pushArraySymVal,
160 - arrayRefAndAssignSetup, pushArgVal, pushArgCount, pushArgArray};
161 +static int (*OpFns[])() = {
162 +#define OP(name, fn) fn,
163 +#include "ops.h"
164 +#undef OP
167 /* Stack-> symN-sym0(FP), argArray, nArgs, oldFP, retPC, argN-arg1, next, ... */
168 #define FP_ARG_ARRAY_CACHE_INDEX (-1)
169 #define FP_ARG_COUNT_INDEX (-2)
170 #define FP_OLD_FP_INDEX (-3)
171 @@ -2983,54 +2943,14 @@ static void dumpVal(DataValue dv)
172 #endif /* #ifdef DEBUG_DISASSEMBLER */
174 #ifdef DEBUG_DISASSEMBLER /* For debugging code generation */
175 static void disasm(Inst *inst, int nInstr)
177 - static const char *opNames[N_OPS] = {
178 - "RETURN_NO_VAL", /* returnNoVal */
179 - "RETURN", /* returnVal */
180 - "PUSH_SYM", /* pushSymVal */
181 - "DUP", /* dupStack */
182 - "ADD", /* add */
183 - "SUB", /* subtract */
184 - "MUL", /* multiply */
185 - "DIV", /* divide */
186 - "MOD", /* modulo */
187 - "NEGATE", /* negate */
188 - "INCR", /* increment */
189 - "DECR", /* decrement */
190 - "GT", /* gt */
191 - "LT", /* lt */
192 - "GE", /* ge */
193 - "LE", /* le */
194 - "EQ", /* eq */
195 - "NE", /* ne */
196 - "BIT_AND", /* bitAnd */
197 - "BIT_OR", /* bitOr */
198 - "AND", /* and */
199 - "OR", /* or */
200 - "NOT", /* not */
201 - "POWER", /* power */
202 - "CONCAT", /* concat */
203 - "ASSIGN", /* assign */
204 - "SUBR_CALL", /* callSubroutine */
205 - "FETCH_RET_VAL", /* fetchRetVal */
206 - "BRANCH", /* branch */
207 - "BRANCH_TRUE", /* branchTrue */
208 - "BRANCH_FALSE", /* branchFalse */
209 - "BRANCH_NEVER", /* branchNever */
210 - "ARRAY_REF", /* arrayRef */
211 - "ARRAY_ASSIGN", /* arrayAssign */
212 - "BEGIN_ARRAY_ITER", /* beginArrayIter */
213 - "ARRAY_ITER", /* arrayIter */
214 - "IN_ARRAY", /* inArray */
215 - "ARRAY_DELETE", /* deleteArrayElement */
216 - "PUSH_ARRAY_SYM", /* pushArraySymVal */
217 - "ARRAY_REF_ASSIGN_SETUP", /* arrayRefAndAssignSetup */
218 - "PUSH_ARG", /* $arg[expr] */
219 - "PUSH_ARG_COUNT", /* $arg[] */
220 - "PUSH_ARG_ARRAY" /* $arg */
221 + static const char *opNames[] = {
222 +#define OP(name, fn) #name,
223 +#include "ops.h"
224 +#undef OP
226 int i, j;
228 printf("\n");
229 for (i = 0; i < nInstr; ++i) {
230 diff --quilt old/source/interpret.h new/source/interpret.h
231 --- old/source/interpret.h
232 +++ new/source/interpret.h
233 @@ -38,19 +38,17 @@
234 events passed to action routines. Tells
235 them that they were called from a macro */
237 enum symTypes {CONST_SYM, GLOBAL_SYM, LOCAL_SYM, ARG_SYM, PROC_VALUE_SYM,
238 C_FUNCTION_SYM, MACRO_FUNCTION_SYM, ACTION_ROUTINE_SYM};
239 -#define N_OPS 43
240 -enum operations {OP_RETURN_NO_VAL, OP_RETURN, OP_PUSH_SYM, OP_DUP, OP_ADD,
241 - OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_NEGATE, OP_INCR, OP_DECR, OP_GT, OP_LT,
242 - OP_GE, OP_LE, OP_EQ, OP_NE, OP_BIT_AND, OP_BIT_OR, OP_AND, OP_OR, OP_NOT,
243 - OP_POWER, OP_CONCAT, OP_ASSIGN, OP_SUBR_CALL, OP_FETCH_RET_VAL, OP_BRANCH,
244 - OP_BRANCH_TRUE, OP_BRANCH_FALSE, OP_BRANCH_NEVER, OP_ARRAY_REF,
245 - OP_ARRAY_ASSIGN, OP_BEGIN_ARRAY_ITER, OP_ARRAY_ITER, OP_IN_ARRAY,
246 - OP_ARRAY_DELETE, OP_PUSH_ARRAY_SYM, OP_ARRAY_REF_ASSIGN_SETUP, OP_PUSH_ARG,
247 - OP_PUSH_ARG_COUNT, OP_PUSH_ARG_ARRAY};
249 +enum operations {
250 +#define OP(name, fn) OP_##name,
251 +#include "ops.h"
252 +#undef OP
253 + N_OPS
256 enum typeTags {NO_TAG, INT_TAG, STRING_TAG, ARRAY_TAG};
258 enum execReturnCodes {MACRO_TIME_LIMIT, MACRO_PREEMPT, MACRO_DONE, MACRO_ERROR};
260 diff --quilt /dev/null new/source/ops.h
261 --- /dev/null
262 +++ new/source/ops.h
263 @@ -0,0 +1,48 @@
264 +#ifndef OP
265 +#error define OP() before including this file
266 +#endif
268 +/* op name function arguments operation */
269 +OP(RETURN_NO_VAL, returnNoVal) /* rewind */
270 +OP(RETURN, returnVal) /* pop(ret), rewind, push(ret) */
271 +OP(PUSH_SYM, pushSymVal) /* sym */ /* push(sym.v) */
272 +OP(DUP, dupStack) /* pop(v), push(v,v) */
273 +OP(ADD, add) /* pop(v2,v1), push(v1 + v2) */
274 +OP(SUB, subtract) /* pop(v2,v1), push(v1 - v2) */
275 +OP(MUL, multiply) /* pop(v2,v1), push(v1 * v2) */
276 +OP(DIV, divide) /* pop(v2,v1), push(v1 / v2) */
277 +OP(MOD, modulo) /* pop(v2,v1), push(v1 % v2) */
278 +OP(NEGATE, negate) /* pop(v), push(-v) */
279 +OP(INCR, increment) /* pop(v), push(v + 1) */
280 +OP(DECR, decrement) /* pop(v), push(v - 1) */
281 +OP(GT, gt) /* pop(v2,v1), push(v1 > v2) */
282 +OP(LT, lt) /* pop(v2,v1), push(v1 < v2) */
283 +OP(GE, ge) /* pop(v2,v1), push(v1 >= v2) */
284 +OP(LE, le) /* pop(v2,v1), push(v1 <= v2) */
285 +OP(EQ, eq) /* pop(v2,v1), push(v1 == v2) */
286 +OP(NE, ne) /* pop(v2,v1), push(v1 != v2) */
287 +OP(BIT_AND, bitAnd) /* pop(v2,v1), push(v1 & v2) */
288 +OP(BIT_OR, bitOr) /* pop(v2,v1), push(v1 | v2) */
289 +OP(AND, and) /* pop(v2,v1), push(v1 && v2) */
290 +OP(OR, or) /* pop(v2,v1), push(v1 || v2) */
291 +OP(NOT, not) /* pop(v), push(!v) */
292 +OP(POWER, power) /* pop(v2,v1), push(v1 ** v2) */
293 +OP(CONCAT, concat) /* pop(s2,s1), push(s1 s2) */
294 +OP(ASSIGN, assign) /* sym */ /* pop(v), sym.v = v */
295 +OP(SUBR_CALL, callSubroutine) /* sym */ /* ret = call(sym), if PC == fetchRetVal: push(ret) */
296 +OP(FETCH_RET_VAL, fetchRetVal) /* internal error */
297 +OP(BRANCH, branch) /* off */ /* PC += off */
298 +OP(BRANCH_TRUE, branchTrue) /* off */ /* pop(v), if v: PC += off */
299 +OP(BRANCH_FALSE, branchFalse) /* off */ /* pop(v), if !v: PC += off */
300 +OP(BRANCH_NEVER, branchNever) /* off */ /* */
301 +OP(ARRAY_REF, arrayRef) /* N */ /* pop(kN..k1,a), push(a[k1..kN]) */
302 +OP(ARRAY_ASSIGN, arrayAssign) /* N */ /* pop(v,kN..k1,a), a[k1..kN]=v */
303 +OP(BEGIN_ARRAY_ITER, beginArrayIter) /* it */ /* pop(a), it=a.begin */
304 +OP(ARRAY_ITER, arrayIter) /* k,it,pc */ /* it ? (k.v=it.k, it++) : PC = pc */
305 +OP(IN_ARRAY, inArray) /* pop(a,k), push(a[k]?1:0) */
306 +OP(ARRAY_DELETE, deleteArrayElement) /*N*/ /* N>0 ? (pop(kN..k1,a), del(a[k])) : (pop(a), delall(a)) */
307 +OP(PUSH_ARRAY_SYM, pushArraySymVal) /*s,i*/ /* if i: s.v=ary()), push(s.v) */
308 +OP(ARRAY_REF_ASSIGN_SETUP, arrayRefAndAssignSetup) /*op,N*/ /* pop(v,kN..a), a[k1..kN] op= v */
309 +OP(PUSH_ARG, pushArgVal) /* pop(num), push($num) */
310 +OP(PUSH_ARG_COUNT, pushArgCount) /* push($n_args) */
311 +OP(PUSH_ARG_ARRAY, pushArgArray) /* push($args) */