From 26bfebc02528f6bba34c65c68590846df7d8180a Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Mon, 27 Oct 2008 21:51:51 +0100 Subject: [PATCH] break/continue to outer loops, !!booleanize unify-branch-setup.patch: * END_LOOP() for FillLoopAddrs() symbol-lookup.patch: * pushArraySymVal: switch operands to create symbol only in createAndRef mode break-continue-multi.patch: * compile time break/continue to outer loops use break/continue to break or continue the th outer loop, the current loop is 0 and can be omitted * rewrite 'for' code generation to avoid SwapCode call booleanize.patch: * !! unary operator B.W. --- Patch: !unify-branch-setup.patch Patch: !symbol-lookup.patch Patch: +break-continue-multi.patch Patch: +booleanize.patch --- EXEC_ERROR.patch | 120 +++++------ MultipleAssignment-redux.patch | 14 +- MultipleAssignment-selector.patch | 6 +- abstract-access-to-PC.patch | 54 ++--- aryiter-on-stack.patch | 46 ++-- booleanize.patch | 34 +++ break-continue-multi.patch | 300 +++++++++++++++++++++++++++ change-sym-types.patch | 34 +-- fix-return-value-from-overlay-routines.patch | 4 +- global-AccumulatorData.patch | 16 +- global-RestartData.patch | 56 ++--- handle-error-in-RunMacroAsSubrCall.patch | 18 +- key-grammar.patch | 22 +- macro_name.patch | 2 +- nested-subroutines.patch | 10 +- pushString.patch | 40 ++-- readonly-statement.patch | 8 +- remove-args-from-DISASM_RT.patch | 88 ++++---- series | 2 + symbol-lookup.patch | 112 +++++++--- ternary-operator-GNU.patch | 16 +- ternary-operator.patch | 8 +- typed-Inst.patch | 30 +-- unify-branch-setup.patch | 110 +++++++++- zero-based-Program-refcount.patch | 14 +- 25 files changed, 816 insertions(+), 348 deletions(-) create mode 100644 booleanize.patch create mode 100644 break-continue-multi.patch diff --git a/EXEC_ERROR.patch b/EXEC_ERROR.patch index 1bc8644..194497c 100644 --- a/EXEC_ERROR.patch +++ b/EXEC_ERROR.patch @@ -6,7 +6,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -1374,10 +1374,12 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1377,10 +1377,12 @@ static void addToGlobalSymTab(Symbol *sy GlobalSymTab[idx] = sym; } @@ -20,7 +20,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c instTypeToStr(PC->type)); \ } \ s = PC->val.sym; \ -@@ -1387,7 +1389,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1390,7 +1392,7 @@ static void addToGlobalSymTab(Symbol *sy #define GET_IMMED(i) \ do { \ if (PC->type != IMMED_INST) { \ @@ -29,7 +29,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c instTypeToStr(PC->type)); \ } \ i = PC->val.immed; \ -@@ -1397,7 +1399,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1400,7 +1402,7 @@ static void addToGlobalSymTab(Symbol *sy #define GET_BRANCH(a) \ do { \ if (PC->type != BRANCH_INST) { \ @@ -38,7 +38,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c instTypeToStr(PC->type)); \ } \ a = PC + PC->val.branch; \ -@@ -1427,7 +1429,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1430,7 +1432,7 @@ static void addToGlobalSymTab(Symbol *sy #define POP_CHECK(n) \ do { \ if (!OK_TO_POP(n)) { \ @@ -47,7 +47,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } \ } while (0) -@@ -1438,17 +1440,17 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1441,17 +1443,17 @@ static void addToGlobalSymTab(Symbol *sy #define PUSH_CHECK(n) \ do { \ if (!OK_TO_PUSH(n)) { \ @@ -68,7 +68,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } \ } while (0) -@@ -1477,10 +1479,10 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1480,10 +1482,10 @@ static void addToGlobalSymTab(Symbol *sy __int = dataVal.val.n; \ } else if (dataVal.tag == STRING_TAG) { \ if (!StringToNum(dataVal.val.str.rep, &__int)) {\ @@ -81,7 +81,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c tagToStr(dataVal.tag)); \ } \ number = __int; \ -@@ -1494,7 +1496,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1497,7 +1499,7 @@ static void addToGlobalSymTab(Symbol *sy } else if (dataVal.tag == INT_TAG) { \ __str = AllocStringOfNumber(dataVal.val.n); \ } else { \ @@ -90,7 +90,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c tagToStr(dataVal.tag)); \ } \ string = __str; \ -@@ -1592,7 +1594,7 @@ static int pushSymVal(void) +@@ -1595,7 +1597,7 @@ static int pushSymVal(void) nArgs = FP_GET_ARG_COUNT(FrameP); argNum = s->value.val.n; if (argNum >= nArgs) { @@ -99,7 +99,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (argNum == N_ARGS_ARG_SYM) { symVal.tag = INT_TAG; -@@ -1605,12 +1607,12 @@ static int pushSymVal(void) +@@ -1608,12 +1610,12 @@ static int pushSymVal(void) char *errMsg; if (!(s->value.val.subr)(FocusWindow, NULL, 0, &symVal, &errMsg)) { @@ -115,7 +115,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH(symVal); -@@ -1650,8 +1652,8 @@ static int pushArgVal(void) +@@ -1653,8 +1655,8 @@ static int pushArgVal(void) --argNum; nArgs = FP_GET_ARG_COUNT(FrameP); if (argNum >= nArgs || argNum < 0) { @@ -126,7 +126,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH(FP_GET_ARG_N(FrameP, argNum)); return STAT_OK; -@@ -1690,7 +1692,7 @@ static int pushArgArray(void) +@@ -1693,7 +1695,7 @@ static int pushArgArray(void) argVal = FP_GET_ARG_N(FrameP, argNum); if (!ArrayInsert(argArray, AllocStringOfNumber(argNum + 1), &argVal)) { @@ -135,7 +135,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } } -@@ -1726,7 +1728,7 @@ static int pushArraySymVal(void) +@@ -1729,7 +1731,7 @@ static int pushArraySymVal(void) dataPtr = &sym->value; } else { @@ -144,7 +144,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (initEmpty && dataPtr->tag == NO_TAG) { -@@ -1735,7 +1737,7 @@ static int pushArraySymVal(void) +@@ -1738,7 +1740,7 @@ static int pushArraySymVal(void) } if (dataPtr->tag == NO_TAG && !inTypeOfMode) { @@ -153,7 +153,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH(*dataPtr); -@@ -1828,7 +1830,7 @@ static int anonArrayNextVal(void) +@@ -1831,7 +1833,7 @@ static int anonArrayNextVal(void) sprintf(numString, "%d", nextIndex); if (!ArrayInsert(&anonArray, AllocStringCpy(numString), &exprVal)) { @@ -162,7 +162,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* we need to increment the index for next time */ -@@ -1880,7 +1882,7 @@ static int anonArrayIndexVal(void) +@@ -1883,7 +1885,7 @@ static int anonArrayIndexVal(void) } if (!ArrayInsert(&anonArray, keyString, &exprVal)) { @@ -171,7 +171,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* push the default next index value first, then the array */ -@@ -1971,7 +1973,7 @@ static int namedArg1orN(Boolean isFirst) +@@ -1974,7 +1976,7 @@ static int namedArg1orN(Boolean isFirst) /* if our index is numeric (or can be converted to a number) we must change the next index value */ if (nDim == 1 && StringToNum(keyString, &index)) { @@ -180,7 +180,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (isFirst) { -@@ -1985,7 +1987,7 @@ static int namedArg1orN(Boolean isFirst) +@@ -1988,7 +1990,7 @@ static int namedArg1orN(Boolean isFirst) } if (!ArrayInsert(&argsArray, keyString, &exprVal)) { @@ -189,7 +189,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* and (re)push the array */ -@@ -2033,13 +2035,13 @@ static int assign(void) +@@ -2036,13 +2038,13 @@ static int assign(void) if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) { if (sym->type == ARG_SYM) { @@ -206,7 +206,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } -@@ -2155,13 +2157,13 @@ static int add(void) +@@ -2158,13 +2160,13 @@ static int add(void) rightIter = arrayIterateNext(rightIter); } if (!insertResult) { @@ -222,7 +222,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } else { -@@ -2169,7 +2171,7 @@ static int add(void) +@@ -2172,7 +2174,7 @@ static int add(void) POP_INT(n1); PUSH_INT(n1 + n2); } @@ -231,7 +231,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2221,13 +2223,13 @@ static int subtract(void) +@@ -2224,13 +2226,13 @@ static int subtract(void) leftIter = arrayIterateNext(leftIter); } if (!insertResult) { @@ -247,7 +247,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } else { -@@ -2235,7 +2237,7 @@ static int subtract(void) +@@ -2238,7 +2240,7 @@ static int subtract(void) POP_INT(n1); PUSH_INT(n1 - n2); } @@ -256,7 +256,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2262,7 +2264,7 @@ static int divide(void) +@@ -2265,7 +2267,7 @@ static int divide(void) POP_INT(n2); POP_INT(n1); if (n2 == 0) { @@ -265,7 +265,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH_INT(n1 / n2); return STAT_OK; -@@ -2278,7 +2280,7 @@ static int modulo(void) +@@ -2281,7 +2283,7 @@ static int modulo(void) POP_INT(n2); POP_INT(n1); if (n2 == 0) { @@ -274,7 +274,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH_INT(n1 % n2); return STAT_OK; -@@ -2359,11 +2361,11 @@ static int eq(void) +@@ -2362,11 +2364,11 @@ static int eq(void) } } else { @@ -288,7 +288,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* negated eq() call */ -@@ -2416,13 +2418,13 @@ static int bitAnd(void) +@@ -2419,13 +2421,13 @@ static int bitAnd(void) rightIter = arrayIterateNext(rightIter); } if (!insertResult) { @@ -304,7 +304,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } else { -@@ -2430,7 +2432,7 @@ static int bitAnd(void) +@@ -2433,7 +2435,7 @@ static int bitAnd(void) POP_INT(n1); PUSH_INT(n1 & n2); } @@ -313,7 +313,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2487,13 +2489,13 @@ static int bitOr(void) +@@ -2490,13 +2492,13 @@ static int bitOr(void) rightIter = arrayIterateNext(rightIter); } if (!insertResult) { @@ -329,7 +329,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } else { -@@ -2501,7 +2503,7 @@ static int bitOr(void) +@@ -2504,7 +2506,7 @@ static int bitOr(void) POP_INT(n1); PUSH_INT(n1 | n2); } @@ -338,7 +338,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } static int and(void) -@@ -2601,7 +2603,7 @@ static int concatenateNwithSep(int nVals +@@ -2604,7 +2606,7 @@ static int concatenateNwithSep(int nVals len += value.val.str.len; } else { @@ -347,7 +347,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c tagToStr(value.tag)); } } -@@ -2723,7 +2725,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2726,7 +2728,7 @@ static int callSubroutineFromSymbol(Symb PreemptRequest = False; if (!sym->value.val.subr(FocusWindow, StackP, nArgs, &result, &errMsg)) @@ -356,7 +356,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH_RET_VAL(result); return PreemptRequest ? STAT_PREEMPT : STAT_OK; } -@@ -2758,8 +2760,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2761,8 +2763,7 @@ static int callSubroutineFromSymbol(Symb Window win; if (haveNamedArgs) { @@ -366,7 +366,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c sym->name); } -@@ -2795,7 +2796,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2798,7 +2799,7 @@ static int callSubroutineFromSymbol(Symb } /* Calling a non subroutine symbol */ @@ -375,7 +375,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2865,7 +2866,7 @@ static int callSubroutineUnpackArray(voi +@@ -2868,7 +2869,7 @@ static int callSubroutineUnpackArray(voi POP(argArray); if (argArray.tag != ARRAY_TAG) { @@ -384,7 +384,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (haveNamedArgs) { -@@ -2899,7 +2900,7 @@ static int callSubroutineUnpackArray(voi +@@ -2902,7 +2903,7 @@ static int callSubroutineUnpackArray(voi } else { if (!ArrayInsert(&dvArray, iter->key, &dvEntry)) { @@ -393,7 +393,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } -@@ -2974,7 +2975,7 @@ int OverlayRoutineFromProg(Program *prog +@@ -2977,7 +2978,7 @@ int OverlayRoutineFromProg(Program *prog */ static int fetchRetVal(void) { @@ -402,7 +402,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* see comments for returnValOrNone() */ -@@ -3117,17 +3118,17 @@ int ArrayCopy(DataValue *dstArray, DataV +@@ -3120,17 +3121,17 @@ int ArrayCopy(DataValue *dstArray, DataV return(errNum); } if (!ArrayInsert(dstArray, srcIter->key, &tmpArray)) { @@ -423,7 +423,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3147,7 +3148,7 @@ static int makeArrayKeyFromArgs(int nArg +@@ -3150,7 +3151,7 @@ static int makeArrayKeyFromArgs(int nArg if (len > 0) { return len; } @@ -432,7 +432,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3464,23 +3465,24 @@ static int arrayRef(void) +@@ -3467,23 +3468,24 @@ static int arrayRef(void) POP(srcArray); if (srcArray.tag == ARRAY_TAG) { if (!ArrayGet(&srcArray, keyString, &valueItem)) { @@ -462,7 +462,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } } -@@ -3517,7 +3519,7 @@ static int arrayAssign(void) +@@ -3520,7 +3522,7 @@ static int arrayAssign(void) POP(dstArray); if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) { @@ -471,7 +471,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (srcValue.tag == ARRAY_TAG) { DataValue arrayCopyValue; -@@ -3529,13 +3531,13 @@ static int arrayAssign(void) +@@ -3532,13 +3534,13 @@ static int arrayAssign(void) } } if (ArrayInsert(&dstArray, keyString, &srcValue)) { @@ -488,7 +488,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3573,20 +3575,21 @@ static int arrayRefAndAssignSetup(void) +@@ -3576,20 +3578,21 @@ static int arrayRefAndAssignSetup(void) PEEK(srcArray, nDim); if (srcArray.tag == ARRAY_TAG) { if (!ArrayGet(&srcArray, keyString, &valueItem)) { @@ -514,7 +514,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } -@@ -3619,16 +3622,16 @@ static int beginArrayIter(void) +@@ -3622,16 +3625,16 @@ static int beginArrayIter(void) iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator); } else { @@ -534,7 +534,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3685,7 +3688,7 @@ static int arrayIter(void) +@@ -3688,7 +3691,7 @@ static int arrayIter(void) keyValPtr = &(keySym->value); } else { @@ -543,7 +543,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } keyValPtr->tag = NO_TAG; -@@ -3697,7 +3700,7 @@ static int arrayIter(void) +@@ -3700,7 +3703,7 @@ static int arrayIter(void) valPtr = &(valSym->value); } else { @@ -552,7 +552,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } valPtr->tag = NO_TAG; } -@@ -3706,7 +3709,7 @@ static int arrayIter(void) +@@ -3709,7 +3712,7 @@ static int arrayIter(void) iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator); } else { @@ -561,7 +561,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } thisEntry = iteratorValPtr->val.arrayPtr; -@@ -3727,7 +3730,7 @@ static int arrayIter(void) +@@ -3730,7 +3733,7 @@ static int arrayIter(void) else { JUMP(branchAddr); } @@ -570,7 +570,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3755,21 +3758,21 @@ static int beginArrayIterArray(void) +@@ -3758,21 +3761,21 @@ static int beginArrayIterArray(void) iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator); } else { @@ -596,7 +596,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } static int countDim(const char *key) -@@ -3865,7 +3868,7 @@ static int arrayIterArray(void) +@@ -3868,7 +3871,7 @@ static int arrayIterArray(void) keyArrayPtr = &(keyArraySym->value); } else { @@ -605,7 +605,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } keyArrayPtr->tag = ARRAY_TAG; keyArrayPtr->val.arrayPtr = NULL; -@@ -3878,7 +3881,7 @@ static int arrayIterArray(void) +@@ -3881,7 +3884,7 @@ static int arrayIterArray(void) valPtr = &valSym->value; } else { @@ -614,7 +614,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } valPtr->tag = NO_TAG; } -@@ -3887,7 +3890,7 @@ static int arrayIterArray(void) +@@ -3890,7 +3893,7 @@ static int arrayIterArray(void) iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator); } else { @@ -623,7 +623,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } thisEntry = iteratorValPtr->val.arrayPtr; -@@ -3908,7 +3911,7 @@ static int arrayIterArray(void) +@@ -3911,7 +3914,7 @@ static int arrayIterArray(void) /* set keys */ if (!splitKeyIntoArray(thisEntry->key, keyArrayPtr)) { @@ -632,7 +632,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (withVal) { -@@ -3952,7 +3955,7 @@ static int inArray(void) +@@ -3955,7 +3958,7 @@ static int inArray(void) POP(theArray); if (theArray.tag != ARRAY_TAG) { @@ -641,7 +641,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PEEK(leftArray, 0); if (leftArray.tag == ARRAY_TAG) { -@@ -3973,7 +3976,7 @@ static int inArray(void) +@@ -3976,7 +3979,7 @@ static int inArray(void) } } PUSH_INT(inResult); @@ -650,7 +650,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -4016,15 +4019,15 @@ static int deleteArrayElement(void) +@@ -4019,15 +4022,15 @@ static int deleteArrayElement(void) } } else { @@ -669,7 +669,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } inTypeOfMode = 1; -@@ -4038,7 +4041,7 @@ static int typeOfOut(void) +@@ -4041,7 +4044,7 @@ static int typeOfOut(void) DataValue retVal; if (!inTypeOfMode) { @@ -678,7 +678,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } inTypeOfMode = 0; -@@ -4089,7 +4092,7 @@ static int arrayAssignNext(void) +@@ -4092,7 +4095,7 @@ static int arrayAssignNext(void) POP(dstArray); if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) { @@ -687,7 +687,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (srcValue.tag == ARRAY_TAG) { -@@ -4105,7 +4108,7 @@ static int arrayAssignNext(void) +@@ -4108,7 +4111,7 @@ static int arrayAssignNext(void) keyString = AllocStringOfNumber(arrayMaxNumIdx(&dstArray) + 1); if (!ArrayInsert(&dstArray, keyString, &srcValue)) { @@ -696,7 +696,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } return STAT_OK; -@@ -4129,7 +4132,7 @@ static int arrayNextNumIdx(void) +@@ -4132,7 +4135,7 @@ static int arrayNextNumIdx(void) POP(srcArray); if (srcArray.tag != ARRAY_TAG) { @@ -705,7 +705,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH_INT(arrayMaxNumIdx(&srcArray) + 1); -@@ -4144,9 +4147,9 @@ static int arrayNextNumIdx(void) +@@ -4147,9 +4150,9 @@ static int arrayNextNumIdx(void) static int errCheck(const char *s) { if (errno == EDOM) diff --git a/MultipleAssignment-redux.patch b/MultipleAssignment-redux.patch index bee781d..b5799a5 100644 --- a/MultipleAssignment-redux.patch +++ b/MultipleAssignment-redux.patch @@ -9,7 +9,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -820,23 +820,6 @@ void SetMacroFocusWindow(WindowInfo *win +@@ -823,23 +823,6 @@ void SetMacroFocusWindow(WindowInfo *win } /* @@ -33,7 +33,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Lookup a constant string by its value. This allows reuse of string ** constants and fixing a leak in the interpreter. */ -@@ -2061,6 +2044,30 @@ static int dupStack(void) +@@ -2064,6 +2047,30 @@ static int dupStack(void) } /* @@ -64,7 +64,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** if left and right arguments are arrays, then the result is a new array ** in which all the keys from both the right and left are copied ** the values from the right array are used in the result array when the -@@ -4513,6 +4520,12 @@ static void disasmInternal(Inst *inst, i +@@ -4516,6 +4523,12 @@ static void disasmInternal(Inst *inst, i ++i; break; @@ -91,7 +91,7 @@ diff --quilt old/source/ops.h new/source/ops.h diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -102,15 +102,6 @@ static int nextSymIsField = 0; +@@ -108,15 +108,6 @@ static int nextSymIsField = 0; /* set to 1 when we don't want a full symbol, just a name (string) for a field name following a '.' */ @@ -107,7 +107,7 @@ diff --quilt old/source/parse.y new/source/parse.y %} %union { -@@ -118,7 +109,6 @@ typedef struct LVinst { +@@ -124,7 +115,6 @@ typedef struct LVinst { Inst *inst; int num; enum operations oper; @@ -115,7 +115,7 @@ diff --quilt old/source/parse.y new/source/parse.y struct { AccumulatorData *acc; Symbol *sym; -@@ -135,7 +125,8 @@ typedef struct LVinst { +@@ -141,7 +131,8 @@ typedef struct LVinst { %type operassign incrdecr %token '=' ADDEQ SUBEQ MULEQ DIVEQ MODEQ ANDEQ OREQ %token INCR DECR @@ -125,7 +125,7 @@ diff --quilt old/source/parse.y new/source/parse.y %token ARGSEP %nonassoc IF_NO_ELSE -@@ -413,113 +404,61 @@ simpstmt: /* simple variable assignmen +@@ -421,113 +412,61 @@ simpstmt: /* simple variable assignmen /* ** Implementing a multi-assignment to a list of lvalues ** diff --git a/MultipleAssignment-selector.patch b/MultipleAssignment-selector.patch index 4435f1a..19d6992 100644 --- a/MultipleAssignment-selector.patch +++ b/MultipleAssignment-selector.patch @@ -6,7 +6,7 @@ diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -422,7 +422,11 @@ lvlistexpr: '(' mark lvlist mark ')' bla +@@ -430,7 +430,11 @@ lvlistexpr: '(' mark lvlist mark ')' bla ** the lvalue, so that the result is ontop od the stack. ** lventry's value will give us the start of this code. */ @@ -19,7 +19,7 @@ diff --quilt old/source/parse.y new/source/parse.y /* start case */ $$ = 1; /* add code to push the rvalue expression value */ -@@ -431,6 +435,16 @@ lvlist: lventry m +@@ -439,6 +443,16 @@ lvlist: lventry m /* swap this code in front of the lvalue assignment code */ SwapCode($1, $2, GetPC()); } @@ -36,7 +36,7 @@ diff --quilt old/source/parse.y new/source/parse.y | lvlist ',' blank lventry mark { /* the index for this entry into the rvalue array */ $$ = $1 + 1; -@@ -440,6 +454,21 @@ lvlist: lventry m +@@ -448,6 +462,21 @@ lvlist: lventry m /* swap this code in front of the lvalue assignment code */ SwapCode($4, $5, GetPC()); } diff --git a/abstract-access-to-PC.patch b/abstract-access-to-PC.patch index ca6c927..19d2344 100644 --- a/abstract-access-to-PC.patch +++ b/abstract-access-to-PC.patch @@ -6,7 +6,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -1319,6 +1319,40 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1322,6 +1322,40 @@ static void addToGlobalSymTab(Symbol *sy GlobalSymTab[idx] = sym; } @@ -47,7 +47,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* true, if you can pop n values */ #define OK_TO_POP(n) \ ((StackP - (n)) >= TheStack) -@@ -1481,8 +1515,7 @@ static int pushSymVal(void) +@@ -1484,8 +1518,7 @@ static int pushSymVal(void) DISASM_RT(PC-1, 2); STACKDUMP(0, 3); @@ -57,7 +57,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (s->type == LOCAL_SYM) { symVal = FP_GET_SYM_VAL(FrameP, s); -@@ -1532,8 +1565,7 @@ static int pushImmed(void) +@@ -1535,8 +1568,7 @@ static int pushImmed(void) DISASM_RT(PC-1, 2); STACKDUMP(0, 3); @@ -67,7 +67,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH_INT(immed); -@@ -1617,10 +1649,8 @@ static int pushArraySymVal(void) +@@ -1620,10 +1652,8 @@ static int pushArraySymVal(void) DISASM_RT(PC-1, 3); STACKDUMP(0, 3); @@ -80,7 +80,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (sym->type == LOCAL_SYM) { dataPtr = &FP_GET_SYM_VAL(FrameP, sym); -@@ -1759,8 +1789,7 @@ static int anonArrayIndexVal(void) +@@ -1762,8 +1792,7 @@ static int anonArrayIndexVal(void) int nextIndex, index; int nDim; @@ -90,7 +90,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-2, 2); STACKDUMP(nDim+3, 3); -@@ -1857,7 +1886,7 @@ static int namedArg1orN(Boolean isFirst) +@@ -1860,7 +1889,7 @@ static int namedArg1orN(Boolean isFirst) DataValue exprVal, argsArray; int nDim, index; @@ -99,7 +99,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-2, 2); STACKDUMP(nDim + (isFirst ? 2 : 1), 3); -@@ -1931,8 +1960,7 @@ static int assign(void) +@@ -1934,8 +1963,7 @@ static int assign(void) DISASM_RT(PC-1, 2); STACKDUMP(1, 3); @@ -109,7 +109,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) { if (sym->type == ARG_SYM) { -@@ -2555,8 +2583,7 @@ static int concat(void) +@@ -2558,8 +2586,7 @@ static int concat(void) int nExpr; @@ -119,7 +119,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-2, 2); STACKDUMP(nExpr, 3); -@@ -2627,10 +2654,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2630,10 +2657,7 @@ static int callSubroutineFromSymbol(Symb if (!sym->value.val.subr(FocusWindow, StackP, nArgs, &result, &errMsg)) return execError(errMsg, sym->name); @@ -131,7 +131,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return PreemptRequest ? STAT_PREEMPT : STAT_OK; } -@@ -2693,10 +2717,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2696,10 +2720,7 @@ static int callSubroutineFromSymbol(Symb sym->value.val.xtproc(FocusWindow->lastFocus, (XEvent *)&key_event, argList, &numArgs); XtFree((char *)argList); @@ -143,7 +143,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return PreemptRequest ? STAT_PREEMPT : STAT_OK; } -@@ -2718,8 +2739,8 @@ static int callSubroutine(void) +@@ -2721,8 +2742,8 @@ static int callSubroutine(void) Symbol *sym; int nArgs; @@ -154,7 +154,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-3, 3); STACKDUMP(nArgs > 0 ? nArgs : -nArgs, 3); -@@ -2757,8 +2778,8 @@ static int callSubroutineUnpackArray(voi +@@ -2760,8 +2781,8 @@ static int callSubroutineUnpackArray(voi DISASM_RT(PC-1, 1); @@ -165,7 +165,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (nArgs < 0) { haveNamedArgs = 1; -@@ -2911,24 +2932,14 @@ static int returnValOrNone(int valOnStac +@@ -2914,24 +2935,14 @@ static int returnValOrNone(int valOnStac if (valOnStack) { POP(retVal); } @@ -194,7 +194,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* NULL return PC indicates end of program */ return PC == NULL ? STAT_DONE : STAT_OK; -@@ -2942,10 +2953,14 @@ static int returnValOrNone(int valOnStac +@@ -2945,10 +2956,14 @@ static int returnValOrNone(int valOnStac */ static int branch(void) { @@ -210,7 +210,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -2973,12 +2988,12 @@ static int branchIf(Boolean trueOrFalse) +@@ -2976,12 +2991,12 @@ static int branchIf(Boolean trueOrFalse) DISASM_RT(PC-1, 2); STACKDUMP(1, 3); @@ -226,7 +226,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -2992,10 +3007,13 @@ static int branchIf(Boolean trueOrFalse) +@@ -2995,10 +3010,13 @@ static int branchIf(Boolean trueOrFalse) */ static int branchNever(void) { @@ -241,7 +241,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -3354,8 +3372,7 @@ static int arrayRef(void) +@@ -3357,8 +3375,7 @@ static int arrayRef(void) char *keyString = NULL; int nDim; @@ -251,7 +251,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-2, 2); STACKDUMP(nDim+1, 3); -@@ -3405,8 +3422,7 @@ static int arrayAssign(void) +@@ -3408,8 +3425,7 @@ static int arrayAssign(void) int errNum; int nDim; @@ -261,7 +261,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-2, 1); STACKDUMP(nDim+2, 3); -@@ -3458,10 +3474,8 @@ static int arrayRefAndAssignSetup(void) +@@ -3461,10 +3477,8 @@ static int arrayRefAndAssignSetup(void) char *keyString = NULL; int binaryOp, nDim; @@ -274,7 +274,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-3, 3); STACKDUMP(nDim + (binaryOp ? 2 : 1), 3); -@@ -3517,8 +3531,7 @@ static int beginArrayIter(void) +@@ -3520,8 +3534,7 @@ static int beginArrayIter(void) DISASM_RT(PC-1, 2); STACKDUMP(1, 3); @@ -284,7 +284,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c POP(arrayVal); -@@ -3577,18 +3590,13 @@ static int arrayIter(void) +@@ -3580,18 +3593,13 @@ static int arrayIter(void) DISASM_RT(PC-1, 4); STACKDUMP(0, 4); @@ -308,7 +308,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (keySym->type == LOCAL_SYM) { keyValPtr = &FP_GET_SYM_VAL(FrameP, keySym); -@@ -3637,7 +3645,7 @@ static int arrayIter(void) +@@ -3640,7 +3648,7 @@ static int arrayIter(void) iteratorValPtr->val.arrayPtr = arrayIterateNext(thisEntry); } else { @@ -317,7 +317,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } return(STAT_OK); } -@@ -3658,8 +3666,7 @@ static int beginArrayIterArray(void) +@@ -3661,8 +3669,7 @@ static int beginArrayIterArray(void) DISASM_RT(PC-1, 2); STACKDUMP(2, 3); @@ -327,7 +327,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c POP(arrayVal); PEEK_INT(nDims, 0); -@@ -3761,23 +3768,15 @@ static int arrayIterArray(void) +@@ -3764,23 +3771,15 @@ static int arrayIterArray(void) DISASM_RT(PC-1, 4); STACKDUMP(1, 4); @@ -357,7 +357,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (keyArraySym->type == LOCAL_SYM) { keyArrayPtr = &FP_GET_SYM_VAL(FrameP, keyArraySym); -@@ -3844,7 +3843,7 @@ static int arrayIterArray(void) +@@ -3847,7 +3846,7 @@ static int arrayIterArray(void) iteratorValPtr->val.arrayPtr = thisEntry; if (!keyFound && (!thisEntry || thisEntry->nodePtrs.color == -1)) { @@ -366,7 +366,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } return STAT_OK; -@@ -3912,8 +3911,7 @@ static int deleteArrayElement(void) +@@ -3915,8 +3914,7 @@ static int deleteArrayElement(void) char *keyString = NULL; int nDim; @@ -376,7 +376,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-2, 2); STACKDUMP(nDim + 1, 3); -@@ -3983,10 +3981,7 @@ static int typeOfOut(void) +@@ -3986,10 +3984,7 @@ static int typeOfOut(void) } retVal.val.str.len = strlen(retVal.val.str.rep); diff --git a/aryiter-on-stack.patch b/aryiter-on-stack.patch index e589a4f..0070eee 100644 --- a/aryiter-on-stack.patch +++ b/aryiter-on-stack.patch @@ -9,7 +9,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -837,24 +837,6 @@ Symbol *InstallMultiAssignExpr(void) +@@ -840,24 +840,6 @@ Symbol *InstallMultiAssignExpr(void) } /* @@ -34,7 +34,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Lookup a constant string by its value. This allows reuse of string ** constants and fixing a leak in the interpreter. */ -@@ -3565,10 +3547,10 @@ static int arrayRefAndAssignSetup(void) +@@ -3568,10 +3550,10 @@ static int arrayRefAndAssignSetup(void) /* ** setup symbol values for array iteration in interpreter ** @@ -48,7 +48,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Where: ** iter is a symbol which gives the position of the iterator value in ** the stack frame -@@ -3576,30 +3558,24 @@ static int arrayRefAndAssignSetup(void) +@@ -3579,30 +3561,24 @@ static int arrayRefAndAssignSetup(void) */ static int beginArrayIter(void) { @@ -86,7 +86,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -3609,10 +3585,10 @@ static int beginArrayIter(void) +@@ -3612,10 +3588,10 @@ static int beginArrayIter(void) ** this allows iterators to progress even if you delete any node in the array ** except the item just after the current key ** @@ -101,7 +101,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Where: ** iter is a symbol which gives the position of the iterator value in ** the stack frame (set up by OP_BEGIN_ARRAY_ITER); that value refers -@@ -3629,10 +3605,9 @@ static int beginArrayIter(void) +@@ -3632,10 +3608,9 @@ static int beginArrayIter(void) */ static int arrayIter(void) { @@ -113,7 +113,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DataValue *keyValPtr; DataValue *valPtr; SparseArrayEntry *thisEntry; -@@ -3640,16 +3615,17 @@ static int arrayIter(void) +@@ -3643,16 +3618,17 @@ static int arrayIter(void) int withVal; DISASM_RT(); @@ -133,7 +133,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (keySym->type == LOCAL_SYM) { keyValPtr = &FP_GET_SYM_VAL(FrameP, keySym); } -@@ -3674,14 +3650,7 @@ static int arrayIter(void) +@@ -3677,14 +3653,7 @@ static int arrayIter(void) valPtr->tag = NO_TAG; } @@ -149,7 +149,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (thisEntry && thisEntry->nodePtrs.color != -1) { /* set key */ keyValPtr->tag = STRING_TAG; -@@ -3694,52 +3663,48 @@ static int arrayIter(void) +@@ -3697,52 +3666,48 @@ static int arrayIter(void) } /* advance iterator */ @@ -215,7 +215,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -3798,17 +3763,16 @@ static Boolean splitKeyIntoArray(const c +@@ -3801,17 +3766,16 @@ static Boolean splitKeyIntoArray(const c /* ** @@ -238,7 +238,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DataValue *keyArrayPtr; DataValue *valPtr; SparseArrayEntry *thisEntry; -@@ -3818,16 +3782,16 @@ static int arrayIterArray(void) +@@ -3821,16 +3785,16 @@ static int arrayIterArray(void) Boolean keyFound = False; DISASM_RT(); @@ -257,7 +257,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PEEK_INT(nDims, 0); if (keyArraySym->type == LOCAL_SYM) { -@@ -3855,14 +3819,7 @@ static int arrayIterArray(void) +@@ -3858,14 +3822,7 @@ static int arrayIterArray(void) valPtr->tag = NO_TAG; } @@ -273,7 +273,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c while (thisEntry && thisEntry->nodePtrs.color != -1) { /* check if this is an nDims key, but only if requested */ -@@ -3892,12 +3849,14 @@ static int arrayIterArray(void) +@@ -3895,12 +3852,14 @@ static int arrayIterArray(void) thisEntry = arrayIterateNext(thisEntry); break; } @@ -289,7 +289,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -4599,39 +4558,26 @@ static void disasmInternal(Inst *inst, i +@@ -4602,39 +4561,26 @@ static void disasmInternal(Inst *inst, i } break; @@ -338,7 +338,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } break; -@@ -4639,27 +4585,22 @@ static void disasmInternal(Inst *inst, i +@@ -4642,27 +4588,22 @@ static void disasmInternal(Inst *inst, i CHECK_OPERANDS(1, IMMED_INST); if (!inst[i+1].val.immed) { /* without val */ @@ -378,7 +378,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -256,71 +256,63 @@ stmt: ';' blank +@@ -264,71 +264,63 @@ stmt: ';' blank ADD_OP(OP_BRANCH); ADD_BR_OFF($3); SET_BR_OFF($5, GetPC()); } | for '(' blank SYMBOL IN blank arrayexpr blank ')' { @@ -395,10 +395,10 @@ diff --quilt old/source/parse.y new/source/parse.y ADD_OP(OP_BRANCH); - ADD_BR_OFF($7+2); - SET_BR_OFF($7+6, GetPC()); -- FillLoopAddrs(GetPC(), $7+2); +- END_LOOP(GetPC(), $7+2); + ADD_BR_OFF($7+1); + SET_BR_OFF($7+4, GetPC()); -+ FillLoopAddrs(GetPC(), $7+1); ++ END_LOOP(GetPC(), $7+1); + ADD_OP(OP_POP); /* remove iter from stack */ } | for '(' blank SYMBOL KEYVAL SYMBOL IN blank arrayexpr blank ')' { @@ -416,10 +416,10 @@ diff --quilt old/source/parse.y new/source/parse.y ADD_OP(OP_BRANCH); - ADD_BR_OFF($9+2); - SET_BR_OFF($9+7, GetPC()); -- FillLoopAddrs(GetPC(), $9+2); +- END_LOOP(GetPC(), $9+2); + ADD_BR_OFF($9+1); + SET_BR_OFF($9+5, GetPC()); -+ FillLoopAddrs(GetPC(), $9+1); ++ END_LOOP(GetPC(), $9+1); + ADD_OP(OP_POP); /* remove iter from stack */ } | for '(' blank SYMBOL '[' numexpropt ']' IN blank arrayexpr blank ')' { @@ -436,10 +436,10 @@ diff --quilt old/source/parse.y new/source/parse.y ADD_OP(OP_BRANCH); - ADD_BR_OFF($10+2); - SET_BR_OFF($10+6, GetPC()); -- FillLoopAddrs(GetPC(), $10+2); +- END_LOOP(GetPC(), $10+2); + ADD_BR_OFF($10+1); + SET_BR_OFF($10+4, GetPC()); -+ FillLoopAddrs(GetPC(), $10+1); ++ END_LOOP(GetPC(), $10+1); + ADD_OP(OP_POP); /* remove iter from stack */ ADD_OP(OP_POP); /* remove nDim from stack */ } @@ -458,10 +458,10 @@ diff --quilt old/source/parse.y new/source/parse.y ADD_OP(OP_BRANCH); - ADD_BR_OFF($12+2); - SET_BR_OFF($12+7, GetPC()); -- FillLoopAddrs(GetPC(), $12+2); +- END_LOOP(GetPC(), $12+2); + ADD_BR_OFF($12+1); + SET_BR_OFF($12+5, GetPC()); -+ FillLoopAddrs(GetPC(), $12+1); ++ END_LOOP(GetPC(), $12+1); + ADD_OP(OP_POP); /* remove iter from stack */ ADD_OP(OP_POP); /* remove nDim from stack */ } diff --git a/booleanize.patch b/booleanize.patch new file mode 100644 index 0000000..d52845f --- /dev/null +++ b/booleanize.patch @@ -0,0 +1,34 @@ +--- + + source/parse.y | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --quilt old/source/parse.y new/source/parse.y +--- old/source/parse.y ++++ new/source/parse.y +@@ -156,7 +156,7 @@ static int nextSymIsField = 0; + %left GT GE LT LE EQ NE IN + %left '+' '-' + %left '*' '/' '%' +-%nonassoc UNARY_MINUS NOT ++%nonassoc UNARY_MINUS NOT NOTNOT + %nonassoc DELETE + %nonassoc INCR DECR + %right POW +@@ -683,6 +683,7 @@ numexpr: '(' blank expr blank ')' + } + | '-' blank numexpr %prec UNARY_MINUS { ADD_OP(OP_NEGATE); } + | NOT blank numexpr { ADD_OP(OP_NOT); } ++ | NOTNOT blank numexpr { ADD_OP(OP_BOOLEANIZE); } + | numexpr '+' blank numexpr { ADD_OP(OP_ADD); } + | numexpr '-' blank numexpr { ADD_OP(OP_SUB); } + | numexpr '*' blank numexpr { ADD_OP(OP_MUL); } +@@ -979,7 +980,7 @@ static int yylex(void) + case '>': return follow('=', GE, GT); + case '<': return follow('=', LE, LT); + case '=': return eq_look_ahead(); +- case '!': return follow('=', NE, NOT); ++ case '!': return follow2('=', NE, '!', NOTNOT, NOT); + case '+': return follow2('+', INCR, '=', ADDEQ, '+'); + case '-': return follow2('-', DECR, '=', SUBEQ, '-'); + case '|': return follow2('|', OR, '=', OREQ, '|'); diff --git a/break-continue-multi.patch b/break-continue-multi.patch new file mode 100644 index 0000000..1a1dc69 --- /dev/null +++ b/break-continue-multi.patch @@ -0,0 +1,300 @@ +--- + + source/interpret.c | 88 +++++++++++++++++++++++++++++++++++++++-------------- + source/interpret.h | 5 +-- + source/parse.y | 60 +++++++++++++++++++++++++----------- + 3 files changed, 112 insertions(+), 41 deletions(-) + +diff --quilt old/source/interpret.c new/source/interpret.c +--- old/source/interpret.c ++++ new/source/interpret.c +@@ -72,11 +72,6 @@ static const char CVSID[] = "$Id: interp + allowed to execute before preempting and + returning to allow other things to run */ + +-/* Temporary markers placed in a branch address location to designate +- which loop address (break or continue) the location needs */ +-#define NEEDS_BREAK 1 +-#define NEEDS_CONTINUE 2 +- + #define N_ARGS_ARG_VAR -1 /* special arg number meaning $n_args value */ + #define MACRO_NAME_ARG_VAR -2 /* special arg number meaning $macro_name value */ + +@@ -172,6 +167,7 @@ static AccumulatorData *Accumulator; + #define ProgP (Accumulator->progP) + #define LoopStack (Accumulator->loopStack) + #define LoopStackPtr (Accumulator->loopStackPtr) ++#define LoopStackCnt (Accumulator->loopStackCnt) + #define ProgramName (Accumulator->name) + + /* Global data for the interpreter */ +@@ -281,6 +277,7 @@ AccumulatorData *BeginCreatingProgram(co + + ProgP = Prog; + LoopStackPtr = LoopStack; ++ LoopStackCnt = 0; + ProgramName = name; + + return old; +@@ -463,10 +460,11 @@ Inst *SwapCode(Inst *start, Inst *bounda + */ + int StartLoopAddrList(char **msg) + { ++ LoopStackCnt++; + return addLoopAddr(NULL, msg); + } + +-int AddBreakAddr(Inst *addr, char **msg) ++int AddBreakAddr(Inst *addr, int count, char **msg) + { + if (LoopStackPtr == LoopStack) { + *msg = "break outside loop"; +@@ -479,11 +477,15 @@ int AddBreakAddr(Inst *addr, char **msg) + if (!addLoopAddr(addr, msg)) { + return 0; + } +- addr->val.immed = NEEDS_BREAK; ++ if (count < 0 || count >= LoopStackCnt) { ++ *msg = "break count out of limits"; ++ return 0; ++ } ++ addr->val.immed = count; + return 1; + } + +-int AddContinueAddr(Inst *addr, char **msg) ++int AddContinueAddr(Inst *addr, int count, char **msg) + { + if (LoopStackPtr == LoopStack) { + *msg = "continue outside loop"; +@@ -496,7 +498,11 @@ int AddContinueAddr(Inst *addr, char **m + if (!addLoopAddr(addr, msg)) { + return 0; + } +- addr->val.immed = NEEDS_CONTINUE; ++ if (count < 0 || count >= LoopStackCnt) { ++ *msg = "break count out of limits"; ++ return 0; ++ } ++ addr->val.immed = -count - 1; + return 1; + } + +@@ -512,23 +518,61 @@ static int addLoopAddr(Inst *addr, char + + int FillLoopAddrs(Inst *breakAddr, Inst *continueAddr, char **msg) + { +- while (True) { +- LoopStackPtr--; +- if (LoopStackPtr < LoopStack) { +- *msg = "internal error (lsu)"; ++ Inst **start, **addr; ++ ++ if (LoopStackCnt == 0) { ++ *msg = "outside any loop"; ++ return 0; ++ } ++ --LoopStackCnt; ++ ++ /* find start of this loop */ ++ start = LoopStackPtr; ++ do { ++ start--; ++ if (*start == NULL) { ++ break; ++ } ++ if (start == LoopStack) { ++ *msg = "no loop stack start marker"; + return 0; +- } +- if (*LoopStackPtr == NULL) +- break; +- if ((*LoopStackPtr)->val.immed == NEEDS_BREAK) +- (*LoopStackPtr)->val.branch = breakAddr - *LoopStackPtr; +- else if ((*LoopStackPtr)->val.immed == NEEDS_CONTINUE) +- (*LoopStackPtr)->val.branch = continueAddr - *LoopStackPtr; ++ } ++ } while (start > LoopStack); ++ ++ addr = start + 1; ++ ++ while (addr < LoopStackPtr) { ++ int count = (*addr)->val.immed; ++ int iscont = 0; ++ if (count < 0) { ++ iscont = 1; ++ count = -(count + 1); ++ } ++ ++ if (count == 0) { ++ if (iscont) { ++ (*addr)->val.branch = continueAddr - *addr; ++ } ++ else { ++ (*addr)->val.branch = breakAddr - *addr; ++ } ++ } + else { +- *msg = "internal error (uat)"; +- return 0; ++ count--; ++ if (iscont) { ++ (*addr)->val.immed = -count - 1; ++ } ++ else { ++ (*addr)->val.immed = count; ++ } ++ *start = *addr; ++ start++; + } ++ ++ addr++; + } ++ ++ LoopStackPtr = start; + return 1; + } + +diff --quilt old/source/interpret.h new/source/interpret.h +--- old/source/interpret.h ++++ new/source/interpret.h +@@ -144,6 +144,7 @@ typedef struct AccumulatorDataTag { + Inst *progP; + Inst *loopStack[LOOP_STACK_SIZE]; + Inst **loopStackPtr; ++ int loopStackCnt; + const char *name; + } AccumulatorData; + +@@ -176,8 +177,8 @@ Symbol *InstallSymbol(const char *name, + const char *LookupString(const char *str, int create); + Inst *SwapCode(Inst *start, Inst *boundary, Inst *end); + int StartLoopAddrList(char **msg); +-int AddBreakAddr(Inst *addr, char **msg); +-int AddContinueAddr(Inst *addr, char **msg); ++int AddBreakAddr(Inst *addr, int loops, char **msg); ++int AddContinueAddr(Inst *addr, int loops, char **msg); + int FillLoopAddrs(Inst *breakAddr, Inst *continueAddr, char **msg); + + /* create a permanently allocated static string */ +diff --quilt old/source/parse.y new/source/parse.y +--- old/source/parse.y ++++ new/source/parse.y +@@ -77,15 +77,15 @@ + return 1; \ + } \ + } while (0) +-#define ADD_BREAK(addr) \ ++#define ADD_BREAK(addr, count) \ + do { \ +- if (!AddBreakAddr(addr, &ErrMsg)) { \ ++ if (!AddBreakAddr(addr, count, &ErrMsg)) { \ + return 1; \ + } \ + } while (0) +-#define ADD_CONTINUE(addr) \ ++#define ADD_CONTINUE(addr, count) \ + do { \ +- if (!AddContinueAddr(addr, &ErrMsg)) { \ ++ if (!AddContinueAddr(addr, count, &ErrMsg)) { \ + return 1; \ + } \ + } while (0) +@@ -129,7 +129,7 @@ static int nextSymIsField = 0; + %token DELETE ARG_LOOKUP + %token IF WHILE DO ELSE FOR BREAK CONTINUE RETURN DEFINE TYPEOF KEYVAL READONLY + %type keyargs key keyopt catlist fnarglsopt fnarglist fnarg +-%type cond comastmts comastmtlst for while do else and or arrayexpr mark ++%type cond branch for while do else and or arrayexpr mark + %type evalsym + %type definesym + %type operassign incrdecr +@@ -139,6 +139,7 @@ static int nextSymIsField = 0; + %type lventry + %token ARGSEP + %type thenx elsex thenelsex ++%type numberopt + + %nonassoc IF_NO_ELSE + %nonassoc ELSE +@@ -255,10 +256,20 @@ stmt: ';' blank + SET_BR_OFF($7, GetPC()); + END_LOOP(GetPC(), $6); + } +- | for '(' comastmts ';' cond ';' comastmts ')' blank block { +- END_LOOP(GetPC()+2+($7-($5+1)), GetPC()); +- SwapCode($5+1, $7, GetPC()); +- ADD_OP(OP_BRANCH); ADD_BR_OFF($3); SET_BR_OFF($5, GetPC()); ++ | for '(' comastmts ';' ++ mark cond branch ';' ++ mark comastmts branch ')' blank ++ mark block { ++ /* after body jump to 2nd comastmts */ ++ ADD_OP(OP_BRANCH); ADD_BR_OFF($9); ++ /* break is after body, cont is 2nd comastmts */ ++ END_LOOP(GetPC(), $9); ++ /* cond == false => jump after body */ ++ SET_BR_OFF($6, GetPC()); ++ /* cond == true => jump to body */ ++ SET_BR_OFF($7, $14); ++ /* after 2nd comastmts jump to cond */ ++ SET_BR_OFF($11, $5); + } + | for '(' blank SYMBOL IN blank arrayexpr blank ')' { + ADD_OP(OP_BEGIN_ARRAY_ITER); +@@ -320,13 +331,13 @@ stmt: ';' blank + ADD_OP(OP_POP); /* remove iter from stack */ + ADD_OP(OP_POP); /* remove nDim from stack */ + } +- | BREAK stmtend blank { ++ | BREAK numberopt stmtend blank { + ADD_OP(OP_BRANCH); ADD_BR_OFF(0); +- ADD_BREAK(GetPC() - 1); ++ ADD_BREAK(GetPC() - 1, $2); + } +- | CONTINUE stmtend blank { ++ | CONTINUE numberopt stmtend blank { + ADD_OP(OP_BRANCH); ADD_BR_OFF(0); +- ADD_CONTINUE(GetPC() - 1); ++ ADD_CONTINUE(GetPC() - 1, $2); + } + | RETURN expr stmtend blank { + ADD_OP(OP_RETURN); +@@ -485,11 +496,11 @@ evalsym: SYMBOL { + } + ; + +-comastmts: blank { $$ = GetPC(); } +- | blank comastmtlst { $$ = $2; } ++comastmts: blank ++ | blank comastmtlst + ; +-comastmtlst: simpstmt blank { $$ = GetPC(); } +- | comastmtlst ',' blank simpstmt blank { $$ = GetPC(); } ++comastmtlst: simpstmt blank ++ | comastmtlst ',' blank simpstmt blank + ; + + /* array key argument lists */ +@@ -785,6 +796,21 @@ dot: '.' %prec '.' { + } + ; + ++numberopt: /* nothing */ { ++ $$ = 0; ++ } ++ | ++ NUMBER { ++ $$ = $1 ++ } ++ ; ++ ++branch: /* nothing */ { ++ ADD_OP(OP_BRANCH); ++ $$ = GetPC(); ++ ADD_BR_OFF(0); ++ } ++ + blank: /* nothing */ + | blank '\n' + ; diff --git a/change-sym-types.patch b/change-sym-types.patch index 217e6a6..d29bb22 100644 --- a/change-sym-types.patch +++ b/change-sym-types.patch @@ -54,7 +54,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -831,8 +835,8 @@ static Symbol *lookupSymbol(Symbol *syml +@@ -834,8 +838,8 @@ static Symbol *lookupSymbol(Symbol *syml /* ** find a symbol in the symbol table ** @@ -65,7 +65,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c */ Symbol *LookupSymbol(const char *name, int create) { -@@ -856,8 +860,8 @@ Symbol *LookupSymbol(const char *name, i +@@ -859,8 +863,8 @@ Symbol *LookupSymbol(const char *name, i if (create) { DataValue noValue = {NO_TAG, {0}}; @@ -76,7 +76,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } return s; -@@ -866,16 +870,17 @@ Symbol *LookupSymbol(const char *name, i +@@ -869,16 +873,17 @@ Symbol *LookupSymbol(const char *name, i /* ** install symbol name in symbol table */ @@ -97,7 +97,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (Interpreter) { s->next = LocalSymList; LocalSymList = s; -@@ -1444,36 +1449,49 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1447,36 +1452,49 @@ static void addToGlobalSymTab(Symbol *sy static int pushSymVal(void) { Symbol *s; @@ -167,16 +167,16 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (symVal.tag == NO_TAG && !inTypeOfMode) { EXEC_ERROR("variable not set: %s", s->name); } -@@ -1605,7 +1623,7 @@ static int pushArraySymVal(void) - GET_SYM(sym, True); +@@ -1608,7 +1626,7 @@ static int pushArraySymVal(void) GET_IMMED(initEmpty); + GET_SYM(sym, initEmpty); - if (sym->type != LOCAL_SYM && sym->type != GLOBAL_SYM) { + if (sym->attr & READONLY_ATTR) { EXEC_ERROR("assigning to non-lvalue array or non-array: %s", sym->name); } dataPtr = &sym->value; -@@ -1912,16 +1930,8 @@ static int assign(void) +@@ -1915,16 +1933,8 @@ static int assign(void) GET_SYM(sym, True); @@ -195,7 +195,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } dataPtr = &sym->value; -@@ -2639,7 +2649,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2642,7 +2652,7 @@ static int callSubroutineFromSymbol(Symb /* ** If the subroutine is built-in, call the built-in routine */ @@ -204,7 +204,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DataValue result; char *errMsg; -@@ -2664,7 +2674,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2667,7 +2677,7 @@ static int callSubroutineFromSymbol(Symb ** stack for local variables (and initialize them), on top of the argument ** values which are already there. */ @@ -213,7 +213,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c prog = sym->value.val.prog; prog->refcount++; /* -nArgs means 'arguments are on stack' */ -@@ -2674,7 +2684,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2677,7 +2687,7 @@ static int callSubroutineFromSymbol(Symb /* ** Call an action routine */ @@ -222,7 +222,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c String *argList; Cardinal numArgs = nArgs; XKeyEvent key_event; -@@ -2718,7 +2728,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2721,7 +2731,7 @@ static int callSubroutineFromSymbol(Symb } /* Calling a non subroutine symbol */ @@ -231,7 +231,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2881,9 +2891,9 @@ int OverlayRoutineFromProg(Program *prog +@@ -2884,9 +2894,9 @@ int OverlayRoutineFromProg(Program *prog { Symbol sym; @@ -243,7 +243,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c sym.value.val.prog = prog; sym.next = NULL; -@@ -3594,14 +3604,14 @@ static int arrayIter(void) +@@ -3597,14 +3607,14 @@ static int arrayIter(void) POP(iterator); @@ -260,7 +260,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c EXEC_ERROR("can't assign to: %s", valSym->name); } valPtr = &valSym->value; -@@ -3752,7 +3762,7 @@ static int arrayIterArray(void) +@@ -3755,7 +3765,7 @@ static int arrayIterArray(void) POP(iterator); PEEK_INT(nDims, 0); @@ -269,7 +269,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c EXEC_ERROR("can't assign to: %s", keyArraySym->name); } keyArrayPtr = &keyArraySym->value; -@@ -3760,7 +3770,7 @@ static int arrayIterArray(void) +@@ -3763,7 +3773,7 @@ static int arrayIterArray(void) keyArrayPtr->val.arrayPtr = NULL; if (withVal) { @@ -278,7 +278,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c EXEC_ERROR("can't assign to: %s", valSym->name); } valPtr = &valSym->value; -@@ -3938,6 +3948,8 @@ static int typeOfOut(void) +@@ -3941,6 +3951,8 @@ static int typeOfOut(void) case ARRAY_TAG: retVal.val.str.rep = PERM_ALLOC_STR("ARRAY"); break; @@ -438,7 +438,7 @@ diff --quilt old/source/macro.c new/source/macro.c diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -207,16 +207,17 @@ define: definekw blank definesym bla +@@ -213,16 +213,17 @@ define: definekw blank definesym bla prog = FinishCreatingProgram($3); sym = LookupSymbol(prog->name, False); if (sym) { diff --git a/fix-return-value-from-overlay-routines.patch b/fix-return-value-from-overlay-routines.patch index 4b3ad04..babeca8 100644 --- a/fix-return-value-from-overlay-routines.patch +++ b/fix-return-value-from-overlay-routines.patch @@ -6,7 +6,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -2853,6 +2853,7 @@ static int callSubroutineUnpackArray(voi +@@ -2856,6 +2856,7 @@ static int callSubroutineUnpackArray(voi int OverlayRoutineFromSymbol(Symbol *sym, int nArgs, int removeArgs) { @@ -14,7 +14,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DataValue *argArray = StackP + nArgs - removeArgs; assert (nArgs >= 0); -@@ -2878,7 +2879,8 @@ int OverlayRoutineFromSymbol(Symbol *sym +@@ -2881,7 +2882,8 @@ int OverlayRoutineFromSymbol(Symbol *sym assert (argArray->tag == NO_TAG); StackP = argArray; } diff --git a/global-AccumulatorData.patch b/global-AccumulatorData.patch index 8629c03..65a09ee 100644 --- a/global-AccumulatorData.patch +++ b/global-AccumulatorData.patch @@ -29,7 +29,7 @@ diff --quilt old/source/interpret.h new/source/interpret.h diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -95,8 +95,6 @@ static int scanString(void); +@@ -101,8 +101,6 @@ static int scanString(void); static char *ErrMsg; static char *InPtr; @@ -38,7 +38,7 @@ diff --quilt old/source/parse.y new/source/parse.y static int AllowDefine; -@@ -202,7 +200,6 @@ definekw: DEFINE { +@@ -208,7 +206,6 @@ definekw: DEFINE { } ; definesym: SYMBOL { @@ -46,7 +46,7 @@ diff --quilt old/source/parse.y new/source/parse.y /* we can't really be sure, that we not overwrite any ** wrong symbol ** -@@ -219,13 +216,12 @@ definesym: SYMBOL { +@@ -225,13 +222,12 @@ definesym: SYMBOL { yyerror("try to override built-in subroutine"); YYERROR; } $$.sym = PromoteToGlobal($1); @@ -61,7 +61,7 @@ diff --quilt old/source/parse.y new/source/parse.y $3.sym->type = MACRO_FUNCTION_SYM; $3.sym->value.tag = NO_TAG; $3.sym->value.val.prog = prog; -@@ -845,7 +841,7 @@ Program *ParseMacro(char *expr, char **m +@@ -853,7 +849,7 @@ Program *ParseMacro(char *expr, char **m const char *name) { Program *prog; @@ -70,7 +70,7 @@ diff --quilt old/source/parse.y new/source/parse.y #if YYDEBUG int oldyydebug = yydebug; -@@ -855,7 +851,7 @@ Program *ParseMacro(char *expr, char **m +@@ -863,7 +859,7 @@ Program *ParseMacro(char *expr, char **m if (!name) name = "--unknown--"; @@ -79,7 +79,7 @@ diff --quilt old/source/parse.y new/source/parse.y /* whether we allow the "define" keyword */ AllowDefine = allowDefine; -@@ -869,8 +865,7 @@ Program *ParseMacro(char *expr, char **m +@@ -877,8 +873,7 @@ Program *ParseMacro(char *expr, char **m if (yyparse()) { *msg = ErrMsg; *stoppedAt = InPtr; @@ -89,7 +89,7 @@ diff --quilt old/source/parse.y new/source/parse.y #if YYDEBUG yydebug = oldyydebug; -@@ -880,8 +875,7 @@ Program *ParseMacro(char *expr, char **m +@@ -888,8 +883,7 @@ Program *ParseMacro(char *expr, char **m } /* get the newly created program */ @@ -187,7 +187,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return newProg; } -@@ -927,9 +919,11 @@ Symbol *LookupSymbol(const char *name) +@@ -930,9 +922,11 @@ Symbol *LookupSymbol(const char *name) hash = hashName(name); /* search in local symbols */ diff --git a/global-RestartData.patch b/global-RestartData.patch index ef4c2b8..3301157 100644 --- a/global-RestartData.patch +++ b/global-RestartData.patch @@ -64,7 +64,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c static int PreemptRequest; /* passes preemption requests from called routines back up to the interpreter */ -@@ -533,8 +530,8 @@ static int setupFrame(RestartData *conte +@@ -536,8 +533,8 @@ static int setupFrame(RestartData *conte } /* !OK_TO_PUSH(totalPushs) */ @@ -75,7 +75,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* Push arguments and caller information onto the stack */ -@@ -648,8 +645,7 @@ int ExecuteMacro(WindowInfo *window, Pro +@@ -651,8 +648,7 @@ int ExecuteMacro(WindowInfo *window, Pro /* Create an execution context (a stack, a stack pointer, a frame pointer, and a program counter) which will retain the program state across preemption and resumption of execution */ @@ -85,7 +85,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c *continuation = context; context->stackP = context->stack; context->runWindow = window; -@@ -663,7 +659,7 @@ int ExecuteMacro(WindowInfo *window, Pro +@@ -666,7 +662,7 @@ int ExecuteMacro(WindowInfo *window, Pro prog->name ? prog->name : ""); if (status == STAT_ERROR) { @@ -94,7 +94,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c FreeRestartData(context); return MACRO_ERROR; } -@@ -680,25 +676,25 @@ int ContinueMacro(RestartData *continuat +@@ -683,25 +679,25 @@ int ContinueMacro(RestartData *continuat { register int status, instCount = 0; register Inst *inst; @@ -128,7 +128,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c instTypeToStr(inst->type)); } else { -@@ -709,28 +705,26 @@ int ContinueMacro(RestartData *continuat +@@ -712,28 +708,26 @@ int ContinueMacro(RestartData *continuat status = (OpFns[inst->val.op])(); break; default: @@ -162,7 +162,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return MACRO_DONE; } } -@@ -740,8 +734,7 @@ int ContinueMacro(RestartData *continuat +@@ -743,8 +737,7 @@ int ContinueMacro(RestartData *continuat X, other macros, and other shell scripts a chance to execute */ instCount++; if (instCount >= INSTRUCTION_LIMIT) { @@ -172,7 +172,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return MACRO_TIME_LIMIT; } } -@@ -763,7 +756,7 @@ int RunMacroAsSubrCall(RestartData *cont +@@ -766,7 +759,7 @@ int RunMacroAsSubrCall(RestartData *cont prog->name ? prog->name : ""); if (status == STAT_ERROR) { @@ -181,7 +181,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c FreeRestartData(context); return MACRO_ERROR; } -@@ -777,7 +770,6 @@ int RunMacroAsSubrCall(RestartData *cont +@@ -780,7 +773,6 @@ int RunMacroAsSubrCall(RestartData *cont void FreeRestartData(RestartData *context) { rewindStack(context); @@ -189,7 +189,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c XtFree((char *)context); } -@@ -798,8 +790,8 @@ void PreemptMacro(void) +@@ -801,8 +793,8 @@ void PreemptMacro(void) */ void ModifyReturnedValue(RestartData *context, DataValue dv) { @@ -200,7 +200,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -808,7 +800,7 @@ void ModifyReturnedValue(RestartData *co +@@ -811,7 +803,7 @@ void ModifyReturnedValue(RestartData *co */ WindowInfo *MacroRunWindow(void) { @@ -209,7 +209,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -818,7 +810,7 @@ WindowInfo *MacroRunWindow(void) +@@ -821,7 +813,7 @@ WindowInfo *MacroRunWindow(void) */ WindowInfo *MacroFocusWindow(void) { @@ -218,7 +218,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -827,7 +819,12 @@ WindowInfo *MacroFocusWindow(void) +@@ -830,7 +822,12 @@ WindowInfo *MacroFocusWindow(void) */ void SetMacroFocusWindow(WindowInfo *window) { @@ -232,7 +232,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -1317,24 +1314,11 @@ void GarbageCollectStrings(void) +@@ -1320,24 +1317,11 @@ void GarbageCollectStrings(void) /* ** Save and restore execution context to data structure "context" */ @@ -261,7 +261,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } static void freeSymbolList(Symbol *symList) -@@ -1374,7 +1358,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1377,7 +1361,7 @@ static void addToGlobalSymTab(Symbol *sy GlobalSymTab[idx] = sym; } @@ -270,7 +270,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #define GET_SYM(s) \ do { \ -@@ -1435,7 +1419,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1438,7 +1422,7 @@ static void addToGlobalSymTab(Symbol *sy /* true, if you can push n values */ #define OK_TO_PUSH(n) \ @@ -279,7 +279,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #define PUSH_CHECK(n) \ do { \ -@@ -1604,9 +1588,8 @@ static int pushSymVal(void) +@@ -1607,9 +1591,8 @@ static int pushSymVal(void) symVal = FP_GET_ARG_N(FrameP, argNum); } } else if (s->type == PROC_VALUE_SYM) { @@ -291,7 +291,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c EXEC_ERROR(errMsg, s->name); } } else -@@ -2371,8 +2354,8 @@ static int eq(void) +@@ -2374,8 +2357,8 @@ static int eq(void) /* negated eq() call */ static int ne(void) { @@ -302,7 +302,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2702,7 +2685,6 @@ static int callSubroutineFromSymbol(Symb +@@ -2705,7 +2688,6 @@ static int callSubroutineFromSymbol(Symb static DataValue noValue = {NO_TAG, {0}}; DataValue argArray = noValue; Program *prog; @@ -310,7 +310,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c int haveNamedArgs = (nArgs < 0); if (haveNamedArgs) { -@@ -2715,6 +2697,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2718,6 +2700,7 @@ static int callSubroutineFromSymbol(Symb */ if (sym->type == C_FUNCTION_SYM) { DataValue result; @@ -318,7 +318,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH(argArray); /* push dummy named arg array */ -@@ -2723,9 +2706,9 @@ static int callSubroutineFromSymbol(Symb +@@ -2726,9 +2709,9 @@ static int callSubroutineFromSymbol(Symb /* Call the function and check for preemption */ PreemptRequest = False; @@ -330,7 +330,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH_RET_VAL(result); return PreemptRequest ? STAT_PREEMPT : STAT_OK; } -@@ -2738,15 +2721,10 @@ static int callSubroutineFromSymbol(Symb +@@ -2741,15 +2724,10 @@ static int callSubroutineFromSymbol(Symb ** values which are already there. */ if (sym->type == MACRO_FUNCTION_SYM) { @@ -347,7 +347,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2999,7 +2977,6 @@ static int returnValOrNone(int valOnStac +@@ -3002,7 +2980,6 @@ static int returnValOrNone(int valOnStac { DataValue retVal; static DataValue noValue = {NO_TAG, {0}}; @@ -355,7 +355,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(); STACKDUMP(StackP - FrameP + FP_GET_ARG_COUNT(FrameP) + FP_TO_ARGS_DIST, 3); -@@ -3012,9 +2989,7 @@ static int returnValOrNone(int valOnStac +@@ -3015,9 +2992,7 @@ static int returnValOrNone(int valOnStac retVal = noValue; } @@ -366,7 +366,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* push returned value, if requsted */ PUSH_RET_VAL(retVal); -@@ -4157,27 +4132,27 @@ static int errCheck(const char *s) +@@ -4160,27 +4135,27 @@ static int errCheck(const char *s) /* ** build a stack dump string, reallocating s as necessary. */ @@ -399,7 +399,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c nFrames = 0; do { nFrames++; -@@ -4204,7 +4179,7 @@ static char *stackDumpStr(DataValue *fp, +@@ -4207,7 +4182,7 @@ static char *stackDumpStr(DataValue *fp, while (*op) *np++ = *op++; @@ -408,7 +408,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c nFrames = 0; do { nFrames++; -@@ -4243,14 +4218,14 @@ static char *stackDumpStr(DataValue *fp, +@@ -4246,14 +4221,14 @@ static char *stackDumpStr(DataValue *fp, ** result. Returns false so a single return execError() statement can ** be used to both process the message and return. */ @@ -425,7 +425,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_ERROR; } -@@ -4856,25 +4831,25 @@ static void stackdumpframe(DataValue *ar +@@ -4859,25 +4834,25 @@ static void stackdumpframe(DataValue *ar #endif /* #ifdef DEBUG_STACK_HEADFIRST */ } @@ -459,7 +459,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c { static int outIsTTY = -1; if (outIsTTY == -1) -@@ -4883,7 +4858,7 @@ static void stackdump(int n, int extra) +@@ -4886,7 +4861,7 @@ static void stackdump(int n, int extra) #ifndef DEBUG_STACKDUMP_EXTRA #define DEBUG_STACKDUMP_EXTRA 0 #endif diff --git a/handle-error-in-RunMacroAsSubrCall.patch b/handle-error-in-RunMacroAsSubrCall.patch index 7aad95e..d127938 100644 --- a/handle-error-in-RunMacroAsSubrCall.patch +++ b/handle-error-in-RunMacroAsSubrCall.patch @@ -29,7 +29,7 @@ diff --quilt old/source/macro.c new/source/macro.c diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -513,19 +513,34 @@ void FillLoopAddrs(Inst *breakAddr, Inst +@@ -516,19 +516,34 @@ int FillLoopAddrs(Inst *breakAddr, Inst /* ** helper function to setup the next frame */ @@ -68,7 +68,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } else { -@@ -536,74 +551,76 @@ static void setupFrame(DataValue **frame +@@ -539,74 +554,76 @@ static void setupFrame(DataValue **frame } /* cached arg array */ @@ -181,7 +181,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } -@@ -619,9 +636,8 @@ int ExecuteMacro(WindowInfo *window, Pro +@@ -622,9 +639,8 @@ int ExecuteMacro(WindowInfo *window, Pro { RestartData *context; static DataValue argArray = {NO_TAG, {0}}; @@ -192,7 +192,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c haveNamedArgs = (nArgs < 0); if (haveNamedArgs) { -@@ -643,10 +659,15 @@ int ExecuteMacro(WindowInfo *window, Pro +@@ -646,10 +662,15 @@ int ExecuteMacro(WindowInfo *window, Pro context->pc = NULL; /* prog will be freed by cller, but by stack also, so inc refcount */ prog->refcount++; @@ -210,7 +210,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* Begin execution, return on error or preemption */ return ContinueMacro(context, result, msg); } -@@ -733,17 +754,29 @@ int ContinueMacro(RestartData *continuat +@@ -736,17 +757,29 @@ int ContinueMacro(RestartData *continuat ** separate contexts, and serializes processing of the two macros without ** additional work. */ @@ -243,7 +243,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c XtFree((char *)context->stack); XtFree((char *)context); } -@@ -2700,12 +2733,15 @@ static int callSubroutineFromSymbol(Symb +@@ -2703,12 +2736,15 @@ static int callSubroutineFromSymbol(Symb ** values which are already there. */ if (sym->type == MACRO_FUNCTION_SYM) { @@ -262,7 +262,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2958,6 +2994,7 @@ static int returnValOrNone(int valOnStac +@@ -2961,6 +2997,7 @@ static int returnValOrNone(int valOnStac { DataValue retVal; static DataValue noValue = {NO_TAG, {0}}; @@ -270,7 +270,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-1, 1); STACKDUMP(StackP - FrameP + FP_GET_ARG_COUNT(FrameP) + FP_TO_ARGS_DIST, 3); -@@ -2969,8 +3006,10 @@ static int returnValOrNone(int valOnStac +@@ -2972,8 +3009,10 @@ static int returnValOrNone(int valOnStac else { retVal = noValue; } @@ -286,7 +286,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c diff --quilt old/source/interpret.h new/source/interpret.h --- old/source/interpret.h +++ new/source/interpret.h -@@ -179,7 +179,7 @@ void FillLoopAddrs(Inst *breakAddr, Inst +@@ -179,7 +179,7 @@ int FillLoopAddrs(Inst *breakAddr, Inst int ExecuteMacro(WindowInfo *window, Program *prog, int nArgs, DataValue *args, DataValue *result, RestartData **continuation, char **msg); int ContinueMacro(RestartData *continuation, DataValue *result, char **msg); diff --git a/key-grammar.patch b/key-grammar.patch index 76c5af1..ae8e571 100644 --- a/key-grammar.patch +++ b/key-grammar.patch @@ -6,7 +6,7 @@ diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -121,7 +121,7 @@ static int nextSymIsField = 0; +@@ -127,7 +127,7 @@ static int nextSymIsField = 0; %token NUMBER %token DELETE ARG_LOOKUP %token IF WHILE DO ELSE FOR BREAK CONTINUE RETURN DEFINE TYPEOF KEYVAL @@ -15,7 +15,7 @@ diff --quilt old/source/parse.y new/source/parse.y %type cond comastmts comastmtlst for while do else and or arrayexpr mark %type evalsym %type definesym -@@ -351,49 +351,27 @@ simpstmt: /* simple variable assignmen +@@ -359,49 +359,27 @@ simpstmt: /* simple variable assignmen ADD_OP(OP_ASSIGN); ADD_SYM($1); } /* delete array entry simple statement */ @@ -83,7 +83,7 @@ diff --quilt old/source/parse.y new/source/parse.y } | initarraylv '[' '@' ']' '=' blank expr { ADD_OP(OP_ARRAY_ASSIGN_NEXT); -@@ -462,13 +440,9 @@ lvlist: blank { +@@ -470,13 +448,9 @@ lvlist: blank { SwapCode($4, $5, GetPC()); } ; @@ -99,7 +99,7 @@ diff --quilt old/source/parse.y new/source/parse.y } ; /* lventry's value is the start of the assignment code */ -@@ -478,17 +452,11 @@ lventry: SYMBOL { +@@ -486,17 +460,11 @@ lventry: SYMBOL { $$ = GetPC(); ADD_OP(OP_ASSIGN); ADD_SYM($1); } @@ -120,7 +120,7 @@ diff --quilt old/source/parse.y new/source/parse.y } ; -@@ -505,11 +473,14 @@ comastmtlst: simp +@@ -513,11 +481,14 @@ comastmtlst: simp ; /* array key argument lists */ @@ -139,7 +139,7 @@ diff --quilt old/source/parse.y new/source/parse.y ; /* string concatenation lists */ -@@ -545,11 +516,8 @@ funccall: TYPEOF '(' { +@@ -553,11 +524,8 @@ funccall: TYPEOF '(' { fnarg: expr { $$ = 0; } @@ -153,9 +153,9 @@ diff --quilt old/source/parse.y new/source/parse.y } ; fnarglsopt: blank { $$ = 0; } -@@ -605,22 +573,16 @@ expr: catlist { +@@ -613,22 +581,16 @@ expr: catlist { initarraylv: SYMBOL { - ADD_OP(OP_PUSH_ARRAY_SYM); ADD_SYM($1); ADD_IMMED(1); + ADD_OP(OP_PUSH_ARRAY_SYM); ADD_IMMED(1); ADD_SYM($1); } - | initarraylv '[' arglistopt ']' { - ADD_OP(OP_ARRAY_REF); ADD_IMMED($3); @@ -168,7 +168,7 @@ diff --quilt old/source/parse.y new/source/parse.y ; arraylv: SYMBOL { - ADD_OP(OP_PUSH_ARRAY_SYM); ADD_SYM($1); ADD_IMMED(0); + ADD_OP(OP_PUSH_ARRAY_SYM); ADD_IMMED(0); ADD_SYM($1); } - | arraylv '[' arglistopt ']' { - ADD_OP(OP_ARRAY_REF); ADD_IMMED($3); @@ -180,7 +180,7 @@ diff --quilt old/source/parse.y new/source/parse.y } ; -@@ -661,15 +623,10 @@ arrentry: blank { +@@ -669,15 +631,10 @@ arrentry: blank { /* make a suitable index >= 0 and add expr there */ ADD_OP(OP_ANONARRAY_NEXT_VAL); } @@ -198,7 +198,7 @@ diff --quilt old/source/parse.y new/source/parse.y } ; -@@ -687,11 +644,8 @@ numexpr: '(' blank expr blank ')' +@@ -695,11 +652,8 @@ numexpr: '(' blank expr blank ')' | ARG_LOOKUP '[' blank ']' { ADD_OP(OP_PUSH_ARG_COUNT); } */ | ARG_LOOKUP { ADD_OP(OP_PUSH_ARG_ARRAY); } diff --git a/macro_name.patch b/macro_name.patch index d943995..33ead56 100644 --- a/macro_name.patch +++ b/macro_name.patch @@ -37,7 +37,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -1505,6 +1512,10 @@ static int pushSymVal(void) +@@ -1508,6 +1515,10 @@ static int pushSymVal(void) symVal.tag = INT_TAG; symVal.val.n = nArgs; } diff --git a/nested-subroutines.patch b/nested-subroutines.patch index 428416f..c25ff05 100644 --- a/nested-subroutines.patch +++ b/nested-subroutines.patch @@ -17,7 +17,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c newProg->refcount = 1; DISASM(newProg->name, newProg->code, ProgP - Prog); -@@ -584,6 +585,29 @@ static int setupFrame(RestartData *conte +@@ -587,6 +588,29 @@ static int setupFrame(RestartData *conte return STAT_OK; } @@ -47,7 +47,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c static void rewindFrame(RestartData *context) { /* get stored return information */ -@@ -592,8 +616,7 @@ static void rewindFrame(RestartData *con +@@ -595,8 +619,7 @@ static void rewindFrame(RestartData *con Inst *newPC = FP_GET_RET_PC(context->frameP); Program *prog = FP_GET_PROG(context->frameP); Symbol *symList = FP_GET_SYM_TAB(context->frameP); @@ -57,7 +57,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* pop past local variables */ context->stackP = context->frameP; -@@ -605,6 +628,14 @@ static void rewindFrame(RestartData *con +@@ -608,6 +631,14 @@ static void rewindFrame(RestartData *con FreeProgram(prog); context->pc = newPC; @@ -72,7 +72,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } static void rewindStack(RestartData *context) -@@ -2677,8 +2708,14 @@ static int callSubroutineFromSymbol(Symb +@@ -2680,8 +2711,14 @@ static int callSubroutineFromSymbol(Symb if (sym->value.tag == MACRO_SUBR_TAG) { prog = sym->value.val.prog; prog->refcount++; @@ -89,7 +89,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -4875,3 +4912,4 @@ static void stackdump(RestartData *conte +@@ -4878,3 +4915,4 @@ static void stackdump(RestartData *conte } #endif /* ifdef DEBUG_STACK */ diff --git a/pushString.patch b/pushString.patch index 475bc3e..25be289 100644 --- a/pushString.patch +++ b/pushString.patch @@ -61,7 +61,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Add a branch offset operand to the current program */ int AddBranchOffset(Inst *to, char **msg) -@@ -819,47 +833,6 @@ void SetMacroFocusWindow(WindowInfo *win +@@ -822,47 +836,6 @@ void SetMacroFocusWindow(WindowInfo *win } } @@ -109,7 +109,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c static Symbol *lookupSymbol(Symbol *symlist, const char *name, unsigned int hash) { -@@ -906,8 +879,7 @@ Symbol *InstallSymbol(const char *name, +@@ -909,8 +882,7 @@ Symbol *InstallSymbol(const char *name, Symbol *s; s = XtNew(Symbol); @@ -119,7 +119,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c s->type = type; s->value = value; s->hash = hashName(s->name); -@@ -1287,7 +1259,6 @@ static void freeSymbolList(Symbol *symLi +@@ -1290,7 +1262,6 @@ static void freeSymbolList(Symbol *symLi while (symList != NULL) { s = symList; symList = s->next; @@ -127,7 +127,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c XtFree((char *)s); } } -@@ -1349,6 +1320,16 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1352,6 +1323,16 @@ static void addToGlobalSymTab(Symbol *sy PC++; \ } while (0) @@ -144,7 +144,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #define JUMP(a) \ do { \ PC = (a); \ -@@ -1531,7 +1512,7 @@ static int pushSymVal(void) +@@ -1534,7 +1515,7 @@ static int pushSymVal(void) if (s->type == LOCAL_SYM) { symVal = FP_GET_SYM_VAL(FrameP, s); @@ -153,7 +153,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c symVal = s->value; } else if (s->type == ARG_SYM) { nArgs = FP_GET_ARG_COUNT(FrameP); -@@ -1583,6 +1564,27 @@ static int pushImmed(void) +@@ -1586,6 +1567,27 @@ static int pushImmed(void) return STAT_OK; } @@ -181,7 +181,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c static int pushArgVal(void) { int nArgs, argNum; -@@ -2921,7 +2923,7 @@ int OverlayRoutineFromProg(Program *prog +@@ -2924,7 +2926,7 @@ int OverlayRoutineFromProg(Program *prog Symbol sym; sym.type = MACRO_FUNCTION_SYM; @@ -190,7 +190,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c sym.value.tag = NO_TAG; sym.value.val.prog = prog; sym.next = NULL; -@@ -4090,6 +4092,100 @@ static int errCheck(const char *s) +@@ -4093,6 +4095,100 @@ static int errCheck(const char *s) } /* @@ -291,7 +291,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** build a stack dump string, reallocating s as necessary. */ static char *stackDumpStr(RestartData *context, const char *msg, char **s, int *pLen) -@@ -4268,6 +4364,8 @@ static const char *instTypeToStr(enum in +@@ -4271,6 +4367,8 @@ static const char *instTypeToStr(enum in return "operation"; case IMMED_INST: return "immediate"; @@ -300,7 +300,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c case BRANCH_INST: return "branch"; case SYM_INST: -@@ -4351,6 +4449,41 @@ int outPrintd() +@@ -4354,6 +4452,41 @@ int outPrintd() #endif /* #ifdef DEBUG_DISASSEMBLER */ #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */ @@ -342,7 +342,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c static void dumpVal(DataValue dv) { switch (dv.tag) { -@@ -4359,38 +4492,16 @@ static void dumpVal(DataValue dv) +@@ -4362,38 +4495,16 @@ static void dumpVal(DataValue dv) break; case STRING_TAG: { @@ -385,7 +385,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } break; -@@ -4453,6 +4564,16 @@ static void dumpInst(Inst *inst, const c +@@ -4456,6 +4567,16 @@ static void dumpInst(Inst *inst, const c printd(" <%s %d>", name, inst->val.immed); break; @@ -402,7 +402,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c case BRANCH_INST: printd(" <%s %+td:%8p>", name, inst->val.branch, inst + inst->val.branch); -@@ -4507,10 +4628,6 @@ static void disasmInternal(Inst *inst, i +@@ -4510,10 +4631,6 @@ static void disasmInternal(Inst *inst, i case OP_ASSIGN: CHECK_OPERANDS(1, SYM_INST); dumpInst(&inst[i+1], NULL); @@ -413,7 +413,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ++i; break; -@@ -4520,6 +4637,12 @@ static void disasmInternal(Inst *inst, i +@@ -4523,6 +4640,12 @@ static void disasmInternal(Inst *inst, i ++i; break; @@ -490,7 +490,7 @@ diff --quilt old/source/interpret.h new/source/interpret.h int StartLoopAddrList(char **msg); int AddBreakAddr(Inst *addr, char **msg); int AddContinueAddr(Inst *addr, char **msg); - void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr); + int FillLoopAddrs(Inst *breakAddr, Inst *continueAddr, char **msg); -/* create a permanently allocated static string (only for use with static strings) */ -#define PERM_ALLOC_STR(xStr) (((char *)("\001" xStr)) + 1) @@ -526,7 +526,7 @@ diff --quilt old/source/parse.y new/source/parse.y #define ADD_BR_OFF(to) \ do { \ if (!AddBranchOffset(to, &ErrMsg)) { \ -@@ -108,13 +114,15 @@ static int nextSymIsField = 0; +@@ -114,13 +120,15 @@ static int nextSymIsField = 0; Symbol *sym; Inst *inst; int num; @@ -543,7 +543,7 @@ diff --quilt old/source/parse.y new/source/parse.y %token NUMBER %token DELETE ARG_LOOKUP %token IF WHILE DO ELSE FOR BREAK CONTINUE RETURN DEFINE TYPEOF KEYVAL -@@ -624,7 +632,7 @@ arraylv: SYMBOL { +@@ -632,7 +640,7 @@ arraylv: SYMBOL { ; field: FIELD { @@ -552,7 +552,7 @@ diff --quilt old/source/parse.y new/source/parse.y } /* this bit allows things like array.5 for array[5] ** | NUMBER { -@@ -674,7 +682,7 @@ arrentry: blank { +@@ -682,7 +690,7 @@ arrentry: blank { numexpr: '(' blank expr blank ')' | NUMBER { ADD_OP(OP_PUSH_IMMED); ADD_IMMED($1); } @@ -561,7 +561,7 @@ diff --quilt old/source/parse.y new/source/parse.y | SYMBOL { ADD_OP(OP_PUSH_SYM); ADD_SYM($1); } | funccall { ADD_OP(OP_FETCH_RET_VAL); -@@ -925,7 +933,7 @@ static int yylex(void) +@@ -933,7 +941,7 @@ static int yylex(void) if (!strcmp(symName, "typeof")) return TYPEOF; if (nextSymIsField) { nextSymIsField = 0; @@ -570,7 +570,7 @@ diff --quilt old/source/parse.y new/source/parse.y return FIELD; } if ((s=LookupSymbol(symName)) == NULL) { -@@ -1260,12 +1268,13 @@ static int scanString(void) +@@ -1268,12 +1276,13 @@ static int scanString(void) if (*InPtr == stopper) { if (!p) { /* this was the size measurement and validation */ diff --git a/readonly-statement.patch b/readonly-statement.patch index 10dcde4..3f41921 100644 --- a/readonly-statement.patch +++ b/readonly-statement.patch @@ -9,7 +9,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -3958,6 +3958,20 @@ static int typeOfOut(void) +@@ -3961,6 +3961,20 @@ static int typeOfOut(void) return STAT_OK; } @@ -41,7 +41,7 @@ diff --quilt old/source/ops.h new/source/ops.h diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -121,7 +121,7 @@ static int nextSymIsField = 0; +@@ -127,7 +127,7 @@ static int nextSymIsField = 0; %token SYMBOL STRING FIELD %token NUMBER %token DELETE ARG_LOOKUP @@ -50,7 +50,7 @@ diff --quilt old/source/parse.y new/source/parse.y %type keyargs key keyopt catlist fnarglsopt fnarglist fnarg %type cond comastmts comastmtlst for while do else and or arrayexpr mark %type evalsym -@@ -380,6 +380,13 @@ simpstmt: /* simple variable assignmen +@@ -388,6 +388,13 @@ simpstmt: /* simple variable assignmen | initarraylv '[' '@' ']' '=' blank expr { ADD_OP(OP_ARRAY_ASSIGN_NEXT); } @@ -64,7 +64,7 @@ diff --quilt old/source/parse.y new/source/parse.y | funccall | lvlistexpr ; -@@ -909,6 +916,7 @@ static int yylex(void) +@@ -917,6 +924,7 @@ static int yylex(void) if (!strcmp(symName, "delete") && follow_non_whitespace('(', SYMBOL, DELETE) == DELETE) return DELETE; if (!strcmp(symName, "define") && follow_non_whitespace('(', SYMBOL, DEFINE) == DEFINE) return DEFINE; if (!strcmp(symName, "typeof")) return TYPEOF; diff --git a/remove-args-from-DISASM_RT.patch b/remove-args-from-DISASM_RT.patch index 9ec5c47..201971f 100644 --- a/remove-args-from-DISASM_RT.patch +++ b/remove-args-from-DISASM_RT.patch @@ -19,7 +19,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #endif /* #ifndef DEBUG_STACK */ /* Global symbols and function definitions, is null initialized */ -@@ -1548,7 +1548,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1551,7 +1551,7 @@ static void addToGlobalSymTab(Symbol *sy #define BINARY_NUMERIC_OPERATION(operator) \ do { \ int n1, n2; \ @@ -28,7 +28,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); \ POP_INT(n2); \ POP_INT(n1); \ -@@ -1559,7 +1559,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1562,7 +1562,7 @@ static void addToGlobalSymTab(Symbol *sy #define UNARY_NUMERIC_OPERATION(operator) \ do { \ int n; \ @@ -37,7 +37,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 3); \ POP_INT(n); \ PUSH_INT(operator n); \ -@@ -1579,7 +1579,7 @@ static int pushSymVal(void) +@@ -1582,7 +1582,7 @@ static int pushSymVal(void) int nArgs, argNum; DataValue symVal; @@ -46,7 +46,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); GET_SYM(s); -@@ -1629,7 +1629,7 @@ static int pushImmed(void) +@@ -1632,7 +1632,7 @@ static int pushImmed(void) { int immed; @@ -55,7 +55,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); GET_IMMED(immed); -@@ -1643,7 +1643,7 @@ static int pushArgVal(void) +@@ -1646,7 +1646,7 @@ static int pushArgVal(void) { int nArgs, argNum; @@ -64,7 +64,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 3); POP_INT(argNum); -@@ -1659,7 +1659,7 @@ static int pushArgVal(void) +@@ -1662,7 +1662,7 @@ static int pushArgVal(void) static int pushArgCount(void) { @@ -73,7 +73,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); PUSH_INT(FP_GET_ARG_COUNT(FrameP)); -@@ -1672,7 +1672,7 @@ static int pushArgArray(void) +@@ -1675,7 +1675,7 @@ static int pushArgArray(void) DataValue argVal, *argArray; Boolean needArgCopy = False; @@ -82,7 +82,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); nArgs = FP_GET_ARG_COUNT(FrameP); -@@ -1713,7 +1713,7 @@ static int pushArraySymVal(void) +@@ -1716,7 +1716,7 @@ static int pushArraySymVal(void) DataValue *dataPtr; int initEmpty; @@ -91,7 +91,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); GET_SYM(sym); -@@ -1756,7 +1756,7 @@ static int anonArrayOpen(void) +@@ -1759,7 +1759,7 @@ static int anonArrayOpen(void) { DataValue dataVal; @@ -100,7 +100,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); /* make an empty array */ -@@ -1787,7 +1787,7 @@ static int anonArraySkip(void) +@@ -1790,7 +1790,7 @@ static int anonArraySkip(void) DataValue anonArray; int nextIndex; @@ -109,7 +109,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); POP(anonArray); -@@ -1819,7 +1819,7 @@ static int anonArrayNextVal(void) +@@ -1822,7 +1822,7 @@ static int anonArrayNextVal(void) int nextIndex; char numString[TYPE_INT_STR_SIZE(int)]; @@ -118,7 +118,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(3, 3); POP(exprVal); -@@ -1856,9 +1856,10 @@ static int anonArrayIndexVal(void) +@@ -1859,9 +1859,10 @@ static int anonArrayIndexVal(void) int nextIndex, index; int nDim; @@ -130,7 +130,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nDim+3, 3); POP(exprVal); -@@ -1903,7 +1904,7 @@ static int anonArrayClose(void) +@@ -1906,7 +1907,7 @@ static int anonArrayClose(void) DataValue anonArray; DataValue next_index; @@ -139,7 +139,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); /* remove top two elements */ -@@ -1953,9 +1954,10 @@ static int namedArg1orN(Boolean isFirst) +@@ -1956,9 +1957,10 @@ static int namedArg1orN(Boolean isFirst) DataValue exprVal, argsArray; int nDim, index; @@ -151,7 +151,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nDim + (isFirst ? 2 : 1), 3); POP(exprVal); -@@ -1999,7 +2001,7 @@ static int swapTop2(void) +@@ -2002,7 +2004,7 @@ static int swapTop2(void) { DataValue dv1, dv2; @@ -160,7 +160,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); POP(dv1); -@@ -2024,7 +2026,7 @@ static int assign(void) +@@ -2027,7 +2029,7 @@ static int assign(void) DataValue *dataPtr; DataValue value; @@ -169,7 +169,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 3); GET_SYM(sym); -@@ -2071,7 +2073,7 @@ static int popStack(void) +@@ -2074,7 +2076,7 @@ static int popStack(void) { DataValue val; @@ -178,7 +178,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 4); POP(val); -@@ -2088,7 +2090,7 @@ static int dupStack(void) +@@ -2091,7 +2093,7 @@ static int dupStack(void) { DataValue value; @@ -187,7 +187,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 3); PEEK(value, 0); -@@ -2110,7 +2112,7 @@ static int add(void) +@@ -2113,7 +2115,7 @@ static int add(void) DataValue leftVal, rightVal, resultArray; int n1, n2; @@ -196,7 +196,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); PEEK(rightVal, 0); -@@ -2182,7 +2184,7 @@ static int subtract(void) +@@ -2185,7 +2187,7 @@ static int subtract(void) DataValue leftVal, rightVal, resultArray; int n1, n2; @@ -205,7 +205,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); PEEK(rightVal, 0); -@@ -2254,7 +2256,7 @@ static int divide(void) +@@ -2257,7 +2259,7 @@ static int divide(void) { int n1, n2; @@ -214,7 +214,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); POP_INT(n2); -@@ -2270,7 +2272,7 @@ static int modulo(void) +@@ -2273,7 +2275,7 @@ static int modulo(void) { int n1, n2; @@ -223,7 +223,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); POP_INT(n2); -@@ -2327,7 +2329,7 @@ static int eq(void) +@@ -2330,7 +2332,7 @@ static int eq(void) { DataValue v1, v2; @@ -232,7 +232,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); POP(v1); -@@ -2383,7 +2385,7 @@ static int bitAnd(void) +@@ -2386,7 +2388,7 @@ static int bitAnd(void) DataValue leftVal, rightVal, resultArray; int n1, n2; @@ -241,7 +241,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); PEEK(rightVal, 0); -@@ -2443,7 +2445,7 @@ static int bitOr(void) +@@ -2446,7 +2448,7 @@ static int bitOr(void) DataValue leftVal, rightVal, resultArray; int n1, n2; @@ -250,7 +250,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); PEEK(rightVal, 0); -@@ -2526,7 +2528,7 @@ static int power(void) +@@ -2529,7 +2531,7 @@ static int power(void) { int n1, n2, n3; @@ -259,7 +259,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); POP_INT(n2); -@@ -2650,9 +2652,10 @@ static int concat(void) +@@ -2653,9 +2655,10 @@ static int concat(void) int nExpr; @@ -271,7 +271,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nExpr, 3); /* remember: concatenateNwithSep() succeeds with a non-positive number */ -@@ -2809,10 +2812,11 @@ static int callSubroutine(void) +@@ -2812,10 +2815,11 @@ static int callSubroutine(void) Symbol *sym; int nArgs; @@ -284,7 +284,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nArgs > 0 ? nArgs : -nArgs, 3); return callSubroutineFromSymbol(sym, nArgs); -@@ -2846,7 +2850,7 @@ static int callSubroutineUnpackArray(voi +@@ -2849,7 +2853,7 @@ static int callSubroutineUnpackArray(voi SparseArrayEntry *iter; DataValue dvEntry, dvArray, argArray; @@ -293,7 +293,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c GET_SYM(sym); GET_IMMED(nArgs); -@@ -2996,7 +3000,7 @@ static int returnValOrNone(int valOnStac +@@ -2999,7 +3003,7 @@ static int returnValOrNone(int valOnStac static DataValue noValue = {NO_TAG, {0}}; RestartData context; @@ -302,7 +302,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(StackP - FrameP + FP_GET_ARG_COUNT(FrameP) + FP_TO_ARGS_DIST, 3); /* return value is on the stack */ -@@ -3028,7 +3032,7 @@ static int branch(void) +@@ -3031,7 +3035,7 @@ static int branch(void) { Inst *addr; @@ -311,7 +311,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); GET_BRANCH(addr); -@@ -3058,7 +3062,7 @@ static int branchIf(Boolean trueOrFalse) +@@ -3061,7 +3065,7 @@ static int branchIf(Boolean trueOrFalse) int value; Inst *addr; @@ -320,7 +320,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 3); GET_BRANCH(addr); -@@ -3082,7 +3086,7 @@ static int branchNever(void) +@@ -3085,7 +3089,7 @@ static int branchNever(void) { Inst *addr; @@ -329,7 +329,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); GET_BRANCH(addr); -@@ -3445,9 +3449,10 @@ static int arrayRef(void) +@@ -3448,9 +3452,10 @@ static int arrayRef(void) char *keyString = NULL; int nDim; @@ -341,7 +341,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nDim+1, 3); if (nDim > 0) { -@@ -3495,9 +3500,10 @@ static int arrayAssign(void) +@@ -3498,9 +3503,10 @@ static int arrayAssign(void) int errNum; int nDim; @@ -353,7 +353,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nDim+2, 3); if (nDim > 0) { -@@ -3547,10 +3553,11 @@ static int arrayRefAndAssignSetup(void) +@@ -3550,10 +3556,11 @@ static int arrayRefAndAssignSetup(void) char *keyString = NULL; int binaryOp, nDim; @@ -366,7 +366,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nDim + (binaryOp ? 2 : 1), 3); if (binaryOp) { -@@ -3601,7 +3608,7 @@ static int beginArrayIter(void) +@@ -3604,7 +3611,7 @@ static int beginArrayIter(void) DataValue *iteratorValPtr; DataValue arrayVal; @@ -375,7 +375,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 3); GET_SYM(iterator); -@@ -3660,7 +3667,7 @@ static int arrayIter(void) +@@ -3663,7 +3670,7 @@ static int arrayIter(void) Inst *branchAddr; int withVal; @@ -384,7 +384,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 4); GET_IMMED(withVal); -@@ -3736,7 +3743,7 @@ static int beginArrayIterArray(void) +@@ -3739,7 +3746,7 @@ static int beginArrayIterArray(void) DataValue arrayVal; int nDims; @@ -393,7 +393,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); GET_SYM(iterator); -@@ -3838,7 +3845,7 @@ static int arrayIterArray(void) +@@ -3841,7 +3848,7 @@ static int arrayIterArray(void) int nDims, d; Boolean keyFound = False; @@ -402,7 +402,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 4); GET_IMMED(withVal); -@@ -3940,7 +3947,7 @@ static int inArray(void) +@@ -3943,7 +3950,7 @@ static int inArray(void) char *keyStr; int inResult = 0; @@ -411,7 +411,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); POP(theArray); -@@ -3984,9 +3991,10 @@ static int deleteArrayElement(void) +@@ -3987,9 +3994,10 @@ static int deleteArrayElement(void) char *keyString = NULL; int nDim; @@ -423,7 +423,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nDim + 1, 3); if (nDim > 0) { -@@ -4074,7 +4082,7 @@ static int arrayAssignNext(void) +@@ -4077,7 +4085,7 @@ static int arrayAssignNext(void) DataValue srcValue, dstArray; int errNum; @@ -432,7 +432,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); POP(srcValue); -@@ -4116,7 +4124,7 @@ static int arrayNextNumIdx(void) +@@ -4119,7 +4127,7 @@ static int arrayNextNumIdx(void) DataValue srcArray; SparseArrayEntry *iter; diff --git a/series b/series index db1834e..8a81603 100644 --- a/series +++ b/series @@ -133,3 +133,5 @@ fix-return-value-from-overlay-routines.patch nested-subroutines.patch macro_name.patch zero-based-Program-refcount.patch +break-continue-multi.patch +booleanize.patch diff --git a/symbol-lookup.patch b/symbol-lookup.patch index 358175b..fc95c24 100644 --- a/symbol-lookup.patch +++ b/symbol-lookup.patch @@ -1,10 +1,11 @@ --- - source/interpret.c | 251 +++++++++++++---------------------------------------- + source/interpret.c | 257 +++++++++++++---------------------------------------- source/interpret.h | 8 - source/macro.c | 6 - - source/parse.y | 73 ++++++--------- - 4 files changed, 101 insertions(+), 237 deletions(-) + source/ops.h | 2 + source/parse.y | 77 +++++++-------- + 5 files changed, 107 insertions(+), 243 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c @@ -85,7 +86,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ProgP++; return 1; } -@@ -522,7 +512,6 @@ static int setupFrame(RestartData *conte +@@ -525,7 +515,6 @@ static int setupFrame(RestartData *conte { static DataValue noValue = {NO_TAG, {0}}; int i, totalPushs = 7; @@ -93,7 +94,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* ** we push only if we have room for the whole frame, so pre-calc the -@@ -531,9 +520,6 @@ static int setupFrame(RestartData *conte +@@ -534,9 +523,6 @@ static int setupFrame(RestartData *conte if (nArgs >= 0) { totalPushs += nArgs; } @@ -103,7 +104,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* !OK_TO_PUSH(totalPushs) */ if (!((context->stackP + totalPushs) <= (context->stack + STACK_SIZE))) { -@@ -571,9 +557,9 @@ static int setupFrame(RestartData *conte +@@ -574,9 +560,9 @@ static int setupFrame(RestartData *conte context->stackP->val.dataval = context->frameP; context->stackP++; @@ -115,7 +116,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c context->stackP++; /* macro name */ -@@ -589,12 +575,6 @@ static int setupFrame(RestartData *conte +@@ -592,12 +578,6 @@ static int setupFrame(RestartData *conte context->frameP = context->stackP; @@ -128,7 +129,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c context->pc = prog->code; return STAT_OK; -@@ -607,6 +587,9 @@ static void rewindFrame(RestartData *con +@@ -610,6 +590,9 @@ static void rewindFrame(RestartData *con DataValue *newFrameP = FP_GET_OLD_FP(context->frameP); Inst *newPC = FP_GET_RET_PC(context->frameP); Program *prog = FP_GET_PROG(context->frameP); @@ -138,7 +139,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* pop past local variables */ context->stackP = context->frameP; -@@ -847,17 +830,20 @@ static Symbol *lookupSymbol(Symbol *syml +@@ -850,17 +833,20 @@ static Symbol *lookupSymbol(Symbol *syml /* ** find a symbol in the symbol table @@ -162,7 +163,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c s = lookupSymbol(LocalSymList, name, hash); if (NULL != s) return s; -@@ -868,7 +854,13 @@ Symbol *LookupSymbol(const char *name) +@@ -871,7 +857,13 @@ Symbol *LookupSymbol(const char *name) if (NULL != s) return s; @@ -177,7 +178,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -884,8 +876,17 @@ Symbol *InstallSymbol(const char *name, +@@ -887,8 +879,17 @@ Symbol *InstallSymbol(const char *name, s->value = value; s->hash = hashName(s->name); if (type == LOCAL_SYM) { @@ -197,7 +198,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else { addToGlobalSymTab(s); } -@@ -893,70 +894,6 @@ Symbol *InstallSymbol(const char *name, +@@ -896,70 +897,6 @@ Symbol *InstallSymbol(const char *name, } /* @@ -268,7 +269,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Convert a long value to its decimal string representation, returned in a ** static string. */ -@@ -1126,7 +1063,7 @@ static SparseArrayEntry *allocateSparseA +@@ -1129,7 +1066,7 @@ static SparseArrayEntry *allocateSparseA { SparseArrayEntryWrapper *mem; @@ -277,7 +278,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c mem->next = AllocatedSparseArrayEntries; AllocatedSparseArrayEntries = mem; #ifdef TRACK_GARBAGE_LEAKS -@@ -1290,14 +1227,19 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1293,14 +1230,19 @@ static void addToGlobalSymTab(Symbol *sy #define EXEC_ERROR(s1, s2) return execError(Interpreter, s1, s2) @@ -299,7 +300,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } while (0) #define GET_IMMED(i) \ -@@ -1508,11 +1450,9 @@ static int pushSymVal(void) +@@ -1511,11 +1453,9 @@ static int pushSymVal(void) DISASM_RT(); STACKDUMP(0, 3); @@ -313,13 +314,13 @@ diff --quilt old/source/interpret.c new/source/interpret.c symVal = s->value; } else if (s->type == ARG_SYM) { nArgs = FP_GET_ARG_COUNT(FrameP); -@@ -1662,18 +1602,13 @@ static int pushArraySymVal(void) +@@ -1665,18 +1605,13 @@ static int pushArraySymVal(void) DISASM_RT(); STACKDUMP(0, 3); - GET_SYM(sym); -+ GET_SYM(sym, True); GET_IMMED(initEmpty); ++ GET_SYM(sym, initEmpty); - if (sym->type == LOCAL_SYM) { - dataPtr = &FP_GET_SYM_VAL(FrameP, sym); @@ -335,7 +336,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (initEmpty && dataPtr->tag == NO_TAG) { dataPtr->tag = ARRAY_TAG; -@@ -1975,7 +1910,7 @@ static int assign(void) +@@ -1978,7 +1913,7 @@ static int assign(void) DISASM_RT(); STACKDUMP(1, 3); @@ -344,7 +345,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) { if (sym->type == ARG_SYM) { -@@ -1988,13 +1923,7 @@ static int assign(void) +@@ -1991,13 +1926,7 @@ static int assign(void) EXEC_ERROR("assignment to non-variable: %s", sym->name); } } @@ -359,7 +360,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c POP(value); -@@ -2778,7 +2707,7 @@ static int callSubroutine(void) +@@ -2781,7 +2710,7 @@ static int callSubroutine(void) DISASM_RT(); @@ -368,7 +369,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c GET_IMMED(nArgs); STACKDUMP(nArgs > 0 ? nArgs : -nArgs, 3); -@@ -2816,7 +2745,7 @@ static int callSubroutineUnpackArray(voi +@@ -2819,7 +2748,7 @@ static int callSubroutineUnpackArray(voi DISASM_RT(); @@ -377,7 +378,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c GET_IMMED(nArgs); if (nArgs < 0) { -@@ -3627,35 +3556,25 @@ static int arrayIter(void) +@@ -3630,35 +3559,25 @@ static int arrayIter(void) STACKDUMP(1, 4); GET_IMMED(withVal); @@ -419,7 +420,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c valPtr->tag = NO_TAG; } -@@ -3794,37 +3713,27 @@ static int arrayIterArray(void) +@@ -3797,37 +3716,27 @@ static int arrayIterArray(void) STACKDUMP(2, 4); GET_IMMED(withVal); @@ -463,7 +464,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c valPtr->tag = NO_TAG; } -@@ -4580,7 +4489,7 @@ static void dumpInst(Inst *inst, const c +@@ -4583,7 +4492,7 @@ static void dumpInst(Inst *inst, const c break; case SYM_INST: @@ -472,7 +473,20 @@ diff --quilt old/source/interpret.c new/source/interpret.c break; case NO_INST: -@@ -4806,11 +4715,6 @@ static void stackdumpframe(DataValue *ar +@@ -4763,9 +4672,9 @@ static void disasmInternal(Inst *inst, i + break; + + case OP_PUSH_ARRAY_SYM: +- CHECK_OPERANDS(2, SYM_INST, IMMED_INST); +- dumpInst(&inst[i+1], +- inst[i+2].val.immed ? "createAndRef" : "refOnly"); ++ CHECK_OPERANDS(2, IMMED_INST, SYM_INST); ++ dumpInst(&inst[i+2], ++ inst[i+1].val.immed ? "createAndRef" : "refOnly"); + i += 2; + break; + +@@ -4809,11 +4718,6 @@ static void stackdumpframe(DataValue *ar DataValue *endDv = (arg1 > outpt) ? arg1 : outpt; int nArgs = FP_GET_ARG_COUNT(fp); @@ -484,7 +498,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #ifdef DEBUG_STACK_HEADFIRST #else /* do caller's frame */ -@@ -4819,17 +4723,6 @@ static void stackdumpframe(DataValue *ar +@@ -4822,17 +4726,6 @@ static void stackdumpframe(DataValue *ar #endif /* #ifdef DEBUG_STACK_HEADFIRST */ /* do current frame */ @@ -502,7 +516,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* output instructions between endDv and sp - 1 inclusive */ #ifdef DEBUG_STACK_HEADFIRST -@@ -4840,7 +4733,6 @@ static void stackdumpframe(DataValue *ar +@@ -4843,7 +4736,6 @@ static void stackdumpframe(DataValue *ar #endif /* #ifdef DEBUG_STACK_HEADFIRST */ { const char *posFmt = "%-6s"; @@ -510,7 +524,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c char *pos = ""; char buffer[sizeof(STACK_DUMP_ARG_PREFIX) + TYPE_INT_STR_SIZE(int)]; -@@ -4864,10 +4756,6 @@ static void stackdumpframe(DataValue *ar +@@ -4867,10 +4759,6 @@ static void stackdumpframe(DataValue *ar sprintf(pos = buffer, STACK_DUMP_ARG_PREFIX "%d", offset + FP_TO_ARGS_DIST + nArgs + 1); } @@ -521,7 +535,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c else if (offset == 0) { pos = "FrameP"; } -@@ -4875,17 +4763,6 @@ static void stackdumpframe(DataValue *ar +@@ -4878,17 +4766,6 @@ static void stackdumpframe(DataValue *ar } printd(posFmt, pos); @@ -593,7 +607,7 @@ diff --quilt old/source/interpret.h new/source/interpret.h diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -111,25 +111,20 @@ static int nextSymIsField = 0; +@@ -117,25 +117,20 @@ static int nextSymIsField = 0; %} %union { @@ -623,7 +637,7 @@ diff --quilt old/source/parse.y new/source/parse.y %type operassign incrdecr %token '=' ADDEQ SUBEQ MULEQ DIVEQ MODEQ ANDEQ OREQ %token INCR DECR -@@ -199,31 +194,29 @@ definekw: DEFINE { +@@ -205,31 +200,29 @@ definekw: DEFINE { } ; definesym: SYMBOL { @@ -674,7 +688,7 @@ diff --quilt old/source/parse.y new/source/parse.y } ; -@@ -532,18 +525,18 @@ funccall: TYPEOF '(' { +@@ -540,18 +533,18 @@ funccall: TYPEOF '(' { } | SYMBOL '(' fnarglsopt ')' { ADD_OP(OP_SUBR_CALL); @@ -696,7 +710,25 @@ diff --quilt old/source/parse.y new/source/parse.y ADD_IMMED($3); } ; -@@ -931,19 +924,17 @@ static int yylex(void) +@@ -618,7 +611,7 @@ expr: catlist { + ; + + initarraylv: SYMBOL { +- ADD_OP(OP_PUSH_ARRAY_SYM); ADD_SYM($1); ADD_IMMED(1); ++ ADD_OP(OP_PUSH_ARRAY_SYM); ADD_IMMED(1); ADD_SYM($1); + } + | initarraylv '[' arglistopt ']' { + ADD_OP(OP_ARRAY_REF); ADD_IMMED($3); +@@ -629,7 +622,7 @@ initarraylv: SYMBOL { + ; + + arraylv: SYMBOL { +- ADD_OP(OP_PUSH_ARRAY_SYM); ADD_SYM($1); ADD_IMMED(0); ++ ADD_OP(OP_PUSH_ARRAY_SYM); ADD_IMMED(0); ADD_SYM($1); + } + | arraylv '[' arglistopt ']' { + ADD_OP(OP_ARRAY_REF); ADD_IMMED($3); +@@ -939,19 +932,17 @@ static int yylex(void) if (!strcmp(symName, "delete") && follow_non_whitespace('(', SYMBOL, DELETE) == DELETE) return DELETE; if (!strcmp(symName, "define") && follow_non_whitespace('(', SYMBOL, DEFINE) == DEFINE) return DEFINE; if (!strcmp(symName, "typeof")) return TYPEOF; @@ -721,7 +753,7 @@ diff --quilt old/source/parse.y new/source/parse.y return SYMBOL; } nextSymIsField = 0; -@@ -1105,7 +1096,7 @@ static Symbol *matchesActionRoutine(char +@@ -1113,7 +1104,7 @@ static Symbol *matchesActionRoutine(char if (!hasDash) return NULL; *symPtr = '\0'; @@ -760,3 +792,15 @@ diff --quilt old/source/macro.c new/source/macro.c if (NULL != hookSymbol && MACRO_FUNCTION_SYM == hookSymbol->type) { Program *hookProg = hookSymbol->value.val.prog; RestartData *restartData; +diff --quilt old/source/ops.h new/source/ops.h +--- old/source/ops.h ++++ new/source/ops.h +@@ -48,7 +48,7 @@ OP(BEGIN_ARRAY_ITER_ARRAY, beginArrayIte + OP(ARRAY_ITER_ARRAY, arrayIterArray) /*w,ka[,v],pc*/ /* top(N),while it: (if dim(it.k)==N: (ka.v=split(it.k),(w?v.v=it.v:),return),it++), PC=pc */ + OP(IN_ARRAY, inArray) /* pop(a,k), push(a[k]?1:0) */ + OP(ARRAY_DELETE, deleteArrayElement) /*N*/ /* N>0 ? (pop(kN..k1,a), del(a[k])) : (pop(a), delall(a)) */ +-OP(PUSH_ARRAY_SYM, pushArraySymVal) /*s,i*/ /* if i: s.v=ary()), push(s.v) */ ++OP(PUSH_ARRAY_SYM, pushArraySymVal) /*i,s*/ /* if i: s.v=ary()), push(s.v) */ + OP(ARRAY_REF_ASSIGN_SETUP, arrayRefAndAssignSetup) /*op,N*/ /* pop(v,kN..a), a[k1..kN] op= v */ + OP(ARRAY_NEXT_NUM_IDX, arrayNextNumIdx) /* pop(a), push(a.nextidx) */ + OP(PUSH_ARG, pushArgVal) /* pop(num), push($num) */ diff --git a/ternary-operator-GNU.patch b/ternary-operator-GNU.patch index dd2875e..b1fe3ad 100644 --- a/ternary-operator-GNU.patch +++ b/ternary-operator-GNU.patch @@ -8,7 +8,7 @@ diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -96,6 +96,7 @@ static int follow2(char expect1, int yes +@@ -102,6 +102,7 @@ static int follow2(char expect1, int yes static int follow_non_whitespace(char expect, int yes, int no); static int eq_look_ahead(void); static int comma_look_ahead(void); @@ -16,7 +16,7 @@ diff --quilt old/source/parse.y new/source/parse.y static Symbol *matchesActionRoutine(char **inPtr); static int scanString(void); -@@ -131,7 +132,7 @@ static int nextSymIsField = 0; +@@ -137,7 +138,7 @@ static int nextSymIsField = 0; %type lvlist %type lventry %token ARGSEP @@ -25,7 +25,7 @@ diff --quilt old/source/parse.y new/source/parse.y %nonassoc IF_NO_ELSE %nonassoc ELSE -@@ -139,7 +140,7 @@ static int nextSymIsField = 0; +@@ -145,7 +146,7 @@ static int nextSymIsField = 0; %nonassoc ';' %nonassoc SYMBOL ARG_LOOKUP %right '=' ADDEQ SUBEQ MULEQ DIVEQ MODEQ ANDEQ OREQ @@ -34,7 +34,7 @@ diff --quilt old/source/parse.y new/source/parse.y %left CONCAT %left OR %left AND -@@ -678,6 +679,9 @@ numexpr: '(' blank expr blank ')' +@@ -686,6 +687,9 @@ numexpr: '(' blank expr blank ')' SET_BR_OFF($2, $5 + 1); /* thenx limb ends at $5+1 */ SET_BR_OFF($5, GetPC()); /* elsex limb ends here */ } @@ -44,7 +44,7 @@ diff --quilt old/source/parse.y new/source/parse.y | incrdecr blank SYMBOL %prec INCR { ADD_OP(OP_PUSH_SYM); ADD_SYM($3); ADD_OP($1); ADD_OP(OP_DUP); ADD_OP(OP_ASSIGN); ADD_SYM($3); -@@ -740,13 +744,24 @@ or: OR { +@@ -748,13 +752,24 @@ or: OR { ; thenx: '?' { @@ -69,7 +69,7 @@ diff --quilt old/source/parse.y new/source/parse.y dot: '.' %prec '.' { nextSymIsField = 1; -@@ -938,6 +953,7 @@ static int yylex(void) +@@ -946,6 +961,7 @@ static int yylex(void) return result; /* but return what we started with */ } case ',': return comma_look_ahead(); @@ -77,7 +77,7 @@ diff --quilt old/source/parse.y new/source/parse.y default: return *(InPtr-1); } } -@@ -1039,6 +1055,24 @@ static int comma_look_ahead(void) +@@ -1047,6 +1063,24 @@ static int comma_look_ahead(void) return ','; } @@ -105,7 +105,7 @@ diff --quilt old/source/parse.y new/source/parse.y diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -2463,6 +2463,36 @@ static int power(void) +@@ -2466,6 +2466,36 @@ static int power(void) return errCheck("exponentiation"); } diff --git a/ternary-operator.patch b/ternary-operator.patch index f13c541..2d1c431 100644 --- a/ternary-operator.patch +++ b/ternary-operator.patch @@ -6,7 +6,7 @@ diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -131,6 +131,7 @@ static int nextSymIsField = 0; +@@ -137,6 +137,7 @@ static int nextSymIsField = 0; %type lvlist %type lventry %token ARGSEP @@ -14,7 +14,7 @@ diff --quilt old/source/parse.y new/source/parse.y %nonassoc IF_NO_ELSE %nonassoc ELSE -@@ -138,6 +139,7 @@ static int nextSymIsField = 0; +@@ -144,6 +145,7 @@ static int nextSymIsField = 0; %nonassoc ';' %nonassoc SYMBOL ARG_LOOKUP %right '=' ADDEQ SUBEQ MULEQ DIVEQ MODEQ ANDEQ OREQ @@ -22,7 +22,7 @@ diff --quilt old/source/parse.y new/source/parse.y %left CONCAT %left OR %left AND -@@ -672,6 +674,10 @@ numexpr: '(' blank expr blank ')' +@@ -680,6 +682,10 @@ numexpr: '(' blank expr blank ')' | numexpr or blank numexpr %prec OR { ADD_OP(OP_OR); SET_BR_OFF($2, GetPC()); } @@ -33,7 +33,7 @@ diff --quilt old/source/parse.y new/source/parse.y | incrdecr blank SYMBOL %prec INCR { ADD_OP(OP_PUSH_SYM); ADD_SYM($3); ADD_OP($1); ADD_OP(OP_DUP); ADD_OP(OP_ASSIGN); ADD_SYM($3); -@@ -733,6 +739,15 @@ or: OR { +@@ -741,6 +747,15 @@ or: OR { } ; diff --git a/typed-Inst.patch b/typed-Inst.patch index f8d7968..6b5b844 100644 --- a/typed-Inst.patch +++ b/typed-Inst.patch @@ -108,7 +108,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return 1; } -@@ -485,10 +501,10 @@ void FillLoopAddrs(Inst *breakAddr, Inst +@@ -485,10 +501,10 @@ int FillLoopAddrs(Inst *breakAddr, Inst } if (*LoopStackPtr == NULL) break; @@ -120,10 +120,10 @@ diff --quilt old/source/interpret.c new/source/interpret.c + (*LoopStackPtr)->val.branch = breakAddr - *LoopStackPtr; + else if ((*LoopStackPtr)->val.immed == NEEDS_CONTINUE) + (*LoopStackPtr)->val.branch = continueAddr - *LoopStackPtr; - else - fprintf(stderr, "NEdit: internal error (uat) in macro parser\n"); - } -@@ -660,14 +676,20 @@ int ContinueMacro(RestartData *continuat + else { + *msg = "internal error (uat)"; + return 0; +@@ -663,14 +679,20 @@ int ContinueMacro(RestartData *continuat /* Execute an instruction */ inst = PC++; @@ -149,7 +149,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* If error return was not STAT_OK, return to caller */ -@@ -743,7 +765,7 @@ void PreemptMacro(void) +@@ -746,7 +768,7 @@ void PreemptMacro(void) */ void ModifyReturnedValue(RestartData *context, DataValue dv) { @@ -158,7 +158,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c *(context->stackP-1) = dv; } -@@ -1321,19 +1343,31 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1324,19 +1346,31 @@ static void addToGlobalSymTab(Symbol *sy #define GET_SYM(s) \ do { \ @@ -193,7 +193,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PC++; \ } while (0) -@@ -1347,7 +1381,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1350,7 +1384,7 @@ static void addToGlobalSymTab(Symbol *sy if (PC == NULL) { \ PUSH(dv); \ } \ @@ -202,7 +202,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH(dv); \ PC++; \ } \ -@@ -4242,6 +4276,23 @@ static const char *tagToStr(enum typeTag +@@ -4245,6 +4279,23 @@ static const char *tagToStr(enum typeTag } } @@ -226,7 +226,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */ static char *printdBuffer = NULL; static int printdPos = 0; -@@ -4378,20 +4429,75 @@ static void dumpVal(DataValue dv) +@@ -4381,20 +4432,75 @@ static void dumpVal(DataValue dv) #endif /* #ifdef DEBUG_DISASSEMBLER */ #ifdef DEBUG_DISASSEMBLER /* For debugging code generation */ @@ -307,7 +307,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } } -@@ -4399,25 +4505,33 @@ static void disasmInternal(Inst *inst, i +@@ -4402,25 +4508,33 @@ static void disasmInternal(Inst *inst, i for (i = 0; i < nInstr; ++i) { printd("Prog %8p", &inst[i]); @@ -349,7 +349,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ++i; break; -@@ -4425,37 +4539,42 @@ static void disasmInternal(Inst *inst, i +@@ -4428,37 +4542,42 @@ static void disasmInternal(Inst *inst, i case OP_BRANCH_TRUE: case OP_BRANCH_FALSE: case OP_BRANCH_NEVER: @@ -403,7 +403,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } i += 2; } -@@ -4463,50 +4582,64 @@ static void disasmInternal(Inst *inst, i +@@ -4466,50 +4585,64 @@ static void disasmInternal(Inst *inst, i case OP_BEGIN_ARRAY_ITER: case OP_BEGIN_ARRAY_ITER_ARRAY: @@ -493,7 +493,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c i += 5; } break; -@@ -4517,21 +4650,23 @@ static void disasmInternal(Inst *inst, i +@@ -4520,21 +4653,23 @@ static void disasmInternal(Inst *inst, i case OP_ANONARRAY_INDEX_VAL: case OP_NAMED_ARG1: case OP_NAMED_ARGN: @@ -524,7 +524,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c i += 2; break; -@@ -4543,7 +4678,7 @@ static void disasmInternal(Inst *inst, i +@@ -4546,7 +4681,7 @@ static void disasmInternal(Inst *inst, i break; default: diff --git a/unify-branch-setup.patch b/unify-branch-setup.patch index c15a90c..38cb0e0 100644 --- a/unify-branch-setup.patch +++ b/unify-branch-setup.patch @@ -1,9 +1,9 @@ --- - source/interpret.c | 53 +++++++++++++++++++++++++++++++++++++---------------- - source/interpret.h | 7 ++++--- - source/parse.y | 36 ++++++++++++++++++++++++++---------- - 3 files changed, 67 insertions(+), 29 deletions(-) + source/interpret.c | 66 ++++++++++++++++++++++++++++++++++++----------------- + source/interpret.h | 9 ++++--- + source/parse.y | 58 ++++++++++++++++++++++++++++++++-------------- + 3 files changed, 91 insertions(+), 42 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c @@ -34,7 +34,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Return the address at which the next instruction will be stored */ Inst *GetPC(void) -@@ -424,34 +434,45 @@ Inst *SwapCode(Inst *start, Inst *bounda +@@ -424,43 +434,54 @@ Inst *SwapCode(Inst *start, Inst *bounda ** address for a break or continue statement, and FillLoopAddrs to fill ** in all the addresses and return to the level of the enclosing loop. */ @@ -94,7 +94,34 @@ diff --quilt old/source/interpret.c new/source/interpret.c + return 1; } - void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr) +-void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr) ++int FillLoopAddrs(Inst *breakAddr, Inst *continueAddr, char **msg) + { + while (True) { + LoopStackPtr--; + if (LoopStackPtr < LoopStack) { +- fprintf(stderr, "NEdit: internal error (lsu) in macro parser\n"); +- return; ++ *msg = "internal error (lsu)"; ++ return 0; + } + if (*LoopStackPtr == NULL) + break; +@@ -468,9 +489,12 @@ void FillLoopAddrs(Inst *breakAddr, Inst + (*LoopStackPtr)->value = breakAddr - *LoopStackPtr; + else if ((*LoopStackPtr)->value == NEEDS_CONTINUE) + (*LoopStackPtr)->value = continueAddr - *LoopStackPtr; +- else +- fprintf(stderr, "NEdit: internal error (uat) in macro parser\n"); ++ else { ++ *msg = "internal error (uat)"; ++ return 0; ++ } + } ++ return 1; + } + + /* diff --quilt old/source/interpret.h new/source/interpret.h --- old/source/interpret.h +++ new/source/interpret.h @@ -106,23 +133,25 @@ diff --quilt old/source/interpret.h new/source/interpret.h Inst *GetPC(void); Symbol *InstallIteratorSymbol(void); Symbol *LookupStringConstSymbol(const char *value); -@@ -160,9 +161,9 @@ Symbol *InstallSymbol(const char *name, +@@ -160,10 +161,10 @@ Symbol *InstallSymbol(const char *name, Symbol *InstallMultiAssignExpr(void); Program *FinishCreatingProgram(AccumulatorData *acc); Inst *SwapCode(Inst *start, Inst *boundary, Inst *end); -void StartLoopAddrList(void); -int AddBreakAddr(Inst *addr); -int AddContinueAddr(Inst *addr); +-void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr); +int StartLoopAddrList(char **msg); +int AddBreakAddr(Inst *addr, char **msg); +int AddContinueAddr(Inst *addr, char **msg); - void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr); ++int FillLoopAddrs(Inst *breakAddr, Inst *continueAddr, char **msg); /* create a permanently allocated static string (only for use with static strings) */ + #define PERM_ALLOC_STR(xStr) (((char *)("\001" xStr)) + 1) diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -55,7 +55,27 @@ +@@ -55,7 +55,33 @@ } while (0) #define SET_BR_OFF(from, to) \ do { \ @@ -137,6 +166,12 @@ diff --quilt old/source/parse.y new/source/parse.y + return 1; \ + } \ + } while (0) ++#define END_LOOP(breakAddr, continueAddr) \ ++ do { \ ++ if (!FillLoopAddrs(breakAddr, continueAddr, &ErrMsg)) { \ ++ return 1; \ ++ } \ ++ } while (0) +#define ADD_BREAK(addr) \ + do { \ + if (!AddBreakAddr(addr, &ErrMsg)) { \ @@ -151,7 +186,60 @@ diff --quilt old/source/parse.y new/source/parse.y } while (0) /* Max. length for a string constant (... there shouldn't be a maximum) */ -@@ -309,15 +329,11 @@ stmt: ';' blank +@@ -228,14 +254,16 @@ stmt: ';' blank + } + | while '(' cond ')' blank block { + ADD_OP(OP_BRANCH); ADD_BR_OFF($1); +- SET_BR_OFF($3, GetPC()); FillLoopAddrs(GetPC(), $1); ++ SET_BR_OFF($3, GetPC()); ++ END_LOOP(GetPC(), $1); + } + | do block WHILE blank '(' mark cond ')' stmtend blank { + ADD_OP(OP_BRANCH); ADD_BR_OFF($1); +- SET_BR_OFF($7, GetPC()); FillLoopAddrs(GetPC(), $6); ++ SET_BR_OFF($7, GetPC()); ++ END_LOOP(GetPC(), $6); + } + | for '(' comastmts ';' cond ';' comastmts ')' blank block { +- FillLoopAddrs(GetPC()+2+($7-($5+1)), GetPC()); ++ END_LOOP(GetPC()+2+($7-($5+1)), GetPC()); + SwapCode($5+1, $7, GetPC()); + ADD_OP(OP_BRANCH); ADD_BR_OFF($3); SET_BR_OFF($5, GetPC()); + } +@@ -253,7 +281,7 @@ stmt: ';' blank + ADD_OP(OP_BRANCH); + ADD_BR_OFF($7+2); + SET_BR_OFF($7+6, GetPC()); +- FillLoopAddrs(GetPC(), $7+2); ++ END_LOOP(GetPC(), $7+2); + } + | for '(' blank SYMBOL KEYVAL SYMBOL IN blank arrayexpr blank ')' { + Symbol *iterSym = InstallIteratorSymbol(); +@@ -270,7 +298,7 @@ stmt: ';' blank + ADD_OP(OP_BRANCH); + ADD_BR_OFF($9+2); + SET_BR_OFF($9+7, GetPC()); +- FillLoopAddrs(GetPC(), $9+2); ++ END_LOOP(GetPC(), $9+2); + } + | for '(' blank SYMBOL '[' numexpropt ']' IN blank arrayexpr blank ')' { + Symbol *iterSym = InstallIteratorSymbol(); +@@ -286,7 +314,7 @@ stmt: ';' blank + ADD_OP(OP_BRANCH); + ADD_BR_OFF($10+2); + SET_BR_OFF($10+6, GetPC()); +- FillLoopAddrs(GetPC(), $10+2); ++ END_LOOP(GetPC(), $10+2); + ADD_OP(OP_POP); /* remove nDim from stack */ + } + | for '(' blank SYMBOL '[' numexpropt ']' KEYVAL SYMBOL IN blank arrayexpr blank ')' { +@@ -304,20 +332,16 @@ stmt: ';' blank + ADD_OP(OP_BRANCH); + ADD_BR_OFF($12+2); + SET_BR_OFF($12+7, GetPC()); +- FillLoopAddrs(GetPC(), $12+2); ++ END_LOOP(GetPC(), $12+2); + ADD_OP(OP_POP); /* remove nDim from stack */ } | BREAK stmtend blank { ADD_OP(OP_BRANCH); ADD_BR_OFF(0); @@ -169,7 +257,7 @@ diff --quilt old/source/parse.y new/source/parse.y } | RETURN expr stmtend blank { ADD_OP(OP_RETURN); -@@ -771,15 +787,15 @@ numexpropt: blank { +@@ -771,15 +795,15 @@ numexpropt: blank { ; while: WHILE blank { diff --git a/zero-based-Program-refcount.patch b/zero-based-Program-refcount.patch index edd9949..2399e1e 100644 --- a/zero-based-Program-refcount.patch +++ b/zero-based-Program-refcount.patch @@ -47,7 +47,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* ** Add an operator (instruction) to the end of the current program */ -@@ -554,7 +568,8 @@ static int setupFrame(RestartData *conte +@@ -557,7 +571,8 @@ static int setupFrame(RestartData *conte /* cached arg array */ *(context->stackP)++ = argArray; @@ -57,7 +57,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c context->stackP->tag = NO_TAG; context->stackP->val.prog = prog; context->stackP++; -@@ -632,7 +647,7 @@ static void rewindFrame(RestartData *con +@@ -635,7 +650,7 @@ static void rewindFrame(RestartData *con context->frameP = newFrameP; @@ -66,7 +66,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c context->pc = newPC; -@@ -685,7 +700,6 @@ int ExecuteMacro(WindowInfo *window, Pro +@@ -688,7 +703,6 @@ int ExecuteMacro(WindowInfo *window, Pro /* pre-set the return PC to NULL */ context->pc = NULL; /* prog will be freed by cller, but by stack also, so inc refcount */ @@ -74,7 +74,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c status = setupFrame(context, prog, nArgs, args, argArray, prog->name ? prog->name : ""); -@@ -2718,7 +2732,6 @@ static int callSubroutineFromSymbol(Symb +@@ -2721,7 +2735,6 @@ static int callSubroutineFromSymbol(Symb */ if (sym->value.tag == MACRO_SUBR_TAG) { prog = sym->value.val.prog; @@ -82,7 +82,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (prog->nested) { return setupNestedFrame(Interpreter, prog); } -@@ -2941,6 +2954,7 @@ int OverlayRoutineFromProg(Program *prog +@@ -2944,6 +2957,7 @@ int OverlayRoutineFromProg(Program *prog { Symbol sym; @@ -149,7 +149,7 @@ diff --quilt old/source/macro.c new/source/macro.c diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -212,7 +212,7 @@ define: definekw blank definesym bla +@@ -218,7 +218,7 @@ define: definekw blank definesym bla yyerror("try to override built-in subroutine"); YYERROR; } @@ -158,7 +158,7 @@ diff --quilt old/source/parse.y new/source/parse.y } else { DataValue subrPtr; -@@ -220,6 +220,7 @@ define: definekw blank definesym bla +@@ -226,6 +226,7 @@ define: definekw blank definesym bla sym = InstallSymbol(prog->name, GLOBAL_SCOPE, READONLY_ATTR, subrPtr); } -- 2.11.4.GIT