aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vm/main.c4
-rw-r--r--vm/runtime.c11
-rw-r--r--vm/runtime.h5
3 files changed, 19 insertions, 1 deletions
diff --git a/vm/main.c b/vm/main.c
index 75549fd..cb2c3fb 100644
--- a/vm/main.c
+++ b/vm/main.c
@@ -55,10 +55,14 @@ int main(int argc, char *argv[])
byte *stack = calloc(stack_size, 1);
registers_t registers = {0};
darr_init(&registers, 8 * WORD_SIZE);
+ heap_t heap = {0};
+ heap_create(&heap);
+
vm_t vm = {0};
vm_load_stack(&vm, stack, stack_size);
vm_load_program(&vm, instructions, number);
vm_load_registers(&vm, registers);
+ vm_load_heap(&vm, heap);
#if VERBOSE >= 1
printf("\t[%sVM-SETUP%s]: Loaded stack and program into VM\n", TERM_GREEN,
diff --git a/vm/runtime.c b/vm/runtime.c
index 622228f..0fbea05 100644
--- a/vm/runtime.c
+++ b/vm/runtime.c
@@ -326,11 +326,22 @@ void vm_load_registers(vm_t *vm, registers_t registers)
vm->registers = registers;
}
+void vm_load_heap(vm_t *vm, heap_t heap)
+{
+ vm->heap = heap;
+}
+
void vm_stop(vm_t *vm)
{
free(vm->registers.data);
free(vm->program.instructions);
free(vm->stack.data);
+ heap_stop(&vm->heap);
+
+ vm->registers = (registers_t){0};
+ vm->program = (struct Program){0};
+ vm->stack = (struct Stack){0};
+ vm->heap = (heap_t){0};
}
void vm_print_registers(vm_t *vm, FILE *fp)
diff --git a/vm/runtime.h b/vm/runtime.h
index 45d467d..6c6042a 100644
--- a/vm/runtime.h
+++ b/vm/runtime.h
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <lib/heap.h>
#include <lib/inst.h>
typedef enum
@@ -45,6 +46,7 @@ typedef struct
byte *data;
word ptr, max;
} stack;
+ heap_t heap;
struct Program
{
inst_t *instructions;
@@ -56,8 +58,9 @@ err_t vm_execute(vm_t *);
err_t vm_execute_all(vm_t *);
void vm_load_stack(vm_t *, byte *, size_t);
-void vm_load_program(vm_t *, inst_t *, size_t);
void vm_load_registers(vm_t *, registers_t);
+void vm_load_heap(vm_t *, heap_t);
+void vm_load_program(vm_t *, inst_t *, size_t);
void vm_stop(vm_t *);
// Print routines