mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Closures work
This commit is contained in:
@@ -823,7 +823,7 @@ static bool execFnCall(Interpreter* interpreter) {
|
||||
Literal ret = popLiteralArray(&returns);
|
||||
|
||||
//check the return types
|
||||
if (AS_TYPE(returnArray->literals[i]).typeOf != ret.type) {
|
||||
if (returnArray->count > 0 && AS_TYPE(returnArray->literals[i]).typeOf != ret.type) {
|
||||
printf(ERROR "ERROR: bad type found in return value\n" RESET);
|
||||
|
||||
//free, and skip out
|
||||
@@ -1066,7 +1066,6 @@ static void execInterpreter(Interpreter* interpreter) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void readInterpreterSections(Interpreter* interpreter) {
|
||||
//data section
|
||||
const short literalCount = readShort(interpreter->bytecode, &interpreter->count);
|
||||
|
||||
@@ -22,7 +22,7 @@ static void setEntryValues(_entry* entry, Literal key, Literal value) {
|
||||
else if (IS_IDENTIFIER(key)) {
|
||||
entry->key = TO_IDENTIFIER_LITERAL( copyString(AS_IDENTIFIER(key), STRLEN_I(key)) );
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
freeLiteral(entry->key); //for types
|
||||
entry->key = key;
|
||||
@@ -38,7 +38,18 @@ static void setEntryValues(_entry* entry, Literal key, Literal value) {
|
||||
buffer[STRLEN(value)] = '\0';
|
||||
entry->value = TO_STRING_LITERAL(buffer);
|
||||
}
|
||||
|
||||
|
||||
//OR take ownership of the copied function
|
||||
else if (IS_FUNCTION(value)) {
|
||||
unsigned char* buffer = ALLOCATE(unsigned char, value.as.function.length);
|
||||
memcpy(buffer, AS_FUNCTION(value), value.as.function.length);
|
||||
|
||||
entry->value = TO_FUNCTION_LITERAL(buffer, value.as.function.length);
|
||||
|
||||
//save the scope
|
||||
entry->value.as.function.scope = value.as.function.scope;
|
||||
}
|
||||
|
||||
else {
|
||||
entry->value = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user