From 4151863cdf18151bb137745ab0f3132ce4e5bebf Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Tue, 14 Oct 2008 13:06:21 +0200 Subject: [PATCH] changes all over the place FastConcat3.diff: * import concatenateNwithSep() return fix InterpretDebug-mods.patch: * printf attribute for printd() * compile time extra stack size SUBR_TAG.patch: * drop typeToStr() global-RestartData.patch: * rename Current to Interpreter B.W. --- Patch: !FastConcat3.diff Patch: !InterpretDebug-mods.patch Patch: !SUBR_TAG.patch Patch: !global-RestartData.patch --- EXEC_ERROR.patch | 111 ++++++++-------- FastConcat3.diff | 48 +++---- GlobalSymTable.patch | 15 +-- InterpretDebug-mods.patch | 161 ++++++++++++++++++----- InterpretDebug5-fix-stackDumpStr.diff | 8 +- InterpretDebug5.diff | 37 +++--- SUBR_TAG.patch | 88 +++---------- Symbol-embed-name.patch | 2 +- abstract-access-to-FrameP.patch | 20 +-- abstract-access-to-PC.patch | 42 +++--- anonArrayNamedArgs7.diff | 20 +-- array-key-array-iterator.patch | 8 +- array-next-num-index.patch | 4 +- arrayReplacesArglist-as-last-argument.patch | 4 +- arrayReplacesArglist5.diff | 12 +- aryiter-on-stack.patch | 24 ++-- callMacroFnByName2.diff | 6 +- core-typeof-syntax.patch | 12 +- drop-SUBR_TAG.patch | 26 ++-- extend-for-key-in-array-syntax.patch | 10 +- global-AccumulatorData.patch | 2 +- global-RestartData.patch | 60 ++++----- handle-error-in-RunMacroAsSubrCall.patch | 2 +- interpret_c-macro-cleanup.patch | 34 +++-- op-not-func-in-Inst.patch | 19 ++- remove-args-from-DISASM_RT.patch | 42 +++--- stringToNum.diff | 2 +- symbol-lookup.patch | 197 ++++++++++++---------------- typed-Inst.patch | 36 ++--- 29 files changed, 536 insertions(+), 516 deletions(-) diff --git a/EXEC_ERROR.patch b/EXEC_ERROR.patch index 34240e1..769db00 100644 --- a/EXEC_ERROR.patch +++ b/EXEC_ERROR.patch @@ -1,7 +1,7 @@ --- - source/interpret.c | 200 +++++++++++++++++++++++++++-------------------------- - 1 file changed, 102 insertions(+), 98 deletions(-) + source/interpret.c | 194 +++++++++++++++++++++++++++-------------------------- + 1 file changed, 99 insertions(+), 95 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c @@ -68,7 +68,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } \ } while (0) -@@ -1489,11 +1491,11 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1489,10 +1491,10 @@ static void addToGlobalSymTab(Symbol *sy __int = dataVal.val.n; \ } else if (dataVal.tag == STRING_TAG) { \ if (!StringToNum(dataVal.val.str.rep, &__int)) {\ @@ -76,24 +76,20 @@ diff --quilt old/source/interpret.c new/source/interpret.c + EXEC_ERROR(StringToNumberMsg, dataVal.val.str.rep); \ } \ } else { \ -- return(execError("incompatible type in integer context: %s", \ -- tagToStr(dataVal.tag))); \ -+ EXEC_ERROR("incompatible type in integer context: %s", \ -+ tagToStr(dataVal.tag)); \ +- return execError("incompatible type in integer context: <%s>", \ ++ EXEC_ERROR("incompatible type in integer context: <%s>", \ + tagToStr(dataVal.tag)); \ } \ number = __int; \ - } while (0) -@@ -1506,8 +1508,8 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1506,7 +1508,7 @@ static void addToGlobalSymTab(Symbol *sy } else if (dataVal.tag == INT_TAG) { \ __str = AllocStringOfNumber(dataVal.val.n); \ } else { \ -- return(execError("incompatible type in string context: %s", \ -- tagToStr(dataVal.tag))); \ -+ EXEC_ERROR("incompatible type in string context: %s", \ -+ tagToStr(dataVal.tag)); \ +- return execError("incompatible type in string context: <%s>", \ ++ EXEC_ERROR("incompatible type in string context: <%s>", \ + tagToStr(dataVal.tag)); \ } \ string = __str; \ - } while (0) @@ -1604,7 +1606,7 @@ static int pushSymVal(void) nArgs = FRAME_GET_ARG_COUNT(); argNum = s->value.val.n; @@ -347,16 +343,16 @@ diff --quilt old/source/interpret.c new/source/interpret.c } static int and(void) -@@ -2675,7 +2677,7 @@ static int concat(void) - - len = concatenateNwithSep(nExpr, "", &out, False); - if (len < 0) { -- return(execError("can only concatenate with string or integer", NULL)); -+ EXEC_ERROR("can only concatenate with string or integer", NULL); +@@ -2618,7 +2620,7 @@ static int concatenateNwithSep(int nVals + len += value.val.str.len; + } + else { +- return execError("incompatible type in string context: <%s>", ++ EXEC_ERROR("incompatible type in string context: <%s>", + tagToStr(value.tag)); + } } - PUSH_STRING(out, len); - return STAT_OK; -@@ -2732,7 +2734,8 @@ static int callSubroutineFromSymbol(Symb +@@ -2735,7 +2737,8 @@ static int callSubroutineFromSymbol(Symb if (symValPtr->tag == SUBR_TAG) { sym = symValPtr->val.sym; } else { @@ -366,7 +362,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } -@@ -2751,7 +2754,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2754,7 +2757,7 @@ static int callSubroutineFromSymbol(Symb PreemptRequest = False; if (!sym->value.val.subr(FocusWindow, StackP, nArgs, &result, &errMsg)) @@ -375,7 +371,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH_RET_VAL(result); return PreemptRequest ? STAT_PREEMPT : STAT_OK; } -@@ -2786,8 +2789,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2789,8 +2792,7 @@ static int callSubroutineFromSymbol(Symb Window win; if (haveNamedArgs) { @@ -385,7 +381,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c sym->name); } -@@ -2823,7 +2825,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2826,7 +2828,7 @@ static int callSubroutineFromSymbol(Symb } /* Calling a non subroutine symbol */ @@ -394,7 +390,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2879,7 +2881,7 @@ static int callSubroutineStackedN(void) +@@ -2882,7 +2884,7 @@ static int callSubroutineStackedN(void) if (nArgs >= 0) { /* should never happen */ @@ -403,7 +399,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } return callSubroutineFromSymbol(sym, nArgs); -@@ -2988,7 +2990,7 @@ static int unpackArrayToArgs(void) +@@ -2991,7 +2993,7 @@ static int unpackArrayToArgs(void) POP(argArray); if (argArray.tag != ARRAY_TAG) { @@ -412,7 +408,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (haveNamedArgs) { -@@ -3023,7 +3025,7 @@ static int unpackArrayToArgs(void) +@@ -3026,7 +3028,7 @@ static int unpackArrayToArgs(void) } else { if (!ArrayInsert(&dvArray, iter->key, &dvEntry)) { @@ -421,7 +417,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } -@@ -3042,7 +3044,7 @@ static int unpackArrayToArgs(void) +@@ -3045,7 +3047,7 @@ static int unpackArrayToArgs(void) */ static int fetchRetVal(void) { @@ -430,7 +426,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* see comments for returnValOrNone() */ -@@ -3182,17 +3184,17 @@ int ArrayCopy(DataValue *dstArray, DataV +@@ -3185,17 +3187,17 @@ int ArrayCopy(DataValue *dstArray, DataV return(errNum); } if (!ArrayInsert(dstArray, srcIter->key, &tmpArray)) { @@ -451,19 +447,16 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3209,9 +3211,9 @@ static int makeArrayKeyFromArgs(int nArg - - len = concatenateNwithSep(nArgs, ARRAY_DIM_SEP, keyString, leaveParams); - if (len < 0) { -- return(execError("can only index array with string or int.", NULL)); -+ EXEC_ERROR("can only index array with string or int.", NULL); +@@ -3215,7 +3217,7 @@ static int makeArrayKeyFromArgs(int nArg + if (len > 0) { + return len; } - return(STAT_OK); + return STAT_OK; } /* -@@ -3531,23 +3533,24 @@ static int arrayRef(void) +@@ -3535,23 +3537,24 @@ static int arrayRef(void) POP(srcArray); if (srcArray.tag == ARRAY_TAG) { if (!ArrayGet(&srcArray, keyString, &valueItem)) { @@ -493,7 +486,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } } -@@ -3584,7 +3587,7 @@ static int arrayAssign(void) +@@ -3588,7 +3591,7 @@ static int arrayAssign(void) POP(dstArray); if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) { @@ -502,7 +495,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (srcValue.tag == ARRAY_TAG) { DataValue arrayCopyValue; -@@ -3596,13 +3599,13 @@ static int arrayAssign(void) +@@ -3600,13 +3603,13 @@ static int arrayAssign(void) } } if (ArrayInsert(&dstArray, keyString, &srcValue)) { @@ -519,7 +512,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3640,20 +3643,21 @@ static int arrayRefAndAssignSetup(void) +@@ -3644,20 +3647,21 @@ static int arrayRefAndAssignSetup(void) PEEK(srcArray, nDim); if (srcArray.tag == ARRAY_TAG) { if (!ArrayGet(&srcArray, keyString, &valueItem)) { @@ -545,7 +538,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } } -@@ -3686,16 +3690,16 @@ static int beginArrayIter(void) +@@ -3690,16 +3694,16 @@ static int beginArrayIter(void) iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); } else { @@ -565,7 +558,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3752,7 +3756,7 @@ static int arrayIter(void) +@@ -3756,7 +3760,7 @@ static int arrayIter(void) keyValPtr = &(keySym->value); } else { @@ -574,7 +567,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } keyValPtr->tag = NO_TAG; -@@ -3764,7 +3768,7 @@ static int arrayIter(void) +@@ -3768,7 +3772,7 @@ static int arrayIter(void) valPtr = &(valSym->value); } else { @@ -583,7 +576,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } valPtr->tag = NO_TAG; } -@@ -3773,7 +3777,7 @@ static int arrayIter(void) +@@ -3777,7 +3781,7 @@ static int arrayIter(void) iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); } else { @@ -592,7 +585,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } thisEntry = iteratorValPtr->val.arrayPtr; -@@ -3794,7 +3798,7 @@ static int arrayIter(void) +@@ -3798,7 +3802,7 @@ static int arrayIter(void) else { JUMP(branchAddr); } @@ -601,7 +594,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3822,21 +3826,21 @@ static int beginArrayIterArray(void) +@@ -3826,21 +3830,21 @@ static int beginArrayIterArray(void) iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); } else { @@ -627,7 +620,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } static int countDim(const char *key) -@@ -3932,7 +3936,7 @@ static int arrayIterArray(void) +@@ -3936,7 +3940,7 @@ static int arrayIterArray(void) keyArrayPtr = &(keyArraySym->value); } else { @@ -636,7 +629,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } keyArrayPtr->tag = ARRAY_TAG; keyArrayPtr->val.arrayPtr = NULL; -@@ -3945,7 +3949,7 @@ static int arrayIterArray(void) +@@ -3949,7 +3953,7 @@ static int arrayIterArray(void) valPtr = &valSym->value; } else { @@ -645,7 +638,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } valPtr->tag = NO_TAG; } -@@ -3954,7 +3958,7 @@ static int arrayIterArray(void) +@@ -3958,7 +3962,7 @@ static int arrayIterArray(void) iteratorValPtr = &FRAME_GET_SYM_VAL(iterator); } else { @@ -654,7 +647,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } thisEntry = iteratorValPtr->val.arrayPtr; -@@ -3975,7 +3979,7 @@ static int arrayIterArray(void) +@@ -3979,7 +3983,7 @@ static int arrayIterArray(void) /* set keys */ if (!splitKeyIntoArray(thisEntry->key, keyArrayPtr)) { @@ -663,7 +656,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (withVal) { -@@ -4019,7 +4023,7 @@ static int inArray(void) +@@ -4023,7 +4027,7 @@ static int inArray(void) POP(theArray); if (theArray.tag != ARRAY_TAG) { @@ -672,7 +665,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PEEK(leftArray, 0); if (leftArray.tag == ARRAY_TAG) { -@@ -4040,7 +4044,7 @@ static int inArray(void) +@@ -4044,7 +4048,7 @@ static int inArray(void) } } PUSH_INT(inResult); @@ -681,7 +674,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -4083,15 +4087,15 @@ static int deleteArrayElement(void) +@@ -4087,15 +4091,15 @@ static int deleteArrayElement(void) } } else { @@ -700,7 +693,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } inTypeOfMode = 1; -@@ -4105,7 +4109,7 @@ static int typeOfOut(void) +@@ -4109,7 +4113,7 @@ static int typeOfOut(void) DataValue retVal; if (!inTypeOfMode) { @@ -709,7 +702,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } inTypeOfMode = 0; -@@ -4159,7 +4163,7 @@ static int arrayAssignNext(void) +@@ -4163,7 +4167,7 @@ static int arrayAssignNext(void) POP(dstArray); if (dstArray.tag != ARRAY_TAG && dstArray.tag != NO_TAG) { @@ -718,7 +711,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } if (srcValue.tag == ARRAY_TAG) { -@@ -4175,7 +4179,7 @@ static int arrayAssignNext(void) +@@ -4179,7 +4183,7 @@ static int arrayAssignNext(void) keyString = AllocStringOfNumber(arrayMaxNumIdx(&dstArray) + 1); if (!ArrayInsert(&dstArray, keyString, &srcValue)) { @@ -727,7 +720,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } return STAT_OK; -@@ -4199,7 +4203,7 @@ static int arrayNextNumIdx(void) +@@ -4203,7 +4207,7 @@ static int arrayNextNumIdx(void) POP(srcArray); if (srcArray.tag != ARRAY_TAG) { @@ -736,7 +729,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } PUSH_INT(arrayMaxNumIdx(&srcArray) + 1); -@@ -4214,9 +4218,9 @@ static int arrayNextNumIdx(void) +@@ -4218,9 +4222,9 @@ static int arrayNextNumIdx(void) static int errCheck(const char *s) { if (errno == EDOM) diff --git a/FastConcat3.diff b/FastConcat3.diff index f286430..da83063 100644 --- a/FastConcat3.diff +++ b/FastConcat3.diff @@ -34,10 +34,10 @@ its content. --- - source/interpret.c | 228 ++++++++++++++++++++++++++++++++++++++--------------- + source/interpret.c | 232 ++++++++++++++++++++++++++++++++++++++--------------- source/interpret.h | 3 source/parse.y | 19 +++- - 3 files changed, 184 insertions(+), 66 deletions(-) + 3 files changed, 188 insertions(+), 66 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c @@ -133,8 +133,8 @@ diff --quilt old/source/interpret.c new/source/interpret.c - sprintf(__str, "%d", dataVal.val.n); \ + __str = AllocStringOfNumber(dataVal.val.n); \ } else { \ - return(execError("incompatible type in string context: %s", \ - tagToStr(dataVal.tag))); \ + return execError("incompatible type in string context: <%s>", \ + tagToStr(dataVal.tag)); \ @@ -1333,9 +1394,8 @@ static int pushArgVal(void) --argNum; nArgs = FP_GET_ARG_COUNT(FrameP); @@ -161,19 +161,20 @@ diff --quilt old/source/interpret.c new/source/interpret.c return(execError("array insertion failure", NULL)); } } -@@ -1959,26 +2017,102 @@ static int power(void) +@@ -1959,26 +2017,105 @@ static int power(void) } /* -** concatenate two top items on the stack -** Before: TheStack-> str2, str1, next, ... -** After: TheStack-> result, next, ... -+** A helper routine used in concat(), and makeArrayKeyFromArgs(). -+** Concatenate a number of values from the stack and return the result as a -+** character pointer in *result and its length as the return value, or less -+** than zero on failure. If a divider is specified, add it between each of the -+** stack elements. The stack elements are popped from the stack if leaveParams -+** is false. ++** A helper routine used in concat(), and makeArrayKeyFromArgs(). Concatenate a ++** number of values from the stack and return the result as a character pointer ++** in *result and its negated length as the return value, or greater than zero ++** on failure. (We do this, because PEEK and POP can cause positive error status ++** STAT_ERROR to be returned.) If a divider is specified, add it between each of ++** the 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) @@ -194,7 +195,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c + + /* evaluate total length (upper limit) */ + len = sepLen * (nVals - 1); -+ for (i = nVals - 1; i >= 0; --i) { ++ for (i = nVals; i--;) { + PEEK(value, i); + if (value.tag == INT_TAG) { + len += lenLongAsStr(value.val.n); @@ -203,7 +204,8 @@ diff --quilt old/source/interpret.c new/source/interpret.c + len += value.val.str.len; + } + else { -+ return -1; /* invalid type */ ++ return execError("incompatible type in string context: <%s>", ++ tagToStr(value.tag)); + } + } + @@ -211,7 +213,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c + res = AllocString(len + 1); + pos = res; + /* write everything into the result */ -+ for (i = nVals - 1; i >= 0; --i) { ++ for (i = nVals; i--;) { + PEEK(value, i); + if (value.tag == INT_TAG) { + pos += strlen(strcpy(pos, longAsStr(value.val.n))); @@ -235,7 +237,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c + + /* now return the results */ + *result = res; -+ return pos - res; ++ return res - pos; /* first position - last position: negated length value */ +} + +/* @@ -271,15 +273,16 @@ diff --quilt old/source/interpret.c new/source/interpret.c + DISASM_RT(PC-2, 2); + STACKDUMP(nExpr, 3); + ++ /* remember: concatenateNwithSep() succeeds with a non-positive number */ + len = concatenateNwithSep(nExpr, "", &out, False); -+ if (len < 0) { -+ return(execError("can only concatenate with string or integer", NULL)); ++ if (len > 0) { ++ return len; + } -+ PUSH_STRING(out, len); ++ PUSH_STRING(out, -len); return STAT_OK; } -@@ -2284,45 +2418,11 @@ int ArrayCopy(DataValue *dstArray, DataV +@@ -2284,45 +2421,12 @@ int ArrayCopy(DataValue *dstArray, DataV */ static int makeArrayKeyFromArgs(int nArgs, char **keyString, int leaveParams) { @@ -323,13 +326,14 @@ diff --quilt old/source/interpret.c new/source/interpret.c - for (i = nArgs - 1; i >= 0; --i) { - POP(tmpVal); - } ++ /* remember: concatenateNwithSep() succeeds with a non-positive number */ + len = concatenateNwithSep(nArgs, ARRAY_DIM_SEP, keyString, leaveParams); -+ if (len < 0) { -+ return(execError("can only index array with string or int.", NULL)); ++ if (len > 0) { ++ return len; } return(STAT_OK); } -@@ -3108,6 +3208,10 @@ static void disasm(Inst *inst, int nInst +@@ -3108,6 +3212,10 @@ static void disasm(Inst *inst, int nInst &inst[i+1] + inst[i+1].value); ++i; } diff --git a/GlobalSymTable.patch b/GlobalSymTable.patch index 1eb26ea..fdb111a 100644 --- a/GlobalSymTable.patch +++ b/GlobalSymTable.patch @@ -4,9 +4,9 @@ Subject: Use a hashtable for the global symbols source/interpret.c | 137 +++++++++++++++++++++++++++++++++++++---------------- source/interpret.h | 1 - source/interpret.c | 137 +++++++++++++++++++++++++++++++++++++---------------- + source/interpret.c | 133 ++++++++++++++++++++++++++++++++++++++--------------- source/interpret.h | 1 - 2 files changed, 99 insertions(+), 39 deletions(-) + 2 files changed, 97 insertions(+), 37 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c @@ -261,17 +261,6 @@ 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) -@@ -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); -- if (sym->value.tag == STRING_TAG && -- strncmp(sym->name, "string #", 8) == 0) { -+ if (sym->type == CONST_SYM -+ && sym->value.tag == STRING_TAG) { - printd(" "); - dumpVal(sym->value); - } diff --quilt old/source/interpret.h new/source/interpret.h --- old/source/interpret.h +++ new/source/interpret.h diff --git a/InterpretDebug-mods.patch b/InterpretDebug-mods.patch index a8f01fb..cfda11c 100644 --- a/InterpretDebug-mods.patch +++ b/InterpretDebug-mods.patch @@ -2,18 +2,23 @@ Subject: modifications to the InterpretDebug patch --- - source/interpret.c | 151 ++++++++++++++++++++++++++++++++++++----------------- - source/interpret.h | 5 + - source/parse.y | 14 +--- - source/userCmds.c | 4 - - 4 files changed, 115 insertions(+), 59 deletions(-) + makefiles/Makefile.bertw | 3 + source/interpret.c | 185 +++++++++++++++++++++++++++++++---------------- + source/interpret.h | 5 - + source/parse.y | 14 +-- + source/userCmds.c | 4 - + 5 files changed, 137 insertions(+), 74 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -114,21 +114,21 @@ static const char *tagToStr(enum typeTag +@@ -112,23 +112,24 @@ static const char *tagToStr(enum typeTag + + #if defined(DEBUG_ASSEMBLY) || defined(DEBUG_STACK) #define DEBUG_DISASSEMBLER - static const char *printd(const char *f, ...); +-static const char *printd(const char *f, ...); ++static const char *printd(const char *f, ...) ++__attribute__((__format__(printf,1,2))); static int outPrintd(); -static void disasm(Inst *inst, int nInstr); +static void disasm(const char *name, Inst *inst, int nInstr); @@ -37,7 +42,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #else /* #ifndef DEBUG_STACK */ #define STACKDUMP(n, x) #define DISASM_RT(i, n) -@@ -161,6 +161,8 @@ static Inst *ProgP; /* next free spot +@@ -161,6 +162,8 @@ static Inst *ProgP; /* next free spot static Inst *LoopStack[LOOP_STACK_SIZE]; /* addresses of break, cont stmts */ static Inst **LoopStackPtr = LoopStack; /* to fill at the end of a loop */ @@ -46,7 +51,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* Global data for the interpreter */ static DataValue *TheStack; /* the stack */ static DataValue *StackP; /* next free spot on stack */ -@@ -253,7 +255,7 @@ void InitMacroGlobals(void) +@@ -253,7 +256,7 @@ void InitMacroGlobals(void) ** Start collecting instructions for a program. Clears the program ** and the symbol table. */ @@ -55,7 +60,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c { /* save state */ acc->localSymList = LocalSymList; -@@ -261,10 +263,12 @@ void BeginCreatingProgram(AccumulatorDat +@@ -261,10 +264,12 @@ void BeginCreatingProgram(AccumulatorDat acc->progP = ProgP; memcpy(acc->loopStack, LoopStack, sizeof(*LoopStack) * LOOP_STACK_SIZE); acc->loopStackPtr = LoopStackPtr; @@ -68,7 +73,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -278,12 +282,12 @@ Program *FinishCreatingProgram(Accumulat +@@ -278,12 +283,12 @@ Program *FinishCreatingProgram(Accumulat int progLen, fpOffset = 0; Symbol *s; @@ -83,7 +88,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c newProg->refcount = 1; /* Local variables' values are stored on the stack. Here we assign -@@ -291,7 +295,7 @@ Program *FinishCreatingProgram(Accumulat +@@ -291,7 +296,7 @@ Program *FinishCreatingProgram(Accumulat for (s = newProg->localSymList; s != NULL; s = s->next) s->value.val.n = fpOffset++; @@ -92,7 +97,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* restore state */ LocalSymList = acc->localSymList; -@@ -299,6 +303,7 @@ Program *FinishCreatingProgram(Accumulat +@@ -299,6 +304,7 @@ Program *FinishCreatingProgram(Accumulat ProgP = acc->progP; memcpy(LoopStack, acc->loopStack, sizeof(*LoopStack) * LOOP_STACK_SIZE); LoopStackPtr = acc->loopStackPtr; @@ -100,7 +105,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return newProg; } -@@ -308,7 +313,6 @@ void FreeProgram(Program *prog) +@@ -308,7 +314,6 @@ void FreeProgram(Program *prog) if (--prog->refcount == 0) { freeSymbolTable(prog->localSymList); XtFree((char *)prog->code); @@ -108,7 +113,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c XtFree((char *)prog); } } -@@ -3074,7 +3078,7 @@ static void arrayDisposeNode(rbTreeNode +@@ -3078,7 +3083,7 @@ static void arrayDisposeNode(rbTreeNode SparseArrayEntry *ArrayNew(void) { @@ -117,7 +122,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3586,7 +3590,9 @@ static int errCheck(const char *s) +@@ -3590,7 +3595,9 @@ static int errCheck(const char *s) */ static char *stackDumpStr(DataValue *fp, const char *msg, char **s, int *pLen) { @@ -128,7 +133,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c const char *op; char *np; DataValue *nfp = fp; -@@ -3594,22 +3600,26 @@ static char *stackDumpStr(DataValue *fp, +@@ -3598,22 +3605,26 @@ static char *stackDumpStr(DataValue *fp, #ifdef DEBUG_STACK const char *dump; @@ -158,7 +163,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #endif if (*pLen < len) { -@@ -3621,10 +3631,25 @@ static char *stackDumpStr(DataValue *fp, +@@ -3625,10 +3636,25 @@ static char *stackDumpStr(DataValue *fp, op = msg; while (*op) *np++ = *op++; @@ -184,7 +189,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c op = FP_GET_ITEM(nfp, FP_FUNCTION_NAME).val.str.rep; while (*op) *np++ = *op++; -@@ -3632,12 +3657,15 @@ static char *stackDumpStr(DataValue *fp, +@@ -3636,12 +3662,15 @@ static char *stackDumpStr(DataValue *fp, nfp = FP_GET_OLD_FP(nfp); } while (pc); #ifdef DEBUG_STACK @@ -201,23 +206,27 @@ diff --quilt old/source/interpret.c new/source/interpret.c return *s; } -@@ -3779,28 +3807,46 @@ static void dumpVal(DataValue dv) +@@ -3781,42 +3810,61 @@ int outPrintd() + #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */ + static void dumpVal(DataValue dv) { ++ printd(" "); switch (dv.tag) { case INT_TAG: - printd("i=%d", dv.val.n); -+ printd(" %d", dv.val.n); ++ printd("<%s %d>", tagToStr(INT_TAG), dv.val.n); break; case STRING_TAG: { - int k; - char s[21]; +- char *src = dv.val.str.rep; + int k, l; + char s[64]; - char *src = dv.val.str.rep; ++ const char *src = dv.val.str.rep; if (!src) { - printd("s="); -+ printd(" "); ++ printd("<%s NULL>", tagToStr(STRING_TAG)); } else { - for (k = 0; src[k] && k < sizeof s - 1; k++) { @@ -245,19 +254,35 @@ diff --quilt old/source/interpret.c new/source/interpret.c } - s[k] = 0; - printd("s=\"%s\"%s[%d]", s, +- src[k] ? "..." : "", strlen(src)); + s[l] = 0; -+ printd(" \"%s\"%s[%d]", s, - src[k] ? "..." : "", strlen(src)); ++ printd("<%s:%u \"%s\"%s>", tagToStr(STRING_TAG), ++ (unsigned)strlen(src), s, src[k] ? "..." : ""); } } break; case ARRAY_TAG: -- printd("%08p [%d]", dv.val.arrayPtr, ArraySize(&dv)); -+ printd(" %8p[%d]", dv.val.arrayPtr, ArraySize(&dv)); +- printd("%08p <%s>[%d]", dv.val.arrayPtr, tagToStr(ARRAY_TAG), +- ArraySize(&dv)); ++ printd("<%s:%u %08p>", tagToStr(ARRAY_TAG), ArraySize(&dv), ++ dv.val.arrayPtr); break; case NO_TAG: if (!dv.val.inst) { -@@ -3826,57 +3872,66 @@ static void disasmInternal(Inst *inst, i + printd("<%s>", tagToStr(NO_TAG)); + } + else { +- printd("?%8p", dv.val.inst); ++ printd("?%08p", dv.val.inst); + } + break; + default: +- printd("UNKNOWN DATA TAG %d ?%8p", dv.tag, dv.val.inst); ++ printd("UNKNOWN DATA TAG %d ?%08p", dv.tag, dv.val.inst); + break; + } + } +@@ -3831,57 +3879,65 @@ static void disasmInternal(Inst *inst, i #undef OP }; int i, j; @@ -282,10 +307,11 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (j == OP_PUSH_SYM || j == OP_ASSIGN) { Symbol *sym = inst[i+1].sym; - printd("%s", sym->name); +- if (sym->value.tag == STRING_TAG && +- strncmp(sym->name, "string #", 8) == 0) { + printd(" %s", sym->name); - if (sym->value.tag == STRING_TAG && - strncmp(sym->name, "string #", 8) == 0) { -+ printd(" "); ++ if (sym->type == CONST_SYM ++ && sym->value.tag == STRING_TAG) { dumpVal(sym->value); } ++i; @@ -337,7 +363,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 +3943,20 @@ static void disasmInternal(Inst *inst, i +@@ -3893,18 +3949,20 @@ static void disasmInternal(Inst *inst, i j == OP_ANONARRAY_INDEX_VAL || j == OP_NAMED_ARG1 || j == OP_NAMED_ARGN) { @@ -364,7 +390,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } printd("\n"); -@@ -3907,18 +3964,20 @@ static void disasmInternal(Inst *inst, i +@@ -3912,18 +3970,20 @@ static void disasmInternal(Inst *inst, i } } if (j == N_OPS) { @@ -387,7 +413,48 @@ diff --quilt old/source/interpret.c new/source/interpret.c outPrintd(); } #endif /* #ifdef DEBUG_DISASSEMBLER */ -@@ -4047,7 +4106,7 @@ static void stackdumpInternal(int n, int +@@ -3974,7 +4034,7 @@ static void stackdumpframe(DataValue *ar + for (dv = endDv; dv < sp; dv++) + #endif /* #ifdef DEBUG_STACK_HEADFIRST */ + { +- const char *posFmt = "%-6s "; ++ const char *posFmt = "%-6s"; + const char *symName = ""; + + char *pos = ""; +@@ -3983,8 +4043,7 @@ static void stackdumpframe(DataValue *ar + const char *leadIn = (dv >= arrow) ? ">>>>" : + (dv == arg1) ? "----" : + (dv == fnNm) ? "====" : ""; +- printd("%4.4s", leadIn); +- printd("%8p%c", dv, topMark); ++ printd("%4.4s%8p%c", leadIn, dv, topMark); + switch (offset) { + case FP_ARG_COUNT_INDEX: pos = "NArgs"; break; /* num. arguments */ + case FP_FUNCTION_NAME: pos = "FnName"; break; +@@ -4002,7 +4061,7 @@ static void stackdumpframe(DataValue *ar + } + else if (0 <= offset && offset < nSyms) { + sprintf(pos = buffer, offset ? "[%d]" : "FP[%d]", offset); +- posFmt = "%6s "; ++ posFmt = "%6s"; + } + else if (offset == 0) { + pos = "FrameP"; +@@ -4020,10 +4079,10 @@ static void stackdumpframe(DataValue *ar + } + } + } +- printd("%-*.*s ", symLen, symLen, symName); ++ printd(" %-*.*s", symLen, symLen, symName); + + if (dv == fnNm && dv->tag == STRING_TAG && dv->val.str.rep) +- printd("%s", dv->val.str.rep); ++ printd(" %s", dv->val.str.rep); + else + dumpVal(*dv); + +@@ -4052,7 +4111,7 @@ static void stackdumpInternal(int n, int if (outpt < TheStack) printd("--------------Stack base--------------\n"); stackdumpframe(arrow, outpt, FrameP, StackP, '*'); @@ -396,6 +463,19 @@ diff --quilt old/source/interpret.c new/source/interpret.c #endif /* #ifdef DEBUG_STACK_HEADFIRST */ } +@@ -4062,7 +4121,11 @@ static void stackdump(int n, int extra) + if (outIsTTY == -1) + outIsTTY = isatty(fileno(stdout)); + +- stackdumpInternal(n, extra); ++#ifndef DEBUG_STACKDUMP_EXTRA ++#define DEBUG_STACKDUMP_EXTRA 0 ++#endif ++ stackdumpInternal(n, extra + DEBUG_STACKDUMP_EXTRA); ++#undef DEBUG_STACKDUMP_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 @@ -488,3 +568,16 @@ diff --quilt old/source/userCmds.c new/source/userCmds.c } /* +diff --quilt old/makefiles/Makefile.bertw new/makefiles/Makefile.bertw +--- old/makefiles/Makefile.bertw ++++ new/makefiles/Makefile.bertw +@@ -23,6 +23,9 @@ ifdef DEBUG + ifdef DEBUG_MACRO + ifndef DEBUG_NO_STACKDUMP + CFLAGS += -DDEBUG_STACK ++ ifdef DEBUG_STACKDUMP_EXTRA ++ CFLAGS += -DDEBUG_STACKDUMP_EXTRA=$(DEBUG_STACKDUMP_EXTRA) ++ endif + endif + ifndef DEBUG_NO_DISASM + CFLAGS += -DDEBUG_ASSEMBLY diff --git a/InterpretDebug5-fix-stackDumpStr.diff b/InterpretDebug5-fix-stackDumpStr.diff index 266e7de..2788eae 100644 --- a/InterpretDebug5-fix-stackDumpStr.diff +++ b/InterpretDebug5-fix-stackDumpStr.diff @@ -6,7 +6,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -3105,6 +3105,7 @@ static char *stackDumpStr(DataValue *fp, +@@ -3109,6 +3109,7 @@ static char *stackDumpStr(DataValue *fp, const char *op; char *np; DataValue *nfp = fp; @@ -14,7 +14,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #ifdef DEBUG_STACK const char *dump; -@@ -3116,9 +3117,12 @@ static char *stackDumpStr(DataValue *fp, +@@ -3120,9 +3121,12 @@ static char *stackDumpStr(DataValue *fp, /* first measure the lengths */ len = strlen(msg) + 1; @@ -29,7 +29,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #ifdef DEBUG_STACK len += strlen(dump); #endif -@@ -3133,12 +3137,15 @@ static char *stackDumpStr(DataValue *fp, +@@ -3137,12 +3141,15 @@ static char *stackDumpStr(DataValue *fp, while (*op) *np++ = *op++; @@ -47,7 +47,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #ifdef DEBUG_STACK op = dump; while (*op) -@@ -3421,8 +3428,8 @@ static void disasm(Inst *inst, int nInst +@@ -3426,8 +3433,8 @@ static void disasm(Inst *inst, int nInst static void stackdumpframe(DataValue *arrow, DataValue *outpt, DataValue *fp, DataValue *sp, char topMark) { diff --git a/InterpretDebug5.diff b/InterpretDebug5.diff index bb69390..b3a86c5 100644 --- a/InterpretDebug5.diff +++ b/InterpretDebug5.diff @@ -42,7 +42,7 @@ being invoked or which file is being interpreted when an error occurs. --- - source/interpret.c | 404 +++++++++++++++++++++++++++++++++++++++++--------- + source/interpret.c | 405 +++++++++++++++++++++++++++++++++++++++++--------- source/interpret.h | 2 source/macro.c | 9 - source/nedit.c | 4 @@ -51,7 +51,7 @@ being invoked or which file is being interpreted when an error occurs. source/parse_noyacc.c | 9 - source/smartIndent.c | 20 +- source/userCmds.c | 49 +++--- - 9 files changed, 403 insertions(+), 107 deletions(-) + 9 files changed, 404 insertions(+), 107 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c @@ -182,7 +182,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (resultArray->tag != ARRAY_TAG) { resultArray->tag = ARRAY_TAG; resultArray->val.arrayPtr = ArrayNew(); -@@ -2184,7 +2209,7 @@ static int callSubroutine(void) +@@ -2187,7 +2212,7 @@ static int callSubroutine(void) prog = sym->value.val.prog; prog->refcount++; /* -nArgs means 'arguments are on stack' */ @@ -191,7 +191,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -2712,7 +2737,7 @@ static int arrayRef(void) +@@ -2716,7 +2741,7 @@ static int arrayRef(void) PC++; DISASM_RT(PC-2, 2); @@ -200,7 +200,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (nDim > 0) { errNum = makeArrayKeyFromArgs(nDim, &keyString, 0); -@@ -2763,7 +2788,7 @@ static int arrayAssign(void) +@@ -2767,7 +2792,7 @@ static int arrayAssign(void) PC++; DISASM_RT(PC-2, 1); @@ -209,7 +209,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (nDim > 0) { POP(srcValue); -@@ -2801,9 +2826,9 @@ static int arrayAssign(void) +@@ -2805,9 +2830,9 @@ static int arrayAssign(void) ** for use with assign-op operators (eg a[i,j] += k ** ** Before: Prog-> [binOp], nDim, next, ... @@ -221,7 +221,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c */ static int arrayRefAndAssignSetup(void) { -@@ -2818,7 +2843,7 @@ static int arrayRefAndAssignSetup(void) +@@ -2822,7 +2847,7 @@ static int arrayRefAndAssignSetup(void) PC++; DISASM_RT(PC-3, 3); @@ -230,7 +230,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (binaryOp) { POP(moveExpr); -@@ -3072,6 +3097,59 @@ static int errCheck(const char *s) +@@ -3076,6 +3101,59 @@ static int errCheck(const char *s) } /* @@ -290,7 +290,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** combine two strings in a static area and set ErrMsg to point to the ** result. Returns false so a single return execError() statement can ** be used to both process the message and return. -@@ -3079,9 +3157,11 @@ static int errCheck(const char *s) +@@ -3083,9 +3161,11 @@ static int errCheck(const char *s) static int execError(const char *s1, const char *s2) { static char msg[MAX_ERR_MSG_LEN]; @@ -303,7 +303,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_ERROR; } -@@ -3131,11 +3211,83 @@ static const char *tagToStr(enum typeTag +@@ -3135,11 +3215,83 @@ static const char *tagToStr(enum typeTag } #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */ @@ -388,7 +388,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c break; case STRING_TAG: { -@@ -3143,38 +3295,38 @@ static void dumpVal(DataValue dv) +@@ -3147,38 +3299,39 @@ static void dumpVal(DataValue dv) char s[21]; char *src = dv.val.str.rep; if (!src) { @@ -407,13 +407,14 @@ diff --quilt old/source/interpret.c new/source/interpret.c } break; case ARRAY_TAG: -- printf(""); -+ printd("%08p [%d]", dv.val.arrayPtr, ArraySize(&dv)); +- printf("<%s>", tagToStr(ARRAY_TAG)); ++ printd("%08p <%s>[%d]", dv.val.arrayPtr, tagToStr(ARRAY_TAG), ++ ArraySize(&dv)); break; case NO_TAG: if (!dv.val.inst) { -- printf(""); -+ printd(""); +- printf("<%s>", tagToStr(NO_TAG)); ++ printd("<%s>", tagToStr(NO_TAG)); } else { - printf("?%8p", dv.val.inst); @@ -434,7 +435,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c { static const char *opNames[] = { #define OP(name, fn) #name, -@@ -3183,15 +3335,15 @@ static void disasm(Inst *inst, int nInst +@@ -3187,15 +3340,15 @@ static void disasm(Inst *inst, int nInst }; int i, j; @@ -454,7 +455,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (sym->value.tag == STRING_TAG && strncmp(sym->name, "string #", 8) == 0) { dumpVal(sym->value); -@@ -3199,29 +3351,29 @@ static void disasm(Inst *inst, int nInst +@@ -3203,29 +3356,29 @@ static void disasm(Inst *inst, int nInst ++i; } else if (j == OP_PUSH_IMMED) { @@ -490,7 +491,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); -@@ -3229,68 +3381,182 @@ static void disasm(Inst *inst, int nInst +@@ -3233,68 +3386,182 @@ static void disasm(Inst *inst, int nInst } else if (j == OP_ARRAY_REF || j == OP_ARRAY_DELETE || j == OP_ARRAY_ASSIGN) { diff --git a/SUBR_TAG.patch b/SUBR_TAG.patch index b7b8f4b..1bd7929 100644 --- a/SUBR_TAG.patch +++ b/SUBR_TAG.patch @@ -19,32 +19,15 @@ The define() macro returns also a pointer to the just created function: --- - source/interpret.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++-- - source/interpret.h | 3 +- - source/macro.c | 25 ++++++++++++++++------ - 3 files changed, 77 insertions(+), 10 deletions(-) + source/interpret.c | 31 ++++++++++++++++++++++++++++++- + source/interpret.h | 3 ++- + source/macro.c | 25 ++++++++++++++++++------- + 3 files changed, 50 insertions(+), 9 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -109,6 +109,7 @@ static SparseArrayEntry *allocateSparseA - static int inTypeOfMode; - - static const char *tagToStr(enum typeTags tag); -+static const char *typeToStr(enum symTypes type); - - /*#define DEBUG_ASSEMBLY*/ - /*#define DEBUG_STACK*/ -@@ -130,7 +131,7 @@ static void disasmInternal(Inst *inst, i - #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) -+#define STACKDUMP(n, x) stackdump(n, (x) + 10) - #define DISASM_RT(i, n) disasm(NULL, i, n) - #else /* #ifndef DEBUG_STACK */ - #define STACKDUMP(n, x) -@@ -343,6 +344,7 @@ int AddSym(Symbol *sym, char **msg) +@@ -344,6 +344,7 @@ int AddSym(Symbol *sym, char **msg) *msg = "macro too large"; return 0; } @@ -52,7 +35,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ProgP->sym = sym; ProgP++; return 1; -@@ -837,6 +839,7 @@ Symbol *InstallSymbol(const char *name, +@@ -838,6 +839,7 @@ Symbol *InstallSymbol(const char *name, strcpy(s->name, name); s->type = type; s->value = value; @@ -60,7 +43,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (type == LOCAL_SYM) { s->next = LocalSymList; LocalSymList = s; -@@ -861,7 +864,7 @@ Symbol *PromoteToGlobal(Symbol *sym) +@@ -862,7 +864,7 @@ Symbol *PromoteToGlobal(Symbol *sym) { Symbol *s; @@ -69,7 +52,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return sym; /* Remove sym from the local symbol list */ -@@ -1418,6 +1421,11 @@ static int pushSymVal(void) +@@ -1419,6 +1421,11 @@ static int pushSymVal(void) &symVal, &errMsg)) { return execError(errMsg, s->name); } @@ -81,7 +64,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else return execError("reading non-variable: %s", s->name); if (symVal.tag == NO_TAG && !inTypeOfMode) { -@@ -2513,12 +2521,26 @@ static int callSubroutineFromSymbol(Symb +@@ -2517,12 +2524,26 @@ static int callSubroutineFromSymbol(Symb Program *prog; char *errMsg; int haveNamedArgs = (nArgs < 0); @@ -108,7 +91,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* ** If the subroutine is built-in, call the built-in routine */ -@@ -3917,6 +3939,9 @@ static int typeOfOut(void) +@@ -3922,6 +3943,9 @@ static int typeOfOut(void) case ARRAY_TAG: retVal.val.str.rep = PERM_ALLOC_STR("ARRAY"); break; @@ -118,56 +101,25 @@ diff --quilt old/source/interpret.c new/source/interpret.c } retVal.val.str.len = strlen(retVal.val.str.rep); -@@ -4170,12 +4195,39 @@ static const char *tagToStr(enum typeTag - return ""; +@@ -4175,6 +4199,8 @@ static const char *tagToStr(enum typeTag + return "string"; case ARRAY_TAG: - return ""; + return "array"; + case SUBR_TAG: -+ return ""; ++ return "subroutine"; case NO_TAG: default: - return ""; - } - } - -+static const char *typeToStr(enum symTypes type) -+{ -+ switch (type) { -+ case CONST_SYM: -+ return ""; -+ case GLOBAL_SYM: -+ return ""; -+ case LOCAL_SYM: -+ return ""; -+ case ARG_SYM: -+ return ""; -+ case PROC_VALUE_SYM: -+ return ""; -+ case C_FUNCTION_SYM: -+ return ""; -+ case MACRO_FUNCTION_SYM: -+ return ""; -+ case ACTION_ROUTINE_SYM: -+ return ""; -+ } -+ -+ return ""; -+} -+ -+ - #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */ - static char *printdBuffer = NULL; - static int printdPos = 0; -@@ -4294,6 +4346,9 @@ static void dumpVal(DataValue dv) - case ARRAY_TAG: - printd(" %8p[%d]", dv.val.arrayPtr, ArraySize(&dv)); + return "no value"; +@@ -4301,6 +4327,9 @@ static void dumpVal(DataValue dv) + printd("<%s:%u %08p>", tagToStr(ARRAY_TAG), ArraySize(&dv), + dv.val.arrayPtr); break; + case SUBR_TAG: -+ printd(" %s", dv.val.sym->name); ++ printd("<%s %s>", tagToStr(SUBR_TAG), dv.val.sym->name); + break; case NO_TAG: if (!dv.val.inst) { - printd(""); + printd("<%s>", tagToStr(NO_TAG)); diff --quilt old/source/interpret.h new/source/interpret.h --- old/source/interpret.h +++ new/source/interpret.h diff --git a/Symbol-embed-name.patch b/Symbol-embed-name.patch index e810a6d..f6de664 100644 --- a/Symbol-embed-name.patch +++ b/Symbol-embed-name.patch @@ -38,7 +38,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* true, if you can pop n values */ -@@ -2736,14 +2735,26 @@ int OverlayRoutineFromSymbol(Symbol *sym +@@ -2739,14 +2738,26 @@ int OverlayRoutineFromSymbol(Symbol *sym int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs) { diff --git a/abstract-access-to-FrameP.patch b/abstract-access-to-FrameP.patch index 5338bf3..2361a23 100644 --- a/abstract-access-to-FrameP.patch +++ b/abstract-access-to-FrameP.patch @@ -109,7 +109,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else { dataPtr = &sym->value; -@@ -2677,7 +2688,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2680,7 +2691,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; } -@@ -3016,7 +3027,7 @@ static int returnValOrNone(int valOnStac +@@ -3019,7 +3030,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) { -@@ -3628,7 +3639,7 @@ static int beginArrayIter(void) +@@ -3632,7 +3643,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)); -@@ -3691,7 +3702,7 @@ static int arrayIter(void) +@@ -3695,7 +3706,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); -@@ -3703,7 +3714,7 @@ static int arrayIter(void) +@@ -3707,7 +3718,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); -@@ -3715,7 +3726,7 @@ static int arrayIter(void) +@@ -3719,7 +3730,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)); -@@ -3764,7 +3775,7 @@ static int beginArrayIterArray(void) +@@ -3768,7 +3779,7 @@ static int beginArrayIterArray(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)); -@@ -3871,7 +3882,7 @@ static int arrayIterArray(void) +@@ -3875,7 +3886,7 @@ static int arrayIterArray(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); -@@ -3884,7 +3895,7 @@ static int arrayIterArray(void) +@@ -3888,7 +3899,7 @@ static int arrayIterArray(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; -@@ -3896,7 +3907,7 @@ static int arrayIterArray(void) +@@ -3900,7 +3911,7 @@ static int arrayIterArray(void) } if (iterator->type == LOCAL_SYM) { diff --git a/abstract-access-to-PC.patch b/abstract-access-to-PC.patch index 7f38284..12ae1f0 100644 --- a/abstract-access-to-PC.patch +++ b/abstract-access-to-PC.patch @@ -109,7 +109,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) { if (sym->type == ARG_SYM) { -@@ -2559,8 +2587,7 @@ static int concat(void) +@@ -2561,8 +2589,7 @@ static int concat(void) int nExpr; @@ -119,7 +119,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-2, 2); STACKDUMP(nExpr, 3); -@@ -2644,10 +2671,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2647,10 +2674,7 @@ static int callSubroutineFromSymbol(Symb if (!sym->value.val.subr(FocusWindow, StackP, nArgs, &result, &errMsg)) return execError(errMsg, sym->name); @@ -131,7 +131,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return PreemptRequest ? STAT_PREEMPT : STAT_OK; } -@@ -2710,10 +2734,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2713,10 +2737,7 @@ static int callSubroutineFromSymbol(Symb sym->value.val.xtproc(FocusWindow->lastFocus, (XEvent *)&key_event, argList, &numArgs); XtFree((char *)argList); @@ -143,7 +143,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return PreemptRequest ? STAT_PREEMPT : STAT_OK; } -@@ -2735,8 +2756,8 @@ static int callSubroutine(void) +@@ -2738,8 +2759,8 @@ static int callSubroutine(void) Symbol *sym; int nArgs; @@ -154,7 +154,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-3, 3); STACKDUMP(nArgs > 0 ? nArgs : -nArgs, 3); -@@ -2760,7 +2781,7 @@ static int callSubroutineStackedN(void) +@@ -2763,7 +2784,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 */ @@ -163,7 +163,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PEEK_INT(nArgs, 0); DISASM_RT(PC-2, 2); -@@ -2875,7 +2896,7 @@ static int unpackArrayToArgs(void) +@@ -2878,7 +2899,7 @@ static int unpackArrayToArgs(void) DISASM_RT(PC-1, 1); STACKDUMP(1, 3); @@ -172,7 +172,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c haveNamedArgs = (nArgs < 0); POP(argArray); -@@ -2967,24 +2988,14 @@ static int returnValOrNone(int valOnStac +@@ -2970,24 +2991,14 @@ static int returnValOrNone(int valOnStac if (valOnStack) { POP(retVal); } @@ -201,7 +201,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* NULL return PC indicates end of program */ return PC == NULL ? STAT_DONE : STAT_OK; -@@ -2998,10 +3009,14 @@ static int returnValOrNone(int valOnStac +@@ -3001,10 +3012,14 @@ static int returnValOrNone(int valOnStac */ static int branch(void) { @@ -217,7 +217,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -3029,12 +3044,12 @@ static int branchIf(Boolean trueOrFalse) +@@ -3032,12 +3047,12 @@ static int branchIf(Boolean trueOrFalse) DISASM_RT(PC-1, 2); STACKDUMP(1, 3); @@ -233,7 +233,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -3048,10 +3063,13 @@ static int branchIf(Boolean trueOrFalse) +@@ -3051,10 +3066,13 @@ static int branchIf(Boolean trueOrFalse) */ static int branchNever(void) { @@ -248,7 +248,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -3412,8 +3430,7 @@ static int arrayRef(void) +@@ -3416,8 +3434,7 @@ static int arrayRef(void) char *keyString = NULL; int nDim; @@ -258,7 +258,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-2, 2); STACKDUMP(nDim+1, 3); -@@ -3463,8 +3480,7 @@ static int arrayAssign(void) +@@ -3467,8 +3484,7 @@ static int arrayAssign(void) int errNum; int nDim; @@ -268,7 +268,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-2, 1); STACKDUMP(nDim+2, 3); -@@ -3516,10 +3532,8 @@ static int arrayRefAndAssignSetup(void) +@@ -3520,10 +3536,8 @@ static int arrayRefAndAssignSetup(void) char *keyString = NULL; int binaryOp, nDim; @@ -281,7 +281,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-3, 3); STACKDUMP(nDim + (binaryOp ? 2 : 1), 3); -@@ -3575,8 +3589,7 @@ static int beginArrayIter(void) +@@ -3579,8 +3593,7 @@ static int beginArrayIter(void) DISASM_RT(PC-1, 2); STACKDUMP(1, 3); @@ -291,7 +291,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c POP(arrayVal); -@@ -3635,18 +3648,13 @@ static int arrayIter(void) +@@ -3639,18 +3652,13 @@ static int arrayIter(void) DISASM_RT(PC-1, 4); STACKDUMP(0, 4); @@ -315,7 +315,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (keySym->type == LOCAL_SYM) { keyValPtr = &FP_GET_SYM_VAL(FrameP, keySym); -@@ -3695,7 +3703,7 @@ static int arrayIter(void) +@@ -3699,7 +3707,7 @@ static int arrayIter(void) iteratorValPtr->val.arrayPtr = arrayIterateNext(thisEntry); } else { @@ -324,7 +324,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } return(STAT_OK); } -@@ -3716,8 +3724,7 @@ static int beginArrayIterArray(void) +@@ -3720,8 +3728,7 @@ static int beginArrayIterArray(void) DISASM_RT(PC-1, 2); STACKDUMP(2, 3); @@ -334,7 +334,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c POP(arrayVal); PEEK_INT(nDims, 0); -@@ -3819,23 +3826,15 @@ static int arrayIterArray(void) +@@ -3823,23 +3830,15 @@ static int arrayIterArray(void) DISASM_RT(PC-1, 4); STACKDUMP(1, 4); @@ -364,7 +364,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (keyArraySym->type == LOCAL_SYM) { keyArrayPtr = &FP_GET_SYM_VAL(FrameP, keyArraySym); -@@ -3902,7 +3901,7 @@ static int arrayIterArray(void) +@@ -3906,7 +3905,7 @@ static int arrayIterArray(void) iteratorValPtr->val.arrayPtr = thisEntry; if (!keyFound && (!thisEntry || thisEntry->nodePtrs.color == -1)) { @@ -373,7 +373,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } return STAT_OK; -@@ -3970,8 +3969,7 @@ static int deleteArrayElement(void) +@@ -3974,8 +3973,7 @@ static int deleteArrayElement(void) char *keyString = NULL; int nDim; @@ -383,7 +383,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM_RT(PC-2, 2); STACKDUMP(nDim + 1, 3); -@@ -4044,10 +4042,7 @@ static int typeOfOut(void) +@@ -4048,10 +4046,7 @@ static int typeOfOut(void) } retVal.val.str.len = strlen(retVal.val.str.rep); diff --git a/anonArrayNamedArgs7.diff b/anonArrayNamedArgs7.diff index 6645c6c..c251fd5 100644 --- a/anonArrayNamedArgs7.diff +++ b/anonArrayNamedArgs7.diff @@ -614,7 +614,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** assign top value to next symbol ** ** Before: Prog-> [symbol], next, ... -@@ -2144,7 +2429,9 @@ static int concat(void) +@@ -2147,7 +2432,9 @@ static int concat(void) /* ** Call a subroutine or function (user defined or built-in). Args are the ** subroutine's symbol, and the number of arguments which have been pushed @@ -625,7 +625,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** ** For a macro subroutine, the return address, frame pointer, number of ** arguments and space for local variables are added to the stack, and the -@@ -2152,27 +2439,35 @@ static int concat(void) +@@ -2155,27 +2442,35 @@ static int concat(void) ** arguments are popped off the stack, and the routine is just called. ** ** Before: Prog-> [subrSym], nArgs, next, ... @@ -666,7 +666,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* ** If the subroutine is built-in, call the built-in routine -@@ -2180,8 +2475,10 @@ static int callSubroutine(void) +@@ -2183,8 +2478,10 @@ static int callSubroutine(void) if (sym->type == C_FUNCTION_SYM) { DataValue result; @@ -678,7 +678,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* Call the function and check for preemption */ PreemptRequest = False; -@@ -2209,7 +2506,8 @@ static int callSubroutine(void) +@@ -2212,7 +2509,8 @@ static int callSubroutine(void) prog = sym->value.val.prog; prog->refcount++; /* -nArgs means 'arguments are on stack' */ @@ -688,7 +688,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -2222,7 +2520,13 @@ static int callSubroutine(void) +@@ -2225,7 +2523,13 @@ static int callSubroutine(void) XKeyEvent key_event; Display *disp; Window win; @@ -703,7 +703,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* Create a fake event with a timestamp suitable for actions which need timestamps, a marker to indicate that the call was from a macro (to stop shell commands from putting up their own separate banner) */ -@@ -2283,7 +2587,7 @@ static int returnVal(void) +@@ -2286,7 +2590,7 @@ static int returnVal(void) /* ** Return from a subroutine call ** Before: Prog-> [next], ... @@ -712,7 +712,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** After: Prog-> next, ..., (in caller)[FETCH_RET_VAL?], ... ** TheStack-> retVal?, next, ... */ -@@ -2349,34 +2653,26 @@ static int branch(void) +@@ -2352,34 +2656,26 @@ static int branch(void) */ static int branchTrue(void) { @@ -756,7 +756,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -3372,7 +3668,14 @@ static void disasmInternal(Inst *inst, i +@@ -3377,7 +3673,14 @@ static void disasmInternal(Inst *inst, i ++i; } else if (j == OP_SUBR_CALL) { @@ -772,7 +772,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c i += 2; } else if (j == OP_BEGIN_ARRAY_ITER) { -@@ -3386,8 +3689,12 @@ static void disasmInternal(Inst *inst, i +@@ -3391,8 +3694,12 @@ static void disasmInternal(Inst *inst, i inst[i+3].value, &inst[i+3] + inst[i+3].value); i += 3; } @@ -787,7 +787,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c printd("nDim=%d", inst[i+1].value); ++i; } -@@ -3481,13 +3788,13 @@ static void stackdumpframe(DataValue *ar +@@ -3486,13 +3793,13 @@ static void stackdumpframe(DataValue *ar printd("%4.4s", leadIn); printd("%8p%c", dv, topMark); switch (offset) { diff --git a/array-key-array-iterator.patch b/array-key-array-iterator.patch index fe517cb..0dd00ac 100644 --- a/array-key-array-iterator.patch +++ b/array-key-array-iterator.patch @@ -28,7 +28,7 @@ The key/value iteration is also supported: diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -1876,6 +1876,26 @@ static int assign(void) +@@ -1877,6 +1877,26 @@ static int assign(void) } /* @@ -55,7 +55,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** copy the top value of the stack ** Before: TheStack-> value, next, ... ** After: TheStack-> value, value, next, ... -@@ -3510,6 +3530,214 @@ static int arrayIter(void) +@@ -3515,6 +3535,214 @@ static int arrayIter(void) } /* @@ -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 -@@ -4005,7 +4233,8 @@ static void disasmInternal(Inst *inst, i +@@ -4011,7 +4239,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; } -@@ -4030,6 +4259,27 @@ static void disasmInternal(Inst *inst, i +@@ -4036,6 +4265,27 @@ static void disasmInternal(Inst *inst, i i += 5; } } diff --git a/array-next-num-index.patch b/array-next-num-index.patch index 5bee932..180b219 100644 --- a/array-next-num-index.patch +++ b/array-next-num-index.patch @@ -22,7 +22,7 @@ assigns expr to the array at position arr[@]. diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -3226,6 +3226,27 @@ SparseArrayEntry *arrayIterateNext(Spars +@@ -3231,6 +3231,27 @@ SparseArrayEntry *arrayIterateNext(Spars return(nextPos); } @@ -50,7 +50,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* ** evaluate an array element and push the result onto the stack ** -@@ -3879,6 +3900,76 @@ static int typeOfOut(void) +@@ -3884,6 +3905,76 @@ static int typeOfOut(void) } /* diff --git a/arrayReplacesArglist-as-last-argument.patch b/arrayReplacesArglist-as-last-argument.patch index a51c28a..720fe10 100644 --- a/arrayReplacesArglist-as-last-argument.patch +++ b/arrayReplacesArglist-as-last-argument.patch @@ -13,7 +13,7 @@ argument array. diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -2747,34 +2747,63 @@ int OverlayRoutineFromProg(Program *prog +@@ -2751,34 +2751,63 @@ int OverlayRoutineFromProg(Program *prog */ static int unpackArrayToArgs(void) { @@ -94,7 +94,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -4320,8 +4349,18 @@ static void disasmInternal(Inst *inst, i +@@ -4326,8 +4355,18 @@ static void disasmInternal(Inst *inst, i } i += 2; } diff --git a/arrayReplacesArglist5.diff b/arrayReplacesArglist5.diff index a4b08e2..87aeb23 100644 --- a/arrayReplacesArglist5.diff +++ b/arrayReplacesArglist5.diff @@ -85,7 +85,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -2443,6 +2448,11 @@ static int concat(void) +@@ -2446,6 +2451,11 @@ static int concat(void) ** For callSubroutine: ** Before: Prog-> [subrSym], nArgs, next, ... ** TheStack-> argArray?, argN-arg1, next, ... @@ -97,7 +97,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** After: Prog-> next, ... -- (built-in called subr) ** TheStack-> retVal?, next, ... ** or: Prog-> (in called)next, ... -- (macro code called subr) -@@ -2565,19 +2575,52 @@ static int callSubroutineFromSymbol(Symb +@@ -2568,19 +2578,52 @@ static int callSubroutineFromSymbol(Symb ** After: Prog-> next, ... -- (built-in called subr) ** Stack-> retVal?, next, ... ** or: Prog-> (in called)next, ... -- (macro code called subr) @@ -153,7 +153,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return callSubroutineFromSymbol(sym, nArgs); } -@@ -2591,7 +2634,10 @@ static int callSubroutine(void) +@@ -2594,7 +2637,10 @@ static int callSubroutine(void) int OverlayRoutineFromSymbol(Symbol *sym, int nArgs, int removeArgs) { @@ -165,7 +165,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (removeArgs > 0) { DataValue *from = StackP + removeArgs; -@@ -2599,12 +2645,20 @@ int OverlayRoutineFromSymbol(Symbol *sym +@@ -2602,12 +2648,20 @@ int OverlayRoutineFromSymbol(Symbol *sym int n = nArgs - removeArgs; nArgs = n; @@ -187,7 +187,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return callSubroutineFromSymbol(sym, nArgs); } -@@ -2627,6 +2681,60 @@ int OverlayRoutineFromProg(Program *prog +@@ -2630,6 +2684,60 @@ int OverlayRoutineFromProg(Program *prog } /* @@ -248,7 +248,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** This should never be executed, returnVal checks for the presence of this ** instruction at the PC to decide whether to push the function's return ** value, then skips over it without executing. -@@ -3740,6 +3848,10 @@ static void disasmInternal(Inst *inst, i +@@ -3745,6 +3853,10 @@ static void disasmInternal(Inst *inst, i } i += 2; } diff --git a/aryiter-on-stack.patch b/aryiter-on-stack.patch index aedce8e..345031c 100644 --- a/aryiter-on-stack.patch +++ b/aryiter-on-stack.patch @@ -33,7 +33,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Lookup a constant string by its value. This allows reuse of string ** constants and fixing a leak in the interpreter. */ -@@ -3602,10 +3584,10 @@ static int arrayRefAndAssignSetup(void) +@@ -3606,10 +3588,10 @@ static int arrayRefAndAssignSetup(void) /* ** setup symbol values for array iteration in interpreter ** @@ -47,7 +47,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Where: ** iter is a symbol which gives the position of the iterator value in ** the stack frame -@@ -3613,30 +3595,24 @@ static int arrayRefAndAssignSetup(void) +@@ -3617,30 +3599,24 @@ static int arrayRefAndAssignSetup(void) */ static int beginArrayIter(void) { @@ -85,7 +85,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -3646,10 +3622,10 @@ static int beginArrayIter(void) +@@ -3650,10 +3626,10 @@ static int beginArrayIter(void) ** this allows iterators to progress even if you delete any node in the array ** except the item just after the current key ** @@ -100,7 +100,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Where: ** iter is a symbol which gives the position of the iterator value in ** the stack frame (set up by OP_BEGIN_ARRAY_ITER); that value refers -@@ -3666,10 +3642,9 @@ static int beginArrayIter(void) +@@ -3670,10 +3646,9 @@ static int beginArrayIter(void) */ static int arrayIter(void) { @@ -112,7 +112,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DataValue *keyValPtr; DataValue *valPtr; SparseArrayEntry *thisEntry; -@@ -3677,16 +3652,17 @@ static int arrayIter(void) +@@ -3681,16 +3656,17 @@ static int arrayIter(void) int withVal; DISASM_RT(); @@ -132,7 +132,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (keySym->type == LOCAL_SYM) { keyValPtr = &FP_GET_SYM_VAL(FrameP, keySym); } -@@ -3711,14 +3687,7 @@ static int arrayIter(void) +@@ -3715,14 +3691,7 @@ static int arrayIter(void) valPtr->tag = NO_TAG; } @@ -148,7 +148,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (thisEntry && thisEntry->nodePtrs.color != -1) { /* set key */ keyValPtr->tag = STRING_TAG; -@@ -3731,52 +3700,48 @@ static int arrayIter(void) +@@ -3735,52 +3704,48 @@ static int arrayIter(void) } /* advance iterator */ @@ -214,7 +214,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -3835,17 +3800,16 @@ static Boolean splitKeyIntoArray(const c +@@ -3839,17 +3804,16 @@ static Boolean splitKeyIntoArray(const c /* ** @@ -237,7 +237,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DataValue *keyArrayPtr; DataValue *valPtr; SparseArrayEntry *thisEntry; -@@ -3855,16 +3819,16 @@ static int arrayIterArray(void) +@@ -3859,16 +3823,16 @@ static int arrayIterArray(void) Boolean keyFound = False; DISASM_RT(); @@ -256,7 +256,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PEEK_INT(nDims, 0); if (keyArraySym->type == LOCAL_SYM) { -@@ -3892,14 +3856,7 @@ static int arrayIterArray(void) +@@ -3896,14 +3860,7 @@ static int arrayIterArray(void) valPtr->tag = NO_TAG; } @@ -272,7 +272,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c while (thisEntry && thisEntry->nodePtrs.color != -1) { /* check if this is an nDims key, but only if requested */ -@@ -3929,12 +3886,14 @@ static int arrayIterArray(void) +@@ -3933,12 +3890,14 @@ static int arrayIterArray(void) thisEntry = arrayIterateNext(thisEntry); break; } @@ -288,7 +288,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return STAT_OK; } -@@ -4617,53 +4576,43 @@ static void disasmInternal(Inst *inst, i +@@ -4598,53 +4557,43 @@ static void disasmInternal(Inst *inst, i ++i; break; diff --git a/callMacroFnByName2.diff b/callMacroFnByName2.diff index b66a2cc..ae61a76 100644 --- a/callMacroFnByName2.diff +++ b/callMacroFnByName2.diff @@ -23,7 +23,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c static int concatenateNwithSep(int nVals, const char *sep, char **result, int leaveParams); static int makeArrayKeyFromArgs(int nArgs, char **keyString, int leaveParams); -@@ -2437,7 +2438,9 @@ static int concat(void) +@@ -2440,7 +2441,9 @@ static int concat(void) ** arguments and space for local variables are added to the stack, and the ** PC is set to point to the new function. For a built-in routine, the ** arguments are popped off the stack, and the routine is just called. @@ -34,7 +34,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Before: Prog-> [subrSym], nArgs, next, ... ** TheStack-> argArray?, argN-arg1, next, ... ** After: Prog-> next, ... -- (built-in called subr) -@@ -2445,30 +2448,21 @@ static int concat(void) +@@ -2448,30 +2451,21 @@ static int concat(void) ** or: Prog-> (in called)next, ... -- (macro code called subr) ** TheStack-> symN-sym1(FP), nArgs, oldFP, retPC, argArray, argN-arg1, next, ... */ @@ -69,7 +69,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* ** If the subroutine is built-in, call the built-in routine */ -@@ -2565,6 +2559,74 @@ static int callSubroutine(void) +@@ -2568,6 +2562,74 @@ static int callSubroutine(void) } /* diff --git a/core-typeof-syntax.patch b/core-typeof-syntax.patch index a1d1d4c..0905558 100644 --- a/core-typeof-syntax.patch +++ b/core-typeof-syntax.patch @@ -43,7 +43,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c static const char *tagToStr(enum typeTags tag); /*#define DEBUG_ASSEMBLY*/ -@@ -1417,7 +1420,7 @@ static int pushSymVal(void) +@@ -1418,7 +1421,7 @@ static int pushSymVal(void) } } else return execError("reading non-variable: %s", s->name); @@ -52,7 +52,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return execError("variable not set: %s", s->name); } -@@ -1545,7 +1548,7 @@ static int pushArraySymVal(void) +@@ -1546,7 +1549,7 @@ static int pushArraySymVal(void) dataPtr->val.arrayPtr = ArrayNew(); } @@ -61,7 +61,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return execError("variable not set: %s", sym->name); } -@@ -2513,9 +2516,6 @@ static int callSubroutineFromSymbol(Symb +@@ -2517,9 +2520,6 @@ static int callSubroutineFromSymbol(Symb nArgs, &result, &errMsg)) return execError(errMsg, sym->name); if (PC->func == fetchRetVal) { @@ -71,7 +71,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH(result); PC++; } -@@ -2582,7 +2582,8 @@ static int callSubroutineFromSymbol(Symb +@@ -2586,7 +2586,8 @@ static int callSubroutineFromSymbol(Symb (XEvent *)&key_event, argList, &numArgs); XtFree((char *)argList); if (PC->func == fetchRetVal) { @@ -81,7 +81,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } return PreemptRequest ? STAT_PREEMPT : STAT_OK; } -@@ -2807,14 +2808,12 @@ static int returnValOrNone(int valOnStac +@@ -2811,14 +2812,12 @@ static int returnValOrNone(int valOnStac PUSH(noValue); } } else if (PC->func == fetchRetVal) { @@ -101,7 +101,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* NULL return PC indicates end of program */ -@@ -3571,6 +3570,55 @@ static int deleteArrayElement(void) +@@ -3576,6 +3575,55 @@ static int deleteArrayElement(void) return(STAT_OK); } diff --git a/drop-SUBR_TAG.patch b/drop-SUBR_TAG.patch index c420fcb..f5a2d7b 100644 --- a/drop-SUBR_TAG.patch +++ b/drop-SUBR_TAG.patch @@ -45,7 +45,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else EXEC_ERROR("reading non-variable: %s", s->name); if (symVal.tag == NO_TAG && !inTypeOfMode) { -@@ -2683,27 +2676,12 @@ static int callSubroutineFromSymbol(Symb +@@ -2686,27 +2679,12 @@ static int callSubroutineFromSymbol(Symb DataValue argArray = noValue; Program *prog; int haveNamedArgs = (nArgs < 0); @@ -73,7 +73,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* ** If the subroutine is built-in, call the built-in routine */ -@@ -2906,7 +2884,6 @@ int OverlayRoutineFromProg(Program *prog +@@ -2909,7 +2887,6 @@ int OverlayRoutineFromProg(Program *prog strcpy(sym->name, prog->name); sym->value.val.prog = prog; sym->next = NULL; @@ -81,7 +81,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ret = OverlayRoutineFromSymbol(sym, nArgs, removeArgs); -@@ -4091,9 +4068,6 @@ static int typeOfOut(void) +@@ -4095,9 +4072,6 @@ static int typeOfOut(void) case ARRAY_TAG: retVal.val.str.rep = PERM_ALLOC_STR("ARRAY"); break; @@ -91,25 +91,25 @@ diff --quilt old/source/interpret.c new/source/interpret.c } retVal.val.str.len = strlen(retVal.val.str.rep); -@@ -4344,8 +4318,6 @@ static const char *tagToStr(enum typeTag - return ""; +@@ -4348,8 +4322,6 @@ static const char *tagToStr(enum typeTag + return "string"; case ARRAY_TAG: - return ""; + return "array"; - case SUBR_TAG: -- return ""; +- return "subroutine"; case NO_TAG: default: - return ""; -@@ -4512,9 +4484,6 @@ static void dumpVal(DataValue dv) - case ARRAY_TAG: - printd(" %8p[%d]", dv.val.arrayPtr, ArraySize(&dv)); + return "no value"; +@@ -4492,9 +4464,6 @@ static void dumpVal(DataValue dv) + printd("<%s:%u %08p>", tagToStr(ARRAY_TAG), ArraySize(&dv), + dv.val.arrayPtr); break; - case SUBR_TAG: -- printd(" %s", dv.val.sym->name); +- printd("<%s %s>", tagToStr(SUBR_TAG), dv.val.sym->name); - break; case NO_TAG: if (!dv.val.inst) { - printd(""); + printd("<%s>", tagToStr(NO_TAG)); diff --quilt old/source/interpret.h new/source/interpret.h --- old/source/interpret.h +++ new/source/interpret.h diff --git a/extend-for-key-in-array-syntax.patch b/extend-for-key-in-array-syntax.patch index 542b029..a427fa2 100644 --- a/extend-for-key-in-array-syntax.patch +++ b/extend-for-key-in-array-syntax.patch @@ -16,7 +16,7 @@ Lets you iterate over the keys and the associated values from a array, like: diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -3366,9 +3366,9 @@ static int arrayRefAndAssignSetup(void) +@@ -3371,9 +3371,9 @@ static int arrayRefAndAssignSetup(void) /* ** setup symbol values for array iteration in interpreter ** @@ -28,7 +28,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** TheStack-> [next], ... ** Where: ** iter is a symbol which gives the position of the iterator value in -@@ -3406,21 +3406,23 @@ static int beginArrayIter(void) +@@ -3411,21 +3411,23 @@ static int beginArrayIter(void) } /* @@ -59,7 +59,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** endLoopBranch is the instruction offset to the instruction following the ** loop (measured from itself) ** arrayVal is the data value holding the array in question -@@ -3430,32 +3432,54 @@ static int beginArrayIter(void) +@@ -3435,32 +3437,54 @@ static int beginArrayIter(void) static int arrayIter(void) { Symbol *iterator; @@ -124,7 +124,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (iterator->type == LOCAL_SYM) { iteratorValPtr = &FP_GET_SYM_VAL(FrameP, iterator); -@@ -3466,10 +3490,17 @@ static int arrayIter(void) +@@ -3471,10 +3495,17 @@ static int arrayIter(void) thisEntry = iteratorValPtr->val.arrayPtr; if (thisEntry && thisEntry->nodePtrs.color != -1) { @@ -146,7 +146,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c iteratorValPtr->val.arrayPtr = arrayIterateNext(thisEntry); } else { -@@ -3979,11 +4010,25 @@ static void disasmInternal(Inst *inst, i +@@ -3985,11 +4016,25 @@ static void disasmInternal(Inst *inst, i ++i; } else if (j == OP_ARRAY_ITER) { diff --git a/global-AccumulatorData.patch b/global-AccumulatorData.patch index 6592526..fceb7a8 100644 --- a/global-AccumulatorData.patch +++ b/global-AccumulatorData.patch @@ -122,7 +122,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c +#define ProgramName (Accumulator->name) /* Global data for the interpreter */ - static RestartData *Current; + static RestartData *Interpreter; @@ -263,20 +263,18 @@ void InitMacroGlobals(void) ** Start collecting instructions for a program. Clears the program ** and the symbol table. diff --git a/global-RestartData.patch b/global-RestartData.patch index d7b7c5d..f78ce45 100644 --- a/global-RestartData.patch +++ b/global-RestartData.patch @@ -31,14 +31,14 @@ diff --quilt old/source/interpret.c new/source/interpret.c -static WindowInfo - *InitiatingWindow = NULL; /* window from which macro was run */ -static WindowInfo *FocusWindow; /* window on which macro commands operate */ -+static RestartData *Current; -+#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 RestartData *Interpreter; ++#define StackP (Interpreter->stackP) ++#define TheStack (Interpreter->stack) ++#define FrameP (Interpreter->frameP) ++#define PC (Interpreter->pc) ++#define InitiatingWindow (Interpreter->runWindow) ++#define FocusWindow (Interpreter->focusWindow) ++#define ErrMsg (Interpreter->errMsg) static int PreemptRequest; /* passes preemption requests from called routines back up to the interpreter */ @@ -185,7 +185,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c WindowInfo *MacroRunWindow(void) { - return InitiatingWindow; -+ return Current ? InitiatingWindow : NULL; ++ return Interpreter ? InitiatingWindow : NULL; } /* @@ -194,7 +194,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c WindowInfo *MacroFocusWindow(void) { - return FocusWindow; -+ return Current ? FocusWindow : NULL; ++ return Interpreter ? FocusWindow : NULL; } /* @@ -203,7 +203,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c void SetMacroFocusWindow(WindowInfo *window) { - FocusWindow = window; -+ if (Current) { ++ if (Interpreter) { + FocusWindow = window; + } + else { @@ -235,8 +235,8 @@ diff --quilt old/source/interpret.c new/source/interpret.c - PC = context->pc; - InitiatingWindow = context->runWindow; - FocusWindow = context->focusWindow; -+ RestartData *old = Current; -+ Current = new; ++ RestartData *old = Interpreter; ++ Interpreter = new; + return old; } @@ -371,7 +371,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2716,7 +2687,6 @@ static int callSubroutineFromSymbol(Symb +@@ -2719,7 +2690,6 @@ static int callSubroutineFromSymbol(Symb static DataValue noValue = {NO_TAG, {0}}; DataValue argArray = noValue; Program *prog; @@ -379,7 +379,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c int haveNamedArgs = (nArgs < 0); DataValue *symValPtr = NULL; -@@ -2726,7 +2696,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2729,7 +2699,7 @@ static int callSubroutineFromSymbol(Symb } if (sym->type == LOCAL_SYM) { @@ -388,7 +388,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else if (sym->type == GLOBAL_SYM) { symValPtr = &sym->value; } -@@ -2744,6 +2714,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2747,6 +2717,7 @@ static int callSubroutineFromSymbol(Symb */ if (sym->type == C_FUNCTION_SYM) { DataValue result; @@ -396,7 +396,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH(argArray); /* push dummy named arg array */ -@@ -2752,9 +2723,9 @@ static int callSubroutineFromSymbol(Symb +@@ -2755,9 +2726,9 @@ static int callSubroutineFromSymbol(Symb /* Call the function and check for preemption */ PreemptRequest = False; @@ -408,7 +408,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH_RET_VAL(result); return PreemptRequest ? STAT_PREEMPT : STAT_OK; } -@@ -2767,15 +2738,10 @@ static int callSubroutineFromSymbol(Symb +@@ -2770,15 +2741,10 @@ static int callSubroutineFromSymbol(Symb ** values which are already there. */ if (sym->type == MACRO_FUNCTION_SYM) { @@ -421,11 +421,11 @@ diff --quilt old/source/interpret.c new/source/interpret.c - status = setupFrame(&context, prog, -nArgs, NULL, argArray, sym->name); - restoreContext(&context); - return status; -+ return setupFrame(Current, prog, -nArgs, NULL, argArray, sym->name); ++ return setupFrame(Interpreter, prog, -nArgs, NULL, argArray, sym->name); } /* -@@ -3070,7 +3036,7 @@ static int returnValOrNone(int valOnStac +@@ -3073,7 +3039,7 @@ static int returnValOrNone(int valOnStac static DataValue noValue = {NO_TAG, {0}}; DISASM_RT(); @@ -434,16 +434,16 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* return value is on the stack */ if (valOnStack) { -@@ -3080,7 +3046,7 @@ static int returnValOrNone(int valOnStac +@@ -3083,7 +3049,7 @@ static int returnValOrNone(int valOnStac retVal = noValue; } - PC = rewindFrame(&FrameP, &StackP); -+ rewindFrame(Current); ++ rewindFrame(Interpreter); /* push returned value, if requsted */ PUSH_RET_VAL(retVal); -@@ -3687,7 +3653,7 @@ static int beginArrayIter(void) +@@ -3691,7 +3657,7 @@ static int beginArrayIter(void) POP(arrayVal); if (iterator->type == LOCAL_SYM) { @@ -452,7 +452,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else { EXEC_ERROR("bad temporary iterator: %s", iterator->name); -@@ -3750,7 +3716,7 @@ static int arrayIter(void) +@@ -3754,7 +3720,7 @@ static int arrayIter(void) GET_BRANCH(branchAddr); if (keySym->type == LOCAL_SYM) { @@ -461,7 +461,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else if (keySym->type == GLOBAL_SYM) { keyValPtr = &(keySym->value); -@@ -3762,7 +3728,7 @@ static int arrayIter(void) +@@ -3766,7 +3732,7 @@ static int arrayIter(void) if (withVal) { if (valSym->type == LOCAL_SYM) { @@ -470,7 +470,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else if (valSym->type == GLOBAL_SYM) { valPtr = &(valSym->value); -@@ -3774,7 +3740,7 @@ static int arrayIter(void) +@@ -3778,7 +3744,7 @@ static int arrayIter(void) } if (iterator->type == LOCAL_SYM) { @@ -479,7 +479,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else { EXEC_ERROR("bad temporary iterator: %s", iterator->name); -@@ -3823,7 +3789,7 @@ static int beginArrayIterArray(void) +@@ -3827,7 +3793,7 @@ static int beginArrayIterArray(void) PEEK_INT(nDims, 0); if (iterator->type == LOCAL_SYM) { @@ -488,7 +488,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else { EXEC_ERROR("bad temporary iterator: %s", iterator->name); -@@ -3930,7 +3896,7 @@ static int arrayIterArray(void) +@@ -3934,7 +3900,7 @@ static int arrayIterArray(void) PEEK_INT(nDims, 0); if (keyArraySym->type == LOCAL_SYM) { @@ -497,7 +497,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else if (keyArraySym->type == GLOBAL_SYM) { keyArrayPtr = &(keyArraySym->value); -@@ -3943,7 +3909,7 @@ static int arrayIterArray(void) +@@ -3947,7 +3913,7 @@ static int arrayIterArray(void) if (withVal) { if (valSym->type == LOCAL_SYM) { @@ -506,7 +506,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else if (valSym->type == GLOBAL_SYM) { valPtr = &valSym->value; -@@ -3955,7 +3921,7 @@ static int arrayIterArray(void) +@@ -3959,7 +3925,7 @@ static int arrayIterArray(void) } if (iterator->type == LOCAL_SYM) { diff --git a/handle-error-in-RunMacroAsSubrCall.patch b/handle-error-in-RunMacroAsSubrCall.patch index bcc1568..b9b65f3 100644 --- a/handle-error-in-RunMacroAsSubrCall.patch +++ b/handle-error-in-RunMacroAsSubrCall.patch @@ -219,7 +219,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c XtFree((char *)context->stack); XtFree((char *)context); } -@@ -2728,12 +2761,15 @@ static int callSubroutineFromSymbol(Symb +@@ -2731,12 +2764,15 @@ static int callSubroutineFromSymbol(Symb ** values which are already there. */ if (sym->type == MACRO_FUNCTION_SYM) { diff --git a/interpret_c-macro-cleanup.patch b/interpret_c-macro-cleanup.patch index d007b46..f01f87f 100644 --- a/interpret_c-macro-cleanup.patch +++ b/interpret_c-macro-cleanup.patch @@ -4,8 +4,8 @@ Use 'do { } while (0)' syntax for macros and consolidate num/string conversion. --- - source/interpret.c | 406 +++++++++++++++++++++++++++++++---------------------- - 1 file changed, 239 insertions(+), 167 deletions(-) + source/interpret.c | 410 +++++++++++++++++++++++++++++++---------------------- + 1 file changed, 241 insertions(+), 169 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c @@ -99,8 +99,8 @@ diff --quilt old/source/interpret.c new/source/interpret.c + return execError(StringToNumberMsg, dataVal.val.str.rep); \ + } \ + } else { \ -+ return(execError("incompatible type in integer context: %s", \ -+ tagToStr(dataVal.tag))); \ ++ return execError("incompatible type in integer context: <%s>", \ ++ tagToStr(dataVal.tag)); \ + } \ + number = __int; \ + } while (0) @@ -114,8 +114,8 @@ diff --quilt old/source/interpret.c new/source/interpret.c + __str = AllocString(TYPE_INT_STR_SIZE(int)); \ + sprintf(__str, "%d", dataVal.val.n); \ + } else { \ -+ return(execError("incompatible type in string context: %s", \ -+ tagToStr(dataVal.tag))); \ ++ return execError("incompatible type in string context: <%s>", \ ++ tagToStr(dataVal.tag)); \ + } \ + string = __str; \ + } while (0) @@ -853,17 +853,31 @@ diff --quilt old/source/interpret.c new/source/interpret.c +{ + switch (tag) { + case INT_TAG: -+ return ""; ++ return "integer"; + case STRING_TAG: -+ return ""; ++ return "string"; + case ARRAY_TAG: -+ return ""; ++ return "array"; + case NO_TAG: + default: -+ return ""; ++ return "no value"; + } +} + #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */ static void dumpVal(DataValue dv) { +@@ -2917,11 +2989,11 @@ static void dumpVal(DataValue dv) + } + break; + case ARRAY_TAG: +- printf(""); ++ printf("<%s>", tagToStr(ARRAY_TAG)); + break; + case NO_TAG: + if (!dv.val.inst) { +- printf(""); ++ printf("<%s>", tagToStr(NO_TAG)); + } + else { + printf("?%8p", dv.val.inst); diff --git a/op-not-func-in-Inst.patch b/op-not-func-in-Inst.patch index 41c7f5a..10de538 100644 --- a/op-not-func-in-Inst.patch +++ b/op-not-func-in-Inst.patch @@ -42,7 +42,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c *(context->stackP-1) = dv; } -@@ -2615,7 +2623,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2618,7 +2626,7 @@ static int callSubroutineFromSymbol(Symb if (!sym->value.val.subr(FocusWindow, StackP, nArgs, &result, &errMsg)) return execError(errMsg, sym->name); @@ -51,7 +51,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH(result); PC++; } -@@ -2681,7 +2689,7 @@ static int callSubroutineFromSymbol(Symb +@@ -2684,7 +2692,7 @@ static int callSubroutineFromSymbol(Symb sym->value.val.xtproc(FocusWindow->lastFocus, (XEvent *)&key_event, argList, &numArgs); XtFree((char *)argList); @@ -60,7 +60,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH(noValue); PC++; } -@@ -2948,7 +2956,7 @@ static int returnValOrNone(int valOnStac +@@ -2951,7 +2959,7 @@ static int returnValOrNone(int valOnStac } else { PUSH(noValue); } @@ -69,7 +69,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (valOnStack) { PUSH(retVal); } else { -@@ -4015,7 +4023,7 @@ static int typeOfOut(void) +@@ -4019,7 +4027,7 @@ static int typeOfOut(void) } retVal.val.str.len = strlen(retVal.val.str.rep); @@ -78,7 +78,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH(retVal); PC++; } -@@ -4442,47 +4450,58 @@ static void disasmInternal(Inst *inst, i +@@ -4423,46 +4431,57 @@ static void disasmInternal(Inst *inst, i #include "ops.h" #undef OP }; @@ -107,7 +107,6 @@ diff --quilt old/source/interpret.c new/source/interpret.c - printd(" %s", sym->name); - if (sym->type == CONST_SYM - && sym->value.tag == STRING_TAG) { -- printd(" "); - dumpVal(sym->value); - } - ++i; @@ -138,7 +137,6 @@ diff --quilt old/source/interpret.c new/source/interpret.c + printd(" %s", inst[i+1].sym->name); + if (inst[i+1].sym->type == CONST_SYM + && inst[i+1].sym->value.tag == STRING_TAG) { -+ printd(" "); + dumpVal(inst[i+1].sym->value); } - else if (j == OP_SUBR_CALL) { @@ -168,7 +166,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) { -@@ -4493,7 +4512,9 @@ static void disasmInternal(Inst *inst, i +@@ -4473,7 +4492,9 @@ static void disasmInternal(Inst *inst, i } i += 2; } @@ -179,7 +177,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); -@@ -4503,85 +4524,95 @@ static void disasmInternal(Inst *inst, i +@@ -4483,85 +4504,95 @@ static void disasmInternal(Inst *inst, i } ++i; } @@ -336,12 +334,13 @@ diff --quilt old/source/interpret.c new/source/interpret.c } - } - if (j == N_OPS) { +- printd(" %x\n", inst[i].value); + + printd("\n"); + break; + + default: - printd(" %x\n", inst[i].value); ++ printd(" \n", inst[i].op); + break; } } diff --git a/remove-args-from-DISASM_RT.patch b/remove-args-from-DISASM_RT.patch index 40d583e..c066ee8 100644 --- a/remove-args-from-DISASM_RT.patch +++ b/remove-args-from-DISASM_RT.patch @@ -9,7 +9,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c @@ -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) + #define STACKDUMP(n, x) stackdump(n, x) -#define DISASM_RT(i, n) disasm(NULL, i, n) +#define DISASM_RT() disasm(NULL, PC - 1, 1) #else /* #ifndef DEBUG_STACK */ @@ -259,7 +259,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(2, 3); POP_INT(n2); -@@ -2665,9 +2667,10 @@ static int concat(void) +@@ -2667,9 +2669,10 @@ static int concat(void) int nExpr; @@ -270,8 +270,8 @@ diff --quilt old/source/interpret.c new/source/interpret.c - DISASM_RT(PC-2, 2); STACKDUMP(nExpr, 3); - len = concatenateNwithSep(nExpr, "", &out, False); -@@ -2837,10 +2840,11 @@ static int callSubroutine(void) + /* remember: concatenateNwithSep() succeeds with a non-positive number */ +@@ -2840,10 +2843,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); -@@ -2862,10 +2866,11 @@ static int callSubroutineStackedN(void) +@@ -2865,10 +2869,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); -@@ -2974,7 +2979,7 @@ static int unpackArrayToArgs(void) +@@ -2977,7 +2982,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); -@@ -3062,7 +3067,7 @@ static int returnValOrNone(int valOnStac +@@ -3065,7 +3070,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 */ -@@ -3092,7 +3097,7 @@ static int branch(void) +@@ -3095,7 +3100,7 @@ static int branch(void) { Inst *addr; @@ -324,7 +324,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(0, 3); GET_BRANCH(addr); -@@ -3122,7 +3127,7 @@ static int branchIf(Boolean trueOrFalse) +@@ -3125,7 +3130,7 @@ static int branchIf(Boolean trueOrFalse) int value; Inst *addr; @@ -333,7 +333,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c STACKDUMP(1, 3); GET_BRANCH(addr); -@@ -3146,7 +3151,7 @@ static int branchNever(void) +@@ -3149,7 +3154,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); -@@ -3511,9 +3516,10 @@ static int arrayRef(void) +@@ -3515,9 +3520,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) { -@@ -3561,9 +3567,10 @@ static int arrayAssign(void) +@@ -3565,9 +3571,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) { -@@ -3613,10 +3620,11 @@ static int arrayRefAndAssignSetup(void) +@@ -3617,10 +3624,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) { -@@ -3667,7 +3675,7 @@ static int beginArrayIter(void) +@@ -3671,7 +3679,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); -@@ -3726,7 +3734,7 @@ static int arrayIter(void) +@@ -3730,7 +3738,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); -@@ -3802,7 +3810,7 @@ static int beginArrayIterArray(void) +@@ -3806,7 +3814,7 @@ static int beginArrayIterArray(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); -@@ -3904,7 +3912,7 @@ static int arrayIterArray(void) +@@ -3908,7 +3916,7 @@ static int arrayIterArray(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); -@@ -4006,7 +4014,7 @@ static int inArray(void) +@@ -4010,7 +4018,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); -@@ -4050,9 +4058,10 @@ static int deleteArrayElement(void) +@@ -4054,9 +4062,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) { -@@ -4143,7 +4152,7 @@ static int arrayAssignNext(void) +@@ -4147,7 +4156,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(2, 3); POP(srcValue); -@@ -4185,7 +4194,7 @@ static int arrayNextNumIdx(void) +@@ -4189,7 +4198,7 @@ static int arrayNextNumIdx(void) DataValue srcArray; SparseArrayEntry *iter; diff --git a/stringToNum.diff b/stringToNum.diff index 416c5ec..64dcd61 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 -@@ -4112,33 +4112,52 @@ static int execError(const char *s1, con +@@ -4117,33 +4117,52 @@ static int execError(const char *s1, con return STAT_ERROR; } diff --git a/symbol-lookup.patch b/symbol-lookup.patch index 5f2596d..19cdc07 100644 --- a/symbol-lookup.patch +++ b/symbol-lookup.patch @@ -1,26 +1,16 @@ --- - source/interpret.c | 628 +++++++++++++++++++++++++---------------------------- + source/interpret.c | 616 ++++++++++++++++++++++++++--------------------------- source/interpret.h | 27 -- source/macro.c | 6 source/ops.h | 1 - source/parse.y | 82 +++--- - 5 files changed, 363 insertions(+), 381 deletions(-) + source/parse.y | 82 +++---- + 5 files changed, 360 insertions(+), 372 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -119,7 +119,8 @@ static const char *instTypeToStr(enum in - - #if defined(DEBUG_ASSEMBLY) || defined(DEBUG_STACK) - #define DEBUG_DISASSEMBLER --static const char *printd(const char *f, ...); -+static const char *printd(const char *f, ...) -+__attribute__ ((__format__(printf,1,2))); - static int outPrintd(); - static void disasm(const char *name, Inst *inst, int nInstr); - static void disasmInternal(Inst *inst, int nInstr); -@@ -170,7 +171,6 @@ static AccumulatorData *Accumulator; +@@ -170,7 +170,6 @@ static AccumulatorData *Accumulator; #define ProgP (Accumulator->progP) #define LoopStack (Accumulator->loopStack) #define LoopStackPtr (Accumulator->loopStackPtr) @@ -28,18 +18,18 @@ diff --quilt old/source/interpret.c new/source/interpret.c #define ProgramName (Accumulator->name) /* Global data for the interpreter */ -@@ -212,8 +212,8 @@ static int (*OpFns[])() = { +@@ -212,8 +211,8 @@ static int (*OpFns[])() = { #define FP_GET_PROG(xFrameP) ((FP_GET_ITEM(xFrameP, FP_PROG_INDEX)).val.prog) #define FP_ARG_START_INDEX(xFrameP) (-(FP_GET_ARG_COUNT(xFrameP) + FP_TO_ARGS_DIST)) #define FP_GET_ARG_N(xFrameP,xN) (FP_GET_ITEM(xFrameP, xN + FP_ARG_START_INDEX(xFrameP))) -#define FP_GET_SYM_N(xFrameP,xN) (FP_GET_ITEM(xFrameP, xN)) -#define FP_GET_SYM_VAL(xFrameP,xSym) (FP_GET_SYM_N(xFrameP, xSym->value.val.n)) +#define FP_GET_SYM_TAB(xFrameP) (FP_GET_ITEM(xFrameP, FP_SYMBOL_TABLE).val.sym) -+#define LocalSymList FP_GET_SYM_TAB(Current->frameP) ++#define LocalSymList FP_GET_SYM_TAB(Interpreter->frameP) /* ** Initialize macro language global variables. Must be called before -@@ -266,10 +266,9 @@ void InitMacroGlobals(void) +@@ -266,10 +265,9 @@ void InitMacroGlobals(void) AccumulatorData *BeginCreatingProgram(const char *name) { AccumulatorData *old = Accumulator; @@ -51,7 +41,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ProgP = Prog; LoopStackPtr = LoopStack; ProgramName = name; -@@ -285,22 +284,15 @@ AccumulatorData *BeginCreatingProgram(co +@@ -285,22 +283,15 @@ AccumulatorData *BeginCreatingProgram(co Program *FinishCreatingProgram(AccumulatorData *old) { Program *newProg; @@ -78,7 +68,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c DISASM(newProg->name, newProg->code, ProgP - Prog); XtFree((char *)Accumulator); -@@ -312,7 +304,6 @@ Program *FinishCreatingProgram(Accumulat +@@ -312,7 +303,6 @@ Program *FinishCreatingProgram(Accumulat void FreeProgram(Program *prog) { if (--prog->refcount == 0) { @@ -86,7 +76,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c XtFree((char *)prog->code); XtFree((char *)prog); } -@@ -336,14 +327,14 @@ int AddOp(int op, char **msg) +@@ -336,14 +326,14 @@ int AddOp(int op, char **msg) /* ** Add a symbol operand to the current program */ @@ -103,7 +93,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ProgP++; return 1; } -@@ -364,6 +355,21 @@ int AddImmediate(int immed, char **msg) +@@ -364,6 +354,21 @@ int AddImmediate(int immed, char **msg) } /* @@ -125,7 +115,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Add a branch offset operand to the current program */ int AddBranchOffset(Inst *to, char **msg) -@@ -507,7 +513,6 @@ static int setupFrame(RestartData *conte +@@ -507,7 +512,6 @@ static int setupFrame(RestartData *conte { static DataValue noValue = {NO_TAG, {0}}; int i, totalPushs = 7; @@ -133,7 +123,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* ** we push only if we have room for the whole frame, so pre-calc the -@@ -516,9 +521,6 @@ static int setupFrame(RestartData *conte +@@ -516,9 +520,6 @@ static int setupFrame(RestartData *conte if (nArgs >= 0) { totalPushs += nArgs; } @@ -143,7 +133,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* !OK_TO_PUSH(totalPushs) */ if (!((context->stackP + totalPushs) <= (context->stack + STACK_SIZE))) { -@@ -556,9 +558,9 @@ static int setupFrame(RestartData *conte +@@ -556,14 +557,14 @@ static int setupFrame(RestartData *conte context->stackP->val.dataval = context->frameP; context->stackP++; @@ -155,7 +145,13 @@ diff --quilt old/source/interpret.c new/source/interpret.c context->stackP++; /* macro name */ -@@ -574,12 +576,6 @@ static int setupFrame(RestartData *conte + context->stackP->tag = STRING_TAG; +- context->stackP->val.str.rep = name; ++ context->stackP->val.str.rep = (char *)name; + context->stackP->val.str.len = strlen(name); + context->stackP++; + +@@ -574,12 +575,6 @@ static int setupFrame(RestartData *conte context->frameP = context->stackP; @@ -168,7 +164,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c context->pc = prog->code; return STAT_OK; -@@ -592,6 +588,9 @@ static void rewindFrame(RestartData *con +@@ -592,6 +587,9 @@ static void rewindFrame(RestartData *con DataValue *newFrameP = FP_GET_OLD_FP(context->frameP); Inst *newPC = FP_GET_RET_PC(context->frameP); Program *prog = FP_GET_PROG(context->frameP); @@ -178,7 +174,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* pop past local variables */ context->stackP = context->frameP; -@@ -636,7 +635,7 @@ int ExecuteMacro(WindowInfo *window, Pro +@@ -636,7 +634,7 @@ int ExecuteMacro(WindowInfo *window, Pro /* Create an execution context (a stack, a stack pointer, a frame pointer, and a program counter) which will retain the program state across preemption and resumption of execution */ @@ -187,7 +183,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c memset(context, 0, sizeof(*context)); *continuation = context; context->stackP = context->stack; -@@ -817,66 +816,6 @@ void SetMacroFocusWindow(WindowInfo *win +@@ -817,72 +815,12 @@ void SetMacroFocusWindow(WindowInfo *win } } @@ -254,7 +250,14 @@ diff --quilt old/source/interpret.c new/source/interpret.c static Symbol *lookupSymbol(const Symbol *symlist, const char *name, unsigned int hash) { -@@ -891,17 +830,20 @@ static Symbol *lookupSymbol(const Symbol + while (NULL != symlist) { + if (hash == symlist->hash && strcmp(symlist->name, name) == 0) +- return symlist; ++ return (Symbol *)symlist; + symlist = symlist->next; + } + +@@ -891,17 +829,20 @@ static Symbol *lookupSymbol(const Symbol /* ** find a symbol in the symbol table @@ -274,11 +277,11 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* search in local symbols */ - if (Accumulator) { -+ if (Current) { ++ if (Interpreter) { s = lookupSymbol(LocalSymList, name, hash); if (NULL != s) return s; -@@ -912,7 +854,13 @@ Symbol *LookupSymbol(const char *name) +@@ -912,7 +853,13 @@ Symbol *LookupSymbol(const char *name) if (NULL != s) return s; @@ -293,7 +296,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -922,15 +870,23 @@ Symbol *InstallSymbol(const char *name, +@@ -922,15 +869,23 @@ Symbol *InstallSymbol(const char *name, { Symbol *s; @@ -308,7 +311,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (type == LOCAL_SYM) { - s->next = LocalSymList; - LocalSymList = s; -+ if (Current) { ++ if (Interpreter) { + s->next = LocalSymList; + LocalSymList = s; + } @@ -322,7 +325,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } else { addToGlobalSymTab(s); } -@@ -938,70 +894,6 @@ Symbol *InstallSymbol(const char *name, +@@ -938,70 +893,6 @@ Symbol *InstallSymbol(const char *name, } /* @@ -393,7 +396,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** Convert a long value to its decimal string representation, returned in a ** static string. */ -@@ -1171,7 +1063,7 @@ static SparseArrayEntry *allocateSparseA +@@ -1171,7 +1062,7 @@ static SparseArrayEntry *allocateSparseA { SparseArrayEntryWrapper *mem; @@ -402,7 +405,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c mem->next = AllocatedSparseArrayEntries; AllocatedSparseArrayEntries = mem; #ifdef TRACK_GARBAGE_LEAKS -@@ -1335,14 +1227,19 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1335,14 +1226,19 @@ static void addToGlobalSymTab(Symbol *sy #define EXEC_ERROR(s1, s2) return execError(s1, s2) @@ -424,7 +427,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } while (0) #define GET_IMMED(i) \ -@@ -1365,6 +1262,16 @@ static void addToGlobalSymTab(Symbol *sy +@@ -1365,6 +1261,16 @@ static void addToGlobalSymTab(Symbol *sy PC++; \ } while (0) @@ -441,7 +444,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #define JUMP(a) \ do { \ PC = (a); \ -@@ -1543,11 +1450,9 @@ static int pushSymVal(void) +@@ -1543,11 +1449,9 @@ static int pushSymVal(void) DISASM_RT(); STACKDUMP(0, 3); @@ -455,7 +458,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c symVal = s->value; } else if (s->type == ARG_SYM) { nArgs = FP_GET_ARG_COUNT(FrameP); -@@ -1599,6 +1504,27 @@ static int pushImmed(void) +@@ -1599,6 +1503,27 @@ static int pushImmed(void) return STAT_OK; } @@ -475,7 +478,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c + + GET_STR(str); + -+ PUSH_STRING(str, strlen(str)); ++ PUSH_STRING((char *)str, strlen(str)); + + return STAT_OK; +} @@ -483,7 +486,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c static int pushArgVal(void) { int nArgs, argNum; -@@ -1676,18 +1602,13 @@ static int pushArraySymVal(void) +@@ -1676,18 +1601,13 @@ static int pushArraySymVal(void) DISASM_RT(); STACKDUMP(0, 3); @@ -505,7 +508,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (initEmpty && dataPtr->tag == NO_TAG) { dataPtr->tag = ARRAY_TAG; -@@ -1989,7 +1910,7 @@ static int assign(void) +@@ -1989,7 +1909,7 @@ static int assign(void) DISASM_RT(); STACKDUMP(1, 3); @@ -514,7 +517,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (sym->type != GLOBAL_SYM && sym->type != LOCAL_SYM) { if (sym->type == ARG_SYM) { -@@ -2002,13 +1923,7 @@ static int assign(void) +@@ -2002,13 +1922,7 @@ static int assign(void) EXEC_ERROR("assignment to non-variable: %s", sym->name); } } @@ -529,7 +532,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c POP(value); -@@ -2765,7 +2680,7 @@ static int callSubroutine(void) +@@ -2768,7 +2682,7 @@ static int callSubroutine(void) DISASM_RT(); @@ -538,7 +541,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c GET_IMMED(nArgs); STACKDUMP(nArgs > 0 ? nArgs : -nArgs, 3); -@@ -2791,7 +2706,7 @@ static int callSubroutineStackedN(void) +@@ -2794,7 +2708,7 @@ static int callSubroutineStackedN(void) DISASM_RT(); @@ -547,7 +550,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c PEEK_INT(nArgs, 0); STACKDUMP(-nArgs + 1, 3); /* +1 for stacked nArgs */ -@@ -2853,25 +2768,15 @@ int OverlayRoutineFromSymbol(Symbol *sym +@@ -2856,25 +2770,15 @@ int OverlayRoutineFromSymbol(Symbol *sym int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs) { @@ -580,7 +583,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -3655,35 +3560,25 @@ static int arrayIter(void) +@@ -3659,35 +3563,25 @@ static int arrayIter(void) STACKDUMP(1, 4); GET_IMMED(withVal); @@ -622,7 +625,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c valPtr->tag = NO_TAG; } -@@ -3822,37 +3717,27 @@ static int arrayIterArray(void) +@@ -3826,37 +3720,27 @@ static int arrayIterArray(void) STACKDUMP(2, 4); GET_IMMED(withVal); @@ -666,7 +669,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c valPtr->tag = NO_TAG; } -@@ -4120,6 +4005,108 @@ static int errCheck(const char *s) +@@ -4124,6 +4008,108 @@ static int errCheck(const char *s) } /* @@ -732,9 +735,9 @@ diff --quilt old/source/interpret.c new/source/interpret.c + /* no space found, create new string bulk */ + if (!blk) { + void *ptr; -+ unsigned size = ROUNDUP(sizeof(stringBlkHdr), sizeof(void *)) ++ unsigned size = (unsigned)ROUNDUP(sizeof(stringBlkHdr), sizeof(void *)) + + sizeof(stringEntry) + len; -+ size = ROUNDUP(size, STRING_BLK_SIZE); ++ size = (unsigned)ROUNDUP(size, STRING_BLK_SIZE); + + posix_memalign(&ptr, STRING_BLK_SIZE, size); + *blkp = blk = ptr; @@ -775,7 +778,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** build a stack dump string, reallocating s as necessary. */ static char *stackDumpStr(DataValue *fp, const char *msg, char **s, int *pLen) -@@ -4157,7 +4144,7 @@ static char *stackDumpStr(DataValue *fp, +@@ -4161,7 +4147,7 @@ static char *stackDumpStr(DataValue *fp, #endif if (*pLen < len) { @@ -784,16 +787,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c *pLen = len; } /* now copy */ -@@ -4286,8 +4273,6 @@ static const char *tagToStr(enum typeTag - static const char *typeToStr(enum symTypes type) - { - switch (type) { -- case CONST_SYM: -- return ""; - case GLOBAL_SYM: - return ""; - case LOCAL_SYM: -@@ -4315,6 +4300,8 @@ static const char *instTypeToStr(enum in +@@ -4294,6 +4280,8 @@ static const char *instTypeToStr(enum in return "operation"; case IMMED_INST: return "immediate"; @@ -802,7 +796,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c case BRANCH_INST: return "branch"; case SYM_INST: -@@ -4398,50 +4385,64 @@ int outPrintd() +@@ -4376,6 +4364,41 @@ int outPrintd() #endif /* #ifdef DEBUG_DISASSEMBLER */ #ifdef DEBUG_DISASSEMBLER /* dumping values in disassembly or stack dump */ @@ -843,19 +837,9 @@ diff --quilt old/source/interpret.c new/source/interpret.c + static void dumpVal(DataValue dv) { - switch (dv.tag) { - case INT_TAG: -- printd(" %d", dv.val.n); -+ printd("", dv.val.n); - break; - case STRING_TAG: - { -- int k, l; -- char s[64]; - char *src = dv.val.str.rep; - if (!src) { -- printd(" "); -+ printd(""); + printd(" "); +@@ -4392,30 +4415,11 @@ static void dumpVal(DataValue dv) + printd("<%s NULL>", tagToStr(STRING_TAG)); } else { - for (k = 0, l = 0; src[k] && l < sizeof s - 1; k++, l++) { @@ -880,23 +864,17 @@ diff --quilt old/source/interpret.c new/source/interpret.c - } - } - s[l] = 0; -- printd(" \"%s\"%s[%d]", s, -- src[k] ? "..." : "", strlen(src)); +- printd("<%s:%u \"%s\"%s>", tagToStr(STRING_TAG), +- (unsigned)strlen(src), s, src[k] ? "..." : ""); + int cut; + unsigned len = strlen(src); + src = printableString(src, &cut); -+ printd("", len, src, -+ cut ? "..." : ""); ++ printd("<%s:%u \"%s\"%s>", tagToStr(STRING_TAG), len, src, ++ cut ? "..." : ""); } } break; - case ARRAY_TAG: -- printd(" %8p[%d]", dv.val.arrayPtr, ArraySize(&dv)); -+ printd("", ArraySize(&dv), dv.val.arrayPtr); - break; - case NO_TAG: - if (!dv.val.inst) { -@@ -4488,6 +4489,17 @@ static void disasmInternal(Inst *inst, i +@@ -4468,6 +4472,17 @@ static void disasmInternal(Inst *inst, i inst[i].val.immed); break; @@ -914,7 +892,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c case BRANCH_INST: printd(" <%s (%+td) %8p>\n", instTypeToStr(inst[i].type), -@@ -4498,7 +4510,7 @@ static void disasmInternal(Inst *inst, i +@@ -4478,7 +4493,7 @@ static void disasmInternal(Inst *inst, i case SYM_INST: printd(" <%s %s>\n", instTypeToStr(inst[i].type), @@ -923,21 +901,20 @@ diff --quilt old/source/interpret.c new/source/interpret.c break; default: -@@ -4517,12 +4529,7 @@ static void disasmInternal(Inst *inst, i +@@ -4499,11 +4514,7 @@ static void disasmInternal(Inst *inst, i switch (inst[i].val.op) { case OP_PUSH_SYM: case OP_ASSIGN: - 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].val.sym->value); - } + printd(" %s", inst[i+1].val.str); ++i; break; -@@ -4531,6 +4538,17 @@ static void disasmInternal(Inst *inst, i +@@ -4512,6 +4523,17 @@ static void disasmInternal(Inst *inst, i ++i; break; @@ -955,7 +932,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c case OP_BRANCH: case OP_BRANCH_TRUE: case OP_BRANCH_FALSE: -@@ -4548,7 +4566,7 @@ static void disasmInternal(Inst *inst, i +@@ -4529,7 +4551,7 @@ static void disasmInternal(Inst *inst, i case OP_SUBR_CALL: { int args = inst[i+2].val.immed; @@ -964,7 +941,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (args < 0) { printd(" %d+args[] (%d)", -args - 1, args); } -@@ -4572,7 +4590,7 @@ static void disasmInternal(Inst *inst, i +@@ -4553,7 +4575,7 @@ static void disasmInternal(Inst *inst, i break; case OP_SUBR_CALL_STACKED_N: @@ -973,7 +950,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ++i; break; -@@ -4580,7 +4598,7 @@ static void disasmInternal(Inst *inst, i +@@ -4561,7 +4583,7 @@ static void disasmInternal(Inst *inst, i if (!inst[i+1].val.immed) { /* without val */ printd(" %s = iter++ end-loop=(%+td) %8p", @@ -982,7 +959,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c inst[i+3].val.branch, &inst[i+3] + inst[i+3].val.branch); i += 3; -@@ -4588,8 +4606,8 @@ static void disasmInternal(Inst *inst, i +@@ -4569,8 +4591,8 @@ static void disasmInternal(Inst *inst, i else { /* with val */ printd(" %s=%s = iter++ end-loop=(%+td) %8p", @@ -993,7 +970,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c inst[i+4].val.branch, &inst[i+4] + inst[i+4].val.branch); i += 4; -@@ -4600,7 +4618,7 @@ static void disasmInternal(Inst *inst, i +@@ -4581,7 +4603,7 @@ static void disasmInternal(Inst *inst, i if (!inst[i+1].val.immed) { /* without val */ printd(" %s[] = iter++ end-loop=(%+td) %8p", @@ -1002,7 +979,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c inst[i+3].val.branch, &inst[i+3] + inst[i+3].val.branch); i += 3; -@@ -4608,8 +4626,8 @@ static void disasmInternal(Inst *inst, i +@@ -4589,8 +4611,8 @@ static void disasmInternal(Inst *inst, i else { /* with val */ printd(" %s[]=%s = iter++ end-loop=(%+td) %8p", @@ -1013,7 +990,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c inst[i+4].val.branch, &inst[i+4] + inst[i+4].val.branch); i += 4; -@@ -4635,7 +4653,7 @@ static void disasmInternal(Inst *inst, i +@@ -4616,7 +4638,7 @@ static void disasmInternal(Inst *inst, i case OP_PUSH_ARRAY_SYM: printd(" %s %s", @@ -1022,7 +999,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c inst[i+2].val.immed ? "createAndRef" : "refOnly"); i += 2; break; -@@ -4678,11 +4696,6 @@ static void stackdumpframe(DataValue *ar +@@ -4659,11 +4681,6 @@ static void stackdumpframe(DataValue *ar DataValue *endDv = (arg1 > outpt) ? arg1 : outpt; int nArgs = FP_GET_ARG_COUNT(fp); @@ -1034,11 +1011,10 @@ diff --quilt old/source/interpret.c new/source/interpret.c #ifdef DEBUG_STACK_HEADFIRST #else /* do caller's frame */ -@@ -4690,19 +4703,6 @@ static void stackdumpframe(DataValue *ar - stackdumpframe(arrow, outpt, oldFP, arg1, ' '); +@@ -4672,17 +4689,6 @@ static void stackdumpframe(DataValue *ar #endif /* #ifdef DEBUG_STACK_HEADFIRST */ -- /* do current frame */ + /* do current frame */ - /* how many symbols are there? */ - for (sym = syms, nSyms = 0; sym != NULL; sym = sym->next) { - nSyms++; @@ -1050,30 +1026,29 @@ diff --quilt old/source/interpret.c new/source/interpret.c - symLen = len; - } - } -- + /* output instructions between endDv and sp - 1 inclusive */ #ifdef DEBUG_STACK_HEADFIRST - dv = sp; -@@ -4712,7 +4712,6 @@ static void stackdumpframe(DataValue *ar +@@ -4693,7 +4699,6 @@ static void stackdumpframe(DataValue *ar #endif /* #ifdef DEBUG_STACK_HEADFIRST */ { - const char *posFmt = "%-6s "; + const char *posFmt = "%-6s"; - const char *symName = ""; char *pos = ""; char buffer[sizeof(STACK_DUMP_ARG_PREFIX) + TYPE_INT_STR_SIZE(int)]; -@@ -4737,10 +4736,6 @@ static void stackdumpframe(DataValue *ar +@@ -4717,10 +4722,6 @@ static void stackdumpframe(DataValue *ar sprintf(pos = buffer, STACK_DUMP_ARG_PREFIX "%d", offset + FP_TO_ARGS_DIST + nArgs + 1); } - else if (0 <= offset && offset < nSyms) { - sprintf(pos = buffer, offset ? "[%d]" : "FP[%d]", offset); -- posFmt = "%6s "; +- posFmt = "%6s"; - } else if (offset == 0) { pos = "FrameP"; } -@@ -4748,17 +4743,6 @@ static void stackdumpframe(DataValue *ar +@@ -4728,17 +4729,6 @@ static void stackdumpframe(DataValue *ar } printd(posFmt, pos); @@ -1086,10 +1061,10 @@ diff --quilt old/source/interpret.c new/source/interpret.c - } - } - } -- printd("%-*.*s ", symLen, symLen, symName); +- printd(" %-*.*s", symLen, symLen, symName); - if (dv == fnNm && dv->tag == STRING_TAG && dv->val.str.rep) - printd("%s", dv->val.str.rep); + printd(" %s", dv->val.str.rep); else diff --quilt old/source/interpret.h new/source/interpret.h --- old/source/interpret.h diff --git a/typed-Inst.patch b/typed-Inst.patch index af889e3..f531703 100644 --- a/typed-Inst.patch +++ b/typed-Inst.patch @@ -1,16 +1,16 @@ --- - source/interpret.c | 218 ++++++++++++++++++++++++++++++++++++----------------- + source/interpret.c | 219 ++++++++++++++++++++++++++++++++++++----------------- source/interpret.h | 16 ++- - 2 files changed, 160 insertions(+), 74 deletions(-) + 2 files changed, 161 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; +@@ -112,6 +112,7 @@ static SparseArrayEntry *allocateSparseA + 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*/ @@ -202,10 +202,10 @@ diff --quilt old/source/interpret.c new/source/interpret.c PUSH(dv); \ PC++; \ } \ -@@ -4322,6 +4356,23 @@ static const char *typeToStr(enum symTyp +@@ -4301,6 +4335,22 @@ static const char *tagToStr(enum typeTag + } } - +static const char *instTypeToStr(enum instTypes type) +{ + switch (type) { @@ -222,11 +222,10 @@ 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; -@@ -4480,26 +4531,54 @@ static void disasmInternal(Inst *inst, i +@@ -4461,25 +4511,55 @@ static void disasmInternal(Inst *inst, i for (i = 0; i < nInstr; ++i) { printd("Prog %8p", &inst[i]); @@ -253,7 +252,9 @@ diff --quilt old/source/interpret.c new/source/interpret.c + break; + + default: -+ printd(" \n", inst[i].val.branch); ++ printd(" \n", inst[i].type, ++ *(void **)&inst[i].val.immed); ++ break; + } + + continue; @@ -273,11 +274,10 @@ diff --quilt old/source/interpret.c new/source/interpret.c - printd(" %s", inst[i+1].sym->name); - if (inst[i+1].sym->type == CONST_SYM - && inst[i+1].sym->value.tag == STRING_TAG) { +- dumpVal(inst[i+1].sym->value); + 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; @@ -289,7 +289,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ++i; break; -@@ -4507,19 +4586,20 @@ static void disasmInternal(Inst *inst, i +@@ -4487,19 +4567,20 @@ static void disasmInternal(Inst *inst, i case OP_BRANCH_TRUE: case OP_BRANCH_FALSE: case OP_BRANCH_NEVER: @@ -315,7 +315,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (args < 0) { printd(" %d+args[] (%d)", -args - 1, args); } -@@ -4531,7 +4611,7 @@ static void disasmInternal(Inst *inst, i +@@ -4511,7 +4592,7 @@ static void disasmInternal(Inst *inst, i break; case OP_UNPACKTOARGS: { @@ -324,7 +324,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c if (args < 0) { printd(" %d+args[] (%d)", -args - 1, args); } -@@ -4543,56 +4623,56 @@ static void disasmInternal(Inst *inst, i +@@ -4523,56 +4604,56 @@ static void disasmInternal(Inst *inst, i break; case OP_SUBR_CALL_STACKED_N: @@ -407,7 +407,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c i += 5; } break; -@@ -4603,21 +4683,21 @@ static void disasmInternal(Inst *inst, i +@@ -4583,21 +4664,21 @@ static void disasmInternal(Inst *inst, i case OP_ANONARRAY_INDEX_VAL: case OP_NAMED_ARG1: case OP_NAMED_ARGN: @@ -434,12 +434,12 @@ diff --quilt old/source/interpret.c new/source/interpret.c i += 2; break; -@@ -4627,7 +4707,7 @@ static void disasmInternal(Inst *inst, i +@@ -4607,7 +4688,7 @@ static void disasmInternal(Inst *inst, i break; default: -- printd(" %x\n", inst[i].value); -+ printd(" %lx\n", inst[i].val.immed); +- printd(" \n", inst[i].op); ++ printd(" \n", inst[i].val.op); break; } } -- 2.11.4.GIT