3 source/interpret.c | 113 ++++++++++++++++++++++++++++++++++-------------------
5 source/parse.y | 14 ++----
6 source/userCmds.c | 4 -
7 4 files changed, 82 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 @@ -163,21 +163,21 @@ static SparseArrayEntry *allocateSparseA
13 #define DEBUG_DISASSEMBLER
14 static const char *printd(const char *f, ...);
15 static int outPrintd();
16 -static void disasm(Inst *inst, int nInstr);
17 +static void disasm(const char *name, Inst *inst, int nInstr);
18 static void disasmInternal(Inst *inst, int nInstr);
19 #endif /* #if defined(DEBUG_ASSEMBLY) || defined(DEBUG_STACK) */
21 #ifdef DEBUG_ASSEMBLY /* for disassembly */
22 -#define DISASM(i, n) disasm(i, n)
23 +#define DISASM(name, i, n) disasm(name, i, n)
24 #else /* #ifndef DEBUG_ASSEMBLY */
26 +#define DISASM(name, i, n)
27 #endif /* #ifndef DEBUG_ASSEMBLY */
29 #ifdef DEBUG_STACK /* for run-time instruction and stack trace */
30 static void stackdump(int n, int extra);
31 static void stackdumpInternal(int n, int extra);
32 #define STACKDUMP(n, x) stackdump(n, x)
33 -#define DISASM_RT(i, n) disasm(i, n)
34 +#define DISASM_RT(i, n) disasm(NULL, i, n)
35 #else /* #ifndef DEBUG_STACK */
36 #define STACKDUMP(n, x)
37 #define DISASM_RT(i, n)
38 @@ -326,7 +326,7 @@ void BeginCreatingProgram(void)
39 ** symbol table) as a package that ExecuteMacro can execute. This
40 ** program must be freed with FreeProgram.
42 -Program *FinishCreatingProgram(void)
43 +Program *FinishCreatingProgram(const char *name)
46 int progLen, fpOffset = 0;
47 @@ -344,8 +344,11 @@ Program *FinishCreatingProgram(void)
48 frame pointer offsets to them. */
49 for (s = newProg->localSymList; s != NULL; s = s->next)
50 s->value.val.n = fpOffset++;
52 - DISASM(newProg->code, ProgP - Prog);
55 + newProg->name = strdup(name);
57 + DISASM(newProg->name, newProg->code, ProgP - Prog);
61 @@ -2951,7 +2954,7 @@ static void arrayDisposeNode(rbTreeNode
63 SparseArrayEntry *ArrayNew(void)
65 - return((SparseArrayEntry *)rbTreeNew(arrayEmptyAllocator));
66 + return((SparseArrayEntry *)rbTreeNew(arrayEmptyAllocator));
70 @@ -3633,28 +3636,46 @@ static void dumpVal(DataValue dv)
74 - printd("i=%d", dv.val.n);
75 + printd("<integer> %d", dv.val.n);
83 char *src = dv.val.str.rep;
86 + printd("<string> <NULL>");
89 - for (k = 0; src[k] && k < sizeof s - 1; k++) {
90 - s[k] = isprint(src[k]) ? src[k] : '?';
91 + for (k = 0, l = 0; src[k] && l < sizeof s - 1; k++, l++) {
93 + const char to[] = "\\\"ntbrfave";
94 +#ifdef EBCDIC_CHARSET
95 + const char from[] = "\\\"\n\t\b\r\f\a\v\x27"; /* EBCDIC escape */
97 + const char from[] = "\\\"\n\t\b\r\f\a\v\x1B"; /* ASCII escape */
99 + if ((e = strchr(from, src[k]))) {
100 + if (l < sizeof s - 2) {
102 + s[l] = to[e - from];
105 + else if (isprint(src[k])) {
113 - printd("s=\"%s\"%s[%d]", s,
115 + printd("<string> \"%s\"%s[%d]", s,
116 src[k] ? "..." : "", strlen(src));
121 - printd("%08p <array>[%d]", dv.val.arrayPtr, ArraySize(&dv));
122 + printd("<array> %8p[%d]", dv.val.arrayPtr, ArraySize(&dv));
126 @@ -3730,56 +3751,66 @@ static void disasmInternal(Inst *inst, i
127 "UNPACKTOARGS", /* unpackArrayToArgs */
130 + static size_t opLen;
134 + for (j = 0; j < N_OPS; ++j) {
135 + if (opLen < strlen(opNames[j])) {
136 + opLen = strlen(opNames[j]);
141 for (i = 0; i < nInstr; ++i) {
142 - printd("Prog %8p ", &inst[i]);
143 + printd("Prog %8p", &inst[i]);
144 for (j = 0; j < N_OPS; ++j) {
145 if (inst[i].func == OpFns[j]) {
146 - printd("%22s ", opNames[j]);
147 + printd(" %*s", (int)opLen, opNames[j]);
148 if (j == OP_PUSH_SYM || j == OP_ASSIGN) {
149 Symbol *sym = inst[i+1].sym;
150 - printd("%s", sym->name);
151 + printd(" %s", sym->name);
152 if (sym->value.tag == STRING_TAG &&
153 strncmp(sym->name, "string #", 8) == 0) {
159 else if (j == OP_BRANCH || j == OP_BRANCH_FALSE ||
160 j == OP_BRANCH_NEVER || j == OP_BRANCH_TRUE) {
161 - printd("to=(%d) %p", inst[i+1].value,
162 + printd(" to=(%+d) %8p", inst[i+1].value,
163 &inst[i+1] + inst[i+1].value);
166 else if (j == OP_CONCAT) {
167 - printd("nExpr=%d", inst[i+1].value);
168 + printd(" nExpr=%d", inst[i+1].value);
171 else if (j == OP_SUBR_CALL) {
172 int args = inst[i+2].value;
173 - printd("%s ", inst[i+1].sym->name);
174 + printd(" %s", inst[i+1].sym->name);
176 - printd("%d+args[] (%d)", -args - 1, args);
177 + printd(" %d+args[] (%d)", -args - 1, args);
180 - printd("%d args", args);
181 + printd(" %d args", args);
185 else if (j == OP_SUBR_CALL_STACKED_N) {
186 - printd("%s args[] (?)", inst[i+1].sym->name);
187 + printd(" %s args[] (?)", inst[i+1].sym->name);
190 else if (j == OP_BEGIN_ARRAY_ITER) {
191 - printd("%s in", inst[i+1].sym->name);
192 + printd(" %s in", inst[i+1].sym->name);
195 else if (j == OP_ARRAY_ITER) {
196 - printd("%s = %s++ end-loop=(%d) %p",
197 + printd(" %s = %s++ end-loop=(%+d) %8p",
200 - inst[i+3].value, &inst[i+3] + inst[i+3].value);
202 + &inst[i+3] + inst[i+3].value);
205 else if (j == OP_ARRAY_REF ||
206 @@ -3788,18 +3819,20 @@ static void disasmInternal(Inst *inst, i
207 j == OP_ANONARRAY_INDEX_VAL ||
208 j == OP_NAMED_ARG1 ||
209 j == OP_NAMED_ARGN) {
210 - printd("nDim=%d", inst[i+1].value);
211 + printd(" nDim=%d", inst[i+1].value);
214 else if (j == OP_ARRAY_REF_ASSIGN_SETUP) {
215 - printd("binOp=%s ", inst[i+1].value ? "true" : "false");
216 - printd("nDim=%d", inst[i+2].value);
217 + printd(" binOp=%s nDim=%d",
218 + inst[i+1].value ? "true" : "false",
222 else if (j == OP_PUSH_ARRAY_SYM) {
223 - printd("%s", inst[++i].sym->name);
224 - printd(" %s", inst[i+1].value ? "createAndRef" : "refOnly");
227 + inst[i+1].sym->name,
228 + inst[i+2].value ? "createAndRef" : "refOnly");
233 @@ -3807,18 +3840,20 @@ static void disasmInternal(Inst *inst, i
237 - printd("%x\n", inst[i].value);
238 + printd(" %x\n", inst[i].value);
243 -static void disasm(Inst *inst, int nInstr)
244 +static void disasm(const char *name, Inst *inst, int nInstr)
246 static int outIsTTY = -1;
247 if (outIsTTY == -1) outIsTTY = isatty(fileno(stdout));
248 if (outIsTTY) { printd("\033[H"); }
249 + if (name) printd(">> %s\n", name);
250 disasmInternal(inst, nInstr);
251 if (outIsTTY) { printd("\033[J\n"); }
252 + if (name) printd("\n");
255 #endif /* #ifdef DEBUG_DISASSEMBLER */
256 @@ -3946,7 +3981,7 @@ static void stackdumpInternal(int n, int
257 if (outpt < TheStack)
258 printd("--------------Stack base--------------\n");
259 stackdumpframe(arrow, outpt, FrameP, StackP, '*');
260 - printd("Stack ----->\n");
261 + printd("Stack ----->\n\n");
262 #endif /* #ifdef DEBUG_STACK_HEADFIRST */
265 diff --quilt old/source/interpret.h new/source/interpret.h
266 --- old/source/interpret.h
267 +++ new/source/interpret.h
268 @@ -151,7 +151,7 @@ Symbol *LookupStringConstSymbol(const ch
269 Symbol *InstallStringConstSymbol(const char *str);
270 Symbol *LookupSymbol(const char *name);
271 Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value);
272 -Program *FinishCreatingProgram(void);
273 +Program *FinishCreatingProgram(const char *name);
274 void SwapCode(Inst *start, Inst *boundary, Inst *end);
275 void StartLoopAddrList(void);
276 int AddBreakAddr(Inst *addr);
277 diff --quilt old/source/parse.y new/source/parse.y
278 --- old/source/parse.y
279 +++ new/source/parse.y
280 @@ -527,10 +527,12 @@ blank: /* nothing */
281 Program *ParseMacro(char *expr, char **msg, char **stoppedAt, const char *name)
284 - static const char *prefix = ">> ";
286 BeginCreatingProgram();
289 + name = "--unknown--";
291 /* call yyparse to parse the string and check for success. If the parse
292 failed, return the error message and string index (the grammar aborts
293 parsing at the first error) */
294 @@ -538,18 +540,12 @@ Program *ParseMacro(char *expr, char **m
298 - FreeProgram(FinishCreatingProgram());
299 + FreeProgram(FinishCreatingProgram(NULL));
303 /* get the newly created program */
304 - prog = FinishCreatingProgram();
307 - name = "--unknown--";
309 - prog->name = XtMalloc(strlen(name) + strlen(prefix) + 1);
310 - strcat(strcpy(prog->name, prefix), name);
311 + prog = FinishCreatingProgram(name);
313 /* parse succeeded */
315 diff --quilt old/source/userCmds.c new/source/userCmds.c
316 --- old/source/userCmds.c
317 +++ new/source/userCmds.c
318 @@ -1286,13 +1286,13 @@ static int doMacroMenuCmd(WindowInfo *wi
319 int DoNamedMacroMenuCmd(WindowInfo *window, const char *itemName)
321 return doMacroMenuCmd(window, itemName, MacroMenuItems, NMacroMenuItems,
326 int DoNamedBGMenuCmd(WindowInfo *window, const char *itemName)
328 return doMacroMenuCmd(window, itemName, BGMenuItems, NBGMenuItems,
329 - "background-menu>");
330 + "Background Menu>");