3 source/interpret.c | 104 +++++++++++++++++++++++++++++++++--------------------
4 source/interpret.h | 2 -
5 source/parse.y | 14 ++-----
6 source/userCmds.c | 4 +-
7 4 files changed, 73 insertions(+), 51 deletions(-)
9 diff --quilt old/source/interpret.c new/source/interpret.c
10 --- old/source/interpret.c
11 +++ new/source/interpret.c
12 @@ -161,25 +161,25 @@ static SparseArrayEntry *allocateSparseA
14 #if defined(DEBUG_ASSEMBLY) || defined(DEBUG_STACK)
15 #define DEBUG_DISASSEMBLER
16 static const char *printd(const char *f, ...);
17 static int outPrintd();
18 -static void disasm(Inst *inst, int nInstr);
19 +static void disasm(const char *name, Inst *inst, int nInstr);
20 static void disasmInternal(Inst *inst, int nInstr);
21 #endif /* #if defined(DEBUG_ASSEMBLY) || defined(DEBUG_STACK) */
23 #ifdef DEBUG_ASSEMBLY /* for disassembly */
24 -#define DISASM(i, n) disasm(i, n)
25 +#define DISASM(name, i, n) disasm(name, i, n)
26 #else /* #ifndef DEBUG_ASSEMBLY */
28 +#define DISASM(name, i, n)
29 #endif /* #ifndef DEBUG_ASSEMBLY */
31 #ifdef DEBUG_STACK /* for run-time instruction and stack trace */
32 static void stackdump(int n, int extra);
33 static void stackdumpInternal(int n, int extra);
34 #define STACKDUMP(n, x) stackdump(n, x)
35 -#define DISASM_RT(i, n) disasm(i, n)
36 +#define DISASM_RT(i, n) disasm(NULL, i, n)
37 #else /* #ifndef DEBUG_STACK */
38 #define STACKDUMP(n, x)
39 #define DISASM_RT(i, n)
40 #endif /* #ifndef DEBUG_STACK */
42 @@ -324,11 +324,11 @@ void BeginCreatingProgram(void)
44 ** Finish up the program under construction, and return it (code and
45 ** symbol table) as a package that ExecuteMacro can execute. This
46 ** program must be freed with FreeProgram.
48 -Program *FinishCreatingProgram(void)
49 +Program *FinishCreatingProgram(const char *name)
52 int progLen, fpOffset = 0;
55 @@ -342,12 +342,15 @@ Program *FinishCreatingProgram(void)
57 /* Local variables' values are stored on the stack. Here we assign
58 frame pointer offsets to them. */
59 for (s = newProg->localSymList; s != NULL; s = s->next)
60 s->value.val.n = fpOffset++;
62 - DISASM(newProg->code, ProgP - Prog);
65 + newProg->name = strdup(name);
67 + DISASM(newProg->name, newProg->code, ProgP - Prog);
72 void FreeProgram(Program *prog)
73 @@ -2919,11 +2922,11 @@ static void arrayDisposeNode(rbTreeNode
77 SparseArrayEntry *ArrayNew(void)
79 - return((SparseArrayEntry *)rbTreeNew(arrayEmptyAllocator));
80 + return((SparseArrayEntry *)rbTreeNew(arrayEmptyAllocator));
84 ** insert a DataValue into an array, allocate the array if needed
85 ** keyStr must be a string that was allocated with AllocString()
86 @@ -3601,32 +3604,50 @@ int outPrintd()
87 #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */
88 static void dumpVal(DataValue dv)
92 - printd("i=%d", dv.val.n);
93 + printd("<integer> %d", dv.val.n);
101 char *src = dv.val.str.rep;
103 - printd("s=<NULL>");
104 + printd("<string> <NULL>");
107 - for (k = 0; src[k] && k < sizeof s - 1; k++) {
108 - s[k] = isprint(src[k]) ? src[k] : '?';
109 + for (k = 0, l = 0; src[k] && l < sizeof s - 1; k++, l++) {
111 + const char to[] = "\\\"ntbrfave";
112 +#ifdef EBCDIC_CHARSET
113 + const char from[] = "\\\"\n\t\b\r\f\a\v\x27"; /* EBCDIC escape */
115 + const char from[] = "\\\"\n\t\b\r\f\a\v\x1B"; /* ASCII escape */
117 + if ((e = strchr(from, src[k]))) {
118 + if (l < sizeof s - 2) {
120 + s[l] = to[e - from];
123 + else if (isprint(src[k])) {
131 - printd("s=\"%s\"%s[%d]", s,
133 + printd("<string> \"%s\"%s[%d]", s,
134 src[k] ? "..." : "", strlen(src));
139 - printd("%08p <array>[%d]", dv.val.arrayPtr, ArraySize(&dv));
140 + printd("<array> %8p[%d]", dv.val.arrayPtr, ArraySize(&dv));
144 printd("<no value>");
146 @@ -3699,98 +3720,103 @@ static void disasmInternal(Inst *inst, i
147 "SUBR_CALL_STACKED_N", /* callSubroutineStackedN */
148 "UNPACKTOARGS", /* unpackArrayToArgs */
153 for (i = 0; i < nInstr; ++i) {
154 - printd("Prog %8p ", &inst[i]);
155 + printd("Prog %8p", &inst[i]);
156 for (j = 0; j < N_OPS; ++j) {
157 if (inst[i].func == OpFns[j]) {
158 - printd("%22s ", opNames[j]);
159 + printd(" %23s", opNames[j]);
160 if (j == OP_PUSH_SYM || j == OP_ASSIGN) {
161 Symbol *sym = inst[i+1].sym;
162 - printd("%s", sym->name);
163 + printd(" %s", sym->name);
164 if (sym->value.tag == STRING_TAG &&
165 strncmp(sym->name, "string #", 8) == 0) {
171 else if (j == OP_BRANCH || j == OP_BRANCH_FALSE ||
172 j == OP_BRANCH_NEVER || j == OP_BRANCH_TRUE) {
173 - printd("to=(%d) %p", inst[i+1].value,
174 + printd(" to=(%+d) %8p", inst[i+1].value,
175 &inst[i+1] + inst[i+1].value);
178 else if (j == OP_CONCAT) {
179 - printd("nExpr=%d", inst[i+1].value);
180 + printd(" nExpr=%d", inst[i+1].value);
183 else if (j == OP_SUBR_CALL) {
184 int args = inst[i+2].value;
185 - printd("%s ", inst[i+1].sym->name);
186 + printd(" %s", inst[i+1].sym->name);
188 - printd("%d+args[] (%d)", -args - 1, args);
189 + printd(" %d+args[] (%d)", -args - 1, args);
192 - printd("%d args", args);
193 + printd(" %d args", args);
197 else if (j == OP_SUBR_CALL_STACKED_N) {
198 - printd("%s args[] (?)", inst[i+1].sym->name);
199 + printd(" %s args[] (?)", inst[i+1].sym->name);
202 else if (j == OP_BEGIN_ARRAY_ITER) {
203 - printd("%s in", inst[i+1].sym->name);
204 + printd(" %s in", inst[i+1].sym->name);
207 else if (j == OP_ARRAY_ITER) {
208 - printd("%s = %s++ end-loop=(%d) %p",
209 + printd(" %s = %s++ end-loop=(%+d) %8p",
212 - inst[i+3].value, &inst[i+3] + inst[i+3].value);
214 + &inst[i+3] + inst[i+3].value);
217 else if (j == OP_ARRAY_REF ||
218 j == OP_ARRAY_DELETE ||
219 j == OP_ARRAY_ASSIGN ||
220 j == OP_ANONARRAY_INDEX_VAL ||
221 j == OP_NAMED_ARG1 ||
222 j == OP_NAMED_ARGN) {
223 - printd("nDim=%d", inst[i+1].value);
224 + printd(" nDim=%d", inst[i+1].value);
227 else if (j == OP_ARRAY_REF_ASSIGN_SETUP) {
228 - printd("binOp=%s ", inst[i+1].value ? "true" : "false");
229 - printd("nDim=%d", inst[i+2].value);
230 + printd(" binOp=%s nDim=%d",
231 + inst[i+1].value ? "true" : "false",
235 else if (j == OP_PUSH_ARRAY_SYM) {
236 - printd("%s", inst[++i].sym->name);
237 - printd(" %s", inst[i+1].value ? "createAndRef" : "refOnly");
240 + inst[i+1].sym->name,
241 + inst[i+2].value ? "createAndRef" : "refOnly");
250 - printd("%x\n", inst[i].value);
251 + printd(" %x\n", inst[i].value);
256 -static void disasm(Inst *inst, int nInstr)
257 +static void disasm(const char *name, Inst *inst, int nInstr)
259 static int outIsTTY = -1;
260 if (outIsTTY == -1) outIsTTY = isatty(fileno(stdout));
261 if (outIsTTY) { printd("\033[H"); }
262 + if (name) printd(">> %s\n", name);
263 disasmInternal(inst, nInstr);
264 if (outIsTTY) { printd("\033[J\n"); }
265 + if (name) printd("\n");
268 #endif /* #ifdef DEBUG_DISASSEMBLER */
270 #ifdef DEBUG_STACK /* for run-time stack dumping */
271 @@ -3914,11 +3940,11 @@ static void stackdumpInternal(int n, int
272 printd("--------------Stack base--------------\n");
274 if (outpt < TheStack)
275 printd("--------------Stack base--------------\n");
276 stackdumpframe(arrow, outpt, FrameP, StackP, '*');
277 - printd("Stack ----->\n");
278 + printd("Stack ----->\n\n");
279 #endif /* #ifdef DEBUG_STACK_HEADFIRST */
282 static void stackdump(int n, int extra)
284 diff --quilt old/source/interpret.h new/source/interpret.h
285 --- old/source/interpret.h
286 +++ new/source/interpret.h
287 @@ -149,11 +149,11 @@ Inst *GetPC(void);
288 Symbol *InstallIteratorSymbol(void);
289 Symbol *LookupStringConstSymbol(const char *value);
290 Symbol *InstallStringConstSymbol(const char *str);
291 Symbol *LookupSymbol(const char *name);
292 Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value);
293 -Program *FinishCreatingProgram(void);
294 +Program *FinishCreatingProgram(const char *name);
295 void SwapCode(Inst *start, Inst *boundary, Inst *end);
296 void StartLoopAddrList(void);
297 int AddBreakAddr(Inst *addr);
298 int AddContinueAddr(Inst *addr);
299 void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr);
300 diff --quilt old/source/parse.y new/source/parse.y
301 --- old/source/parse.y
302 +++ new/source/parse.y
303 @@ -525,33 +525,29 @@ blank: /* nothing */
304 ** to where parsing failed in stoppedAt.
306 Program *ParseMacro(char *expr, char **msg, char **stoppedAt, const char *name)
309 - static const char *prefix = ">> ";
311 BeginCreatingProgram();
314 + name = "--unknown--";
316 /* call yyparse to parse the string and check for success. If the parse
317 failed, return the error message and string index (the grammar aborts
318 parsing at the first error) */
323 - FreeProgram(FinishCreatingProgram());
324 + FreeProgram(FinishCreatingProgram(NULL));
328 /* get the newly created program */
329 - prog = FinishCreatingProgram();
332 - name = "--unknown--";
334 - prog->name = XtMalloc(strlen(name) + strlen(prefix) + 1);
335 - strcat(strcpy(prog->name, prefix), name);
336 + prog = FinishCreatingProgram(name);
338 /* parse succeeded */
342 diff --quilt old/source/userCmds.c new/source/userCmds.c
343 --- old/source/userCmds.c
344 +++ new/source/userCmds.c
345 @@ -1284,17 +1284,17 @@ static int doMacroMenuCmd(WindowInfo *wi
348 int DoNamedMacroMenuCmd(WindowInfo *window, const char *itemName)
350 return doMacroMenuCmd(window, itemName, MacroMenuItems, NMacroMenuItems,
355 int DoNamedBGMenuCmd(WindowInfo *window, const char *itemName)
357 return doMacroMenuCmd(window, itemName, BGMenuItems, NBGMenuItems,
358 - "background-menu>");
359 + "Background Menu>");
364 ** Rebuild all of the Shell, Macro, Background menus of given editor window.