From 10dbe8f8f10443626500b876029f5b43c1900393 Mon Sep 17 00:00:00 2001 From: Ratstail91 Date: Mon, 31 Jul 2023 16:17:33 +1000 Subject: [PATCH] Fixed casting + grouping, resolved #67 --- Repl.vcxproj | 44 ++++++++++++++------------- Toy.vcxproj | 4 +-- source/toy_parser.c | 4 ++- test/scripts/group-casting-bugfix.toy | 11 +++++++ test/test_interpreter.c | 1 + 5 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 test/scripts/group-casting-bugfix.toy diff --git a/Repl.vcxproj b/Repl.vcxproj index 555ef5c..2bd6283 100644 --- a/Repl.vcxproj +++ b/Repl.vcxproj @@ -71,12 +71,12 @@ false - $(SolutionDir)out\$(Configuration)\ - $(Platform)\$(ProjectName)\$(Configuration)\ + $(SolutionDir)out\ + $(Platform)\$(Configuration)\$(ProjectName)\ - $(SolutionDir)out\$(Configuration)\ - $(Platform)\$(ProjectName)\$(Configuration)\ + $(SolutionDir)out\ + $(Platform)\$(Configuration)\$(ProjectName)\ @@ -110,7 +110,7 @@ Toy.lib;%(AdditionalDependencies) - $(SolutionDir)out\$(Configuration) + $(SolutionDir)out $(SolutionDir)/source;%(AdditionalIncludeDirectories) @@ -125,30 +125,32 @@ $(SolutionDir)/source;%(AdditionalIncludeDirectories) - $(SolutionDir)out\$(Configuration) + $(SolutionDir)out Toy.lib;%(AdditionalDependencies) - - - - - - - - - - - - - - - {26360002-cc2a-469a-9b28-ba0c1af41657} + + + + + + + + + + + + + + + + + diff --git a/Toy.vcxproj b/Toy.vcxproj index 58baba4..aa3a9b6 100644 --- a/Toy.vcxproj +++ b/Toy.vcxproj @@ -71,12 +71,12 @@ $(SolutionDir)out\ - $(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ false $(SolutionDir)out\ - $(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ false diff --git a/source/toy_parser.c b/source/toy_parser.c index 796d338..d24e346 100644 --- a/source/toy_parser.c +++ b/source/toy_parser.c @@ -757,7 +757,7 @@ static Toy_Opcode fnCall(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { //casting value Toy_ASTNode* rhsNode = NULL; - grouping(parser, &rhsNode); + parsePrecedence(parser, &rhsNode, PREC_TERNARY); //emit the cast node @@ -766,6 +766,8 @@ static Toy_Opcode fnCall(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { //pass it off to the caller *nodeHandle = lhsNode; + consume(parser, TOY_TOKEN_PAREN_RIGHT, "Expected ')' at end of cast grouping"); + return TOY_OP_GROUPING_BEGIN; //dummy value } diff --git a/test/scripts/group-casting-bugfix.toy b/test/scripts/group-casting-bugfix.toy new file mode 100644 index 0000000..595b338 --- /dev/null +++ b/test/scripts/group-casting-bugfix.toy @@ -0,0 +1,11 @@ +//test for casting + grouping, see #67 +{ + assert string(10 % 4) == "2", "basic group casting failed"; + assert string 4 == "4", "Normal casting failed"; + + assert typeof string(10 % 4) == string, "group casting type failed"; +} + + + +print "All good"; \ No newline at end of file diff --git a/test/test_interpreter.c b/test/test_interpreter.c index d454a9e..b67de22 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", + "group-casting-bugfix.toy", "increment-postfix-bugfix.toy", "index-arrays.toy", "index-assignment-both-bugfix.toy",