aboutsummaryrefslogtreecommitdiff
path: root/vm/runtime.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 22:08:06 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 22:08:06 +0000
commit90ee9b492db7bf2f8efcf07c30faa719aecec920 (patch)
tree479cf5323250f62f53e5e0369d8e50314436f618 /vm/runtime.c
parent0649b3f3804fa1b8924eed9214f33bce6a2c06e8 (diff)
downloadovm-90ee9b492db7bf2f8efcf07c30faa719aecec920.tar.gz
ovm-90ee9b492db7bf2f8efcf07c30faa719aecec920.tar.bz2
ovm-90ee9b492db7bf2f8efcf07c30faa719aecec920.zip
Implemented MGET_STACK and MSET_STACK in the runtime
Very easy, they just pop a word then defer to their normal versions. This is probably the best case where a macro works directly so I didn't even need to write a function form for them first. One thing is that then names for the macros are quite bad right now, probably need renaming.
Diffstat (limited to 'vm/runtime.c')
-rw-r--r--vm/runtime.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/vm/runtime.c b/vm/runtime.c
index 67c288c..4c4d9ff 100644
--- a/vm/runtime.c
+++ b/vm/runtime.c
@@ -60,7 +60,7 @@ const char *err_as_cstr(err_t err)
err_t vm_execute(vm_t *vm)
{
- static_assert(NUMBER_OF_OPCODES == 84, "vm_execute: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 90, "vm_execute: Out of date");
struct Program *prog = &vm->program;
if (prog->ptr >= prog->max)
return ERR_END_OF_PROGRAM;
@@ -113,6 +113,8 @@ err_t vm_execute(vm_t *vm)
OPCODE_IS_TYPE(instruction.opcode, OP_GTE) ||
OPCODE_IS_TYPE(instruction.opcode, OP_PLUS) ||
OPCODE_IS_TYPE(instruction.opcode, OP_MULT) ||
+ OPCODE_IS_TYPE(instruction.opcode, OP_MSET_STACK) ||
+ OPCODE_IS_TYPE(instruction.opcode, OP_MGET_STACK) ||
instruction.opcode == OP_MDELETE || instruction.opcode == OP_MSIZE)
{
prog->ptr++;
@@ -804,6 +806,23 @@ err_t vm_pop_word(vm_t *vm, data_t *ret)
return ERR_OK;
}
+#define VM_MEMORY_STACK_CONSTR(ACTION, TYPE) \
+ err_t vm_##ACTION##_stack_##TYPE(vm_t *vm) \
+ { \
+ data_t n = {0}; \
+ err_t err = vm_pop_word(vm, &n); \
+ if (err) \
+ return err; \
+ return vm_##ACTION##_##TYPE(vm, n.as_word); \
+ }
+
+VM_MEMORY_STACK_CONSTR(mset, byte)
+VM_MEMORY_STACK_CONSTR(mset, hword)
+VM_MEMORY_STACK_CONSTR(mset, word)
+VM_MEMORY_STACK_CONSTR(mget, byte)
+VM_MEMORY_STACK_CONSTR(mget, hword)
+VM_MEMORY_STACK_CONSTR(mget, word)
+
err_t vm_mdelete(vm_t *vm)
{
data_t ptr = {0};