diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -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; } |