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