From cfafba589bd4fc3aa4743743f71d1719cfa9e3b1 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 26 Nov 2022 09:53:59 +0000 Subject: [PATCH] All tests passing, repl builds successfully --- repl/lib_standard.c | 4 ++-- repl/lib_timer.c | 6 ++--- repl/repl_main.c | 6 ++--- repl/repl_tools.c | 6 ++--- test/makefile | 22 +------------------ ...call_from_host.c => test_call_from_host.c} | 6 ++--- test/{xtest_libraries.c => test_libraries.c} | 6 ++--- ...ue_data_type.c => test_opaque_data_type.c} | 6 ++--- 8 files changed, 21 insertions(+), 41 deletions(-) rename test/{xtest_call_from_host.c => test_call_from_host.c} (98%) rename test/{xtest_libraries.c => test_libraries.c} (97%) rename test/{xtest_opaque_data_type.c => test_opaque_data_type.c} (97%) diff --git a/repl/lib_standard.c b/repl/lib_standard.c index 8061941..26debdb 100644 --- a/repl/lib_standard.c +++ b/repl/lib_standard.c @@ -18,7 +18,7 @@ static int nativeClock(Interpreter* interpreter, LiteralArray* arguments) { //push to the stack int len = strlen(timestr) - 1; //-1 for the newline - Literal timeLiteral = TO_STRING_LITERAL(copyString(timestr, len), len); + Literal timeLiteral = TO_STRING_LITERAL(createRefStringLength(timestr, len)); //push to the stack pushLiteralArray(&interpreter->stack, timeLiteral); @@ -57,7 +57,7 @@ int hookStandard(Interpreter* interpreter, Literal identifier, Literal alias) { //load the dict with functions for (int i = 0; natives[i].name; i++) { - Literal name = TO_STRING_LITERAL(copyString(natives[i].name, strlen(natives[i].name)), strlen(natives[i].name)); + Literal name = TO_STRING_LITERAL(createRefStringLength(natives[i].name, strlen(natives[i].name))); Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0); func.type = LITERAL_FUNCTION_NATIVE; diff --git a/repl/lib_timer.c b/repl/lib_timer.c index efb2426..efa47ea 100644 --- a/repl/lib_timer.c +++ b/repl/lib_timer.c @@ -292,12 +292,12 @@ static int nativeTimerToString(Interpreter* interpreter, LiteralArray* arguments if (timer->tv_sec == 0 && timer->tv_usec < 0) { //special case, for when the negative sign is encoded in the usec char buffer[128]; snprintf(buffer, 128, "-%ld.%06ld", timer->tv_sec, -timer->tv_usec); - resultLiteral = TO_STRING_LITERAL( copyString(buffer, strlen(buffer)), strlen(buffer)); + resultLiteral = TO_STRING_LITERAL(createRefStringLength(buffer, strlen(buffer))); } else { //normal case char buffer[128]; snprintf(buffer, 128, "%ld.%06ld", timer->tv_sec, timer->tv_usec); - resultLiteral = TO_STRING_LITERAL( copyString(buffer, strlen(buffer)), strlen(buffer)); + resultLiteral = TO_STRING_LITERAL(createRefStringLength(buffer, strlen(buffer))); } pushLiteralArray(&interpreter->stack, resultLiteral); @@ -374,7 +374,7 @@ int hookTimer(Interpreter* interpreter, Literal identifier, Literal alias) { //load the dict with functions for (int i = 0; natives[i].name; i++) { - Literal name = TO_STRING_LITERAL(copyString(natives[i].name, strlen(natives[i].name)), strlen(natives[i].name)); + Literal name = TO_STRING_LITERAL(createRefStringLength(natives[i].name, strlen(natives[i].name))); Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0); func.type = LITERAL_FUNCTION_NATIVE; diff --git a/repl/repl_main.c b/repl/repl_main.c index cf2b80d..998e611 100644 --- a/repl/repl_main.c +++ b/repl/repl_main.c @@ -50,15 +50,15 @@ void repl() { ASTNode* node = scanParser(&parser); while(node != NULL) { //pack up and restart - if (node->type == AST_NODEERROR) { + if (node->type == AST_NODE_ERROR) { printf(ERROR "error node detected\n" RESET); error = true; - freeNode(node); + freeASTNode(node); break; } writeCompiler(&compiler, node); - freeNode(node); + freeASTNode(node); node = scanParser(&parser); } diff --git a/repl/repl_tools.c b/repl/repl_tools.c index b9bf20d..df3fd2c 100644 --- a/repl/repl_tools.c +++ b/repl/repl_tools.c @@ -78,16 +78,16 @@ unsigned char* compileString(char* source, size_t* size) { ASTNode* node = scanParser(&parser); while(node != NULL) { //pack up and leave - if (node->type == AST_NODEERROR) { + if (node->type == AST_NODE_ERROR) { printf(ERROR "error node detected\n" RESET); - freeNode(node); + freeASTNode(node); freeCompiler(&compiler); freeParser(&parser); return NULL; } writeCompiler(&compiler, node); - freeNode(node); + freeASTNode(node); node = scanParser(&parser); } diff --git a/test/makefile b/test/makefile index 38d58b7..afcd46c 100644 --- a/test/makefile +++ b/test/makefile @@ -4,27 +4,7 @@ IDIR +=. ../source ../repl CFLAGS +=$(addprefix -I,$(IDIR)) -g -Wall -W -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable LIBS += ODIR = obj - -#TARGETS = $(wildcard ../source/*.c) $(wildcard ../repl/lib_*.c) - -#literal primitives -TARGETS+=../source/memory.c ../source/refstring.c ../source/literal.c ../source/literal_array.c ../source/literal_dictionary.c ../source/scope.c - -#lexer -TARGETS+=../source/toy_common.c ../source/keyword_types.c ../source/lexer.c - -#ast primitives -TARGETS+=../source/ast_node.c - -#parser -TARGETS+=../source/parser.c - -#compiler -TARGETS+=../source/compiler.c - -#interpreter -TARGETS+=../source/interpreter.c ../source/builtin.c - +TARGETS = $(wildcard ../source/*.c) $(wildcard ../repl/lib_*.c) TESTS = $(wildcard test_*.c) OBJ = $(addprefix $(ODIR)/,$(TARGETS:../source/%.c=%.o)) $(addprefix $(ODIR)/,$(TESTS:.c=.o)) diff --git a/test/xtest_call_from_host.c b/test/test_call_from_host.c similarity index 98% rename from test/xtest_call_from_host.c rename to test/test_call_from_host.c index 10d2115..dca9797 100644 --- a/test/xtest_call_from_host.c +++ b/test/test_call_from_host.c @@ -64,16 +64,16 @@ unsigned char* compileString(char* source, size_t* size) { ASTNode* node = scanParser(&parser); while(node != NULL) { //pack up and leave - if (node->type == AST_NODEERROR) { + if (node->type == AST_NODE_ERROR) { printf(ERROR "error node detected\n" RESET); - freeNode(node); + freeASTNode(node); freeCompiler(&compiler); freeParser(&parser); return NULL; } writeCompiler(&compiler, node); - freeNode(node); + freeASTNode(node); node = scanParser(&parser); } diff --git a/test/xtest_libraries.c b/test/test_libraries.c similarity index 97% rename from test/xtest_libraries.c rename to test/test_libraries.c index f096a76..0fdf458 100644 --- a/test/xtest_libraries.c +++ b/test/test_libraries.c @@ -79,16 +79,16 @@ unsigned char* compileString(char* source, size_t* size) { ASTNode* node = scanParser(&parser); while(node != NULL) { //pack up and leave - if (node->type == AST_NODEERROR) { + if (node->type == AST_NODE_ERROR) { printf(ERROR "error node detected\n" RESET); - freeNode(node); + freeASTNode(node); freeCompiler(&compiler); freeParser(&parser); return NULL; } writeCompiler(&compiler, node); - freeNode(node); + freeASTNode(node); node = scanParser(&parser); } diff --git a/test/xtest_opaque_data_type.c b/test/test_opaque_data_type.c similarity index 97% rename from test/xtest_opaque_data_type.c rename to test/test_opaque_data_type.c index cfcbf7a..2977bc9 100644 --- a/test/xtest_opaque_data_type.c +++ b/test/test_opaque_data_type.c @@ -62,16 +62,16 @@ unsigned char* compileString(char* source, size_t* size) { ASTNode* node = scanParser(&parser); while(node != NULL) { //pack up and leave - if (node->type == AST_NODEERROR) { + if (node->type == AST_NODE_ERROR) { printf(ERROR "error node detected\n" RESET); - freeNode(node); + freeASTNode(node); freeCompiler(&compiler); freeParser(&parser); return NULL; } writeCompiler(&compiler, node); - freeNode(node); + freeASTNode(node); node = scanParser(&parser); }