From 5231572578a0a407002a85f5c89559bfce7f8a6b Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 26 Nov 2022 16:03:56 +0000 Subject: [PATCH] Updated Toy to 0.6.3 --- Toy | 2 +- core/engine_node.c | 4 ++-- core/lib_engine.c | 6 +++--- core/lib_input.c | 4 ++-- core/lib_node.c | 10 +++++----- core/lib_standard.c | 4 ++-- core/lib_timer.c | 6 +++--- core/makefile | 1 + core/repl_tools.c | 6 +++--- 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Toy b/Toy index 7bf18a7..fb55f42 160000 --- a/Toy +++ b/Toy @@ -1 +1 @@ -Subproject commit 7bf18a744c84a14f9942fba6bdc2e1f6bd02d09a +Subproject commit fb55f42d0ec7205136dad09437730a4603c0b0cd diff --git a/core/engine_node.c b/core/engine_node.c index af58953..2157431 100644 --- a/core/engine_node.c +++ b/core/engine_node.c @@ -137,7 +137,7 @@ Literal callEngineNodeLiteral(EngineNode* node, Interpreter* interpreter, Litera Literal callEngineNode(EngineNode* node, Interpreter* interpreter, char* fnName, LiteralArray* args) { //call "fnName" on this node, and all children, if it exists - Literal key = TO_IDENTIFIER_LITERAL(copyString(fnName, strlen(fnName)), strlen(fnName)); + Literal key = TO_IDENTIFIER_LITERAL(createRefString(fnName)); Literal ret = callEngineNodeLiteral(node, interpreter, key, args); @@ -185,7 +185,7 @@ void callRecursiveEngineNodeLiteral(EngineNode* node, Interpreter* interpreter, void callRecursiveEngineNode(EngineNode* node, Interpreter* interpreter, char* fnName, LiteralArray* args) { //call "fnName" on this node, and all children, if it exists - Literal key = TO_IDENTIFIER_LITERAL(copyString(fnName, strlen(fnName)), strlen(fnName)); + Literal key = TO_IDENTIFIER_LITERAL(createRefString(fnName)); callRecursiveEngineNodeLiteral(node, interpreter, key, args); diff --git a/core/lib_engine.c b/core/lib_engine.c index 79047d2..b400a16 100644 --- a/core/lib_engine.c +++ b/core/lib_engine.c @@ -35,7 +35,7 @@ static int nativeInitWindow(Interpreter* interpreter, LiteralArray* arguments) { //init the window engine.window = SDL_CreateWindow( - AS_STRING(caption), + toCString(AS_STRING(caption)), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, engine.screenWidth = AS_INTEGER(screenWidth), @@ -108,7 +108,7 @@ static int nativeLoadRootNode(Interpreter* interpreter, LiteralArray* arguments) //load the new root node size_t size = 0; - char* source = readFile(AS_STRING(fname), &size); + char* source = readFile(toCString(AS_STRING(fname)), &size); unsigned char* tb = compileString(source, &size); free((void*)source); @@ -176,7 +176,7 @@ int hookEngine(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(createRefString(natives[i].name)); Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0); func.type = LITERAL_FUNCTION_NATIVE; diff --git a/core/lib_input.c b/core/lib_input.c index 1abe256..033c0d5 100644 --- a/core/lib_input.c +++ b/core/lib_input.c @@ -33,7 +33,7 @@ static int nativeMapInputEventToKey(Interpreter* interpreter, LiteralArray* argu } //use the keycode for faster lookups - SDL_Keycode keycode = SDL_GetKeyFromName( AS_STRING(symLiteral) ); + SDL_Keycode keycode = SDL_GetKeyFromName( toCString(AS_STRING(symLiteral)) ); if (keycode == SDLK_UNKNOWN) { interpreter->errorOutput("Unknown key found: "); @@ -94,7 +94,7 @@ int hookInput(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(createRefString(natives[i].name)); Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0); func.type = LITERAL_FUNCTION_NATIVE; diff --git a/core/lib_node.c b/core/lib_node.c index 3441d78..6aae282 100644 --- a/core/lib_node.c +++ b/core/lib_node.c @@ -32,7 +32,7 @@ static int nativeLoadNode(Interpreter* interpreter, LiteralArray* arguments) { //load the new node size_t size = 0; - char* source = readFile(AS_STRING(fname), &size); + char* source = readFile(toCString(AS_STRING(fname)), &size); unsigned char* tb = compileString(source, &size); free((void*)source); @@ -311,7 +311,7 @@ static int nativeLoadTexture(Interpreter* interpreter, LiteralArray* arguments) freeTextureEngineNode(node); } - if (loadTextureEngineNode(node, AS_STRING(fname)) != 0) { + if (loadTextureEngineNode(node, toCString(AS_STRING(fname))) != 0) { interpreter->errorOutput("Failed to load the texture into the EngineNode\n"); freeLiteral(fname); freeLiteral(nodeLiteral); @@ -588,8 +588,8 @@ static int nativeCallNode(Interpreter* interpreter, LiteralArray* arguments) { return -1; } - char* strptr = AS_STRING(fnName); - Literal fnNameIdentifier = TO_IDENTIFIER_LITERAL(copyString(strptr, strlen(strptr)), strlen(strptr)); + //allow refstring to do it's magic + Literal fnNameIdentifier = TO_IDENTIFIER_LITERAL(copyRefString(AS_STRING(fnName))); //call the function Literal result = callEngineNodeLiteral(AS_OPAQUE(nodeLiteral), interpreter, fnNameIdentifier, &extraArgs); @@ -644,7 +644,7 @@ int hookNode(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(createRefString(natives[i].name)); Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0); func.type = LITERAL_FUNCTION_NATIVE; diff --git a/core/lib_standard.c b/core/lib_standard.c index 8061941..52f339e 100644 --- a/core/lib_standard.c +++ b/core/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(createRefString(natives[i].name)); Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0); func.type = LITERAL_FUNCTION_NATIVE; diff --git a/core/lib_timer.c b/core/lib_timer.c index efb2426..cd098c7 100644 --- a/core/lib_timer.c +++ b/core/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(createRefString(natives[i].name)); Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0); func.type = LITERAL_FUNCTION_NATIVE; diff --git a/core/makefile b/core/makefile index 838400f..63955e1 100644 --- a/core/makefile +++ b/core/makefile @@ -31,6 +31,7 @@ library: libs $(OBJ) static: libs $(OBJ) ar crs $(CORE_OUTDIR)/lib$(OUTNAME).a $(OBJ) -L../$(LIBDIR) $(LIBS) +#copy the stuff from Toy/repl that is needed libs: cp ../Toy/repl/lib* . cp ../Toy/repl/repl_tools.* . diff --git a/core/repl_tools.c b/core/repl_tools.c index b9bf20d..df3fd2c 100644 --- a/core/repl_tools.c +++ b/core/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); }