Fixed a post-fix increment issue, highlighted in the game engine

This commit is contained in:
2023-06-20 13:54:21 +10:00
parent f6ec6a8c73
commit 0e41b00ef4
5 changed files with 32 additions and 5 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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";

View File

@@ -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",