aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-15 04:36:47 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-15 04:36:47 +0100
commitd52d7ad413ffaf5d48fe57c082d823f6052cbc4a (patch)
tree2ddf4220e7468e727580db75eb7017e200d80aa6 /src
parent49a85a20d830fb197478ed6cd56f3f1554dba61b (diff)
downloadovm-d52d7ad413ffaf5d48fe57c082d823f6052cbc4a.tar.gz
ovm-d52d7ad413ffaf5d48fe57c082d823f6052cbc4a.tar.bz2
ovm-d52d7ad413ffaf5d48fe57c082d823f6052cbc4a.zip
Implemented a union type to make vm_push_* routines uniform
Function dispatch
Diffstat (limited to 'src')
-rw-r--r--src/main.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 30abda7..130dbfd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -35,20 +35,26 @@ typedef struct
} stack;
} vm_t;
-void vm_push_byte(vm_t *vm, byte b)
+typedef union
+{
+ byte as_byte;
+ word as_word;
+} data_t;
+
+void vm_push_byte(vm_t *vm, data_t b)
{
if (vm->stack.pointer >= VM_STACK_MAX)
return;
- vm->stack.data[vm->stack.pointer++] = b;
+ vm->stack.data[vm->stack.pointer++] = b.as_byte;
}
-void vm_push_word(vm_t *vm, word w)
+void vm_push_word(vm_t *vm, data_t w)
{
// NOTE: Relies on sizeof measuring in bytes
if (vm->stack.pointer + sizeof(w) >= VM_STACK_MAX)
return;
- memcpy(vm->stack.data + vm->stack.pointer, &w, sizeof(w));
- vm->stack.pointer += sizeof(w);
+ memcpy(vm->stack.data + vm->stack.pointer, &w.as_word, sizeof(w.as_word));
+ vm->stack.pointer += sizeof(w.as_word);
}
int main(void)