function calls work

This commit is contained in:
2026-07-03 19:06:40 +10:00
parent cffcd87c06
commit d708e2e46f
2 changed files with 26 additions and 1 deletions

View File

@@ -705,7 +705,30 @@ struct GroundExecutionResult _GroundBytecodeInstructionExecute(GroundBytecodeIns
// make a copy of the current state and attach it to the function
GroundBytecodeFunction* function = &HEAP_GET(heap, instruction->args.at[0])->as.Function;
if (function->closure == NULL) {}
if (function->closure == NULL) {
function->closure = malloc(sizeof(GroundBytecodeHeap));
if (function->closure == NULL) {
Ground.Log.Error("malloc failed in Ground.Bytecode.Instruction.execute");
Ground.Flags.error = true;
return CONTINUE;
}
}
GroundBytecodeHeap newHeap = {
.capacity = heap->capacity,
.len = heap->len,
.heap = malloc(sizeof(GroundBytecodeValue) * heap->capacity)
};
if (newHeap.heap == NULL) {
Ground.Log.Error("malloc failed in Ground.Bytecode.Instruction.execute");
Ground.Flags.error = true;
return CONTINUE;
}
for (GroundSize i = 0; i < heap->len; i++) {
newHeap.heap[i] = Ground.Copy.BytecodeValue(&heap->heap[i]);
}
return CONTINUE;
}

View File

@@ -201,6 +201,8 @@ struct _Ground Ground = {
.State = _GroundCopyState,
.Identifier = _GroundCopyIdentifier,
.BytecodeValue = _GroundCopyBytecodeValue,
},
.List = {