From ad97b5bf7589747904ac393abf11997a2a0cccd8 Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Thu, 31 Jan 2008 13:58:50 +0100 Subject: [PATCH] update to arrayReplacesArglist5.diff B.W. --- InterpretDebug-disasm.patch | 4 +- ...acesArglist4.diff => arrayReplacesArglist5.diff | 103 ++++++++++++++------- core-typeof-syntax.patch | 8 +- enhanced-disable-typeof-macro.patch | 4 +- enhanced-hooks.2008-01-20.1.diff | 6 +- extend-for-key-in-array-syntax.patch | 6 +- extend-if-key-in-array-syntax.patch | 6 +- series | 2 +- stringToNum.diff | 2 +- 9 files changed, 91 insertions(+), 50 deletions(-) rename arrayReplacesArglist4.diff => arrayReplacesArglist5.diff (82%) diff --git a/InterpretDebug-disasm.patch b/InterpretDebug-disasm.patch index 5b231cf..7946b49 100644 --- a/InterpretDebug-disasm.patch +++ b/InterpretDebug-disasm.patch @@ -70,7 +70,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } void FreeProgram(Program *prog) -@@ -3830,18 +3833,31 @@ static void dumpVal(DataValue dv) +@@ -3841,18 +3844,31 @@ static void dumpVal(DataValue dv) printd("i=%d", dv.val.n); break; case STRING_TAG: @@ -104,7 +104,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c printd("s=\"%s\"%s[%d]", s, src[k] ? "..." : "", strlen(src)); } -@@ -3928,107 +3944,110 @@ static void disasmInternal(Inst *inst, i +@@ -3939,107 +3955,110 @@ static void disasmInternal(Inst *inst, i "TYPEOF_IN", /* typeOfIn */ "TYPEOF_OUT", /* typeOfOut */ }; diff --git a/arrayReplacesArglist4.diff b/arrayReplacesArglist5.diff similarity index 82% rename from arrayReplacesArglist4.diff rename to arrayReplacesArglist5.diff index 17df5fc..3575931 100644 --- a/arrayReplacesArglist4.diff +++ b/arrayReplacesArglist5.diff @@ -10,10 +10,10 @@ --- - source/interpret.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++----- + source/interpret.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++------- source/interpret.h | 2 - source/parse.y | 32 +++++++++--- - 3 files changed, 146 insertions(+), 21 deletions(-) + source/parse.y | 32 +++++++--- + 3 files changed, 165 insertions(+), 29 deletions(-) diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c @@ -70,20 +70,53 @@ diff --quilt old/source/interpret.c new/source/interpret.c StackP++; StackP->tag = INT_TAG; /* nArgs */ -@@ -1360,11 +1366,11 @@ static int pushArgArray(void) - resultArray->tag = ARRAY_TAG; - resultArray->val.arrayPtr = ArrayNew(); +@@ -1347,33 +1353,36 @@ static int pushArgCount(void) + } + + static int pushArgArray(void) + { + int nArgs, argNum; +- DataValue argVal, *resultArray; ++ DataValue argVal, *argArray; ++ Boolean needArgCopy = False; + + DISASM_RT(PC-1, 1); + STACKDUMP(0, 3); + + nArgs = FP_GET_ARG_COUNT(FrameP); +- resultArray = &FP_GET_ARG_ARRAY_CACHE(FrameP); +- if (resultArray->tag != ARRAY_TAG) { +- resultArray->tag = ARRAY_TAG; +- resultArray->val.arrayPtr = ArrayNew(); ++ argArray = &FP_GET_ARG_ARRAY_CACHE(FrameP); ++ if (argArray->tag != ARRAY_TAG) { ++ /* we require a real array in the argArray position */ ++ argArray->tag = ARRAY_TAG; ++ argArray->val.arrayPtr = ArrayNew(); ++ needArgCopy = True; } - /* load arguments from positional arg list if not already done */ +- /* load arguments from positional arg list if not already done */ - if (nArgs && !ArrayGet(resultArray, longAsStr(argNum + 1), &argVal)) { -+ if (nArgs && !ArrayGet(resultArray, (char *)longAsStr(argNum+1), &argVal)) { ++ if (needArgCopy || (nArgs && !ArrayGet(argArray, (char *)"1", &argVal))) { ++ /* load arguments from positional arg list if not already done */ for (argNum = 0; argNum < nArgs; ++argNum) { argVal = FP_GET_ARG_N(FrameP, argNum); - if (!ArrayInsert(resultArray, AllocStringOfNumber(argNum + 1), +- if (!ArrayInsert(resultArray, AllocStringOfNumber(argNum + 1), ++ if (!ArrayInsert(argArray, AllocStringOfNumber(argNum + 1), &argVal)) { return(execError("argument array insertion failure", NULL)); -@@ -2340,10 +2346,15 @@ static int concat(void) + } + } + } +- PUSH(*resultArray); ++ PUSH(*argArray); + return STAT_OK; + } + + /* + ** Push an array (by reference) onto the stack +@@ -2340,10 +2349,15 @@ static int concat(void) */ /* ** For callSubroutine: @@ -99,7 +132,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** or: Prog-> (in called)next, ... -- (macro code called subr) ** TheStack-> symN-sym1(FP), nArgs, oldFP, retPC, argArray, argN-arg1, next, ... */ -@@ -2363,12 +2374,13 @@ static int callSubroutineFromSymbol(Symb +@@ -2363,12 +2377,13 @@ static int callSubroutineFromSymbol(Symb ** If the subroutine is built-in, call the built-in routine */ if (sym->type == C_FUNCTION_SYM) { @@ -114,7 +147,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c StackP -= nArgs + 1; /* Call the function and check for preemption */ -@@ -2488,23 +2500,56 @@ static int callSubroutineFromSymbol(Symb +@@ -2488,23 +2503,56 @@ static int callSubroutineFromSymbol(Symb ** Stack-> argN-arg1, next, ... ** ** After: Prog-> next, ... -- (built-in called subr) @@ -174,7 +207,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c } /* -@@ -2514,24 +2559,35 @@ static int callSubroutine(void) +@@ -2514,24 +2562,35 @@ static int callSubroutine(void) ** removeArgs must indicate how many. */ @@ -212,7 +245,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* ** Assumes a valid prog. Wraps the program in a dummy symbol then calls -@@ -2542,18 +2598,64 @@ int OverlayRoutineFromSymbol(Symbol *sym +@@ -2542,18 +2601,72 @@ int OverlayRoutineFromSymbol(Symbol *sym int OverlayRoutineFromProg(Program *prog, int nArgs, int removeArgs) { Symbol sym; @@ -228,15 +261,24 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* +** For special call style where the $args array in the called function is -+** assigned from an array in the caller (as "calledFunc([]=argsArray)"), ++** assigned from an array in the caller (as "calledFunc(=argsArray)"), +** take consecutive elements indexed from 1 and put them on the stack, leaving -+** the actual array at the top of the stack. Finally, add the negative of the -+** number of arguments plus 1 (for the argArray itself). This operation must -+** be followed by OP_SUBR_CALL_STACKED_N (callSubroutineStackedN()). ++** a copy of the actual array at the top of the stack, with the stacked ++** arguments removed. Finally, add the negative of the number of arguments ++** aplus 1 (for the argArray itself). This operation must be followed ++** by OP_SUBR_CALL_STACKED_N (callSubroutineStackedN()). ++** ++** The array copy is needed because if/when the $args array is accessed, the ++** arguments are copied back to the array, probably in different positions, as ++** is the case of a "call(=array)" function, where the first argument is ++** removed (the function name) and the others shifted down once. Without a ++** copy, this modifies the original array - a pass by reference not allowed in ++** the language. ++** +** Before: Prog-> next, ... -+** Stack-> argArray, next, ... ++** TheStack-> argArray, next, ... +** After: Prog-> next, ... -+** Stack-> -(nArgs+1), argArray, argN-arg1, next, ... ++** TheStack-> -(nArgs+1), argArray, argN-arg1, next, ... +*/ +static int unpackArrayToArgs(void) +{ @@ -249,10 +291,9 @@ diff --quilt old/source/interpret.c new/source/interpret.c + + POP(dvEntry) + -+ if (dvArray.tag != ARRAY_TAG) { ++ if (dvEntry.tag != ARRAY_TAG) { + return execError("argument array call made with non-array value", NULL); + } -+ + res = ArrayCopy(&dvArray, &dvEntry); + if (res != STAT_OK) { + return execError("cannot copy array in array call", NULL); @@ -260,11 +301,11 @@ diff --quilt old/source/interpret.c new/source/interpret.c + + /* push positional argument entries in the array on the stack */ + for (nArgs = 1; ; ++nArgs) { -+ char *key = (char *)longAsStr(nArgs); -+ if (!ArrayGet(&dvArray, key, &dvEntry)) ++ char *ind = (char *)longAsStr(nArgs); ++ if (!ArrayGet(&dvArray, ind, &dvEntry)) + break; + /* remove them from remaining array */ -+ ArrayDelete(&dvArray, key); ++ ArrayDelete(&dvArray, ind); + PUSH(dvEntry) + } + PUSH(dvArray) @@ -278,7 +319,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** value, then skips over it without executing. */ static int fetchRetVal(void) -@@ -3581,10 +3683,12 @@ static void disasmInternal(Inst *inst, i +@@ -3581,10 +3694,12 @@ static void disasmInternal(Inst *inst, i "ARRAY_INDEX_VAL", /* anonArrayIndexVal: "{ [i]=expr }" */ "ARRAY_CLOSE", /* anonArrayClose: "{...}" */ "NAMED_ARG1", /* namedArg1: "fn([...]=..., ...)" */ @@ -291,7 +332,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c printd("\n"); for (i = 0; i < nInstr; ++i) { -@@ -3620,10 +3724,14 @@ static void disasmInternal(Inst *inst, i +@@ -3620,10 +3735,14 @@ static void disasmInternal(Inst *inst, i else { printd("%d args", args); } @@ -306,7 +347,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ++i; } else if (j == OP_ARRAY_ITER) { -@@ -3667,10 +3775,11 @@ static void disasm(Inst *inst, int nInst +@@ -3667,10 +3786,11 @@ static void disasm(Inst *inst, int nInst { static int outIsTTY = -1; if (outIsTTY == -1) outIsTTY = isatty(fileno(stdout)); @@ -318,7 +359,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #endif /* #ifdef DEBUG_DISASSEMBLER */ #ifdef DEBUG_STACK /* for run-time stack dumping */ -@@ -3707,11 +3816,11 @@ static void stackdumpframe(DataValue *ar +@@ -3707,11 +3827,11 @@ static void stackdumpframe(DataValue *ar if (len > 27) len = 27; if (len > symLen) @@ -331,7 +372,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c #ifdef DEBUG_STACK_HEADFIRST dv = sp; while (--dv >= endDv) -@@ -3754,11 +3863,11 @@ static void stackdumpframe(DataValue *ar +@@ -3754,11 +3874,11 @@ static void stackdumpframe(DataValue *ar break; } printd(posFmt, pos); @@ -344,7 +385,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c symName = sym->name; break; } -@@ -3767,11 +3876,11 @@ static void stackdumpframe(DataValue *ar +@@ -3767,11 +3887,11 @@ static void stackdumpframe(DataValue *ar printd("%-*.*s ", symLen, symLen, symName); if (dv == fnNm && dv->tag == STRING_TAG && dv->val.str.rep) diff --git a/core-typeof-syntax.patch b/core-typeof-syntax.patch index 02cc0e5..cfaae7f 100644 --- a/core-typeof-syntax.patch +++ b/core-typeof-syntax.patch @@ -50,7 +50,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c StackP++; if (StackP >= &TheStack[STACK_SIZE]) { return execError(StackOverflowMsg, ""); -@@ -1426,11 +1432,11 @@ static int pushArraySymVal(void) +@@ -1429,11 +1435,11 @@ static int pushArraySymVal(void) if (initEmpty && dataPtr->tag == NO_TAG) { dataPtr->tag = ARRAY_TAG; dataPtr->val.arrayPtr = ArrayNew(); @@ -63,7 +63,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c *StackP = *dataPtr; StackP++; -@@ -2756,18 +2762,16 @@ static int returnValOrNone(int valOnStac +@@ -2767,18 +2773,16 @@ static int returnValOrNone(int valOnStac PUSH(retVal); } else { PUSH(noValue); @@ -88,7 +88,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; } -@@ -3582,10 +3586,59 @@ static int deleteArrayElement(void) +@@ -3593,10 +3597,59 @@ static int deleteArrayElement(void) return(execError("attempt to delete from non-array", NULL)); } return(STAT_OK); @@ -148,7 +148,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** creates appropriate error messages and returns false */ static int errCheck(const char *s) -@@ -3870,10 +3923,12 @@ static void disasmInternal(Inst *inst, i +@@ -3881,10 +3934,12 @@ static void disasmInternal(Inst *inst, i "SUBR_CALL_STACKED_N", /* callSubroutineStackedN */ "UNPACKTOARGS", /* unpackArrayToArgs */ "ARRAY_INDEX", /* arrayIndex */ diff --git a/enhanced-disable-typeof-macro.patch b/enhanced-disable-typeof-macro.patch index a8e2f56..b289487 100644 --- a/enhanced-disable-typeof-macro.patch +++ b/enhanced-disable-typeof-macro.patch @@ -50,7 +50,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return execError(StackOverflowMsg, ""); } return STAT_OK; -@@ -1425,15 +1421,13 @@ static int pushArraySymVal(void) +@@ -1428,15 +1424,13 @@ static int pushArraySymVal(void) if (initEmpty && dataPtr->tag == NO_TAG) { dataPtr->tag = ARRAY_TAG; dataPtr->val.arrayPtr = ArrayNew(); @@ -66,7 +66,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c StackP++; if (StackP >= &TheStack[STACK_SIZE]) { -@@ -3077,21 +3071,17 @@ static int arrayRef(void) +@@ -3088,21 +3082,17 @@ static int arrayRef(void) } POP(srcArray) diff --git a/enhanced-hooks.2008-01-20.1.diff b/enhanced-hooks.2008-01-20.1.diff index ac36a6d..b00eb8a 100644 --- a/enhanced-hooks.2008-01-20.1.diff +++ b/enhanced-hooks.2008-01-20.1.diff @@ -1842,7 +1842,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c return execError(StackOverflowMsg, ""); } return STAT_OK; -@@ -1417,13 +1425,15 @@ static int pushArraySymVal(void) +@@ -1420,13 +1428,15 @@ static int pushArraySymVal(void) if (initEmpty && dataPtr->tag == NO_TAG) { dataPtr->tag = ARRAY_TAG; dataPtr->val.arrayPtr = ArrayNew(); @@ -1858,7 +1858,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c StackP++; if (StackP >= &TheStack[STACK_SIZE]) { -@@ -3067,17 +3077,21 @@ static int arrayRef(void) +@@ -3078,17 +3088,21 @@ static int arrayRef(void) } POP(srcArray) @@ -1882,7 +1882,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c else { POP(srcArray) if (srcArray.tag == ARRAY_TAG) { -@@ -3480,10 +3494,11 @@ static int execError(const char *s1, con +@@ -3491,10 +3505,11 @@ static int execError(const char *s1, con static char msg[MAX_ERR_MSG_LEN]; static char *err = NULL; static int errlen = 0; diff --git a/extend-for-key-in-array-syntax.patch b/extend-for-key-in-array-syntax.patch index 1a73715..24f7611 100644 --- a/extend-for-key-in-array-syntax.patch +++ b/extend-for-key-in-array-syntax.patch @@ -34,7 +34,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* Stack-> symN-sym0(FP), nArgs, oldFP, retPC, argArray, argN-arg1, next, ... */ #define FP_ARG_COUNT_INDEX (-1) #define FP_FUNCTION_NAME (-2) /* !! */ -@@ -3351,10 +3354,147 @@ static int arrayIter(void) +@@ -3362,10 +3365,147 @@ static int arrayIter(void) } return(STAT_OK); } @@ -182,7 +182,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** if the key exists, 1 is pushed onto the stack, otherwise 0 ** if the left argument is an array 1 is pushed onto the stack if every key ** in the left array exists in the right array, otherwise 0 -@@ -3728,19 +3868,21 @@ static void disasmInternal(Inst *inst, i +@@ -3739,19 +3879,21 @@ static void disasmInternal(Inst *inst, i "NAMED_ARGN", /* namedArgN: "fn(..., [...]=...)" */ "SWAP_TOP2", /* swapTop2: cf namedArgN */ "SUBR_CALL_STACKED_N", /* callSubroutineStackedN */ @@ -205,7 +205,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c printd("%s", sym->name); if (sym->value.tag == STRING_TAG && strncmp(sym->name, "string #", 8) == 0) { -@@ -3771,21 +3913,31 @@ static void disasmInternal(Inst *inst, i +@@ -3782,21 +3924,31 @@ static void disasmInternal(Inst *inst, i } else if (j == OP_SUBR_CALL_STACKED_N) { printd("%s args[] (?)", inst[i+1].sym->name); diff --git a/extend-if-key-in-array-syntax.patch b/extend-if-key-in-array-syntax.patch index 9d09712..33ab2a3 100644 --- a/extend-if-key-in-array-syntax.patch +++ b/extend-if-key-in-array-syntax.patch @@ -33,7 +33,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c /* Stack-> symN-sym0(FP), nArgs, oldFP, retPC, argArray, argN-arg1, next, ... */ #define FP_ARG_COUNT_INDEX (-1) #define FP_FUNCTION_NAME (-2) /* !! */ -@@ -1752,10 +1754,45 @@ static int assign(void) +@@ -1755,10 +1757,45 @@ static int assign(void) } return STAT_OK; } @@ -79,7 +79,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c ** After: TheStack-> value, value, next, ... */ static int dupStack(void) -@@ -3690,10 +3727,11 @@ static void disasmInternal(Inst *inst, i +@@ -3701,10 +3738,11 @@ static void disasmInternal(Inst *inst, i "NAMED_ARG1", /* namedArg1: "fn([...]=..., ...)" */ "NAMED_ARGN", /* namedArgN: "fn(..., [...]=...)" */ "SWAP_TOP2", /* swapTop2: cf namedArgN */ @@ -91,7 +91,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c printd("\n"); for (i = 0; i < nInstr; ++i) { -@@ -3749,11 +3787,12 @@ static void disasmInternal(Inst *inst, i +@@ -3760,11 +3798,12 @@ static void disasmInternal(Inst *inst, i else if (j == OP_ARRAY_REF || j == OP_ARRAY_DELETE || j == OP_ARRAY_ASSIGN || diff --git a/series b/series index fc07aa7..53fa72c 100644 --- a/series +++ b/series @@ -28,7 +28,7 @@ anonArrayNamedArgs7.diff macroStringLiterals3.diff callMacroFnByName2.diff callMacroFnByName2-help-SH.patch -arrayReplacesArglist4.diff +arrayReplacesArglist5.diff enhanced-hooks.2008-01-20.1.diff enhanced-backup-files.patch enhanced-disable-typeof-macro.patch diff --git a/stringToNum.diff b/stringToNum.diff index 02ab9c2..eb62a2f 100644 --- a/stringToNum.diff +++ b/stringToNum.diff @@ -10,7 +10,7 @@ diff --quilt old/source/interpret.c new/source/interpret.c --- old/source/interpret.c +++ new/source/interpret.c -@@ -3722,37 +3722,56 @@ static int execError(const char *s1, con +@@ -3733,37 +3733,56 @@ static int execError(const char *s1, con msg[MAX_ERR_MSG_LEN - 1] = '\0'; ErrMsg = stackDumpStr(FrameP, msg, &err, &errlen); return STAT_ERROR; -- 2.11.4.GIT