diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-15 04:35:07 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-15 04:35:07 +0100 |
commit | 49a85a20d830fb197478ed6cd56f3f1554dba61b (patch) | |
tree | 72034e73154b55d40daa76905c97a57023e3217a /src/main.c | |
parent | 1101716f0f1461b5fc1115a55c3b5bb7e06cf133 (diff) | |
download | ovm-49a85a20d830fb197478ed6cd56f3f1554dba61b.tar.gz ovm-49a85a20d830fb197478ed6cd56f3f1554dba61b.tar.bz2 ovm-49a85a20d830fb197478ed6cd56f3f1554dba61b.zip |
Added functions to push a byte and a word
Maybe I should make a union for the type, so I can dispatch via
function pointers?
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -12,6 +12,7 @@ #include <stdint.h> #include <stdio.h> +#include <string.h> typedef uint64_t u64; typedef uint32_t u32; @@ -34,6 +35,22 @@ typedef struct } stack; } vm_t; +void vm_push_byte(vm_t *vm, byte b) +{ + if (vm->stack.pointer >= VM_STACK_MAX) + return; + vm->stack.data[vm->stack.pointer++] = b; +} + +void vm_push_word(vm_t *vm, word 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); +} + int main(void) { puts("Hello, world!"); |