aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-15 05:33:42 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-15 05:33:42 +0100
commitda1c4aad3513ed602dd0fcac7fa2002eff70ed7d (patch)
tree5eff7e698a235d45215b3ca076ba61b89c7fb5de /src
parent268fdf0ca06238e4c450e01ad014c4ac7151180c (diff)
downloadovm-da1c4aad3513ed602dd0fcac7fa2002eff70ed7d.tar.gz
ovm-da1c4aad3513ed602dd0fcac7fa2002eff70ed7d.tar.bz2
ovm-da1c4aad3513ed602dd0fcac7fa2002eff70ed7d.zip
Changed stack.pointer->stack.ptr
Diffstat (limited to 'src')
-rw-r--r--src/main.c26
1 files changed, 13 insertions, 13 deletions
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;
}