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