progress on external functions
This commit is contained in:
@@ -300,6 +300,9 @@ struct GroundBytecodeFunction {
|
|||||||
GroundBytecodeHeap* closure;
|
GroundBytecodeHeap* closure;
|
||||||
|
|
||||||
GroundSize _requiredSize;
|
GroundSize _requiredSize;
|
||||||
|
|
||||||
|
// Only for native function
|
||||||
|
GroundType* returnType;
|
||||||
};
|
};
|
||||||
struct GroundBytecodeStruct {};
|
struct GroundBytecodeStruct {};
|
||||||
struct GroundBytecodeObject {};
|
struct GroundBytecodeObject {};
|
||||||
|
|||||||
@@ -82,14 +82,12 @@ struct GroundExecutionResult _GroundBytecodeInstructionExecute(GroundBytecodeIns
|
|||||||
PRINT: {
|
PRINT: {
|
||||||
for (GroundSize i = 0; i < instruction->args.len; i++) {
|
for (GroundSize i = 0; i < instruction->args.len; i++) {
|
||||||
printValue(HEAP_GET(heap, instruction->args.at[i]));
|
printValue(HEAP_GET(heap, instruction->args.at[i]));
|
||||||
printf(" ");
|
|
||||||
}
|
}
|
||||||
return CONTINUE;
|
return CONTINUE;
|
||||||
}
|
}
|
||||||
PRINTLN: {
|
PRINTLN: {
|
||||||
for (GroundSize i = 0; i < instruction->args.len; i++) {
|
for (GroundSize i = 0; i < instruction->args.len; i++) {
|
||||||
printValue(HEAP_GET(heap, instruction->args.at[i]));
|
printValue(HEAP_GET(heap, instruction->args.at[i]));
|
||||||
printf(" ");
|
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
return CONTINUE;
|
return CONTINUE;
|
||||||
@@ -835,21 +833,64 @@ struct GroundExecutionResult _GroundBytecodeInstructionExecute(GroundBytecodeIns
|
|||||||
GroundBytecodeFunction bf = {
|
GroundBytecodeFunction bf = {
|
||||||
.isNativeFunction = true,
|
.isNativeFunction = true,
|
||||||
.closure = NULL,
|
.closure = NULL,
|
||||||
.program.native = handle,
|
.program.native = function,
|
||||||
.args = {
|
.args = {
|
||||||
.at = malloc(sizeof(GroundFunctionArg) * argsSize),
|
.at = malloc(sizeof(GroundFunctionArg) * argsSize),
|
||||||
.capacity = argsSize,
|
.capacity = argsSize,
|
||||||
.count = 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.Log.Error("malloc failed in Ground.Bytecode.Instruction.execute");
|
||||||
Ground.Flags.error = true;
|
Ground.Flags.error = true;
|
||||||
return CONTINUE;
|
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;
|
return CONTINUE;
|
||||||
}
|
}
|
||||||
CREATELABEL: {
|
CREATELABEL: {
|
||||||
|
|||||||
Reference in New Issue
Block a user