From 7b501b71b54427afb49f38afb349d6219c37b91e Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 14 Feb 2023 16:57:56 +0000 Subject: [PATCH] commandLine now initializes with default values --- source/toy_common.c | 29 +++++++++++----------- source/toy_common.h | 2 +- test/test_call_from_host.c | 50 +++++++++++++++++++------------------- 3 files changed, 40 insertions(+), 41 deletions(-) diff --git a/source/toy_common.c b/source/toy_common.c index cfa49f7..42c1154 100644 --- a/source/toy_common.c +++ b/source/toy_common.c @@ -15,23 +15,22 @@ STATIC_ASSERT(sizeof(unsigned char) == 1); STATIC_ASSERT(sizeof(unsigned short) == 2); STATIC_ASSERT(sizeof(unsigned int) == 4); -//declare the singleton -Toy_CommandLine Toy_commandLine; +//declare the singleton with default values +Toy_CommandLine Toy_commandLine = { + .error = false, + .help = false, + .version = false, + .binaryfile = NULL, + .sourcefile = NULL, + .compilefile = NULL, + .outfile = "out.tb", + .source = NULL, + .initialfile = NULL, + .enablePrintNewline = true, + .verbose = false +}; void Toy_initCommandLine(int argc, const char* argv[]) { - //default values - Toy_commandLine.error = false; - Toy_commandLine.help = false; - Toy_commandLine.version = false; - Toy_commandLine.binaryfile = NULL; - Toy_commandLine.sourcefile = NULL; - Toy_commandLine.compilefile = NULL; - Toy_commandLine.outfile = "out.tb"; - Toy_commandLine.source = NULL; - Toy_commandLine.initialfile = NULL; - Toy_commandLine.enablePrintNewline = true; - Toy_commandLine.verbose = false; - for (int i = 1; i < argc; i++) { //start at 1 to skip the program name Toy_commandLine.error = true; //error state by default, set to false by successful flags diff --git a/source/toy_common.h b/source/toy_common.h index 0953a4d..52afdf1 100644 --- a/source/toy_common.h +++ b/source/toy_common.h @@ -6,7 +6,7 @@ #define TOY_VERSION_MAJOR 0 #define TOY_VERSION_MINOR 9 -#define TOY_VERSION_PATCH 1 +#define TOY_VERSION_PATCH 2 #define TOY_VERSION_BUILD __DATE__ " " __TIME__ //platform/compiler-specific instructions diff --git a/test/test_call_from_host.c b/test/test_call_from_host.c index 9cc1ae5..d693339 100644 --- a/test/test_call_from_host.c +++ b/test/test_call_from_host.c @@ -20,7 +20,7 @@ static void noPrintFn(const char* output) { } void error(char* msg) { - printf("%s", msg); + printf("%s\n", msg); exit(-1); } @@ -41,7 +41,7 @@ int main() { //test answer { - interpreter.printOutput("Testing answer\n"); + interpreter.printOutput("Testing answer"); Toy_LiteralArray arguments; Toy_initLiteralArray(&arguments); @@ -52,15 +52,15 @@ int main() { //check the results if (arguments.count != 0) { - error("Arguments has the wrong number of members\n"); + error("Arguments has the wrong number of members"); } if (returns.count != 1) { - error("Returns has the wrong number of members\n"); + error("Returns has the wrong number of members"); } if (!TOY_IS_INTEGER(returns.literals[0]) || TOY_AS_INTEGER(returns.literals[0]) != 42) { - error("Returned value is incorrect\n"); + error("Returned value is incorrect"); } Toy_freeLiteralArray(&arguments); @@ -69,7 +69,7 @@ int main() { //test identity { - interpreter.printOutput("Testing identity\n"); + interpreter.printOutput("Testing identity"); Toy_LiteralArray arguments; Toy_initLiteralArray(&arguments); @@ -85,17 +85,17 @@ int main() { //check the results if (arguments.count != 0) { - error("Arguments has the wrong number of members\n"); + error("Arguments has the wrong number of members"); } if (returns.count != 1) { - error("Returns has the wrong number of members\n"); + error("Returns has the wrong number of members"); } float epsilon = 0.1; //because floats are evil if (!TOY_IS_FLOAT(returns.literals[0]) || fabs(TOY_AS_FLOAT(returns.literals[0]) - pi) > epsilon) { - error("Returned value is incorrect\n"); + error("Returned value is incorrect"); } Toy_freeLiteralArray(&arguments); @@ -104,7 +104,7 @@ int main() { //test makeCounter (closures) { - interpreter.printOutput("Testing makeCounter (closures)\n"); + interpreter.printOutput("Testing makeCounter (closures)"); Toy_LiteralArray arguments; Toy_initLiteralArray(&arguments); @@ -115,11 +115,11 @@ int main() { //check the results if (arguments.count != 0) { - error("Arguments has the wrong number of members\n"); + error("Arguments has the wrong number of members"); } if (returns.count != 1) { - error("Returns has the wrong number of members\n"); + error("Returns has the wrong number of members"); } //grab the resulting literal @@ -139,15 +139,15 @@ int main() { //check the results if (arguments.count != 0) { - error("Arguments (1) has the wrong number of members\n"); + error("Arguments (1) has the wrong number of members"); } if (returns.count != 1) { - error("Returns (1) has the wrong number of members\n"); + error("Returns (1) has the wrong number of members"); } if (!TOY_IS_INTEGER(returns.literals[0]) || TOY_AS_INTEGER(returns.literals[0]) != 1) { - error("Returned value (1) is incorrect\n"); + error("Returned value (1) is incorrect"); } Toy_freeLiteralArray(&arguments); @@ -164,15 +164,15 @@ int main() { //check the results if (arguments.count != 0) { - error("Arguments (2) has the wrong number of members\n"); + error("Arguments (2) has the wrong number of members"); } if (returns.count != 1) { - error("Returns (2) has the wrong number of members\n"); + error("Returns (2) has the wrong number of members"); } if (!TOY_IS_INTEGER(returns.literals[0]) || TOY_AS_INTEGER(returns.literals[0]) != 2) { - error("Returned value (2) is incorrect\n"); + error("Returned value (2) is incorrect"); } Toy_freeLiteralArray(&arguments); @@ -189,15 +189,15 @@ int main() { //check the results if (arguments.count != 0) { - error("Arguments (3) has the wrong number of members\n"); + error("Arguments (3) has the wrong number of members"); } if (returns.count != 1) { - error("Returns (3) has the wrong number of members\n"); + error("Returns (3) has the wrong number of members"); } if (!TOY_IS_INTEGER(returns.literals[0]) || TOY_AS_INTEGER(returns.literals[0]) != 3) { - error("Returned value (3) is incorrect\n"); + error("Returned value (3) is incorrect"); } Toy_freeLiteralArray(&arguments); @@ -209,7 +209,7 @@ int main() { //test assertion failure { - interpreter.printOutput("Testing assertion failure\n"); + interpreter.printOutput("Testing assertion failure"); Toy_setInterpreterAssert(&interpreter, noPrintFn); @@ -222,15 +222,15 @@ int main() { //check the results if (arguments.count != 0) { - error("Arguments has the wrong number of members\n"); + error("Arguments has the wrong number of members"); } if (returns.count != 1 || !TOY_IS_NULL(returns.literals[0])) { - error("Returns has the wrong number of members\n"); + error("Returns has the wrong number of members"); } if (!ret) { - error("Assertion gives the wrong return value\n"); + error("Assertion gives the wrong return value"); } Toy_freeLiteralArray(&arguments);