From 74cadbe92fb1102cfe6cf84faba3d3185bde5b5c Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Sat, 11 Oct 2008 22:32:42 +0200 Subject: [PATCH] convert 'pass context' to 'global context' parse-define.patch: * import v7 * fix readCheckMacro...() wrt macroCmdData ?= NULL InterpretDebug-mods.patch: * add frame counter to backtrace * add headings for backtrace and stack abstract-access-to-PC.patch: * split-up into unify-branch-setup.patch and typed-Inst.patch OP_FUNCTION.patch: * dropped because of uselessness B.W. Patch: !parse-define.patch Patch: !InterpretDebug-mods.patch Patch: +unify-branch-setup.patch Patch: !abstract-access-to-PC.patch Patch: +typed-Inst.patch Patch: -OP_FUNCTION.patch Patch: -pass-context-to-ops.patch Patch: +global-RestartData.patch Patch: +global-AccumulatorData.patch --- EXEC_ERROR.patch | 136 +- FastConcat3.diff | 4 +- GlobalSymTable.patch | 2 +- InterpretDebug-mods.patch | 122 +- InterpretDebug5.diff | 8 +- MultipleAssignment.diff | 6 +- OP_FUNCTION.patch | 541 ---- ParseFields3.diff | 22 +- RSunderlineStyle.diff | 8 +- SUBR_TAG.patch | 10 +- UnderlineStyle.diff | 4 +- abstract-access-to-FrameP.patch | 38 +- abstract-access-to-PC.patch | 1376 +++------ anonArrayNamedArgs7.diff | 10 +- array-next-num-index.patch | 4 +- arrayReplacesArglist-as-last-argument.patch | 10 +- arrayReplacesArglist5.diff | 6 +- callMacroFnByName2.diff | 2 +- core-typeof-syntax.patch | 4 +- define_macro.patch | 4 +- dictionary-fix-string-alloc.patch | 4 +- dictionary.patch | 2 +- escape_literal_macro.patch | 2 +- extend-for-key-in-array-syntax.patch | 8 +- full-single-quoted.patch | 2 +- global-AccumulatorData.patch | 195 ++ global-RestartData.patch | 546 ++++ handle-error-in-RunMacroAsSubrCall.patch | 4 +- highlight_calltip_line.patch | 2 +- indexNotInArray.diff | 2 +- macroJoin.diff | 2 +- macroSemicolons.diff | 8 +- macroSplit.diff | 12 +- macroStringLiterals3.diff | 6 +- macro_hooks.patch | 4 +- matching_patterns.patch | 4 +- multi-dim-key-iterator-arr.patch | 8 +- nmvarNEDIT_HOME2.diff | 2 +- op-not-func-in-Inst.patch | 6 +- parse-define.patch | 111 +- parseEnhance2.diff | 130 +- pass-context-to-ops.patch | 3096 --------------------- pos_line_convert.patch | 2 +- pushImmed.patch | 6 +- relativeFileNormalization.diff | 10 +- remove-args-from-DISASM_RT.patch | 100 +- remove-cast-warnings.patch | 12 +- series | 6 +- setWindowTitleFormat.diff | 2 +- shell_command-make-input-parameter-optional.patch | 2 +- stringToNum.diff | 2 +- timer_macros.patch | 2 +- transient-documents.patch | 2 +- typed-Inst.patch | 481 ++++ unify-branch-setup.patch | 190 ++ 55 files changed, 2286 insertions(+), 5004 deletions(-) delete mode 100644 OP_FUNCTION.patch rewrite abstract-access-to-PC.patch (75%) create mode 100644 global-AccumulatorData.patch create mode 100644 global-RestartData.patch delete mode 100644 pass-context-to-ops.patch create mode 100644 typed-Inst.patch create mode 100644 unify-branch-setup.patch diff --git a/EXEC_ERROR.patch b/EXEC_ERROR.patch index 7030416..b2ab213 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 -@@ -1378,10 +1378,12 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1375,10 +1375,12 @@ static void addToGlobalSymTab(Symbol *sy GlobalSymTab[idx] = sym; } @@ -19,8 +19,8 @@ diff --quilt old/source/interpret.c new/source/interpret.c + EXEC_ERROR("Unexpected instruction, expected : %s", \ instTypeToStr(PC->type)); \ } \ - s = PC++->val.sym; \ -@@ -1390,7 +1392,7 @@ static void addToGlobalSymTab(Symbol *sy + s = PC->val.sym; \ +@@ -1388,7 +1390,7 @@ static void addToGlobalSymTab(Symbol *sy #define GET_IMMED(i) \ do { \ if (PC->type != IMMED_INST) { \ @@ -28,8 +28,8 @@ diff --quilt old/source/interpret.c new/source/interpret.c + EXEC_ERROR("Unexpected instruction, expected : %s", \ instTypeToStr(PC->type)); \ } \ - i = PC++->val.immed; \ -@@ -1399,7 +1401,7 @@ static void addToGlobalSymTab(Symbol *sy + i = PC->val.immed; \ +@@ -1398,7 +1400,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; \ -@@ -1440,7 +1442,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1439,7 +1441,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) -@@ -1451,17 +1453,17 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1450,17 +1452,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) -@@ -1490,11 +1492,11 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1489,11 +1491,11 @@ static void addToGlobalSymTab(Symbol *sy __int = dataVal.val.n; \ } else if (dataVal.tag == STRING_TAG) { \ if (!StringToNum(dataVal.val.str.rep, &__int)) {\ @@ -83,7 +83,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } \ number = __int; \ } while (0) -@@ -1507,8 +1509,8 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1506,8 +1508,8 @@ static void addToGlobalSymTab(Symbol *sy } else if (dataVal.tag == INT_TAG) { \ __str = AllocStringOfNumber(dataVal.val.n); \ } else { \ @@ -94,7 +94,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } \ string = __str; \ } while (0) -@@ -1605,7 +1607,7 @@ OP_FUNCTION(pushSymVal) +@@ -1604,7 +1606,7 @@ static int pushSymVal(void) nArgs = FRAME_GET_ARG_COUNT(); argNum = s->value.val.n; if (argNum >= nArgs) { @@ -103,7 +103,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (argNum == N_ARGS_ARG_SYM) { symVal.tag = INT_TAG; -@@ -1618,7 +1620,7 @@ OP_FUNCTION(pushSymVal) +@@ -1617,7 +1619,7 @@ static int pushSymVal(void) char *errMsg; if (!(s->value.val.subr)(FocusWindow, NULL, 0, &symVal, &errMsg)) { @@ -112,7 +112,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } else if (s->type == C_FUNCTION_SYM || s->type == MACRO_FUNCTION_SYM -@@ -1626,9 +1628,9 @@ OP_FUNCTION(pushSymVal) +@@ -1625,9 +1627,9 @@ static int pushSymVal(void) symVal.tag = SUBR_TAG; symVal.val.sym = s; } else @@ -124,7 +124,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH(symVal); -@@ -1668,8 +1670,8 @@ OP_FUNCTION(pushArgVal) +@@ -1667,8 +1669,8 @@ static int pushArgVal(void) --argNum; nArgs = FRAME_GET_ARG_COUNT(); if (argNum >= nArgs || argNum < 0) { @@ -135,7 +135,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH(FRAME_GET_ARG_N(argNum)); return STAT_OK; -@@ -1708,7 +1710,7 @@ OP_FUNCTION(pushArgArray) +@@ -1707,7 +1709,7 @@ static int pushArgArray(void) argVal = FRAME_GET_ARG_N(argNum); if (!ArrayInsert(argArray, AllocStringOfNumber(argNum + 1), &argVal)) { @@ -144,7 +144,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } } -@@ -1744,7 +1746,7 @@ OP_FUNCTION(pushArraySymVal) +@@ -1743,7 +1745,7 @@ static int pushArraySymVal(void) dataPtr = &sym->value; } else { @@ -153,7 +153,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (initEmpty && dataPtr->tag == NO_TAG) { -@@ -1753,7 +1755,7 @@ OP_FUNCTION(pushArraySymVal) +@@ -1752,7 +1754,7 @@ static int pushArraySymVal(void) } if (dataPtr->tag == NO_TAG && !inTypeOfMode) { @@ -162,7 +162,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH(*dataPtr); -@@ -1846,7 +1848,7 @@ OP_FUNCTION(anonArrayNextVal) +@@ -1845,7 +1847,7 @@ static int anonArrayNextVal(void) sprintf(numString, "%d", nextIndex); if (!ArrayInsert(&anonArray, AllocStringCpy(numString), &exprVal)) { @@ -171,7 +171,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* we need to increment the index for next time */ -@@ -1898,7 +1900,7 @@ OP_FUNCTION(anonArrayIndexVal) +@@ -1897,7 +1899,7 @@ static int anonArrayIndexVal(void) } if (!ArrayInsert(&anonArray, keyString, &exprVal)) { @@ -180,7 +180,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* push the default next index value first, then the array */ -@@ -1989,7 +1991,7 @@ static int namedArg1orN(Boolean isFirst) +@@ -1988,7 +1990,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)) { @@ -189,7 +189,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (isFirst) { -@@ -2003,7 +2005,7 @@ static int namedArg1orN(Boolean isFirst) +@@ -2002,7 +2004,7 @@ static int namedArg1orN(Boolean isFirst) } if (!ArrayInsert(&argsArray, keyString, &exprVal)) { @@ -198,7 +198,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* and (re)push the array */ -@@ -2051,13 +2053,13 @@ OP_FUNCTION(assign) +@@ -2050,13 +2052,13 @@ static int assign(void) if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) { if (sym->type == ARG_SYM) { @@ -215,7 +215,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } -@@ -2173,13 +2175,13 @@ OP_FUNCTION(add) +@@ -2172,13 +2174,13 @@ static int add(void) rightIter = arrayIterateNext(rightIter); } if (!insertResult) { @@ -231,7 +231,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } else { -@@ -2187,7 +2189,7 @@ OP_FUNCTION(add) +@@ -2186,7 +2188,7 @@ static int add(void) POP_INT(n1); PUSH_INT(n1 + n2); } @@ -240,7 +240,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2239,13 +2241,13 @@ OP_FUNCTION(subtract) +@@ -2238,13 +2240,13 @@ static int subtract(void) leftIter = arrayIterateNext(leftIter); } if (!insertResult) { @@ -256,7 +256,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } else { -@@ -2253,7 +2255,7 @@ OP_FUNCTION(subtract) +@@ -2252,7 +2254,7 @@ static int subtract(void) POP_INT(n1); PUSH_INT(n1 - n2); } @@ -265,7 +265,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2280,7 +2282,7 @@ OP_FUNCTION(divide) +@@ -2279,7 +2281,7 @@ static int divide(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; -@@ -2296,7 +2298,7 @@ OP_FUNCTION(modulo) +@@ -2295,7 +2297,7 @@ static int modulo(void) POP_INT(n2); POP_INT(n1); if (n2 == 0) { @@ -283,7 +283,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH_INT(n1 % n2); return STAT_OK; -@@ -2377,11 +2379,11 @@ OP_FUNCTION(eq) +@@ -2376,11 +2378,11 @@ static int eq(void) } } else { @@ -297,7 +297,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* negated eq() call */ -@@ -2434,13 +2436,13 @@ OP_FUNCTION(bitAnd) +@@ -2433,13 +2435,13 @@ static int bitAnd(void) rightIter = arrayIterateNext(rightIter); } if (!insertResult) { @@ -313,7 +313,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } else { -@@ -2448,7 +2450,7 @@ OP_FUNCTION(bitAnd) +@@ -2447,7 +2449,7 @@ static int bitAnd(void) POP_INT(n1); PUSH_INT(n1 & n2); } @@ -322,7 +322,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2505,13 +2507,13 @@ OP_FUNCTION(bitOr) +@@ -2504,13 +2506,13 @@ static int bitOr(void) rightIter = arrayIterateNext(rightIter); } if (!insertResult) { @@ -338,7 +338,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } else { -@@ -2519,7 +2521,7 @@ OP_FUNCTION(bitOr) +@@ -2518,7 +2520,7 @@ static int bitOr(void) POP_INT(n1); PUSH_INT(n1 | n2); } @@ -346,8 +346,8 @@ diff --quilt old/source/interpret.c new/source/interpret.c + return STAT_OK; } - OP_FUNCTION(and) -@@ -2676,7 +2678,7 @@ OP_FUNCTION(concat) + static int and(void) +@@ -2675,7 +2677,7 @@ static int concat(void) len = concatenateNwithSep(nExpr, "", &out, False); if (len < 0) { @@ -356,7 +356,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH_STRING(out, len); return STAT_OK; -@@ -2733,7 +2735,8 @@ static int callSubroutineFromSymbol(Symb +@@ -2732,7 +2734,8 @@ static int callSubroutineFromSymbol(Symb if (symValPtr->tag == SUBR_TAG) { sym = symValPtr->val.sym; } else { @@ -366,7 +366,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } -@@ -2752,7 +2755,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2751,7 +2754,7 @@ static int callSubroutineFromSymbol(Symb PreemptRequest = False; if (!sym->value.val.subr(FocusWindow, StackP, nArgs, &result, &errMsg)) @@ -375,7 +375,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH_RET_VAL(result); return PreemptRequest ? STAT_PREEMPT : STAT_OK; } -@@ -2787,8 +2790,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2786,8 +2789,7 @@ static int callSubroutineFromSymbol(Symb Window win; if (haveNamedArgs) { @@ -385,7 +385,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c sym->name); } -@@ -2824,7 +2826,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2823,7 +2825,7 @@ static int callSubroutineFromSymbol(Symb } /* Calling a non subroutine symbol */ @@ -394,7 +394,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2880,7 +2882,7 @@ OP_FUNCTION(callSubroutineStackedN) +@@ -2879,7 +2881,7 @@ static int callSubroutineStackedN(void) if (nArgs >= 0) { /* should never happen */ @@ -403,7 +403,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } return callSubroutineFromSymbol(sym, nArgs); -@@ -2989,7 +2991,7 @@ OP_FUNCTION(unpackArrayToArgs) +@@ -2988,7 +2990,7 @@ static int unpackArrayToArgs(void) POP(argArray); if (argArray.tag != ARRAY_TAG) { @@ -412,7 +412,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (haveNamedArgs) { -@@ -3024,7 +3026,7 @@ OP_FUNCTION(unpackArrayToArgs) +@@ -3023,7 +3025,7 @@ static int unpackArrayToArgs(void) } else { if (!ArrayInsert(&dvArray, iter->key, &dvEntry)) { @@ -421,16 +421,16 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } -@@ -3043,7 +3045,7 @@ OP_FUNCTION(unpackArrayToArgs) +@@ -3042,7 +3044,7 @@ static int unpackArrayToArgs(void) */ - OP_FUNCTION(fetchRetVal) + static int fetchRetVal(void) { - return execError("internal error: frv", NULL); + EXEC_ERROR("internal error: frv", NULL); } /* see comments for returnValOrNone() */ -@@ -3183,17 +3185,17 @@ int ArrayCopy(DataValue *dstArray, DataV +@@ -3182,17 +3184,17 @@ int ArrayCopy(DataValue *dstArray, DataV return(errNum); } if (!ArrayInsert(dstArray, srcIter->key, &tmpArray)) { @@ -451,7 +451,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3210,9 +3212,9 @@ static int makeArrayKeyFromArgs(int nArg +@@ -3209,9 +3211,9 @@ static int makeArrayKeyFromArgs(int nArg len = concatenateNwithSep(nArgs, ARRAY_DIM_SEP, keyString, leaveParams); if (len < 0) { @@ -463,7 +463,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3532,23 +3534,24 @@ OP_FUNCTION(arrayRef) +@@ -3531,23 +3533,24 @@ static int arrayRef(void) POP(srcArray); if (srcArray.tag == ARRAY_TAG) { if (!ArrayGet(&srcArray, keyString, &valueItem)) { @@ -493,7 +493,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } } -@@ -3585,7 +3588,7 @@ OP_FUNCTION(arrayAssign) +@@ -3584,7 +3587,7 @@ static int arrayAssign(void) POP(dstArray); if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) { @@ -502,7 +502,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (srcValue.tag == ARRAY_TAG) { DataValue arrayCopyValue; -@@ -3597,13 +3600,13 @@ OP_FUNCTION(arrayAssign) +@@ -3596,13 +3599,13 @@ static int arrayAssign(void) } } if (ArrayInsert(&dstArray, keyString, &srcValue)) { @@ -519,7 +519,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3641,20 +3644,21 @@ OP_FUNCTION(arrayRefAndAssignSetup) +@@ -3640,20 +3643,21 @@ static int arrayRefAndAssignSetup(void) PEEK(srcArray, nDim); if (srcArray.tag == ARRAY_TAG) { if (!ArrayGet(&srcArray, keyString, &valueItem)) { @@ -545,7 +545,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } -@@ -3687,16 +3691,16 @@ OP_FUNCTION(beginArrayIter) +@@ -3686,16 +3690,16 @@ static int beginArrayIter(void) iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); } else { @@ -565,7 +565,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3753,7 +3757,7 @@ OP_FUNCTION(arrayIter) +@@ -3752,7 +3756,7 @@ static int arrayIter(void) keyValPtr = &(keySym->value); } else { @@ -574,7 +574,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } keyValPtr->tag = NO_TAG; -@@ -3765,7 +3769,7 @@ OP_FUNCTION(arrayIter) +@@ -3764,7 +3768,7 @@ static int arrayIter(void) valPtr = &(valSym->value); } else { @@ -583,7 +583,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } valPtr->tag = NO_TAG; } -@@ -3774,7 +3778,7 @@ OP_FUNCTION(arrayIter) +@@ -3773,7 +3777,7 @@ static int arrayIter(void) iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); } else { @@ -592,7 +592,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } thisEntry = iteratorValPtr->val.arrayPtr; -@@ -3795,7 +3799,7 @@ OP_FUNCTION(arrayIter) +@@ -3794,7 +3798,7 @@ static int arrayIter(void) else { JUMP(branchAddr); } @@ -601,7 +601,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3823,21 +3827,21 @@ OP_FUNCTION(beginArrayMultiIterArray) +@@ -3822,21 +3826,21 @@ static int beginArrayMultiIterArray(void iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); } else { @@ -627,7 +627,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } static int countDim(const char *key) -@@ -3933,7 +3937,7 @@ OP_FUNCTION(arrayMultiIterArray) +@@ -3932,7 +3936,7 @@ static int arrayMultiIterArray(void) keyArrayPtr = &(keyArraySym->value); } else { @@ -636,7 +636,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } keyArrayPtr->tag = ARRAY_TAG; keyArrayPtr->val.arrayPtr = NULL; -@@ -3946,7 +3950,7 @@ OP_FUNCTION(arrayMultiIterArray) +@@ -3945,7 +3949,7 @@ static int arrayMultiIterArray(void) valPtr = &valSym->value; } else { @@ -645,7 +645,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } valPtr->tag = NO_TAG; } -@@ -3955,7 +3959,7 @@ OP_FUNCTION(arrayMultiIterArray) +@@ -3954,7 +3958,7 @@ static int arrayMultiIterArray(void) iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); } else { @@ -654,7 +654,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } thisEntry = iteratorValPtr->val.arrayPtr; -@@ -3976,7 +3980,7 @@ OP_FUNCTION(arrayMultiIterArray) +@@ -3975,7 +3979,7 @@ static int arrayMultiIterArray(void) /* set keys */ if (!splitKeyIntoArray(thisEntry->key, keyArrayPtr)) { @@ -663,7 +663,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (withVal) { -@@ -4020,7 +4024,7 @@ OP_FUNCTION(inArray) +@@ -4019,7 +4023,7 @@ static int inArray(void) POP(theArray); if (theArray.tag != ARRAY_TAG) { @@ -672,7 +672,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PEEK(leftArray, 0); if (leftArray.tag == ARRAY_TAG) { -@@ -4041,7 +4045,7 @@ OP_FUNCTION(inArray) +@@ -4040,7 +4044,7 @@ static int inArray(void) } } PUSH_INT(inResult); @@ -681,7 +681,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -4084,15 +4088,15 @@ OP_FUNCTION(deleteArrayElement) +@@ -4083,15 +4087,15 @@ static int deleteArrayElement(void) } } else { @@ -692,7 +692,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c + return STAT_OK; } - OP_FUNCTION(typeOfIn) + static int typeOfIn(void) { if (inTypeOfMode) { - return(execError("I'm already in typeof-mode", NULL)); @@ -700,7 +700,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } inTypeOfMode = 1; -@@ -4106,7 +4110,7 @@ OP_FUNCTION(typeOfOut) +@@ -4105,7 +4109,7 @@ static int typeOfOut(void) DataValue retVal; if (!inTypeOfMode) { @@ -709,7 +709,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } inTypeOfMode = 0; -@@ -4160,7 +4164,7 @@ OP_FUNCTION(arrayAssignNext) +@@ -4159,7 +4163,7 @@ static int arrayAssignNext(void) POP(dstArray); if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) { @@ -718,7 +718,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (srcValue.tag == ARRAY_TAG) { -@@ -4176,7 +4180,7 @@ OP_FUNCTION(arrayAssignNext) +@@ -4175,7 +4179,7 @@ static int arrayAssignNext(void) keyString = AllocStringOfNumber(arrayMaxNumIdx(&dstArray) + 1); if (!ArrayInsert(&dstArray, keyString, &srcValue)) { @@ -727,7 +727,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } return STAT_OK; -@@ -4200,7 +4204,7 @@ OP_FUNCTION(arrayNextNumIdx) +@@ -4199,7 +4203,7 @@ static int arrayNextNumIdx(void) POP(srcArray); if (srcArray.tag != ARRAY_TAG) { @@ -736,7 +736,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH_INT(arrayMaxNumIdx(&srcArray) + 1); -@@ -4215,9 +4219,9 @@ OP_FUNCTION(arrayNextNumIdx) +@@ -4214,9 +4218,9 @@ static int arrayNextNumIdx(void) static int errCheck(const char *s) { if (errno == EDOM) diff --git a/FastConcat3.diff b/FastConcat3.diff index d160c6f..f286430 100644 --- a/FastConcat3.diff +++ b/FastConcat3.diff @@ -370,8 +370,8 @@ diff --quilt old/source/parse.y new/source/parse.y +%type arglist catlist %type cond comastmts for while else and or arrayexpr %type evalsym - -@@ -357,9 +357,20 @@ arglist: /* nothing */ { + %type definesym +@@ -361,9 +361,20 @@ arglist: /* nothing */ { $$ = $1 + 1; } ; diff --git a/GlobalSymTable.patch b/GlobalSymTable.patch index ae78afa..1eb26ea 100644 --- a/GlobalSymTable.patch +++ b/GlobalSymTable.patch @@ -261,7 +261,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) -@@ -4378,8 +4437,8 @@ static void disasmInternal(Inst *inst, i +@@ -4402,8 +4461,8 @@ static void disasmInternal(Inst *inst, i if (j == OP_PUSH_SYM || j == OP_ASSIGN) { Symbol *sym = inst[i+1].sym; printd(" %s", sym->name); diff --git a/InterpretDebug-mods.patch b/InterpretDebug-mods.patch index c4eff89..a8f01fb 100644 --- a/InterpretDebug-mods.patch +++ b/InterpretDebug-mods.patch @@ -2,11 +2,11 @@ Subject: modifications to the InterpretDebug patch --- - source/interpret.c | 117 ++++++++++++++++++++++++++++++++++------------------- - source/interpret.h | 5 +- - source/parse.y | 14 ++---- + source/interpret.c | 151 ++++++++++++++++++++++++++++++++++++----------------- + source/interpret.h | 5 + + source/parse.y | 14 +--- source/userCmds.c | 4 - - 4 files changed, 86 insertions(+), 54 deletions(-) + 4 files changed, 115 insertions(+), 59 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c @@ -117,7 +117,91 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3779,28 +3783,46 @@ static void dumpVal(DataValue dv) +@@ -3586,7 +3590,9 @@ static int errCheck(const char *s) + */ + static char *stackDumpStr(DataValue *fp, const char *msg, char **s, int *pLen) + { +- int len; ++ static const char backtraceMsg[] = "\n\nBacktrace:"; ++ char frameBuf[TYPE_INT_STR_SIZE(int) + 2]; ++ int len, nFrames, frameWidth, thisFrameWidth; + const char *op; + char *np; + DataValue *nfp = fp; +@@ -3594,22 +3600,26 @@ static char *stackDumpStr(DataValue *fp, + + #ifdef DEBUG_STACK + const char *dump; +- printd("\n\n"); ++ static const char stackdumpMsg[] = "\n\nStack:\n"; + disasmInternal(PC - 1, 1); + stackdumpInternal(0, 50); + dump = printd(NULL); + #endif + + /* first measure the lengths */ +- len = strlen(msg) + 1; ++ len = strlen(msg) + strlen(backtraceMsg) + 1; + nfp = fp; ++ nFrames = 0; + do { ++ nFrames++; + len = len + FP_GET_ITEM(nfp, FP_FUNCTION_NAME).val.str.len + 1; + pc = FP_GET_RET_PC(nfp); + nfp = FP_GET_OLD_FP(nfp); + } while (pc); ++ frameWidth = lenLongAsStr(nFrames); ++ len += nFrames * (2 + frameWidth); + #ifdef DEBUG_STACK +- len += strlen(dump); ++ len += strlen(stackdumpMsg) + strlen(dump); + #endif + if (*pLen < len) + { +@@ -3621,10 +3631,25 @@ static char *stackDumpStr(DataValue *fp, + op = msg; + while (*op) + *np++ = *op++; ++ op = backtraceMsg; ++ while (*op) ++ *np++ = *op++; + + nfp = fp; ++ nFrames = 0; + do { ++ nFrames++; + *np++ = '\n'; ++ *np++ = '#'; ++ thisFrameWidth = 0; ++ op = longAsStr(nFrames); ++ while (*op) { ++ thisFrameWidth++; ++ *np++ = *op++; ++ } ++ while (thisFrameWidth++ < frameWidth) ++ *np++ = ' '; ++ *np++ = ' '; + op = FP_GET_ITEM(nfp, FP_FUNCTION_NAME).val.str.rep; + while (*op) + *np++ = *op++; +@@ -3632,12 +3657,15 @@ static char *stackDumpStr(DataValue *fp, + nfp = FP_GET_OLD_FP(nfp); + } while (pc); + #ifdef DEBUG_STACK ++ op = stackdumpMsg; ++ while (*op) ++ *np++ = *op++; + op = dump; + while (*op) + *np++ = *op++; + #endif + +- *np = 0; ++ *np = '\0'; + return *s; + } + +@@ -3779,28 +3807,46 @@ static void dumpVal(DataValue dv) { switch (dv.tag) { case INT_TAG: @@ -173,7 +257,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c break; case NO_TAG: if (!dv.val.inst) { -@@ -3826,57 +3848,66 @@ static void disasmInternal(Inst *inst, i +@@ -3826,57 +3872,66 @@ static void disasmInternal(Inst *inst, i #undef OP }; int i, j; @@ -253,7 +337,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c inst[i+1].sym->name, inst[i+2].sym->name, inst[i+3].value, &inst[i+3] + inst[i+3].value); -@@ -3888,18 +3919,20 @@ static void disasmInternal(Inst *inst, i +@@ -3888,18 +3943,20 @@ static void disasmInternal(Inst *inst, i j == OP_ANONARRAY_INDEX_VAL || j == OP_NAMED_ARG1 || j == OP_NAMED_ARGN) { @@ -280,7 +364,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } printd("\n"); -@@ -3907,18 +3940,20 @@ static void disasmInternal(Inst *inst, i +@@ -3907,18 +3964,20 @@ static void disasmInternal(Inst *inst, i } } if (j == N_OPS) { @@ -303,7 +387,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c outPrintd(); } #endif /* #ifdef DEBUG_DISASSEMBLER */ -@@ -4047,7 +4082,7 @@ static void stackdumpInternal(int n, int +@@ -4047,7 +4106,7 @@ static void stackdumpInternal(int n, int if (outpt < TheStack) printd("--------------Stack base--------------\n"); stackdumpframe(arrow, outpt, FrameP, StackP, '*'); @@ -344,16 +428,16 @@ 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 -@@ -195,7 +195,7 @@ define: DEFINE { - yyerror("try to override built-in subroutine"); YYERROR; - } - $$.sym = PromoteToGlobal($4); -- BeginCreatingProgram($$.acc); -+ BeginCreatingProgram($$.sym->name, $$.acc); +@@ -196,7 +196,7 @@ definesym: SYMBOL { + yyerror("try to override built-in subroutine"); YYERROR; + } + $$.sym = PromoteToGlobal($1); +- BeginCreatingProgram($$.acc); ++ BeginCreatingProgram($$.sym->name, $$.acc); } - blank blockwb { - ADD_OP(OP_RETURN_NO_VAL); -@@ -745,14 +745,16 @@ Program *ParseMacro(char *expr, char **m + ; + define: definekw blank definesym blank blockwb { +@@ -747,14 +747,16 @@ Program *ParseMacro(char *expr, char **m { Program *prog; AccumulatorData *acc = (AccumulatorData *)XtMalloc(sizeof(*acc)); @@ -372,7 +456,7 @@ diff --quilt old/source/parse.y new/source/parse.y /* whether we allow the "define" keyword */ AllowDefine = allowDefine; -@@ -780,12 +782,6 @@ Program *ParseMacro(char *expr, char **m +@@ -782,12 +784,6 @@ Program *ParseMacro(char *expr, char **m prog = FinishCreatingProgram(acc); XtFree((char *)acc); diff --git a/InterpretDebug5.diff b/InterpretDebug5.diff index f28d7a7..bb69390 100644 --- a/InterpretDebug5.diff +++ b/InterpretDebug5.diff @@ -748,7 +748,7 @@ diff --quilt old/source/macro.c new/source/macro.c if (prog == NULL) { if (errPos != NULL) { *errPos = stoppedAt; -@@ -1221,7 +1222,7 @@ void DoMacro(WindowInfo *window, const c +@@ -1222,7 +1223,7 @@ void DoMacro(WindowInfo *window, const c tMacro[macroLen+1] = '\0'; /* Parse the macro and report errors if it fails */ @@ -757,7 +757,7 @@ diff --quilt old/source/macro.c new/source/macro.c if (prog == NULL) { ParseError(window->shell, tMacro, stoppedAt, errInName, errMsg); XtFree(tMacro); -@@ -1485,7 +1486,7 @@ selEnd += $text_length - startLength\n}\ +@@ -1486,7 +1487,7 @@ selEnd += $text_length - startLength\n}\ sprintf(loopedCmd, loopMacro, how, command); /* Parse the resulting macro into an executable program "prog" */ @@ -797,7 +797,7 @@ diff --quilt old/source/parse.h new/source/parse.h diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -628,10 +628,12 @@ blank: /* nothing */ +@@ -632,10 +632,12 @@ blank: /* nothing */ ** as a pointer to a static string in msg, and the length of the string up ** to where parsing failed in stoppedAt. */ @@ -811,7 +811,7 @@ diff --quilt old/source/parse.y new/source/parse.y #if YYDEBUG int oldyydebug = yydebug; -@@ -666,6 +668,12 @@ Program *ParseMacro(char *expr, char **m +@@ -670,6 +672,12 @@ Program *ParseMacro(char *expr, char **m prog = FinishCreatingProgram(acc); XtFree((char *)acc); diff --git a/MultipleAssignment.diff b/MultipleAssignment.diff index 8bf7ff8..6ffcc5f 100644 --- a/MultipleAssignment.diff +++ b/MultipleAssignment.diff @@ -143,7 +143,7 @@ diff --quilt old/source/macro.c new/source/macro.c { "length", lengthMS }, { "get_range", getRangeMS }, { "t_print", tPrintMS }, -@@ -1812,6 +1818,76 @@ static int escapedStringLength(char *str +@@ -1813,6 +1819,76 @@ static int escapedStringLength(char *str } /* @@ -247,7 +247,7 @@ diff --quilt old/source/parse.y new/source/parse.y struct { AccumulatorData *acc; Symbol *sym; -@@ -104,6 +114,7 @@ static int nextSymIsField = 0; +@@ -105,6 +115,7 @@ static int nextSymIsField = 0; %type operassign incrdecr %token '=' ADDEQ SUBEQ MULEQ DIVEQ MODEQ ANDEQ OREQ %token INCR DECR @@ -255,7 +255,7 @@ diff --quilt old/source/parse.y new/source/parse.y %nonassoc IF_NO_ELSE %nonassoc ELSE -@@ -326,6 +337,120 @@ simpstmt: /* simple variable assignmen +@@ -328,6 +339,120 @@ simpstmt: /* simple variable assignmen ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); } | funccall diff --git a/OP_FUNCTION.patch b/OP_FUNCTION.patch deleted file mode 100644 index c5616eb..0000000 --- a/OP_FUNCTION.patch +++ /dev/null @@ -1,541 +0,0 @@ ---- - - source/interpret.c | 129 +++++++++++++++++++++++++++-------------------------- - 1 file changed, 66 insertions(+), 63 deletions(-) - -diff --quilt old/source/interpret.c new/source/interpret.c ---- old/source/interpret.c -+++ new/source/interpret.c -@@ -84,7 +84,10 @@ static int addLoopAddr(Inst *addr, char - static void saveContext(RestartData *context); - static void restoreContext(RestartData *context); - --#define OP(name, fn) static int fn(void); -+/* the function prototype of a operand instruction */ -+#define OP_FUNCTION(op) static int op(void) -+ -+#define OP(name, fn) OP_FUNCTION(fn); - #include "ops.h" - #undef OP - static int returnValOrNone(int valOnStack); -@@ -190,7 +193,7 @@ static int PreemptRequest; /* pass - - /* Array for mapping operations to functions for performing the operations - Must correspond to the enum called "operations" in interpret.h */ --static int (*OpFns[])() = { -+OP_FUNCTION((*OpFns[])) = { - #define OP(name, fn) fn, - #include "ops.h" - #undef OP -@@ -1583,7 +1586,7 @@ static void addToGlobalSymTab(Symbol *sy - ** After: Prog-> Sym, [next], ... - ** TheStack-> [symVal], next, ... - */ --static int pushSymVal(void) -+OP_FUNCTION(pushSymVal) - { - Symbol *s; - int nArgs, argNum; -@@ -1640,7 +1643,7 @@ static int pushSymVal(void) - ** After: Prog-> immediate, [next], ... - ** TheStack-> [immediate], next, ... - */ --static int pushImmed(void) -+OP_FUNCTION(pushImmed) - { - int immed; - -@@ -1654,7 +1657,7 @@ static int pushImmed(void) - return STAT_OK; - } - --static int pushArgVal(void) -+OP_FUNCTION(pushArgVal) - { - int nArgs, argNum; - -@@ -1672,7 +1675,7 @@ static int pushArgVal(void) - return STAT_OK; - } - --static int pushArgCount(void) -+OP_FUNCTION(pushArgCount) - { - DISASM_RT(PC-1, 1); - STACKDUMP(0, 3); -@@ -1681,7 +1684,7 @@ static int pushArgCount(void) - return STAT_OK; - } - --static int pushArgArray(void) -+OP_FUNCTION(pushArgArray) - { - int nArgs, argNum; - DataValue argVal, *argArray; -@@ -1722,7 +1725,7 @@ static int pushArgArray(void) - ** makeEmpty is either true (1) or false (0): if true, and the element is not - ** present in the array, create it. - */ --static int pushArraySymVal(void) -+OP_FUNCTION(pushArraySymVal) - { - Symbol *sym; - DataValue *dataPtr; -@@ -1767,7 +1770,7 @@ static int pushArraySymVal(void) - ** After: Prog-> [next], ... - ** TheStack-> [empty-array, 0], next, ... - */ --static int anonArrayOpen(void) -+OP_FUNCTION(anonArrayOpen) - { - DataValue dataVal; - -@@ -1797,7 +1800,7 @@ static int anonArrayOpen(void) - ** After: Prog-> [next], ... - ** TheStack-> [anon-array, next-index+1], next, ... - */ --static int anonArraySkip(void) -+OP_FUNCTION(anonArraySkip) - { - DataValue anonArray; - int nextIndex; -@@ -1828,7 +1831,7 @@ static int anonArraySkip(void) - ** After: Prog-> [next], ... - ** TheStack-> [anon-array, next-index+1], next, ... - */ --static int anonArrayNextVal(void) -+OP_FUNCTION(anonArrayNextVal) - { - DataValue exprVal, anonArray; - int nextIndex; -@@ -1863,7 +1866,7 @@ static int anonArrayNextVal(void) - ** After: Prog-> nDim, [next], ... - ** TheStack-> [anon-array, new-next-index], next, ... - */ --static int anonArrayIndexVal(void) -+OP_FUNCTION(anonArrayIndexVal) - { - int errNum; - char *keyString = NULL; -@@ -1913,7 +1916,7 @@ static int anonArrayIndexVal(void) - ** After: Prog-> [next], ... - ** TheStack-> [anon-array], next, ... - */ --static int anonArrayClose(void) -+OP_FUNCTION(anonArrayClose) - { - DataValue anonArray; - DataValue next_index; -@@ -1939,7 +1942,7 @@ static int anonArrayClose(void) - ** After: Prog-> nDim, [next], ... - ** TheStack-> args, argN-arg1, next, ... - */ --static int namedArg1(void) -+OP_FUNCTION(namedArg1) - { - return namedArg1orN(True); - } -@@ -1953,7 +1956,7 @@ static int namedArg1(void) - ** After: Prog-> nDim, [next], ... - ** TheStack-> [args], argN-arg1, next, ... - */ --static int namedArgN() -+OP_FUNCTION(namedArgN) - { - return namedArg1orN(False); - } -@@ -2010,7 +2013,7 @@ static int namedArg1orN(Boolean isFirst) - /* - ** exchange top two values on the stack - */ --static int swapTop2(void) -+OP_FUNCTION(swapTop2) - { - DataValue dv1, dv2; - -@@ -2033,7 +2036,7 @@ static int swapTop2(void) - ** After: Prog-> symbol, [next], ... - ** TheStack-> next, ... - */ --static int assign(void) -+OP_FUNCTION(assign) - { - Symbol *sym; - DataValue *dataPtr; -@@ -2082,7 +2085,7 @@ static int assign(void) - ** After: Prog-> next, ... (unchanged) - ** TheStack-> [next], ... - */ --static int popStack(void) -+OP_FUNCTION(popStack) - { - DataValue val; - -@@ -2099,7 +2102,7 @@ static int popStack(void) - ** Before: TheStack-> value, next, ... - ** After: TheStack-> value, value, next, ... - */ --static int dupStack(void) -+OP_FUNCTION(dupStack) - { - DataValue value; - -@@ -2120,7 +2123,7 @@ static int dupStack(void) - ** Before: TheStack-> value2, value1, next, ... - ** After: TheStack-> resValue, next, ... - */ --static int add(void) -+OP_FUNCTION(add) - { - DataValue leftVal, rightVal, resultArray; - int n1, n2; -@@ -2192,7 +2195,7 @@ static int add(void) - ** Before: TheStack-> value2, value1, next, ... - ** After: TheStack-> resValue, next, ... - */ --static int subtract(void) -+OP_FUNCTION(subtract) - { - DataValue leftVal, rightVal, resultArray; - int n1, n2; -@@ -2260,12 +2263,12 @@ static int subtract(void) - ** Before: TheStack-> value, next, ... - ** After: TheStack-> resValue, next, ... - */ --static int multiply(void) -+OP_FUNCTION(multiply) - { - BINARY_NUMERIC_OPERATION(*); - } - --static int divide(void) -+OP_FUNCTION(divide) - { - int n1, n2; - -@@ -2281,7 +2284,7 @@ static int divide(void) - return STAT_OK; - } - --static int modulo(void) -+OP_FUNCTION(modulo) - { - int n1, n2; - -@@ -2297,37 +2300,37 @@ static int modulo(void) - return STAT_OK; - } - --static int negate(void) -+OP_FUNCTION(negate) - { - UNARY_NUMERIC_OPERATION(-); - } - --static int increment(void) -+OP_FUNCTION(increment) - { - UNARY_NUMERIC_OPERATION(++); - } - --static int decrement(void) -+OP_FUNCTION(decrement) - { - UNARY_NUMERIC_OPERATION(--); - } - --static int gt(void) -+OP_FUNCTION(gt) - { - BINARY_NUMERIC_OPERATION(>); - } - --static int lt(void) -+OP_FUNCTION(lt) - { - BINARY_NUMERIC_OPERATION(<); - } - --static int ge(void) -+OP_FUNCTION(ge) - { - BINARY_NUMERIC_OPERATION(>=); - } - --static int le(void) -+OP_FUNCTION(le) - { - BINARY_NUMERIC_OPERATION(<=); - } -@@ -2338,7 +2341,7 @@ static int le(void) - ** After: TheStack-> resValue, next, ... - ** where resValue is 1 for true, 0 for false - */ --static int eq(void) -+OP_FUNCTION(eq) - { - DataValue v1, v2; - -@@ -2380,7 +2383,7 @@ static int eq(void) - } - - /* negated eq() call */ --static int ne(void) -+OP_FUNCTION(ne) - { - eq(); - return not(); -@@ -2393,7 +2396,7 @@ static int ne(void) - ** Before: TheStack-> value2, value1, next, ... - ** After: TheStack-> resValue, next, ... - */ --static int bitAnd(void) -+OP_FUNCTION(bitAnd) - { - DataValue leftVal, rightVal, resultArray; - int n1, n2; -@@ -2453,7 +2456,7 @@ static int bitAnd(void) - ** Before: TheStack-> value2, value1, next, ... - ** After: TheStack-> resValue, next, ... - */ --static int bitOr(void) -+OP_FUNCTION(bitOr) - { - DataValue leftVal, rightVal, resultArray; - int n1, n2; -@@ -2517,17 +2520,17 @@ static int bitOr(void) - return(STAT_OK); - } - --static int and(void) -+OP_FUNCTION(and) - { - BINARY_NUMERIC_OPERATION(&&); - } - --static int or(void) -+OP_FUNCTION(or) - { - BINARY_NUMERIC_OPERATION(||); - } - --static int not(void) -+OP_FUNCTION(not) - { - UNARY_NUMERIC_OPERATION(!); - } -@@ -2537,7 +2540,7 @@ static int not(void) - ** Before: TheStack-> raisedBy, number, next, ... - ** After: TheStack-> result, next, ... - */ --static int power(void) -+OP_FUNCTION(power) - { - int n1, n2, n3; - -@@ -2656,7 +2659,7 @@ static int concatenateNwithSep(int nVals - ** After: Prog-> nExpr, [next], ... - ** TheStack-> concatResult, next, ... - */ --static int concat(void) -+OP_FUNCTION(concat) - { - char *out; - int len; -@@ -2830,7 +2833,7 @@ static int callSubroutineFromSymbol(Symb - ** or: Prog-> (in called)next, ... -- (macro code called subr) - ** Stack-> symN-sym1(FP), nArgs, oldFP, retPC, argArray, argN-arg1, next, ... - */ --static int callSubroutine(void) -+OP_FUNCTION(callSubroutine) - { - Symbol *sym; - int nArgs; -@@ -2853,7 +2856,7 @@ static int callSubroutine(void) - ** or: Prog-> (in called)next, ... -- (macro code called subr) - ** Stack-> symN-sym1(FP), nArgs, oldFP, retPC, argArray, argN-arg1, next, ... - */ --static int callSubroutineStackedN(void) -+OP_FUNCTION(callSubroutineStackedN) - { - Symbol *sym; - int nArgs; -@@ -2966,7 +2969,7 @@ int OverlayRoutineFromProg(Program *prog - ** After: Prog-> next, ... - ** TheStack-> -(nArgs+1), argArray, argN-arg1, next, ... - */ --static int unpackArrayToArgs(void) -+OP_FUNCTION(unpackArrayToArgs) - { - int nArgs, i, res, haveNamedArgs; - SparseArrayEntry *iter; -@@ -3033,17 +3036,17 @@ static int unpackArrayToArgs(void) - ** instruction at the PC to decide whether to push the function's return - ** value, then skips over it without executing. - */ --static int fetchRetVal(void) -+OP_FUNCTION(fetchRetVal) - { - return execError("internal error: frv", NULL); - } - - /* see comments for returnValOrNone() */ --static int returnNoVal(void) -+OP_FUNCTION(returnNoVal) - { - return returnValOrNone(False); - } --static int returnVal(void) -+OP_FUNCTION(returnVal) - { - return returnValOrNone(True); - } -@@ -3086,7 +3089,7 @@ static int returnValOrNone(int valOnStac - ** Before: Prog-> [branchDest], next, ..., (branchdest)next - ** After: Prog-> branchDest, next, ..., (branchdest)[next] - */ --static int branch(void) -+OP_FUNCTION(branch) - { - Inst *addr; - -@@ -3107,11 +3110,11 @@ static int branch(void) - ** After: either: Prog-> branchDest, [next], ... - ** After: or: Prog-> branchDest, next, ..., (branchdest)[next] - */ --static int branchTrue(void) -+OP_FUNCTION(branchTrue) - { - return branchIf(True); - } --static int branchFalse(void) -+OP_FUNCTION(branchFalse) - { - return branchIf(False); - } -@@ -3140,7 +3143,7 @@ static int branchIf(Boolean trueOrFalse) - ** Before: Prog-> [branchDest], next, ... - ** After: Prog-> branchDest, [next], ... - */ --static int branchNever(void) -+OP_FUNCTION(branchNever) - { - Inst *addr; - -@@ -3502,7 +3505,7 @@ static int arrayMaxNumIdx(DataValue *the - ** After: Prog-> nDim, [next], ... - ** TheStack-> indexedArrayVal, next, ... - */ --static int arrayRef(void) -+OP_FUNCTION(arrayRef) - { - int errNum; - DataValue srcArray, valueItem; -@@ -3552,7 +3555,7 @@ static int arrayRef(void) - ** After: Prog-> nDim, [next], ... - ** TheStack-> next, ... - */ --static int arrayAssign(void) -+OP_FUNCTION(arrayAssign) - { - char *keyString = NULL; - DataValue srcValue, dstArray; -@@ -3604,7 +3607,7 @@ static int arrayAssign(void) - ** After: Prog-> binOp, nDim, [next], ... - ** TheStack-> [rhs], arrayValue, ArraySym, next, ... - */ --static int arrayRefAndAssignSetup(void) -+OP_FUNCTION(arrayRefAndAssignSetup) - { - int errNum; - DataValue srcArray, valueItem, moveExpr; -@@ -3659,7 +3662,7 @@ static int arrayRefAndAssignSetup(void) - ** the stack frame - ** arrayVal is the data value holding the array in question - */ --static int beginArrayIter(void) -+OP_FUNCTION(beginArrayIter) - { - Symbol *iterator; - DataValue *iteratorValPtr; -@@ -3712,7 +3715,7 @@ static int beginArrayIter(void) - ** The return-to-start-of-loop branch (at the end of the loop) should address - ** the ARRAY_ITER instruction - */ --static int arrayIter(void) -+OP_FUNCTION(arrayIter) - { - Symbol *iterator; - Symbol *keySym; -@@ -3793,7 +3796,7 @@ static int arrayIter(void) - ** After: Prog-> iter, [ARRAY_MULTI_ITER_ARRAY], withVal, keyArraySym(, valSym), iter, endLoopBranch, next, ... - ** TheStack-> [nDims], next, ... - */ --static int beginArrayMultiIterArray(void) -+OP_FUNCTION(beginArrayMultiIterArray) - { - Symbol *iterator; - DataValue *iteratorValPtr; -@@ -3888,7 +3891,7 @@ static Boolean splitKeyIntoArray(const c - ** After: Prog-> iter, ARRAY_MULTI_ITER_ARRAY, withVal, keyArraySym, (, valSym), iter, endLoopBranch, [next], ... - ** TheStack-> [nDims], next, ... (unchanged) - */ --static int arrayMultiIterArray(void) -+OP_FUNCTION(arrayMultiIterArray) - { - Symbol *iterator; - Symbol *keyArraySym; -@@ -3998,7 +4001,7 @@ static int arrayMultiIterArray(void) - ** After: Prog-> [next], ... -- (unchanged) - ** TheStack-> next, ... - */ --static int inArray(void) -+OP_FUNCTION(inArray) - { - DataValue theArray, leftArray, theValue; - char *keyStr; -@@ -4042,7 +4045,7 @@ static int inArray(void) - ** After: Prog-> nDim, [next], ... - ** TheStack-> next, ... - */ --static int deleteArrayElement(void) -+OP_FUNCTION(deleteArrayElement) - { - DataValue theArray; - char *keyString = NULL; -@@ -4077,7 +4080,7 @@ static int deleteArrayElement(void) - return(STAT_OK); - } - --static int typeOfIn(void) -+OP_FUNCTION(typeOfIn) - { - if (inTypeOfMode) { - return(execError("I'm already in typeof-mode", NULL)); -@@ -4088,7 +4091,7 @@ static int typeOfIn(void) - return STAT_OK; - } - --static int typeOfOut(void) -+OP_FUNCTION(typeOfOut) - { - DataValue val; - DataValue retVal; -@@ -4135,7 +4138,7 @@ static int typeOfOut(void) - ** After: Prog-> next, ... (unchanged) - ** TheStack-> next, ... - */ --static int arrayAssignNext(void) -+OP_FUNCTION(arrayAssignNext) - { - char *keyString = NULL; - DataValue srcValue, dstArray; -@@ -4178,7 +4181,7 @@ static int arrayAssignNext(void) - ** After: Prog-> next, ... (unchanged) - ** TheStack-> numIdx, next, ... - */ --static int arrayNextNumIdx(void) -+OP_FUNCTION(arrayNextNumIdx) - { - DataValue srcArray; - SparseArrayEntry *iter; diff --git a/ParseFields3.diff b/ParseFields3.diff index 8e8a239..f12c675 100644 --- a/ParseFields3.diff +++ b/ParseFields3.diff @@ -49,7 +49,7 @@ diff --quilt old/source/parse.y new/source/parse.y %token NUMBER %token DELETE ARG_LOOKUP %token IF WHILE ELSE FOR BREAK CONTINUE RETURN DEFINE -@@ -113,6 +117,7 @@ static int AllowDefine; +@@ -114,6 +118,7 @@ static int AllowDefine; %nonassoc DELETE %nonassoc INCR DECR %right POW @@ -57,7 +57,7 @@ diff --quilt old/source/parse.y new/source/parse.y %nonassoc '[' %nonassoc '(' -@@ -254,6 +259,10 @@ simpstmt: SYMBOL '=' expr { +@@ -258,6 +263,10 @@ simpstmt: SYMBOL '=' expr { | DELETE arraylv '[' arglist ']' { ADD_OP(OP_ARRAY_DELETE); ADD_IMMED($4); } @@ -68,7 +68,7 @@ diff --quilt old/source/parse.y new/source/parse.y | initarraylv '[' arglist ']' '=' expr { ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3); } -@@ -312,6 +321,65 @@ simpstmt: SYMBOL '=' expr { +@@ -316,6 +325,65 @@ simpstmt: SYMBOL '=' expr { ADD_OP(OP_DECR); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($4); } @@ -134,7 +134,7 @@ diff --quilt old/source/parse.y new/source/parse.y | SYMBOL '(' arglist ')' { ADD_OP(OP_SUBR_CALL); ADD_SYM(PromoteToGlobal($1)); ADD_IMMED($3); -@@ -379,6 +447,9 @@ initarraylv: SYMBOL { +@@ -383,6 +451,9 @@ initarraylv: SYMBOL { | initarraylv '[' arglist ']' { ADD_OP(OP_ARRAY_REF); ADD_IMMED($3); } @@ -144,7 +144,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); -@@ -386,7 +457,21 @@ arraylv: SYMBOL { +@@ -390,7 +461,21 @@ arraylv: SYMBOL { | arraylv '[' arglist ']' { ADD_OP(OP_ARRAY_REF); ADD_IMMED($3); } @@ -166,7 +166,7 @@ diff --quilt old/source/parse.y new/source/parse.y arrayexpr: numexpr { $$ = GetPC(); } -@@ -418,6 +503,9 @@ numexpr: NUMBER { +@@ -422,6 +507,9 @@ numexpr: NUMBER { | numexpr '[' arglist ']' { ADD_OP(OP_ARRAY_REF); ADD_IMMED($3); } @@ -176,7 +176,7 @@ diff --quilt old/source/parse.y new/source/parse.y | numexpr '+' numexpr { ADD_OP(OP_ADD); } -@@ -521,6 +609,10 @@ or: OR { +@@ -525,6 +613,10 @@ or: OR { ADD_BR_OFF(0); } ; @@ -187,7 +187,7 @@ diff --quilt old/source/parse.y new/source/parse.y blank: /* nothing */ | blank '\n' ; -@@ -551,6 +643,8 @@ Program *ParseMacro(char *expr, char **m +@@ -555,6 +647,8 @@ Program *ParseMacro(char *expr, char **m /* whether we allow the "define" keyword */ AllowDefine = allowDefine; @@ -196,7 +196,7 @@ diff --quilt old/source/parse.y new/source/parse.y /* call yyparse to parse the string and check for success. If the parse failed, return the error message and string index (the grammar aborts parsing at the first error) */ -@@ -625,6 +719,7 @@ static int yylex(void) +@@ -629,6 +723,7 @@ static int yylex(void) if (isdigit((unsigned char)*InPtr)) { /* number */ sscanf(InPtr, "%d%n", &yylval.num, &len); InPtr += len; @@ -204,7 +204,7 @@ diff --quilt old/source/parse.y new/source/parse.y return NUMBER; } -@@ -653,6 +748,11 @@ static int yylex(void) +@@ -657,6 +752,11 @@ static int yylex(void) if (!strcmp(symName, "$args")) return ARG_LOOKUP; if (!strcmp(symName, "delete") && follow_non_whitespace('(', SYMBOL, DELETE) == DELETE) return DELETE; if (!strcmp(symName, "define")) return DEFINE; @@ -216,7 +216,7 @@ diff --quilt old/source/parse.y new/source/parse.y if ((s=LookupSymbol(symName)) == NULL) { s = InstallSymbol(symName, symName[0]=='$' ? (((symName[1] > '0' && symName[1] <= '9') && symName[2] == 0) ? -@@ -663,6 +763,7 @@ static int yylex(void) +@@ -667,6 +767,7 @@ static int yylex(void) yylval.sym = s; return SYMBOL; } diff --git a/RSunderlineStyle.diff b/RSunderlineStyle.diff index 1f2065b..85b50b9 100644 --- a/RSunderlineStyle.diff +++ b/RSunderlineStyle.diff @@ -61,7 +61,7 @@ diff --quilt old/source/macro.c new/source/macro.c { "rangeset_set_name", rangesetSetNameMS }, { "rangeset_set_mode", rangesetSetModeMS }, { "rangeset_get_by_name", rangesetGetByNameMS }, -@@ -5798,7 +5801,7 @@ static int rangesetInfoMS(WindowInfo *wi +@@ -5799,7 +5802,7 @@ static int rangesetInfoMS(WindowInfo *wi { RangesetTable *rangesetTable = window->buffer->rangesetTable; Rangeset *rangeset = NULL; @@ -70,7 +70,7 @@ diff --quilt old/source/macro.c new/source/macro.c char *color, *name, *mode; DataValue element; int label = 0; -@@ -5815,7 +5818,8 @@ static int rangesetInfoMS(WindowInfo *wi +@@ -5816,7 +5819,8 @@ static int rangesetInfoMS(WindowInfo *wi rangeset = RangesetFetch(rangesetTable, label); } @@ -80,7 +80,7 @@ diff --quilt old/source/macro.c new/source/macro.c /* set up result */ result->tag = ARRAY_TAG; -@@ -5849,7 +5853,15 @@ static int rangesetInfoMS(WindowInfo *wi +@@ -5850,7 +5854,15 @@ static int rangesetInfoMS(WindowInfo *wi M_FAILURE("Failed to allocate array value \"mode\" in %s"); if (!ArrayInsert(result, PERM_ALLOC_STR("mode"), &element)) M_FAILURE("Failed to insert array element \"mode\" in %s"); @@ -97,7 +97,7 @@ diff --quilt old/source/macro.c new/source/macro.c return True; } -@@ -6022,6 +6034,60 @@ static int rangesetSetColorMS(WindowInfo +@@ -6023,6 +6035,60 @@ static int rangesetSetColorMS(WindowInfo } /* diff --git a/SUBR_TAG.patch b/SUBR_TAG.patch index 1a44346..b7b8f4b 100644 --- a/SUBR_TAG.patch +++ b/SUBR_TAG.patch @@ -118,7 +118,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } retVal.val.str.len = strlen(retVal.val.str.rep); -@@ -4146,12 +4171,39 @@ static const char *tagToStr(enum typeTag +@@ -4170,12 +4195,39 @@ static const char *tagToStr(enum typeTag return ""; case ARRAY_TAG: return ""; @@ -158,7 +158,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; -@@ -4270,6 +4322,9 @@ static void dumpVal(DataValue dv) +@@ -4294,6 +4346,9 @@ static void dumpVal(DataValue dv) case ARRAY_TAG: printd(" %8p[%d]", dv.val.arrayPtr, ArraySize(&dv)); break; @@ -191,7 +191,7 @@ diff --quilt old/source/interpret.h new/source/interpret.h diff --quilt old/source/macro.c new/source/macro.c --- old/source/macro.c +++ new/source/macro.c -@@ -3804,27 +3804,35 @@ static int filenameDialogMS(WindowInfo* +@@ -3805,27 +3805,35 @@ static int filenameDialogMS(WindowInfo* static int callMS(WindowInfo *window, DataValue *argList, int nArgs, DataValue *result, char **errMsg) { @@ -233,7 +233,7 @@ diff --quilt old/source/macro.c new/source/macro.c */ static int defineMS(WindowInfo *window, DataValue *argList, int nArgs, DataValue *result, char **errMsg) -@@ -3838,7 +3846,6 @@ static int defineMS(WindowInfo *window, +@@ -3839,7 +3847,6 @@ static int defineMS(WindowInfo *window, char *override = NULL; Program *prog; Symbol *sym; @@ -241,7 +241,7 @@ diff --quilt old/source/macro.c new/source/macro.c if (nArgs < 2 || nArgs > 3) { return wrongNArgsErr(errMsg); -@@ -3908,11 +3915,15 @@ static int defineMS(WindowInfo *window, +@@ -3909,11 +3916,15 @@ static int defineMS(WindowInfo *window, sym->value.val.prog = prog; } } else { diff --git a/UnderlineStyle.diff b/UnderlineStyle.diff index 0f8be37..d06dbb6 100644 --- a/UnderlineStyle.diff +++ b/UnderlineStyle.diff @@ -190,7 +190,7 @@ diff --quilt old/source/highlightData.h new/source/highlightData.h diff --quilt old/source/macro.c new/source/macro.c --- old/source/macro.c +++ new/source/macro.c -@@ -6026,7 +6026,8 @@ static int rangesetSetModeMS(WindowInfo +@@ -6027,7 +6027,8 @@ static int rangesetSetModeMS(WindowInfo ** ["color"] Foreground color name of style ** ["background"] Background color name of style if specified ** ["bold"] '1' if style is bold, '0' otherwise @@ -200,7 +200,7 @@ diff --quilt old/source/macro.c new/source/macro.c ** Given position and pattern code we obtain: ** ["rgb"] RGB representation of foreground color of style ** ["back_rgb"] RGB representation of background color of style -@@ -6120,6 +6121,12 @@ static int fillStyleResult(DataValue *re +@@ -6121,6 +6122,12 @@ static int fillStyleResult(DataValue *re M_ARRAY_INSERT_FAILURE(); } diff --git a/abstract-access-to-FrameP.patch b/abstract-access-to-FrameP.patch index c654069..d034ba4 100644 --- a/abstract-access-to-FrameP.patch +++ b/abstract-access-to-FrameP.patch @@ -6,7 +6,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -1386,6 +1386,17 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1388,6 +1388,17 @@ static void addToGlobalSymTab(Symbol *sy } \ } while (0) @@ -24,7 +24,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) -@@ -1551,11 +1562,11 @@ static int pushSymVal(void) +@@ -1553,11 +1564,11 @@ static int pushSymVal(void) GET_SYM(s); if (s->type == LOCAL_SYM) { @@ -38,7 +38,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c argNum = s->value.val.n; if (argNum >= nArgs) { return execError("referenced undefined argument: %s", s->name); -@@ -1565,7 +1576,7 @@ static int pushSymVal(void) +@@ -1567,7 +1578,7 @@ static int pushSymVal(void) symVal.val.n = nArgs; } else { @@ -47,7 +47,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } else if (s->type == PROC_VALUE_SYM) { char *errMsg; -@@ -1619,12 +1630,12 @@ static int pushArgVal(void) +@@ -1621,12 +1632,12 @@ static int pushArgVal(void) POP_INT(argNum); --argNum; @@ -62,7 +62,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -1633,7 +1644,7 @@ static int pushArgCount(void) +@@ -1635,7 +1646,7 @@ static int pushArgCount(void) DISASM_RT(PC-1, 1); STACKDUMP(0, 3); @@ -71,7 +71,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -1646,8 +1657,8 @@ static int pushArgArray(void) +@@ -1648,8 +1659,8 @@ static int pushArgArray(void) DISASM_RT(PC-1, 1); STACKDUMP(0, 3); @@ -82,7 +82,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (argArray->tag != ARRAY_TAG) { /* we require a real array in the argArray position */ argArray->tag = ARRAY_TAG; -@@ -1658,7 +1669,7 @@ static int pushArgArray(void) +@@ -1660,7 +1671,7 @@ static int pushArgArray(void) if (needArgCopy || (nArgs && !ArrayGet(argArray, (char *)"1", &argVal))) { /* load arguments from positional arg list if not already done */ for (argNum = 0; argNum < nArgs; ++argNum) { @@ -91,7 +91,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (!ArrayInsert(argArray, AllocStringOfNumber(argNum + 1), &argVal)) { return(execError("argument array insertion failure", NULL)); -@@ -1691,7 +1702,7 @@ static int pushArraySymVal(void) +@@ -1693,7 +1704,7 @@ static int pushArraySymVal(void) GET_IMMED(initEmpty); if (sym->type == LOCAL_SYM) { @@ -100,7 +100,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else if (sym->type == GLOBAL_SYM) { dataPtr = &sym->value; -@@ -2013,7 +2024,7 @@ static int assign(void) +@@ -2015,7 +2026,7 @@ static int assign(void) } if (sym->type == LOCAL_SYM) { @@ -109,7 +109,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else { dataPtr = &sym->value; -@@ -2675,7 +2686,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2677,7 +2688,7 @@ static int callSubroutineFromSymbol(Symb } if (sym->type == LOCAL_SYM) { @@ -118,7 +118,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else if (sym->type == GLOBAL_SYM) { symValPtr = &sym->value; } -@@ -3014,7 +3025,7 @@ static int returnValOrNone(int valOnStac +@@ -3016,7 +3027,7 @@ static int returnValOrNone(int valOnStac static DataValue noValue = {NO_TAG, {0}}; DISASM_RT(PC-1, 1); @@ -127,7 +127,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* return value is on the stack */ if (valOnStack) { -@@ -3626,7 +3637,7 @@ static int beginArrayIter(void) +@@ -3628,7 +3639,7 @@ static int beginArrayIter(void) POP(arrayVal); if (iterator->type == LOCAL_SYM) { @@ -136,7 +136,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else { return(execError("bad temporary iterator: %s", iterator->name)); -@@ -3689,7 +3700,7 @@ static int arrayIter(void) +@@ -3691,7 +3702,7 @@ static int arrayIter(void) GET_BRANCH(branchAddr); if (keySym->type == LOCAL_SYM) { @@ -145,7 +145,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else if (keySym->type == GLOBAL_SYM) { keyValPtr = &(keySym->value); -@@ -3701,7 +3712,7 @@ static int arrayIter(void) +@@ -3703,7 +3714,7 @@ static int arrayIter(void) if (withVal) { if (valSym->type == LOCAL_SYM) { @@ -154,7 +154,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else if (valSym->type == GLOBAL_SYM) { valPtr = &(valSym->value); -@@ -3713,7 +3724,7 @@ static int arrayIter(void) +@@ -3715,7 +3726,7 @@ static int arrayIter(void) } if (iterator->type == LOCAL_SYM) { @@ -163,7 +163,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else { return(execError("bad temporary iterator: %s", iterator->name)); -@@ -3762,7 +3773,7 @@ static int beginArrayMultiIterArray(void +@@ -3764,7 +3775,7 @@ static int beginArrayMultiIterArray(void PEEK_INT(nDims, 0); if (iterator->type == LOCAL_SYM) { @@ -172,7 +172,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else { return(execError("bad temporary iterator: %s", iterator->name)); -@@ -3869,7 +3880,7 @@ static int arrayMultiIterArray(void) +@@ -3871,7 +3882,7 @@ static int arrayMultiIterArray(void) PEEK_INT(nDims, 0); if (keyArraySym->type == LOCAL_SYM) { @@ -181,7 +181,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else if (keyArraySym->type == GLOBAL_SYM) { keyArrayPtr = &(keyArraySym->value); -@@ -3882,7 +3893,7 @@ static int arrayMultiIterArray(void) +@@ -3884,7 +3895,7 @@ static int arrayMultiIterArray(void) if (withVal) { if (valSym->type == LOCAL_SYM) { @@ -190,7 +190,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else if (valSym->type == GLOBAL_SYM) { valPtr = &valSym->value; -@@ -3894,7 +3905,7 @@ static int arrayMultiIterArray(void) +@@ -3896,7 +3907,7 @@ static int arrayMultiIterArray(void) } if (iterator->type == LOCAL_SYM) { diff --git a/abstract-access-to-PC.patch b/abstract-access-to-PC.patch dissimilarity index 75% index 2efa3ae..4e66d10 100644 --- a/abstract-access-to-PC.patch +++ b/abstract-access-to-PC.patch @@ -1,979 +1,397 @@ ---- - - source/interpret.c | 430 ++++++++++++++++++++++++++++++++--------------------- - source/interpret.h | 23 +- - source/parse.y | 36 +++- - 3 files changed, 301 insertions(+), 188 deletions(-) - -diff --quilt old/source/interpret.c new/source/interpret.c ---- old/source/interpret.c -+++ new/source/interpret.c -@@ -80,7 +80,7 @@ static const char CVSID[] = "$Id: interp - - enum opStatusCodes {STAT_OK=2, STAT_DONE, STAT_ERROR, STAT_PREEMPT}; - --static void addLoopAddr(Inst *addr); -+static int addLoopAddr(Inst *addr, char **msg); - static void saveContext(RestartData *context); - static void restoreContext(RestartData *context); - -@@ -113,6 +113,7 @@ static int inTypeOfMode; - - static const char *tagToStr(enum typeTags tag); - static const char *typeToStr(enum symTypes type); -+static const char *instTypeToStr(enum instTypes type); - - /*#define DEBUG_ASSEMBLY*/ - /*#define DEBUG_STACK*/ -@@ -336,7 +337,8 @@ int AddOp(int op, char **msg) - *msg = "macro too large"; - return 0; - } -- ProgP->op = op; -+ ProgP->type = OP_INST; -+ ProgP->val.op = op; - ProgP++; - return 1; - } -@@ -351,7 +353,8 @@ int AddSym(Symbol *sym, char **msg) - return 0; - } - sym->added = 1; -- ProgP->sym = sym; -+ ProgP->type = SYM_INST; -+ ProgP->val.sym = sym; - ProgP++; - return 1; - } -@@ -359,13 +362,14 @@ int AddSym(Symbol *sym, char **msg) - /* - ** Add an immediate value operand to the current program - */ --int AddImmediate(int value, char **msg) -+int AddImmediate(int immed, char **msg) - { - if (ProgP >= &Prog[PROGRAM_SIZE]) { - *msg = "macro too large"; - return 0; - } -- ProgP->value = value; -+ ProgP->type = IMMED_INST; -+ ProgP->val.immed = immed; - ProgP++; - return 1; - } -@@ -379,14 +383,28 @@ int AddBranchOffset(Inst *to, char **msg - *msg = "macro too large"; - return 0; - } -- /* Should be ptrdiff_t for branch offsets */ -- ProgP->value = to - ProgP; -+ ProgP->type = BRANCH_INST; -+ ProgP->val.branch = to - ProgP; - ProgP++; - - return 1; - } - - /* -+** Set a branch offset to an operand previously added with AddBranchOffset() -+*/ -+int SetBranchOffset(Inst *from, Inst *to, char **msg) -+{ -+ if (from->type != BRANCH_INST) { -+ *msg = "not a branch instruction"; -+ return 0; -+ } -+ from->val.branch = to - from; -+ -+ return 1; -+} -+ -+/* - ** Return the address at which the next instruction will be stored - */ - Inst *GetPC(void) -@@ -423,34 +441,53 @@ 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. - */ --void StartLoopAddrList(void) -+int StartLoopAddrList(char **msg) - { -- addLoopAddr(NULL); -+ return addLoopAddr(NULL, msg); - } - --int AddBreakAddr(Inst *addr) -+int AddBreakAddr(Inst *addr, char **msg) - { -- if (LoopStackPtr == LoopStack) return 1; -- addLoopAddr(addr); -- addr->value = NEEDS_BREAK; -- return 0; -+ if (LoopStackPtr == LoopStack) { -+ *msg = "break outside loop"; -+ return 0; -+ } -+ if (addr->type != BRANCH_INST) { -+ *msg = "not a branch instruction for break"; -+ return 0; -+ } -+ if (!addLoopAddr(addr, msg)) { -+ return 0; -+ } -+ addr->val.immed = NEEDS_BREAK; -+ return 1; - } - --int AddContinueAddr(Inst *addr) --{ -- if (LoopStackPtr == LoopStack) return 1; -- addLoopAddr(addr); -- addr->value = NEEDS_CONTINUE; -- return 0; -+int AddContinueAddr(Inst *addr, char **msg) -+{ -+ if (LoopStackPtr == LoopStack) { -+ *msg = "continue outside loop"; -+ return 0; -+ } -+ if (addr->type != BRANCH_INST) { -+ *msg = "not a branch instruction for continue"; -+ return 0; -+ } -+ if (!addLoopAddr(addr, msg)) { -+ return 0; -+ } -+ addr->val.immed = NEEDS_CONTINUE; -+ return 1; - } - --static void addLoopAddr(Inst *addr) -+static int addLoopAddr(Inst *addr, char **msg) - { -- if (LoopStackPtr > &LoopStack[LOOP_STACK_SIZE-1]) { -- fprintf(stderr, "NEdit: loop stack overflow in macro parser"); -- return; -+ if (LoopStackPtr >= &LoopStack[LOOP_STACK_SIZE]) { -+ *msg = "loop stack overflow"; -+ return 0; - } - *LoopStackPtr++ = addr; -+ return 1; - } - - void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr) -@@ -463,10 +500,10 @@ void FillLoopAddrs(Inst *breakAddr, Inst - } - if (*LoopStackPtr == NULL) - break; -- if ((*LoopStackPtr)->value == NEEDS_BREAK) -- (*LoopStackPtr)->value = breakAddr - *LoopStackPtr; -- else if ((*LoopStackPtr)->value == NEEDS_CONTINUE) -- (*LoopStackPtr)->value = continueAddr - *LoopStackPtr; -+ if ((*LoopStackPtr)->val.immed == NEEDS_BREAK) -+ (*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"); - } -@@ -638,14 +675,20 @@ int ContinueMacro(RestartData *continuat - - /* Execute an instruction */ - inst = PC++; -- switch (inst->op) { -+ if (inst->type != OP_INST) { -+ status = execError("Unexpected instruction of type %s", -+ instTypeToStr(inst->type)); -+ } -+ else { -+ switch (inst->val.op) { - #define OP(name, fn) case OP_##name: - #include "ops.h" - #undef OP -- status = (OpFns[inst->op])(); -- break; -- default: -- status = execError("Illegal instruction at %8p", (char *)inst); -+ status = (OpFns[inst->val.op])(); -+ break; -+ default: -+ status = execError("Illegal instruction at %8p", (char *)inst); -+ } - } - - /* If error return was not STAT_OK, return to caller */ -@@ -721,7 +764,7 @@ void PreemptMacro(void) - */ - void ModifyReturnedValue(RestartData *context, DataValue dv) - { -- if ((context->pc-1)->op == OP_FETCH_RET_VAL) -+ if ((context->pc-1)->val.op == OP_FETCH_RET_VAL) - *(context->stackP-1) = dv; - } - -@@ -1299,6 +1342,50 @@ static void addToGlobalSymTab(Symbol *sy - GlobalSymTab[idx] = sym; - } - -+#define GET_SYM(s) \ -+ do { \ -+ if (PC->type != SYM_INST) { \ -+ return execError("Unexpected instruction, expected : %s", \ -+ instTypeToStr(PC->type)); \ -+ } \ -+ s = PC++->val.sym; \ -+ } while (0) -+ -+#define GET_IMMED(i) \ -+ do { \ -+ if (PC->type != IMMED_INST) { \ -+ return execError("Unexpected instruction, expected : %s", \ -+ instTypeToStr(PC->type)); \ -+ } \ -+ i = PC++->val.immed; \ -+ } while (0) -+ -+#define GET_BRANCH(a) \ -+ do { \ -+ if (PC->type != BRANCH_INST) { \ -+ return execError("Unexpected instruction, expected : %s", \ -+ instTypeToStr(PC->type)); \ -+ } \ -+ a = PC + PC->val.branch; \ -+ PC++; \ -+ } while (0) -+ -+#define JUMP(a) \ -+ do { \ -+ PC = (a); \ -+ } while (0) -+ -+#define PUSH_RET_VAL(dv) \ -+ do { \ -+ if (PC == NULL) { \ -+ PUSH(dv); \ -+ } \ -+ else if (PC->type == OP_INST && PC->val.op == OP_FETCH_RET_VAL) { \ -+ PUSH(dv); \ -+ PC++; \ -+ } \ -+ } while (0) -+ - /* true, if you can pop n values */ - #define OK_TO_POP(n) \ - ((StackP - (n)) >= TheStack) -@@ -1461,8 +1548,7 @@ static int pushSymVal(void) - DISASM_RT(PC-1, 2); - STACKDUMP(0, 3); - -- s = PC->sym; -- PC++; -+ GET_SYM(s); - - if (s->type == LOCAL_SYM) { - symVal = FP_GET_SYM_VAL(FrameP, s); -@@ -1517,8 +1603,7 @@ static int pushImmed(void) - DISASM_RT(PC-1, 2); - STACKDUMP(0, 3); - -- immed = PC->value; -- PC++; -+ GET_IMMED(immed); - - PUSH_INT(immed); - -@@ -1602,10 +1687,8 @@ static int pushArraySymVal(void) - DISASM_RT(PC-1, 3); - STACKDUMP(0, 3); - -- sym = PC->sym; -- PC++; -- initEmpty = PC->value; -- PC++; -+ GET_SYM(sym); -+ GET_IMMED(initEmpty); - - if (sym->type == LOCAL_SYM) { - dataPtr = &FP_GET_SYM_VAL(FrameP, sym); -@@ -1744,8 +1827,7 @@ static int anonArrayIndexVal(void) - int nextIndex, index; - int nDim; - -- nDim = PC->value; -- PC++; -+ GET_IMMED(nDim); - - DISASM_RT(PC-2, 2); - STACKDUMP(nDim+3, 3); -@@ -1842,7 +1924,7 @@ static int namedArg1orN(Boolean isFirst) - DataValue exprVal, argsArray; - int nDim, index; - -- nDim = (PC++)->value; -+ GET_IMMED(nDim); - - DISASM_RT(PC-2, 2); - STACKDUMP(nDim + (isFirst ? 2 : 1), 3); -@@ -1916,8 +1998,7 @@ static int assign(void) - DISASM_RT(PC-1, 2); - STACKDUMP(1, 3); - -- sym = PC->sym; -- PC++; -+ GET_SYM(sym); - - if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) { - if (sym->type == ARG_SYM) { -@@ -2538,8 +2619,7 @@ static int concat(void) - - int nExpr; - -- nExpr = PC->value; -- PC++; -+ GET_IMMED(nExpr); - - DISASM_RT(PC-2, 2); - STACKDUMP(nExpr, 3); -@@ -2623,10 +2703,7 @@ static int callSubroutineFromSymbol(Symb - if (!sym->value.val.subr(FocusWindow, StackP, - nArgs, &result, &errMsg)) - return execError(errMsg, sym->name); -- if (PC->op == OP_FETCH_RET_VAL) { -- PUSH(result); -- PC++; -- } -+ PUSH_RET_VAL(result); - return PreemptRequest ? STAT_PREEMPT : STAT_OK; - } - -@@ -2689,10 +2766,7 @@ static int callSubroutineFromSymbol(Symb - sym->value.val.xtproc(FocusWindow->lastFocus, - (XEvent *)&key_event, argList, &numArgs); - XtFree((char *)argList); -- if (PC->op == OP_FETCH_RET_VAL) { -- PUSH(noValue); -- PC++; -- } -+ PUSH_RET_VAL(noValue); - return PreemptRequest ? STAT_PREEMPT : STAT_OK; - } - -@@ -2714,8 +2788,8 @@ static int callSubroutine(void) - Symbol *sym; - int nArgs; - -- sym = PC++->sym; -- nArgs = PC++->value; -+ GET_SYM(sym); -+ GET_IMMED(nArgs); - - DISASM_RT(PC-3, 3); - STACKDUMP(nArgs > 0 ? nArgs : -nArgs, 3); -@@ -2739,7 +2813,7 @@ static int callSubroutineStackedN(void) - /* this is much like callSubroutine, but we get nArgs off the stack - and it will always be negative since there is always an argArray */ - -- sym = PC++->sym; -+ GET_SYM(sym); - - PEEK_INT(nArgs, 0); - DISASM_RT(PC-2, 2); -@@ -2854,7 +2928,7 @@ static int unpackArrayToArgs(void) - DISASM_RT(PC-1, 1); - STACKDUMP(1, 3); - -- nArgs = PC++->value; -+ GET_IMMED(nArgs); - haveNamedArgs = (nArgs < 0); - - POP(argArray); -@@ -2946,24 +3020,14 @@ static int returnValOrNone(int valOnStac - if (valOnStack) { - POP(retVal); - } -+ else { -+ retVal = noValue; -+ } - - PC = rewindFrame(&FrameP, &StackP); - - /* push returned value, if requsted */ -- if (PC == NULL) { -- if (valOnStack) { -- PUSH(retVal); -- } else { -- PUSH(noValue); -- } -- } else if (PC->op == OP_FETCH_RET_VAL) { -- if (valOnStack) { -- PUSH(retVal); -- } else { -- PUSH(noValue); -- } -- PC++; -- } -+ PUSH_RET_VAL(retVal); - - /* NULL return PC indicates end of program */ - return PC == NULL ? STAT_DONE : STAT_OK; -@@ -2977,10 +3041,14 @@ static int returnValOrNone(int valOnStac - */ - static int branch(void) - { -+ Inst *addr; -+ - DISASM_RT(PC-1, 2); - STACKDUMP(0, 3); - -- PC += PC->value; -+ GET_BRANCH(addr); -+ JUMP(addr); -+ - return STAT_OK; - } - -@@ -3005,15 +3073,15 @@ static int branchIf(Boolean trueOrFalse) - int value; - Inst *addr; - -+ GET_BRANCH(addr); -+ - DISASM_RT(PC-1, 2); - STACKDUMP(1, 3); - - POP_INT(value); -- addr = PC + PC->value; -- PC++; - - if (!value == !trueOrFalse) -- PC = addr; -+ JUMP(addr); - return STAT_OK; - } - -@@ -3027,10 +3095,13 @@ static int branchIf(Boolean trueOrFalse) - */ - static int branchNever(void) - { -+ Inst *addr; -+ - DISASM_RT(PC-1, 2); - STACKDUMP(0, 3); - -- PC++; -+ GET_BRANCH(addr); -+ - return STAT_OK; - } - -@@ -3391,8 +3462,7 @@ static int arrayRef(void) - char *keyString = NULL; - int nDim; - -- nDim = PC->value; -- PC++; -+ GET_IMMED(nDim); - - DISASM_RT(PC-2, 2); - STACKDUMP(nDim+1, 3); -@@ -3442,8 +3512,7 @@ static int arrayAssign(void) - int errNum; - int nDim; - -- nDim = PC->value; -- PC++; -+ GET_IMMED(nDim); - - DISASM_RT(PC-2, 1); - STACKDUMP(nDim+2, 3); -@@ -3495,10 +3564,8 @@ static int arrayRefAndAssignSetup(void) - char *keyString = NULL; - int binaryOp, nDim; - -- binaryOp = PC->value; -- PC++; -- nDim = PC->value; -- PC++; -+ GET_IMMED(binaryOp); -+ GET_IMMED(nDim); - - DISASM_RT(PC-3, 3); - STACKDUMP(nDim + (binaryOp ? 2 : 1), 3); -@@ -3554,8 +3621,7 @@ static int beginArrayIter(void) - DISASM_RT(PC-1, 2); - STACKDUMP(1, 3); - -- iterator = PC->sym; -- PC++; -+ GET_SYM(iterator); - - POP(arrayVal); - -@@ -3614,18 +3680,13 @@ static int arrayIter(void) - DISASM_RT(PC-1, 4); - STACKDUMP(0, 4); - -- withVal = PC->value; -- PC++; -- keySym = PC->sym; -- PC++; -+ GET_IMMED(withVal); -+ GET_SYM(keySym); - if (withVal) { -- valSym = PC->sym; -- PC++; -+ GET_SYM(valSym); - } -- iterator = PC->sym; -- PC++; -- branchAddr = PC + PC->value; -- PC++; -+ GET_SYM(iterator); -+ GET_BRANCH(branchAddr); - - if (keySym->type == LOCAL_SYM) { - keyValPtr = &FP_GET_SYM_VAL(FrameP, keySym); -@@ -3674,7 +3735,7 @@ static int arrayIter(void) - iteratorValPtr->val.arrayPtr = arrayIterateNext(thisEntry); - } - else { -- PC = branchAddr; -+ JUMP(branchAddr); - } - return(STAT_OK); - } -@@ -3695,8 +3756,7 @@ static int beginArrayMultiIterArray(void - DISASM_RT(PC-1, 2); - STACKDUMP(2, 3); - -- iterator = PC->sym; -- PC++; -+ GET_SYM(iterator); - - POP(arrayVal); - PEEK_INT(nDims, 0); -@@ -3798,23 +3858,15 @@ static int arrayMultiIterArray(void) - DISASM_RT(PC-1, 4); - STACKDUMP(1, 4); - -- withVal = PC->value; -- PC++; -- -- PEEK_INT(nDims, 0); -- -- keyArraySym = PC->sym; -- PC++; -- -+ GET_IMMED(withVal); -+ GET_SYM(keyArraySym); - if (withVal) { -- valSym = PC->sym; -- PC++; -+ GET_SYM(valSym); - } -+ GET_SYM(iterator); -+ GET_BRANCH(branchAddr); - -- iterator = PC->sym; -- PC++; -- branchAddr = PC + PC->value; -- PC++; -+ PEEK_INT(nDims, 0); - - if (keyArraySym->type == LOCAL_SYM) { - keyArrayPtr = &FP_GET_SYM_VAL(FrameP, keyArraySym); -@@ -3881,7 +3933,7 @@ static int arrayMultiIterArray(void) - iteratorValPtr->val.arrayPtr = thisEntry; - - if (!keyFound && (!thisEntry || thisEntry->nodePtrs.color == -1)) { -- PC = branchAddr; -+ JUMP(branchAddr); - } - - return STAT_OK; -@@ -3949,8 +4001,7 @@ static int deleteArrayElement(void) - char *keyString = NULL; - int nDim; - -- nDim = PC->value; -- PC++; -+ GET_IMMED(nDim); - - DISASM_RT(PC-2, 2); - STACKDUMP(nDim + 1, 3); -@@ -4023,10 +4074,7 @@ static int typeOfOut(void) - } - retVal.val.str.len = strlen(retVal.val.str.rep); - -- if (PC->op == OP_FETCH_RET_VAL) { -- PUSH(retVal); -- PC++; -- } -+ PUSH_RET_VAL(retVal); - - return STAT_OK; - } -@@ -4282,6 +4330,23 @@ static const char *typeToStr(enum symTyp - } - - -+static const char *instTypeToStr(enum instTypes type) -+{ -+ switch (type) { -+ case OP_INST: -+ return ""; -+ case IMMED_INST: -+ return ""; -+ case BRANCH_INST: -+ return ""; -+ case SYM_INST: -+ return ""; -+ default: -+ return ""; -+ } -+} -+ -+ - #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */ - static char *printdBuffer = NULL; - static int printdPos = 0; -@@ -4440,26 +4505,50 @@ static void disasmInternal(Inst *inst, i - for (i = 0; i < nInstr; ++i) { - printd("Prog %8p", &inst[i]); - -- switch (inst[i].op) { -+ if (inst[i].type != OP_INST) { -+ switch (inst[i].type) { -+ case IMMED_INST: -+ printd(" %s: %d\n", -+ instTypeToStr(inst[i].type), -+ inst[i].val.immed); -+ break; -+ case BRANCH_INST: -+ printd(" %s: (%+td) %8p\n", -+ instTypeToStr(inst[i].type), -+ inst[i].val.branch, -+ &inst[i] + inst[i].val.branch); -+ case SYM_INST: -+ printd(" %s: %s\n", -+ instTypeToStr(inst[i].type), -+ inst[i].val.sym->name); -+ break; -+ default: -+ printd(" : %tx\n", inst[i].val.branch); -+ } -+ -+ continue; -+ } -+ -+ switch (inst[i].val.op) { - #define OP(name, fn) case OP_##name: - #include "ops.h" - #undef OP -- printd(" %*s", (int)opLen, opNames[inst[i].op]); -+ printd(" %*s", (int)opLen, opNames[inst[i].val.op]); - -- switch (inst[i].op) { -+ switch (inst[i].val.op) { - case OP_PUSH_SYM: - case OP_ASSIGN: -- printd(" %s", inst[i+1].sym->name); -- if (inst[i+1].sym->type == CONST_SYM -- && inst[i+1].sym->value.tag == STRING_TAG) { -+ printd(" %s", inst[i+1].val.sym->name); -+ if (inst[i+1].val.sym->type == CONST_SYM -+ && inst[i+1].val.sym->value.tag == STRING_TAG) { - printd(" "); -- dumpVal(inst[i+1].sym->value); -+ dumpVal(inst[i+1].val.sym->value); - } - ++i; - break; - - case OP_PUSH_IMMED: -- printd(" %d", inst[i+1].value); -+ printd(" %d", inst[i+1].val.immed); - ++i; - break; - -@@ -4467,19 +4556,20 @@ static void disasmInternal(Inst *inst, i - case OP_BRANCH_TRUE: - case OP_BRANCH_FALSE: - case OP_BRANCH_NEVER: -- printd(" to=(%+d) %8p", -- inst[i+1].value, &inst[i+1] + inst[i+1].value); -+ printd(" to=(%+td) %8p", -+ inst[i+1].val.branch, -+ &inst[i+1] + inst[i+1].val.branch); - ++i; - break; - - case OP_CONCAT: -- printd(" nExpr=%d", inst[i+1].value); -+ printd(" nExpr=%d", inst[i+1].val.immed); - ++i; - break; - - case OP_SUBR_CALL: { -- int args = inst[i+2].value; -- printd(" %s", inst[i+1].sym->name); -+ int args = inst[i+2].val.immed; -+ printd(" %s", inst[i+1].val.sym->name); - if (args < 0) { - printd(" %d+args[] (%d)", -args - 1, args); - } -@@ -4491,7 +4581,7 @@ static void disasmInternal(Inst *inst, i - break; - - case OP_UNPACKTOARGS: { -- int args = inst[i+2].value; -+ int args = inst[i+2].val.immed; - if (args < 0) { - printd(" %d+args[] (%d)", -args - 1, args); - } -@@ -4503,56 +4593,56 @@ static void disasmInternal(Inst *inst, i - break; - - case OP_SUBR_CALL_STACKED_N: -- printd(" %s =args[] (?)", inst[i+1].sym->name); -+ printd(" %s =args[] (?)", inst[i+1].val.sym->name); - ++i; - break; - - case OP_BEGIN_ARRAY_ITER: - case OP_BEGIN_ARRAY_MULTI_ITER_ARRAY: -- printd(" %s in", inst[i+1].sym->name); -+ printd(" %s in", inst[i+1].val.sym->name); - ++i; - break; - - case OP_ARRAY_ITER: -- if (!inst[i+1].value) { -+ if (!inst[i+1].val.immed) { - /* without val */ -- printd(" %s = %s++ end-loop=(%+d) %8p", -- inst[i+2].sym->name, -- inst[i+3].sym->name, -- inst[i+4].value, -- &inst[i+4] + inst[i+4].value); -+ printd(" %s = %s++ end-loop=(%+td) %8p", -+ inst[i+2].val.sym->name, -+ inst[i+3].val.sym->name, -+ inst[i+4].val.branch, -+ &inst[i+4] + inst[i+4].val.branch); - i += 4; - } - else { - /* with val */ -- printd(" %s=%s = %s++ end-loop=(%+d) %8p", -- inst[i+2].sym->name, -- inst[i+3].sym->name, -- inst[i+4].sym->name, -- inst[i+5].value, -- &inst[i+5] + inst[i+5].value); -+ printd(" %s=%s = %s++ end-loop=(%+td) %8p", -+ inst[i+2].val.sym->name, -+ inst[i+3].val.sym->name, -+ inst[i+4].val.sym->name, -+ inst[i+5].val.branch, -+ &inst[i+5] + inst[i+5].val.branch); - i += 5; - } - break; - - case OP_ARRAY_MULTI_ITER_ARRAY: -- if (!inst[i+1].value) { -+ if (!inst[i+1].val.immed) { - /* without val */ -- printd(" %s[] = %s++ end-loop=(%+d) %8p", -- inst[i+2].sym->name, -- inst[i+3].sym->name, -- inst[i+4].value, -- &inst[i+4] + inst[i+4].value); -+ printd(" %s[] = %s++ end-loop=(%+td) %8p", -+ inst[i+2].val.sym->name, -+ inst[i+3].val.sym->name, -+ inst[i+4].val.branch, -+ &inst[i+4] + inst[i+4].val.branch); - i += 4; - } - else { - /* with val */ -- printd(" %s[]=%s = %s++ end-loop=(%+d) %8p", -- inst[i+2].sym->name, -- inst[i+3].sym->name, -- inst[i+4].sym->name, -- inst[i+5].value, -- &inst[i+5] + inst[i+5].value); -+ printd(" %s[]=%s = %s++ end-loop=(%+td) %8p", -+ inst[i+2].val.sym->name, -+ inst[i+3].val.sym->name, -+ inst[i+4].val.sym->name, -+ inst[i+5].val.branch, -+ &inst[i+5] + inst[i+5].val.branch); - i += 5; - } - break; -@@ -4563,21 +4653,21 @@ static void disasmInternal(Inst *inst, i - case OP_ANONARRAY_INDEX_VAL: - case OP_NAMED_ARG1: - case OP_NAMED_ARGN: -- printd(" nDim=%d", inst[i+1].value); -+ printd(" nDim=%d", inst[i+1].val.immed); - ++i; - break; - - case OP_ARRAY_REF_ASSIGN_SETUP: - printd(" binOp=%s nDim=%d", -- inst[i+1].value ? "true" : "false", -- inst[i+2].value); -+ inst[i+1].val.immed ? "true" : "false", -+ inst[i+2].val.immed); - i += 2; - break; - - case OP_PUSH_ARRAY_SYM: - printd(" %s %s", -- inst[i+1].sym->name, -- inst[i+2].value ? "createAndRef" : "refOnly"); -+ inst[i+1].val.sym->name, -+ inst[i+2].val.immed ? "createAndRef" : "refOnly"); - i += 2; - break; - -@@ -4587,7 +4677,7 @@ static void disasmInternal(Inst *inst, i - break; - - default: -- printd(" %x\n", inst[i].value); -+ printd(" %lx\n", inst[i].val.immed); - break; - } - } -diff --quilt old/source/interpret.h new/source/interpret.h ---- old/source/interpret.h -+++ new/source/interpret.h -@@ -54,6 +54,8 @@ enum typeTags {NO_TAG, INT_TAG, STRING_T - - enum execReturnCodes {MACRO_TIME_LIMIT, MACRO_PREEMPT, MACRO_DONE, MACRO_ERROR}; - -+enum instTypes {OP_INST, IMMED_INST, BRANCH_INST, SYM_INST}; -+ - #define ARRAY_DIM_SEP "\034" - - struct DataValueTag; -@@ -61,10 +63,14 @@ struct SparseArrayEntryTag; - struct ProgramTag; - struct SymbolRec; - --typedef union InstTag { -- enum operations op; -- int value; -- struct SymbolRec *sym; -+typedef struct InstTag { -+ enum instTypes type; -+ union { -+ enum operations op; -+ int immed; -+ ptrdiff_t branch; -+ struct SymbolRec *sym; -+ } val; - } Inst; - - typedef int (*BuiltInSubr)(WindowInfo *window, struct DataValueTag *argList, -@@ -150,8 +156,9 @@ int ArrayCopy(DataValue *dstArray, DataV - void BeginCreatingProgram(const char *name, AccumulatorData *acc); - int AddOp(int op, char **msg); - int AddSym(Symbol *sym, char **msg); --int AddImmediate(int value, char **msg); -+int AddImmediate(int immed, char **msg); - int AddBranchOffset(Inst *to, char **msg); -+int SetBranchOffset(Inst *from, Inst *to, char **msg); - Inst *GetPC(void); - Symbol *InstallIteratorSymbol(void); - Symbol *LookupStringConstSymbol(const char *value); -@@ -161,9 +168,9 @@ 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); -+int StartLoopAddrList(char **msg); -+int AddBreakAddr(Inst *addr, char **msg); -+int AddContinueAddr(Inst *addr, char **msg); - void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr); - - /* create a permanently allocated static string (only for use with static strings) */ -diff --quilt old/source/parse.y new/source/parse.y ---- old/source/parse.y -+++ new/source/parse.y -@@ -55,7 +55,27 @@ - } while (0) - #define SET_BR_OFF(from, to) \ - do { \ -- ((from)->value) = ((Inst *)(to)) - ((Inst *)(from)); \ -+ if (!SetBranchOffset(from, to, &ErrMsg)) { \ -+ return 1; \ -+ } \ -+ } while (0) -+#define START_LOOP() \ -+ do { \ -+ if (!StartLoopAddrList(&ErrMsg)) { \ -+ return 1; \ -+ } \ -+ } while (0) -+#define ADD_BREAK(addr) \ -+ do { \ -+ if (!AddBreakAddr(addr, &ErrMsg)) { \ -+ return 1; \ -+ } \ -+ } while (0) -+#define ADD_CONTINUE(addr) \ -+ do { \ -+ if (!AddContinueAddr(addr, &ErrMsg)) { \ -+ return 1; \ -+ } \ - } while (0) - - /* Max. length for a string constant (... there shouldn't be a maximum) */ -@@ -307,15 +327,11 @@ stmt: ';' blank - } - | BREAK stmtend blank { - ADD_OP(OP_BRANCH); ADD_BR_OFF(0); -- if (AddBreakAddr(GetPC()-1)) { -- yyerror("break outside loop"); YYERROR; -- } -+ ADD_BREAK(GetPC() - 1); - } - | CONTINUE stmtend blank { - ADD_OP(OP_BRANCH); ADD_BR_OFF(0); -- if (AddContinueAddr(GetPC()-1)) { -- yyerror("continue outside loop"); YYERROR; -- } -+ ADD_CONTINUE(GetPC() - 1); - } - | RETURN expr stmtend blank { - ADD_OP(OP_RETURN); -@@ -773,15 +789,15 @@ numexpropt: blank { - ; - - while: WHILE blank { -- $$ = GetPC(); StartLoopAddrList(); -+ $$ = GetPC(); START_LOOP(); - } - ; - do: DO blank { -- $$ = GetPC(); StartLoopAddrList(); -+ $$ = GetPC(); START_LOOP(); - } - ; - for: FOR blank { -- StartLoopAddrList(); $$ = GetPC(); -+ START_LOOP(); $$ = GetPC(); - } - ; - else: ELSE blank { +--- + + source/interpret.c | 175 +++++++++++++++++++++++++---------------------------- + 1 file changed, 85 insertions(+), 90 deletions(-) + +diff --quilt old/source/interpret.c new/source/interpret.c +--- old/source/interpret.c ++++ new/source/interpret.c +@@ -1320,6 +1320,40 @@ static void addToGlobalSymTab(Symbol *sy + GlobalSymTab[idx] = sym; + } + ++#define GET_SYM(s) \ ++ do { \ ++ s = PC->sym; \ ++ PC++; \ ++ } while (0) ++ ++#define GET_IMMED(i) \ ++ do { \ ++ i = PC->value; \ ++ PC++; \ ++ } while (0) ++ ++#define GET_BRANCH(a) \ ++ do { \ ++ a = PC + PC->value; \ ++ PC++; \ ++ } while (0) ++ ++#define JUMP(a) \ ++ do { \ ++ PC = (a); \ ++ } while (0) ++ ++#define PUSH_RET_VAL(dv) \ ++ do { \ ++ if (PC == NULL) { \ ++ PUSH(dv); \ ++ } \ ++ else if (PC->op == OP_FETCH_RET_VAL) { \ ++ PUSH(dv); \ ++ PC++; \ ++ } \ ++ } while (0) ++ + /* true, if you can pop n values */ + #define OK_TO_POP(n) \ + ((StackP - (n)) >= TheStack) +@@ -1482,8 +1516,7 @@ static int pushSymVal(void) + DISASM_RT(PC-1, 2); + STACKDUMP(0, 3); + +- s = PC->sym; +- PC++; ++ GET_SYM(s); + + if (s->type == LOCAL_SYM) { + symVal = FP_GET_SYM_VAL(FrameP, s); +@@ -1538,8 +1571,7 @@ static int pushImmed(void) + DISASM_RT(PC-1, 2); + STACKDUMP(0, 3); + +- immed = PC->value; +- PC++; ++ GET_IMMED(immed); + + PUSH_INT(immed); + +@@ -1623,10 +1655,8 @@ static int pushArraySymVal(void) + DISASM_RT(PC-1, 3); + STACKDUMP(0, 3); + +- sym = PC->sym; +- PC++; +- initEmpty = PC->value; +- PC++; ++ GET_SYM(sym); ++ GET_IMMED(initEmpty); + + if (sym->type == LOCAL_SYM) { + dataPtr = &FP_GET_SYM_VAL(FrameP, sym); +@@ -1765,8 +1795,7 @@ static int anonArrayIndexVal(void) + int nextIndex, index; + int nDim; + +- nDim = PC->value; +- PC++; ++ GET_IMMED(nDim); + + DISASM_RT(PC-2, 2); + STACKDUMP(nDim+3, 3); +@@ -1863,7 +1892,7 @@ static int namedArg1orN(Boolean isFirst) + DataValue exprVal, argsArray; + int nDim, index; + +- nDim = (PC++)->value; ++ GET_IMMED(nDim); + + DISASM_RT(PC-2, 2); + STACKDUMP(nDim + (isFirst ? 2 : 1), 3); +@@ -1937,8 +1966,7 @@ static int assign(void) + DISASM_RT(PC-1, 2); + STACKDUMP(1, 3); + +- sym = PC->sym; +- PC++; ++ GET_SYM(sym); + + if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) { + if (sym->type == ARG_SYM) { +@@ -2559,8 +2587,7 @@ static int concat(void) + + int nExpr; + +- nExpr = PC->value; +- PC++; ++ GET_IMMED(nExpr); + + DISASM_RT(PC-2, 2); + STACKDUMP(nExpr, 3); +@@ -2644,10 +2671,7 @@ static int callSubroutineFromSymbol(Symb + if (!sym->value.val.subr(FocusWindow, StackP, + nArgs, &result, &errMsg)) + return execError(errMsg, sym->name); +- if (PC->op == OP_FETCH_RET_VAL) { +- PUSH(result); +- PC++; +- } ++ PUSH_RET_VAL(result); + return PreemptRequest ? STAT_PREEMPT : STAT_OK; + } + +@@ -2710,10 +2734,7 @@ static int callSubroutineFromSymbol(Symb + sym->value.val.xtproc(FocusWindow->lastFocus, + (XEvent *)&key_event, argList, &numArgs); + XtFree((char *)argList); +- if (PC->op == OP_FETCH_RET_VAL) { +- PUSH(noValue); +- PC++; +- } ++ PUSH_RET_VAL(noValue); + return PreemptRequest ? STAT_PREEMPT : STAT_OK; + } + +@@ -2735,8 +2756,8 @@ static int callSubroutine(void) + Symbol *sym; + int nArgs; + +- sym = PC++->sym; +- nArgs = PC++->value; ++ GET_SYM(sym); ++ GET_IMMED(nArgs); + + DISASM_RT(PC-3, 3); + STACKDUMP(nArgs > 0 ? nArgs : -nArgs, 3); +@@ -2760,7 +2781,7 @@ static int callSubroutineStackedN(void) + /* this is much like callSubroutine, but we get nArgs off the stack + and it will always be negative since there is always an argArray */ + +- sym = PC++->sym; ++ GET_SYM(sym); + + PEEK_INT(nArgs, 0); + DISASM_RT(PC-2, 2); +@@ -2875,7 +2896,7 @@ static int unpackArrayToArgs(void) + DISASM_RT(PC-1, 1); + STACKDUMP(1, 3); + +- nArgs = PC++->value; ++ GET_IMMED(nArgs); + haveNamedArgs = (nArgs < 0); + + POP(argArray); +@@ -2967,24 +2988,14 @@ static int returnValOrNone(int valOnStac + if (valOnStack) { + POP(retVal); + } ++ else { ++ retVal = noValue; ++ } + + PC = rewindFrame(&FrameP, &StackP); + + /* push returned value, if requsted */ +- if (PC == NULL) { +- if (valOnStack) { +- PUSH(retVal); +- } else { +- PUSH(noValue); +- } +- } else if (PC->op == OP_FETCH_RET_VAL) { +- if (valOnStack) { +- PUSH(retVal); +- } else { +- PUSH(noValue); +- } +- PC++; +- } ++ PUSH_RET_VAL(retVal); + + /* NULL return PC indicates end of program */ + return PC == NULL ? STAT_DONE : STAT_OK; +@@ -2998,10 +3009,14 @@ static int returnValOrNone(int valOnStac + */ + static int branch(void) + { ++ Inst *addr; ++ + DISASM_RT(PC-1, 2); + STACKDUMP(0, 3); + +- PC += PC->value; ++ GET_BRANCH(addr); ++ JUMP(addr); ++ + return STAT_OK; + } + +@@ -3029,12 +3044,12 @@ static int branchIf(Boolean trueOrFalse) + DISASM_RT(PC-1, 2); + STACKDUMP(1, 3); + ++ GET_BRANCH(addr); ++ + POP_INT(value); +- addr = PC + PC->value; +- PC++; + + if (!value == !trueOrFalse) +- PC = addr; ++ JUMP(addr); + return STAT_OK; + } + +@@ -3048,10 +3063,13 @@ static int branchIf(Boolean trueOrFalse) + */ + static int branchNever(void) + { ++ Inst *addr; ++ + DISASM_RT(PC-1, 2); + STACKDUMP(0, 3); + +- PC++; ++ GET_BRANCH(addr); ++ + return STAT_OK; + } + +@@ -3412,8 +3430,7 @@ static int arrayRef(void) + char *keyString = NULL; + int nDim; + +- nDim = PC->value; +- PC++; ++ GET_IMMED(nDim); + + DISASM_RT(PC-2, 2); + STACKDUMP(nDim+1, 3); +@@ -3463,8 +3480,7 @@ static int arrayAssign(void) + int errNum; + int nDim; + +- nDim = PC->value; +- PC++; ++ GET_IMMED(nDim); + + DISASM_RT(PC-2, 1); + STACKDUMP(nDim+2, 3); +@@ -3516,10 +3532,8 @@ static int arrayRefAndAssignSetup(void) + char *keyString = NULL; + int binaryOp, nDim; + +- binaryOp = PC->value; +- PC++; +- nDim = PC->value; +- PC++; ++ GET_IMMED(binaryOp); ++ GET_IMMED(nDim); + + DISASM_RT(PC-3, 3); + STACKDUMP(nDim + (binaryOp ? 2 : 1), 3); +@@ -3575,8 +3589,7 @@ static int beginArrayIter(void) + DISASM_RT(PC-1, 2); + STACKDUMP(1, 3); + +- iterator = PC->sym; +- PC++; ++ GET_SYM(iterator); + + POP(arrayVal); + +@@ -3635,18 +3648,13 @@ static int arrayIter(void) + DISASM_RT(PC-1, 4); + STACKDUMP(0, 4); + +- withVal = PC->value; +- PC++; +- keySym = PC->sym; +- PC++; ++ GET_IMMED(withVal); ++ GET_SYM(keySym); + if (withVal) { +- valSym = PC->sym; +- PC++; ++ GET_SYM(valSym); + } +- iterator = PC->sym; +- PC++; +- branchAddr = PC + PC->value; +- PC++; ++ GET_SYM(iterator); ++ GET_BRANCH(branchAddr); + + if (keySym->type == LOCAL_SYM) { + keyValPtr = &FP_GET_SYM_VAL(FrameP, keySym); +@@ -3695,7 +3703,7 @@ static int arrayIter(void) + iteratorValPtr->val.arrayPtr = arrayIterateNext(thisEntry); + } + else { +- PC = branchAddr; ++ JUMP(branchAddr); + } + return(STAT_OK); + } +@@ -3716,8 +3724,7 @@ static int beginArrayMultiIterArray(void + DISASM_RT(PC-1, 2); + STACKDUMP(2, 3); + +- iterator = PC->sym; +- PC++; ++ GET_SYM(iterator); + + POP(arrayVal); + PEEK_INT(nDims, 0); +@@ -3819,23 +3826,15 @@ static int arrayMultiIterArray(void) + DISASM_RT(PC-1, 4); + STACKDUMP(1, 4); + +- withVal = PC->value; +- PC++; +- +- PEEK_INT(nDims, 0); +- +- keyArraySym = PC->sym; +- PC++; +- ++ GET_IMMED(withVal); ++ GET_SYM(keyArraySym); + if (withVal) { +- valSym = PC->sym; +- PC++; ++ GET_SYM(valSym); + } ++ GET_SYM(iterator); ++ GET_BRANCH(branchAddr); + +- iterator = PC->sym; +- PC++; +- branchAddr = PC + PC->value; +- PC++; ++ PEEK_INT(nDims, 0); + + if (keyArraySym->type == LOCAL_SYM) { + keyArrayPtr = &FP_GET_SYM_VAL(FrameP, keyArraySym); +@@ -3902,7 +3901,7 @@ static int arrayMultiIterArray(void) + iteratorValPtr->val.arrayPtr = thisEntry; + + if (!keyFound && (!thisEntry || thisEntry->nodePtrs.color == -1)) { +- PC = branchAddr; ++ JUMP(branchAddr); + } + + return STAT_OK; +@@ -3970,8 +3969,7 @@ static int deleteArrayElement(void) + char *keyString = NULL; + int nDim; + +- nDim = PC->value; +- PC++; ++ GET_IMMED(nDim); + + DISASM_RT(PC-2, 2); + STACKDUMP(nDim + 1, 3); +@@ -4044,10 +4042,7 @@ static int typeOfOut(void) + } + retVal.val.str.len = strlen(retVal.val.str.rep); + +- if (PC->op == OP_FETCH_RET_VAL) { +- PUSH(retVal); +- PC++; +- } ++ PUSH_RET_VAL(retVal); + + return STAT_OK; + } diff --git a/anonArrayNamedArgs7.diff b/anonArrayNamedArgs7.diff index 2945295..6645c6c 100644 --- a/anonArrayNamedArgs7.diff +++ b/anonArrayNamedArgs7.diff @@ -813,8 +813,8 @@ diff --quilt old/source/parse.y new/source/parse.y +%type arglistopt arglist catlist fnarglsopt fnarglist fnarg %type cond comastmts comastmtlst for while do else and or arrayexpr mark %type evalsym - %type operassign incrdecr -@@ -325,7 +325,7 @@ simpstmt: /* simple variable assignmen + %type definesym +@@ -327,7 +327,7 @@ simpstmt: /* simple variable assignmen ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); } /* function call */ @@ -823,7 +823,7 @@ diff --quilt old/source/parse.y new/source/parse.y ADD_OP(OP_SUBR_CALL); ADD_SYM(PromoteToGlobal($1)); ADD_IMMED($3); } -@@ -356,6 +356,60 @@ catlist: numexpr %prec CONC +@@ -358,6 +358,60 @@ catlist: numexpr %prec CONC | catlist numexpr %prec CONCAT { $$ = $1 + 1; } ; @@ -884,7 +884,7 @@ diff --quilt old/source/parse.y new/source/parse.y expr: catlist { if ($1 > 1) { ADD_OP(OP_CONCAT); ADD_IMMED($1); -@@ -400,17 +454,57 @@ arrayexpr: numexpr { +@@ -402,17 +456,57 @@ arrayexpr: numexpr { } ; @@ -943,7 +943,7 @@ diff --quilt old/source/parse.y new/source/parse.y | ARG_LOOKUP { ADD_OP(OP_PUSH_ARG_ARRAY); } | numexpr '[' arglistopt ']' { ADD_OP(OP_ARRAY_REF); ADD_IMMED($3); -@@ -455,6 +549,7 @@ numexpr: '(' blank expr blank ')' +@@ -457,6 +551,7 @@ numexpr: '(' blank expr blank ')' ADD_OP(OP_IN_ARRAY); ADD_OP(OP_NOT); } diff --git a/array-next-num-index.patch b/array-next-num-index.patch index e75ca44..7745c5d 100644 --- a/array-next-num-index.patch +++ b/array-next-num-index.patch @@ -130,7 +130,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 -@@ -395,6 +395,9 @@ simpstmt: /* simple variable assignmen +@@ -397,6 +397,9 @@ simpstmt: /* simple variable assignmen ADD_OP($1); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); } @@ -140,7 +140,7 @@ diff --quilt old/source/parse.y new/source/parse.y | funccall | lvlistexpr ; -@@ -709,6 +712,9 @@ numexpr: '(' blank expr blank ')' +@@ -711,6 +714,9 @@ numexpr: '(' blank expr blank ')' | numexpr dot field { ADD_OP(OP_ARRAY_REF); ADD_IMMED(1); } diff --git a/arrayReplacesArglist-as-last-argument.patch b/arrayReplacesArglist-as-last-argument.patch index 3c8f860..a51c28a 100644 --- a/arrayReplacesArglist-as-last-argument.patch +++ b/arrayReplacesArglist-as-last-argument.patch @@ -94,7 +94,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -4296,8 +4325,18 @@ static void disasmInternal(Inst *inst, i +@@ -4320,8 +4349,18 @@ static void disasmInternal(Inst *inst, i } i += 2; } @@ -125,7 +125,7 @@ diff --quilt old/source/parse.y new/source/parse.y static Symbol *matchesActionRoutine(char **inPtr); static int scanString(void); -@@ -116,6 +117,7 @@ typedef struct LVinst { +@@ -117,6 +118,7 @@ typedef struct LVinst { %token '=' ADDEQ SUBEQ MULEQ DIVEQ MODEQ ANDEQ OREQ %token INCR DECR %type lvlist lventry @@ -133,7 +133,7 @@ diff --quilt old/source/parse.y new/source/parse.y %nonassoc IF_NO_ELSE %nonassoc ELSE -@@ -553,6 +555,14 @@ funccall: TYPEOF '(' { +@@ -555,6 +557,14 @@ funccall: TYPEOF '(' { | SYMBOL '(' blank '=' blank expr blank ')' { /* a single array replaces the argument list */ ADD_OP(OP_UNPACKTOARGS); @@ -148,7 +148,7 @@ diff --quilt old/source/parse.y new/source/parse.y ADD_OP(OP_SUBR_CALL_STACKED_N); ADD_SYM(PromoteToGlobal($1)); } -@@ -991,6 +1001,7 @@ static int yylex(void) +@@ -993,6 +1003,7 @@ static int yylex(void) ++InPtr; return result; /* but return what we started with */ } @@ -156,7 +156,7 @@ diff --quilt old/source/parse.y new/source/parse.y default: return *(InPtr-1); } } -@@ -1075,6 +1086,23 @@ static int eq_look_ahead(void) +@@ -1077,6 +1088,23 @@ static int eq_look_ahead(void) return '='; } diff --git a/arrayReplacesArglist5.diff b/arrayReplacesArglist5.diff index a6f5019..a4b08e2 100644 --- a/arrayReplacesArglist5.diff +++ b/arrayReplacesArglist5.diff @@ -262,7 +262,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 -@@ -325,11 +325,7 @@ simpstmt: /* simple variable assignmen +@@ -327,11 +327,7 @@ simpstmt: /* simple variable assignmen ADD_OP($1); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); } @@ -275,7 +275,7 @@ diff --quilt old/source/parse.y new/source/parse.y ; evalsym: SYMBOL { -@@ -357,6 +353,19 @@ catlist: numexpr %prec CONC +@@ -359,6 +355,19 @@ catlist: numexpr %prec CONC | catlist numexpr %prec CONCAT { $$ = $1 + 1; } ; @@ -295,7 +295,7 @@ diff --quilt old/source/parse.y new/source/parse.y /* function argument lists */ fnarg: expr { $$ = 0; -@@ -495,9 +504,7 @@ numexpr: '(' blank expr blank ')' +@@ -497,9 +506,7 @@ numexpr: '(' blank expr blank ')' | NUMBER { ADD_OP(OP_PUSH_IMMED); ADD_IMMED($1); } | STRING { ADD_OP(OP_PUSH_SYM); ADD_SYM($1); } | SYMBOL { ADD_OP(OP_PUSH_SYM); ADD_SYM($1); } diff --git a/callMacroFnByName2.diff b/callMacroFnByName2.diff index 8586c1c..b66a2cc 100644 --- a/callMacroFnByName2.diff +++ b/callMacroFnByName2.diff @@ -178,7 +178,7 @@ diff --quilt old/source/macro.c new/source/macro.c { NULL, NULL } /* sentinel */ }; -@@ -3492,6 +3495,31 @@ static int filenameDialogMS(WindowInfo* +@@ -3493,6 +3496,31 @@ static int filenameDialogMS(WindowInfo* return True; } diff --git a/core-typeof-syntax.patch b/core-typeof-syntax.patch index c3ffca4..a1d1d4c 100644 --- a/core-typeof-syntax.patch +++ b/core-typeof-syntax.patch @@ -169,7 +169,7 @@ diff --quilt old/source/parse.y new/source/parse.y %type arglistopt arglist catlist fnarglsopt fnarglist fnarg %type cond comastmts comastmtlst for while do else and or arrayexpr mark %type evalsym -@@ -478,8 +478,13 @@ catlist: numexpr %prec CONC +@@ -480,8 +480,13 @@ catlist: numexpr %prec CONC | catlist numexpr %prec CONCAT { $$ = $1 + 1; } ; @@ -185,7 +185,7 @@ diff --quilt old/source/parse.y new/source/parse.y ADD_OP(OP_SUBR_CALL); ADD_SYM(PromoteToGlobal($1)); ADD_IMMED($3); } -@@ -867,6 +872,7 @@ static int yylex(void) +@@ -869,6 +874,7 @@ static int yylex(void) if (!strcmp(symName, "$args")) return ARG_LOOKUP; if (!strcmp(symName, "delete") && follow_non_whitespace('(', SYMBOL, DELETE) == DELETE) return DELETE; if (!strcmp(symName, "define")) return DEFINE; diff --git a/define_macro.patch b/define_macro.patch index cd1bd48..c65d826 100644 --- a/define_macro.patch +++ b/define_macro.patch @@ -34,7 +34,7 @@ diff --quilt old/source/macro.c new/source/macro.c { NULL, NULL } /* sentinel */ }; -@@ -3680,6 +3684,99 @@ static int callMS(WindowInfo *window, Da +@@ -3681,6 +3685,99 @@ static int callMS(WindowInfo *window, Da return OverlayRoutineFromSymbol(sym, nArgs, 1); } @@ -164,7 +164,7 @@ diff --quilt old/doc/help.etx new/doc/help.etx diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -953,7 +953,7 @@ static int yylex(void) +@@ -955,7 +955,7 @@ static int yylex(void) if (!strcmp(symName, "in")) return IN; if (!strcmp(symName, "$args")) return ARG_LOOKUP; if (!strcmp(symName, "delete") && follow_non_whitespace('(', SYMBOL, DELETE) == DELETE) return DELETE; diff --git a/dictionary-fix-string-alloc.patch b/dictionary-fix-string-alloc.patch index 3d6e030..7b450bb 100644 --- a/dictionary-fix-string-alloc.patch +++ b/dictionary-fix-string-alloc.patch @@ -8,7 +8,7 @@ Subject: remove double allocation in dictionary patch diff --quilt old/source/macro.c new/source/macro.c --- old/source/macro.c +++ new/source/macro.c -@@ -6182,7 +6182,6 @@ static int dictsaveMS(WindowInfo *window +@@ -6183,7 +6183,6 @@ static int dictsaveMS(WindowInfo *window } result->tag = STRING_TAG; @@ -16,7 +16,7 @@ diff --quilt old/source/macro.c new/source/macro.c AllocNStringCpy(&result->val.str, dictionary_filename); return True; -@@ -6275,21 +6274,17 @@ static int dictcompleteMS(WindowInfo *wi +@@ -6276,21 +6275,17 @@ static int dictcompleteMS(WindowInfo *wi items_left = complete_dict(string, s2, minchars, maxmatches); /* so invoke a new search */ if (items_left <= 0) { diff --git a/dictionary.patch b/dictionary.patch index 318a800..b5335c9 100644 --- a/dictionary.patch +++ b/dictionary.patch @@ -25992,7 +25992,7 @@ diff --quilt old/source/macro.c new/source/macro.c { NULL, NULL } /* sentinel */ }; -@@ -6027,6 +6045,260 @@ static int getMatchingMS(WindowInfo *win +@@ -6028,6 +6046,260 @@ static int getMatchingMS(WindowInfo *win return True; } diff --git a/escape_literal_macro.patch b/escape_literal_macro.patch index 5db5db4..5b4547f 100644 --- a/escape_literal_macro.patch +++ b/escape_literal_macro.patch @@ -30,7 +30,7 @@ diff --quilt old/source/macro.c new/source/macro.c { NULL, NULL } /* sentinel */ }; -@@ -4036,6 +4039,54 @@ static int timerRemoveMS(WindowInfo *win +@@ -4037,6 +4040,54 @@ static int timerRemoveMS(WindowInfo *win return True; } diff --git a/extend-for-key-in-array-syntax.patch b/extend-for-key-in-array-syntax.patch index ad7439c..542b029 100644 --- a/extend-for-key-in-array-syntax.patch +++ b/extend-for-key-in-array-syntax.patch @@ -146,7 +146,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c iteratorValPtr->val.arrayPtr = arrayIterateNext(thisEntry); } else { -@@ -3955,11 +3986,25 @@ static void disasmInternal(Inst *inst, i +@@ -3979,11 +4010,25 @@ static void disasmInternal(Inst *inst, i ++i; } else if (j == OP_ARRAY_ITER) { @@ -197,7 +197,7 @@ diff --quilt old/source/parse.y new/source/parse.y %type arglistopt arglist catlist fnarglsopt fnarglist fnarg %type cond comastmts comastmtlst for while do else and or arrayexpr mark %type evalsym -@@ -236,14 +237,37 @@ stmt: ';' blank +@@ -238,14 +239,37 @@ stmt: ';' blank } | for '(' blank SYMBOL IN blank arrayexpr blank ')' { Symbol *iterSym = InstallIteratorSymbol(); @@ -239,7 +239,7 @@ diff --quilt old/source/parse.y new/source/parse.y | BREAK stmtend blank { ADD_OP(OP_BRANCH); ADD_BR_OFF(0); if (AddBreakAddr(GetPC()-1)) { -@@ -901,7 +925,7 @@ static int yylex(void) +@@ -903,7 +927,7 @@ static int yylex(void) switch (result) { case '>': return follow('=', GE, GT); case '<': return follow('=', LE, LT); @@ -248,7 +248,7 @@ diff --quilt old/source/parse.y new/source/parse.y case '!': return follow('=', NE, NOT); case '+': return follow2('+', INCR, '=', ADDEQ, '+'); case '-': return follow2('-', DECR, '=', SUBEQ, '-'); -@@ -964,6 +988,45 @@ static int follow_non_whitespace(char ex +@@ -966,6 +990,45 @@ static int follow_non_whitespace(char ex } } diff --git a/full-single-quoted.patch b/full-single-quoted.patch index cc579bf..d58dcaf 100644 --- a/full-single-quoted.patch +++ b/full-single-quoted.patch @@ -17,7 +17,7 @@ double quoted string. diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -1035,8 +1035,11 @@ static int scanString(void) +@@ -1037,8 +1037,11 @@ static int scanString(void) handleBackslash = (stopper == '\"'); len = 0; InPtr++; diff --git a/global-AccumulatorData.patch b/global-AccumulatorData.patch new file mode 100644 index 0000000..bf4c769 --- /dev/null +++ b/global-AccumulatorData.patch @@ -0,0 +1,195 @@ +--- + + source/interpret.c | 53 ++++++++++++++++++++++++----------------------------- + source/interpret.h | 4 ++-- + source/parse.y | 14 +++++--------- + 3 files changed, 31 insertions(+), 40 deletions(-) + +diff --quilt old/source/interpret.h new/source/interpret.h +--- old/source/interpret.h ++++ new/source/interpret.h +@@ -154,7 +154,8 @@ int ArrayCopy(DataValue *dstArray, DataV + + /* Routines for creating a program, (accumulated beginning with + BeginCreatingProgram and returned via FinishCreatingProgram) */ +-void BeginCreatingProgram(const char *name, AccumulatorData *acc); ++AccumulatorData *BeginCreatingProgram(const char *name); ++Program *FinishCreatingProgram(AccumulatorData *old); + int AddOp(int op, char **msg); + int AddSym(Symbol *sym, char **msg); + int AddImmediate(int immed, char **msg); +@@ -167,7 +168,6 @@ Symbol *InstallStringConstSymbol(const c + Symbol *LookupSymbol(const char *name); + Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value); + Symbol *InstallMultiAssignExpr(void); +-Program *FinishCreatingProgram(AccumulatorData *acc); + Inst *SwapCode(Inst *start, Inst *boundary, Inst *end); + int StartLoopAddrList(char **msg); + int AddBreakAddr(Inst *addr, char **msg); +diff --quilt old/source/parse.y new/source/parse.y +--- old/source/parse.y ++++ new/source/parse.y +@@ -202,7 +202,6 @@ definekw: DEFINE { + } + ; + definesym: SYMBOL { +- $$.acc = (AccumulatorData *)XtMalloc(sizeof(AccumulatorData)); + /* we can't really be sure, that we not overwrite any + ** wrong symbol + ** +@@ -219,13 +218,12 @@ definesym: SYMBOL { + yyerror("try to override built-in subroutine"); YYERROR; + } + $$.sym = PromoteToGlobal($1); +- BeginCreatingProgram($$.sym->name, $$.acc); ++ $$.acc = BeginCreatingProgram($$.sym->name); + } + ; + define: definekw blank definesym blank blockwb { + ADD_OP(OP_RETURN_NO_VAL); + Program *prog = FinishCreatingProgram($3.acc); +- XtFree((char *)$3.acc); + $3.sym->type = MACRO_FUNCTION_SYM; + $3.sym->value.tag = NO_TAG; + $3.sym->value.val.prog = prog; +@@ -849,7 +847,7 @@ Program *ParseMacro(char *expr, char **m + const char *name) + { + Program *prog; +- AccumulatorData *acc = (AccumulatorData *)XtMalloc(sizeof(*acc)); ++ AccumulatorData *old; + + #if YYDEBUG + int oldyydebug = yydebug; +@@ -859,7 +857,7 @@ Program *ParseMacro(char *expr, char **m + if (!name) + name = "--unknown--"; + +- BeginCreatingProgram(name, acc); ++ old = BeginCreatingProgram(name); + + /* whether we allow the "define" keyword */ + AllowDefine = allowDefine; +@@ -873,8 +871,7 @@ Program *ParseMacro(char *expr, char **m + if (yyparse()) { + *msg = ErrMsg; + *stoppedAt = InPtr; +- FreeProgram(FinishCreatingProgram(acc)); +- XtFree((char *)acc); ++ FreeProgram(FinishCreatingProgram(old)); + + #if YYDEBUG + yydebug = oldyydebug; +@@ -884,8 +881,7 @@ Program *ParseMacro(char *expr, char **m + } + + /* get the newly created program */ +- prog = FinishCreatingProgram(acc); +- XtFree((char *)acc); ++ prog = FinishCreatingProgram(old); + + /* parse succeeded */ + *msg = ""; +diff --quilt old/source/interpret.c new/source/interpret.c +--- old/source/interpret.c ++++ new/source/interpret.c +@@ -165,13 +165,13 @@ static const char *StackUnderflowMsg = " + static const char *StringToNumberMsg = "string '%s' could not be converted to number"; + + /* Temporary global data for use while accumulating programs */ +-static Symbol *LocalSymList = NULL; /* symbols local to the program */ +-static Inst Prog[PROGRAM_SIZE]; /* the program */ +-static Inst *ProgP; /* next free spot for code gen. */ +-static Inst *LoopStack[LOOP_STACK_SIZE]; /* addresses of break, cont stmts */ +-static Inst **LoopStackPtr = LoopStack; /* to fill at the end of a loop */ +- +-static const char *ProgramName = ""; ++static AccumulatorData *Accumulator; ++#define Prog (Accumulator->prog) ++#define ProgP (Accumulator->progP) ++#define LoopStack (Accumulator->loopStack) ++#define LoopStackPtr (Accumulator->loopStackPtr) ++#define LocalSymList (Accumulator->localSymList) ++#define ProgramName (Accumulator->name) + + /* Global data for the interpreter */ + static RestartData *Current; +@@ -264,20 +264,18 @@ void InitMacroGlobals(void) + ** Start collecting instructions for a program. Clears the program + ** and the symbol table. + */ +-void BeginCreatingProgram(const char *name, AccumulatorData *acc) ++AccumulatorData *BeginCreatingProgram(const char *name) + { +- /* save state */ +- acc->localSymList = LocalSymList; +- memcpy(acc->prog, Prog, sizeof(*Prog) * PROGRAM_SIZE); +- acc->progP = ProgP; +- memcpy(acc->loopStack, LoopStack, sizeof(*LoopStack) * LOOP_STACK_SIZE); +- acc->loopStackPtr = LoopStackPtr; +- acc->name = ProgramName; ++ AccumulatorData *old = Accumulator; ++ Accumulator = (AccumulatorData *)XtMalloc(sizeof(*Accumulator)); ++ memset(Accumulator, 0, sizeof(*Accumulator)); + + LocalSymList = NULL; + ProgP = Prog; + LoopStackPtr = LoopStack; + ProgramName = name; ++ ++ return old; + } + + /* +@@ -285,16 +283,16 @@ void BeginCreatingProgram(const char *na + ** symbol table) as a package that ExecuteMacro can execute. This + ** program must be freed with FreeProgram. + */ +-Program *FinishCreatingProgram(AccumulatorData *acc) ++Program *FinishCreatingProgram(AccumulatorData *old) + { + Program *newProg; + int progLen, fpOffset = 0; + Symbol *s; + + newProg = (Program *)XtMalloc(sizeof(Program) + strlen(ProgramName)); +- progLen = ((char *)ProgP) - ((char *)Prog); +- newProg->code = (Inst *)XtMalloc(progLen); +- memcpy(newProg->code, Prog, progLen); ++ progLen = ProgP - Prog; ++ newProg->code = (Inst *)XtMalloc(progLen * sizeof(Inst)); ++ memcpy(newProg->code, Prog, progLen * sizeof(Inst)); + newProg->localSymList = LocalSymList; + strcpy(newProg->name, ProgramName); + newProg->refcount = 1; +@@ -306,13 +304,8 @@ Program *FinishCreatingProgram(Accumulat + + DISASM(newProg->name, newProg->code, ProgP - Prog); + +- /* restore state */ +- LocalSymList = acc->localSymList; +- memcpy(Prog, acc->prog, sizeof(*Prog) * PROGRAM_SIZE); +- ProgP = acc->progP; +- memcpy(LoopStack, acc->loopStack, sizeof(*LoopStack) * LOOP_STACK_SIZE); +- LoopStackPtr = acc->loopStackPtr; +- ProgramName = acc->name; ++ XtFree((char *)Accumulator); ++ Accumulator = old; + + return newProg; + } +@@ -938,9 +931,11 @@ Symbol *LookupSymbol(const char *name) + hash = hashName(name); + + /* search in local symbols */ +- s = lookupSymbol(LocalSymList, name, hash); +- if (NULL != s) +- return s; ++ if (Accumulator) { ++ s = lookupSymbol(LocalSymList, name, hash); ++ if (NULL != s) ++ return s; ++ } + + /* search in global symbols */ + s = lookupSymbol(GlobalSymTab[hash & GLOBAL_SYMTAB_MASK], name, hash); diff --git a/global-RestartData.patch b/global-RestartData.patch new file mode 100644 index 0000000..17223f7 --- /dev/null +++ b/global-RestartData.patch @@ -0,0 +1,546 @@ +--- + + source/interpret.c | 197 +++++++++++++++++++++++------------------------------ + source/interpret.h | 3 + 2 files changed, 89 insertions(+), 111 deletions(-) + +diff --quilt old/source/interpret.c new/source/interpret.c +--- old/source/interpret.c ++++ new/source/interpret.c +@@ -81,8 +81,7 @@ static const char CVSID[] = "$Id: interp + enum opStatusCodes {STAT_OK=2, STAT_DONE, STAT_ERROR, STAT_PREEMPT}; + + static int addLoopAddr(Inst *addr, char **msg); +-static void saveContext(RestartData *context); +-static void restoreContext(RestartData *context); ++static RestartData *setContext(RestartData *context); + + #define OP(name, fn) static int fn(void); + #include "ops.h" +@@ -175,16 +174,15 @@ static Inst **LoopStackPtr = LoopStack; + static const char *ProgramName = ""; + + /* Global data for the interpreter */ +-static DataValue *TheStack; /* the stack */ +-static DataValue *StackP; /* next free spot on stack */ +-static DataValue *FrameP; /* frame pointer (start of local variables +- for the current subroutine invocation) */ +-static Inst *PC; /* program counter during execution */ +-static char *ErrMsg; /* global for returning error messages +- from executing functions */ +-static WindowInfo +- *InitiatingWindow = NULL; /* window from which macro was run */ +-static WindowInfo *FocusWindow; /* window on which macro commands operate */ ++static RestartData *Current; ++static void *no_context_in_use; ++#define StackP (Current->stackP) ++#define TheStack (Current->stack) ++#define FrameP (Current->frameP) ++#define PC (Current->pc) ++#define InitiatingWindow (Current->runWindow) ++#define FocusWindow (Current->focusWindow) ++#define ErrMsg (Current->errMsg) + static int PreemptRequest; /* passes preemption requests from called + routines back up to the interpreter */ + +@@ -532,7 +530,7 @@ static int setupFrame(RestartData *conte + } + + /* !OK_TO_PUSH(totalPushs) */ +- if (!((context->stackP + totalPushs) <= &context->stack[STACK_SIZE])) { ++ if (!((context->stackP + totalPushs) <= (context->stack + STACK_SIZE))) { + return execError(StackOverflowMsg, ""); + } + +@@ -596,30 +594,30 @@ static int setupFrame(RestartData *conte + return STAT_OK; + } + +-static Inst *rewindFrame(DataValue **frameP, DataValue **stackP) ++static void rewindFrame(RestartData *context) + { + /* get stored return information */ +- int nArgs = FP_GET_ARG_COUNT(*frameP); +- DataValue *newFrameP = FP_GET_OLD_FP(*frameP); +- Inst *newPC = FP_GET_RET_PC(*frameP); +- Program *prog = FP_GET_PROG(*frameP); ++ int nArgs = FP_GET_ARG_COUNT(context->frameP); ++ DataValue *newFrameP = FP_GET_OLD_FP(context->frameP); ++ Inst *newPC = FP_GET_RET_PC(context->frameP); ++ Program *prog = FP_GET_PROG(context->frameP); + + /* pop past local variables */ +- *stackP = *frameP; ++ context->stackP = context->frameP; + /* pop past arguments */ +- *stackP -= (FP_TO_ARGS_DIST + nArgs); ++ context->stackP -= (FP_TO_ARGS_DIST + nArgs); + +- *frameP = newFrameP; ++ context->frameP = newFrameP; + + FreeProgram(prog); + +- return newPC; ++ context->pc = newPC; + } + + static void rewindStack(RestartData *context) + { + while (context->pc) { +- context->pc = rewindFrame(&context->frameP, &context->stackP); ++ rewindFrame(context); + } + } + +@@ -648,7 +646,7 @@ int ExecuteMacro(WindowInfo *window, Pro + and a program counter) which will retain the program state across + preemption and resumption of execution */ + context = (RestartData *)XtMalloc(sizeof(RestartData)); +- context->stack = (DataValue *)XtMalloc(sizeof(DataValue) * STACK_SIZE); ++ memset(context, 0, sizeof(*context)); + *continuation = context; + context->stackP = context->stack; + context->runWindow = window; +@@ -679,18 +677,17 @@ int ContinueMacro(RestartData *continuat + { + register int status, instCount = 0; + register Inst *inst; +- RestartData oldContext; +- +- /* To allow macros to be invoked arbitrarily (such as those automatically +- triggered within smart-indent) within executing macros, this call is +- reentrant. */ +- saveContext(&oldContext); ++ RestartData *oldContext; + + /* ++ ** To allow macros to be invoked arbitrarily (such as those automatically ++ ** triggered within smart-indent) within executing macros, this call is ++ ** reentrant. ++ ** + ** Execution Loop: Call the succesive routine addresses in the program + ** until one returns something other than STAT_OK, then take action + */ +- restoreContext(continuation); ++ oldContext = setContext(continuation); + ErrMsg = NULL; + for (;;) { + +@@ -715,21 +712,18 @@ int ContinueMacro(RestartData *continuat + /* If error return was not STAT_OK, return to caller */ + if (status != STAT_OK) { + if (status == STAT_PREEMPT) { +- saveContext(continuation); +- restoreContext(&oldContext); ++ setContext(oldContext); + return MACRO_PREEMPT; + } else if (status == STAT_ERROR) { + *msg = ErrMsg; +- saveContext(continuation); ++ setContext(oldContext); + FreeRestartData(continuation); +- restoreContext(&oldContext); + return MACRO_ERROR; + } else if (status == STAT_DONE) { + *msg = ""; + *result = *--StackP; +- saveContext(continuation); ++ setContext(oldContext); + FreeRestartData(continuation); +- restoreContext(&oldContext); + return MACRO_DONE; + } + } +@@ -739,8 +733,7 @@ int ContinueMacro(RestartData *continuat + X, other macros, and other shell scripts a chance to execute */ + instCount++; + if (instCount >= INSTRUCTION_LIMIT) { +- saveContext(continuation); +- restoreContext(&oldContext); ++ setContext(oldContext); + return MACRO_TIME_LIMIT; + } + } +@@ -776,7 +769,6 @@ int RunMacroAsSubrCall(RestartData *cont + void FreeRestartData(RestartData *context) + { + rewindStack(context); +- XtFree((char *)context->stack); + XtFree((char *)context); + } + +@@ -797,8 +789,8 @@ void PreemptMacro(void) + */ + void ModifyReturnedValue(RestartData *context, DataValue dv) + { +- if ((context->pc-1)->val.op == OP_FETCH_RET_VAL) +- *(context->stackP-1) = dv; ++ if ((context->pc - 1)->val.op == OP_FETCH_RET_VAL) ++ *(context->stackP - 1) = dv; + } + + /* +@@ -807,7 +799,12 @@ void ModifyReturnedValue(RestartData *co + */ + WindowInfo *MacroRunWindow(void) + { +- return InitiatingWindow; ++ if (Current) { ++ return InitiatingWindow; ++ } ++ else { ++ return NULL; ++ } + } + + /* +@@ -817,7 +814,12 @@ WindowInfo *MacroRunWindow(void) + */ + WindowInfo *MacroFocusWindow(void) + { +- return FocusWindow; ++ if (Current) { ++ return FocusWindow; ++ } ++ else { ++ return NULL; ++ } + } + + /* +@@ -826,7 +828,12 @@ WindowInfo *MacroFocusWindow(void) + */ + void SetMacroFocusWindow(WindowInfo *window) + { +- FocusWindow = window; ++ if (Current) { ++ FocusWindow = window; ++ } ++ else { ++ fprintf(stderr, "NEdit: setting FocusWindow while not running a macro\n"); ++ } + } + + /* +@@ -1319,24 +1326,11 @@ void GarbageCollectStrings(void) + /* + ** Save and restore execution context to data structure "context" + */ +-static void saveContext(RestartData *context) ++static RestartData *setContext(RestartData *new) + { +- context->stack = TheStack; +- context->stackP = StackP; +- context->frameP = FrameP; +- context->pc = PC; +- context->runWindow = InitiatingWindow; +- context->focusWindow = FocusWindow; +-} +- +-static void restoreContext(RestartData *context) +-{ +- TheStack = context->stack; +- StackP = context->stackP; +- FrameP = context->frameP; +- PC = context->pc; +- InitiatingWindow = context->runWindow; +- FocusWindow = context->focusWindow; ++ RestartData *old = Current; ++ Current = new; ++ return old; + } + + static void freeSymbolList(Symbol *symList) +@@ -1423,17 +1417,6 @@ static void addToGlobalSymTab(Symbol *sy + } \ + } while (0) + +-#define FRAME_GET_ITEM(xIndex) FP_GET_ITEM(FrameP,xIndex) +-#define FRAME_GET_ARG_ARRAY() FP_GET_ARG_ARRAY(FrameP) +-#define FRAME_GET_ARG_COUNT() FP_GET_ARG_COUNT(FrameP) +-#define FRAME_GET_OLD_FP() FP_GET_OLD_FP(FrameP) +-#define FRAME_GET_RET_PC() FP_GET_RET_PC(FrameP) +-#define FRAME_GET_PROG() FP_GET_PROG(FrameP) +-#define FRAME_ARG_START_INDEX() FP_ARG_START_INDEX(FrameP) +-#define FRAME_GET_ARG_N(xN) FP_GET_ARG_N(FrameP,xN) +-#define FRAME_GET_SYM_N(xN) FP_GET_SYM_N(FrameP,xN) +-#define FRAME_GET_SYM_VAL(xSym) FP_GET_SYM_VAL(FrameP,xSym) +- + /* true, if you can pop n values */ + #define OK_TO_POP(n) \ + ((StackP - (n)) >= TheStack) +@@ -1447,7 +1430,7 @@ static void addToGlobalSymTab(Symbol *sy + + /* true, if you can push n values */ + #define OK_TO_PUSH(n) \ +- (StackP + (n) <= &TheStack[STACK_SIZE]) ++ (StackP + (n) <= (TheStack + STACK_SIZE)) + + #define PUSH_CHECK(n) \ + do { \ +@@ -1599,11 +1582,11 @@ static int pushSymVal(void) + GET_SYM(s); + + if (s->type == LOCAL_SYM) { +- symVal = FRAME_GET_SYM_VAL(s); ++ symVal = FP_GET_SYM_VAL(FrameP, s); + } else if (s->type == GLOBAL_SYM || s->type == CONST_SYM) { + symVal = s->value; + } else if (s->type == ARG_SYM) { +- nArgs = FRAME_GET_ARG_COUNT(); ++ nArgs = FP_GET_ARG_COUNT(FrameP); + argNum = s->value.val.n; + if (argNum >= nArgs) { + EXEC_ERROR("referenced undefined argument: %s", s->name); +@@ -1613,12 +1596,11 @@ static int pushSymVal(void) + symVal.val.n = nArgs; + } + else { +- symVal = FRAME_GET_ARG_N(argNum); ++ symVal = FP_GET_ARG_N(FrameP, argNum); + } + } else if (s->type == PROC_VALUE_SYM) { +- char *errMsg; +- if (!(s->value.val.subr)(FocusWindow, NULL, 0, +- &symVal, &errMsg)) { ++ char *errMsg; ++ if (!s->value.val.subr(FocusWindow, NULL, 0, &symVal, &errMsg)) { + EXEC_ERROR(errMsg, s->name); + } + } else if (s->type == C_FUNCTION_SYM +@@ -1667,12 +1649,12 @@ static int pushArgVal(void) + + POP_INT(argNum); + --argNum; +- nArgs = FRAME_GET_ARG_COUNT(); ++ nArgs = FP_GET_ARG_COUNT(FrameP); + if (argNum >= nArgs || argNum < 0) { + EXEC_ERROR("referenced undefined argument: $args[%s]", + longAsStr(argNum + 1)); + } +- PUSH(FRAME_GET_ARG_N(argNum)); ++ PUSH(FP_GET_ARG_N(FrameP, argNum)); + return STAT_OK; + } + +@@ -1681,7 +1663,7 @@ static int pushArgCount(void) + DISASM_RT(); + STACKDUMP(0, 3); + +- PUSH_INT(FRAME_GET_ARG_COUNT()); ++ PUSH_INT(FP_GET_ARG_COUNT(FrameP)); + return STAT_OK; + } + +@@ -1694,8 +1676,8 @@ static int pushArgArray(void) + DISASM_RT(); + STACKDUMP(0, 3); + +- nArgs = FRAME_GET_ARG_COUNT(); +- argArray = &FRAME_GET_ARG_ARRAY(); ++ nArgs = FP_GET_ARG_COUNT(FrameP); ++ argArray = &FP_GET_ARG_ARRAY(FrameP); + if (argArray->tag != ARRAY_TAG) { + /* we require a real array in the argArray position */ + argArray->tag = ARRAY_TAG; +@@ -1706,7 +1688,7 @@ static int pushArgArray(void) + if (needArgCopy || (nArgs && !ArrayGet(argArray, (char *)"1", &argVal))) { + /* load arguments from positional arg list if not already done */ + for (argNum = 0; argNum < nArgs; ++argNum) { +- argVal = FRAME_GET_ARG_N(argNum); ++ argVal = FP_GET_ARG_N(FrameP, argNum); + if (!ArrayInsert(argArray, AllocStringOfNumber(argNum + 1), + &argVal)) { + EXEC_ERROR("argument array insertion failure", NULL); +@@ -1739,7 +1721,7 @@ static int pushArraySymVal(void) + GET_IMMED(initEmpty); + + if (sym->type == LOCAL_SYM) { +- dataPtr = &FRAME_GET_SYM_VAL(sym); ++ dataPtr = &FP_GET_SYM_VAL(FrameP, sym); + } + else if (sym->type == GLOBAL_SYM) { + dataPtr = &sym->value; +@@ -2063,7 +2045,7 @@ static int assign(void) + } + + if (sym->type == LOCAL_SYM) { +- dataPtr = &FRAME_GET_SYM_VAL(sym); ++ dataPtr = &FP_GET_SYM_VAL(FrameP, sym); + } + else { + dataPtr = &sym->value; +@@ -2388,8 +2370,8 @@ static int eq(void) + /* negated eq() call */ + static int ne(void) + { +- eq(); +- return not(); ++ int status = eq(); ++ return (status == STAT_OK) ? not() : status; + } + + /* +@@ -2716,7 +2698,6 @@ static int callSubroutineFromSymbol(Symb + static DataValue noValue = {NO_TAG, {0}}; + DataValue argArray = noValue; + Program *prog; +- char *errMsg; + int haveNamedArgs = (nArgs < 0); + DataValue *symValPtr = NULL; + +@@ -2726,7 +2707,7 @@ static int callSubroutineFromSymbol(Symb + } + + if (sym->type == LOCAL_SYM) { +- symValPtr = &FRAME_GET_SYM_VAL(sym); ++ symValPtr = &FP_GET_SYM_VAL(FrameP, sym); + } else if (sym->type == GLOBAL_SYM) { + symValPtr = &sym->value; + } +@@ -2744,6 +2725,7 @@ static int callSubroutineFromSymbol(Symb + */ + if (sym->type == C_FUNCTION_SYM) { + DataValue result; ++ char *errMsg; + + PUSH(argArray); /* push dummy named arg array */ + +@@ -2752,9 +2734,9 @@ static int callSubroutineFromSymbol(Symb + + /* Call the function and check for preemption */ + PreemptRequest = False; +- if (!sym->value.val.subr(FocusWindow, StackP, +- nArgs, &result, &errMsg)) ++ if (!sym->value.val.subr(FocusWindow, StackP, nArgs, &result, &errMsg)) { + EXEC_ERROR(errMsg, sym->name); ++ } + PUSH_RET_VAL(result); + return PreemptRequest ? STAT_PREEMPT : STAT_OK; + } +@@ -2767,15 +2749,10 @@ static int callSubroutineFromSymbol(Symb + ** values which are already there. + */ + if (sym->type == MACRO_FUNCTION_SYM) { +- RestartData context; +- int status; + prog = sym->value.val.prog; + prog->refcount++; + /* -nArgs means 'arguments are on stack' */ +- saveContext(&context); +- status = setupFrame(&context, prog, -nArgs, NULL, argArray, sym->name); +- restoreContext(&context); +- return status; ++ return setupFrame(Current, prog, -nArgs, NULL, argArray, sym->name); + } + + /* +@@ -3070,7 +3047,7 @@ static int returnValOrNone(int valOnStac + static DataValue noValue = {NO_TAG, {0}}; + + DISASM_RT(); +- STACKDUMP(StackP - FrameP + FRAME_GET_ARG_COUNT() + FP_TO_ARGS_DIST, 3); ++ STACKDUMP(StackP - FrameP + FP_GET_ARG_COUNT(FrameP) + FP_TO_ARGS_DIST, 3); + + /* return value is on the stack */ + if (valOnStack) { +@@ -3080,7 +3057,7 @@ static int returnValOrNone(int valOnStac + retVal = noValue; + } + +- PC = rewindFrame(&FrameP, &StackP); ++ rewindFrame(Current); + + /* push returned value, if requsted */ + PUSH_RET_VAL(retVal); +@@ -3687,7 +3664,7 @@ static int beginArrayIter(void) + POP(arrayVal); + + if (iterator->type == LOCAL_SYM) { +- iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); ++ iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator); + } + else { + EXEC_ERROR("bad temporary iterator: %s", iterator->name); +@@ -3750,7 +3727,7 @@ static int arrayIter(void) + GET_BRANCH(branchAddr); + + if (keySym->type == LOCAL_SYM) { +- keyValPtr = &FRAME_GET_SYM_VAL(keySym); ++ keyValPtr = &FP_GET_SYM_VAL(FrameP, keySym); + } + else if (keySym->type == GLOBAL_SYM) { + keyValPtr = &(keySym->value); +@@ -3762,7 +3739,7 @@ static int arrayIter(void) + + if (withVal) { + if (valSym->type == LOCAL_SYM) { +- valPtr = &FRAME_GET_SYM_VAL(valSym); ++ valPtr = &FP_GET_SYM_VAL(FrameP, valSym); + } + else if (valSym->type == GLOBAL_SYM) { + valPtr = &(valSym->value); +@@ -3774,7 +3751,7 @@ static int arrayIter(void) + } + + if (iterator->type == LOCAL_SYM) { +- iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); ++ iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator); + } + else { + EXEC_ERROR("bad temporary iterator: %s", iterator->name); +@@ -3823,7 +3800,7 @@ static int beginArrayMultiIterArray(void + PEEK_INT(nDims, 0); + + if (iterator->type == LOCAL_SYM) { +- iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); ++ iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator); + } + else { + EXEC_ERROR("bad temporary iterator: %s", iterator->name); +@@ -3930,7 +3907,7 @@ static int arrayMultiIterArray(void) + PEEK_INT(nDims, 0); + + if (keyArraySym->type == LOCAL_SYM) { +- keyArrayPtr = &FRAME_GET_SYM_VAL(keyArraySym); ++ keyArrayPtr = &FP_GET_SYM_VAL(FrameP, keyArraySym); + } + else if (keyArraySym->type == GLOBAL_SYM) { + keyArrayPtr = &(keyArraySym->value); +@@ -3943,7 +3920,7 @@ static int arrayMultiIterArray(void) + + if (withVal) { + if (valSym->type == LOCAL_SYM) { +- valPtr = &FRAME_GET_SYM_VAL(valSym); ++ valPtr = &FP_GET_SYM_VAL(FrameP, valSym); + } + else if (valSym->type == GLOBAL_SYM) { + valPtr = &valSym->value; +@@ -3955,7 +3932,7 @@ static int arrayMultiIterArray(void) + } + + if (iterator->type == LOCAL_SYM) { +- iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); ++ iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator); + } + else { + EXEC_ERROR("bad temporary iterator: %s", iterator->name); +diff --quilt old/source/interpret.h new/source/interpret.h +--- old/source/interpret.h ++++ new/source/interpret.h +@@ -121,12 +121,13 @@ typedef struct ProgramTag { + + /* Information needed to re-start a preempted macro */ + typedef struct { +- DataValue *stack; ++ DataValue stack[STACK_SIZE]; + DataValue *stackP; + DataValue *frameP; + Inst *pc; + WindowInfo *runWindow; + WindowInfo *focusWindow; ++ char *errMsg; + } RestartData; + + /* state of the accumulator (aka compiler) */ diff --git a/handle-error-in-RunMacroAsSubrCall.patch b/handle-error-in-RunMacroAsSubrCall.patch index f87bdd0..bcc1568 100644 --- a/handle-error-in-RunMacroAsSubrCall.patch +++ b/handle-error-in-RunMacroAsSubrCall.patch @@ -8,7 +8,7 @@ diff --quilt old/source/macro.c new/source/macro.c --- old/source/macro.c +++ new/source/macro.c -@@ -1064,8 +1064,15 @@ static void runMacro(WindowInfo *window, +@@ -1065,8 +1065,15 @@ static void runMacro(WindowInfo *window, instead of starting a new one, so we don't have to keep a separate context, and the macros will serialize themselves automatically */ if (window->macroCmdData != NULL) { @@ -219,7 +219,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c XtFree((char *)context->stack); XtFree((char *)context); } -@@ -2726,12 +2759,15 @@ static int callSubroutineFromSymbol(Symb +@@ -2728,12 +2761,15 @@ static int callSubroutineFromSymbol(Symb ** values which are already there. */ if (sym->type == MACRO_FUNCTION_SYM) { diff --git a/highlight_calltip_line.patch b/highlight_calltip_line.patch index 561ef25..f8b6fc3 100644 --- a/highlight_calltip_line.patch +++ b/highlight_calltip_line.patch @@ -241,7 +241,7 @@ diff --quilt old/source/macro.c new/source/macro.c /* DISABLED for 5.4 { "set_backlight_string", setBacklightStringMS }, */ -@@ -3443,6 +3446,57 @@ static int killCalltipMS(WindowInfo *win +@@ -3444,6 +3447,57 @@ static int killCalltipMS(WindowInfo *win } /* diff --git a/indexNotInArray.diff b/indexNotInArray.diff index 5a7475e..d8cfa75 100644 --- a/indexNotInArray.diff +++ b/indexNotInArray.diff @@ -20,7 +20,7 @@ The Enhancements to NEdit macro parsing patch includes this small change. diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -583,7 +583,12 @@ numexpr: NUMBER { +@@ -587,7 +587,12 @@ numexpr: NUMBER { | numexpr IN numexpr { ADD_OP(OP_IN_ARRAY); } diff --git a/macroJoin.diff b/macroJoin.diff index 59871cb..77d9374 100644 --- a/macroJoin.diff +++ b/macroJoin.diff @@ -26,7 +26,7 @@ diff --quilt old/source/macro.c new/source/macro.c { NULL, NULL } /* sentinel */ }; -@@ -4814,6 +4817,126 @@ static int splitMS(WindowInfo *window, D +@@ -4815,6 +4818,126 @@ static int splitMS(WindowInfo *window, D } /* diff --git a/macroSemicolons.diff b/macroSemicolons.diff index 584012b..06ed6d9 100644 --- a/macroSemicolons.diff +++ b/macroSemicolons.diff @@ -16,7 +16,7 @@ The Enhancements to NEdit macro parsing patch includes this change. diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -103,6 +103,7 @@ static int nextSymIsField = 0; +@@ -104,6 +104,7 @@ static int nextSymIsField = 0; %nonassoc IF_NO_ELSE %nonassoc ELSE @@ -24,10 +24,10 @@ diff --quilt old/source/parse.y new/source/parse.y %nonassoc SYMBOL ARG_LOOKUP %right '=' ADDEQ SUBEQ MULEQ DIVEQ MODEQ ANDEQ OREQ %left CONCAT -@@ -187,7 +188,10 @@ define: DEFINE { - $5.sym->value.val.prog = prog; +@@ -191,7 +192,10 @@ define: definekw blank definesym bla } ; + -stmt: simpstmt '\n' blank +stmtend: '\n' | ';' + ; @@ -36,7 +36,7 @@ diff --quilt old/source/parse.y new/source/parse.y | IF '(' cond ')' blank block %prec IF_NO_ELSE { SET_BR_OFF($3, GetPC()); } -@@ -213,22 +217,22 @@ stmt: simpstmt '\n' blank +@@ -217,22 +221,22 @@ stmt: simpstmt '\n' blank SET_BR_OFF($5+5, GetPC()); FillLoopAddrs(GetPC(), $5+2); } diff --git a/macroSplit.diff b/macroSplit.diff index 23c8aea..ded45e7 100644 --- a/macroSplit.diff +++ b/macroSplit.diff @@ -38,7 +38,7 @@ to make a == b at the end. which is trickier (albeit more general). diff --quilt old/source/macro.c new/source/macro.c --- old/source/macro.c +++ new/source/macro.c -@@ -3880,14 +3880,39 @@ static int stringCompareMS(WindowInfo *w +@@ -3881,14 +3881,39 @@ static int stringCompareMS(WindowInfo *w } /* @@ -86,7 +86,7 @@ diff --quilt old/source/macro.c new/source/macro.c */ static int splitMS(WindowInfo *window, DataValue *argList, int nArgs, -@@ -3900,8 +3925,13 @@ static int splitMS(WindowInfo *window, D +@@ -3901,8 +3926,13 @@ static int splitMS(WindowInfo *window, D char indexStr[TYPE_INT_STR_SIZE(int)], *allocIndexStr; DataValue element; int elementLen; @@ -102,7 +102,7 @@ diff --quilt old/source/macro.c new/source/macro.c return(wrongNArgsErr(errMsg)); } if (!readStringArg(argList[0], &sourceStr, stringStorage[0], errMsg)) { -@@ -3920,16 +3950,40 @@ static int splitMS(WindowInfo *window, D +@@ -3921,16 +3951,40 @@ static int splitMS(WindowInfo *window, D *errMsg = "second argument must be a non-empty string: %s"; return(False); } @@ -149,7 +149,7 @@ diff --quilt old/source/macro.c new/source/macro.c result->tag = ARRAY_TAG; result->val.arrayPtr = ArrayNew(); -@@ -3946,9 +4000,13 @@ static int splitMS(WindowInfo *window, D +@@ -3947,9 +4001,13 @@ static int splitMS(WindowInfo *window, D return(False); } strcpy(allocIndexStr, indexStr); @@ -166,7 +166,7 @@ diff --quilt old/source/macro.c new/source/macro.c elementEnd = found ? foundStart : strLength; elementLen = elementEnd - lastEnd; element.tag = STRING_TAG; -@@ -3982,8 +4040,8 @@ static int splitMS(WindowInfo *window, D +@@ -3983,8 +4041,8 @@ static int splitMS(WindowInfo *window, D } strcpy(allocIndexStr, indexStr); element.tag = STRING_TAG; @@ -177,7 +177,7 @@ diff --quilt old/source/macro.c new/source/macro.c element.val.str.rep = PERM_ALLOC_STR(""); element.val.str.len = 0; -@@ -4014,7 +4072,7 @@ static int splitMS(WindowInfo *window, D +@@ -4015,7 +4073,7 @@ static int splitMS(WindowInfo *window, D found = SearchString(sourceStr, splitStr, SEARCH_FORWARD, searchType, False, strLength, &foundStart, &foundEnd, NULL, NULL, GetWindowDelimiters(window)); diff --git a/macroStringLiterals3.diff b/macroStringLiterals3.diff index a40ca9d..2d61f40 100644 --- a/macroStringLiterals3.diff +++ b/macroStringLiterals3.diff @@ -124,7 +124,7 @@ diff --quilt old/source/parse.y new/source/parse.y static char *ErrMsg; static char *InPtr; -@@ -695,12 +696,6 @@ static int yylex(void) +@@ -697,12 +698,6 @@ static int yylex(void) int i, len; Symbol *s; static DataValue value = {NO_TAG, {0}}; @@ -137,7 +137,7 @@ diff --quilt old/source/parse.y new/source/parse.y int result; skipWhitespace(); -@@ -761,115 +756,10 @@ static int yylex(void) +@@ -763,115 +758,10 @@ static int yylex(void) } nextSymIsField = 0; @@ -257,7 +257,7 @@ diff --quilt old/source/parse.y new/source/parse.y } /* process remaining two character tokens or return single char as token */ -@@ -973,6 +863,177 @@ static Symbol *matchesActionRoutine(char +@@ -975,6 +865,177 @@ static Symbol *matchesActionRoutine(char } /* diff --git a/macro_hooks.patch b/macro_hooks.patch index b8e0138..d1263f9 100644 --- a/macro_hooks.patch +++ b/macro_hooks.patch @@ -183,7 +183,7 @@ diff --quilt old/source/highlightData.c new/source/highlightData.c diff --quilt old/source/macro.c new/source/macro.c --- old/source/macro.c +++ new/source/macro.c -@@ -1212,8 +1212,10 @@ void SafeGC(void) +@@ -1213,8 +1213,10 @@ void SafeGC(void) WindowInfo *win; for (win=WindowList; win!=NULL; win=win->next) @@ -196,7 +196,7 @@ diff --quilt old/source/macro.c new/source/macro.c GarbageCollectStrings(); } -@@ -6020,3 +6022,60 @@ static int readStringArg(DataValue dv, c +@@ -6021,3 +6023,60 @@ static int readStringArg(DataValue dv, c *errMsg = "%s called with unknown object"; return False; } diff --git a/matching_patterns.patch b/matching_patterns.patch index ab0fc01..e9dc11e 100644 --- a/matching_patterns.patch +++ b/matching_patterns.patch @@ -542,7 +542,7 @@ diff --quilt old/source/macro.c new/source/macro.c { "$overtype_mode", overTypeModeMV }, { "$read_only", readOnlyMV }, { "$locked", lockedMV }, -@@ -4529,16 +4533,6 @@ static int showMatchingMV(WindowInfo *wi +@@ -4530,16 +4534,6 @@ static int showMatchingMV(WindowInfo *wi return True; } @@ -559,7 +559,7 @@ diff --quilt old/source/macro.c new/source/macro.c static int overTypeModeMV(WindowInfo *window, DataValue *argList, int nArgs, DataValue *result, char **errMsg) { -@@ -5946,6 +5940,93 @@ static int getPatternAtPosMS(WindowInfo +@@ -5947,6 +5941,93 @@ static int getPatternAtPosMS(WindowInfo HighlightStyleOfCode(window, patCode), bufferPos); } diff --git a/multi-dim-key-iterator-arr.patch b/multi-dim-key-iterator-arr.patch index 324f046..2ae9c0d 100644 --- a/multi-dim-key-iterator-arr.patch +++ b/multi-dim-key-iterator-arr.patch @@ -270,7 +270,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** determine if a key or keys exists in an array ** if the left argument is a string or integer a single check is performed ** if the key exists, 1 is pushed onto the stack, otherwise 0 -@@ -3981,7 +4209,8 @@ static void disasmInternal(Inst *inst, i +@@ -4005,7 +4233,8 @@ static void disasmInternal(Inst *inst, i printd(" %s args[] (?)", inst[i+1].sym->name); ++i; } @@ -280,7 +280,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c printd(" %s in", inst[i+1].sym->name); ++i; } -@@ -4006,6 +4235,27 @@ static void disasmInternal(Inst *inst, i +@@ -4030,6 +4259,27 @@ static void disasmInternal(Inst *inst, i i += 5; } } @@ -311,7 +311,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 -@@ -268,6 +268,41 @@ stmt: ';' blank +@@ -270,6 +270,41 @@ stmt: ';' blank SET_BR_OFF($9+7, GetPC()); FillLoopAddrs(GetPC(), $9+2); } @@ -353,7 +353,7 @@ diff --quilt old/source/parse.y new/source/parse.y | BREAK stmtend blank { ADD_OP(OP_BRANCH); ADD_BR_OFF(0); if (AddBreakAddr(GetPC()-1)) { -@@ -714,6 +749,13 @@ numexpr: '(' blank expr blank ')' +@@ -716,6 +751,13 @@ numexpr: '(' blank expr blank ')' | arrconstr ; diff --git a/nmvarNEDIT_HOME2.diff b/nmvarNEDIT_HOME2.diff index 05dc9d3..2ffbd40 100644 --- a/nmvarNEDIT_HOME2.diff +++ b/nmvarNEDIT_HOME2.diff @@ -37,7 +37,7 @@ diff --quilt old/source/macro.c new/source/macro.c { NULL, NULL } /* sentinel */ }; -@@ -4761,6 +4764,28 @@ static int versionMV(WindowInfo* window, +@@ -4762,6 +4765,28 @@ static int versionMV(WindowInfo* window, } /* diff --git a/op-not-func-in-Inst.patch b/op-not-func-in-Inst.patch index e17a9c0..0d8e2b9 100644 --- a/op-not-func-in-Inst.patch +++ b/op-not-func-in-Inst.patch @@ -78,7 +78,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH(retVal); PC++; } -@@ -4418,47 +4426,58 @@ static void disasmInternal(Inst *inst, i +@@ -4442,47 +4450,58 @@ static void disasmInternal(Inst *inst, i #include "ops.h" #undef OP }; @@ -168,7 +168,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c int args = inst[i+2].value; printd(" %s", inst[i+1].sym->name); if (args < 0) { -@@ -4469,7 +4488,9 @@ static void disasmInternal(Inst *inst, i +@@ -4493,7 +4512,9 @@ static void disasmInternal(Inst *inst, i } i += 2; } @@ -179,7 +179,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c int args = inst[i+2].value; if (args < 0) { printd(" %d+args[] (%d)", -args - 1, args); -@@ -4479,85 +4500,95 @@ static void disasmInternal(Inst *inst, i +@@ -4503,85 +4524,95 @@ static void disasmInternal(Inst *inst, i } ++i; } diff --git a/parse-define.patch b/parse-define.patch index 439dc68..e243789 100644 --- a/parse-define.patch +++ b/parse-define.patch @@ -1,5 +1,5 @@ From: Bert Wesarg -Subject: [PATCH v6] parse "define" in the parser +Subject: [PATCH v8] parse "define" in the parser This removes the ugly parsing of the "define" keyword. It solves this by saving and restoring the state of the program accumulation. This solves @@ -14,8 +14,13 @@ in the same scope, i.e. this works now: t_print(a "\n") ChangeLog: + v8: + * restore behavior in readCheckMacroString. I.e. if the window has a + context, don't wait for completion + v7: + * avoid intra-actions v6: - * never asign to a $n variable in yacc + * never assign to a $n variable in yacc v5: * fix memcpy sizeof arguments v4: @@ -32,13 +37,13 @@ ChangeLog: source/interpret.c | 24 ++++++-- source/interpret.h | 16 +++++ - source/macro.c | 139 ++++++++------------------------------------------- + source/macro.c | 140 ++++++++------------------------------------------- source/nedit.c | 2 source/parse.h | 2 - source/parse.y | 79 +++++++++++++++++++++++----- + source/parse.y | 83 +++++++++++++++++++++++++----- source/smartIndent.c | 8 +- source/userCmds.c | 4 - - 8 files changed, 126 insertions(+), 148 deletions(-) + 8 files changed, 131 insertions(+), 148 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c @@ -162,7 +167,7 @@ diff --quilt old/source/macro.c new/source/macro.c if (prog == NULL) { fprintf(stderr, "NEdit internal error, learn/replay macro syntax error: %s\n", -@@ -851,126 +851,31 @@ int CheckMacroString(Widget dialogParent +@@ -851,126 +851,32 @@ int CheckMacroString(Widget dialogParent static int readCheckMacroString(Widget dialogParent, char *string, WindowInfo *runWindow, const char *errIn, char **errPos) { @@ -289,10 +294,11 @@ diff --quilt old/source/macro.c new/source/macro.c - while (NULL != (prog = (Program*) Pop(progStack))) { - RunMacroAsSubrCall(prog); + if (runWindow != NULL) { ++ int waitForCompletion = runWindow->macroCmdData == NULL; + XEvent nextEvent; + /* runMacro() is responsable for freeing prog */ + runMacro(runWindow, prog); -+ while (runWindow->macroCmdData != NULL) { ++ while (waitForCompletion && runWindow->macroCmdData != NULL) { + XtAppNextEvent(XtWidgetToApplicationContext(runWindow->shell), + &nextEvent); + ServerDispatchEvent(&nextEvent); @@ -308,7 +314,7 @@ diff --quilt old/source/macro.c new/source/macro.c return True; } -@@ -1230,7 +1135,7 @@ void DoMacro(WindowInfo *window, const c +@@ -1230,7 +1136,7 @@ void DoMacro(WindowInfo *window, const c tMacro[macroLen+1] = '\0'; /* Parse the macro and report errors if it fails */ @@ -317,7 +323,7 @@ diff --quilt old/source/macro.c new/source/macro.c if (prog == NULL) { ParseError(window->shell, tMacro, stoppedAt, errInName, errMsg); XtFree(tMacro); -@@ -1494,7 +1399,7 @@ selEnd += $text_length - startLength\n}\ +@@ -1494,7 +1400,7 @@ selEnd += $text_length - startLength\n}\ sprintf(loopedCmd, loopMacro, how, command); /* Parse the resulting macro into an executable program "prog" */ @@ -352,7 +358,7 @@ diff --quilt old/source/parse.h new/source/parse.h diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y +++ new/source/parse.y -@@ -75,16 +75,22 @@ static char *InPtr; +@@ -75,19 +75,26 @@ static char *InPtr; extern Inst *LoopStack[]; /* addresses of break, cont stmts */ extern Inst **LoopStackPtr; /* to fill at the end of a loop */ @@ -376,16 +382,20 @@ diff --quilt old/source/parse.y new/source/parse.y %type arglist %type cond comastmts for while else and or arrayexpr %type evalsym -@@ -111,7 +117,7 @@ extern Inst **LoopStackPtr; /* to fill ++%type definesym + + %nonassoc IF_NO_ELSE + %nonassoc ELSE +@@ -111,7 +118,7 @@ extern Inst **LoopStackPtr; /* to fill %% /* Rules */ -program: blank stmts { -+program: blank allstmts { ++program: blank topstmts { ADD_OP(OP_RETURN_NO_VAL); return 0; } | blank '{' blank stmts '}' { -@@ -124,13 +130,57 @@ program: blank stmts { +@@ -124,13 +131,60 @@ program: blank stmts { return 1; } ; @@ -399,52 +409,55 @@ diff --quilt old/source/parse.y new/source/parse.y stmts: stmt | stmts stmt ; -+allstmts: allstmt -+ | allstmts allstmt ++topstmts: topstmt ++ | topstmts topstmt + ; -+allstmt: stmt ++topstmt: stmt + | define + ; -+define: DEFINE { ++ ++definekw: DEFINE { + /* bail out early, in case of unallowed "define" */ + if (!AllowDefine) { + yyerror("macro definitions not allowed"); YYERROR; + } + } -+ blank SYMBOL { -+ $$.acc = (AccumulatorData *) -+ XtMalloc(sizeof(AccumulatorData)); -+ /* we can't really be sure, that we not overwrite any -+ ** wrong symbol -+ ** -+ ** we should only overwrite installed MACRO_FUNCTION_SYM -+ ** and this is questionable. -+ */ -+ if ($4->type == MACRO_FUNCTION_SYM) { -+ FreeProgram($4->value.val.prog); -+ } -+ else if ($4->type == LOCAL_SYM || -+ $4->type == GLOBAL_SYM) { -+ /* newly created sym, or we overwrite a local sym */; -+ } else { -+ yyerror("try to override built-in subroutine"); YYERROR; -+ } -+ $$.sym = PromoteToGlobal($4); -+ BeginCreatingProgram($$.acc); ++ ; ++definesym: SYMBOL { ++ $$.acc = (AccumulatorData *)XtMalloc(sizeof(AccumulatorData)); ++ /* we can't really be sure, that we not overwrite any ++ ** wrong symbol ++ ** ++ ** we should only overwrite installed MACRO_FUNCTION_SYM ++ ** and this is questionable. ++ */ ++ if ($1->type == MACRO_FUNCTION_SYM) { ++ FreeProgram($1->value.val.prog); ++ } ++ else if ($1->type == LOCAL_SYM || ++ $1->type == GLOBAL_SYM) { ++ /* newly created sym, or we overwrite a local sym */; ++ } else { ++ yyerror("try to override built-in subroutine"); YYERROR; ++ } ++ $$.sym = PromoteToGlobal($1); ++ BeginCreatingProgram($$.acc); + } -+ blank blockwb { -+ ADD_OP(OP_RETURN_NO_VAL); -+ Program *prog = FinishCreatingProgram($5.acc); -+ XtFree((char *)$5.acc); -+ $5.sym->type = MACRO_FUNCTION_SYM; -+ $5.sym->value.tag = NO_TAG; -+ $5.sym->value.val.prog = prog; ++ ; ++define: definekw blank definesym blank blockwb { ++ ADD_OP(OP_RETURN_NO_VAL); ++ Program *prog = FinishCreatingProgram($3.acc); ++ XtFree((char *)$3.acc); ++ $3.sym->type = MACRO_FUNCTION_SYM; ++ $3.sym->value.tag = NO_TAG; ++ $3.sym->value.val.prog = prog; + } + ; ++ stmt: simpstmt '\n' blank | IF '(' cond ')' blank block %prec IF_NO_ELSE { SET_BR_OFF($3, GetPC()); -@@ -474,17 +524,20 @@ blank: /* nothing */ +@@ -474,17 +528,20 @@ blank: /* nothing */ ** as a pointer to a static string in msg, and the length of the string up ** to where parsing failed in stoppedAt. */ @@ -467,7 +480,7 @@ diff --quilt old/source/parse.y new/source/parse.y /* call yyparse to parse the string and check for success. If the parse failed, return the error message and string index (the grammar aborts -@@ -493,7 +546,8 @@ Program *ParseMacro(char *expr, char **m +@@ -493,7 +550,8 @@ Program *ParseMacro(char *expr, char **m if (yyparse()) { *msg = ErrMsg; *stoppedAt = InPtr; @@ -477,7 +490,7 @@ diff --quilt old/source/parse.y new/source/parse.y #if YYDEBUG yydebug = oldyydebug; -@@ -503,7 +557,8 @@ Program *ParseMacro(char *expr, char **m +@@ -503,7 +561,8 @@ Program *ParseMacro(char *expr, char **m } /* get the newly created program */ @@ -487,7 +500,7 @@ diff --quilt old/source/parse.y new/source/parse.y /* parse succeeded */ *msg = ""; -@@ -566,9 +621,8 @@ static int yylex(void) +@@ -566,9 +625,8 @@ static int yylex(void) return NUMBER; } @@ -499,7 +512,7 @@ diff --quilt old/source/parse.y new/source/parse.y the ambiguity, handled in matchesActionRoutine. */ if (isalpha((unsigned char)*InPtr) || *InPtr == '$') { if ((s=matchesActionRoutine(&InPtr)) == NULL) { -@@ -591,10 +645,7 @@ static int yylex(void) +@@ -591,10 +649,7 @@ static int yylex(void) if (!strcmp(symName, "in")) return IN; if (!strcmp(symName, "$args")) return ARG_LOOKUP; if (!strcmp(symName, "delete") && follow_non_whitespace('(', SYMBOL, DELETE) == DELETE) return DELETE; diff --git a/parseEnhance2.diff b/parseEnhance2.diff index c7e87f6..3912eba 100644 --- a/parseEnhance2.diff +++ b/parseEnhance2.diff @@ -33,8 +33,8 @@ This patch adds the following features to NEdit's macro language: --- - source/parse.y | 455 +++++++++++++++++++++------------------------------------ - 1 file changed, 174 insertions(+), 281 deletions(-) + source/parse.y | 453 +++++++++++++++++++++------------------------------------ + 1 file changed, 172 insertions(+), 281 deletions(-) diff --quilt old/source/parse.y new/source/parse.y --- old/source/parse.y @@ -47,7 +47,7 @@ diff --quilt old/source/parse.y new/source/parse.y struct { AccumulatorData *acc; Symbol *sym; -@@ -95,10 +96,13 @@ static int nextSymIsField = 0; +@@ -95,11 +96,14 @@ static int nextSymIsField = 0; %token STRING SYMBOL FIELD %token NUMBER %token DELETE ARG_LOOKUP @@ -58,13 +58,14 @@ diff --quilt old/source/parse.y new/source/parse.y +%type arglistopt arglist catlist +%type cond comastmts comastmtlst for while do else and or arrayexpr mark %type evalsym + %type definesym +%type operassign incrdecr +%token '=' ADDEQ SUBEQ MULEQ DIVEQ MODEQ ANDEQ OREQ +%token INCR DECR %nonassoc IF_NO_ELSE %nonassoc ELSE -@@ -137,6 +141,7 @@ program: blank allstmts { +@@ -138,6 +142,7 @@ program: blank topstmts { return 1; } ; @@ -72,19 +73,8 @@ diff --quilt old/source/parse.y new/source/parse.y blockwb: '{' blank stmts '}' blank | '{' blank '}' blank ; -@@ -152,6 +157,7 @@ allstmts: allstmt - allstmt: stmt - | define - ; -+ - define: DEFINE { - /* bail out early, in case of unallowed "define" */ - if (!AllowDefine) { -@@ -188,34 +194,43 @@ define: DEFINE { - $5.sym->value.val.prog = prog; - } - ; -+ +@@ -194,32 +199,40 @@ define: definekw blank definesym bla + stmtend: '\n' | ';' ; + @@ -133,7 +123,7 @@ diff --quilt old/source/parse.y new/source/parse.y } | BREAK stmtend blank { ADD_OP(OP_BRANCH); ADD_BR_OFF(0); -@@ -236,207 +251,109 @@ stmt: ';' blank +@@ -240,207 +253,109 @@ stmt: ';' blank ADD_OP(OP_RETURN_NO_VAL); } ; @@ -157,24 +147,24 @@ diff --quilt old/source/parse.y new/source/parse.y } - | evalsym ADDEQ expr { - ADD_OP(OP_ADD); ADD_OP(OP_ASSIGN); ADD_SYM($1); -- } ++ | evalsym operassign blank expr { ++ ADD_OP($2); ADD_OP(OP_ASSIGN); ADD_SYM($1); + } - | evalsym SUBEQ expr { - ADD_OP(OP_SUB); ADD_OP(OP_ASSIGN); ADD_SYM($1); -- } ++ | incrdecr blank SYMBOL { ++ ADD_OP(OP_PUSH_SYM); ADD_SYM($3); ADD_OP($1); ++ ADD_OP(OP_ASSIGN); ADD_SYM($3); + } - | evalsym MULEQ expr { - ADD_OP(OP_MUL); ADD_OP(OP_ASSIGN); ADD_SYM($1); - } - | evalsym DIVEQ expr { - ADD_OP(OP_DIV); ADD_OP(OP_ASSIGN); ADD_SYM($1); -+ | evalsym operassign blank expr { -+ ADD_OP($2); ADD_OP(OP_ASSIGN); ADD_SYM($1); - } +- } - | evalsym MODEQ expr { - ADD_OP(OP_MOD); ADD_OP(OP_ASSIGN); ADD_SYM($1); -+ | incrdecr blank SYMBOL { -+ ADD_OP(OP_PUSH_SYM); ADD_SYM($3); ADD_OP($1); -+ ADD_OP(OP_ASSIGN); ADD_SYM($3); - } +- } - | evalsym ANDEQ expr { - ADD_OP(OP_BIT_AND); ADD_OP(OP_ASSIGN); ADD_SYM($1); - } @@ -202,8 +192,9 @@ diff --quilt old/source/parse.y new/source/parse.y + | initarraylv '[' arglistopt ']' operassign blank expr { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED($3); - ADD_OP(OP_ADD); -- ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3); -- } ++ ADD_OP($5); + ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3); + } - | initarraylv '[' arglist ']' SUBEQ expr { - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED($3); - ADD_OP(OP_SUB); @@ -235,17 +226,20 @@ diff --quilt old/source/parse.y new/source/parse.y - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3); - } - | initarraylv '[' arglist ']' INCR { -- ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($3); ++ | initarraylv '[' arglistopt ']' incrdecr { + ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($3); - ADD_OP(OP_INCR); + ADD_OP($5); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3); } - | initarraylv '[' arglist ']' DECR { -+ | initarraylv '[' arglistopt ']' incrdecr { - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($3); +- ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($3); - ADD_OP(OP_DECR); -+ ADD_OP($5); - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3); +- ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3); ++ | incrdecr blank initarraylv '[' arglistopt ']' { ++ ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($5); ++ ADD_OP($1); ++ ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($5); } - | INCR initarraylv '[' arglist ']' { - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($4); @@ -259,29 +253,28 @@ diff --quilt old/source/parse.y new/source/parse.y - } - /* array.field assignment */ - | initarraylv dot field '=' expr { -- ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); -- } ++ /* array.field assignment, op-assignment, incr/decrement */ ++ | initarraylv dot field '=' blank expr { + ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); + } - | initarraylv dot field ADDEQ expr { - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED(1); - ADD_OP(OP_ADD); -- ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); -- } ++ | initarraylv dot field operassign blank expr { ++ ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1);ADD_IMMED(1); ++ ADD_OP($4); + ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); + } - | initarraylv dot field SUBEQ expr { - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED(1); - ADD_OP(OP_SUB); - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); -+ | incrdecr blank initarraylv '[' arglistopt ']' { -+ ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($5); -+ ADD_OP($1); -+ ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($5); - } +- } - | initarraylv dot field MULEQ expr { - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED(1); - ADD_OP(OP_MUL); -+ /* array.field assignment, op-assignment, incr/decrement */ -+ | initarraylv dot field '=' blank expr { - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); - } +- ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); +- } - | initarraylv dot field DIVEQ expr { - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED(1); - ADD_OP(OP_DIV); @@ -308,27 +301,24 @@ diff --quilt old/source/parse.y new/source/parse.y - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); - } - | initarraylv dot field DECR { -- ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED(1); ++ | initarraylv dot field incrdecr { + ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED(1); - ADD_OP(OP_DECR); -+ | initarraylv dot field operassign blank expr { -+ ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1);ADD_IMMED(1); + ADD_OP($4); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); } - | INCR initarraylv dot field { -+ | initarraylv dot field incrdecr { ++ | incrdecr blank initarraylv dot field { ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED(1); - ADD_OP(OP_INCR); -+ ADD_OP($4); ++ ADD_OP($1); ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); } - | DECR initarraylv dot field { -+ | incrdecr blank initarraylv dot field { - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED(1); +- ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED(1); - ADD_OP(OP_DECR); -+ ADD_OP($1); - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); - } +- ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1); +- } - | SYMBOL '(' arglist ')' { + /* function call */ + | SYMBOL '(' arglistopt ')' { @@ -403,7 +393,7 @@ diff --quilt old/source/parse.y new/source/parse.y ; expr: catlist { -@@ -445,20 +362,22 @@ expr: catlist { +@@ -449,20 +364,22 @@ expr: catlist { } } ; @@ -428,7 +418,7 @@ diff --quilt old/source/parse.y new/source/parse.y ADD_OP(OP_ARRAY_REF); ADD_IMMED($3); } | arraylv dot field { -@@ -480,134 +399,89 @@ arrayexpr: numexpr { +@@ -484,134 +401,89 @@ arrayexpr: numexpr { $$ = GetPC(); } ; @@ -578,14 +568,14 @@ diff --quilt old/source/parse.y new/source/parse.y -while: WHILE { +while: WHILE blank { ++ $$ = GetPC(); StartLoopAddrList(); ++ } ++ ; ++do: DO blank { $$ = GetPC(); StartLoopAddrList(); } ; -for: FOR { -+do: DO blank { -+ $$ = GetPC(); StartLoopAddrList(); -+ } -+ ; +for: FOR blank { StartLoopAddrList(); $$ = GetPC(); } @@ -609,7 +599,7 @@ diff --quilt old/source/parse.y new/source/parse.y and: AND { ADD_OP(OP_DUP); ADD_OP(OP_BRANCH_FALSE); $$ = GetPC(); ADD_BR_OFF(0); -@@ -618,17 +492,18 @@ or: OR { +@@ -622,17 +494,18 @@ or: OR { ADD_BR_OFF(0); } ; @@ -629,7 +619,7 @@ diff --quilt old/source/parse.y new/source/parse.y /* ** Parse a null terminated string and create a program from it (this is the ** parser entry point). The program created by this routine can be -@@ -694,19 +569,8 @@ Program *ParseMacro(char *expr, char **m +@@ -698,19 +571,8 @@ Program *ParseMacro(char *expr, char **m return prog; } @@ -650,7 +640,7 @@ diff --quilt old/source/parse.y new/source/parse.y /* skip whitespace, backslash-newline combinations, and comments, which are all considered whitespace */ for (;;) { -@@ -714,7 +578,8 @@ static int yylex(void) +@@ -718,7 +580,8 @@ static int yylex(void) InPtr += 2; else if (*InPtr == ' ' || *InPtr == '\t') InPtr++; @@ -660,7 +650,7 @@ diff --quilt old/source/parse.y new/source/parse.y while (*InPtr != '\n' && *InPtr != '\0') { /* Comments stop at escaped newlines */ if (*InPtr == '\\' && *(InPtr + 1) == '\n') { -@@ -722,10 +587,28 @@ static int yylex(void) +@@ -726,10 +589,28 @@ static int yylex(void) break; } InPtr++; @@ -690,7 +680,7 @@ diff --quilt old/source/parse.y new/source/parse.y /* return end of input at the end of the string */ if (*InPtr == '\0') { -@@ -755,6 +638,7 @@ static int yylex(void) +@@ -759,6 +640,7 @@ static int yylex(void) } *p = '\0'; if (!strcmp(symName, "while")) return WHILE; @@ -698,7 +688,7 @@ diff --quilt old/source/parse.y new/source/parse.y if (!strcmp(symName, "if")) return IF; if (!strcmp(symName, "else")) return ELSE; if (!strcmp(symName, "for")) return FOR; -@@ -894,7 +778,8 @@ static int yylex(void) +@@ -898,7 +780,8 @@ static int yylex(void) } /* process remaining two character tokens or return single char as token */ @@ -708,7 +698,7 @@ diff --quilt old/source/parse.y new/source/parse.y case '>': return follow('=', GE, GT); case '<': return follow('=', LE, LT); case '=': return follow('=', EQ, '='); -@@ -907,6 +792,14 @@ static int yylex(void) +@@ -911,6 +794,14 @@ static int yylex(void) case '/': return follow('=', DIVEQ, '/'); case '%': return follow('=', MODEQ, '%'); case '^': return POW; diff --git a/pass-context-to-ops.patch b/pass-context-to-ops.patch deleted file mode 100644 index 5da00f2..0000000 --- a/pass-context-to-ops.patch +++ /dev/null @@ -1,3096 +0,0 @@ ---- - - source/interpret.c | 295 +++++------- - source/interpret.h | 22 - source/macro.c | 1248 +++++++++++++++++++++++++++++++---------------------- - source/macro.h | 2 - 4 files changed, 898 insertions(+), 669 deletions(-) - -diff --quilt old/source/interpret.c new/source/interpret.c ---- old/source/interpret.c -+++ new/source/interpret.c -@@ -81,29 +81,29 @@ static const char CVSID[] = "$Id: interp - enum opStatusCodes {STAT_OK=2, STAT_DONE, STAT_ERROR, STAT_PREEMPT}; - - static int addLoopAddr(Inst *addr, char **msg); --static void saveContext(RestartData *context); --static void restoreContext(RestartData *context); - - /* the function prototype of a operand instruction */ --#define OP_FUNCTION(op) static int op(void) -+#define OP_FUNCTION(op) static int op(RestartData *context) - - #define OP(name, fn) OP_FUNCTION(fn); - #include "ops.h" - #undef OP --static int returnValOrNone(int valOnStack); --static int branchIf(Boolean trueOrFalse); --static int namedArg1orN(Boolean isFirst); -- --static int callSubroutineFromSymbol(Symbol *sym, int nArgs); --static int concatenateNwithSep(int nVals, const char *sep, char **result, -- int leaveParams); --static int makeArrayKeyFromArgs(int nArgs, char **keyString, int leaveParams); -+static int returnValOrNone(RestartData *context, int valOnStack); -+static int branchIf(RestartData *context, Boolean trueOrFalse); -+static int namedArg1orN(RestartData *context, Boolean isFirst); -+ -+static int callSubroutineFromSymbol(RestartData *context, Symbol *sym, -+ int nArgs); -+static int concatenateNwithSep(RestartData *context, int nVals, const char *sep, -+ char **result, int leaveParams); -+static int makeArrayKeyFromArgs(RestartData *context, int nArgs, -+ char **keyString, int leaveParams); - static void freeSymbolList(Symbol *symList); - static void addToGlobalSymTab(Symbol *sym); - static unsigned int hashNameWith(unsigned int hash, const char *name); - static unsigned int hashName(const char *name); --static int errCheck(const char *s); --static int execError(const char *s1, const char *s2); -+static int errCheck(RestartData *context, const char *s); -+static int execError(RestartData *context, const char *s1, const char *s2); - static rbTreeNode *arrayEmptyAllocator(void); - static rbTreeNode *arrayAllocateNode(rbTreeNode *src); - static int arrayEntryCopyToNode(rbTreeNode *dst, rbTreeNode *src); -@@ -136,9 +136,9 @@ static void disasmInternal(Inst *inst, i - #endif /* #ifndef DEBUG_ASSEMBLY */ - - #ifdef DEBUG_STACK /* for run-time instruction and stack trace */ --static void stackdump(int n, int extra); --static void stackdumpInternal(int n, int extra); --#define STACKDUMP(n, x) stackdump(n, (x) + 10) -+static void stackdump(RestartData *context, int n, int extra); -+static void stackdumpInternal(RestartData *context, int n, int extra); -+#define STACKDUMP(n, x) stackdump(context, n, (x) + 10) - #define DISASM_RT() disasm(NULL, PC - 1, 1) - #else /* #ifndef DEBUG_STACK */ - #define STACKDUMP(n, x) -@@ -178,13 +178,6 @@ static Inst **LoopStackPtr = LoopStack; - static const char *ProgramName = ""; - - /* Global data for the interpreter */ --static DataValue *TheStack; /* the stack */ --static DataValue *StackP; /* next free spot on stack */ --static DataValue *FrameP; /* frame pointer (start of local variables -- for the current subroutine invocation) */ --static Inst *PC; /* program counter during execution */ --static char *ErrMsg; /* global for returning error messages -- from executing functions */ - static WindowInfo - *InitiatingWindow = NULL; /* window from which macro was run */ - static WindowInfo *FocusWindow; /* window on which macro commands operate */ -@@ -536,7 +529,7 @@ static int setupFrame(RestartData *conte - - /* !OK_TO_PUSH(totalPushs) */ - if (!((context->stackP + totalPushs) <= &context->stack[STACK_SIZE])) { -- return execError(StackOverflowMsg, ""); -+ return execError(context, StackOverflowMsg, ""); - } - - /* Push arguments and caller information onto the stack */ -@@ -599,30 +592,30 @@ static int setupFrame(RestartData *conte - return STAT_OK; - } - --static Inst *rewindFrame(DataValue **frameP, DataValue **stackP) -+static void rewindFrame(RestartData *context) - { - /* get stored return information */ -- int nArgs = FP_GET_ARG_COUNT(*frameP); -- DataValue *newFrameP = FP_GET_OLD_FP(*frameP); -- Inst *newPC = FP_GET_RET_PC(*frameP); -- Program *prog = FP_GET_PROG(*frameP); -+ int nArgs = FP_GET_ARG_COUNT(context->frameP); -+ DataValue *newFrameP = FP_GET_OLD_FP(context->frameP); -+ Inst *newPC = FP_GET_RET_PC(context->frameP); -+ Program *prog = FP_GET_PROG(context->frameP); - - /* pop past local variables */ -- *stackP = *frameP; -+ context->stackP = context->frameP; - /* pop past arguments */ -- *stackP -= (FP_TO_ARGS_DIST + nArgs); -+ context->stackP -= (FP_TO_ARGS_DIST + nArgs); - -- *frameP = newFrameP; -+ context->frameP = newFrameP; - - FreeProgram(prog); - -- return newPC; -+ context->pc = newPC; - } - - static void rewindStack(RestartData *context) - { - while (context->pc) { -- context->pc = rewindFrame(&context->frameP, &context->stackP); -+ rewindFrame(context); - } - } - -@@ -665,7 +658,7 @@ int ExecuteMacro(WindowInfo *window, Pro - prog->name ? prog->name : ""); - - if (status == STAT_ERROR) { -- *msg = ErrMsg; -+ *msg = context->errMsg; - FreeRestartData(context); - return MACRO_ERROR; - } -@@ -682,25 +675,23 @@ int ContinueMacro(RestartData *continuat - { - register int status, instCount = 0; - register Inst *inst; -- RestartData oldContext; -- -- /* To allow macros to be invoked arbitrarily (such as those automatically -- triggered within smart-indent) within executing macros, this call is -- reentrant. */ -- saveContext(&oldContext); -- -+ WindowInfo *oldRunWindow = InitiatingWindow; -+ WindowInfo *oldFocusWindow = FocusWindow; -+ - /* - ** Execution Loop: Call the succesive routine addresses in the program - ** until one returns something other than STAT_OK, then take action - */ -- restoreContext(continuation); -- ErrMsg = NULL; -+ InitiatingWindow = continuation->runWindow; -+ FocusWindow = continuation->focusWindow; -+ continuation->errMsg = NULL; - for (;;) { - - /* Execute an instruction */ -- inst = PC++; -+ inst = continuation->pc++; - if (inst->type != OP_INST) { -- status = execError("Unexpected instruction of type %s", -+ status = execError(continuation, -+ "Unexpected instruction of type %s", - instTypeToStr(inst->type)); - } - else { -@@ -708,31 +699,34 @@ int ContinueMacro(RestartData *continuat - #define OP(name, fn) case OP_##name: - #include "ops.h" - #undef OP -- status = (OpFns[inst->val.op])(); -+ status = (OpFns[inst->val.op])(continuation); - break; - default: -- status = execError("Illegal instruction at %8p", (char *)inst); -+ status = execError(continuation, "Illegal instruction at %8p", -+ (char *)inst); - } - } - - /* If error return was not STAT_OK, return to caller */ - if (status != STAT_OK) { - if (status == STAT_PREEMPT) { -- saveContext(continuation); -- restoreContext(&oldContext); -+ continuation->runWindow = InitiatingWindow; -+ continuation->focusWindow = FocusWindow; -+ InitiatingWindow = oldRunWindow; -+ FocusWindow = oldFocusWindow; - return MACRO_PREEMPT; - } else if (status == STAT_ERROR) { -- *msg = ErrMsg; -- saveContext(continuation); -+ *msg = continuation->errMsg; - FreeRestartData(continuation); -- restoreContext(&oldContext); -+ InitiatingWindow = oldRunWindow; -+ FocusWindow = oldFocusWindow; - return MACRO_ERROR; - } else if (status == STAT_DONE) { - *msg = ""; -- *result = *--StackP; -- saveContext(continuation); -+ *result = *--continuation->stackP; - FreeRestartData(continuation); -- restoreContext(&oldContext); -+ InitiatingWindow = oldRunWindow; -+ FocusWindow = oldFocusWindow; - return MACRO_DONE; - } - } -@@ -742,8 +736,10 @@ int ContinueMacro(RestartData *continuat - X, other macros, and other shell scripts a chance to execute */ - instCount++; - if (instCount >= INSTRUCTION_LIMIT) { -- saveContext(continuation); -- restoreContext(&oldContext); -+ continuation->runWindow = InitiatingWindow; -+ continuation->focusWindow = FocusWindow; -+ InitiatingWindow = oldRunWindow; -+ FocusWindow = oldFocusWindow; - return MACRO_TIME_LIMIT; - } - } -@@ -765,7 +761,7 @@ int RunMacroAsSubrCall(RestartData *cont - prog->name ? prog->name : ""); - - if (status == STAT_ERROR) { -- *msg = ErrMsg; -+ *msg = context->errMsg; - FreeRestartData(context); - return MACRO_ERROR; - } -@@ -800,8 +796,8 @@ void PreemptMacro(void) - */ - void ModifyReturnedValue(RestartData *context, DataValue dv) - { -- if ((context->pc-1)->val.op == OP_FETCH_RET_VAL) -- *(context->stackP-1) = dv; -+ if ((context->pc - 1)->val.op == OP_FETCH_RET_VAL) -+ *(context->stackP - 1) = dv; - } - - /* -@@ -1319,29 +1315,6 @@ void GarbageCollectStrings(void) - #endif - } - --/* --** Save and restore execution context to data structure "context" --*/ --static void saveContext(RestartData *context) --{ -- context->stack = TheStack; -- context->stackP = StackP; -- context->frameP = FrameP; -- context->pc = PC; -- context->runWindow = InitiatingWindow; -- context->focusWindow = FocusWindow; --} -- --static void restoreContext(RestartData *context) --{ -- TheStack = context->stack; -- StackP = context->stackP; -- FrameP = context->frameP; -- PC = context->pc; -- InitiatingWindow = context->runWindow; -- FocusWindow = context->focusWindow; --} -- - static void freeSymbolList(Symbol *symList) - { - Symbol *s; -@@ -1378,7 +1351,12 @@ static void addToGlobalSymTab(Symbol *sy - GlobalSymTab[idx] = sym; - } - --#define EXEC_ERROR(s1, s2) return execError(s1, s2) -+#define StackP (context->stackP) -+#define TheStack (context->stack) -+#define FrameP (context->frameP) -+#define PC (context->pc) -+ -+#define EXEC_ERROR(s1, s2) return execError(context, s1, s2) - - #define GET_SYM(s) \ - do { \ -@@ -1386,7 +1364,8 @@ static void addToGlobalSymTab(Symbol *sy - EXEC_ERROR("Unexpected instruction, expected : %s", \ - instTypeToStr(PC->type)); \ - } \ -- s = PC++->val.sym; \ -+ s = PC->val.sym; \ -+ PC++; \ - } while (0) - - #define GET_IMMED(i) \ -@@ -1395,7 +1374,8 @@ static void addToGlobalSymTab(Symbol *sy - EXEC_ERROR("Unexpected instruction, expected : %s", \ - instTypeToStr(PC->type)); \ - } \ -- i = PC++->val.immed; \ -+ i = PC->val.immed; \ -+ PC++; \ - } while (0) - - #define GET_BRANCH(a) \ -@@ -1617,10 +1597,8 @@ OP_FUNCTION(pushSymVal) - symVal = FRAME_GET_ARG_N(argNum); - } - } else if (s->type == PROC_VALUE_SYM) { -- char *errMsg; -- if (!(s->value.val.subr)(FocusWindow, NULL, 0, -- &symVal, &errMsg)) { -- EXEC_ERROR(errMsg, s->name); -+ if (!s->value.val.subr(context, NULL, 0, &symVal)) { -+ EXEC_ERROR(context->errMsg, s->name); - } - } else if (s->type == C_FUNCTION_SYM - || s->type == MACRO_FUNCTION_SYM -@@ -1885,7 +1863,7 @@ OP_FUNCTION(anonArrayIndexVal) - POP(exprVal); - - /* the next nDim stack entries form the index */ -- errNum = makeArrayKeyFromArgs(nDim, &keyString, 0); -+ errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 0); - if (errNum != STAT_OK) { - return errNum; - } -@@ -1947,7 +1925,7 @@ OP_FUNCTION(anonArrayClose) - */ - OP_FUNCTION(namedArg1) - { -- return namedArg1orN(True); -+ return namedArg1orN(context, True); - } - - /* -@@ -1961,13 +1939,13 @@ OP_FUNCTION(namedArg1) - */ - OP_FUNCTION(namedArgN) - { -- return namedArg1orN(False); -+ return namedArg1orN(context, False); - } - - /* - ** implementation for namedArg1(), namedArgN() - */ --static int namedArg1orN(Boolean isFirst) -+static int namedArg1orN(RestartData *context, Boolean isFirst) - { - int errNum; - char *keyString = NULL; -@@ -1983,7 +1961,7 @@ static int namedArg1orN(Boolean isFirst) - POP(exprVal); - - /* the next nDim stack entries form the index */ -- errNum = makeArrayKeyFromArgs(nDim, &keyString, 0); -+ errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 0); - if (errNum != STAT_OK) { - return errNum; - } -@@ -2389,8 +2367,8 @@ OP_FUNCTION(eq) - /* negated eq() call */ - OP_FUNCTION(ne) - { -- eq(); -- return not(); -+ eq(context); -+ return not(context); - } - - /* -@@ -2581,7 +2559,7 @@ OP_FUNCTION(power) - } - } - PUSH_INT(n3); -- return errCheck("exponentiation"); -+ return errCheck(context, "exponentiation"); - } - - /* -@@ -2592,8 +2570,8 @@ OP_FUNCTION(power) - ** stack elements. The stack elements are popped from the stack if leaveParams - ** is false. - */ --static int concatenateNwithSep(int nVals, const char *sep, char **result, -- int leaveParams) -+static int concatenateNwithSep(RestartData *context, int nVals, const char *sep, -+ char **result, int leaveParams) - { - DataValue value; - char *res = NULL; -@@ -2676,7 +2654,7 @@ OP_FUNCTION(concat) - - STACKDUMP(nExpr, 3); - -- len = concatenateNwithSep(nExpr, "", &out, False); -+ len = concatenateNwithSep(context, nExpr, "", &out, False); - if (len < 0) { - EXEC_ERROR("can only concatenate with string or integer", NULL); - } -@@ -2710,7 +2688,8 @@ OP_FUNCTION(concat) - ** or: Prog-> (in called)next, ... -- (macro code called subr) - ** TheStack-> symN-sym1(FP), nArgs, oldFP, retPC, argArray, argN-arg1, next, ... - */ --static int callSubroutineFromSymbol(Symbol *sym, int nArgs) -+static int callSubroutineFromSymbol(RestartData *context, Symbol *sym, -+ int nArgs) - { - Symbol *s; - int i; -@@ -2753,9 +2732,9 @@ static int callSubroutineFromSymbol(Symb - - /* Call the function and check for preemption */ - PreemptRequest = False; -- if (!sym->value.val.subr(FocusWindow, StackP, -- nArgs, &result, &errMsg)) -- EXEC_ERROR(errMsg, sym->name); -+ if (!sym->value.val.subr(context, StackP, nArgs, &result)) { -+ EXEC_ERROR(context->errMsg, sym->name); -+ } - PUSH_RET_VAL(result); - return PreemptRequest ? STAT_PREEMPT : STAT_OK; - } -@@ -2768,15 +2747,10 @@ static int callSubroutineFromSymbol(Symb - ** values which are already there. - */ - if (sym->type == MACRO_FUNCTION_SYM) { -- RestartData context; -- int status; - prog = sym->value.val.prog; - prog->refcount++; - /* -nArgs means 'arguments are on stack' */ -- saveContext(&context); -- status = setupFrame(&context, prog, -nArgs, NULL, argArray, sym->name); -- restoreContext(&context); -- return status; -+ return setupFrame(context, prog, -nArgs, NULL, argArray, sym->name); - } - - /* -@@ -2798,11 +2772,11 @@ static int callSubroutineFromSymbol(Symb - timestamps, a marker to indicate that the call was from a macro - (to stop shell commands from putting up their own separate banner) */ - disp=XtDisplay(InitiatingWindow->shell); -- win=XtWindow(InitiatingWindow->shell); -+ win=XtWindow(InitiatingWindow->shell); - - key_event.type = KeyPress; - key_event.send_event = MACRO_EVENT_MARKER; -- key_event.time=XtLastTimestampProcessed(XtDisplay(InitiatingWindow->shell)); -+ key_event.time=XtLastTimestampProcessed(XtDisplay(InitiatingWindow->shell)); - - /* The following entries are just filled in to avoid problems - in strange cases, like calling "self_insert()" directly from the -@@ -2818,7 +2792,7 @@ static int callSubroutineFromSymbol(Symb - - /* Call the action routine and check for preemption */ - PreemptRequest = False; -- sym->value.val.xtproc(FocusWindow->lastFocus, -+ sym->value.val.xtproc(MacroFocusWindow()->lastFocus, - (XEvent *)&key_event, argList, &numArgs); - XtFree((char *)argList); - PUSH_RET_VAL(noValue); -@@ -2850,7 +2824,7 @@ OP_FUNCTION(callSubroutine) - - STACKDUMP(nArgs > 0 ? nArgs : -nArgs, 3); - -- return callSubroutineFromSymbol(sym, nArgs); -+ return callSubroutineFromSymbol(context, sym, nArgs); - } - - /* -@@ -2885,7 +2859,7 @@ OP_FUNCTION(callSubroutineStackedN) - EXEC_ERROR("array argument call to %s erroneous", sym->name); - } - -- return callSubroutineFromSymbol(sym, nArgs); -+ return callSubroutineFromSymbol(context, sym, nArgs); - } - - /* -@@ -2894,8 +2868,8 @@ OP_FUNCTION(callSubroutineStackedN) - ** written in macro.c. If the caller has already "consumed" stack elements, - ** removeArgs must indicate how many. - */ -- --int OverlayRoutineFromSymbol(Symbol *sym, int nArgs, int removeArgs) -+int OverlayRoutineFromSymbol(RestartData *context, Symbol *sym, int nArgs, -+ int removeArgs) - { - DataValue *argArray = StackP + nArgs - removeArgs; - -@@ -2922,7 +2896,7 @@ int OverlayRoutineFromSymbol(Symbol *sym - assert (argArray->tag == NO_TAG); - StackP = argArray; - } -- return callSubroutineFromSymbol(sym, nArgs); -+ return callSubroutineFromSymbol(context, sym, nArgs); - } - - /* -@@ -2930,8 +2904,8 @@ int OverlayRoutineFromSymbol(Symbol *sym - ** OverlayRoutineFromSymbol(). In this way a piece of compiled code can be - ** executed in the caller's context from a function in macro.c. - */ -- --int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs) -+int OverlayRoutineFromProg(RestartData *context, Program *prog, int nArgs, -+ int removeArgs) - { - Symbol *sym; - int ret; -@@ -2948,7 +2922,7 @@ int OverlayRoutineFromProg(Program *prog - sym->next = NULL; - sym->added = 0; - -- ret = OverlayRoutineFromSymbol(sym, nArgs, removeArgs); -+ ret = OverlayRoutineFromSymbol(context, sym, nArgs, removeArgs); - - free(sym); - -@@ -3051,11 +3025,11 @@ OP_FUNCTION(fetchRetVal) - /* see comments for returnValOrNone() */ - OP_FUNCTION(returnNoVal) - { -- return returnValOrNone(False); -+ return returnValOrNone(context, False); - } - OP_FUNCTION(returnVal) - { -- return returnValOrNone(True); -+ return returnValOrNone(context, True); - } - - /* -@@ -3065,7 +3039,7 @@ OP_FUNCTION(returnVal) - ** After: Prog-> next, ..., (in caller)[FETCH_RET_VAL?], ... - ** TheStack-> retVal?, next, ... - */ --static int returnValOrNone(int valOnStack) -+static int returnValOrNone(RestartData *context, int valOnStack) - { - DataValue retVal; - static DataValue noValue = {NO_TAG, {0}}; -@@ -3081,7 +3055,7 @@ static int returnValOrNone(int valOnStac - retVal = noValue; - } - -- PC = rewindFrame(&FrameP, &StackP); -+ rewindFrame(context); - - /* push returned value, if requsted */ - PUSH_RET_VAL(retVal); -@@ -3119,13 +3093,13 @@ OP_FUNCTION(branch) - */ - OP_FUNCTION(branchTrue) - { -- return branchIf(True); -+ return branchIf(context, True); - } - OP_FUNCTION(branchFalse) - { -- return branchIf(False); -+ return branchIf(context, False); - } --static int branchIf(Boolean trueOrFalse) -+static int branchIf(RestartData *context, Boolean trueOrFalse) - { - int value; - Inst *addr; -@@ -3206,11 +3180,13 @@ int ArrayCopy(DataValue *dstArray, DataV - ** I really need to optimize the size approximation rather than assuming - ** a worst case size for every integer argument - */ --static int makeArrayKeyFromArgs(int nArgs, char **keyString, int leaveParams) -+static int makeArrayKeyFromArgs(RestartData *context, int nArgs, -+ char **keyString, int leaveParams) - { - int len; - -- len = concatenateNwithSep(nArgs, ARRAY_DIM_SEP, keyString, leaveParams); -+ len = concatenateNwithSep(context, nArgs, ARRAY_DIM_SEP, keyString, -+ leaveParams); - if (len < 0) { - EXEC_ERROR("can only index array with string or int.", NULL); - } -@@ -3526,7 +3502,7 @@ OP_FUNCTION(arrayRef) - STACKDUMP(nDim+1, 3); - - if (nDim > 0) { -- errNum = makeArrayKeyFromArgs(nDim, &keyString, 0); -+ errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 0); - if (errNum != STAT_OK) { - return(errNum); - } -@@ -3580,7 +3556,7 @@ OP_FUNCTION(arrayAssign) - if (nDim > 0) { - POP(srcValue); - -- errNum = makeArrayKeyFromArgs(nDim, &keyString, 0); -+ errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 0); - if (errNum != STAT_OK) { - return(errNum); - } -@@ -3636,7 +3612,7 @@ OP_FUNCTION(arrayRefAndAssignSetup) - } - - if (nDim > 0) { -- errNum = makeArrayKeyFromArgs(nDim, &keyString, 1); -+ errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 1); - if (errNum != STAT_OK) { - return(errNum); - } -@@ -4072,7 +4048,7 @@ OP_FUNCTION(deleteArrayElement) - if (nDim > 0) { - int errNum; - -- errNum = makeArrayKeyFromArgs(nDim, &keyString, 0); -+ errNum = makeArrayKeyFromArgs(context, nDim, &keyString, 0); - if (errNum != STAT_OK) { - return(errNum); - } -@@ -4216,7 +4192,7 @@ OP_FUNCTION(arrayNextNumIdx) - ** checks errno after operations which can set it. If an error occured, - ** creates appropriate error messages and returns false - */ --static int errCheck(const char *s) -+static int errCheck(RestartData *context, const char *s) - { - if (errno == EDOM) - EXEC_ERROR("%s argument out of domain", s); -@@ -4229,25 +4205,25 @@ static int errCheck(const char *s) - /* - ** build a stack dump string, reallocating s as necessary. - */ --static char *stackDumpStr(DataValue *fp, const char *msg, char **s, int *pLen) -+static void stackDumpStr(RestartData *context, const char *msg, char **s, int *pLen) - { - int len; - const char *op; - char *np; -- DataValue *nfp = fp; -+ DataValue *nfp = context->frameP; - Inst *pc; - - #ifdef DEBUG_STACK - const char *dump; - printd("\n\n"); -- disasmInternal(PC - 1, 1); -- stackdumpInternal(0, 50); -+ disasmInternal(context->pc - 1, 1); -+ stackdumpInternal(context, 0, 50); - dump = printd(NULL); - #endif - - /* first measure the lengths */ - len = strlen(msg) + 1; -- nfp = fp; -+ nfp = context->frameP; - do { - len = len + FP_GET_ITEM(nfp, FP_FUNCTION_NAME).val.str.len + 1; - pc = FP_GET_RET_PC(nfp); -@@ -4267,7 +4243,7 @@ static char *stackDumpStr(DataValue *fp, - while (*op) - *np++ = *op++; - -- nfp = fp; -+ nfp = context->frameP; - do { - *np++ = '\n'; - op = FP_GET_ITEM(nfp, FP_FUNCTION_NAME).val.str.rep; -@@ -4283,22 +4259,22 @@ static char *stackDumpStr(DataValue *fp, - #endif - - *np = 0; -- return *s; -+ context->errMsg = *s; - } - - /* --** combine two strings in a static area and set ErrMsg to point to the --** result. Returns false so a single return execError() statement can -+** combine two strings in a static area and set continuation->errMsg to point -+** to the result. Returns false so a single return execError() statement can - ** be used to both process the message and return. - */ --static int execError(const char *s1, const char *s2) -+static int execError(RestartData *context, const char *s1, const char *s2) - { - static char msg[MAX_ERR_MSG_LEN]; - static char *err = NULL; - static int errlen = 0; - - sprintf(msg, s1, s2); -- ErrMsg = stackDumpStr(FrameP, msg, &err, &errlen); -+ stackDumpStr(context, msg, &err, &errlen); - return STAT_ERROR; - } - -@@ -4410,6 +4386,11 @@ static const char *instTypeToStr(enum in - } - - -+#undef StackP -+#undef TheStack -+#undef FrameP -+#undef PC -+ - #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */ - static char *printdBuffer = NULL; - static int printdPos = 0; -@@ -4869,31 +4850,31 @@ static void stackdumpframe(DataValue *ar - #endif /* #ifdef DEBUG_STACK_HEADFIRST */ - } - --static void stackdumpInternal(int n, int extra) -+static void stackdumpInternal(RestartData *context, int n, int extra) - { -- DataValue *arrow = StackP - n; -- DataValue *outpt = StackP - n - extra; -+ DataValue *arrow = context->stackP - n; -+ DataValue *outpt = context->stackP - n - extra; - - #ifdef DEBUG_STACK_HEADFIRST - printd("Stack ----->\n"); -- stackdumpframe(arrow, outpt, FrameP, StackP, '*'); -- if (outpt < TheStack) -+ stackdumpframe(arrow, outpt, context->frameP, context->stackP, '*'); -+ if (outpt < context->stack) - printd("--------------Stack base--------------\n"); - #else -- if (outpt < TheStack) -+ if (outpt < context->stack) - printd("--------------Stack base--------------\n"); -- stackdumpframe(arrow, outpt, FrameP, StackP, '*'); -+ stackdumpframe(arrow, outpt, context->frameP, context->stackP, '*'); - printd("Stack ----->\n\n"); - #endif /* #ifdef DEBUG_STACK_HEADFIRST */ - } - --static void stackdump(int n, int extra) -+static void stackdump(RestartData *context, int n, int extra) - { - static int outIsTTY = -1; - if (outIsTTY == -1) - outIsTTY = isatty(fileno(stdout)); - -- stackdumpInternal(n, extra); -+ stackdumpInternal(context, n, extra); - - if (outIsTTY) - printd("\033[J\n"); -diff --quilt old/source/interpret.h new/source/interpret.h ---- old/source/interpret.h -+++ new/source/interpret.h -@@ -62,6 +62,7 @@ struct DataValueTag; - struct SparseArrayEntryTag; - struct ProgramTag; - struct SymbolRec; -+struct RestartDataTag; - - typedef struct InstTag { - enum instTypes type; -@@ -73,8 +74,8 @@ typedef struct InstTag { - } val; - } Inst; - --typedef int (*BuiltInSubr)(WindowInfo *window, struct DataValueTag *argList, -- int nArgs, struct DataValueTag *result, char **errMsg); -+typedef int (BuiltInSubr)(struct RestartDataTag *context, -+ struct DataValueTag *argList, int nArgs, struct DataValueTag *result); - - typedef struct NStringTag { - char *rep; -@@ -86,11 +87,11 @@ typedef struct DataValueTag { - union { - int n; - struct NStringTag str; -- BuiltInSubr subr; -- struct ProgramTag* prog; -+ BuiltInSubr *subr; -+ struct ProgramTag *prog; - XtActionProc xtproc; -- Inst* inst; -- struct DataValueTag* dataval; -+ Inst *inst; -+ struct DataValueTag *dataval; - struct SparseArrayEntryTag *arrayPtr; - struct SymbolRec *sym; - } val; -@@ -120,13 +121,14 @@ typedef struct ProgramTag { - } Program; - - /* Information needed to re-start a preempted macro */ --typedef struct { -+typedef struct RestartDataTag { - DataValue *stack; - DataValue *stackP; - DataValue *frameP; - Inst *pc; - WindowInfo *runWindow; - WindowInfo *focusWindow; -+ char *errMsg; - } RestartData; - - /* state of the accumulator (aka compiler) */ -@@ -183,8 +185,10 @@ int ContinueMacro(RestartData *continuat - int RunMacroAsSubrCall(RestartData *context, Program *prog, char **msg); - void PreemptMacro(void); - --int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs); --int OverlayRoutineFromSymbol(Symbol *sym, int nArgs, int removeArgs); -+int OverlayRoutineFromProg(RestartData *context, Program *prog, int nArgs, -+ int removeArgs); -+int OverlayRoutineFromSymbol(RestartData *context, Symbol *sym, int nArgs, -+ int removeArgs); - - char *AllocString(int length); - char *AllocStringNCpy(const char *s, int length); -diff --quilt old/source/macro.c new/source/macro.c ---- old/source/macro.c -+++ new/source/macro.c -@@ -170,82 +170,82 @@ static void bannerTimeoutProc(XtPointer - static Boolean continueWorkProc(XtPointer clientData); - static int escapeStringChars(char *fromString, char *toString); - static int escapedStringLength(char *string); --static int argsMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int nArgsMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int lengthMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int minMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int maxMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int focusWindowMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int getRangeMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int getCharacterMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int replaceRangeMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int replaceSelectionMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int getSelectionMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int validNumberMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int replaceInStringMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int replaceSubstringMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int fullFileNameMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int readFileMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int writeFileMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int appendFileMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -+static int argsMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int nArgsMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int lengthMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int minMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int maxMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int focusWindowMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int getRangeMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int getCharacterMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int replaceRangeMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int replaceSelectionMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int getSelectionMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int validNumberMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int replaceInStringMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int replaceSubstringMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int fullFileNameMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int readFileMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int writeFileMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int appendFileMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - static int writeOrAppendFile(int append, WindowInfo *window, - DataValue *argList, int nArgs, DataValue *result, char **errMsg); --static int substringMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int toupperMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int tolowerMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int stringToClipboardMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int clipboardToStringMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int searchMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int searchStringMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int setCursorPosMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int beepMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int selectMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int selectRectangleMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int tPrintMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int getenvMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int shellCmdMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int dialogMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -+static int substringMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int toupperMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int tolowerMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int stringToClipboardMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int clipboardToStringMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int searchMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int searchStringMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int setCursorPosMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int beepMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int selectMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int selectRectangleMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int tPrintMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int getenvMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int shellCmdMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int dialogMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - static void dialogBtnCB(Widget w, XtPointer clientData, XtPointer callData); - static void dialogCloseCB(Widget w, XtPointer clientData, XtPointer callData); - #ifdef LESSTIF_VERSION - static void dialogEscCB(Widget w, XtPointer clientData, XEvent *event, - Boolean *cont); - #endif /* LESSTIF_VERSION */ --static int stringDialogMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -+static int stringDialogMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - static void stringDialogBtnCB(Widget w, XtPointer clientData, - XtPointer callData); - static void stringDialogCloseCB(Widget w, XtPointer clientData, -@@ -254,122 +254,122 @@ static void stringDialogCloseCB(Widget w - static void stringDialogEscCB(Widget w, XtPointer clientData, XEvent *event, - Boolean *cont); - #endif /* LESSTIF_VERSION */ --static int calltipMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int killCalltipMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int highlightCTLineMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -+static int calltipMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int killCalltipMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int highlightCTLineMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - /* T Balinski */ --static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -+static int listDialogMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - static void listDialogBtnCB(Widget w, XtPointer clientData, -- XtPointer callData); -+ XtPointer callData); - static void listDialogCloseCB(Widget w, XtPointer clientData, -- XtPointer callData); -+ XtPointer callData); - /* T Balinski End */ - #ifdef LESSTIF_VERSION - static void listDialogEscCB(Widget w, XtPointer clientData, XEvent *event, - Boolean *cont); - #endif /* LESSTIF_VERSION */ --static int stringCompareMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int splitMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int joinMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -+static int stringCompareMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int splitMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int joinMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - /* DISASBLED for 5.4 --static int setBacklightStringMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); -+static int setBacklightStringMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result); - */ --static int cursorMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int lineMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int columnMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int fileNameMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int filePathMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int lengthMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int selectionStartMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int selectionEndMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int selectionLeftMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int selectionRightMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int statisticsLineMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int incSearchLineMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int showLineNumbersMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int autoIndentMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int wrapTextMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int highlightSyntaxMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int makeBackupCopyMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int incBackupMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int showMatchingMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int overTypeModeMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int readOnlyMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int lockedMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int fileFormatMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int fontNameMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int fontNameItalicMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int fontNameBoldMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int fontNameBoldItalicMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int subscriptSepMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int minFontWidthMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int maxFontWidthMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int wrapMarginMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int topLineMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int numDisplayLinesMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int displayWidthMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int activePaneMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int nPanesMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int emptyArrayMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int serverNameMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int tabDistMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int emTabDistMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int useTabsMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int modifiedMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int languageModeMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int calltipIDMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -+static int cursorMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int lineMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int columnMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int fileNameMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int filePathMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int lengthMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int selectionStartMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int selectionEndMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int selectionLeftMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int selectionRightMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int statisticsLineMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int incSearchLineMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int showLineNumbersMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int autoIndentMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int wrapTextMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int highlightSyntaxMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int makeBackupCopyMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int incBackupMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int showMatchingMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int overTypeModeMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int readOnlyMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int lockedMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int fileFormatMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int fontNameMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int fontNameItalicMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int fontNameBoldMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int fontNameBoldItalicMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int subscriptSepMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int minFontWidthMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int maxFontWidthMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int wrapMarginMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int topLineMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int numDisplayLinesMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int displayWidthMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int activePaneMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int nPanesMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int emptyArrayMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int serverNameMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int tabDistMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int emTabDistMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int useTabsMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int modifiedMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int languageModeMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int calltipIDMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - static int readSearchArgs(DataValue *argList, int nArgs, int*searchDirection, - int *searchType, int *wrap, char **errMsg); - static int wrongNArgsErr(char **errMsg); -@@ -379,101 +379,101 @@ static int readIntArg(DataValue dv, int - static int readStringArg(DataValue dv, char **result, char *stringStorage, - char **errMsg); - /* DISABLED FOR 5.4 --static int backlightStringMV(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); -+static int backlightStringMV(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result); - */ --static int rangesetListMV(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); --static int versionMV(WindowInfo* window, DataValue* argList, int nArgs, -- DataValue* result, char** errMsg); --static int neditHomeMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int transientMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int rangesetCreateMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int rangesetDestroyMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int rangesetGetByNameMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int rangesetAddMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int rangesetSubtractMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int rangesetInvertMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int rangesetInfoMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int rangesetRangeMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int rangesetIncludesPosMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); --static int rangesetSetColorMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); --static int rangesetSetUnderlineMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); --static int rangesetSetNameMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); --static int rangesetSetModeMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); -+static int rangesetListMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int versionMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int neditHomeMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int transientMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int rangesetCreateMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int rangesetDestroyMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int rangesetGetByNameMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int rangesetAddMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int rangesetSubtractMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int rangesetInvertMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int rangesetInfoMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int rangesetRangeMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int rangesetIncludesPosMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result); -+static int rangesetSetColorMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result); -+static int rangesetSetUnderlineMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result); -+static int rangesetSetNameMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result); -+static int rangesetSetModeMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result); - - static int fillPatternResult(DataValue *result, char **errMsg, WindowInfo *window, - char *patternName, Boolean preallocatedPatternName, Boolean includeName, - char *styleName, int bufferPos); --static int getPatternByNameMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int getPatternAtPosMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -+static int getPatternByNameMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int getPatternAtPosMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - - static int fillStyleResult(DataValue *result, char **errMsg, - WindowInfo *window, char *styleName, Boolean preallocatedStyleName, - Boolean includeName, int patCode, int bufferPos); --static int getStyleByNameMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int getStyleAtPosMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int filenameDialogMS(WindowInfo* window, DataValue* argList, int nArgs, -- DataValue* result, char** errMsg); --static int callMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); --static int setWindowTitleMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); -+static int getStyleByNameMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int getStyleAtPosMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int filenameDialogMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int callMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int setWindowTitleMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - - /* Pattern Match Feature */ --static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -+static int getMatchingMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - --static int dictinsertMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int dictcompleteMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int dictsaveMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int dictappendMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int dictiselementMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -+static int dictinsertMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int dictcompleteMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int dictsaveMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int dictappendMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int dictiselementMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - --static int defineMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -+static int defineMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); - - /* - * UL convertPos patch: - * add "to_pos", "to_line", "to_column" macro subroutines - */ --static int toPosMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int toLineMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); --static int toColumnMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg); -- --static int timerAddMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); --static int timerRemoveMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); --static int escapeLiteralMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg); -+static int toPosMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int toLineMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+static int toColumnMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result); -+ -+static int timerAddMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result); -+static int timerRemoveMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result); -+static int escapeLiteralMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result); - - /* Built-in subroutines and variables for the macro language */ - static const BuiltInSubrName MacroSubrs[] = { -@@ -1190,7 +1190,7 @@ int MacroWindowCloseActions(WindowInfo * - for (w=WindowList; w!=NULL; w=w->next) { - mcd = (macroCmdInfo *)w->macroCmdData; - if (w == MacroRunWindow() && MacroFocusWindow() == window) -- SetMacroFocusWindow(MacroRunWindow()); -+ SetMacroFocusWindow(w); - else if (mcd != NULL && mcd->context->focusWindow == window) - mcd->context->focusWindow = mcd->context->runWindow; - } -@@ -1908,9 +1908,11 @@ static int escapedStringLength(char *str - ** return $args - ** } - */ --static int argsMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int argsMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - DataValue *argsArray = &argList[nArgs]; - DataValue *argVal; - int argNum; -@@ -1944,9 +1946,11 @@ static int argsMS(WindowInfo *window, Da - ** return i - ** } - */ --static int nArgsMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int nArgsMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - DataValue *argsArray = &argList[0]; - DataValue val; - -@@ -1970,9 +1974,11 @@ static int nArgsMS(WindowInfo *window, D - /* - ** Built-in macro subroutine for getting the length of a string - */ --static int lengthMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int lengthMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char *string, stringStorage[TYPE_INT_STR_SIZE(int)]; - - if (nArgs != 1) -@@ -1987,9 +1993,11 @@ static int lengthMS(WindowInfo *window, - /* - ** Built-in macro subroutines for min and max - */ --static int minMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int minMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int minVal, value, i; - - if (nArgs == 1) -@@ -2005,9 +2013,11 @@ static int minMS(WindowInfo *window, Dat - result->val.n = minVal; - return True; - } --static int maxMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int maxMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int maxVal, value, i; - - if (nArgs == 1) -@@ -2024,9 +2034,11 @@ static int maxMS(WindowInfo *window, Dat - return True; - } - --static int focusWindowMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int focusWindowMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[TYPE_INT_STR_SIZE(int)], *string; - WindowInfo *w; - char fullname[MAXPATHLEN]; -@@ -2097,9 +2109,11 @@ static int focusWindowMS(WindowInfo *win - ** Built-in macro subroutine for getting text from the current window's text - ** buffer - */ --static int getRangeMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int getRangeMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int from, to; - textBuffer *buf = window->buffer; - char *rangeText; -@@ -2134,9 +2148,11 @@ static int getRangeMS(WindowInfo *window - ** Built-in macro subroutine for getting a single character at the position - ** given, from the current window - */ --static int getCharacterMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int getCharacterMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int pos; - textBuffer *buf = window->buffer; - -@@ -2162,9 +2178,11 @@ static int getCharacterMS(WindowInfo *wi - ** Built-in macro subroutine for replacing text in the current window's text - ** buffer - */ --static int replaceRangeMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int replaceRangeMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int from, to; - char stringStorage[TYPE_INT_STR_SIZE(int)], *string; - textBuffer *buf = window->buffer; -@@ -2212,9 +2230,11 @@ static int replaceRangeMS(WindowInfo *wi - ** Built-in macro subroutine for replacing the primary-selection selected - ** text in the current window's text buffer - */ --static int replaceSelectionMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int replaceSelectionMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[TYPE_INT_STR_SIZE(int)], *string; - - /* Validate argument and convert to string */ -@@ -2252,9 +2272,11 @@ static int replaceSelectionMS(WindowInfo - ** the primary selection in the current window's text buffer, or in any - ** part of screen if "any" argument is given - */ --static int getSelectionMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int getSelectionMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char *selText; - - /* Read argument list to check for "any" keyword, and get the appropriate -@@ -2285,9 +2307,11 @@ static int getSelectionMS(WindowInfo *wi - ** Built-in macro subroutine for determining if implicit conversion of - ** a string to number will succeed or fail - */ --static int validNumberMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int validNumberMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char *string, stringStorage[TYPE_INT_STR_SIZE(int)]; - - if (nArgs != 1) { -@@ -2306,9 +2330,11 @@ static int validNumberMS(WindowInfo *win - /* - ** Built-in macro subroutine for replacing a substring within another string - */ --static int replaceSubstringMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int replaceSubstringMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int from, to, length, replaceLen, outLen; - char stringStorage[2][TYPE_INT_STR_SIZE(int)], *string, *replStr; - -@@ -2345,9 +2371,11 @@ static int replaceSubstringMS(WindowInfo - ** Built-in macro subroutine for getting a substring of a string. - ** Called as substring(string, from [, to]) - */ --static int substringMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int substringMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int from, to, length; - char stringStorage[TYPE_INT_STR_SIZE(int)], *string; - -@@ -2376,9 +2404,11 @@ static int substringMS(WindowInfo *windo - return True; - } - --static int toupperMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int toupperMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int i, length; - char stringStorage[TYPE_INT_STR_SIZE(int)], *string; - -@@ -2397,9 +2427,11 @@ static int toupperMS(WindowInfo *window, - return True; - } - --static int tolowerMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int tolowerMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int i, length; - char stringStorage[TYPE_INT_STR_SIZE(int)], *string; - -@@ -2418,9 +2450,11 @@ static int tolowerMS(WindowInfo *window, - return True; - } - --static int stringToClipboardMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int stringToClipboardMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - long itemID = 0; - XmString s; - int stat; -@@ -2450,9 +2484,11 @@ static int stringToClipboardMS(WindowInf - return True; - } - --static int clipboardToStringMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int clipboardToStringMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - unsigned long length, retLength; - long id = 0; - -@@ -2568,9 +2604,11 @@ static char *convFilePathToAbsolute(cons - ** to a full one, using the current window's directory as a base for relative - ** path specifications. It does not check for file/path validity. - */ --static int fullFileNameMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int fullFileNameMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[TYPE_INT_STR_SIZE(int)], *name; - size_t len; - -@@ -2603,9 +2641,11 @@ static int fullFileNameMS(WindowInfo *wi - ** file as a string in the subroutine return value. On failure, returns - ** the empty string "" and an 0 $readStatus. - */ --static int readFileMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int readFileMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[TYPE_INT_STR_SIZE(int)], *name; - struct stat statbuf; - FILE *fp; -@@ -2672,15 +2712,19 @@ errorNoClose: - ** to a file named in parameter $2. Returns 1 on successful write, or 0 if - ** unsuccessful. - */ --static int writeFileMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int writeFileMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - return writeOrAppendFile(False, window, argList, nArgs, result, errMsg); - } - --static int appendFileMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int appendFileMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - return writeOrAppendFile(True, window, argList, nArgs, result, errMsg); - } - -@@ -2735,9 +2779,11 @@ static int writeOrAppendFile(int append, - ** Returns the starting position of the match, or -1 if nothing matched. - ** also returns the ending position of the match in $searchEndPos - */ --static int searchMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int searchMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - DataValue newArgList[9]; - - /* Use the search string routine, by adding the buffer contents as -@@ -2754,7 +2800,7 @@ static int searchMS(WindowInfo *window, - /* copy other arguments to the new argument list */ - memcpy(&newArgList[1], argList, nArgs * sizeof(DataValue)); - -- return searchStringMS(window, newArgList, nArgs+1, result, errMsg); -+ return searchStringMS(context, newArgList, nArgs+1, result); - } - - /* -@@ -2768,9 +2814,11 @@ static int searchMS(WindowInfo *window, - ** Returns the starting position of the match, or -1 if nothing matched. - ** also returns the ending position of the match in $searchEndPos - */ --static int searchStringMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int searchStringMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int beginPos, wrap, direction, found = False, foundStart, foundEnd, type; - int skipSearch = False, len; - char stringStorage[2][TYPE_INT_STR_SIZE(int)], *string, *searchStr; -@@ -2835,9 +2883,11 @@ static int searchStringMS(WindowInfo *wi - ** were performed and "copy" was specified, returns a copy of the original - ** string. Otherwise returns an empty string (""). - */ --static int replaceInStringMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int replaceInStringMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[3][TYPE_INT_STR_SIZE(int)], *string, *searchStr, *replaceStr; - char *argStr, *replacedStr; - int searchType = SEARCH_LITERAL, copyStart, copyEnd; -@@ -2929,9 +2979,11 @@ static int readSearchArgs(DataValue *arg - return True; - } - --static int setCursorPosMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int setCursorPosMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int pos; - - /* Get argument and convert to int */ -@@ -2946,9 +2998,11 @@ static int setCursorPosMS(WindowInfo *wi - return True; - } - --static int selectMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int selectMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int start, end, startTmp; - - /* Get arguments and convert to int */ -@@ -2976,9 +3030,11 @@ static int selectMS(WindowInfo *window, - return True; - } - --static int selectRectangleMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int selectRectangleMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int start, end, left, right; - - /* Get arguments and convert to int */ -@@ -3002,9 +3058,11 @@ static int selectRectangleMS(WindowInfo - /* - ** Macro subroutine to ring the bell - */ --static int beepMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int beepMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - if (nArgs != 0) - return wrongNArgsErr(errMsg); - XBell(XtDisplay(window->shell), 0); -@@ -3012,9 +3070,11 @@ static int beepMS(WindowInfo *window, Da - return True; - } - --static int tPrintMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int tPrintMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[TYPE_INT_STR_SIZE(int)], *string; - int i; - -@@ -3033,9 +3093,11 @@ static int tPrintMS(WindowInfo *window, - /* - ** Built-in macro subroutine for getting the value of an environment variable - */ --static int getenvMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int getenvMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[1][TYPE_INT_STR_SIZE(int)]; - char *name; - char *value; -@@ -3057,9 +3119,11 @@ static int getenvMS(WindowInfo *window, - return True; - } - --static int shellCmdMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int shellCmdMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[2][TYPE_INT_STR_SIZE(int)], *cmdString, *inputString = ""; - - if (nArgs != 1 && nArgs != 2) -@@ -3109,9 +3173,11 @@ void ReturnShellCommandOutput(WindowInfo - ReturnGlobals[SHELL_CMD_STATUS]->value.val.n = status; - } - --static int dialogMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int dialogMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - macroCmdInfo *cmdData; - char stringStorage[TYPE_INT_STR_SIZE(int)]; - char btnStorage[TYPE_INT_STR_SIZE(int)]; -@@ -3286,9 +3352,11 @@ static void dialogEscCB(Widget w, XtPoin - } - #endif /* LESSTIF_VERSION */ - --static int stringDialogMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int stringDialogMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - macroCmdInfo *cmdData; - char stringStorage[TYPE_INT_STR_SIZE(int)]; - char btnStorage[TYPE_INT_STR_SIZE(int)]; -@@ -3512,9 +3580,11 @@ static void stringDialogEscCB(Widget w, - ** Does this need to go on IgnoredActions? I don't think so, since - ** showing a calltip may be part of the action you want to learn. - */ --static int calltipMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int calltipMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[TYPE_INT_STR_SIZE(int)], *tipText, *txtArg; - Boolean anchored = False, lookup = True; - int mode = -1, i; -@@ -3605,9 +3675,11 @@ bad_arg: - /* - ** A subroutine to kill the current calltip - */ --static int killCalltipMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int killCalltipMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int calltipID = 0; - - if (nArgs > 1) { -@@ -3628,9 +3700,11 @@ static int killCalltipMS(WindowInfo *win - /* - ** highlight_calltip_line(ctID, line) - */ --static int highlightCTLineMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int highlightCTLineMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int calltipID = 0; - int line; - int highlightResult; -@@ -3679,9 +3753,11 @@ static int highlightCTLineMS(WindowInfo - /* - * A subroutine to get the ID of the current calltip, or 0 if there is none. - */ --static int calltipIDMV(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg) -+static int calltipIDMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = GetCalltipID(window, 0); - return True; -@@ -3708,9 +3784,11 @@ static int calltipIDMV(WindowInfo *windo - ** - ** Note that defaultName doesn't work on all *tifs. :-( - */ --static int filenameDialogMS(WindowInfo* window, DataValue* argList, int nArgs, -- DataValue* result, char** errMsg) -+static int filenameDialogMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[5][TYPE_INT_STR_SIZE(int)]; - char filename[MAXPATHLEN + 1]; - char* title = "Choose Filename"; -@@ -3811,9 +3889,11 @@ static int filenameDialogMS(WindowInfo* - /* - * call(fnname, arg, ...) - */ --static int callMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg) -+static int callMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - Symbol *sym; - - if (nArgs < 1) { -@@ -3838,15 +3918,17 @@ static int callMS(WindowInfo *window, Da - return False; - } - -- return OverlayRoutineFromSymbol(sym, nArgs, 1); -+ return OverlayRoutineFromSymbol(context, sym, nArgs, 1); - } - - /* - * subr = define(func_name, func_body[, "override"]) - */ --static int defineMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int defineMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[3][TYPE_INT_STR_SIZE(int)]; - char *name = NULL; - char *body = NULL; -@@ -3940,9 +4022,11 @@ static int defineMS(WindowInfo *window, - /* - * set_window_title(format[, ("text"|"format")]) - */ --static int setWindowTitleMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg) -+static int setWindowTitleMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[2][TYPE_INT_STR_SIZE(int)]; - char *fmt = NULL; - char *type = NULL; -@@ -4064,9 +4148,11 @@ out: - /* - * timer_ID = timer_add(macro_name, timeout[, "global"]) - */ --static int timerAddMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int timerAddMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int timeout; - char stringStorage[2][TYPE_INT_STR_SIZE(int)]; - char *name = NULL; -@@ -4132,9 +4218,11 @@ static int timerAddMS(WindowInfo *window - /* - * timer_remove(timer_ID) - */ --static int timerRemoveMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int timerRemoveMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int timerid; - XtIntervalId id; - TimerProcData *data, **s; -@@ -4175,9 +4263,11 @@ static int timerRemoveMS(WindowInfo *win - /* - * escaped_string = escape_literal(string) - */ --static int escapeLiteralMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int escapeLiteralMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - static const char chars_to_escape[] = "()[]<>{}.\\|^$*+?&"; - char stringStorage[TYPE_INT_STR_SIZE(int)]; - char *string = NULL; -@@ -4221,9 +4311,11 @@ static int escapeLiteralMS(WindowInfo *w - } - - /* T Balinski */ --static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int listDialogMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - macroCmdInfo *cmdData; - char stringStorage[TYPE_INT_STR_SIZE(int)]; - char textStorage[TYPE_INT_STR_SIZE(int)]; -@@ -4568,9 +4660,11 @@ static void listDialogEscCB(Widget w, Xt - #endif /* LESSTIF_VERSION */ - - --static int stringCompareMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int stringCompareMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[3][TYPE_INT_STR_SIZE(int)]; - char *leftStr, *rightStr, *argStr; - int considerCase = True; -@@ -4644,9 +4738,11 @@ static int stringCompareMS(WindowInfo *w - ** array sub-scripts (unless "lastnotnull" is present) - */ - --static int splitMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int splitMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[3][TYPE_INT_STR_SIZE(int)]; - char *sourceStr, *splitStr, *typeSplitStr; - int searchType, beginPos, foundStart, foundEnd, strLength, lastEnd; -@@ -4835,9 +4931,11 @@ static int splitMS(WindowInfo *window, D - ** end will be one beyond the last valid integer index of a contiguous sequence - ** starting at start. - */ --static int joinMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int joinMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[TYPE_INT_STR_SIZE(int)]; - char *sepStr; - int start, end, index; -@@ -4950,8 +5048,8 @@ static int joinMS(WindowInfo *window, Da - ** will be cleared, turning off backlighting. - */ - /* DISABLED for 5.4 --static int setBacklightStringMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg) -+static int setBacklightStringMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result) - { - char *backlightString; - -@@ -4977,17 +5075,21 @@ static int setBacklightStringMS(WindowIn - return True; - } */ - --static int cursorMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int cursorMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = TextGetCursorPos(window->lastFocus); - return True; - } - --static int lineMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int lineMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int line, cursorPos, colNum; - - result->tag = INT_TAG; -@@ -4998,9 +5100,11 @@ static int lineMV(WindowInfo *window, Da - return True; - } - --static int columnMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int columnMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - textBuffer *buf = window->buffer; - int cursorPos; - -@@ -5011,51 +5115,63 @@ static int columnMV(WindowInfo *window, - return True; - } - --static int fileNameMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int fileNameMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = STRING_TAG; - AllocNStringCpy(&result->val.str, window->filename); - return True; - } - --static int filePathMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int filePathMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = STRING_TAG; - AllocNStringCpy(&result->val.str, window->path); - return True; - } - --static int lengthMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int lengthMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->buffer->length; - return True; - } - --static int selectionStartMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int selectionStartMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->buffer->primary.selected ? - window->buffer->primary.start : -1; - return True; - } - --static int selectionEndMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int selectionEndMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->buffer->primary.selected ? - window->buffer->primary.end : -1; - return True; - } - --static int selectionLeftMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int selectionLeftMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - selection *sel = &window->buffer->primary; - - result->tag = INT_TAG; -@@ -5063,9 +5179,11 @@ static int selectionLeftMV(WindowInfo *w - return True; - } - --static int selectionRightMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int selectionRightMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - selection *sel = &window->buffer->primary; - - result->tag = INT_TAG; -@@ -5073,9 +5191,11 @@ static int selectionRightMV(WindowInfo * - return True; - } - --static int wrapMarginMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int wrapMarginMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int margin, nCols; - - XtVaGetValues(window->textArea, textNcolumns, &nCols, -@@ -5085,33 +5205,41 @@ static int wrapMarginMV(WindowInfo *wind - return True; - } - --static int statisticsLineMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int statisticsLineMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->showStats ? 1 : 0; - return True; - } - --static int incSearchLineMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int incSearchLineMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->showISearchLine ? 1 : 0; - return True; - } - --static int showLineNumbersMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int showLineNumbersMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->showLineNumbers ? 1 : 0; - return True; - } - --static int autoIndentMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int autoIndentMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char *res = NULL; - - switch (window->indentStyle) { -@@ -5135,9 +5263,11 @@ static int autoIndentMV(WindowInfo *wind - return True; - } - --static int wrapTextMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int wrapTextMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char *res = NULL; - - switch (window->wrapMode) { -@@ -5161,33 +5291,41 @@ static int wrapTextMV(WindowInfo *window - return True; - } - --static int highlightSyntaxMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int highlightSyntaxMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->highlightSyntax ? 1 : 0; - return True; - } - --static int makeBackupCopyMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int makeBackupCopyMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->saveOldVersion ? 1 : 0; - return True; - } - --static int incBackupMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int incBackupMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->autoSave ? 1 : 0; - return True; - } - --static int showMatchingMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int showMatchingMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char *res = NULL; - - switch (window->showMatchingStyle) { -@@ -5211,33 +5349,41 @@ static int showMatchingMV(WindowInfo *wi - return True; - } - --static int overTypeModeMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int overTypeModeMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->overstrike ? 1 : 0; - return True; - } - --static int readOnlyMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int readOnlyMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = (IS_ANY_LOCKED(window->lockReasons)) ? 1 : 0; - return True; - } - --static int lockedMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int lockedMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = (IS_USER_LOCKED(window->lockReasons)) ? 1 : 0; - return True; - } - --static int fileFormatMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int fileFormatMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char *res = NULL; - - switch (window->fileFormat) { -@@ -5260,130 +5406,162 @@ static int fileFormatMV(WindowInfo *wind - return True; - } - --static int fontNameMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int fontNameMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = STRING_TAG; - AllocNStringCpy(&result->val.str, window->fontName); - return True; - } - --static int fontNameItalicMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int fontNameItalicMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = STRING_TAG; - AllocNStringCpy(&result->val.str, window->italicFontName); - return True; - } - --static int fontNameBoldMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int fontNameBoldMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = STRING_TAG; - AllocNStringCpy(&result->val.str, window->boldFontName); - return True; - } - --static int fontNameBoldItalicMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int fontNameBoldItalicMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = STRING_TAG; - AllocNStringCpy(&result->val.str, window->boldItalicFontName); - return True; - } - --static int subscriptSepMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int subscriptSepMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = STRING_TAG; - result->val.str.rep = PERM_ALLOC_STR(ARRAY_DIM_SEP); - result->val.str.len = strlen(result->val.str.rep); - return True; - } - --static int minFontWidthMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int minFontWidthMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = TextGetMinFontWidth(window->textArea, window->highlightSyntax); - return True; - } - --static int maxFontWidthMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int maxFontWidthMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = TextGetMaxFontWidth(window->textArea, window->highlightSyntax); - return True; - } - --static int topLineMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int topLineMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = TextFirstVisibleLine(window->lastFocus); - return True; - } - --static int numDisplayLinesMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int numDisplayLinesMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = TextNumVisibleLines(window->lastFocus); - return True; - } - --static int displayWidthMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int displayWidthMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = TextVisibleWidth(window->lastFocus); - return True; - } - --static int activePaneMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int activePaneMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = WidgetToPaneIndex(window, window->lastFocus) + 1; - return True; - } - --static int nPanesMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int nPanesMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->nPanes + 1; - return True; - } - --static int emptyArrayMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int emptyArrayMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = ARRAY_TAG; - result->val.arrayPtr = NULL; - return True; - } - --static int serverNameMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int serverNameMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = STRING_TAG; - AllocNStringCpy(&result->val.str, GetPrefServerName()); - return True; - } - --static int tabDistMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int tabDistMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->buffer->tabDist; - return True; - } - --static int emTabDistMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int emTabDistMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int dist; - - XtVaGetValues(window->textArea, textNemulateTabs, &dist, NULL); -@@ -5392,25 +5570,31 @@ static int emTabDistMV(WindowInfo *windo - return True; - } - --static int useTabsMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int useTabsMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->buffer->useTabs; - return True; - } - --static int modifiedMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int modifiedMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = window->fileChanged; - return True; - } - --static int languageModeMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int languageModeMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char *lmName = LanguageModeName(window->languageMode); - - if (lmName == NULL) -@@ -5421,8 +5605,8 @@ static int languageModeMV(WindowInfo *wi - } - - /* DISABLED for 5.4 --static int backlightStringMV(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg) -+static int backlightStringMV(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result) - { - char *backlightString = window->backlightCharTypes; - -@@ -5438,9 +5622,11 @@ static int backlightStringMV(WindowInfo - /* - ** Range set macro variables and functions - */ --static int rangesetListMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int rangesetListMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - RangesetTable *rangesetTable = window->buffer->rangesetTable; - unsigned char *rangesetList; - char *allocIndexStr; -@@ -5484,9 +5670,11 @@ static int rangesetListMV(WindowInfo *wi - ** different point revisions. This is done because the macro interface - ** does not change for the same version. - */ --static int versionMV(WindowInfo* window, DataValue* argList, int nArgs, -- DataValue* result, char** errMsg) -+static int versionMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - static unsigned version = NEDIT_VERSION * 1000 + NEDIT_REVISION; - - result->tag = INT_TAG; -@@ -5500,9 +5688,11 @@ static int versionMV(WindowInfo* window, - ** default of ~/.nedit or $HOME. (See the online documentation for details - ** about the algorithm.) - */ --static int neditHomeMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int neditHomeMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - const char *neditRCName = GetRCFileName(NEDIT_RC); - char neditHome[MAXPATHLEN]; - -@@ -5519,9 +5709,11 @@ static int neditHomeMV(WindowInfo *windo - /* - ** Returns the transient status of the current window - */ --static int transientMV(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int transientMV(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - result->tag = INT_TAG; - result->val.n = !!window->transient; - return True; -@@ -5535,9 +5727,11 @@ static int transientMV(WindowInfo *windo - ** If called with no arguments, returns a single rangeset label (not an array), - ** or an empty string if there are no rangesets available. - */ --static int rangesetCreateMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int rangesetCreateMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int label; - int i, nRangesetsRequired; - DataValue element; -@@ -5591,9 +5785,11 @@ static int rangesetCreateMS(WindowInfo * - /* - ** Built-in macro subroutine for forgetting a range set. - */ --static int rangesetDestroyMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int rangesetDestroyMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - RangesetTable *rangesetTable = window->buffer->rangesetTable; - DataValue *array; - DataValue element; -@@ -5654,9 +5850,11 @@ static int rangesetDestroyMS(WindowInfo - ** Arguments are $1: range set name. - ** return value is an array indexed 0 to n, with the rangeset labels as values; - */ --static int rangesetGetByNameMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int rangesetGetByNameMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[1][TYPE_INT_STR_SIZE(int)]; - Rangeset *rangeset; - int label; -@@ -5719,9 +5917,11 @@ static int rangesetGetByNameMS(WindowInf - ** if any to specify range to add - must not be rectangular). Returns the - ** index of the newly added range (cases b and c), or 0 (case a). - */ --static int rangesetAddMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int rangesetAddMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - textBuffer *buffer = window->buffer; - RangesetTable *rangesetTable = buffer->rangesetTable; - Rangeset *targetRangeset, *sourceRangeset; -@@ -5818,9 +6018,11 @@ static int rangesetAddMS(WindowInfo *win - ** to RangesetSubtract()/RangesetSubtractBetween(), the handling of an - ** undefined destination range, and that it returns no value. - */ --static int rangesetSubtractMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int rangesetSubtractMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - textBuffer *buffer = window->buffer; - RangesetTable *rangesetTable = buffer->rangesetTable; - Rangeset *targetRangeset, *sourceRangeset; -@@ -5897,9 +6099,11 @@ static int rangesetSubtractMS(WindowInfo - ** label (one alphabetic character). Returns nothing. Fails if range set - ** undefined. - */ --static int rangesetInvertMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int rangesetInvertMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - - RangesetTable *rangesetTable = window->buffer->rangesetTable; - Rangeset *rangeset; -@@ -5937,9 +6141,11 @@ static int rangesetInvertMS(WindowInfo * - ** argument of a rangeset label. Returns an array with the following keys: - ** defined, count, color, mode. - */ --static int rangesetInfoMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int rangesetInfoMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - RangesetTable *rangesetTable = window->buffer->rangesetTable; - Rangeset *rangeset = NULL; - int count, defined, uline; -@@ -6012,9 +6218,11 @@ static int rangesetInfoMS(WindowInfo *wi - ** ranges, otherwise select the individual range specified. Returns - ** an array with the keys "start" and "end" and values - */ --static int rangesetRangeMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int rangesetRangeMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - textBuffer *buffer = window->buffer; - RangesetTable *rangesetTable = buffer->rangesetTable; - Rangeset *rangeset; -@@ -6078,9 +6286,11 @@ static int rangesetRangeMS(WindowInfo *w - ** false (zero) if not in a range, range index (1-based) if in a range; - ** fails if parameters were bad. - */ --static int rangesetIncludesPosMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg) -+static int rangesetIncludesPosMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - textBuffer *buffer = window->buffer; - RangesetTable *rangesetTable = buffer->rangesetTable; - Rangeset *rangeset; -@@ -6132,9 +6342,11 @@ static int rangesetIncludesPosMS(WindowI - ** found/applied. If no color is applied, any current color is removed. Returns - ** true if the rangeset is valid. - */ --static int rangesetSetColorMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg) -+static int rangesetSetColorMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[1][TYPE_INT_STR_SIZE(int)]; - textBuffer *buffer = window->buffer; - RangesetTable *rangesetTable = buffer->rangesetTable; -@@ -6180,9 +6392,11 @@ static int rangesetSetColorMS(WindowInfo - ** the underlineMode string, which should be specified as "leave" (let any - ** syntax highlighting underlines to appear as undisturbed), "add" or "remove". - */ --static int rangesetSetUnderlineMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg) -+static int rangesetSetUnderlineMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[1][TYPE_INT_STR_SIZE(int)]; - textBuffer *buffer = window->buffer; - RangesetTable *rangesetTable = buffer->rangesetTable; -@@ -6232,9 +6446,11 @@ static int rangesetSetUnderlineMS(Window - ** Set the name of a range set's ranges. Returns - ** true if the rangeset is valid. - */ --static int rangesetSetNameMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg) -+static int rangesetSetNameMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[1][TYPE_INT_STR_SIZE(int)]; - textBuffer *buffer = window->buffer; - RangesetTable *rangesetTable = buffer->rangesetTable; -@@ -6278,9 +6494,11 @@ static int rangesetSetNameMS(WindowInfo - ** Change a range's modification response. Returns true if the rangeset is - ** valid and the response type name is valid. - */ --static int rangesetSetModeMS(WindowInfo *window, DataValue *argList, -- int nArgs, DataValue *result, char **errMsg) -+static int rangesetSetModeMS(RestartData *context, DataValue *argList, -+ int nArgs, DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[1][TYPE_INT_STR_SIZE(int)]; - textBuffer *buffer = window->buffer; - RangesetTable *rangesetTable = buffer->rangesetTable; -@@ -6462,9 +6680,11 @@ static int fillStyleResult(DataValue *re - ** ["italic"] '1' if style is italic, '0' otherwise - ** - */ --static int getStyleByNameMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int getStyleByNameMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[1][TYPE_INT_STR_SIZE(int)]; - char *styleName; - -@@ -6502,9 +6722,11 @@ static int getStyleByNameMS(WindowInfo * - ** ["extent"] Forward distance from position over which style applies - ** - */ --static int getStyleAtPosMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int getStyleAtPosMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int patCode; - int bufferPos; - textBuffer *buf = window->buffer; -@@ -6607,9 +6829,11 @@ static int fillPatternResult(DataValue * - ** The returned array looks like this: - ** ["style"] Name of style - */ --static int getPatternByNameMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int getPatternByNameMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[1][TYPE_INT_STR_SIZE(int)]; - char *patternName = NULL; - highlightPattern *pattern; -@@ -6645,9 +6869,11 @@ static int getPatternByNameMS(WindowInfo - ** ["style"] Name of style - ** ["extent"] Distance from position over which this pattern applies - */ --static int getPatternAtPosMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int getPatternAtPosMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int bufferPos = -1; - textBuffer *buffer = window->buffer; - int patCode = 0; -@@ -6703,9 +6929,11 @@ static int getPatternAtPosMS(WindowInfo - ** of "pos" holds "-1", "len" holds "0" and "direction" holds "-1". - ** - */ --static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int getMatchingMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int startPos; - int matchPos, matchLen; - int direction; -@@ -6780,9 +7008,11 @@ static int getMatchingMS(WindowInfo *win - /* Insert a string into the acutal dictionary */ - /* Syntax : dictinsert(string) % assuming weight = 1 */ - /* dictinsert(string, weight) */ --static int dictinsertMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int dictinsertMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - static long nr_insertions = 0; - int weight = 1; - -@@ -6830,9 +7060,11 @@ static int dictinsertMS(WindowInfo *wind - /* Test if string is an element of the acutal dictionary */ - /* Syntax : weight = dictiselement(string) */ - /* Output argument : (integer) weight of element */ --static int dictiselementMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int dictiselementMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[25], *string; - unsigned long weight; - -@@ -6862,9 +7094,11 @@ static int dictiselementMS(WindowInfo *w - - /* Load/append file to current dictionary */ - /* Syntax : dict_append(filename) */ --static int dictappendMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int dictappendMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char stringStorage[25], *string; - - /* Validate arguments and convert to int */ -@@ -6887,9 +7121,11 @@ static int dictappendMS(WindowInfo *wind - /* dict_save(filename) => set dictionary filename (otherwise default filename is used) */ - /* dict_save("") => return current filename as string */ - /* dict_save(autoSave, cumulSave) => autoSave = "on"/"off"/"flush", cumulSave=0,1,2,3,... */ --static int dictsaveMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int dictsaveMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int cumulSave = 0; - - char stringStorage[25], *string; -@@ -6957,9 +7193,11 @@ static int dictsaveMS(WindowInfo *window - */ - #define MAXMATCHES 128 - --static int dictcompleteMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int dictcompleteMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int minchars = 0; - int maxmatches = 1; - static char *s2[MAXMATCHES]; /* at max, 128 possible completions can be returned */ -@@ -7028,9 +7266,11 @@ static int dictcompleteMS(WindowInfo *wi - ** UL convertPos patch: - ** translate given line / column parameter to text buffer position. - */ --static int toPosMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int toPosMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - char *lineStr, stringStorage1[TYPE_INT_STR_SIZE(int)]; - char *colStr , stringStorage2[TYPE_INT_STR_SIZE(int)]; - char *lineColString; -@@ -7129,9 +7369,11 @@ static int toPosMS(WindowInfo *window, D - ** UL convertPos patch: - ** translate given text buffer position to line number. - */ --static int toLineMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int toLineMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int line, column; - int pos; - -@@ -7174,9 +7416,11 @@ static int toLineMS(WindowInfo *window, - ** UL convertPos patch: - ** translate given text buffer position to column number. - */ --static int toColumnMS(WindowInfo *window, DataValue *argList, int nArgs, -- DataValue *result, char **errMsg) -+static int toColumnMS(RestartData *context, DataValue *argList, int nArgs, -+ DataValue *result) - { -+ WindowInfo *window = MacroFocusWindow(); -+ char **errMsg = &context->errMsg; - int line, column; - int pos; - textBuffer *buf = window->buffer; -diff --quilt old/source/macro.h new/source/macro.h ---- old/source/macro.h -+++ new/source/macro.h -@@ -37,7 +37,7 @@ - - typedef struct BuiltInSubrNameTag { - const char *name; /* its macro identifier */ -- BuiltInSubr macroSubr; /* pointer to the function to call */ -+ BuiltInSubr *macroSubr; /* pointer to the function to call */ - } BuiltInSubrName; - - /* Structure used to build an initialized static array, each entry describing a diff --git a/pos_line_convert.patch b/pos_line_convert.patch index 709f1a8..a6defe0 100644 --- a/pos_line_convert.patch +++ b/pos_line_convert.patch @@ -96,7 +96,7 @@ diff --quilt old/source/macro.c new/source/macro.c { NULL, NULL } /* sentinel */ }; -@@ -6391,6 +6405,202 @@ static int dictcompleteMS(WindowInfo *wi +@@ -6392,6 +6406,202 @@ static int dictcompleteMS(WindowInfo *wi } /* end of new macros for dictionary Christian Merkwirth 2000 */ diff --git a/pushImmed.patch b/pushImmed.patch index e232b95..11c8a50 100644 --- a/pushImmed.patch +++ b/pushImmed.patch @@ -79,8 +79,8 @@ diff --quilt old/source/parse.y new/source/parse.y +%type arglist %type cond comastmts for while else and or arrayexpr %type evalsym - -@@ -380,7 +381,7 @@ arrayexpr: numexpr { + %type definesym +@@ -384,7 +385,7 @@ arrayexpr: numexpr { } ; numexpr: NUMBER { @@ -89,7 +89,7 @@ diff --quilt old/source/parse.y new/source/parse.y } | STRING { ADD_OP(OP_PUSH_SYM); ADD_SYM($1); -@@ -611,13 +612,8 @@ static int yylex(void) +@@ -615,13 +616,8 @@ static int yylex(void) /* process number tokens */ if (isdigit((unsigned char)*InPtr)) { /* number */ diff --git a/relativeFileNormalization.diff b/relativeFileNormalization.diff index 00e9824..64c667d 100644 --- a/relativeFileNormalization.diff +++ b/relativeFileNormalization.diff @@ -92,7 +92,7 @@ diff --quilt old/source/macro.c new/source/macro.c { NULL, NULL } /* sentinel */ }; -@@ -2042,7 +2045,7 @@ static int focusWindowMS(WindowInfo *win +@@ -2043,7 +2046,7 @@ static int focusWindowMS(WindowInfo *win if (w == NULL) { strncpy(normalizedString, string, MAXPATHLEN); normalizedString[MAXPATHLEN-1] = '\0'; @@ -101,7 +101,7 @@ diff --quilt old/source/macro.c new/source/macro.c /* Something is broken with the input pathname. */ *errMsg = "Pathname too long in focus_window()"; return False; -@@ -2478,6 +2481,108 @@ static int clipboardToStringMS(WindowInf +@@ -2479,6 +2482,108 @@ static int clipboardToStringMS(WindowInf return True; } @@ -210,7 +210,7 @@ diff --quilt old/source/macro.c new/source/macro.c /* ** Built-in macro subroutine for reading the contents of a text file into -@@ -2498,7 +2603,9 @@ static int readFileMS(WindowInfo *window +@@ -2499,7 +2604,9 @@ static int readFileMS(WindowInfo *window return wrongNArgsErr(errMsg); if (!readStringArg(argList[0], &name, stringStorage, errMsg)) return False; @@ -221,7 +221,7 @@ diff --quilt old/source/macro.c new/source/macro.c /* Read the whole file into an allocated string */ if ((fp = fopen(name, "r")) == NULL) goto errorNoClose; -@@ -2577,7 +2684,9 @@ static int writeOrAppendFile(int append, +@@ -2578,7 +2685,9 @@ static int writeOrAppendFile(int append, return False; if (!readStringArg(argList[1], &name, stringStorage[0], errMsg)) return False; @@ -232,7 +232,7 @@ diff --quilt old/source/macro.c new/source/macro.c /* open the file */ if ((fp = fopen(name, append ? "a" : "w")) == NULL) { result->tag = INT_TAG; -@@ -5253,7 +5362,7 @@ static int neditHomeMV(WindowInfo *windo +@@ -5254,7 +5363,7 @@ static int neditHomeMV(WindowInfo *windo const char *neditRCName = GetRCFileName(NEDIT_RC); char neditHome[MAXPATHLEN]; diff --git a/remove-args-from-DISASM_RT.patch b/remove-args-from-DISASM_RT.patch index f6988fd..595e07b 100644 --- a/remove-args-from-DISASM_RT.patch +++ b/remove-args-from-DISASM_RT.patch @@ -6,7 +6,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -139,10 +139,10 @@ static void disasmInternal(Inst *inst, i +@@ -136,10 +136,10 @@ static void disasmInternal(Inst *inst, i static void stackdump(int n, int extra); static void stackdumpInternal(int n, int extra); #define STACKDUMP(n, x) stackdump(n, (x) + 10) @@ -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 */ -@@ -1561,7 +1561,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1560,7 +1560,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); \ -@@ -1572,7 +1572,7 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1571,7 +1571,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); \ -@@ -1592,7 +1592,7 @@ OP_FUNCTION(pushSymVal) +@@ -1591,7 +1591,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); -@@ -1647,7 +1647,7 @@ OP_FUNCTION(pushImmed) +@@ -1646,7 +1646,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); -@@ -1661,7 +1661,7 @@ OP_FUNCTION(pushArgVal) +@@ -1660,7 +1660,7 @@ static int pushArgVal(void) { int nArgs, argNum; @@ -64,16 +64,16 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 3); POP_INT(argNum); -@@ -1677,7 +1677,7 @@ OP_FUNCTION(pushArgVal) +@@ -1676,7 +1676,7 @@ static int pushArgVal(void) - OP_FUNCTION(pushArgCount) + static int pushArgCount(void) { - DISASM_RT(PC-1, 1); + DISASM_RT(); STACKDUMP(0, 3); PUSH_INT(FRAME_GET_ARG_COUNT()); -@@ -1690,7 +1690,7 @@ OP_FUNCTION(pushArgArray) +@@ -1689,7 +1689,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 = FRAME_GET_ARG_COUNT(); -@@ -1731,7 +1731,7 @@ OP_FUNCTION(pushArraySymVal) +@@ -1730,7 +1730,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); -@@ -1774,7 +1774,7 @@ OP_FUNCTION(anonArrayOpen) +@@ -1773,7 +1773,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 */ -@@ -1805,7 +1805,7 @@ OP_FUNCTION(anonArraySkip) +@@ -1804,7 +1804,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); -@@ -1837,7 +1837,7 @@ OP_FUNCTION(anonArrayNextVal) +@@ -1836,7 +1836,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); -@@ -1874,9 +1874,10 @@ OP_FUNCTION(anonArrayIndexVal) +@@ -1873,9 +1873,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); -@@ -1921,7 +1922,7 @@ OP_FUNCTION(anonArrayClose) +@@ -1920,7 +1921,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 */ -@@ -1971,9 +1972,10 @@ static int namedArg1orN(Boolean isFirst) +@@ -1970,9 +1971,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); -@@ -2017,7 +2019,7 @@ OP_FUNCTION(swapTop2) +@@ -2016,7 +2018,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); -@@ -2042,7 +2044,7 @@ OP_FUNCTION(assign) +@@ -2041,7 +2043,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); -@@ -2089,7 +2091,7 @@ OP_FUNCTION(popStack) +@@ -2088,7 +2090,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); -@@ -2106,7 +2108,7 @@ OP_FUNCTION(dupStack) +@@ -2105,7 +2107,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); -@@ -2128,7 +2130,7 @@ OP_FUNCTION(add) +@@ -2127,7 +2129,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); -@@ -2200,7 +2202,7 @@ OP_FUNCTION(subtract) +@@ -2199,7 +2201,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); -@@ -2272,7 +2274,7 @@ OP_FUNCTION(divide) +@@ -2271,7 +2273,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); -@@ -2288,7 +2290,7 @@ OP_FUNCTION(modulo) +@@ -2287,7 +2289,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); -@@ -2345,7 +2347,7 @@ OP_FUNCTION(eq) +@@ -2344,7 +2346,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); -@@ -2401,7 +2403,7 @@ OP_FUNCTION(bitAnd) +@@ -2400,7 +2402,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); -@@ -2461,7 +2463,7 @@ OP_FUNCTION(bitOr) +@@ -2460,7 +2462,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); -@@ -2544,7 +2546,7 @@ OP_FUNCTION(power) +@@ -2543,7 +2545,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); -@@ -2666,9 +2668,10 @@ OP_FUNCTION(concat) +@@ -2665,9 +2667,10 @@ static int concat(void) int nExpr; @@ -271,7 +271,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nExpr, 3); len = concatenateNwithSep(nExpr, "", &out, False); -@@ -2838,10 +2841,11 @@ OP_FUNCTION(callSubroutine) +@@ -2837,10 +2840,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); -@@ -2863,10 +2867,11 @@ OP_FUNCTION(callSubroutineStackedN) +@@ -2862,10 +2866,11 @@ static int callSubroutineStackedN(void) /* this is much like callSubroutine, but we get nArgs off the stack and it will always be negative since there is always an argArray */ @@ -297,7 +297,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(-nArgs + 1, 3); /* +1 for stacked nArgs */ POP_INT(nArgs); -@@ -2975,7 +2980,7 @@ OP_FUNCTION(unpackArrayToArgs) +@@ -2974,7 +2979,7 @@ static int unpackArrayToArgs(void) SparseArrayEntry *iter; DataValue dvEntry, dvArray, argArray; @@ -306,7 +306,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 3); GET_IMMED(nArgs); -@@ -3063,7 +3068,7 @@ static int returnValOrNone(int valOnStac +@@ -3062,7 +3067,7 @@ static int returnValOrNone(int valOnStac DataValue retVal; static DataValue noValue = {NO_TAG, {0}}; @@ -315,7 +315,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(StackP - FrameP + FRAME_GET_ARG_COUNT() + FP_TO_ARGS_DIST, 3); /* return value is on the stack */ -@@ -3093,7 +3098,7 @@ OP_FUNCTION(branch) +@@ -3092,7 +3097,7 @@ static int branch(void) { Inst *addr; @@ -324,16 +324,16 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); GET_BRANCH(addr); -@@ -3125,7 +3130,7 @@ static int branchIf(Boolean trueOrFalse) - - GET_BRANCH(addr); +@@ -3122,7 +3127,7 @@ static int branchIf(Boolean trueOrFalse) + int value; + Inst *addr; - DISASM_RT(PC-1, 2); + DISASM_RT(); STACKDUMP(1, 3); - POP_INT(value); -@@ -3147,7 +3152,7 @@ OP_FUNCTION(branchNever) + GET_BRANCH(addr); +@@ -3146,7 +3151,7 @@ static int branchNever(void) { Inst *addr; @@ -342,7 +342,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); GET_BRANCH(addr); -@@ -3512,9 +3517,10 @@ OP_FUNCTION(arrayRef) +@@ -3511,9 +3516,10 @@ static int arrayRef(void) char *keyString = NULL; int nDim; @@ -354,7 +354,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nDim+1, 3); if (nDim > 0) { -@@ -3562,9 +3568,10 @@ OP_FUNCTION(arrayAssign) +@@ -3561,9 +3567,10 @@ static int arrayAssign(void) int errNum; int nDim; @@ -366,7 +366,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nDim+2, 3); if (nDim > 0) { -@@ -3614,10 +3621,11 @@ OP_FUNCTION(arrayRefAndAssignSetup) +@@ -3613,10 +3620,11 @@ static int arrayRefAndAssignSetup(void) char *keyString = NULL; int binaryOp, nDim; @@ -379,7 +379,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nDim + (binaryOp ? 2 : 1), 3); if (binaryOp) { -@@ -3668,7 +3676,7 @@ OP_FUNCTION(beginArrayIter) +@@ -3667,7 +3675,7 @@ static int beginArrayIter(void) DataValue *iteratorValPtr; DataValue arrayVal; @@ -388,7 +388,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 3); GET_SYM(iterator); -@@ -3727,7 +3735,7 @@ OP_FUNCTION(arrayIter) +@@ -3726,7 +3734,7 @@ static int arrayIter(void) Inst *branchAddr; int withVal; @@ -397,7 +397,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 4); GET_IMMED(withVal); -@@ -3803,7 +3811,7 @@ OP_FUNCTION(beginArrayMultiIterArray) +@@ -3802,7 +3810,7 @@ static int beginArrayMultiIterArray(void DataValue arrayVal; int nDims; @@ -406,7 +406,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); GET_SYM(iterator); -@@ -3905,7 +3913,7 @@ OP_FUNCTION(arrayMultiIterArray) +@@ -3904,7 +3912,7 @@ static int arrayMultiIterArray(void) int nDims, d; Boolean keyFound = False; @@ -415,7 +415,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 4); GET_IMMED(withVal); -@@ -4007,7 +4015,7 @@ OP_FUNCTION(inArray) +@@ -4006,7 +4014,7 @@ static int inArray(void) char *keyStr; int inResult = 0; @@ -424,7 +424,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); POP(theArray); -@@ -4051,9 +4059,10 @@ OP_FUNCTION(deleteArrayElement) +@@ -4050,9 +4058,10 @@ static int deleteArrayElement(void) char *keyString = NULL; int nDim; @@ -436,7 +436,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(nDim + 1, 3); if (nDim > 0) { -@@ -4144,7 +4153,7 @@ OP_FUNCTION(arrayAssignNext) +@@ -4143,7 +4152,7 @@ static int arrayAssignNext(void) DataValue srcValue, dstArray; int errNum; @@ -445,7 +445,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); POP(srcValue); -@@ -4186,7 +4195,7 @@ OP_FUNCTION(arrayNextNumIdx) +@@ -4185,7 +4194,7 @@ static int arrayNextNumIdx(void) DataValue srcArray; SparseArrayEntry *iter; diff --git a/remove-cast-warnings.patch b/remove-cast-warnings.patch index 8c41470..8ee72ba 100644 --- a/remove-cast-warnings.patch +++ b/remove-cast-warnings.patch @@ -129,7 +129,7 @@ diff --quilt old/source/file.c new/source/file.c diff --quilt old/source/macro.c new/source/macro.c --- old/source/macro.c +++ new/source/macro.c -@@ -2846,7 +2846,7 @@ static int dialogMS(WindowInfo *window, +@@ -2847,7 +2847,7 @@ static int dialogMS(WindowInfo *window, readStringArg(argList[i], &btnLabel, btnStorage, errMsg); btn = XtVaCreateManagedWidget("mdBtn", xmPushButtonWidgetClass, dialog, XmNlabelString, s1=XmStringCreateSimple(btnLabel), @@ -138,7 +138,7 @@ diff --quilt old/source/macro.c new/source/macro.c XtAddCallback(btn, XmNactivateCallback, dialogBtnCB, window); XmStringFree(s1); } -@@ -2887,7 +2887,7 @@ static void dialogBtnCB(Widget w, XtPoin +@@ -2888,7 +2888,7 @@ static void dialogBtnCB(Widget w, XtPoin return; /* shouldn't happen */ if (XtClass(w) == xmPushButtonWidgetClass) { XtVaGetValues(w, XmNuserData, &userData, NULL); @@ -147,7 +147,7 @@ diff --quilt old/source/macro.c new/source/macro.c } else retVal.val.n = 1; retVal.tag = INT_TAG; -@@ -3023,7 +3023,7 @@ static int stringDialogMS(WindowInfo *wi +@@ -3024,7 +3024,7 @@ static int stringDialogMS(WindowInfo *wi readStringArg(argList[i], &btnLabel, btnStorage, errMsg); btn = XtVaCreateManagedWidget("mdBtn", xmPushButtonWidgetClass, dialog, XmNlabelString, s1=XmStringCreateSimple(btnLabel), @@ -156,7 +156,7 @@ diff --quilt old/source/macro.c new/source/macro.c XtAddCallback(btn, XmNactivateCallback, stringDialogBtnCB, window); XmStringFree(s1); } -@@ -3077,7 +3077,7 @@ static void stringDialogBtnCB(Widget w, +@@ -3078,7 +3078,7 @@ static void stringDialogBtnCB(Widget w, returned in w. */ if (XtClass(w) == xmPushButtonWidgetClass) { XtVaGetValues(w, XmNuserData, &userData, NULL); @@ -165,7 +165,7 @@ diff --quilt old/source/macro.c new/source/macro.c } else btnNum = 1; -@@ -3602,7 +3602,7 @@ static int listDialogMS(WindowInfo *wind +@@ -3603,7 +3603,7 @@ static int listDialogMS(WindowInfo *wind readStringArg(argList[i], &btnLabel, btnStorage, errMsg); btn = XtVaCreateManagedWidget("mdBtn", xmPushButtonWidgetClass, dialog, XmNlabelString, s1=XmStringCreateSimple(btnLabel), @@ -174,7 +174,7 @@ diff --quilt old/source/macro.c new/source/macro.c XtAddCallback(btn, XmNactivateCallback, listDialogBtnCB, window); XmStringFree(s1); } -@@ -3682,7 +3682,7 @@ static void listDialogBtnCB(Widget w, Xt +@@ -3683,7 +3683,7 @@ static void listDialogBtnCB(Widget w, Xt returned in w. */ if (XtClass(w) == xmPushButtonWidgetClass) { XtVaGetValues(w, XmNuserData, &userData, NULL); diff --git a/series b/series index 37a1023..453095f 100644 --- a/series +++ b/series @@ -113,10 +113,12 @@ textDisp-cursor-position.patch macroJoin.diff backup-tilde-at-end.patch op-not-func-in-Inst.patch +unify-branch-setup.patch abstract-access-to-PC.patch +typed-Inst.patch abstract-access-to-FrameP.patch handle-error-in-RunMacroAsSubrCall.patch -OP_FUNCTION.patch remove-args-from-DISASM_RT.patch EXEC_ERROR.patch -pass-context-to-ops.patch +global-RestartData.patch +global-AccumulatorData.patch diff --git a/setWindowTitleFormat.diff b/setWindowTitleFormat.diff index b79f4cb..4f939e8 100644 --- a/setWindowTitleFormat.diff +++ b/setWindowTitleFormat.diff @@ -64,7 +64,7 @@ diff --quilt old/source/macro.c new/source/macro.c { NULL, NULL } /* sentinel */ }; -@@ -3791,6 +3794,80 @@ static int defineMS(WindowInfo *window, +@@ -3792,6 +3795,80 @@ static int defineMS(WindowInfo *window, return True; } diff --git a/shell_command-make-input-parameter-optional.patch b/shell_command-make-input-parameter-optional.patch index 83dae84..654d484 100644 --- a/shell_command-make-input-parameter-optional.patch +++ b/shell_command-make-input-parameter-optional.patch @@ -12,7 +12,7 @@ optional and defaults it to "". diff --quilt old/source/macro.c new/source/macro.c --- old/source/macro.c +++ new/source/macro.c -@@ -2708,13 +2708,14 @@ static int getenvMS(WindowInfo *window, +@@ -2709,13 +2709,14 @@ static int getenvMS(WindowInfo *window, static int shellCmdMS(WindowInfo *window, DataValue *argList, int nArgs, DataValue *result, char **errMsg) { diff --git a/stringToNum.diff b/stringToNum.diff index 0e41d56..416c5ec 100644 --- a/stringToNum.diff +++ b/stringToNum.diff @@ -11,7 +11,7 @@ It seems a shame to scan a string twice, as the older version does. diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -4088,33 +4088,52 @@ static int execError(const char *s1, con +@@ -4112,33 +4112,52 @@ static int execError(const char *s1, con return STAT_ERROR; } diff --git a/timer_macros.patch b/timer_macros.patch index e58ce1a..cc2e140 100644 --- a/timer_macros.patch +++ b/timer_macros.patch @@ -47,7 +47,7 @@ diff --quilt old/source/macro.c new/source/macro.c { NULL, NULL } /* sentinel */ }; -@@ -3868,6 +3875,167 @@ static int setWindowTitleMS(WindowInfo * +@@ -3869,6 +3876,167 @@ static int setWindowTitleMS(WindowInfo * return True; } diff --git a/transient-documents.patch b/transient-documents.patch index 1eddd2b..ea8f9f4 100644 --- a/transient-documents.patch +++ b/transient-documents.patch @@ -438,7 +438,7 @@ diff --quilt old/source/macro.c new/source/macro.c { NULL, NULL } /* sentinel */ }; -@@ -4842,6 +4845,17 @@ static int neditHomeMV(WindowInfo *windo +@@ -4843,6 +4846,17 @@ static int neditHomeMV(WindowInfo *windo } /* diff --git a/typed-Inst.patch b/typed-Inst.patch new file mode 100644 index 0000000..e99bdb0 --- /dev/null +++ b/typed-Inst.patch @@ -0,0 +1,481 @@ +--- + + source/interpret.c | 214 +++++++++++++++++++++++++++++++++++------------------ + source/interpret.h | 16 ++- + 2 files changed, 156 insertions(+), 74 deletions(-) + +diff --quilt old/source/interpret.c new/source/interpret.c +--- old/source/interpret.c ++++ new/source/interpret.c +@@ -113,6 +113,7 @@ static int inTypeOfMode; + + static const char *tagToStr(enum typeTags tag); + static const char *typeToStr(enum symTypes type); ++static const char *instTypeToStr(enum instTypes type); + + /*#define DEBUG_ASSEMBLY*/ + /*#define DEBUG_STACK*/ +@@ -336,7 +337,8 @@ int AddOp(int op, char **msg) + *msg = "macro too large"; + return 0; + } +- ProgP->op = op; ++ ProgP->type = OP_INST; ++ ProgP->val.op = op; + ProgP++; + return 1; + } +@@ -351,7 +353,8 @@ int AddSym(Symbol *sym, char **msg) + return 0; + } + sym->added = 1; +- ProgP->sym = sym; ++ ProgP->type = SYM_INST; ++ ProgP->val.sym = sym; + ProgP++; + return 1; + } +@@ -359,13 +362,14 @@ int AddSym(Symbol *sym, char **msg) + /* + ** Add an immediate value operand to the current program + */ +-int AddImmediate(int value, char **msg) ++int AddImmediate(int immed, char **msg) + { + if (ProgP >= &Prog[PROGRAM_SIZE]) { + *msg = "macro too large"; + return 0; + } +- ProgP->value = value; ++ ProgP->type = IMMED_INST; ++ ProgP->val.immed = immed; + ProgP++; + return 1; + } +@@ -379,8 +383,8 @@ int AddBranchOffset(Inst *to, char **msg + *msg = "macro too large"; + return 0; + } +- /* Should be ptrdiff_t for branch offsets */ +- ProgP->value = to - ProgP; ++ ProgP->type = BRANCH_INST; ++ ProgP->val.branch = to - ProgP; + ProgP++; + + return 1; +@@ -391,7 +395,11 @@ int AddBranchOffset(Inst *to, char **msg + */ + int SetBranchOffset(Inst *from, Inst *to, char **msg) + { +- from->value = to - from; ++ if (from->type != BRANCH_INST) { ++ *msg = "not a branch instruction"; ++ return 0; ++ } ++ from->val.branch = to - from; + + return 1; + } +@@ -444,10 +452,14 @@ int AddBreakAddr(Inst *addr, char **msg) + *msg = "break outside loop"; + return 0; + } ++ if (addr->type != BRANCH_INST) { ++ *msg = "not a branch instruction for break"; ++ return 0; ++ } + if (!addLoopAddr(addr, msg)) { + return 0; + } +- addr->value = NEEDS_BREAK; ++ addr->val.branch = NEEDS_BREAK; + return 1; + } + +@@ -457,10 +469,14 @@ int AddContinueAddr(Inst *addr, char **m + *msg = "continue outside loop"; + return 0; + } ++ if (addr->type != BRANCH_INST) { ++ *msg = "not a branch instruction for break"; ++ return 0; ++ } + if (!addLoopAddr(addr, msg)) { + return 0; + } +- addr->value = NEEDS_CONTINUE; ++ addr->val.branch = NEEDS_CONTINUE; + return 1; + } + +@@ -484,10 +500,10 @@ void FillLoopAddrs(Inst *breakAddr, Inst + } + if (*LoopStackPtr == NULL) + break; +- if ((*LoopStackPtr)->value == NEEDS_BREAK) +- (*LoopStackPtr)->value = breakAddr - *LoopStackPtr; +- else if ((*LoopStackPtr)->value == NEEDS_CONTINUE) +- (*LoopStackPtr)->value = continueAddr - *LoopStackPtr; ++ if ((*LoopStackPtr)->val.immed == NEEDS_BREAK) ++ (*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"); + } +@@ -659,14 +675,20 @@ int ContinueMacro(RestartData *continuat + + /* Execute an instruction */ + inst = PC++; +- switch (inst->op) { ++ if (inst->type != OP_INST) { ++ status = execError("Unexpected instruction of type %s", ++ instTypeToStr(inst->type)); ++ } ++ else { ++ switch (inst->val.op) { + #define OP(name, fn) case OP_##name: + #include "ops.h" + #undef OP +- status = (OpFns[inst->op])(); +- break; +- default: +- status = execError("Illegal instruction at %8p", (char *)inst); ++ status = (OpFns[inst->val.op])(); ++ break; ++ default: ++ status = execError("Illegal instruction at %8p", (char *)inst); ++ } + } + + /* If error return was not STAT_OK, return to caller */ +@@ -742,7 +764,7 @@ void PreemptMacro(void) + */ + void ModifyReturnedValue(RestartData *context, DataValue dv) + { +- if ((context->pc-1)->op == OP_FETCH_RET_VAL) ++ if ((context->pc-1)->val.op == OP_FETCH_RET_VAL) + *(context->stackP-1) = dv; + } + +@@ -1322,19 +1344,31 @@ static void addToGlobalSymTab(Symbol *sy + + #define GET_SYM(s) \ + do { \ +- s = PC->sym; \ ++ if (PC->type != SYM_INST) { \ ++ return execError("Unexpected instruction, expected : %s", \ ++ instTypeToStr(PC->type)); \ ++ } \ ++ s = PC->val.sym; \ + PC++; \ + } while (0) + + #define GET_IMMED(i) \ + do { \ +- i = PC->value; \ ++ if (PC->type != IMMED_INST) { \ ++ return execError("Unexpected instruction, expected : %s", \ ++ instTypeToStr(PC->type)); \ ++ } \ ++ i = PC->val.immed; \ + PC++; \ + } while (0) + + #define GET_BRANCH(a) \ + do { \ +- a = PC + PC->value; \ ++ if (PC->type != BRANCH_INST) { \ ++ return execError("Unexpected instruction, expected : %s", \ ++ instTypeToStr(PC->type)); \ ++ } \ ++ a = PC + PC->val.branch; \ + PC++; \ + } while (0) + +@@ -1348,7 +1382,7 @@ static void addToGlobalSymTab(Symbol *sy + if (PC == NULL) { \ + PUSH(dv); \ + } \ +- else if (PC->op == OP_FETCH_RET_VAL) { \ ++ else if (PC->type == OP_INST && PC->val.op == OP_FETCH_RET_VAL) { \ + PUSH(dv); \ + PC++; \ + } \ +@@ -4322,6 +4356,23 @@ static const char *typeToStr(enum symTyp + } + + ++static const char *instTypeToStr(enum instTypes type) ++{ ++ switch (type) { ++ case OP_INST: ++ return ""; ++ case IMMED_INST: ++ return ""; ++ case BRANCH_INST: ++ return ""; ++ case SYM_INST: ++ return ""; ++ default: ++ return ""; ++ } ++} ++ ++ + #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */ + static char *printdBuffer = NULL; + static int printdPos = 0; +@@ -4480,26 +4531,50 @@ static void disasmInternal(Inst *inst, i + for (i = 0; i < nInstr; ++i) { + printd("Prog %8p", &inst[i]); + +- switch (inst[i].op) { ++ if (inst[i].type != OP_INST) { ++ switch (inst[i].type) { ++ case IMMED_INST: ++ printd(" %s: %d\n", ++ instTypeToStr(inst[i].type), ++ inst[i].val.immed); ++ break; ++ case BRANCH_INST: ++ printd(" %s: (%+td) %8p\n", ++ instTypeToStr(inst[i].type), ++ inst[i].val.branch, ++ &inst[i] + inst[i].val.branch); ++ case SYM_INST: ++ printd(" %s: %s\n", ++ instTypeToStr(inst[i].type), ++ inst[i].val.sym->name); ++ break; ++ default: ++ printd(" : %tx\n", inst[i].val.branch); ++ } ++ ++ continue; ++ } ++ ++ switch (inst[i].val.op) { + #define OP(name, fn) case OP_##name: + #include "ops.h" + #undef OP +- printd(" %*s", (int)opLen, opNames[inst[i].op]); ++ printd(" %*s", (int)opLen, opNames[inst[i].val.op]); + +- switch (inst[i].op) { ++ switch (inst[i].val.op) { + case OP_PUSH_SYM: + case OP_ASSIGN: +- printd(" %s", inst[i+1].sym->name); +- if (inst[i+1].sym->type == CONST_SYM +- && inst[i+1].sym->value.tag == STRING_TAG) { ++ printd(" %s", inst[i+1].val.sym->name); ++ if (inst[i+1].val.sym->type == CONST_SYM ++ && inst[i+1].val.sym->value.tag == STRING_TAG) { + printd(" "); +- dumpVal(inst[i+1].sym->value); ++ dumpVal(inst[i+1].val.sym->value); + } + ++i; + break; + + case OP_PUSH_IMMED: +- printd(" %d", inst[i+1].value); ++ printd(" %d", inst[i+1].val.immed); + ++i; + break; + +@@ -4507,19 +4582,20 @@ static void disasmInternal(Inst *inst, i + case OP_BRANCH_TRUE: + case OP_BRANCH_FALSE: + case OP_BRANCH_NEVER: +- printd(" to=(%+d) %8p", +- inst[i+1].value, &inst[i+1] + inst[i+1].value); ++ printd(" to=(%+td) %8p", ++ inst[i+1].val.branch, ++ &inst[i+1] + inst[i+1].val.branch); + ++i; + break; + + case OP_CONCAT: +- printd(" nExpr=%d", inst[i+1].value); ++ printd(" nExpr=%d", inst[i+1].val.immed); + ++i; + break; + + case OP_SUBR_CALL: { +- int args = inst[i+2].value; +- printd(" %s", inst[i+1].sym->name); ++ int args = inst[i+2].val.immed; ++ printd(" %s", inst[i+1].val.sym->name); + if (args < 0) { + printd(" %d+args[] (%d)", -args - 1, args); + } +@@ -4531,7 +4607,7 @@ static void disasmInternal(Inst *inst, i + break; + + case OP_UNPACKTOARGS: { +- int args = inst[i+2].value; ++ int args = inst[i+2].val.immed; + if (args < 0) { + printd(" %d+args[] (%d)", -args - 1, args); + } +@@ -4543,56 +4619,56 @@ static void disasmInternal(Inst *inst, i + break; + + case OP_SUBR_CALL_STACKED_N: +- printd(" %s =args[] (?)", inst[i+1].sym->name); ++ printd(" %s =args[] (?)", inst[i+1].val.sym->name); + ++i; + break; + + case OP_BEGIN_ARRAY_ITER: + case OP_BEGIN_ARRAY_MULTI_ITER_ARRAY: +- printd(" %s in", inst[i+1].sym->name); ++ printd(" %s in", inst[i+1].val.sym->name); + ++i; + break; + + case OP_ARRAY_ITER: +- if (!inst[i+1].value) { ++ if (!inst[i+1].val.immed) { + /* without val */ +- printd(" %s = %s++ end-loop=(%+d) %8p", +- inst[i+2].sym->name, +- inst[i+3].sym->name, +- inst[i+4].value, +- &inst[i+4] + inst[i+4].value); ++ printd(" %s = %s++ end-loop=(%+td) %8p", ++ inst[i+2].val.sym->name, ++ inst[i+3].val.sym->name, ++ inst[i+4].val.branch, ++ &inst[i+4] + inst[i+4].val.branch); + i += 4; + } + else { + /* with val */ +- printd(" %s=%s = %s++ end-loop=(%+d) %8p", +- inst[i+2].sym->name, +- inst[i+3].sym->name, +- inst[i+4].sym->name, +- inst[i+5].value, +- &inst[i+5] + inst[i+5].value); ++ printd(" %s=%s = %s++ end-loop=(%+td) %8p", ++ inst[i+2].val.sym->name, ++ inst[i+3].val.sym->name, ++ inst[i+4].val.sym->name, ++ inst[i+5].val.branch, ++ &inst[i+5] + inst[i+5].val.branch); + i += 5; + } + break; + + case OP_ARRAY_MULTI_ITER_ARRAY: +- if (!inst[i+1].value) { ++ if (!inst[i+1].val.immed) { + /* without val */ +- printd(" %s[] = %s++ end-loop=(%+d) %8p", +- inst[i+2].sym->name, +- inst[i+3].sym->name, +- inst[i+4].value, +- &inst[i+4] + inst[i+4].value); ++ printd(" %s[] = %s++ end-loop=(%+td) %8p", ++ inst[i+2].val.sym->name, ++ inst[i+3].val.sym->name, ++ inst[i+4].val.branch, ++ &inst[i+4] + inst[i+4].val.branch); + i += 4; + } + else { + /* with val */ +- printd(" %s[]=%s = %s++ end-loop=(%+d) %8p", +- inst[i+2].sym->name, +- inst[i+3].sym->name, +- inst[i+4].sym->name, +- inst[i+5].value, +- &inst[i+5] + inst[i+5].value); ++ printd(" %s[]=%s = %s++ end-loop=(%+td) %8p", ++ inst[i+2].val.sym->name, ++ inst[i+3].val.sym->name, ++ inst[i+4].val.sym->name, ++ inst[i+5].val.branch, ++ &inst[i+5] + inst[i+5].val.branch); + i += 5; + } + break; +@@ -4603,21 +4679,21 @@ static void disasmInternal(Inst *inst, i + case OP_ANONARRAY_INDEX_VAL: + case OP_NAMED_ARG1: + case OP_NAMED_ARGN: +- printd(" nDim=%d", inst[i+1].value); ++ printd(" nDim=%d", inst[i+1].val.immed); + ++i; + break; + + case OP_ARRAY_REF_ASSIGN_SETUP: + printd(" binOp=%s nDim=%d", +- inst[i+1].value ? "true" : "false", +- inst[i+2].value); ++ inst[i+1].val.immed ? "true" : "false", ++ inst[i+2].val.immed); + i += 2; + break; + + case OP_PUSH_ARRAY_SYM: + printd(" %s %s", +- inst[i+1].sym->name, +- inst[i+2].value ? "createAndRef" : "refOnly"); ++ inst[i+1].val.sym->name, ++ inst[i+2].val.immed ? "createAndRef" : "refOnly"); + i += 2; + break; + +@@ -4627,7 +4703,7 @@ static void disasmInternal(Inst *inst, i + break; + + default: +- printd(" %x\n", inst[i].value); ++ printd(" %lx\n", inst[i].val.immed); + break; + } + } +diff --quilt old/source/interpret.h new/source/interpret.h +--- old/source/interpret.h ++++ new/source/interpret.h +@@ -54,6 +54,8 @@ enum typeTags {NO_TAG, INT_TAG, STRING_T + + enum execReturnCodes {MACRO_TIME_LIMIT, MACRO_PREEMPT, MACRO_DONE, MACRO_ERROR}; + ++enum instTypes {OP_INST, IMMED_INST, BRANCH_INST, SYM_INST}; ++ + #define ARRAY_DIM_SEP "\034" + + struct DataValueTag; +@@ -61,10 +63,14 @@ struct SparseArrayEntryTag; + struct ProgramTag; + struct SymbolRec; + +-typedef union InstTag { +- enum operations op; +- int value; +- struct SymbolRec *sym; ++typedef struct InstTag { ++ enum instTypes type; ++ union { ++ enum operations op; ++ int immed; ++ ptrdiff_t branch; ++ struct SymbolRec *sym; ++ } val; + } Inst; + + typedef int (*BuiltInSubr)(WindowInfo *window, struct DataValueTag *argList, +@@ -150,7 +156,7 @@ int ArrayCopy(DataValue *dstArray, DataV + void BeginCreatingProgram(const char *name, AccumulatorData *acc); + int AddOp(int op, char **msg); + int AddSym(Symbol *sym, char **msg); +-int AddImmediate(int value, char **msg); ++int AddImmediate(int immed, char **msg); + int AddBranchOffset(Inst *to, char **msg); + int SetBranchOffset(Inst *from, Inst *to, char **msg); + Inst *GetPC(void); diff --git a/unify-branch-setup.patch b/unify-branch-setup.patch new file mode 100644 index 0000000..9179174 --- /dev/null +++ b/unify-branch-setup.patch @@ -0,0 +1,190 @@ +--- + + source/interpret.c | 53 +++++++++++++++++++++++++++++++++++++---------------- + source/interpret.h | 7 ++++--- + source/parse.y | 36 ++++++++++++++++++++++++++---------- + 3 files changed, 67 insertions(+), 29 deletions(-) + +diff --quilt old/source/interpret.c new/source/interpret.c +--- old/source/interpret.c ++++ new/source/interpret.c +@@ -80,7 +80,7 @@ static const char CVSID[] = "$Id: interp + + enum opStatusCodes {STAT_OK=2, STAT_DONE, STAT_ERROR, STAT_PREEMPT}; + +-static void addLoopAddr(Inst *addr); ++static int addLoopAddr(Inst *addr, char **msg); + static void saveContext(RestartData *context); + static void restoreContext(RestartData *context); + +@@ -387,6 +387,16 @@ int AddBranchOffset(Inst *to, char **msg + } + + /* ++** Set a branch offset to an operand previously added with AddBranchOffset() ++*/ ++int SetBranchOffset(Inst *from, Inst *to, char **msg) ++{ ++ from->value = to - from; ++ ++ return 1; ++} ++ ++/* + ** Return the address at which the next instruction will be stored + */ + Inst *GetPC(void) +@@ -423,34 +433,45 @@ 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. + */ +-void StartLoopAddrList(void) ++int StartLoopAddrList(char **msg) + { +- addLoopAddr(NULL); ++ return addLoopAddr(NULL, msg); + } + +-int AddBreakAddr(Inst *addr) ++int AddBreakAddr(Inst *addr, char **msg) + { +- if (LoopStackPtr == LoopStack) return 1; +- addLoopAddr(addr); ++ if (LoopStackPtr == LoopStack) { ++ *msg = "break outside loop"; ++ return 0; ++ } ++ if (!addLoopAddr(addr, msg)) { ++ return 0; ++ } + addr->value = NEEDS_BREAK; +- return 0; ++ return 1; + } + +-int AddContinueAddr(Inst *addr) +-{ +- if (LoopStackPtr == LoopStack) return 1; +- addLoopAddr(addr); ++int AddContinueAddr(Inst *addr, char **msg) ++{ ++ if (LoopStackPtr == LoopStack) { ++ *msg = "continue outside loop"; ++ return 0; ++ } ++ if (!addLoopAddr(addr, msg)) { ++ return 0; ++ } + addr->value = NEEDS_CONTINUE; +- return 0; ++ return 1; + } + +-static void addLoopAddr(Inst *addr) ++static int addLoopAddr(Inst *addr, char **msg) + { +- if (LoopStackPtr > &LoopStack[LOOP_STACK_SIZE-1]) { +- fprintf(stderr, "NEdit: loop stack overflow in macro parser"); +- return; ++ if (LoopStackPtr >= &LoopStack[LOOP_STACK_SIZE]) { ++ *msg = "loop stack overflow"; ++ return 0; + } + *LoopStackPtr++ = addr; ++ return 1; + } + + void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr) +diff --quilt old/source/interpret.h new/source/interpret.h +--- old/source/interpret.h ++++ new/source/interpret.h +@@ -152,6 +152,7 @@ int AddOp(int op, char **msg); + int AddSym(Symbol *sym, char **msg); + int AddImmediate(int value, char **msg); + int AddBranchOffset(Inst *to, char **msg); ++int SetBranchOffset(Inst *from, Inst *to, char **msg); + Inst *GetPC(void); + Symbol *InstallIteratorSymbol(void); + Symbol *LookupStringConstSymbol(const char *value); +@@ -161,9 +162,9 @@ 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); ++int StartLoopAddrList(char **msg); ++int AddBreakAddr(Inst *addr, char **msg); ++int AddContinueAddr(Inst *addr, char **msg); + void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr); + + /* create a permanently allocated static string (only for use with static strings) */ +diff --quilt old/source/parse.y new/source/parse.y +--- old/source/parse.y ++++ new/source/parse.y +@@ -55,7 +55,27 @@ + } while (0) + #define SET_BR_OFF(from, to) \ + do { \ +- ((from)->value) = ((Inst *)(to)) - ((Inst *)(from)); \ ++ if (!SetBranchOffset(from, to, &ErrMsg)) { \ ++ return 1; \ ++ } \ ++ } while (0) ++#define START_LOOP() \ ++ do { \ ++ if (!StartLoopAddrList(&ErrMsg)) { \ ++ return 1; \ ++ } \ ++ } while (0) ++#define ADD_BREAK(addr) \ ++ do { \ ++ if (!AddBreakAddr(addr, &ErrMsg)) { \ ++ return 1; \ ++ } \ ++ } while (0) ++#define ADD_CONTINUE(addr) \ ++ do { \ ++ if (!AddContinueAddr(addr, &ErrMsg)) { \ ++ return 1; \ ++ } \ + } while (0) + + /* Max. length for a string constant (... there shouldn't be a maximum) */ +@@ -309,15 +329,11 @@ stmt: ';' blank + } + | BREAK stmtend blank { + ADD_OP(OP_BRANCH); ADD_BR_OFF(0); +- if (AddBreakAddr(GetPC()-1)) { +- yyerror("break outside loop"); YYERROR; +- } ++ ADD_BREAK(GetPC() - 1); + } + | CONTINUE stmtend blank { + ADD_OP(OP_BRANCH); ADD_BR_OFF(0); +- if (AddContinueAddr(GetPC()-1)) { +- yyerror("continue outside loop"); YYERROR; +- } ++ ADD_CONTINUE(GetPC() - 1); + } + | RETURN expr stmtend blank { + ADD_OP(OP_RETURN); +@@ -775,15 +791,15 @@ numexpropt: blank { + ; + + while: WHILE blank { +- $$ = GetPC(); StartLoopAddrList(); ++ $$ = GetPC(); START_LOOP(); + } + ; + do: DO blank { +- $$ = GetPC(); StartLoopAddrList(); ++ $$ = GetPC(); START_LOOP(); + } + ; + for: FOR blank { +- StartLoopAddrList(); $$ = GetPC(); ++ START_LOOP(); $$ = GetPC(); + } + ; + else: ELSE blank { -- 2.11.4.GIT