mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Fixed a post-fix increment issue, highlighted in the game engine
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#define TOY_VERSION_MAJOR 1
|
#define TOY_VERSION_MAJOR 1
|
||||||
#define TOY_VERSION_MINOR 1
|
#define TOY_VERSION_MINOR 1
|
||||||
#define TOY_VERSION_PATCH 5
|
#define TOY_VERSION_PATCH 6
|
||||||
#define TOY_VERSION_BUILD Toy_private_version_build()
|
#define TOY_VERSION_BUILD Toy_private_version_build()
|
||||||
|
|
||||||
//platform/compiler-specific instructions
|
//platform/compiler-specific instructions
|
||||||
|
|||||||
@@ -86,5 +86,9 @@ typedef enum Toy_Opcode {
|
|||||||
TOY_OP_FN_END, //different from SECTION_END
|
TOY_OP_FN_END, //different from SECTION_END
|
||||||
TOY_OP_SECTION_END = 255,
|
TOY_OP_SECTION_END = 255,
|
||||||
//TODO: add more
|
//TODO: add more
|
||||||
|
|
||||||
|
//prefix & postfix signals (used internally)
|
||||||
|
TOY_OP_PREFIX,
|
||||||
|
TOY_OP_POSTFIX,
|
||||||
} Toy_Opcode;
|
} Toy_Opcode;
|
||||||
|
|
||||||
|
|||||||
@@ -693,7 +693,7 @@ static Toy_Opcode incrementPrefix(Toy_Parser* parser, Toy_ASTNode** nodeHandle)
|
|||||||
|
|
||||||
Toy_freeASTNode(tmpNode);
|
Toy_freeASTNode(tmpNode);
|
||||||
|
|
||||||
return TOY_OP_EOF;
|
return TOY_OP_PREFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Toy_Opcode incrementInfix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) {
|
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);
|
Toy_freeASTNode(tmpNode);
|
||||||
|
|
||||||
return TOY_OP_EOF;
|
return TOY_OP_POSTFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Toy_Opcode decrementPrefix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) {
|
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);
|
Toy_freeASTNode(tmpNode);
|
||||||
|
|
||||||
return TOY_OP_EOF;
|
return TOY_OP_PREFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Toy_Opcode decrementInfix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) {
|
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);
|
Toy_freeASTNode(tmpNode);
|
||||||
|
|
||||||
return TOY_OP_EOF;
|
return TOY_OP_POSTFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Toy_Opcode fnCall(Toy_Parser* parser, Toy_ASTNode** nodeHandle) {
|
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;
|
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);
|
Toy_emitASTNodeBinary(nodeHandle, rhsNode, opcode);
|
||||||
|
|
||||||
//optimise away the constants
|
//optimise away the constants
|
||||||
|
|||||||
15
test/scripts/increment-postfix-bugfix.toy
Normal file
15
test/scripts/increment-postfix-bugfix.toy
Normal 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";
|
||||||
@@ -119,6 +119,7 @@ int main() {
|
|||||||
"dottify-bugfix.toy",
|
"dottify-bugfix.toy",
|
||||||
"function-within-function-bugfix.toy",
|
"function-within-function-bugfix.toy",
|
||||||
"functions.toy",
|
"functions.toy",
|
||||||
|
"increment-postfix-bugfix.toy",
|
||||||
"index-arrays.toy",
|
"index-arrays.toy",
|
||||||
"index-assignment-both-bugfix.toy",
|
"index-assignment-both-bugfix.toy",
|
||||||
"index-assignment-intermediate-bugfix.toy",
|
"index-assignment-intermediate-bugfix.toy",
|
||||||
|
|||||||
Reference in New Issue
Block a user