aboutsummaryrefslogtreecommitdiff
path: root/vm
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 17:52:15 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 17:52:15 +0000
commit90d901345abcbb271653fbee6749a2b3273fb62e (patch)
treee69feda86a5adc2660e4daf7c73a8507761e0b6a /vm
parent7a1129d80f6903db6e6a919bdeae403f924d69f6 (diff)
downloadovm-90d901345abcbb271653fbee6749a2b3273fb62e.tar.gz
ovm-90d901345abcbb271653fbee6749a2b3273fb62e.tar.bz2
ovm-90d901345abcbb271653fbee6749a2b3273fb62e.zip
Added a routine to cleanup resources allocated to the VM
This means the stack should be heap allocated, which makes sense as beyond 1KB one should really be using the heap rather than the stack.
Diffstat (limited to 'vm')
-rw-r--r--vm/runtime.c7
-rw-r--r--vm/runtime.h1
2 files changed, 8 insertions, 0 deletions
diff --git a/vm/runtime.c b/vm/runtime.c
index 240ba6f..3279354 100644
--- a/vm/runtime.c
+++ b/vm/runtime.c
@@ -325,6 +325,13 @@ void vm_load_registers(vm_t *vm, registers_t registers)
vm->registers = registers;
}
+void vm_stop(vm_t *vm)
+{
+ free(vm->registers.data);
+ free(vm->program.instructions);
+ free(vm->stack.data);
+}
+
void vm_print_registers(vm_t *vm, FILE *fp)
{
registers_t reg = vm->registers;
diff --git a/vm/runtime.h b/vm/runtime.h
index 1226ea9..9dd639e 100644
--- a/vm/runtime.h
+++ b/vm/runtime.h
@@ -58,6 +58,7 @@ 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_stop(vm_t *);
// Print routines
#define VM_PRINT_PROGRAM_EXCERPT 5