Hooked runner's drive system into the engine paths

This commit is contained in:
2023-01-27 06:24:31 +00:00
parent 894861aaf1
commit fcefc4c5b0
8 changed files with 166 additions and 114 deletions

View File

@@ -8,6 +8,8 @@
#include "toy_console_colors.h"
#include "lib_runner.h"
//errors here should be fatal
static void fatalError(char* message) {
fprintf(stderr, TOY_CC_ERROR "%s" TOY_CC_RESET, message);
@@ -84,17 +86,26 @@ static int nativeLoadRootNode(Toy_Interpreter* interpreter, Toy_LiteralArray* ar
}
//extract the arguments
Toy_Literal fname = Toy_popLiteralArray(arguments);
Toy_Literal drivePathLiteral = Toy_popLiteralArray(arguments);
Toy_Literal fnameIdn = fname;
if (TOY_IS_IDENTIFIER(fname) && Toy_parseIdentifierToValue(interpreter, &fname)) {
Toy_freeLiteral(fnameIdn);
Toy_Literal drivePathLiteralIdn = drivePathLiteral;
if (TOY_IS_IDENTIFIER(drivePathLiteral) && Toy_parseIdentifierToValue(interpreter, &drivePathLiteral)) {
Toy_freeLiteral(drivePathLiteralIdn);
}
//check argument types
if (!TOY_IS_STRING(fname)) {
if (!TOY_IS_STRING(drivePathLiteral)) {
interpreter->errorOutput("Incorrect argument type passed to loadRootNode\n");
Toy_freeLiteral(fname);
Toy_freeLiteral(drivePathLiteral);
return -1;
}
Toy_Literal filePathLiteral = Toy_getFilePathLiteral(interpreter, &drivePathLiteral);
Toy_freeLiteral(drivePathLiteral); //not needed anymore
if (!TOY_IS_STRING(filePathLiteral)) {
Toy_freeLiteral(filePathLiteral);
return -1;
}
@@ -110,7 +121,7 @@ static int nativeLoadRootNode(Toy_Interpreter* interpreter, Toy_LiteralArray* ar
//load the new root node
size_t size = 0;
char* source = Toy_readFile(Toy_toCString(TOY_AS_STRING(fname)), &size);
char* source = Toy_readFile(Toy_toCString(TOY_AS_STRING(filePathLiteral)), &size);
unsigned char* tb = Toy_compileString(source, &size);
free((void*)source);
@@ -142,7 +153,7 @@ static int nativeLoadRootNode(Toy_Interpreter* interpreter, Toy_LiteralArray* ar
//cleanup
Toy_freeLiteralArray(&inner.stack);
Toy_freeLiteralArray(&inner.literalCache);
Toy_freeLiteral(fname);
Toy_freeLiteral(filePathLiteral);
return 0;
}