fix hex regex in SH
[nedit-bw.git] / SUBR_TAG.patch
blob5a890a003de26b733346272166e92389c3d35b32
1 ---
3 source/interpret.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++----
4 source/interpret.h | 3 +-
5 source/macro.c | 25 ++++++++++++++-----
6 3 files changed, 83 insertions(+), 12 deletions(-)
8 diff --quilt old/source/interpret.c new/source/interpret.c
9 --- old/source/interpret.c
10 +++ new/source/interpret.c
11 @@ -184,11 +184,11 @@ static void disasmInternal(Inst *inst, i
12 #endif /* #ifndef DEBUG_ASSEMBLY */
14 #ifdef DEBUG_STACK /* for run-time instruction and stack trace */
15 static void stackdump(int n, int extra);
16 static void stackdumpInternal(int n, int extra);
17 -#define STACKDUMP(n, x) stackdump(n, x)
18 +#define STACKDUMP(n, x) stackdump(n, (x) + 10)
19 #define DISASM_RT(i, n) disasm(NULL, i, n)
20 #else /* #ifndef DEBUG_STACK */
21 #define STACKDUMP(n, x)
22 #define DISASM_RT(i, n)
23 #endif /* #ifndef DEBUG_STACK */
24 @@ -304,10 +304,11 @@ static int (*OpFns[N_OPS])() = {returnNo
25 return execError(StackOverflowMsg, ""); \
26 } \
27 } while (0)
29 static const char *tagToStr(enum typeTags tag);
30 +static const char *typeToStr(enum symTypes type);
33 ** Initialize macro language global variables. Must be called before
34 ** any macros are even parsed, because the parser uses action routine
35 ** symbols to comprehend hyphenated names.
36 @@ -425,10 +426,11 @@ int AddSym(Symbol *sym, char **msg)
38 if (ProgP >= &Prog[PROGRAM_SIZE]) {
39 *msg = "macro too large";
40 return 0;
42 + sym->added = 1;
43 ProgP->sym = sym;
44 ProgP++;
45 return 1;
48 @@ -866,10 +868,11 @@ Symbol *InstallSymbol(const char *name,
49 s = (Symbol *)malloc(sizeof(Symbol));
50 s->name = (char *)malloc(strlen(name)+1); /* +1 for '\0' */
51 strcpy(s->name, name);
52 s->type = type;
53 s->value = value;
54 + s->added = 0;
55 if (type == LOCAL_SYM) {
56 s->next = LocalSymList;
57 LocalSymList = s;
58 } else {
59 s->next = GlobalSymList;
60 @@ -883,13 +886,12 @@ Symbol *InstallSymbol(const char *name,
61 ** list.
63 Symbol *PromoteToGlobal(Symbol *sym)
65 Symbol *s;
66 - static DataValue noValue = {NO_TAG, {0}};
68 - if (sym->type != LOCAL_SYM)
69 + if (sym->type != LOCAL_SYM || sym->added)
70 return sym;
72 /* Remove sym from the local symbol list */
73 if (sym == LocalSymList)
74 LocalSymList = sym->next;
75 @@ -903,11 +905,16 @@ Symbol *PromoteToGlobal(Symbol *sym)
78 s = LookupSymbol(sym->name);
79 if (s != NULL)
80 return s;
81 - return InstallSymbol(sym->name, GLOBAL_SYM, noValue);
83 + sym->type = GLOBAL_SYM;
84 + sym->next = GlobalSymList;
85 + GlobalSymList = sym;
87 + return sym;
91 ** Convert a long value to its decimal string representation, returned in a
92 ** static string.
93 @@ -1380,10 +1387,15 @@ static int pushSymVal(void)
94 } else if (s->type == PROC_VALUE_SYM) {
95 char *errMsg;
96 if (!(s->value.val.subr)(FocusWindow, NULL, 0, &symVal, &errMsg)) {
97 return execError(errMsg, s->name);
99 + } else if (s->type == C_FUNCTION_SYM
100 + || s->type == MACRO_FUNCTION_SYM
101 + || s->type == ACTION_ROUTINE_SYM) {
102 + symVal.tag = SUBR_TAG;
103 + symVal.val.sym = s;
104 } else {
105 return execError("reading non-variable: %s", s->name);
108 if (symVal.tag == NO_TAG && !inTypeOfMode) {
109 @@ -2464,14 +2476,28 @@ static int callSubroutineFromSymbol(Symb
110 int i;
111 static DataValue noValue = {NO_TAG, {0}};
112 Program *prog;
113 char *errMsg;
114 int haveNamedArgs = (nArgs < 0);
115 + DataValue *symValPtr = NULL;
117 if (haveNamedArgs)
118 nArgs = -nArgs - 1;
120 + if (sym->type == LOCAL_SYM) {
121 + symValPtr = &FP_GET_SYM_VAL(FrameP, sym);
122 + } else if (sym->type == GLOBAL_SYM) {
123 + symValPtr = &sym->value;
125 + if (symValPtr) {
126 + if (symValPtr->tag == SUBR_TAG) {
127 + sym = symValPtr->val.sym;
128 + } else {
129 + return execError("%s is not a variable holding a subroutine pointer", sym->name);
134 ** If the subroutine is built-in, call the built-in routine
136 if (sym->type == C_FUNCTION_SYM) {
137 DataValue result;
138 @@ -3972,10 +3998,13 @@ static int typeOfOut(void)
139 retVal.val.str.rep = PERM_ALLOC_STR("STRING");
140 break;
141 case ARRAY_TAG:
142 retVal.val.str.rep = PERM_ALLOC_STR("ARRAY");
143 break;
144 + case SUBR_TAG:
145 + retVal.val.str.rep = PERM_ALLOC_STR("SUBROUTINE");
146 + break;
148 retVal.val.str.len = strlen(retVal.val.str.rep);
150 if (PC->func == fetchRetVal) {
151 PUSH(retVal);
152 @@ -4124,16 +4153,43 @@ static const char *tagToStr(enum typeTag
153 return "<integer>";
154 case STRING_TAG:
155 return "<string>";
156 case ARRAY_TAG:
157 return "<array>";
158 + case SUBR_TAG:
159 + return "<subroutine>";
160 case NO_TAG:
161 default:
162 return "<no value>";
166 +static const char *typeToStr(enum symTypes type)
168 + switch (type) {
169 + case CONST_SYM:
170 + return "<const>";
171 + case GLOBAL_SYM:
172 + return "<global>";
173 + case LOCAL_SYM:
174 + return "<local>";
175 + case ARG_SYM:
176 + return "<arg>";
177 + case PROC_VALUE_SYM:
178 + return "<proc value>";
179 + case C_FUNCTION_SYM:
180 + return "<C function>";
181 + case MACRO_FUNCTION_SYM:
182 + return "<macro function>";
183 + case ACTION_ROUTINE_SYM:
184 + return "<action routine>";
187 + return "";
191 #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */
192 static char *printdBuffer = NULL;
193 static int printdPos = 0;
194 static int printdSize = 0;
196 @@ -4248,10 +4304,13 @@ static void dumpVal(DataValue dv)
198 break;
199 case ARRAY_TAG:
200 printd("<array> %8p[%d]", dv.val.arrayPtr, ArraySize(&dv));
201 break;
202 + case SUBR_TAG:
203 + printd("<subroutine> %s", dv.val.sym->name);
204 + break;
205 case NO_TAG:
206 if (!dv.val.inst) {
207 printd("<no value>");
209 else {
210 diff --quilt old/source/interpret.h new/source/interpret.h
211 --- old/source/interpret.h
212 +++ new/source/interpret.h
213 @@ -58,11 +58,11 @@ enum operations {OP_RETURN_NO_VAL, OP_RE
214 OP_ARRAY_INDEX,
215 OP_ARRAY_MULTI_ITER,
216 OP_BEGIN_ARRAY_MULTI_ITER_ARRAY, OP_ARRAY_MULTI_ITER_ARRAY, OP_POP,
217 N_OPS};
219 -enum typeTags {NO_TAG, INT_TAG, STRING_TAG, ARRAY_TAG};
220 +enum typeTags {NO_TAG, INT_TAG, STRING_TAG, ARRAY_TAG, SUBR_TAG};
222 enum execReturnCodes {MACRO_TIME_LIMIT, MACRO_PREEMPT, MACRO_DONE, MACRO_ERROR};
224 #define ARRAY_DIM_SEP "\034"
226 @@ -110,10 +110,11 @@ typedef struct SparseArrayEntryTag {
227 typedef struct SymbolRec {
228 char *name;
229 enum symTypes type;
230 DataValue value;
231 struct SymbolRec *next; /* to link to another */
232 + int added;
233 } Symbol;
235 typedef struct ProgramTag {
236 Symbol *localSymList;
237 Inst *code;
238 diff --quilt old/source/macro.c new/source/macro.c
239 --- old/source/macro.c
240 +++ new/source/macro.c
241 @@ -3870,31 +3870,39 @@ static int filenameDialogMS(WindowInfo*
242 * call(fnname, arg, ...)
244 static int callMS(WindowInfo *window, DataValue *argList,
245 int nArgs, DataValue *result, char **errMsg)
247 - char stringStorage[TYPE_INT_STR_SIZE(int)];
248 Symbol *sym;
249 - char *fnname;
251 if (nArgs < 1) {
252 *errMsg = "subroutine %s called without arguments";
253 return False;
255 - if (!readStringArg(argList[0], &fnname, stringStorage, errMsg)) {
256 - return False;
257 + if (argList[0].tag == SUBR_TAG) {
258 + sym = argList[0].val.sym;
259 + } else {
260 + char stringStorage[TYPE_INT_STR_SIZE(int)];
261 + char *fnname;
263 + if (!readStringArg(argList[0], &fnname, stringStorage, errMsg)) {
264 + return False;
267 + sym = LookupSymbol(fnname);
269 - sym = LookupSymbol(fnname);
271 if (!sym) {
272 *errMsg = "subroutine name invalid";
273 return False;
276 return OverlayRoutineFromSymbol(sym, nArgs, 1);
280 - * define(func_name, func_body[, "override"])
281 + * subr = define(func_name, func_body[, "override"])
283 static int defineMS(WindowInfo *window, DataValue *argList, int nArgs,
284 DataValue *result, char **errMsg)
286 char stringStorage[3][TYPE_INT_STR_SIZE(int)];
287 @@ -3904,11 +3912,10 @@ static int defineMS(WindowInfo *window,
288 char *stoppedAt = NULL;
289 char *namePtr;
290 char *override = NULL;
291 Program *prog;
292 Symbol *sym;
293 - DataValue subrPtr;
295 if (nArgs < 2 || nArgs > 3) {
296 return wrongNArgsErr(errMsg);
298 if (!readStringArg(argList[0], &name, stringStorage[0], errMsg)) {
299 @@ -3972,15 +3979,19 @@ static int defineMS(WindowInfo *window,
301 FreeProgram(sym->value.val.prog);
302 sym->value.val.prog = prog;
304 } else {
305 + DataValue subrPtr;
306 subrPtr.val.prog = prog;
307 subrPtr.tag = NO_TAG;
308 sym = InstallSymbol(name, MACRO_FUNCTION_SYM, subrPtr);
311 + result->tag = SUBR_TAG;
312 + result->val.sym = sym;
314 return True;
318 * set_window_title(format[, ("text"|"format")])