diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-01 17:49:33 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-01 17:49:33 +0000 |
commit | 7a1129d80f6903db6e6a919bdeae403f924d69f6 (patch) | |
tree | 09410d90faae04bcd1aa4656e3d6b6bb9fee2118 /vm/runtime.h | |
parent | 89fd2b0d17da72aec688946e89eeae4bf196e419 (diff) | |
download | ovm-7a1129d80f6903db6e6a919bdeae403f924d69f6.tar.gz ovm-7a1129d80f6903db6e6a919bdeae403f924d69f6.tar.bz2 ovm-7a1129d80f6903db6e6a919bdeae403f924d69f6.zip |
VM registers are now a dynamic array
Stack based machines generally need "variable space". This may be
quite via a symbol-to-word association a list, a hashmap, or some
other system. Here I decide to go for the simplest: extending the
register system to a dynamic/infinite number of them. This means, in
practice, that we may use a theoretically infinite number of indexed
words, hwords and bytes to act as variable space. This means that the
onus is on those who are targeting this virtual machine to create
their own association system to create syntactic variables: all the
machinery is technically installed within the VM, without the veneer
that causes extra cruft.
Diffstat (limited to 'vm/runtime.h')
-rw-r--r-- | vm/runtime.h | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/vm/runtime.h b/vm/runtime.h index be907b3..1226ea9 100644 --- a/vm/runtime.h +++ b/vm/runtime.h @@ -33,13 +33,13 @@ typedef enum const char *err_as_cstr(err_t); -#define VM_REGISTERS 8 +typedef darr_t registers_t; +#define VM_NTH_REGISTER(REGISTERS, N) (((word *)((REGISTERS).data))[N]) +#define VM_REGISTERS_AVAILABLE(REGISTERS) (((REGISTERS).available) / WORD_SIZE) + typedef struct { - struct Registers - { - word reg[VM_REGISTERS]; - } registers; + registers_t registers; struct Stack { byte *data; @@ -57,6 +57,7 @@ err_t vm_execute_all(vm_t *); void vm_load_stack(vm_t *, byte *, size_t); void vm_load_program(vm_t *, inst_t *, size_t); +void vm_load_registers(vm_t *, registers_t); // Print routines #define VM_PRINT_PROGRAM_EXCERPT 5 @@ -83,15 +84,15 @@ static const push_f PUSH_ROUTINES[] = { [OP_PUSH_WORD] = vm_push_word, }; -err_t vm_push_byte_register(vm_t *, byte); -err_t vm_push_hword_register(vm_t *, byte); -err_t vm_push_word_register(vm_t *, byte); +err_t vm_push_byte_register(vm_t *, word); +err_t vm_push_hword_register(vm_t *, word); +err_t vm_push_word_register(vm_t *, word); -err_t vm_mov_byte(vm_t *, byte); -err_t vm_mov_hword(vm_t *, byte); -err_t vm_mov_word(vm_t *, byte); +err_t vm_mov_byte(vm_t *, word); +err_t vm_mov_hword(vm_t *, word); +err_t vm_mov_word(vm_t *, word); -typedef err_t (*reg_f)(vm_t *, byte); +typedef err_t (*reg_f)(vm_t *, word); static const reg_f REG_ROUTINES[] = { [OP_PUSH_REGISTER_BYTE] = vm_push_byte_register, [OP_PUSH_REGISTER_HWORD] = vm_push_hword_register, |