Updated Toy to 0.6.3

This commit is contained in:
2022-11-26 16:03:56 +00:00
parent da9afb7e5b
commit 5231572578
9 changed files with 22 additions and 21 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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.* .

View File

@@ -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);
}