Updated Toy to 0.6.3
This commit is contained in:
2
Toy
2
Toy
Submodule Toy updated: 7bf18a744c...fb55f42d0e
@@ -137,7 +137,7 @@ Literal callEngineNodeLiteral(EngineNode* node, Interpreter* interpreter, Litera
|
|||||||
|
|
||||||
Literal callEngineNode(EngineNode* node, Interpreter* interpreter, char* fnName, LiteralArray* args) {
|
Literal callEngineNode(EngineNode* node, Interpreter* interpreter, char* fnName, LiteralArray* args) {
|
||||||
//call "fnName" on this node, and all children, if it exists
|
//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);
|
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) {
|
void callRecursiveEngineNode(EngineNode* node, Interpreter* interpreter, char* fnName, LiteralArray* args) {
|
||||||
//call "fnName" on this node, and all children, if it exists
|
//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);
|
callRecursiveEngineNodeLiteral(node, interpreter, key, args);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ static int nativeInitWindow(Interpreter* interpreter, LiteralArray* arguments) {
|
|||||||
|
|
||||||
//init the window
|
//init the window
|
||||||
engine.window = SDL_CreateWindow(
|
engine.window = SDL_CreateWindow(
|
||||||
AS_STRING(caption),
|
toCString(AS_STRING(caption)),
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
SDL_WINDOWPOS_UNDEFINED,
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
SDL_WINDOWPOS_UNDEFINED,
|
||||||
engine.screenWidth = AS_INTEGER(screenWidth),
|
engine.screenWidth = AS_INTEGER(screenWidth),
|
||||||
@@ -108,7 +108,7 @@ static int nativeLoadRootNode(Interpreter* interpreter, LiteralArray* arguments)
|
|||||||
|
|
||||||
//load the new root node
|
//load the new root node
|
||||||
size_t size = 0;
|
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);
|
unsigned char* tb = compileString(source, &size);
|
||||||
free((void*)source);
|
free((void*)source);
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ int hookEngine(Interpreter* interpreter, Literal identifier, Literal alias) {
|
|||||||
|
|
||||||
//load the dict with functions
|
//load the dict with functions
|
||||||
for (int i = 0; natives[i].name; i++) {
|
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);
|
Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0);
|
||||||
func.type = LITERAL_FUNCTION_NATIVE;
|
func.type = LITERAL_FUNCTION_NATIVE;
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ static int nativeMapInputEventToKey(Interpreter* interpreter, LiteralArray* argu
|
|||||||
}
|
}
|
||||||
|
|
||||||
//use the keycode for faster lookups
|
//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) {
|
if (keycode == SDLK_UNKNOWN) {
|
||||||
interpreter->errorOutput("Unknown key found: ");
|
interpreter->errorOutput("Unknown key found: ");
|
||||||
@@ -94,7 +94,7 @@ int hookInput(Interpreter* interpreter, Literal identifier, Literal alias) {
|
|||||||
|
|
||||||
//load the dict with functions
|
//load the dict with functions
|
||||||
for (int i = 0; natives[i].name; i++) {
|
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);
|
Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0);
|
||||||
func.type = LITERAL_FUNCTION_NATIVE;
|
func.type = LITERAL_FUNCTION_NATIVE;
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ static int nativeLoadNode(Interpreter* interpreter, LiteralArray* arguments) {
|
|||||||
|
|
||||||
//load the new node
|
//load the new node
|
||||||
size_t size = 0;
|
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);
|
unsigned char* tb = compileString(source, &size);
|
||||||
free((void*)source);
|
free((void*)source);
|
||||||
|
|
||||||
@@ -311,7 +311,7 @@ static int nativeLoadTexture(Interpreter* interpreter, LiteralArray* arguments)
|
|||||||
freeTextureEngineNode(node);
|
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");
|
interpreter->errorOutput("Failed to load the texture into the EngineNode\n");
|
||||||
freeLiteral(fname);
|
freeLiteral(fname);
|
||||||
freeLiteral(nodeLiteral);
|
freeLiteral(nodeLiteral);
|
||||||
@@ -588,8 +588,8 @@ static int nativeCallNode(Interpreter* interpreter, LiteralArray* arguments) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* strptr = AS_STRING(fnName);
|
//allow refstring to do it's magic
|
||||||
Literal fnNameIdentifier = TO_IDENTIFIER_LITERAL(copyString(strptr, strlen(strptr)), strlen(strptr));
|
Literal fnNameIdentifier = TO_IDENTIFIER_LITERAL(copyRefString(AS_STRING(fnName)));
|
||||||
|
|
||||||
//call the function
|
//call the function
|
||||||
Literal result = callEngineNodeLiteral(AS_OPAQUE(nodeLiteral), interpreter, fnNameIdentifier, &extraArgs);
|
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
|
//load the dict with functions
|
||||||
for (int i = 0; natives[i].name; i++) {
|
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);
|
Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0);
|
||||||
func.type = LITERAL_FUNCTION_NATIVE;
|
func.type = LITERAL_FUNCTION_NATIVE;
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ static int nativeClock(Interpreter* interpreter, LiteralArray* arguments) {
|
|||||||
|
|
||||||
//push to the stack
|
//push to the stack
|
||||||
int len = strlen(timestr) - 1; //-1 for the newline
|
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
|
//push to the stack
|
||||||
pushLiteralArray(&interpreter->stack, timeLiteral);
|
pushLiteralArray(&interpreter->stack, timeLiteral);
|
||||||
@@ -57,7 +57,7 @@ int hookStandard(Interpreter* interpreter, Literal identifier, Literal alias) {
|
|||||||
|
|
||||||
//load the dict with functions
|
//load the dict with functions
|
||||||
for (int i = 0; natives[i].name; i++) {
|
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);
|
Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0);
|
||||||
func.type = LITERAL_FUNCTION_NATIVE;
|
func.type = LITERAL_FUNCTION_NATIVE;
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
if (timer->tv_sec == 0 && timer->tv_usec < 0) { //special case, for when the negative sign is encoded in the usec
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
snprintf(buffer, 128, "-%ld.%06ld", timer->tv_sec, -timer->tv_usec);
|
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
|
else { //normal case
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
snprintf(buffer, 128, "%ld.%06ld", timer->tv_sec, timer->tv_usec);
|
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);
|
pushLiteralArray(&interpreter->stack, resultLiteral);
|
||||||
@@ -374,7 +374,7 @@ int hookTimer(Interpreter* interpreter, Literal identifier, Literal alias) {
|
|||||||
|
|
||||||
//load the dict with functions
|
//load the dict with functions
|
||||||
for (int i = 0; natives[i].name; i++) {
|
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);
|
Literal func = TO_FUNCTION_LITERAL((void*)natives[i].fn, 0);
|
||||||
func.type = LITERAL_FUNCTION_NATIVE;
|
func.type = LITERAL_FUNCTION_NATIVE;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ library: libs $(OBJ)
|
|||||||
static: libs $(OBJ)
|
static: libs $(OBJ)
|
||||||
ar crs $(CORE_OUTDIR)/lib$(OUTNAME).a $(OBJ) -L../$(LIBDIR) $(LIBS)
|
ar crs $(CORE_OUTDIR)/lib$(OUTNAME).a $(OBJ) -L../$(LIBDIR) $(LIBS)
|
||||||
|
|
||||||
|
#copy the stuff from Toy/repl that is needed
|
||||||
libs:
|
libs:
|
||||||
cp ../Toy/repl/lib* .
|
cp ../Toy/repl/lib* .
|
||||||
cp ../Toy/repl/repl_tools.* .
|
cp ../Toy/repl/repl_tools.* .
|
||||||
|
|||||||
@@ -78,16 +78,16 @@ unsigned char* compileString(char* source, size_t* size) {
|
|||||||
ASTNode* node = scanParser(&parser);
|
ASTNode* node = scanParser(&parser);
|
||||||
while(node != NULL) {
|
while(node != NULL) {
|
||||||
//pack up and leave
|
//pack up and leave
|
||||||
if (node->type == AST_NODEERROR) {
|
if (node->type == AST_NODE_ERROR) {
|
||||||
printf(ERROR "error node detected\n" RESET);
|
printf(ERROR "error node detected\n" RESET);
|
||||||
freeNode(node);
|
freeASTNode(node);
|
||||||
freeCompiler(&compiler);
|
freeCompiler(&compiler);
|
||||||
freeParser(&parser);
|
freeParser(&parser);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeCompiler(&compiler, node);
|
writeCompiler(&compiler, node);
|
||||||
freeNode(node);
|
freeASTNode(node);
|
||||||
node = scanParser(&parser);
|
node = scanParser(&parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user