From 76ddd5703e73cc7435595f7b38c8d8a1c63a80d0 Mon Sep 17 00:00:00 2001 From: Ratstail91 Date: Sun, 5 Mar 2023 00:24:07 +1100 Subject: [PATCH] Hack: just track the intermediate depth externally --- source/toy_interpreter.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/toy_interpreter.c b/source/toy_interpreter.c index 121b40a..574de9d 100644 --- a/source/toy_interpreter.c +++ b/source/toy_interpreter.c @@ -1651,7 +1651,7 @@ static bool execIndex(Toy_Interpreter* interpreter, bool assignIntermediate) { } if (!TOY_IS_ARRAY(compound) && !TOY_IS_DICTIONARY(compound) && !TOY_IS_STRING(compound)) { - interpreter->errorOutput("Unknown compound found in indexing notation: "); + interpreter->errorOutput("Unknown compound found in index notation: "); Toy_printLiteralCustom(compound, interpreter->errorOutput); interpreter->errorOutput("\n"); @@ -1720,7 +1720,7 @@ static bool execIndex(Toy_Interpreter* interpreter, bool assignIntermediate) { return true; } -static bool execIndexAssign(Toy_Interpreter* interpreter) { +static bool execIndexAssign(Toy_Interpreter* interpreter, int assignDepth) { //assume -> compound, first, second, third, assign are all on the stack Toy_Literal assign = TOY_TO_NULL_LITERAL, third = TOY_TO_NULL_LITERAL, second = TOY_TO_NULL_LITERAL, first = TOY_TO_NULL_LITERAL, compound = TOY_TO_NULL_LITERAL, result = TOY_TO_NULL_LITERAL; @@ -1756,7 +1756,7 @@ static bool execIndexAssign(Toy_Interpreter* interpreter) { } //iterate... - while(interpreter->stack.count >= 4) { + while(assignDepth-- >= 0) { Toy_freeLiteral(assign); Toy_freeLiteral(third); Toy_freeLiteral(second); @@ -1914,6 +1914,9 @@ static void execInterpreter(Toy_Interpreter* interpreter) { interpreter->codeStart = interpreter->count; } + //BUGFIX + int intermediateAssignDepth = 0; + unsigned char opcode = readByte(interpreter->bytecode, &interpreter->count); while(opcode != TOY_OP_EOF && opcode != TOY_OP_SECTION_END && !interpreter->panic) { @@ -2128,12 +2131,14 @@ static void execInterpreter(Toy_Interpreter* interpreter) { if (!execIndex(interpreter, true)) { return; } + intermediateAssignDepth++; break; case TOY_OP_INDEX_ASSIGN: - if (!execIndexAssign(interpreter)) { + if (!execIndexAssign(interpreter, intermediateAssignDepth)) { return; } + intermediateAssignDepth = 0; break; case TOY_OP_POP_STACK: