3 source/interpret.c | 200 +++++++++++++++++++++++++++--------------------------
4 1 file changed, 102 insertions(+), 98 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,11 +1491,11 @@ 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 - tagToStr(dataVal.tag))); \
81 + EXEC_ERROR("incompatible type in integer context: %s", \
82 + tagToStr(dataVal.tag)); \
86 @@ -1506,8 +1508,8 @@ static void addToGlobalSymTab(Symbol *sy
87 } else if (dataVal.tag == INT_TAG) { \
88 __str = AllocStringOfNumber(dataVal.val.n); \
90 - return(execError("incompatible type in string context: %s", \
91 - tagToStr(dataVal.tag))); \
92 + EXEC_ERROR("incompatible type in string context: %s", \
93 + tagToStr(dataVal.tag)); \
97 @@ -1604,7 +1606,7 @@ static int pushSymVal(void)
98 nArgs = FRAME_GET_ARG_COUNT();
99 argNum = s->value.val.n;
100 if (argNum >= nArgs) {
101 - return execError("referenced undefined argument: %s", s->name);
102 + EXEC_ERROR("referenced undefined argument: %s", s->name);
104 if (argNum == N_ARGS_ARG_SYM) {
105 symVal.tag = INT_TAG;
106 @@ -1617,7 +1619,7 @@ static int pushSymVal(void)
108 if (!(s->value.val.subr)(FocusWindow, NULL, 0,
110 - return execError(errMsg, s->name);
111 + EXEC_ERROR(errMsg, s->name);
113 } else if (s->type == C_FUNCTION_SYM
114 || s->type == MACRO_FUNCTION_SYM
115 @@ -1625,9 +1627,9 @@ static int pushSymVal(void)
116 symVal.tag = SUBR_TAG;
119 - return execError("reading non-variable: %s", s->name);
120 + EXEC_ERROR("reading non-variable: %s", s->name);
121 if (symVal.tag == NO_TAG && !inTypeOfMode) {
122 - return execError("variable not set: %s", s->name);
123 + EXEC_ERROR("variable not set: %s", s->name);
127 @@ -1667,8 +1669,8 @@ static int pushArgVal(void)
129 nArgs = FRAME_GET_ARG_COUNT();
130 if (argNum >= nArgs || argNum < 0) {
131 - return execError("referenced undefined argument: $args[%s]",
132 - longAsStr(argNum + 1));
133 + EXEC_ERROR("referenced undefined argument: $args[%s]",
134 + longAsStr(argNum + 1));
136 PUSH(FRAME_GET_ARG_N(argNum));
138 @@ -1707,7 +1709,7 @@ static int pushArgArray(void)
139 argVal = FRAME_GET_ARG_N(argNum);
140 if (!ArrayInsert(argArray, AllocStringOfNumber(argNum + 1),
142 - return(execError("argument array insertion failure", NULL));
143 + EXEC_ERROR("argument array insertion failure", NULL);
147 @@ -1743,7 +1745,7 @@ static int pushArraySymVal(void)
148 dataPtr = &sym->value;
151 - return execError("assigning to non-lvalue array or non-array: %s", sym->name);
152 + EXEC_ERROR("assigning to non-lvalue array or non-array: %s", sym->name);
155 if (initEmpty && dataPtr->tag == NO_TAG) {
156 @@ -1752,7 +1754,7 @@ static int pushArraySymVal(void)
159 if (dataPtr->tag == NO_TAG && !inTypeOfMode) {
160 - return execError("variable not set: %s", sym->name);
161 + EXEC_ERROR("variable not set: %s", sym->name);
165 @@ -1845,7 +1847,7 @@ static int anonArrayNextVal(void)
167 sprintf(numString, "%d", nextIndex);
168 if (!ArrayInsert(&anonArray, AllocStringCpy(numString), &exprVal)) {
169 - return(execError("array insertion failure", NULL));
170 + EXEC_ERROR("array insertion failure", NULL);
173 /* we need to increment the index for next time */
174 @@ -1897,7 +1899,7 @@ static int anonArrayIndexVal(void)
177 if (!ArrayInsert(&anonArray, keyString, &exprVal)) {
178 - return(execError("array insertion failure", NULL));
179 + EXEC_ERROR("array insertion failure", NULL);
182 /* push the default next index value first, then the array */
183 @@ -1988,7 +1990,7 @@ static int namedArg1orN(Boolean isFirst)
184 /* if our index is numeric (or can be converted to a number) we must
185 change the next index value */
186 if (nDim == 1 && StringToNum(keyString, &index)) {
187 - return execError("named argument name must not be numeric", NULL);
188 + EXEC_ERROR("named argument name must not be numeric", NULL);
192 @@ -2002,7 +2004,7 @@ static int namedArg1orN(Boolean isFirst)
195 if (!ArrayInsert(&argsArray, keyString, &exprVal)) {
196 - return(execError("named argument insertion failure", NULL));
197 + EXEC_ERROR("named argument insertion failure", NULL);
200 /* and (re)push the array */
201 @@ -2050,13 +2052,13 @@ static int assign(void)
203 if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) {
204 if (sym->type == ARG_SYM) {
205 - return execError("assignment to function argument: %s", sym->name);
206 + EXEC_ERROR("assignment to function argument: %s", sym->name);
208 else if (sym->type == PROC_VALUE_SYM) {
209 - return execError("assignment to read-only variable: %s", sym->name);
210 + EXEC_ERROR("assignment to read-only variable: %s", sym->name);
213 - return execError("assignment to non-variable: %s", sym->name);
214 + EXEC_ERROR("assignment to non-variable: %s", sym->name);
218 @@ -2172,13 +2174,13 @@ static int add(void)
219 rightIter = arrayIterateNext(rightIter);
222 - return(execError("array insertion failure", NULL));
223 + EXEC_ERROR("array insertion failure", NULL);
229 - return(execError("can't mix math with arrays and non-arrays", NULL));
230 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
234 @@ -2186,7 +2188,7 @@ static int add(void)
243 @@ -2238,13 +2240,13 @@ static int subtract(void)
244 leftIter = arrayIterateNext(leftIter);
247 - return(execError("array insertion failure", NULL));
248 + EXEC_ERROR("array insertion failure", NULL);
254 - return(execError("can't mix math with arrays and non-arrays", NULL));
255 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
259 @@ -2252,7 +2254,7 @@ static int subtract(void)
268 @@ -2279,7 +2281,7 @@ static int divide(void)
272 - return execError("division by zero", "");
273 + EXEC_ERROR("division by zero", "");
277 @@ -2295,7 +2297,7 @@ static int modulo(void)
281 - return execError("modulo by zero", "");
282 + EXEC_ERROR("modulo by zero", "");
286 @@ -2376,11 +2378,11 @@ static int eq(void)
290 - return(execError("incompatible types to compare", NULL));
291 + EXEC_ERROR("incompatible types to compare", NULL);
299 /* negated eq() call */
300 @@ -2433,13 +2435,13 @@ static int bitAnd(void)
301 rightIter = arrayIterateNext(rightIter);
304 - return(execError("array insertion failure", NULL));
305 + EXEC_ERROR("array insertion failure", NULL);
311 - return(execError("can't mix math with arrays and non-arrays", NULL));
312 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
316 @@ -2447,7 +2449,7 @@ static int bitAnd(void)
325 @@ -2504,13 +2506,13 @@ static int bitOr(void)
326 rightIter = arrayIterateNext(rightIter);
329 - return(execError("array insertion failure", NULL));
330 + EXEC_ERROR("array insertion failure", NULL);
336 - return(execError("can't mix math with arrays and non-arrays", NULL));
337 + EXEC_ERROR("can't mix math with arrays and non-arrays", NULL);
341 @@ -2518,7 +2520,7 @@ static int bitOr(void)
350 @@ -2675,7 +2677,7 @@ static int concat(void)
352 len = concatenateNwithSep(nExpr, "", &out, False);
354 - return(execError("can only concatenate with string or integer", NULL));
355 + EXEC_ERROR("can only concatenate with string or integer", NULL);
357 PUSH_STRING(out, len);
359 @@ -2732,7 +2734,8 @@ static int callSubroutineFromSymbol(Symb
360 if (symValPtr->tag == SUBR_TAG) {
361 sym = symValPtr->val.sym;
363 - return execError("%s is not a variable holding a subroutine pointer", sym->name);
364 + EXEC_ERROR("%s is not a variable holding a subroutine pointer",
369 @@ -2751,7 +2754,7 @@ static int callSubroutineFromSymbol(Symb
370 PreemptRequest = False;
371 if (!sym->value.val.subr(FocusWindow, StackP,
372 nArgs, &result, &errMsg))
373 - return execError(errMsg, sym->name);
374 + EXEC_ERROR(errMsg, sym->name);
375 PUSH_RET_VAL(result);
376 return PreemptRequest ? STAT_PREEMPT : STAT_OK;
378 @@ -2786,8 +2789,7 @@ static int callSubroutineFromSymbol(Symb
383 - "%s action routine called with named argument array",
384 + EXEC_ERROR("%s action routine called with named argument array",
388 @@ -2823,7 +2825,7 @@ static int callSubroutineFromSymbol(Symb
391 /* Calling a non subroutine symbol */
392 - return execError("%s is not a function or subroutine", sym->name);
393 + EXEC_ERROR("%s is not a function or subroutine", sym->name);
397 @@ -2879,7 +2881,7 @@ static int callSubroutineStackedN(void)
400 /* should never happen */
401 - return execError("array argument call to %s erroneous", sym->name);
402 + EXEC_ERROR("array argument call to %s erroneous", sym->name);
405 return callSubroutineFromSymbol(sym, nArgs);
406 @@ -2988,7 +2990,7 @@ static int unpackArrayToArgs(void)
409 if (argArray.tag != ARRAY_TAG) {
410 - return execError("argument array call made with non-array value", NULL);
411 + EXEC_ERROR("argument array call made with non-array value", NULL);
415 @@ -3023,7 +3025,7 @@ static int unpackArrayToArgs(void)
418 if (!ArrayInsert(&dvArray, iter->key, &dvEntry)) {
419 - return(execError("array copy failed", NULL));
420 + EXEC_ERROR("array copy failed", NULL);
424 @@ -3042,7 +3044,7 @@ static int unpackArrayToArgs(void)
426 static int fetchRetVal(void)
428 - return execError("internal error: frv", NULL);
429 + EXEC_ERROR("internal error: frv", NULL);
432 /* see comments for returnValOrNone() */
433 @@ -3182,17 +3184,17 @@ int ArrayCopy(DataValue *dstArray, DataV
436 if (!ArrayInsert(dstArray, srcIter->key, &tmpArray)) {
437 - return(execError("array copy failed", NULL));
442 if (!ArrayInsert(dstArray, srcIter->key, &srcIter->value)) {
443 - return(execError("array copy failed", NULL));
447 srcIter = arrayIterateNext(srcIter);
454 @@ -3209,9 +3211,9 @@ static int makeArrayKeyFromArgs(int nArg
456 len = concatenateNwithSep(nArgs, ARRAY_DIM_SEP, keyString, leaveParams);
458 - return(execError("can only index array with string or int.", NULL));
459 + EXEC_ERROR("can only index array with string or int.", NULL);
466 @@ -3531,23 +3533,24 @@ static int arrayRef(void)
468 if (srcArray.tag == ARRAY_TAG) {
469 if (!ArrayGet(&srcArray, keyString, &valueItem)) {
470 - return(execError("referenced array value not in array: %s", keyString));
471 + EXEC_ERROR("referenced array value not in array: %s",
479 - return(execError("operator [] on non-array", NULL));
480 + EXEC_ERROR("operator [] on non-array", NULL);
485 if (srcArray.tag == ARRAY_TAG) {
486 PUSH_INT(ArraySize(&srcArray));
491 - return(execError("operator [] on non-array", NULL));
492 + EXEC_ERROR("operator [] on non-array", NULL);
496 @@ -3584,7 +3587,7 @@ static int arrayAssign(void)
499 if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) {
500 - return(execError("cannot assign array element of non-array", NULL));
501 + EXEC_ERROR("cannot assign array element of non-array", NULL);
503 if (srcValue.tag == ARRAY_TAG) {
504 DataValue arrayCopyValue;
505 @@ -3596,13 +3599,13 @@ static int arrayAssign(void)
508 if (ArrayInsert(&dstArray, keyString, &srcValue)) {
513 - return(execError("array member allocation failure", NULL));
514 + EXEC_ERROR("array member allocation failure", NULL);
517 - return(execError("empty operator []", NULL));
518 + EXEC_ERROR("empty operator []", NULL);
522 @@ -3640,20 +3643,21 @@ static int arrayRefAndAssignSetup(void)
523 PEEK(srcArray, nDim);
524 if (srcArray.tag == ARRAY_TAG) {
525 if (!ArrayGet(&srcArray, keyString, &valueItem)) {
526 - return(execError("referenced array value not in array: %s", keyString));
527 + EXEC_ERROR("referenced array value not in array: %s",
538 - return(execError("operator [] on non-array", NULL));
539 + EXEC_ERROR("operator [] on non-array", NULL);
543 - return(execError("array[] not an lvalue", NULL));
544 + EXEC_ERROR("array[] not an lvalue", NULL);
548 @@ -3686,16 +3690,16 @@ static int beginArrayIter(void)
549 iteratorValPtr = &FRAME_GET_SYM_VAL(iterator);
552 - return(execError("bad temporary iterator: %s", iterator->name));
553 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
556 iteratorValPtr->tag = INT_TAG;
557 if (arrayVal.tag != ARRAY_TAG) {
558 - return(execError("can't iterate non-array", NULL));
559 + EXEC_ERROR("can't iterate non-array", NULL);
562 iteratorValPtr->val.arrayPtr = arrayIterateFirst(&arrayVal);
568 @@ -3752,7 +3756,7 @@ static int arrayIter(void)
569 keyValPtr = &(keySym->value);
572 - return(execError("can't assign to: %s", keySym->name));
573 + EXEC_ERROR("can't assign to: %s", keySym->name);
575 keyValPtr->tag = NO_TAG;
577 @@ -3764,7 +3768,7 @@ static int arrayIter(void)
578 valPtr = &(valSym->value);
581 - return(execError("can't assign to: %s", valSym->name));
582 + EXEC_ERROR("can't assign to: %s", valSym->name);
584 valPtr->tag = NO_TAG;
586 @@ -3773,7 +3777,7 @@ static int arrayIter(void)
587 iteratorValPtr = &FRAME_GET_SYM_VAL(iterator);
590 - return(execError("bad temporary iterator: %s", iterator->name));
591 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
594 thisEntry = iteratorValPtr->val.arrayPtr;
595 @@ -3794,7 +3798,7 @@ static int arrayIter(void)
604 @@ -3822,21 +3826,21 @@ static int beginArrayMultiIterArray(void
605 iteratorValPtr = &FRAME_GET_SYM_VAL(iterator);
608 - return(execError("bad temporary iterator: %s", iterator->name));
609 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
613 - return(execError("bad multi dimension", NULL));
614 + EXEC_ERROR("bad multi dimension", NULL);
617 iteratorValPtr->tag = INT_TAG;
618 if (arrayVal.tag != ARRAY_TAG) {
619 - return(execError("can't iterate non-array", NULL));
620 + EXEC_ERROR("can't iterate non-array", NULL);
623 iteratorValPtr->val.arrayPtr = arrayIterateFirst(&arrayVal);
629 static int countDim(const char *key)
630 @@ -3932,7 +3936,7 @@ static int arrayMultiIterArray(void)
631 keyArrayPtr = &(keyArraySym->value);
634 - return(execError("can't assign to: %s", keyArraySym->name));
635 + EXEC_ERROR("can't assign to: %s", keyArraySym->name);
637 keyArrayPtr->tag = ARRAY_TAG;
638 keyArrayPtr->val.arrayPtr = NULL;
639 @@ -3945,7 +3949,7 @@ static int arrayMultiIterArray(void)
640 valPtr = &valSym->value;
643 - return(execError("can't assign to: %s", valSym->name));
644 + EXEC_ERROR("can't assign to: %s", valSym->name);
646 valPtr->tag = NO_TAG;
648 @@ -3954,7 +3958,7 @@ static int arrayMultiIterArray(void)
649 iteratorValPtr = &FRAME_GET_SYM_VAL(iterator);
652 - return(execError("bad temporary iterator: %s", iterator->name));
653 + EXEC_ERROR("bad temporary iterator: %s", iterator->name);
656 thisEntry = iteratorValPtr->val.arrayPtr;
657 @@ -3975,7 +3979,7 @@ static int arrayMultiIterArray(void)
660 if (!splitKeyIntoArray(thisEntry->key, keyArrayPtr)) {
661 - return(execError("can't split key: %s", thisEntry->key));
662 + EXEC_ERROR("can't split key: %s", thisEntry->key);
666 @@ -4019,7 +4023,7 @@ static int inArray(void)
669 if (theArray.tag != ARRAY_TAG) {
670 - return(execError("operator in on non-array", NULL));
671 + EXEC_ERROR("operator in on non-array", NULL);
674 if (leftArray.tag == ARRAY_TAG) {
675 @@ -4040,7 +4044,7 @@ static int inArray(void)
684 @@ -4083,15 +4087,15 @@ static int deleteArrayElement(void)
688 - return(execError("attempt to delete from non-array", NULL));
689 + EXEC_ERROR("attempt to delete from non-array", NULL);
695 static int typeOfIn(void)
698 - return(execError("I'm already in typeof-mode", NULL));
699 + EXEC_ERROR("I'm already in typeof-mode", NULL);
703 @@ -4105,7 +4109,7 @@ static int typeOfOut(void)
707 - return(execError("I'm not in typeof-mode", NULL));
708 + EXEC_ERROR("I'm not in typeof-mode", NULL);
712 @@ -4159,7 +4163,7 @@ static int arrayAssignNext(void)
715 if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) {
716 - return execError("cannot assign array element of non-array", NULL);
717 + EXEC_ERROR("cannot assign array element of non-array", NULL);
720 if (srcValue.tag == ARRAY_TAG) {
721 @@ -4175,7 +4179,7 @@ static int arrayAssignNext(void)
722 keyString = AllocStringOfNumber(arrayMaxNumIdx(&dstArray) + 1);
724 if (!ArrayInsert(&dstArray, keyString, &srcValue)) {
725 - return execError("array member allocation failure", NULL);
726 + EXEC_ERROR("array member allocation failure", NULL);
730 @@ -4199,7 +4203,7 @@ static int arrayNextNumIdx(void)
733 if (srcArray.tag != ARRAY_TAG) {
734 - return execError("operator [@] on non-array", NULL);
735 + EXEC_ERROR("operator [@] on non-array", NULL);
738 PUSH_INT(arrayMaxNumIdx(&srcArray) + 1);
739 @@ -4214,9 +4218,9 @@ static int arrayNextNumIdx(void)
740 static int errCheck(const char *s)
743 - return execError("%s argument out of domain", s);
744 + EXEC_ERROR("%s argument out of domain", s);
745 else if (errno == ERANGE)
746 - return execError("%s result out of range", s);
747 + EXEC_ERROR("%s result out of range", s);