3 source/interpret.c | 194 +++++++++++++++++++++++++++--------------------------
4 1 file changed, 99 insertions(+), 95 deletions(-)
6 diff --quilt old/source/interpret.c new/source/interpret.c
7 --- old/source/interpret.c
8 +++ new/source/interpret.c
9 @@ -1375,10 +1375,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 @@ -1388,7 +1390,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 @@ -1398,7 +1400,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 @@ -1439,7 +1441,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 @@ -1450,17 +1452,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 @@ -1489,10 +1491,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 @@ -1506,7 +1508,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 @@ -1604,7 +1606,7 @@ static int pushSymVal(void)
94 nArgs = FRAME_GET_ARG_COUNT();
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 @@ -1617,7 +1619,7 @@ 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);
109 } else if (s->type == C_FUNCTION_SYM
110 || s->type == MACRO_FUNCTION_SYM
111 @@ -1625,9 +1627,9 @@ static int pushSymVal(void)
112 symVal.tag = SUBR_TAG;
115 - return execError("reading non-variable: %s", s->name);
116 + EXEC_ERROR("reading non-variable: %s", s->name);
117 if (symVal.tag == NO_TAG && !inTypeOfMode) {
118 - return execError("variable not set: %s", s->name);
119 + EXEC_ERROR("variable not set: %s", s->name);
123 @@ -1667,8 +1669,8 @@ static int pushArgVal(void)
125 nArgs = FRAME_GET_ARG_COUNT();
126 if (argNum >= nArgs || argNum < 0) {
127 - return execError("referenced undefined argument: $args[%s]",
128 - longAsStr(argNum + 1));
129 + EXEC_ERROR("referenced undefined argument: $args[%s]",
130 + longAsStr(argNum + 1));
132 PUSH(FRAME_GET_ARG_N(argNum));
134 @@ -1707,7 +1709,7 @@ static int pushArgArray(void)
135 argVal = FRAME_GET_ARG_N(argNum);
136 if (!ArrayInsert(argArray, AllocStringOfNumber(argNum + 1),
138 - return(execError("argument array insertion failure", NULL));
139 + EXEC_ERROR("argument array insertion failure", NULL);
143 @@ -1743,7 +1745,7 @@ static int pushArraySymVal(void)
144 dataPtr = &sym->value;
147 - return execError("assigning to non-lvalue array or non-array: %s", sym->name);
148 + EXEC_ERROR("assigning to non-lvalue array or non-array: %s", sym->name);
151 if (initEmpty && dataPtr->tag == NO_TAG) {
152 @@ -1752,7 +1754,7 @@ static int pushArraySymVal(void)
155 if (dataPtr->tag == NO_TAG && !inTypeOfMode) {
156 - return execError("variable not set: %s", sym->name);
157 + EXEC_ERROR("variable not set: %s", sym->name);
161 @@ -1845,7 +1847,7 @@ static int anonArrayNextVal(void)
163 sprintf(numString, "%d", nextIndex);
164 if (!ArrayInsert(&anonArray, AllocStringCpy(numString), &exprVal)) {
165 - return(execError("array insertion failure", NULL));
166 + EXEC_ERROR("array insertion failure", NULL);
169 /* we need to increment the index for next time */
170 @@ -1897,7 +1899,7 @@ static int anonArrayIndexVal(void)
173 if (!ArrayInsert(&anonArray, keyString, &exprVal)) {
174 - return(execError("array insertion failure", NULL));
175 + EXEC_ERROR("array insertion failure", NULL);
178 /* push the default next index value first, then the array */
179 @@ -1988,7 +1990,7 @@ static int namedArg1orN(Boolean isFirst)
180 /* if our index is numeric (or can be converted to a number) we must
181 change the next index value */
182 if (nDim == 1 && StringToNum(keyString, &index)) {
183 - return execError("named argument name must not be numeric", NULL);
184 + EXEC_ERROR("named argument name must not be numeric", NULL);
188 @@ -2002,7 +2004,7 @@ static int namedArg1orN(Boolean isFirst)
191 if (!ArrayInsert(&argsArray, keyString, &exprVal)) {
192 - return(execError("named argument insertion failure", NULL));
193 + EXEC_ERROR("named argument insertion failure", NULL);
196 /* and (re)push the array */
197 @@ -2050,13 +2052,13 @@ static int assign(void)
199 if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) {
200 if (sym->type == ARG_SYM) {
201 - return execError("assignment to function argument: %s", sym->name);
202 + EXEC_ERROR("assignment to function argument: %s", sym->name);
204 else if (sym->type == PROC_VALUE_SYM) {
205 - return execError("assignment to read-only variable: %s", sym->name);
206 + EXEC_ERROR("assignment to read-only variable: %s", sym->name);
209 - return execError("assignment to non-variable: %s", sym->name);
210 + EXEC_ERROR("assignment to non-variable: %s", sym->name);
214 @@ -2172,13 +2174,13 @@ static int add(void)
215 rightIter = arrayIterateNext(rightIter);
218 - return(execError("array insertion failure", NULL));
219 + EXEC_ERROR("array insertion failure", NULL);
225 - return(execError("can't mix math with arrays and non-arrays", NULL));
226 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
230 @@ -2186,7 +2188,7 @@ static int add(void)
239 @@ -2238,13 +2240,13 @@ static int subtract(void)
240 leftIter = arrayIterateNext(leftIter);
243 - return(execError("array insertion failure", NULL));
244 + EXEC_ERROR("array insertion failure", NULL);
250 - return(execError("can't mix math with arrays and non-arrays", NULL));
251 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
255 @@ -2252,7 +2254,7 @@ static int subtract(void)
264 @@ -2279,7 +2281,7 @@ static int divide(void)
268 - return execError("division by zero", "");
269 + EXEC_ERROR("division by zero", "");
273 @@ -2295,7 +2297,7 @@ static int modulo(void)
277 - return execError("modulo by zero", "");
278 + EXEC_ERROR("modulo by zero", "");
282 @@ -2376,11 +2378,11 @@ static int eq(void)
286 - return(execError("incompatible types to compare", NULL));
287 + EXEC_ERROR("incompatible types to compare", NULL);
295 /* negated eq() call */
296 @@ -2433,13 +2435,13 @@ static int bitAnd(void)
297 rightIter = arrayIterateNext(rightIter);
300 - return(execError("array insertion failure", NULL));
301 + EXEC_ERROR("array insertion failure", NULL);
307 - return(execError("can't mix math with arrays and non-arrays", NULL));
308 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
312 @@ -2447,7 +2449,7 @@ static int bitAnd(void)
321 @@ -2504,13 +2506,13 @@ static int bitOr(void)
322 rightIter = arrayIterateNext(rightIter);
325 - return(execError("array insertion failure", NULL));
326 + EXEC_ERROR("array insertion failure", NULL);
332 - return(execError("can't mix math with arrays and non-arrays", NULL));
333 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
337 @@ -2518,7 +2520,7 @@ static int bitOr(void)
346 @@ -2618,7 +2620,7 @@ static int concatenateNwithSep(int nVals
347 len += value.val.str.len;
350 - return execError("incompatible type in string context: <%s>",
351 + EXEC_ERROR("incompatible type in string context: <%s>",
352 tagToStr(value.tag));
355 @@ -2735,7 +2737,8 @@ static int callSubroutineFromSymbol(Symb
356 if (symValPtr->tag == SUBR_TAG) {
357 sym = symValPtr->val.sym;
359 - return execError("%s is not a variable holding a subroutine pointer", sym->name);
360 + EXEC_ERROR("%s is not a variable holding a subroutine pointer",
365 @@ -2754,7 +2757,7 @@ static int callSubroutineFromSymbol(Symb
366 PreemptRequest = False;
367 if (!sym->value.val.subr(FocusWindow, StackP,
368 nArgs, &result, &errMsg))
369 - return execError(errMsg, sym->name);
370 + EXEC_ERROR(errMsg, sym->name);
371 PUSH_RET_VAL(result);
372 return PreemptRequest ? STAT_PREEMPT : STAT_OK;
374 @@ -2789,8 +2792,7 @@ static int callSubroutineFromSymbol(Symb
379 - "%s action routine called with named argument array",
380 + EXEC_ERROR("%s action routine called with named argument array",
384 @@ -2826,7 +2828,7 @@ static int callSubroutineFromSymbol(Symb
387 /* Calling a non subroutine symbol */
388 - return execError("%s is not a function or subroutine", sym->name);
389 + EXEC_ERROR("%s is not a function or subroutine", sym->name);
393 @@ -2882,7 +2884,7 @@ static int callSubroutineStackedN(void)
396 /* should never happen */
397 - return execError("array argument call to %s erroneous", sym->name);
398 + EXEC_ERROR("array argument call to %s erroneous", sym->name);
401 return callSubroutineFromSymbol(sym, nArgs);
402 @@ -2991,7 +2993,7 @@ static int unpackArrayToArgs(void)
405 if (argArray.tag != ARRAY_TAG) {
406 - return execError("argument array call made with non-array value", NULL);
407 + EXEC_ERROR("argument array call made with non-array value", NULL);
411 @@ -3026,7 +3028,7 @@ static int unpackArrayToArgs(void)
414 if (!ArrayInsert(&dvArray, iter->key, &dvEntry)) {
415 - return(execError("array copy failed", NULL));
416 + EXEC_ERROR("array copy failed", NULL);
420 @@ -3045,7 +3047,7 @@ static int unpackArrayToArgs(void)
422 static int fetchRetVal(void)
424 - return execError("internal error: frv", NULL);
425 + EXEC_ERROR("internal error: frv", NULL);
428 /* see comments for returnValOrNone() */
429 @@ -3185,17 +3187,17 @@ int ArrayCopy(DataValue *dstArray, DataV
432 if (!ArrayInsert(dstArray, srcIter->key, &tmpArray)) {
433 - return(execError("array copy failed", NULL));
438 if (!ArrayInsert(dstArray, srcIter->key, &srcIter->value)) {
439 - return(execError("array copy failed", NULL));
443 srcIter = arrayIterateNext(srcIter);
450 @@ -3215,7 +3217,7 @@ static int makeArrayKeyFromArgs(int nArg
459 @@ -3535,23 +3537,24 @@ static int arrayRef(void)
461 if (srcArray.tag == ARRAY_TAG) {
462 if (!ArrayGet(&srcArray, keyString, &valueItem)) {
463 - return(execError("referenced array value not in array: %s", keyString));
464 + EXEC_ERROR("referenced array value not in array: %s",
472 - return(execError("operator [] on non-array", NULL));
473 + EXEC_ERROR("operator [] on non-array", NULL);
478 if (srcArray.tag == ARRAY_TAG) {
479 PUSH_INT(ArraySize(&srcArray));
484 - return(execError("operator [] on non-array", NULL));
485 + EXEC_ERROR("operator [] on non-array", NULL);
489 @@ -3588,7 +3591,7 @@ static int arrayAssign(void)
492 if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) {
493 - return(execError("cannot assign array element of non-array", NULL));
494 + EXEC_ERROR("cannot assign array element of non-array", NULL);
496 if (srcValue.tag == ARRAY_TAG) {
497 DataValue arrayCopyValue;
498 @@ -3600,13 +3603,13 @@ static int arrayAssign(void)
501 if (ArrayInsert(&dstArray, keyString, &srcValue)) {
506 - return(execError("array member allocation failure", NULL));
507 + EXEC_ERROR("array member allocation failure", NULL);
510 - return(execError("empty operator []", NULL));
511 + EXEC_ERROR("empty operator []", NULL);
515 @@ -3644,20 +3647,21 @@ static int arrayRefAndAssignSetup(void)
516 PEEK(srcArray, nDim);
517 if (srcArray.tag == ARRAY_TAG) {
518 if (!ArrayGet(&srcArray, keyString, &valueItem)) {
519 - return(execError("referenced array value not in array: %s", keyString));
520 + EXEC_ERROR("referenced array value not in array: %s",
531 - return(execError("operator [] on non-array", NULL));
532 + EXEC_ERROR("operator [] on non-array", NULL);
536 - return(execError("array[] not an lvalue", NULL));
537 + EXEC_ERROR("array[] not an lvalue", NULL);
541 @@ -3690,16 +3694,16 @@ static int beginArrayIter(void)
542 iteratorValPtr = &FRAME_GET_SYM_VAL(iterator);
545 - return(execError("bad temporary iterator: %s", iterator->name));
546 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
549 iteratorValPtr->tag = INT_TAG;
550 if (arrayVal.tag != ARRAY_TAG) {
551 - return(execError("can't iterate non-array", NULL));
552 + EXEC_ERROR("can't iterate non-array", NULL);
555 iteratorValPtr->val.arrayPtr = arrayIterateFirst(&arrayVal);
561 @@ -3756,7 +3760,7 @@ static int arrayIter(void)
562 keyValPtr = &(keySym->value);
565 - return(execError("can't assign to: %s", keySym->name));
566 + EXEC_ERROR("can't assign to: %s", keySym->name);
568 keyValPtr->tag = NO_TAG;
570 @@ -3768,7 +3772,7 @@ static int arrayIter(void)
571 valPtr = &(valSym->value);
574 - return(execError("can't assign to: %s", valSym->name));
575 + EXEC_ERROR("can't assign to: %s", valSym->name);
577 valPtr->tag = NO_TAG;
579 @@ -3777,7 +3781,7 @@ static int arrayIter(void)
580 iteratorValPtr = &FRAME_GET_SYM_VAL(iterator);
583 - return(execError("bad temporary iterator: %s", iterator->name));
584 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
587 thisEntry = iteratorValPtr->val.arrayPtr;
588 @@ -3798,7 +3802,7 @@ static int arrayIter(void)
597 @@ -3826,21 +3830,21 @@ static int beginArrayIterArray(void)
598 iteratorValPtr = &FRAME_GET_SYM_VAL(iterator);
601 - return(execError("bad temporary iterator: %s", iterator->name));
602 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
606 - return(execError("bad multi dimension", NULL));
607 + EXEC_ERROR("bad multi dimension", NULL);
610 iteratorValPtr->tag = INT_TAG;
611 if (arrayVal.tag != ARRAY_TAG) {
612 - return(execError("can't iterate non-array", NULL));
613 + EXEC_ERROR("can't iterate non-array", NULL);
616 iteratorValPtr->val.arrayPtr = arrayIterateFirst(&arrayVal);
622 static int countDim(const char *key)
623 @@ -3936,7 +3940,7 @@ static int arrayIterArray(void)
624 keyArrayPtr = &(keyArraySym->value);
627 - return(execError("can't assign to: %s", keyArraySym->name));
628 + EXEC_ERROR("can't assign to: %s", keyArraySym->name);
630 keyArrayPtr->tag = ARRAY_TAG;
631 keyArrayPtr->val.arrayPtr = NULL;
632 @@ -3949,7 +3953,7 @@ static int arrayIterArray(void)
633 valPtr = &valSym->value;
636 - return(execError("can't assign to: %s", valSym->name));
637 + EXEC_ERROR("can't assign to: %s", valSym->name);
639 valPtr->tag = NO_TAG;
641 @@ -3958,7 +3962,7 @@ static int arrayIterArray(void)
642 iteratorValPtr = &FRAME_GET_SYM_VAL(iterator);
645 - return(execError("bad temporary iterator: %s", iterator->name));
646 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
649 thisEntry = iteratorValPtr->val.arrayPtr;
650 @@ -3979,7 +3983,7 @@ static int arrayIterArray(void)
653 if (!splitKeyIntoArray(thisEntry->key, keyArrayPtr)) {
654 - return(execError("can't split key: %s", thisEntry->key));
655 + EXEC_ERROR("can't split key: %s", thisEntry->key);
659 @@ -4023,7 +4027,7 @@ static int inArray(void)
662 if (theArray.tag != ARRAY_TAG) {
663 - return(execError("operator in on non-array", NULL));
664 + EXEC_ERROR("operator in on non-array", NULL);
667 if (leftArray.tag == ARRAY_TAG) {
668 @@ -4044,7 +4048,7 @@ static int inArray(void)
677 @@ -4087,15 +4091,15 @@ static int deleteArrayElement(void)
681 - return(execError("attempt to delete from non-array", NULL));
682 + EXEC_ERROR("attempt to delete from non-array", NULL);
688 static int typeOfIn(void)
691 - return(execError("I'm already in typeof-mode", NULL));
692 + EXEC_ERROR("I'm already in typeof-mode", NULL);
696 @@ -4109,7 +4113,7 @@ static int typeOfOut(void)
700 - return(execError("I'm not in typeof-mode", NULL));
701 + EXEC_ERROR("I'm not in typeof-mode", NULL);
705 @@ -4163,7 +4167,7 @@ static int arrayAssignNext(void)
708 if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) {
709 - return execError("cannot assign array element of non-array", NULL);
710 + EXEC_ERROR("cannot assign array element of non-array", NULL);
713 if (srcValue.tag == ARRAY_TAG) {
714 @@ -4179,7 +4183,7 @@ static int arrayAssignNext(void)
715 keyString = AllocStringOfNumber(arrayMaxNumIdx(&dstArray) + 1);
717 if (!ArrayInsert(&dstArray, keyString, &srcValue)) {
718 - return execError("array member allocation failure", NULL);
719 + EXEC_ERROR("array member allocation failure", NULL);
723 @@ -4203,7 +4207,7 @@ static int arrayNextNumIdx(void)
726 if (srcArray.tag != ARRAY_TAG) {
727 - return execError("operator [@] on non-array", NULL);
728 + EXEC_ERROR("operator [@] on non-array", NULL);
731 PUSH_INT(arrayMaxNumIdx(&srcArray) + 1);
732 @@ -4218,9 +4222,9 @@ static int arrayNextNumIdx(void)
733 static int errCheck(const char *s)
736 - return execError("%s argument out of domain", s);
737 + EXEC_ERROR("%s argument out of domain", s);
738 else if (errno == ERANGE)
739 - return execError("%s result out of range", s);
740 + EXEC_ERROR("%s result out of range", s);