progress on external functions
This commit is contained in:
@@ -82,14 +82,12 @@ struct GroundExecutionResult _GroundBytecodeInstructionExecute(GroundBytecodeIns
|
||||
PRINT: {
|
||||
for (GroundSize i = 0; i < instruction->args.len; i++) {
|
||||
printValue(HEAP_GET(heap, instruction->args.at[i]));
|
||||
printf(" ");
|
||||
}
|
||||
return CONTINUE;
|
||||
}
|
||||
PRINTLN: {
|
||||
for (GroundSize i = 0; i < instruction->args.len; i++) {
|
||||
printValue(HEAP_GET(heap, instruction->args.at[i]));
|
||||
printf(" ");
|
||||
}
|
||||
printf("\n");
|
||||
return CONTINUE;
|
||||
@@ -835,21 +833,64 @@ struct GroundExecutionResult _GroundBytecodeInstructionExecute(GroundBytecodeIns
|
||||
GroundBytecodeFunction bf = {
|
||||
.isNativeFunction = true,
|
||||
.closure = NULL,
|
||||
.program.native = handle,
|
||||
.program.native = function,
|
||||
.args = {
|
||||
.at = malloc(sizeof(GroundFunctionArg) * argsSize),
|
||||
.capacity = argsSize,
|
||||
.count = argsSize
|
||||
},
|
||||
.returnType = malloc(sizeof(GroundType))
|
||||
};
|
||||
if (bf.args.at == NULL) {
|
||||
if (bf.args.at == NULL || bf.returnType == NULL) {
|
||||
Ground.Log.Error("malloc failed in Ground.Bytecode.Instruction.execute");
|
||||
Ground.Flags.error = true;
|
||||
return CONTINUE;
|
||||
}
|
||||
for (size_t i = 0; i < argsSize; i++) {
|
||||
|
||||
enum GroundTypeType returnTypeType = HEAP_GET(heap, instruction->args.at[3])->type.type;
|
||||
|
||||
switch (returnTypeType) {
|
||||
case GroundType_Struct: {
|
||||
bf.returnType->type = GroundType_Object;
|
||||
// TODO implement structs
|
||||
break;
|
||||
}
|
||||
case GroundType_CoreType: {
|
||||
bf.returnType->type = HEAP_GET(heap, instruction->args.at[3])->as.CoreType;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// should have been caught elsewhere, not really our problem
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < argsSize; i++) {
|
||||
enum GroundTypeType argTypeType = HEAP_GET(heap, instruction->args.at[i + 4])->as.CoreType;
|
||||
switch (argTypeType) {
|
||||
case GroundType_Struct: {
|
||||
bf.args.at[i].as.type.type = GroundType_Object;
|
||||
// TODO implement structs
|
||||
break;
|
||||
}
|
||||
case GroundType_CoreType: {
|
||||
bf.args.at[i].as.type.type = HEAP_GET(heap, instruction->args.at[3])->as.CoreType;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// should have been caught elsewhere, not really our problem
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GroundBytecodeValue val = {
|
||||
.type = {GroundType_Function},
|
||||
.as.Function = bf
|
||||
};
|
||||
|
||||
HEAP_SET(heap, instruction->args.at[3], val);
|
||||
|
||||
return CONTINUE;
|
||||
}
|
||||
CREATELABEL: {
|
||||
|
||||
Reference in New Issue
Block a user