From d708e2e46f752669d52dca383f60097f609ee528 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Fri, 3 Jul 2026 19:06:40 +1000 Subject: [PATCH] function calls work --- src/Bytecode/Instruction/execute.c | 25 ++++++++++++++++++++++++- src/libmain.c | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Bytecode/Instruction/execute.c b/src/Bytecode/Instruction/execute.c index 3aad2ec..cb62b27 100644 --- a/src/Bytecode/Instruction/execute.c +++ b/src/Bytecode/Instruction/execute.c @@ -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; } diff --git a/src/libmain.c b/src/libmain.c index 73eb3e6..5437172 100644 --- a/src/libmain.c +++ b/src/libmain.c @@ -201,6 +201,8 @@ struct _Ground Ground = { .State = _GroundCopyState, .Identifier = _GroundCopyIdentifier, + + .BytecodeValue = _GroundCopyBytecodeValue, }, .List = {