diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-15 05:39:19 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-15 05:39:19 +0100 |
commit | 2de37b20e2904d09ff5337c8e0cc04c9fde5f38a (patch) | |
tree | d7d1b576c096247fecd7fca0993ec75b697096d6 /src | |
parent | a8747faa08a06aa6f4a0a14af73732bbcb82d84d (diff) | |
download | ovm-2de37b20e2904d09ff5337c8e0cc04c9fde5f38a.tar.gz ovm-2de37b20e2904d09ff5337c8e0cc04c9fde5f38a.tar.bz2 ovm-2de37b20e2904d09ff5337c8e0cc04c9fde5f38a.zip |
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?
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -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 |