From 2de37b20e2904d09ff5337c8e0cc04c9fde5f38a Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 15 Oct 2023 05:39:19 +0100 Subject: Changed stack data to be a pointer I wouldn't really want this to be malloc'd per se, you could make a byte array on the stack then pass it into the VM? --- src/main.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 24589d2..df596a7 100644 --- a/src/main.c +++ b/src/main.c @@ -15,20 +15,18 @@ #include "./base.h" -#define VM_STACK_MAX 1024 - typedef struct { struct Stack { - byte data[VM_STACK_MAX]; - word ptr; + byte *data; + word ptr, size; } stack; } vm_t; void vm_push_byte(vm_t *vm, data_t b) { - if (vm->stack.ptr >= VM_STACK_MAX) + if (vm->stack.ptr >= vm->stack.size) // TODO: Error STACK_OVERFLOW return; vm->stack.data[vm->stack.ptr++] = b.as_byte; @@ -36,7 +34,7 @@ void vm_push_byte(vm_t *vm, data_t b) void vm_push_word(vm_t *vm, data_t w) { - if (vm->stack.ptr + WORD_SIZE >= VM_STACK_MAX) + if (vm->stack.ptr + WORD_SIZE >= vm->stack.size) // TODO: Error STACK_OVERFLOW return; // By default store in big endian @@ -51,7 +49,7 @@ void vm_push_word(vm_t *vm, data_t w) void vm_push_float(vm_t *vm, data_t f) { - if (vm->stack.ptr + FLOAT_SIZE >= VM_STACK_MAX) + if (vm->stack.ptr + FLOAT_SIZE >= vm->stack.size) // TODO: Error STACK_OVERFLOW return; // TODO: Make this machine independent (encode IEEE754 floats -- cgit v1.2.3-13-gbd6f