update to arrayReplacesArglist5.diff
[nedit-bw.git] / InterpretDebug-disasm.patch
blob7946b4957fa7d1cbcb57ae91b47f510367fc64a3
1 ---
3 source/interpret.c | 85 ++++++++++++++++++++++++++++++++---------------------
4 source/interpret.h | 2 -
5 source/parse.y | 14 +++-----
6 source/userCmds.c | 4 +-
7 4 files changed, 60 insertions(+), 45 deletions(-)
9 diff --quilt old/source/interpret.c new/source/interpret.c
10 --- old/source/interpret.c
11 +++ new/source/interpret.c
12 @@ -169,25 +169,25 @@ static int inTypeOfMode;
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 */
27 -#define DISASM(i, n)
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 @@ -335,11 +335,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)
51 Program *newProg;
52 int progLen, fpOffset = 0;
53 Symbol *s;
55 @@ -353,12 +353,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);
64 + if (name)
65 + newProg->name = strdup(name);
67 + DISASM(newProg->name, newProg->code, ProgP - Prog);
69 return newProg;
72 void FreeProgram(Program *prog)
73 @@ -3841,18 +3844,31 @@ static void dumpVal(DataValue dv)
74 printd("i=%d", dv.val.n);
75 break;
76 case STRING_TAG:
78 int k;
79 - char s[21];
80 + char s[64];
81 char *src = dv.val.str.rep;
82 if (!src) {
83 printd("s=<NULL>");
85 else {
86 for (k = 0; src[k] && k < sizeof s - 1; k++) {
87 - s[k] = isprint(src[k]) ? src[k] : '?';
88 + char *e;
89 + const char *from = "\\\"\n\t\b\r\f\v";
90 + const char *to = "\\\"ntbrfv";
91 + if (isprint(src[k])) {
92 + s[k] = src[k];
93 + }
94 + else if (k < sizeof s - 2 &&
95 + (e = strchr(from, src[k]))) {
96 + s[k++] = '\\';
97 + s[k] = to[e - from];
98 + }
99 + else {
100 + s[k] = '?';
103 s[k] = 0;
104 printd("s=\"%s\"%s[%d]", s,
105 src[k] ? "..." : "", strlen(src));
107 @@ -3939,107 +3955,110 @@ static void disasmInternal(Inst *inst, i
108 "TYPEOF_IN", /* typeOfIn */
109 "TYPEOF_OUT", /* typeOfOut */
111 int i, j;
113 - printd("\n");
114 for (i = 0; i < nInstr; ++i) {
115 - printd("Prog %8p ", &inst[i]);
116 + printd("Prog %4d", i);
117 for (j = 0; j < N_OPS; ++j) {
118 if (inst[i].func == OpFns[j]) {
119 - printd("%23s ", opNames[j]);
120 + printd(" %23s", opNames[j]);
121 if (j == OP_PUSH_SYM || j == OP_ASSIGN) {
122 Symbol *sym = inst[i+1].sym;
123 - printd("%s", sym->name);
124 + printd(" %s", sym->name);
125 if (sym->value.tag == STRING_TAG &&
126 strncmp(sym->name, "string #", 8) == 0) {
127 dumpVal(sym->value);
129 ++i;
131 else if (j == OP_BRANCH || j == OP_BRANCH_FALSE ||
132 j == OP_BRANCH_NEVER || j == OP_BRANCH_TRUE) {
133 - printd("to=(%d) %p", inst[i+1].value,
134 - &inst[i+1] + inst[i+1].value);
135 + printd(" to=(%+d) %d", inst[i+1].value,
136 + inst[i+1].value + i + 1);
137 ++i;
139 else if (j == OP_CONCAT) {
140 - printd("nExpr=%d", inst[i+1].value);
141 + printd(" nExpr=%d", inst[i+1].value);
142 ++i;
144 else if (j == OP_SUBR_CALL) {
145 int args = inst[i+2].value;
146 - printd("%s ", inst[i+1].sym->name);
147 + printd(" %s", inst[i+1].sym->name);
148 if (args < 0) {
149 - printd("%d+args[] (%d)", -args - 1, args);
150 + printd(" %d+args[] (%d)", -args - 1, args);
152 else {
153 - printd("%d args", args);
154 + printd(" %d args", args);
156 i += 2;
158 else if (j == OP_SUBR_CALL_STACKED_N) {
159 - printd("%s args[] (?)", inst[i+1].sym->name);
160 + printd(" %s args[] (?)", inst[i+1].sym->name);
161 ++i;
163 else if (j == OP_BEGIN_ARRAY_ITER ||
164 j == OP_BEGIN_ARRAY_ITER_KEYVAL) {
165 - printd("%s in", inst[i+1].sym->name);
166 + printd(" %s in", inst[i+1].sym->name);
167 ++i;
169 else if (j == OP_ARRAY_ITER) {
170 - printd("%s = %s++ end-loop=(%d) %p",
171 + printd(" %s = %s++ end-loop=(%+d) %d",
172 inst[i+1].sym->name,
173 inst[i+2].sym->name,
174 - inst[i+3].value, &inst[i+3] + inst[i+3].value);
175 + inst[i+3].value,
176 + inst[i+3].value + i + 3);
177 i += 3;
179 else if (j == OP_ARRAY_ITER_KEYVAL) {
180 - printf("[%s]=%s = %s++ end-loop=(%d) %p",
181 + printf(" [%s]=%s = %s++ end-loop=(%+d) %d",
182 inst[i+1].sym->name,
183 inst[i+2].sym->name,
184 inst[i+3].sym->name,
185 inst[i+4].value,
186 - &inst[i+4] + inst[i+4].value);
187 + inst[i+4].value + i + 4);
188 i += 4;
190 else if (j == OP_ARRAY_REF ||
191 j == OP_ARRAY_DELETE ||
192 j == OP_ARRAY_ASSIGN ||
193 j == OP_ANONARRAY_INDEX_VAL ||
194 j == OP_NAMED_ARG1 ||
195 j == OP_NAMED_ARGN ||
196 j == OP_ARRAY_INDEX) {
197 - printd("nDim=%d", inst[i+1].value);
198 + printd(" nDim=%d", inst[i+1].value);
199 ++i;
201 else if (j == OP_ARRAY_REF_ASSIGN_SETUP) {
202 - printd("binOp=%s ", inst[i+1].value ? "true" : "false");
203 - printd("nDim=%d", inst[i+2].value);
204 + printd(" binOp=%s nDim=%d",
205 + inst[i+1].value ? "true" : "false",
206 + inst[i+2].value);
207 i += 2;
209 else if (j == OP_PUSH_ARRAY_SYM) {
210 - printd("%s", inst[++i].sym->name);
211 - printd(" %s", inst[i+1].value ? "createAndRef" : "refOnly");
212 - ++i;
213 + printd(" %s %s",
214 + inst[i+1].sym->name,
215 + inst[i+2].value ? "createAndRef" : "refOnly");
216 + i += 2;
219 printd("\n");
220 break;
223 if (j == N_OPS) {
224 - printd("%x\n", inst[i].value);
225 + printd(" %x\n", inst[i].value);
230 -static void disasm(Inst *inst, int nInstr)
231 +static void disasm(const char *name, Inst *inst, int nInstr)
233 static int outIsTTY = -1;
234 if (outIsTTY == -1) outIsTTY = isatty(fileno(stdout));
235 if (outIsTTY) { printd("\033[H"); }
236 + if (name) printd("\n>> %s\n", name);
237 disasmInternal(inst, nInstr);
238 if (outIsTTY) { printd("\033[J\n"); }
239 outPrintd();
241 #endif /* #ifdef DEBUG_DISASSEMBLER */
242 diff --quilt old/source/interpret.h new/source/interpret.h
243 --- old/source/interpret.h
244 +++ new/source/interpret.h
245 @@ -152,11 +152,11 @@ Inst *GetPC(void);
246 Symbol *InstallIteratorSymbol(void);
247 Symbol *LookupStringConstSymbol(const char *value);
248 Symbol *InstallStringConstSymbol(const char *str);
249 Symbol *LookupSymbol(const char *name);
250 Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value);
251 -Program *FinishCreatingProgram(void);
252 +Program *FinishCreatingProgram(const char *name);
253 void SwapCode(Inst *start, Inst *boundary, Inst *end);
254 void StartLoopAddrList(void);
255 int AddBreakAddr(Inst *addr);
256 int AddContinueAddr(Inst *addr);
257 void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr);
258 diff --quilt old/source/parse.y new/source/parse.y
259 --- old/source/parse.y
260 +++ new/source/parse.y
261 @@ -554,33 +554,29 @@ blank: /* nothing */
262 ** to where parsing failed in stoppedAt.
264 Program *ParseMacro(char *expr, char **msg, char **stoppedAt, const char *name)
266 Program *prog;
267 - static const char *prefix = ">> ";
269 BeginCreatingProgram();
271 + if (!name)
272 + name = "--unknown--";
274 /* call yyparse to parse the string and check for success. If the parse
275 failed, return the error message and string index (the grammar aborts
276 parsing at the first error) */
277 InPtr = expr;
278 if (yyparse()) {
279 *msg = ErrMsg;
280 *stoppedAt = InPtr;
281 - FreeProgram(FinishCreatingProgram());
282 + FreeProgram(FinishCreatingProgram(NULL));
283 return NULL;
286 /* get the newly created program */
287 - prog = FinishCreatingProgram();
289 - if (!name)
290 - name = "--unknown--";
292 - prog->name = XtMalloc(strlen(name) + strlen(prefix) + 1);
293 - strcat(strcpy(prog->name, prefix), name);
294 + prog = FinishCreatingProgram(name);
296 /* parse succeeded */
297 *msg = "";
298 *stoppedAt = InPtr;
299 return prog;
300 diff --quilt old/source/userCmds.c new/source/userCmds.c
301 --- old/source/userCmds.c
302 +++ new/source/userCmds.c
303 @@ -1284,17 +1284,17 @@ static int doMacroMenuCmd(WindowInfo *wi
306 int DoNamedMacroMenuCmd(WindowInfo *window, const char *itemName)
308 return doMacroMenuCmd(window, itemName, MacroMenuItems, NMacroMenuItems,
309 - "macro-menu>");
310 + "Macro Menu>");
313 int DoNamedBGMenuCmd(WindowInfo *window, const char *itemName)
315 return doMacroMenuCmd(window, itemName, BGMenuItems, NBGMenuItems,
316 - "background-menu>");
317 + "Background Menu>");
321 ** Cache user menus:
322 ** Rebuild all of the Shell, Macro, Background menus of given editor window.