From da1c4aad3513ed602dd0fcac7fa2002eff70ed7d Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 15 Oct 2023 05:33:42 +0100 Subject: Changed stack.pointer->stack.ptr --- src/main.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 3abc801..09677b4 100644 --- a/src/main.c +++ b/src/main.c @@ -45,21 +45,21 @@ typedef struct struct Stack { byte data[VM_STACK_MAX]; - word pointer; + word ptr; } stack; } vm_t; void vm_push_byte(vm_t *vm, data_t b) { - if (vm->stack.pointer >= VM_STACK_MAX) + if (vm->stack.ptr >= VM_STACK_MAX) // TODO: Error STACK_OVERFLOW return; - vm->stack.data[vm->stack.pointer++] = b.as_byte; + vm->stack.data[vm->stack.ptr++] = b.as_byte; } void vm_push_word(vm_t *vm, data_t w) { - if (vm->stack.pointer + WORD_SIZE >= VM_STACK_MAX) + if (vm->stack.ptr + WORD_SIZE >= VM_STACK_MAX) // TODO: Error STACK_OVERFLOW return; // By default store in big endian @@ -74,26 +74,26 @@ void vm_push_word(vm_t *vm, data_t w) void vm_push_float(vm_t *vm, data_t f) { - if (vm->stack.pointer + FLOAT_SIZE >= VM_STACK_MAX) + if (vm->stack.ptr + FLOAT_SIZE >= VM_STACK_MAX) // TODO: Error STACK_OVERFLOW return; // TODO: Make this machine independent (encode IEEE754 floats // yourself?) - memcpy(vm->stack.data + vm->stack.pointer, &f.as_float, FLOAT_SIZE); - vm->stack.pointer += FLOAT_SIZE; + memcpy(vm->stack.data + vm->stack.ptr, &f.as_float, FLOAT_SIZE); + vm->stack.ptr += FLOAT_SIZE; } byte vm_pop_byte(vm_t *vm) { - if (vm->stack.pointer == 0) + if (vm->stack.ptr == 0) // TODO: Error STACK_UNDERFLOW return 0; - return vm->stack.data[--vm->stack.pointer]; + return vm->stack.data[--vm->stack.ptr]; } word vm_pop_word(vm_t *vm) { - if (vm->stack.pointer < WORD_SIZE) + if (vm->stack.ptr < WORD_SIZE) // TODO: Error STACK_UNDERFLOW return 0; word w = 0; @@ -108,14 +108,14 @@ word vm_pop_word(vm_t *vm) f64 vm_pop_float(vm_t *vm) { - if (vm->stack.pointer < FLOAT_SIZE) + if (vm->stack.ptr < FLOAT_SIZE) // TODO: Error STACK_UNDERFLOW return 0; f64 f = 0; // TODO: Make this machine independent (encode IEEE754 floats // yourself?) - memcpy(&f, vm->stack.data + vm->stack.pointer - FLOAT_SIZE, FLOAT_SIZE); - vm->stack.pointer -= FLOAT_SIZE; + memcpy(&f, vm->stack.data + vm->stack.ptr - FLOAT_SIZE, FLOAT_SIZE); + vm->stack.ptr -= FLOAT_SIZE; return f; } -- cgit v1.2.3-13-gbd6f