From 7f692b4cb4eb0b8b575e0dd9887d63668d9ee9eb Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 31 Jul 2023 11:15:10 +1000 Subject: [PATCH 1/6] Renamed the about library to toy_version_info library, resovled #81 --- repl/lib_about.h | 5 ----- repl/{lib_about.c => lib_toy_version_info.c} | 10 +++++----- repl/lib_toy_version_info.h | 5 +++++ repl/repl_main.c | 4 ++-- repl/repl_tools.c | 4 ++-- repl/repl_tools.h | 2 +- test/scripts/lib/{about.toy => toy_version_info.toy} | 4 ++-- test/test_libraries.c | 6 +++--- 8 files changed, 20 insertions(+), 20 deletions(-) delete mode 100644 repl/lib_about.h rename repl/{lib_about.c => lib_toy_version_info.c} (96%) create mode 100644 repl/lib_toy_version_info.h rename test/scripts/lib/{about.toy => toy_version_info.toy} (55%) diff --git a/repl/lib_about.h b/repl/lib_about.h deleted file mode 100644 index c7ba214..0000000 --- a/repl/lib_about.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "toy_interpreter.h" - -int Toy_hookAbout(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias); diff --git a/repl/lib_about.c b/repl/lib_toy_version_info.c similarity index 96% rename from repl/lib_about.c rename to repl/lib_toy_version_info.c index b9cda17..cf323a9 100644 --- a/repl/lib_about.c +++ b/repl/lib_toy_version_info.c @@ -1,23 +1,23 @@ -#include "lib_about.h" +#include "lib_toy_version_info.h" #include "toy_memory.h" -int Toy_hookAbout(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias) { - //the about keys +int Toy_hookToyVersionInfo(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias) { + //the info keys Toy_Literal majorKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("major")); Toy_Literal minorKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("minor")); Toy_Literal patchKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("patch")); Toy_Literal buildKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("build")); Toy_Literal authorKeyLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString("author")); - //the about identifiers + //the info identifiers Toy_Literal majorIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("major")); Toy_Literal minorIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("minor")); Toy_Literal patchIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("patch")); Toy_Literal buildIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("build")); Toy_Literal authorIdentifierLiteral = TOY_TO_IDENTIFIER_LITERAL(Toy_createRefString("author")); - //the about values + //the info values Toy_Literal majorLiteral = TOY_TO_INTEGER_LITERAL(TOY_VERSION_MAJOR); Toy_Literal minorLiteral = TOY_TO_INTEGER_LITERAL(TOY_VERSION_MINOR); Toy_Literal patchLiteral = TOY_TO_INTEGER_LITERAL(TOY_VERSION_PATCH); diff --git a/repl/lib_toy_version_info.h b/repl/lib_toy_version_info.h new file mode 100644 index 0000000..1dd3fa0 --- /dev/null +++ b/repl/lib_toy_version_info.h @@ -0,0 +1,5 @@ +#pragma once + +#include "toy_interpreter.h" + +int Toy_hookToyVersionInfo(Toy_Interpreter* interpreter, Toy_Literal identifier, Toy_Literal alias); diff --git a/repl/repl_main.c b/repl/repl_main.c index 4992dad..2c07562 100644 --- a/repl/repl_main.c +++ b/repl/repl_main.c @@ -1,6 +1,6 @@ #include "repl_tools.h" #include "drive_system.h" -#include "lib_about.h" +#include "lib_toy_version_info.h" #include "lib_standard.h" #include "lib_random.h" #include "lib_runner.h" @@ -26,7 +26,7 @@ void repl(const char* initialInput) { Toy_initInterpreter(&interpreter); //inject the libs - Toy_injectNativeHook(&interpreter, "about", Toy_hookAbout); + Toy_injectNativeHook(&interpreter, "toy_version_info", Toy_hookToyVersionInfo); Toy_injectNativeHook(&interpreter, "standard", Toy_hookStandard); Toy_injectNativeHook(&interpreter, "random", Toy_hookRandom); Toy_injectNativeHook(&interpreter, "runner", Toy_hookRunner); diff --git a/repl/repl_tools.c b/repl/repl_tools.c index 63090f9..6e58a44 100644 --- a/repl/repl_tools.c +++ b/repl/repl_tools.c @@ -1,5 +1,5 @@ #include "repl_tools.h" -#include "lib_about.h" +#include "lib_toy_version_info.h" #include "lib_standard.h" #include "lib_random.h" #include "lib_runner.h" @@ -111,7 +111,7 @@ void Toy_runBinary(const unsigned char* tb, size_t size) { Toy_initInterpreter(&interpreter); //inject the libs - Toy_injectNativeHook(&interpreter, "about", Toy_hookAbout); + Toy_injectNativeHook(&interpreter, "toy_version_info", Toy_hookToyVersionInfo); Toy_injectNativeHook(&interpreter, "standard", Toy_hookStandard); Toy_injectNativeHook(&interpreter, "random", Toy_hookRandom); Toy_injectNativeHook(&interpreter, "runner", Toy_hookRunner); diff --git a/repl/repl_tools.h b/repl/repl_tools.h index d589a20..c8c464c 100644 --- a/repl/repl_tools.h +++ b/repl/repl_tools.h @@ -46,7 +46,7 @@ const unsigned char* Toy_compileString(const char* source, size_t* size); This function takes a bytecode array of `size` size, and executes it. The libraries available to the code are currently: -* lib_about +* lib_toy_version_info * lib_standard * lib_random * lib_runner diff --git a/test/scripts/lib/about.toy b/test/scripts/lib/toy_version_info.toy similarity index 55% rename from test/scripts/lib/about.toy rename to test/scripts/lib/toy_version_info.toy index 51de8c1..87a4c3a 100644 --- a/test/scripts/lib/about.toy +++ b/test/scripts/lib/toy_version_info.toy @@ -1,5 +1,5 @@ -import about as about; -import about; +import toy_version_info as toy_version_info; +import toy_version_info; assert author == "Kayne Ruse, KR Game Studios", "Author failed"; diff --git a/test/test_libraries.c b/test/test_libraries.c index ce3c9d3..58c9e77 100644 --- a/test/test_libraries.c +++ b/test/test_libraries.c @@ -14,10 +14,10 @@ #include "../repl/repl_tools.h" #include "../repl/drive_system.h" -#include "../repl/lib_about.h" +#include "../repl/lib_toy_version_info.h" +#include "../repl/lib_standard.h" #include "../repl/lib_random.h" #include "../repl/lib_runner.h" -#include "../repl/lib_standard.h" //supress the print output static void noPrintFn(const char* output) { @@ -72,7 +72,7 @@ int main() { //run each file in test/scripts Payload payloads[] = { {"interactions.toy", "standard", Toy_hookStandard}, //interactions needs standard - {"about.toy", "about", Toy_hookAbout}, + {"toy_version_info.toy", "toy_version_info", Toy_hookToyVersionInfo}, {"standard.toy", "standard", Toy_hookStandard}, {"runner.toy", "runner", Toy_hookRunner}, {"random.toy", "random", Toy_hookRandom}, From 35bfa1b9f1af2d693a222ce71a94f42f7f613e1a Mon Sep 17 00:00:00 2001 From: Ratstail91 Date: Mon, 31 Jul 2023 12:06:04 +1000 Subject: [PATCH 2/6] Tweak, these were annoying me --- repl/lib_standard.c | 8 ++++---- repl/repl_tools.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/repl/lib_standard.c b/repl/lib_standard.c index ebfb0a3..786cbd3 100644 --- a/repl/lib_standard.c +++ b/repl/lib_standard.c @@ -202,11 +202,11 @@ static int nativeMax(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) //cooerce if needed if (TOY_IS_INTEGER(resultLiteral) && TOY_IS_FLOAT(selfLiteral)) { - resultLiteral = TOY_TO_FLOAT_LITERAL( TOY_AS_INTEGER(resultLiteral) ); + resultLiteral = TOY_TO_FLOAT_LITERAL( (float)TOY_AS_INTEGER(resultLiteral) ); } if (TOY_IS_FLOAT(resultLiteral) && TOY_IS_INTEGER(selfLiteral)) { - selfLiteral = TOY_TO_FLOAT_LITERAL( TOY_AS_INTEGER(selfLiteral) ); + selfLiteral = TOY_TO_FLOAT_LITERAL( (float)TOY_AS_INTEGER(selfLiteral) ); } //compare @@ -258,11 +258,11 @@ static int nativeMin(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) //cooerce if needed if (TOY_IS_INTEGER(resultLiteral) && TOY_IS_FLOAT(selfLiteral)) { - resultLiteral = TOY_TO_FLOAT_LITERAL( TOY_AS_INTEGER(resultLiteral) ); + resultLiteral = TOY_TO_FLOAT_LITERAL( (float)TOY_AS_INTEGER(resultLiteral) ); } if (TOY_IS_FLOAT(resultLiteral) && TOY_IS_INTEGER(selfLiteral)) { - selfLiteral = TOY_TO_FLOAT_LITERAL( TOY_AS_INTEGER(selfLiteral) ); + selfLiteral = TOY_TO_FLOAT_LITERAL( (float)TOY_AS_INTEGER(selfLiteral) ); } //compare diff --git a/repl/repl_tools.c b/repl/repl_tools.c index 6e58a44..a222c18 100644 --- a/repl/repl_tools.c +++ b/repl/repl_tools.c @@ -159,7 +159,7 @@ static unsigned char readByte(const unsigned char* tb, int* count) { static const char* readString(const unsigned char* tb, int* count) { const unsigned char* ret = tb + *count; - *count += strlen((char*)ret) + 1; //+1 for null character + *count += (int)strlen((char*)ret) + 1; //+1 for null character return (const char*)ret; } From 9e4ad7a9a5508e37283d9c39f985912a9917278f Mon Sep 17 00:00:00 2001 From: Ratstail91 Date: Mon, 31 Jul 2023 16:17:33 +1000 Subject: [PATCH 3/6] 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..7085085 --- /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", From 10dbe8f8f10443626500b876029f5b43c1900393 Mon Sep 17 00:00:00 2001 From: Ratstail91 Date: Mon, 31 Jul 2023 16:17:33 +1000 Subject: [PATCH 4/6] 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", From 1ed1993489b116c69e81d1fa9b3fd0693fa808bf Mon Sep 17 00:00:00 2001 From: Ratstail91 Date: Mon, 31 Jul 2023 16:55:27 +1000 Subject: [PATCH 5/6] Whoops, lets try that again. --- source/toy_parser.c | 19 ++----------------- test/scripts/group-casting-bugfix.toy | 2 +- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/source/toy_parser.c b/source/toy_parser.c index d24e346..557be42 100644 --- a/source/toy_parser.c +++ b/source/toy_parser.c @@ -750,25 +750,10 @@ static Toy_Opcode decrementInfix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { static Toy_Opcode fnCall(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { //wait - is the previous token a type? this should be casting instead if (parser->previous.type >= TOY_TOKEN_NULL && parser->previous.type <= TOY_TOKEN_ANY) { - //casting type - Toy_ASTNode* lhsNode = NULL; - castingPrefix(parser, &lhsNode); - advance(parser); - //casting value - Toy_ASTNode* rhsNode = NULL; - parsePrecedence(parser, &rhsNode, PREC_TERNARY); + parsePrecedence(parser, nodeHandle, PREC_TERM); - //emit the cast node - - Toy_emitASTNodeBinary(&lhsNode, rhsNode, TOY_OP_TYPE_CAST); - - //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 + return TOY_OP_TYPE_CAST; //opcode value } advance(parser); //skip the left paren diff --git a/test/scripts/group-casting-bugfix.toy b/test/scripts/group-casting-bugfix.toy index 595b338..221daac 100644 --- a/test/scripts/group-casting-bugfix.toy +++ b/test/scripts/group-casting-bugfix.toy @@ -1,7 +1,7 @@ //test for casting + grouping, see #67 { assert string(10 % 4) == "2", "basic group casting failed"; - assert string 4 == "4", "Normal casting failed"; + assert string 4 == "4", "normal casting failed"; assert typeof string(10 % 4) == string, "group casting type failed"; } From 7690dce3f6f3d53697fa97cdc5241dd7465b22cf Mon Sep 17 00:00:00 2001 From: Ratstail91 Date: Mon, 31 Jul 2023 17:26:07 +1000 Subject: [PATCH 6/6] Fixed casting and grouping --- source/toy_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/toy_parser.c b/source/toy_parser.c index 557be42..3bb96a5 100644 --- a/source/toy_parser.c +++ b/source/toy_parser.c @@ -751,7 +751,7 @@ static Toy_Opcode fnCall(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { //wait - is the previous token a type? this should be casting instead if (parser->previous.type >= TOY_TOKEN_NULL && parser->previous.type <= TOY_TOKEN_ANY) { //casting value - parsePrecedence(parser, nodeHandle, PREC_TERM); + parsePrecedence(parser, nodeHandle, PREC_CALL); return TOY_OP_TYPE_CAST; //opcode value }