diff --git a/source/toy_common.h b/source/toy_common.h index 2425ffc..43d4f90 100644 --- a/source/toy_common.h +++ b/source/toy_common.h @@ -6,7 +6,7 @@ #define TOY_VERSION_MAJOR 1 #define TOY_VERSION_MINOR 1 -#define TOY_VERSION_PATCH 5 +#define TOY_VERSION_PATCH 6 #define TOY_VERSION_BUILD Toy_private_version_build() //platform/compiler-specific instructions diff --git a/source/toy_opcodes.h b/source/toy_opcodes.h index 45f0fbb..08d774a 100644 --- a/source/toy_opcodes.h +++ b/source/toy_opcodes.h @@ -86,5 +86,9 @@ typedef enum Toy_Opcode { TOY_OP_FN_END, //different from SECTION_END TOY_OP_SECTION_END = 255, //TODO: add more + + //prefix & postfix signals (used internally) + TOY_OP_PREFIX, + TOY_OP_POSTFIX, } Toy_Opcode; diff --git a/source/toy_parser.c b/source/toy_parser.c index a06052f..796d338 100644 --- a/source/toy_parser.c +++ b/source/toy_parser.c @@ -693,7 +693,7 @@ static Toy_Opcode incrementPrefix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) Toy_freeASTNode(tmpNode); - return TOY_OP_EOF; + return TOY_OP_PREFIX; } static Toy_Opcode incrementInfix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { @@ -710,7 +710,7 @@ static Toy_Opcode incrementInfix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { Toy_freeASTNode(tmpNode); - return TOY_OP_EOF; + return TOY_OP_POSTFIX; } static Toy_Opcode decrementPrefix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { @@ -727,7 +727,7 @@ static Toy_Opcode decrementPrefix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) Toy_freeASTNode(tmpNode); - return TOY_OP_EOF; + return TOY_OP_PREFIX; } static Toy_Opcode decrementInfix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { @@ -744,7 +744,7 @@ static Toy_Opcode decrementInfix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { Toy_freeASTNode(tmpNode); - return TOY_OP_EOF; + return TOY_OP_POSTFIX; } static Toy_Opcode fnCall(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { @@ -1287,6 +1287,13 @@ static void parsePrecedence(Toy_Parser* parser, Toy_ASTNode** nodeHandle, Preced continue; } + //BUGFIX: keep going, don't skip out on a postfix + if (opcode == TOY_OP_PREFIX || opcode == TOY_OP_POSTFIX) { + Toy_freeASTNode(*nodeHandle); + *nodeHandle = rhsNode; + continue; + } + Toy_emitASTNodeBinary(nodeHandle, rhsNode, opcode); //optimise away the constants diff --git a/test/scripts/increment-postfix-bugfix.toy b/test/scripts/increment-postfix-bugfix.toy new file mode 100644 index 0000000..4d35d59 --- /dev/null +++ b/test/scripts/increment-postfix-bugfix.toy @@ -0,0 +1,15 @@ +var a = 0; + +if (a++ >= 1) { + assert false, "increment postfix bugfix failed (first check)"; +} + + +if (a++ >= 1) { + +} + +assert a == 2, "increment postfix bugfix failed (second check)"; + + +print "All good"; \ No newline at end of file diff --git a/test/test_interpreter.c b/test/test_interpreter.c index d57c68c..d454a9e 100644 --- a/test/test_interpreter.c +++ b/test/test_interpreter.c @@ -119,6 +119,7 @@ int main() { "dottify-bugfix.toy", "function-within-function-bugfix.toy", "functions.toy", + "increment-postfix-bugfix.toy", "index-arrays.toy", "index-assignment-both-bugfix.toy", "index-assignment-intermediate-bugfix.toy",