comment reduxed MultipleAssignment
[nedit-bw.git] / interpret_c-macro-cleanup.patch
blobf01f87f649503040a1dd4666c0890935d32a54d0
1 Subject: interpret.c: macro cleanup
3 Use 'do { } while (0)' syntax for macros and consolidate num/string conversion.
5 ---
7 source/interpret.c | 410 +++++++++++++++++++++++++++++++----------------------
8 1 file changed, 241 insertions(+), 169 deletions(-)
10 diff --quilt old/source/interpret.c new/source/interpret.c
11 --- old/source/interpret.c
12 +++ new/source/interpret.c
13 @@ -136,6 +136,8 @@ static int arrayEntryCompare(rbTreeNode
14 static void arrayDisposeNode(rbTreeNode *src);
15 static SparseArrayEntry *allocateSparseArrayEntry(void);
17 +static const char *tagToStr(enum typeTags tag);
19 /*#define DEBUG_ASSEMBLY*/
20 /*#define DEBUG_STACK*/
22 @@ -177,7 +179,7 @@ static SparseArrayEntryWrapper *Allocate
23 the macros are used */
24 static const char *StackOverflowMsg = "macro stack overflow";
25 static const char *StackUnderflowMsg = "macro stack underflow";
26 -static const char *StringToNumberMsg = "string could not be converted to number";
27 +static const char *StringToNumberMsg = "string '%s' could not be converted to number";
29 /* Temporary global data for use while accumulating programs */
30 static Symbol *LocalSymList = NULL; /* symbols local to the program */
31 @@ -1128,98 +1130,152 @@ static void freeSymbolTable(Symbol *symT
35 +/* true, if you can pop n values */
36 +#define OK_TO_POP(n) \
37 + ((StackP - (n)) >= TheStack)
39 +#define POP_CHECK(n) \
40 + do { \
41 + if (!OK_TO_POP(n)) { \
42 + return execError(StackUnderflowMsg, ""); \
43 + } \
44 + } while (0)
46 +/* true, if you can push n values */
47 +#define OK_TO_PUSH(n) \
48 + (StackP + (n) <= &TheStack[STACK_SIZE])
50 + #define PUSH_CHECK(n) \
51 + do { \
52 + if (!OK_TO_PUSH(n)) { \
53 + return execError(StackOverflowMsg, ""); \
54 + } \
55 + } while (0)
57 +#define PEEK_CHECK(n) \
58 + do { \
59 + if (!OK_TO_POP((n) + 1)) { \
60 + return execError(StackUnderflowMsg, ""); \
61 + } \
62 + if (!OK_TO_PUSH(-(n))) { \
63 + return execError(StackOverflowMsg, ""); \
64 + } \
65 + } while (0)
67 #define POP(dataVal) \
68 - if (StackP == TheStack) \
69 - return execError(StackUnderflowMsg, ""); \
70 - dataVal = *--StackP;
71 + do { \
72 + POP_CHECK(1); \
73 + dataVal = *--StackP; \
74 + } while (0)
76 #define PUSH(dataVal) \
77 - if (StackP >= &TheStack[STACK_SIZE]) \
78 - return execError(StackOverflowMsg, ""); \
79 - *StackP++ = dataVal;
80 + do { \
81 + PUSH_CHECK(1); \
82 + *StackP++ = dataVal; \
83 + } while (0)
85 #define PEEK(dataVal, peekIndex) \
86 - dataVal = *(StackP - peekIndex - 1);
87 + do { \
88 + PEEK_CHECK(peekIndex); \
89 + dataVal = *(StackP - peekIndex - 1); \
90 + } while (0)
92 +#define TO_INT(dataVal, number) \
93 + do { \
94 + int __int; \
95 + if (dataVal.tag == INT_TAG) { \
96 + __int = dataVal.val.n; \
97 + } else if (dataVal.tag == STRING_TAG) { \
98 + if (!StringToNum(dataVal.val.str.rep, &__int)) {\
99 + return execError(StringToNumberMsg, dataVal.val.str.rep); \
100 + } \
101 + } else { \
102 + return execError("incompatible type in integer context: <%s>", \
103 + tagToStr(dataVal.tag)); \
104 + } \
105 + number = __int; \
106 + } while (0)
108 +#define TO_STRING(dataVal, string) \
109 + do { \
110 + char *__str; \
111 + if (dataVal.tag == STRING_TAG) { \
112 + __str = dataVal.val.str.rep; \
113 + } else if (dataVal.tag == INT_TAG) { \
114 + __str = AllocString(TYPE_INT_STR_SIZE(int)); \
115 + sprintf(__str, "%d", dataVal.val.n); \
116 + } else { \
117 + return execError("incompatible type in string context: <%s>", \
118 + tagToStr(dataVal.tag)); \
119 + } \
120 + string = __str; \
121 + } while (0)
123 #define POP_INT(number) \
124 - if (StackP == TheStack) \
125 - return execError(StackUnderflowMsg, ""); \
126 - --StackP; \
127 - if (StackP->tag == STRING_TAG) { \
128 - if (!StringToNum(StackP->val.str.rep, &number)) \
129 - return execError(StringToNumberMsg, ""); \
130 - } else if (StackP->tag == INT_TAG) \
131 - number = StackP->val.n; \
132 - else \
133 - return(execError("can't convert array to integer", NULL));
134 + do { \
135 + DataValue dv; \
136 + POP(dv); \
137 + TO_INT(dv, number); \
138 + } while (0)
140 #define POP_STRING(string) \
141 - if (StackP == TheStack) \
142 - return execError(StackUnderflowMsg, ""); \
143 - --StackP; \
144 - if (StackP->tag == INT_TAG) { \
145 - string = AllocString(TYPE_INT_STR_SIZE(int)); \
146 - sprintf(string, "%d", StackP->val.n); \
147 - } else if (StackP->tag == STRING_TAG) \
148 - string = StackP->val.str.rep; \
149 - else \
150 - return(execError("can't convert array to string", NULL));
152 -#define PEEK_STRING(string, peekIndex) \
153 - if ((StackP - peekIndex - 1)->tag == INT_TAG) { \
154 - string = AllocString(TYPE_INT_STR_SIZE(int)); \
155 - sprintf(string, "%d", (StackP - peekIndex - 1)->val.n); \
156 - } \
157 - else if ((StackP - peekIndex - 1)->tag == STRING_TAG) { \
158 - string = (StackP - peekIndex - 1)->val.str.rep; \
159 - } \
160 - else { \
161 - return(execError("can't convert array to string", NULL)); \
163 + do { \
164 + DataValue dv; \
165 + POP(dv); \
166 + TO_STRING(dv, string); \
167 + } while (0)
169 #define PEEK_INT(number, peekIndex) \
170 - if ((StackP - peekIndex - 1)->tag == STRING_TAG) { \
171 - if (!StringToNum((StackP - peekIndex - 1)->val.str.rep, &number)) { \
172 - return execError(StringToNumberMsg, ""); \
173 - } \
174 - } else if ((StackP - peekIndex - 1)->tag == INT_TAG) { \
175 - number = (StackP - peekIndex - 1)->val.n; \
176 - } \
177 - else { \
178 - return(execError("can't convert array to string", NULL)); \
180 + do { \
181 + DataValue dv; \
182 + PEEK(dv, peekIndex); \
183 + TO_INT(dv, number); \
184 + } while (0)
186 +#define PEEK_STRING(string, peekIndex) \
187 + do { \
188 + DataValue dv; \
189 + PEEK(dv); \
190 + TO_STRING(dv, string); \
191 + } while (0)
193 #define PUSH_INT(number) \
194 - if (StackP >= &TheStack[STACK_SIZE]) \
195 - return execError(StackOverflowMsg, ""); \
196 - StackP->tag = INT_TAG; \
197 - StackP->val.n = number; \
198 - StackP++;
200 + do { \
201 + DataValue dv; \
202 + dv.tag = INT_TAG; \
203 + dv.val.n = (number); \
204 + PUSH(dv); \
205 + } while (0)
207 #define PUSH_STRING(string, length) \
208 - if (StackP >= &TheStack[STACK_SIZE]) \
209 - return execError(StackOverflowMsg, ""); \
210 - StackP->tag = STRING_TAG; \
211 - StackP->val.str.rep = string; \
212 - StackP->val.str.len = length; \
213 - StackP++;
214 + do { \
215 + DataValue dv; \
216 + dv.tag = STRING_TAG; \
217 + dv.val.str.rep = (string); \
218 + dv.val.str.len = (length); \
219 + PUSH(dv); \
220 + } while (0)
222 #define BINARY_NUMERIC_OPERATION(operator) \
223 - int n1, n2; \
224 - DISASM_RT(PC-1, 1); \
225 - STACKDUMP(2, 3); \
226 - POP_INT(n2) \
227 - POP_INT(n1) \
228 - PUSH_INT(n1 operator n2) \
229 - return STAT_OK;
230 + do { \
231 + int n1, n2; \
232 + DISASM_RT(PC-1, 1); \
233 + STACKDUMP(2, 3); \
234 + POP_INT(n2); \
235 + POP_INT(n1); \
236 + PUSH_INT(n1 operator n2); \
237 + return STAT_OK; \
238 + } while (0)
240 #define UNARY_NUMERIC_OPERATION(operator) \
241 - int n; \
242 - DISASM_RT(PC-1, 1); \
243 - STACKDUMP(1, 3); \
244 - POP_INT(n) \
245 - PUSH_INT(operator n) \
246 - return STAT_OK;
247 + do { \
248 + int n; \
249 + DISASM_RT(PC-1, 1); \
250 + STACKDUMP(1, 3); \
251 + POP_INT(n); \
252 + PUSH_INT(operator n); \
253 + return STAT_OK; \
254 + } while (0)
257 ** copy a symbol's value onto the stack
258 @@ -1269,7 +1325,7 @@ static int pushSymVal(void)
259 return execError("variable not set: %s", s->name);
262 - PUSH(symVal)
263 + PUSH(symVal);
265 return STAT_OK;
267 @@ -1281,7 +1337,7 @@ static int pushArgVal(void)
268 DISASM_RT(PC-1, 1);
269 STACKDUMP(1, 3);
271 - POP_INT(argNum)
272 + POP_INT(argNum);
273 --argNum;
274 nArgs = FP_GET_ARG_COUNT(FrameP);
275 if (argNum >= nArgs || argNum < 0) {
276 @@ -1372,7 +1428,7 @@ static int pushArraySymVal(void)
277 return execError("variable not set: %s", sym->name);
280 - PUSH(*dataPtr)
281 + PUSH(*dataPtr);
283 return STAT_OK;
285 @@ -1416,7 +1472,7 @@ static int assign(void)
286 dataPtr = &sym->value;
289 - POP(value)
290 + POP(value);
292 if (value.tag == ARRAY_TAG) {
293 ArrayCopy(dataPtr, &value);
294 @@ -1439,8 +1495,8 @@ static int dupStack(void)
295 DISASM_RT(PC-1, 1);
296 STACKDUMP(1, 3);
298 - PEEK(value, 0)
299 - PUSH(value)
300 + PEEK(value, 0);
301 + PUSH(value);
303 return STAT_OK;
305 @@ -1461,16 +1517,16 @@ static int add(void)
306 DISASM_RT(PC-1, 1);
307 STACKDUMP(2, 3);
309 - PEEK(rightVal, 0)
310 + PEEK(rightVal, 0);
311 if (rightVal.tag == ARRAY_TAG) {
312 - PEEK(leftVal, 1)
313 + PEEK(leftVal, 1);
314 if (leftVal.tag == ARRAY_TAG) {
315 SparseArrayEntry *leftIter, *rightIter;
316 resultArray.tag = ARRAY_TAG;
317 resultArray.val.arrayPtr = ArrayNew();
319 - POP(rightVal)
320 - POP(leftVal)
321 + POP(rightVal);
322 + POP(leftVal);
323 leftIter = arrayIterateFirst(&leftVal);
324 rightIter = arrayIterateFirst(&rightVal);
325 while (leftIter || rightIter) {
326 @@ -1504,16 +1560,16 @@ static int add(void)
327 return(execError("array insertion failure", NULL));
330 - PUSH(resultArray)
331 + PUSH(resultArray);
333 else {
334 return(execError("can't mix math with arrays and non-arrays", NULL));
337 else {
338 - POP_INT(n2)
339 - POP_INT(n1)
340 - PUSH_INT(n1 + n2)
341 + POP_INT(n2);
342 + POP_INT(n1);
343 + PUSH_INT(n1 + n2);
345 return(STAT_OK);
347 @@ -1533,16 +1589,16 @@ static int subtract(void)
348 DISASM_RT(PC-1, 1);
349 STACKDUMP(2, 3);
351 - PEEK(rightVal, 0)
352 + PEEK(rightVal, 0);
353 if (rightVal.tag == ARRAY_TAG) {
354 - PEEK(leftVal, 1)
355 + PEEK(leftVal, 1);
356 if (leftVal.tag == ARRAY_TAG) {
357 SparseArrayEntry *leftIter, *rightIter;
358 resultArray.tag = ARRAY_TAG;
359 resultArray.val.arrayPtr = ArrayNew();
361 - POP(rightVal)
362 - POP(leftVal)
363 + POP(rightVal);
364 + POP(leftVal);
365 leftIter = arrayIterateFirst(&leftVal);
366 rightIter = arrayIterateFirst(&rightVal);
367 while (leftIter) {
368 @@ -1570,16 +1626,16 @@ static int subtract(void)
369 return(execError("array insertion failure", NULL));
372 - PUSH(resultArray)
373 + PUSH(resultArray);
375 else {
376 return(execError("can't mix math with arrays and non-arrays", NULL));
379 else {
380 - POP_INT(n2)
381 - POP_INT(n1)
382 - PUSH_INT(n1 - n2)
383 + POP_INT(n2);
384 + POP_INT(n1);
385 + PUSH_INT(n1 - n2);
387 return(STAT_OK);
389 @@ -1595,7 +1651,7 @@ static int subtract(void)
391 static int multiply(void)
393 - BINARY_NUMERIC_OPERATION(*)
394 + BINARY_NUMERIC_OPERATION(*);
397 static int divide(void)
398 @@ -1605,12 +1661,12 @@ static int divide(void)
399 DISASM_RT(PC-1, 1);
400 STACKDUMP(2, 3);
402 - POP_INT(n2)
403 - POP_INT(n1)
404 + POP_INT(n2);
405 + POP_INT(n1);
406 if (n2 == 0) {
407 return execError("division by zero", "");
409 - PUSH_INT(n1 / n2)
410 + PUSH_INT(n1 / n2);
411 return STAT_OK;
414 @@ -1621,48 +1677,48 @@ static int modulo(void)
415 DISASM_RT(PC-1, 1);
416 STACKDUMP(2, 3);
418 - POP_INT(n2)
419 - POP_INT(n1)
420 + POP_INT(n2);
421 + POP_INT(n1);
422 if (n2 == 0) {
423 return execError("modulo by zero", "");
425 - PUSH_INT(n1 % n2)
426 + PUSH_INT(n1 % n2);
427 return STAT_OK;
430 static int negate(void)
432 - UNARY_NUMERIC_OPERATION(-)
433 + UNARY_NUMERIC_OPERATION(-);
436 static int increment(void)
438 - UNARY_NUMERIC_OPERATION(++)
439 + UNARY_NUMERIC_OPERATION(++);
442 static int decrement(void)
444 - UNARY_NUMERIC_OPERATION(--)
445 + UNARY_NUMERIC_OPERATION(--);
448 static int gt(void)
450 - BINARY_NUMERIC_OPERATION(>)
451 + BINARY_NUMERIC_OPERATION(>);
454 static int lt(void)
456 - BINARY_NUMERIC_OPERATION(<)
457 + BINARY_NUMERIC_OPERATION(<);
460 static int ge(void)
462 - BINARY_NUMERIC_OPERATION(>=)
463 + BINARY_NUMERIC_OPERATION(>=);
466 static int le(void)
468 - BINARY_NUMERIC_OPERATION(<=)
469 + BINARY_NUMERIC_OPERATION(<=);
473 @@ -1678,8 +1734,8 @@ static int eq(void)
474 DISASM_RT(PC-1, 1);
475 STACKDUMP(2, 3);
477 - POP(v1)
478 - POP(v2)
479 + POP(v1);
480 + POP(v2);
481 if (v1.tag == INT_TAG && v2.tag == INT_TAG) {
482 v1.val.n = v1.val.n == v2.val.n;
484 @@ -1708,7 +1764,7 @@ static int eq(void)
485 return(execError("incompatible types to compare", NULL));
487 v1.tag = INT_TAG;
488 - PUSH(v1)
489 + PUSH(v1);
490 return(STAT_OK);
493 @@ -1734,16 +1790,16 @@ static int bitAnd(void)
494 DISASM_RT(PC-1, 1);
495 STACKDUMP(2, 3);
497 - PEEK(rightVal, 0)
498 + PEEK(rightVal, 0);
499 if (rightVal.tag == ARRAY_TAG) {
500 - PEEK(leftVal, 1)
501 + PEEK(leftVal, 1);
502 if (leftVal.tag == ARRAY_TAG) {
503 SparseArrayEntry *leftIter, *rightIter;
504 resultArray.tag = ARRAY_TAG;
505 resultArray.val.arrayPtr = ArrayNew();
507 - POP(rightVal)
508 - POP(leftVal)
509 + POP(rightVal);
510 + POP(leftVal);
511 leftIter = arrayIterateFirst(&leftVal);
512 rightIter = arrayIterateFirst(&rightVal);
513 while (leftIter && rightIter) {
514 @@ -1765,16 +1821,16 @@ static int bitAnd(void)
515 return(execError("array insertion failure", NULL));
518 - PUSH(resultArray)
519 + PUSH(resultArray);
521 else {
522 return(execError("can't mix math with arrays and non-arrays", NULL));
525 else {
526 - POP_INT(n2)
527 - POP_INT(n1)
528 - PUSH_INT(n1 & n2)
529 + POP_INT(n2);
530 + POP_INT(n1);
531 + PUSH_INT(n1 & n2);
533 return(STAT_OK);
535 @@ -1794,16 +1850,16 @@ static int bitOr(void)
536 DISASM_RT(PC-1, 1);
537 STACKDUMP(2, 3);
539 - PEEK(rightVal, 0)
540 + PEEK(rightVal, 0);
541 if (rightVal.tag == ARRAY_TAG) {
542 - PEEK(leftVal, 1)
543 + PEEK(leftVal, 1);
544 if (leftVal.tag == ARRAY_TAG) {
545 SparseArrayEntry *leftIter, *rightIter;
546 resultArray.tag = ARRAY_TAG;
547 resultArray.val.arrayPtr = ArrayNew();
549 - POP(rightVal)
550 - POP(leftVal)
551 + POP(rightVal);
552 + POP(leftVal);
553 leftIter = arrayIterateFirst(&leftVal);
554 rightIter = arrayIterateFirst(&rightVal);
555 while (leftIter || rightIter) {
556 @@ -1836,33 +1892,33 @@ static int bitOr(void)
557 return(execError("array insertion failure", NULL));
560 - PUSH(resultArray)
561 + PUSH(resultArray);
563 else {
564 return(execError("can't mix math with arrays and non-arrays", NULL));
567 else {
568 - POP_INT(n2)
569 - POP_INT(n1)
570 - PUSH_INT(n1 | n2)
571 + POP_INT(n2);
572 + POP_INT(n1);
573 + PUSH_INT(n1 | n2);
575 return(STAT_OK);
578 static int and(void)
580 - BINARY_NUMERIC_OPERATION(&&)
581 + BINARY_NUMERIC_OPERATION(&&);
584 static int or(void)
586 - BINARY_NUMERIC_OPERATION(||)
587 + BINARY_NUMERIC_OPERATION(||);
590 static int not(void)
592 - UNARY_NUMERIC_OPERATION(!)
593 + UNARY_NUMERIC_OPERATION(!);
597 @@ -1877,8 +1933,8 @@ static int power(void)
598 DISASM_RT(PC-1, 1);
599 STACKDUMP(2, 3);
601 - POP_INT(n2)
602 - POP_INT(n1)
603 + POP_INT(n2);
604 + POP_INT(n1);
605 /* We need to round to deal with pow() giving results slightly above
606 or below the real result since it deals with floating point numbers.
607 Note: We're not really wanting rounded results, we merely
608 @@ -1906,7 +1962,7 @@ static int power(void)
609 n3 = (int)(pow((double)n1, (double)n2) + (double)0.5);
612 - PUSH_INT(n3)
613 + PUSH_INT(n3);
614 return errCheck("exponentiation");
617 @@ -1923,14 +1979,14 @@ static int concat(void)
618 DISASM_RT(PC-1, 1);
619 STACKDUMP(2, 3);
621 - POP_STRING(s2)
622 - POP_STRING(s1)
623 + POP_STRING(s2);
624 + POP_STRING(s1);
625 len1 = strlen(s1);
626 len2 = strlen(s2);
627 out = AllocString(len1 + len2 + 1);
628 strncpy(out, s1, len1);
629 strcpy(&out[len1], s2);
630 - PUSH_STRING(out, len1 + len2)
631 + PUSH_STRING(out, len1 + len2);
632 return STAT_OK;
635 @@ -1985,7 +2041,7 @@ static int callSubroutine(void)
636 if (result.tag == NO_TAG) {
637 return execError("%s does not return a value", sym->name);
639 - PUSH(result);
640 + PUSH(result);
641 PC++;
643 return PreemptRequest ? STAT_PREEMPT : STAT_OK;
644 @@ -2035,7 +2091,7 @@ static int callSubroutine(void)
645 argList = (String *)XtCalloc(nArgs, sizeof(*argList));
646 /* pop arguments off the stack and put them in the argument list */
647 for (i=nArgs-1; i>=0; i--) {
648 - POP_STRING(argList[i])
649 + POP_STRING(argList[i]);
652 /* Call the action routine and check for preemption */
653 @@ -2090,7 +2146,7 @@ static int returnValOrNone(int valOnStac
655 /* return value is on the stack */
656 if (valOnStack) {
657 - POP(retVal);
658 + POP(retVal);
661 PC = rewindFrame(&FrameP, &StackP);
662 @@ -2098,13 +2154,13 @@ static int returnValOrNone(int valOnStac
663 /* push returned value, if requsted */
664 if (PC == NULL) {
665 if (valOnStack) {
666 - PUSH(retVal);
667 + PUSH(retVal);
668 } else {
669 - PUSH(noValue);
670 + PUSH(noValue);
672 } else if (PC->func == fetchRetVal) {
673 if (valOnStack) {
674 - PUSH(retVal);
675 + PUSH(retVal);
676 PC++;
677 } else {
678 return execError(
679 @@ -2148,7 +2204,7 @@ static int branchTrue(void)
680 DISASM_RT(PC-1, 2);
681 STACKDUMP(1, 3);
683 - POP_INT(value)
684 + POP_INT(value);
685 addr = PC + PC->value;
686 PC++;
688 @@ -2164,7 +2220,7 @@ static int branchFalse(void)
689 DISASM_RT(PC-1, 2);
690 STACKDUMP(1, 3);
692 - POP_INT(value)
693 + POP_INT(value);
694 addr = PC + PC->value;
695 PC++;
697 @@ -2243,7 +2299,7 @@ static int makeArrayKeyFromArgs(int nArg
699 keyLength = sepLen * (nArgs - 1);
700 for (i = nArgs - 1; i >= 0; --i) {
701 - PEEK(tmpVal, i)
702 + PEEK(tmpVal, i);
703 if (tmpVal.tag == INT_TAG) {
704 keyLength += TYPE_INT_STR_SIZE(tmpVal.val.n);
706 @@ -2260,7 +2316,7 @@ static int makeArrayKeyFromArgs(int nArg
707 if (i != nArgs - 1) {
708 strcat(*keyString, ARRAY_DIM_SEP);
710 - PEEK(tmpVal, i)
711 + PEEK(tmpVal, i);
712 if (tmpVal.tag == INT_TAG) {
713 sprintf(&((*keyString)[strlen(*keyString)]), "%d", tmpVal.val.n);
715 @@ -2273,7 +2329,7 @@ static int makeArrayKeyFromArgs(int nArg
717 if (!leaveParams) {
718 for (i = nArgs - 1; i >= 0; --i) {
719 - POP(tmpVal)
720 + POP(tmpVal);
723 return(STAT_OK);
724 @@ -2497,12 +2553,12 @@ static int arrayRef(void)
725 return(errNum);
728 - POP(srcArray)
729 + POP(srcArray);
730 if (srcArray.tag == ARRAY_TAG) {
731 if (!ArrayGet(&srcArray, keyString, &valueItem)) {
732 return(execError("referenced array value not in array: %s", keyString));
734 - PUSH(valueItem)
735 + PUSH(valueItem);
736 return(STAT_OK);
738 else {
739 @@ -2510,9 +2566,9 @@ static int arrayRef(void)
742 else {
743 - POP(srcArray)
744 + POP(srcArray);
745 if (srcArray.tag == ARRAY_TAG) {
746 - PUSH_INT(ArraySize(&srcArray))
747 + PUSH_INT(ArraySize(&srcArray));
748 return(STAT_OK);
750 else {
751 @@ -2543,14 +2599,14 @@ static int arrayAssign(void)
752 STACKDUMP(nDim, 3);
754 if (nDim > 0) {
755 - POP(srcValue)
756 + POP(srcValue);
758 errNum = makeArrayKeyFromArgs(nDim, &keyString, 0);
759 if (errNum != STAT_OK) {
760 return(errNum);
763 - POP(dstArray)
764 + POP(dstArray);
766 if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) {
767 return(execError("cannot assign array element of non-array", NULL));
768 @@ -2598,7 +2654,7 @@ static int arrayRefAndAssignSetup(void)
769 STACKDUMP(nDim + 1, 3);
771 if (binaryOp) {
772 - POP(moveExpr)
773 + POP(moveExpr);
776 if (nDim > 0) {
777 @@ -2607,14 +2663,14 @@ static int arrayRefAndAssignSetup(void)
778 return(errNum);
781 - PEEK(srcArray, nDim)
782 + PEEK(srcArray, nDim);
783 if (srcArray.tag == ARRAY_TAG) {
784 if (!ArrayGet(&srcArray, keyString, &valueItem)) {
785 return(execError("referenced array value not in array: %s", keyString));
787 - PUSH(valueItem)
788 + PUSH(valueItem);
789 if (binaryOp) {
790 - PUSH(moveExpr)
791 + PUSH(moveExpr);
793 return(STAT_OK);
795 @@ -2651,7 +2707,7 @@ static int beginArrayIter(void)
796 iterator = PC->sym;
797 PC++;
799 - POP(arrayVal)
800 + POP(arrayVal);
802 if (iterator->type == LOCAL_SYM) {
803 iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator);
804 @@ -2763,15 +2819,15 @@ static int inArray(void)
805 DISASM_RT(PC-1, 1);
806 STACKDUMP(2, 3);
808 - POP(theArray)
809 + POP(theArray);
810 if (theArray.tag != ARRAY_TAG) {
811 return(execError("operator in on non-array", NULL));
813 - PEEK(leftArray, 0)
814 + PEEK(leftArray, 0);
815 if (leftArray.tag == ARRAY_TAG) {
816 SparseArrayEntry *iter;
818 - POP(leftArray)
819 + POP(leftArray);
820 inResult = 1;
821 iter = arrayIterateFirst(&leftArray);
822 while (inResult && iter) {
823 @@ -2780,12 +2836,12 @@ static int inArray(void)
826 else {
827 - POP_STRING(keyStr)
828 + POP_STRING(keyStr);
829 if (ArrayGet(&theArray, keyStr, &theValue)) {
830 inResult = 1;
833 - PUSH_INT(inResult)
834 + PUSH_INT(inResult);
835 return(STAT_OK);
838 @@ -2819,7 +2875,7 @@ static int deleteArrayElement(void)
842 - POP(theArray)
843 + POP(theArray);
844 if (theArray.tag == ARRAY_TAG) {
845 if (nDim > 0) {
846 ArrayDelete(&theArray, keyString);
847 @@ -2891,6 +2947,22 @@ int StringToNum(const char *string, int
848 return True;
852 +static const char *tagToStr(enum typeTags tag)
854 + switch (tag) {
855 + case INT_TAG:
856 + return "integer";
857 + case STRING_TAG:
858 + return "string";
859 + case ARRAY_TAG:
860 + return "array";
861 + case NO_TAG:
862 + default:
863 + return "no value";
867 #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */
868 static void dumpVal(DataValue dv)
870 @@ -2917,11 +2989,11 @@ static void dumpVal(DataValue dv)
872 break;
873 case ARRAY_TAG:
874 - printf("<array>");
875 + printf("<%s>", tagToStr(ARRAY_TAG));
876 break;
877 case NO_TAG:
878 if (!dv.val.inst) {
879 - printf("<no value>");
880 + printf("<%s>", tagToStr(NO_TAG));
882 else {
883 printf("?%8p", dv.val.inst);