3 source/interpret.c | 189 ++++++++++++++++++++++++++---------------------------
4 1 file changed, 96 insertions(+), 93 deletions(-)
6 diff --quilt old/source/interpret.c new/source/interpret.c
7 --- old/source/interpret.c
8 +++ new/source/interpret.c
9 @@ -1374,10 +1374,12 @@ static void addToGlobalSymTab(Symbol *sy
10 GlobalSymTab[idx] = sym;
13 +#define EXEC_ERROR(s1, s2) return execError(s1, s2)
17 if (PC->type != SYM_INST) { \
18 - return execError("Unexpected instruction, expected <symbol>: <%s>", \
19 + EXEC_ERROR("Unexpected instruction, expected <symbol>: <%s>", \
20 instTypeToStr(PC->type)); \
23 @@ -1387,7 +1389,7 @@ static void addToGlobalSymTab(Symbol *sy
24 #define GET_IMMED(i) \
26 if (PC->type != IMMED_INST) { \
27 - return execError("Unexpected instruction, expected <immediate>: <%s>", \
28 + EXEC_ERROR("Unexpected instruction, expected <immediate>: <%s>", \
29 instTypeToStr(PC->type)); \
32 @@ -1397,7 +1399,7 @@ static void addToGlobalSymTab(Symbol *sy
33 #define GET_BRANCH(a) \
35 if (PC->type != BRANCH_INST) { \
36 - return execError("Unexpected instruction, expected <branch>: <%s>", \
37 + EXEC_ERROR("Unexpected instruction, expected <branch>: <%s>", \
38 instTypeToStr(PC->type)); \
40 a = PC + PC->val.branch; \
41 @@ -1427,7 +1429,7 @@ static void addToGlobalSymTab(Symbol *sy
42 #define POP_CHECK(n) \
44 if (!OK_TO_POP(n)) { \
45 - return execError(StackUnderflowMsg, ""); \
46 + EXEC_ERROR(StackUnderflowMsg, ""); \
50 @@ -1438,17 +1440,17 @@ static void addToGlobalSymTab(Symbol *sy
51 #define PUSH_CHECK(n) \
53 if (!OK_TO_PUSH(n)) { \
54 - return execError(StackOverflowMsg, ""); \
55 + EXEC_ERROR(StackOverflowMsg, ""); \
59 #define PEEK_CHECK(n) \
61 if (!OK_TO_POP((n) + 1)) { \
62 - return execError(StackUnderflowMsg, ""); \
63 + EXEC_ERROR(StackUnderflowMsg, ""); \
65 if (!OK_TO_PUSH(-(n))) { \
66 - return execError(StackOverflowMsg, ""); \
67 + EXEC_ERROR(StackOverflowMsg, ""); \
71 @@ -1477,10 +1479,10 @@ static void addToGlobalSymTab(Symbol *sy
72 __int = dataVal.val.n; \
73 } else if (dataVal.tag == STRING_TAG) { \
74 if (!StringToNum(dataVal.val.str.rep, &__int)) {\
75 - return execError(StringToNumberMsg, dataVal.val.str.rep); \
76 + EXEC_ERROR(StringToNumberMsg, dataVal.val.str.rep); \
79 - return execError("incompatible type in integer context: <%s>", \
80 + EXEC_ERROR("incompatible type in integer context: <%s>", \
81 tagToStr(dataVal.tag)); \
84 @@ -1494,7 +1496,7 @@ static void addToGlobalSymTab(Symbol *sy
85 } else if (dataVal.tag == INT_TAG) { \
86 __str = AllocStringOfNumber(dataVal.val.n); \
88 - return execError("incompatible type in string context: <%s>", \
89 + EXEC_ERROR("incompatible type in string context: <%s>", \
90 tagToStr(dataVal.tag)); \
93 @@ -1592,7 +1594,7 @@ static int pushSymVal(void)
94 nArgs = FP_GET_ARG_COUNT(FrameP);
95 argNum = s->value.val.n;
96 if (argNum >= nArgs) {
97 - return execError("referenced undefined argument: %s", s->name);
98 + EXEC_ERROR("referenced undefined argument: %s", s->name);
100 if (argNum == N_ARGS_ARG_SYM) {
101 symVal.tag = INT_TAG;
102 @@ -1605,12 +1607,12 @@ static int pushSymVal(void)
104 if (!(s->value.val.subr)(FocusWindow, NULL, 0,
106 - return execError(errMsg, s->name);
107 + EXEC_ERROR(errMsg, s->name);
110 - return execError("reading non-variable: %s", s->name);
111 + EXEC_ERROR("reading non-variable: %s", s->name);
112 if (symVal.tag == NO_TAG && !inTypeOfMode) {
113 - return execError("variable not set: %s", s->name);
114 + EXEC_ERROR("variable not set: %s", s->name);
118 @@ -1650,8 +1652,8 @@ static int pushArgVal(void)
120 nArgs = FP_GET_ARG_COUNT(FrameP);
121 if (argNum >= nArgs || argNum < 0) {
122 - return execError("referenced undefined argument: $args[%s]",
123 - longAsStr(argNum + 1));
124 + EXEC_ERROR("referenced undefined argument: $args[%s]",
125 + longAsStr(argNum + 1));
127 PUSH(FP_GET_ARG_N(FrameP, argNum));
129 @@ -1690,7 +1692,7 @@ static int pushArgArray(void)
130 argVal = FP_GET_ARG_N(FrameP, argNum);
131 if (!ArrayInsert(argArray, AllocStringOfNumber(argNum + 1),
133 - return(execError("argument array insertion failure", NULL));
134 + EXEC_ERROR("argument array insertion failure", NULL);
138 @@ -1726,7 +1728,7 @@ static int pushArraySymVal(void)
139 dataPtr = &sym->value;
142 - return execError("assigning to non-lvalue array or non-array: %s", sym->name);
143 + EXEC_ERROR("assigning to non-lvalue array or non-array: %s", sym->name);
146 if (initEmpty && dataPtr->tag == NO_TAG) {
147 @@ -1735,7 +1737,7 @@ static int pushArraySymVal(void)
150 if (dataPtr->tag == NO_TAG && !inTypeOfMode) {
151 - return execError("variable not set: %s", sym->name);
152 + EXEC_ERROR("variable not set: %s", sym->name);
156 @@ -1828,7 +1830,7 @@ static int anonArrayNextVal(void)
158 sprintf(numString, "%d", nextIndex);
159 if (!ArrayInsert(&anonArray, AllocStringCpy(numString), &exprVal)) {
160 - return(execError("array insertion failure", NULL));
161 + EXEC_ERROR("array insertion failure", NULL);
164 /* we need to increment the index for next time */
165 @@ -1880,7 +1882,7 @@ static int anonArrayIndexVal(void)
168 if (!ArrayInsert(&anonArray, keyString, &exprVal)) {
169 - return(execError("array insertion failure", NULL));
170 + EXEC_ERROR("array insertion failure", NULL);
173 /* push the default next index value first, then the array */
174 @@ -1971,7 +1973,7 @@ static int namedArg1orN(Boolean isFirst)
175 /* if our index is numeric (or can be converted to a number) we must
176 change the next index value */
177 if (nDim == 1 && StringToNum(keyString, &index)) {
178 - return execError("named argument name must not be numeric", NULL);
179 + EXEC_ERROR("named argument name must not be numeric", NULL);
183 @@ -1985,7 +1987,7 @@ static int namedArg1orN(Boolean isFirst)
186 if (!ArrayInsert(&argsArray, keyString, &exprVal)) {
187 - return(execError("named argument insertion failure", NULL));
188 + EXEC_ERROR("named argument insertion failure", NULL);
191 /* and (re)push the array */
192 @@ -2033,13 +2035,13 @@ static int assign(void)
194 if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) {
195 if (sym->type == ARG_SYM) {
196 - return execError("assignment to function argument: %s", sym->name);
197 + EXEC_ERROR("assignment to function argument: %s", sym->name);
199 else if (sym->type == PROC_VALUE_SYM) {
200 - return execError("assignment to read-only variable: %s", sym->name);
201 + EXEC_ERROR("assignment to read-only variable: %s", sym->name);
204 - return execError("assignment to non-variable: %s", sym->name);
205 + EXEC_ERROR("assignment to non-variable: %s", sym->name);
209 @@ -2155,13 +2157,13 @@ static int add(void)
210 rightIter = arrayIterateNext(rightIter);
213 - return(execError("array insertion failure", NULL));
214 + EXEC_ERROR("array insertion failure", NULL);
220 - return(execError("can't mix math with arrays and non-arrays", NULL));
221 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
225 @@ -2169,7 +2171,7 @@ static int add(void)
234 @@ -2221,13 +2223,13 @@ static int subtract(void)
235 leftIter = arrayIterateNext(leftIter);
238 - return(execError("array insertion failure", NULL));
239 + EXEC_ERROR("array insertion failure", NULL);
245 - return(execError("can't mix math with arrays and non-arrays", NULL));
246 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
250 @@ -2235,7 +2237,7 @@ static int subtract(void)
259 @@ -2262,7 +2264,7 @@ static int divide(void)
263 - return execError("division by zero", "");
264 + EXEC_ERROR("division by zero", "");
268 @@ -2278,7 +2280,7 @@ static int modulo(void)
272 - return execError("modulo by zero", "");
273 + EXEC_ERROR("modulo by zero", "");
277 @@ -2359,11 +2361,11 @@ static int eq(void)
281 - return(execError("incompatible types to compare", NULL));
282 + EXEC_ERROR("incompatible types to compare", NULL);
290 /* negated eq() call */
291 @@ -2416,13 +2418,13 @@ static int bitAnd(void)
292 rightIter = arrayIterateNext(rightIter);
295 - return(execError("array insertion failure", NULL));
296 + EXEC_ERROR("array insertion failure", NULL);
302 - return(execError("can't mix math with arrays and non-arrays", NULL));
303 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
307 @@ -2430,7 +2432,7 @@ static int bitAnd(void)
316 @@ -2487,13 +2489,13 @@ static int bitOr(void)
317 rightIter = arrayIterateNext(rightIter);
320 - return(execError("array insertion failure", NULL));
321 + EXEC_ERROR("array insertion failure", NULL);
327 - return(execError("can't mix math with arrays and non-arrays", NULL));
328 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
332 @@ -2501,7 +2503,7 @@ static int bitOr(void)
341 @@ -2601,7 +2603,7 @@ static int concatenateNwithSep(int nVals
342 len += value.val.str.len;
345 - return execError("incompatible type in string context: <%s>",
346 + EXEC_ERROR("incompatible type in string context: <%s>",
347 tagToStr(value.tag));
350 @@ -2723,7 +2725,7 @@ static int callSubroutineFromSymbol(Symb
351 PreemptRequest = False;
352 if (!sym->value.val.subr(FocusWindow, StackP,
353 nArgs, &result, &errMsg))
354 - return execError(errMsg, sym->name);
355 + EXEC_ERROR(errMsg, sym->name);
356 PUSH_RET_VAL(result);
357 return PreemptRequest ? STAT_PREEMPT : STAT_OK;
359 @@ -2758,8 +2760,7 @@ static int callSubroutineFromSymbol(Symb
364 - "%s action routine called with named argument array",
365 + EXEC_ERROR("%s action routine called with named argument array",
369 @@ -2795,7 +2796,7 @@ static int callSubroutineFromSymbol(Symb
372 /* Calling a non subroutine symbol */
373 - return execError("%s is not a function or subroutine", sym->name);
374 + EXEC_ERROR("%s is not a function or subroutine", sym->name);
378 @@ -2865,7 +2866,7 @@ static int callSubroutineUnpackArray(voi
381 if (argArray.tag != ARRAY_TAG) {
382 - return execError("argument array call made with non-array value", NULL);
383 + EXEC_ERROR("argument array call made with non-array value", NULL);
387 @@ -2899,7 +2900,7 @@ static int callSubroutineUnpackArray(voi
390 if (!ArrayInsert(&dvArray, iter->key, &dvEntry)) {
391 - return(execError("array copy failed", NULL));
392 + EXEC_ERROR("array copy failed", NULL);
396 @@ -2974,7 +2975,7 @@ int OverlayRoutineFromProg(Program *prog
398 static int fetchRetVal(void)
400 - return execError("internal error: frv", NULL);
401 + EXEC_ERROR("internal error: frv", NULL);
404 /* see comments for returnValOrNone() */
405 @@ -3117,17 +3118,17 @@ int ArrayCopy(DataValue *dstArray, DataV
408 if (!ArrayInsert(dstArray, srcIter->key, &tmpArray)) {
409 - return(execError("array copy failed", NULL));
414 if (!ArrayInsert(dstArray, srcIter->key, &srcIter->value)) {
415 - return(execError("array copy failed", NULL));
419 srcIter = arrayIterateNext(srcIter);
426 @@ -3147,7 +3148,7 @@ static int makeArrayKeyFromArgs(int nArg
435 @@ -3464,23 +3465,24 @@ static int arrayRef(void)
437 if (srcArray.tag == ARRAY_TAG) {
438 if (!ArrayGet(&srcArray, keyString, &valueItem)) {
439 - return(execError("referenced array value not in array: %s", keyString));
440 + EXEC_ERROR("referenced array value not in array: %s",
448 - return(execError("operator [] on non-array", NULL));
449 + EXEC_ERROR("operator [] on non-array", NULL);
454 if (srcArray.tag == ARRAY_TAG) {
455 PUSH_INT(ArraySize(&srcArray));
460 - return(execError("operator [] on non-array", NULL));
461 + EXEC_ERROR("operator [] on non-array", NULL);
465 @@ -3517,7 +3519,7 @@ static int arrayAssign(void)
468 if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) {
469 - return(execError("cannot assign array element of non-array", NULL));
470 + EXEC_ERROR("cannot assign array element of non-array", NULL);
472 if (srcValue.tag == ARRAY_TAG) {
473 DataValue arrayCopyValue;
474 @@ -3529,13 +3531,13 @@ static int arrayAssign(void)
477 if (ArrayInsert(&dstArray, keyString, &srcValue)) {
482 - return(execError("array member allocation failure", NULL));
483 + EXEC_ERROR("array member allocation failure", NULL);
486 - return(execError("empty operator []", NULL));
487 + EXEC_ERROR("empty operator []", NULL);
491 @@ -3573,20 +3575,21 @@ static int arrayRefAndAssignSetup(void)
492 PEEK(srcArray, nDim);
493 if (srcArray.tag == ARRAY_TAG) {
494 if (!ArrayGet(&srcArray, keyString, &valueItem)) {
495 - return(execError("referenced array value not in array: %s", keyString));
496 + EXEC_ERROR("referenced array value not in array: %s",
507 - return(execError("operator [] on non-array", NULL));
508 + EXEC_ERROR("operator [] on non-array", NULL);
512 - return(execError("array[] not an lvalue", NULL));
513 + EXEC_ERROR("array[] not an lvalue", NULL);
517 @@ -3619,16 +3622,16 @@ static int beginArrayIter(void)
518 iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator);
521 - return(execError("bad temporary iterator: %s", iterator->name));
522 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
525 iteratorValPtr->tag = INT_TAG;
526 if (arrayVal.tag != ARRAY_TAG) {
527 - return(execError("can't iterate non-array", NULL));
528 + EXEC_ERROR("can't iterate non-array", NULL);
531 iteratorValPtr->val.arrayPtr = arrayIterateFirst(&arrayVal);
537 @@ -3685,7 +3688,7 @@ static int arrayIter(void)
538 keyValPtr = &(keySym->value);
541 - return(execError("can't assign to: %s", keySym->name));
542 + EXEC_ERROR("can't assign to: %s", keySym->name);
544 keyValPtr->tag = NO_TAG;
546 @@ -3697,7 +3700,7 @@ static int arrayIter(void)
547 valPtr = &(valSym->value);
550 - return(execError("can't assign to: %s", valSym->name));
551 + EXEC_ERROR("can't assign to: %s", valSym->name);
553 valPtr->tag = NO_TAG;
555 @@ -3706,7 +3709,7 @@ static int arrayIter(void)
556 iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator);
559 - return(execError("bad temporary iterator: %s", iterator->name));
560 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
563 thisEntry = iteratorValPtr->val.arrayPtr;
564 @@ -3727,7 +3730,7 @@ static int arrayIter(void)
573 @@ -3755,21 +3758,21 @@ static int beginArrayIterArray(void)
574 iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator);
577 - return(execError("bad temporary iterator: %s", iterator->name));
578 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
582 - return(execError("bad multi dimension", NULL));
583 + EXEC_ERROR("bad multi dimension", NULL);
586 iteratorValPtr->tag = INT_TAG;
587 if (arrayVal.tag != ARRAY_TAG) {
588 - return(execError("can't iterate non-array", NULL));
589 + EXEC_ERROR("can't iterate non-array", NULL);
592 iteratorValPtr->val.arrayPtr = arrayIterateFirst(&arrayVal);
598 static int countDim(const char *key)
599 @@ -3865,7 +3868,7 @@ static int arrayIterArray(void)
600 keyArrayPtr = &(keyArraySym->value);
603 - return(execError("can't assign to: %s", keyArraySym->name));
604 + EXEC_ERROR("can't assign to: %s", keyArraySym->name);
606 keyArrayPtr->tag = ARRAY_TAG;
607 keyArrayPtr->val.arrayPtr = NULL;
608 @@ -3878,7 +3881,7 @@ static int arrayIterArray(void)
609 valPtr = &valSym->value;
612 - return(execError("can't assign to: %s", valSym->name));
613 + EXEC_ERROR("can't assign to: %s", valSym->name);
615 valPtr->tag = NO_TAG;
617 @@ -3887,7 +3890,7 @@ static int arrayIterArray(void)
618 iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator);
621 - return(execError("bad temporary iterator: %s", iterator->name));
622 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
625 thisEntry = iteratorValPtr->val.arrayPtr;
626 @@ -3908,7 +3911,7 @@ static int arrayIterArray(void)
629 if (!splitKeyIntoArray(thisEntry->key, keyArrayPtr)) {
630 - return(execError("can't split key: %s", thisEntry->key));
631 + EXEC_ERROR("can't split key: %s", thisEntry->key);
635 @@ -3952,7 +3955,7 @@ static int inArray(void)
638 if (theArray.tag != ARRAY_TAG) {
639 - return(execError("operator in on non-array", NULL));
640 + EXEC_ERROR("operator in on non-array", NULL);
643 if (leftArray.tag == ARRAY_TAG) {
644 @@ -3973,7 +3976,7 @@ static int inArray(void)
653 @@ -4016,15 +4019,15 @@ static int deleteArrayElement(void)
657 - return(execError("attempt to delete from non-array", NULL));
658 + EXEC_ERROR("attempt to delete from non-array", NULL);
664 static int typeOfIn(void)
667 - return(execError("I'm already in typeof-mode", NULL));
668 + EXEC_ERROR("I'm already in typeof-mode", NULL);
672 @@ -4038,7 +4041,7 @@ static int typeOfOut(void)
676 - return(execError("I'm not in typeof-mode", NULL));
677 + EXEC_ERROR("I'm not in typeof-mode", NULL);
681 @@ -4089,7 +4092,7 @@ static int arrayAssignNext(void)
684 if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) {
685 - return execError("cannot assign array element of non-array", NULL);
686 + EXEC_ERROR("cannot assign array element of non-array", NULL);
689 if (srcValue.tag == ARRAY_TAG) {
690 @@ -4105,7 +4108,7 @@ static int arrayAssignNext(void)
691 keyString = AllocStringOfNumber(arrayMaxNumIdx(&dstArray) + 1);
693 if (!ArrayInsert(&dstArray, keyString, &srcValue)) {
694 - return execError("array member allocation failure", NULL);
695 + EXEC_ERROR("array member allocation failure", NULL);
699 @@ -4129,7 +4132,7 @@ static int arrayNextNumIdx(void)
702 if (srcArray.tag != ARRAY_TAG) {
703 - return execError("operator [@] on non-array", NULL);
704 + EXEC_ERROR("operator [@] on non-array", NULL);
707 PUSH_INT(arrayMaxNumIdx(&srcArray) + 1);
708 @@ -4144,9 +4147,9 @@ static int arrayNextNumIdx(void)
709 static int errCheck(const char *s)
712 - return execError("%s argument out of domain", s);
713 + EXEC_ERROR("%s argument out of domain", s);
714 else if (errno == ERANGE)
715 - return execError("%s result out of range", s);
716 + EXEC_ERROR("%s result out of range", s);