This patch consolidates the macro op definition and declaration, plus a little
documentation.
Its done by a new header "ops.h" where all ops are defined. This header is
than included in the right place with a definition of the OP() macro.
The documentation idea is borrowed from code from Tony and slightly adjusted.
---
source/Makefile.dependencies | 16 +++---
source/interpret.c | 108 +++++--------------------------------------
source/interpret.h | 16 ++----
source/ops.h | 48 +++++++++++++++++++
4 files changed, 77 insertions(+), 111 deletions(-)
diff --quilt old/source/Makefile.dependencies new/source/Makefile.dependencies
--- old/source/Makefile.dependencies
+++ new/source/Makefile.dependencies
@@ -12,30 +12,30 @@ highlight.o: highlight.c highlight.h ned
textP.h regularExp.h highlightData.h preferences.h window.h \
../util/misc.h ../util/DialogF.h
highlightData.o: highlightData.c highlightData.h nedit.h textBuf.h \
highlight.h regularExp.h preferences.h help.h help_topic.h window.h \
regexConvert.h ../util/misc.h ../util/DialogF.h ../util/managedList.h
-interpret.o: interpret.c interpret.h nedit.h textBuf.h rbTree.h menu.h \
+interpret.o: interpret.c interpret.h ops.h nedit.h textBuf.h rbTree.h menu.h \
text.h
linkdate.o: linkdate.c
macro.o: macro.c macro.h nedit.h textBuf.h text.h window.h preferences.h \
- interpret.h rbTree.h parse.h search.h server.h shell.h smartIndent.h \
+ interpret.h ops.h rbTree.h parse.h search.h server.h shell.h smartIndent.h \
userCmds.h selection.h tags.h calltips.h textDisp.h ../util/DialogF.h \
../util/misc.h ../util/fileUtils.h ../util/utils.h highlight.h \
highlightData.h rangeset.h
menu.o: menu.c menu.h nedit.h textBuf.h text.h file.h window.h search.h \
selection.h undo.h shift.h help.h help_topic.h preferences.h tags.h \
- userCmds.h shell.h macro.h highlight.h highlightData.h interpret.h \
+ userCmds.h shell.h macro.h highlight.h highlightData.h interpret.h ops.h \
rbTree.h smartIndent.h windowTitle.h ../util/getfiles.h \
../util/DialogF.h ../util/misc.h ../util/fileUtils.h ../util/utils.h
nc.o: nc.c server_common.h ../util/fileUtils.h ../util/utils.h \
../util/prefFile.h ../util/system.h ../util/clearcase.h
nedit.o: nedit.c nedit.h textBuf.h file.h preferences.h regularExp.h \
- selection.h tags.h menu.h macro.h server.h window.h interpret.h \
+ selection.h tags.h menu.h macro.h server.h window.h interpret.h ops.h \
rbTree.h parse.h help.h help_topic.h ../util/misc.h \
../util/printUtils.h ../util/fileUtils.h ../util/getfiles.h
-parse_noyacc.o: parse_noyacc.c parse.h interpret.h nedit.h textBuf.h \
+parse_noyacc.o: parse_noyacc.c parse.h interpret.h ops.h nedit.h textBuf.h \
rbTree.h
preferences.o: preferences.c preferences.h nedit.h textBuf.h text.h \
search.h window.h userCmds.h highlight.h highlightData.h help.h \
help_topic.h regularExp.h smartIndent.h windowTitle.h server.h tags.h \
../util/prefFile.h ../util/misc.h ../util/DialogF.h \
@@ -54,14 +54,14 @@ server.o: server.c server.h window.h ned
macro.h menu.h preferences.h server_common.h ../util/fileUtils.h \
../util/utils.h
server_common.o: server_common.c textBuf.h nedit.h server_common.h \
../util/utils.h
shell.o: shell.c shell.h nedit.h textBuf.h text.h window.h preferences.h \
- file.h macro.h interpret.h rbTree.h ../util/DialogF.h ../util/misc.h
+ file.h macro.h interpret.h ops.h rbTree.h ../util/DialogF.h ../util/misc.h
shift.o: shift.c shift.h nedit.h textBuf.h text.h window.h
smartIndent.o: smartIndent.c smartIndent.h nedit.h textBuf.h text.h \
- preferences.h interpret.h rbTree.h macro.h window.h parse.h shift.h \
+ preferences.h interpret.h ops.h rbTree.h macro.h window.h parse.h shift.h \
help.h help_topic.h ../util/DialogF.h ../util/misc.h
tags.o: tags.c tags.h nedit.h textBuf.h text.h window.h file.h \
preferences.h search.h selection.h calltips.h textDisp.h \
../util/DialogF.h ../util/fileUtils.h ../util/misc.h ../util/utils.h
text.o: text.c text.h textBuf.h textP.h textDisp.h textSel.h textDrag.h \
@@ -72,11 +72,11 @@ textDisp.o: textDisp.c textDisp.h textBu
textDrag.o: textDrag.c textDrag.h text.h textBuf.h textDisp.h textP.h
textSel.o: textSel.c textSel.h textP.h textBuf.h textDisp.h text.h
undo.o: undo.c undo.h nedit.h textBuf.h text.h search.h window.h file.h \
userCmds.h preferences.h
userCmds.o: userCmds.c userCmds.h nedit.h textBuf.h text.h preferences.h \
- window.h menu.h shell.h macro.h file.h interpret.h rbTree.h parse.h \
+ window.h menu.h shell.h macro.h file.h interpret.h ops.h rbTree.h parse.h \
../util/DialogF.h ../util/misc.h ../util/managedList.h
window.o: window.c window.h nedit.h textBuf.h textSel.h text.h textDisp.h \
textP.h menu.h file.h search.h undo.h preferences.h selection.h \
server.h shell.h macro.h highlight.h smartIndent.h userCmds.h nedit.bm \
n.bm windowTitle.h ../util/clearcase.h ../util/misc.h \
diff --quilt old/source/interpret.c new/source/interpret.c
--- old/source/interpret.c
+++ new/source/interpret.c
@@ -80,54 +80,16 @@ static const char CVSID[] = "$Id: interp
enum opStatusCodes {STAT_OK=2, STAT_DONE, STAT_ERROR, STAT_PREEMPT};
static void addLoopAddr(Inst *addr);
static void saveContext(RestartData *context);
static void restoreContext(RestartData *context);
-static int returnNoVal(void);
-static int returnVal(void);
+
+#define OP(name, fn) static int fn(void);
+#include "ops.h"
+#undef OP
static int returnValOrNone(int valOnStack);
-static int pushSymVal(void);
-static int pushArgVal(void);
-static int pushArgCount(void);
-static int pushArgArray(void);
-static int pushArraySymVal(void);
-static int dupStack(void);
-static int add(void);
-static int subtract(void);
-static int multiply(void);
-static int divide(void);
-static int modulo(void);
-static int negate(void);
-static int increment(void);
-static int decrement(void);
-static int gt(void);
-static int lt(void);
-static int ge(void);
-static int le(void);
-static int eq(void);
-static int ne(void);
-static int bitAnd(void);
-static int bitOr(void);
-static int and(void);
-static int or(void);
-static int not(void);
-static int power(void);
-static int concat(void);
-static int assign(void);
-static int callSubroutine(void);
-static int fetchRetVal(void);
-static int branch(void);
-static int branchTrue(void);
-static int branchFalse(void);
-static int branchNever(void);
-static int arrayRef(void);
-static int arrayAssign(void);
-static int arrayRefAndAssignSetup(void);
-static int beginArrayIter(void);
-static int arrayIter(void);
-static int inArray(void);
-static int deleteArrayElement(void);
+
static void freeSymbolTable(Symbol *symTab);
static int errCheck(const char *s);
static int execError(const char *s1, const char *s2);
static rbTreeNode *arrayEmptyAllocator(void);
static rbTreeNode *arrayAllocateNode(rbTreeNode *src);
@@ -200,17 +162,15 @@ static WindowInfo *FocusWindow; /* w
static int PreemptRequest; /* passes preemption requests from called
routines back up to the interpreter */
/* Array for mapping operations to functions for performing the operations
Must correspond to the enum called "operations" in interpret.h */
-static int (*OpFns[N_OPS])() = {returnNoVal, returnVal, pushSymVal, dupStack,
- add, subtract, multiply, divide, modulo, negate, increment, decrement,
- gt, lt, ge, le, eq, ne, bitAnd, bitOr, and, or, not, power, concat,
- assign, callSubroutine, fetchRetVal, branch, branchTrue, branchFalse,
- branchNever, arrayRef, arrayAssign, beginArrayIter, arrayIter, inArray,
- deleteArrayElement, pushArraySymVal,
- arrayRefAndAssignSetup, pushArgVal, pushArgCount, pushArgArray};
+static int (*OpFns[])() = {
+#define OP(name, fn) fn,
+#include "ops.h"
+#undef OP
+};
/* Stack-> symN-sym0(FP), argArray, nArgs, oldFP, retPC, argN-arg1, next, ...
*/
#define FP_ARG_ARRAY_CACHE_INDEX (-1)
#define FP_ARG_COUNT_INDEX (-2)
#define FP_OLD_FP_INDEX (-3)
@@ -2911,54 +2871,14 @@ static void dumpVal(DataValue dv)
#endif /* #ifdef DEBUG_DISASSEMBLER */
#ifdef DEBUG_DISASSEMBLER /* For debugging code generation */
static void disasm(Inst *inst, int nInstr)
{
- static const char *opNames[N_OPS] = {
- "RETURN_NO_VAL", /* returnNoVal */
- "RETURN", /* returnVal */
- "PUSH_SYM", /* pushSymVal */
- "DUP", /* dupStack */
- "ADD", /* add */
- "SUB", /* subtract */
- "MUL", /* multiply */
- "DIV", /* divide */
- "MOD", /* modulo */
- "NEGATE", /* negate */
- "INCR", /* increment */
- "DECR", /* decrement */
- "GT", /* gt */
- "LT", /* lt */
- "GE", /* ge */
- "LE", /* le */
- "EQ", /* eq */
- "NE", /* ne */
- "BIT_AND", /* bitAnd */
- "BIT_OR", /* bitOr */
- "AND", /* and */
- "OR", /* or */
- "NOT", /* not */
- "POWER", /* power */
- "CONCAT", /* concat */
- "ASSIGN", /* assign */
- "SUBR_CALL", /* callSubroutine */
- "FETCH_RET_VAL", /* fetchRetVal */
- "BRANCH", /* branch */
- "BRANCH_TRUE", /* branchTrue */
- "BRANCH_FALSE", /* branchFalse */
- "BRANCH_NEVER", /* branchNever */
- "ARRAY_REF", /* arrayRef */
- "ARRAY_ASSIGN", /* arrayAssign */
- "BEGIN_ARRAY_ITER", /* beginArrayIter */
- "ARRAY_ITER", /* arrayIter */
- "IN_ARRAY", /* inArray */
- "ARRAY_DELETE", /* deleteArrayElement */
- "PUSH_ARRAY_SYM", /* pushArraySymVal */
- "ARRAY_REF_ASSIGN_SETUP", /* arrayRefAndAssignSetup */
- "PUSH_ARG", /* $arg[expr] */
- "PUSH_ARG_COUNT", /* $arg[] */
- "PUSH_ARG_ARRAY" /* $arg */
+ static const char *opNames[] = {
+#define OP(name, fn) #name,
+#include "ops.h"
+#undef OP
};
int i, j;
printf("\n");
for (i = 0; i < nInstr; ++i) {
diff --quilt old/source/interpret.h new/source/interpret.h
--- old/source/interpret.h
+++ new/source/interpret.h
@@ -38,19 +38,17 @@
events passed to action routines. Tells
them that they were called from a macro */
enum symTypes {CONST_SYM, GLOBAL_SYM, LOCAL_SYM, ARG_SYM, PROC_VALUE_SYM,
C_FUNCTION_SYM, MACRO_FUNCTION_SYM, ACTION_ROUTINE_SYM};
-#define N_OPS 43
-enum operations {OP_RETURN_NO_VAL, OP_RETURN, OP_PUSH_SYM, OP_DUP, OP_ADD,
- OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_NEGATE, OP_INCR, OP_DECR, OP_GT, OP_LT,
- OP_GE, OP_LE, OP_EQ, OP_NE, OP_BIT_AND, OP_BIT_OR, OP_AND, OP_OR, OP_NOT,
- OP_POWER, OP_CONCAT, OP_ASSIGN, OP_SUBR_CALL, OP_FETCH_RET_VAL, OP_BRANCH,
- OP_BRANCH_TRUE, OP_BRANCH_FALSE, OP_BRANCH_NEVER, OP_ARRAY_REF,
- OP_ARRAY_ASSIGN, OP_BEGIN_ARRAY_ITER, OP_ARRAY_ITER, OP_IN_ARRAY,
- OP_ARRAY_DELETE, OP_PUSH_ARRAY_SYM, OP_ARRAY_REF_ASSIGN_SETUP, OP_PUSH_ARG,
- OP_PUSH_ARG_COUNT, OP_PUSH_ARG_ARRAY};
+
+enum operations {
+#define OP(name, fn) OP_##name,
+#include "ops.h"
+#undef OP
+ N_OPS
+};
enum typeTags {NO_TAG, INT_TAG, STRING_TAG, ARRAY_TAG};
enum execReturnCodes {MACRO_TIME_LIMIT, MACRO_PREEMPT, MACRO_DONE,
MACRO_ERROR};
diff --quilt /dev/null new/source/ops.h
--- /dev/null
+++ new/source/ops.h
@@ -0,0 +1,48 @@
+#ifndef OP
+#error define OP() before including this file
+#endif
+
+/* op name function arguments operation */
+OP(RETURN_NO_VAL, returnNoVal) /* rewind */
+OP(RETURN, returnVal) /* pop(ret), rewind,
push(ret) */
+OP(PUSH_SYM, pushSymVal) /* sym */ /* push(sym.v) */
+OP(DUP, dupStack) /* pop(v), push(v,v) */
+OP(ADD, add) /* pop(v2,v1), push(v1 +
v2) */
+OP(SUB, subtract) /* pop(v2,v1), push(v1 -
v2) */
+OP(MUL, multiply) /* pop(v2,v1), push(v1 *
v2) */
+OP(DIV, divide) /* pop(v2,v1), push(v1 /
v2) */
+OP(MOD, modulo) /* pop(v2,v1), push(v1 %
v2) */
+OP(NEGATE, negate) /* pop(v), push(-v) */
+OP(INCR, increment) /* pop(v), push(v + 1) */
+OP(DECR, decrement) /* pop(v), push(v - 1) */
+OP(GT, gt) /* pop(v2,v1), push(v1 >
v2) */
+OP(LT, lt) /* pop(v2,v1), push(v1 <
v2) */
+OP(GE, ge) /* pop(v2,v1), push(v1 >=
v2) */
+OP(LE, le) /* pop(v2,v1), push(v1 <=
v2) */
+OP(EQ, eq) /* pop(v2,v1), push(v1 ==
v2) */
+OP(NE, ne) /* pop(v2,v1), push(v1 !=
v2) */
+OP(BIT_AND, bitAnd) /* pop(v2,v1), push(v1 &
v2) */
+OP(BIT_OR, bitOr) /* pop(v2,v1), push(v1 |
v2) */
+OP(AND, and) /* pop(v2,v1), push(v1 &&
v2) */
+OP(OR, or) /* pop(v2,v1), push(v1 ||
v2) */
+OP(NOT, not) /* pop(v), push(!v) */
+OP(POWER, power) /* pop(v2,v1), push(v1 **
v2) */
+OP(CONCAT, concat) /* pop(s2,s1), push(s1
s2) */
+OP(ASSIGN, assign) /* sym */ /* pop(v), sym.v = v */
+OP(SUBR_CALL, callSubroutine) /* sym */ /* ret = call(sym), if PC
== fetchRetVal: push(ret) */
+OP(FETCH_RET_VAL, fetchRetVal) /* internal error */
+OP(BRANCH, branch) /* off */ /* PC += off */
+OP(BRANCH_TRUE, branchTrue) /* off */ /* pop(v), if v: PC +=
off */
+OP(BRANCH_FALSE, branchFalse) /* off */ /* pop(v), if !v: PC +=
off */
+OP(BRANCH_NEVER, branchNever) /* off */ /* */
+OP(ARRAY_REF, arrayRef) /* N */ /* pop(kN..k1,a),
push(a[k1..kN]) */
+OP(ARRAY_ASSIGN, arrayAssign) /* N */ /* pop(v,kN..k1,a),
a[k1..kN]=v */
+OP(BEGIN_ARRAY_ITER, beginArrayIter) /* it */ /* pop(a), it=a.begin */
+OP(ARRAY_ITER, arrayIter) /* k,it,pc */ /* it ? (k.v=it.k, it++)
: PC = pc */
+OP(IN_ARRAY, inArray) /* pop(a,k),
push(a[k]?1:0) */
+OP(ARRAY_DELETE, deleteArrayElement) /*N*/ /* N>0 ? (pop(kN..k1,a),
del(a[k])) : (pop(a), delall(a)) */
+OP(PUSH_ARRAY_SYM, pushArraySymVal) /*s,i*/ /* if i: s.v=ary()),
push(s.v) */
+OP(ARRAY_REF_ASSIGN_SETUP, arrayRefAndAssignSetup) /*op,N*/ /* pop(v,kN..a),
a[k1..kN] op= v */
+OP(PUSH_ARG, pushArgVal) /* pop(num), push($num) */
+OP(PUSH_ARG_COUNT, pushArgCount) /* push($n_args) */
+OP(PUSH_ARG_ARRAY, pushArgArray) /* push($args) */
--
NEdit Develop mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/develop