aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 17:56:22 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 17:56:22 +0000
commitc244e7c4a4d8a069d5ebae523880aa4356b0ff07 (patch)
tree85916a127ec90d5f6b77be4d683976581fee18a8
parent57e692327963dabac9a1fcfda25548644a3a56cf (diff)
downloadovm-c244e7c4a4d8a069d5ebae523880aa4356b0ff07.tar.gz
ovm-c244e7c4a4d8a069d5ebae523880aa4356b0ff07.tar.bz2
ovm-c244e7c4a4d8a069d5ebae523880aa4356b0ff07.zip
Use vm_stop and vm_load_registers
By default I initialise the registers with 8 words, though this may not be necessary for your purposes.
-rw-r--r--vm/main.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/vm/main.c b/vm/main.c
index faf4299..75549fd 100644
--- a/vm/main.c
+++ b/vm/main.c
@@ -51,10 +51,14 @@ int main(int argc, char *argv[])
TERM_RESET, number);
#endif
- byte stack[256];
+ size_t stack_size = 256;
+ byte *stack = calloc(stack_size, 1);
+ registers_t registers = {0};
+ darr_init(&registers, 8 * WORD_SIZE);
vm_t vm = {0};
- vm_load_stack(&vm, stack, ARR_SIZE(stack));
+ vm_load_stack(&vm, stack, stack_size);
vm_load_program(&vm, instructions, number);
+ vm_load_registers(&vm, registers);
#if VERBOSE >= 1
printf("\t[%sVM-SETUP%s]: Loaded stack and program into VM\n", TERM_GREEN,
@@ -70,7 +74,7 @@ int main(int argc, char *argv[])
vm_print_all(&vm, stderr);
ret = 255 - err;
}
- free(instructions);
+ vm_stop(&vm);
#if VERBOSE >= 1
printf("[%sINTERPRETER%s]: Finished execution\n", TERM_GREEN, TERM_RESET);