CVS rebase
[nedit-bw.git] / InterpretDebug-mods.patch
blob5108f8672412e53de29f8175454db782ce70da4c
1 ---
3 source/interpret.c | 113 ++++++++++++++++++++++++++++++++++-------------------
4 source/interpret.h | 2
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 */
25 -#define DISASM(i, n)
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)
45 Program *newProg;
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);
54 + if (name)
55 + newProg->name = strdup(name);
57 + DISASM(newProg->name, newProg->code, ProgP - Prog);
59 return newProg;
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)
72 switch (dv.tag) {
73 case INT_TAG:
74 - printd("i=%d", dv.val.n);
75 + printd("<integer> %d", dv.val.n);
76 break;
77 case STRING_TAG:
79 - int k;
80 - char s[21];
81 + int k, l;
82 + char s[64];
83 char *src = dv.val.str.rep;
84 if (!src) {
85 - printd("s=<NULL>");
86 + printd("<string> <NULL>");
88 else {
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++) {
92 + char *e;
93 + const char to[] = "\\\"ntbrfave";
94 +#ifdef EBCDIC_CHARSET
95 + const char from[] = "\\\"\n\t\b\r\f\a\v\x27"; /* EBCDIC escape */
96 +#else
97 + const char from[] = "\\\"\n\t\b\r\f\a\v\x1B"; /* ASCII escape */
98 +#endif
99 + if ((e = strchr(from, src[k]))) {
100 + if (l < sizeof s - 2) {
101 + s[l++] = '\\';
102 + s[l] = to[e - from];
105 + else if (isprint(src[k])) {
106 + s[l] = src[k];
108 + else {
109 + s[l] = '?';
112 - s[k] = 0;
113 - printd("s=\"%s\"%s[%d]", s,
114 + s[l] = 0;
115 + printd("<string> \"%s\"%s[%d]", s,
116 src[k] ? "..." : "", strlen(src));
119 break;
120 case ARRAY_TAG:
121 - printd("%08p <array>[%d]", dv.val.arrayPtr, ArraySize(&dv));
122 + printd("<array> %8p[%d]", dv.val.arrayPtr, ArraySize(&dv));
123 break;
124 case NO_TAG:
125 if (!dv.val.inst) {
126 @@ -3730,56 +3751,66 @@ static void disasmInternal(Inst *inst, i
127 "UNPACKTOARGS", /* unpackArrayToArgs */
129 int i, j;
130 + static size_t opLen;
132 - printd("\n");
133 + if (!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) {
154 + printd(" ");
155 dumpVal(sym->value);
157 ++i;
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);
164 ++i;
166 else if (j == OP_CONCAT) {
167 - printd("nExpr=%d", inst[i+1].value);
168 + printd(" nExpr=%d", inst[i+1].value);
169 ++i;
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);
175 if (args < 0) {
176 - printd("%d+args[] (%d)", -args - 1, args);
177 + printd(" %d+args[] (%d)", -args - 1, args);
179 else {
180 - printd("%d args", args);
181 + printd(" %d args", args);
183 i += 2;
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);
188 ++i;
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);
193 ++i;
195 else if (j == OP_ARRAY_ITER) {
196 - printd("%s = %s++ end-loop=(%d) %p",
197 + printd(" %s = %s++ end-loop=(%+d) %8p",
198 inst[i+1].sym->name,
199 inst[i+2].sym->name,
200 - inst[i+3].value, &inst[i+3] + inst[i+3].value);
201 + inst[i+3].value,
202 + &inst[i+3] + inst[i+3].value);
203 i += 3;
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);
212 ++i;
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",
219 + inst[i+2].value);
220 i += 2;
222 else if (j == OP_PUSH_ARRAY_SYM) {
223 - printd("%s", inst[++i].sym->name);
224 - printd(" %s", inst[i+1].value ? "createAndRef" : "refOnly");
225 - ++i;
226 + printd(" %s %s",
227 + inst[i+1].sym->name,
228 + inst[i+2].value ? "createAndRef" : "refOnly");
229 + i += 2;
232 printd("\n");
233 @@ -3807,18 +3840,20 @@ static void disasmInternal(Inst *inst, i
236 if (j == N_OPS) {
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");
253 outPrintd();
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)
283 Program *prog;
284 - static const char *prefix = ">> ";
286 BeginCreatingProgram();
288 + if (!name)
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
295 if (yyparse()) {
296 *msg = ErrMsg;
297 *stoppedAt = InPtr;
298 - FreeProgram(FinishCreatingProgram());
299 + FreeProgram(FinishCreatingProgram(NULL));
300 return NULL;
303 /* get the newly created program */
304 - prog = FinishCreatingProgram();
306 - if (!name)
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 */
314 *msg = "";
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,
322 - "macro-menu>");
323 + "Macro Menu>");
326 int DoNamedBGMenuCmd(WindowInfo *window, const char *itemName)
328 return doMacroMenuCmd(window, itemName, BGMenuItems, NBGMenuItems,
329 - "background-menu>");
330 + "Background Menu>");