From 2490966554a378af4a48b51d5e7eb717a570285a Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 15 Oct 2023 21:13:15 +0100 Subject: Implemented vm_execute for pop routines --- src/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index d2c003b..f431dd7 100644 --- a/src/main.c +++ b/src/main.c @@ -146,20 +146,26 @@ data_t vm_pop_float(vm_t *vm) } typedef void (*push_f)(vm_t *, data_t); -typedef void (*mov_f)(vm_t *, data_t, word); - static const push_f PUSH_ROUTINES[] = { [OP_PUSH_BYTE] = vm_push_byte, [OP_PUSH_WORD] = vm_push_word, [OP_PUSH_FLOAT] = vm_push_float, }; +typedef void (*mov_f)(vm_t *, data_t, word); static const mov_f MOV_ROUTINES[] = { [OP_MOV_BYTE] = vm_mov_byte, [OP_MOV_WORD] = vm_mov_word, [OP_MOV_FLOAT] = vm_mov_float, }; +typedef data_t (*pop_f)(vm_t *); +static const pop_f POP_ROUTINES[] = { + [OP_POP_BYTE] = vm_pop_byte, + [OP_POP_WORD] = vm_pop_word, + [OP_POP_FLOAT] = vm_pop_float, +}; + void vm_execute(vm_t *vm) { struct Program *prog = &vm->program; @@ -178,6 +184,13 @@ void vm_execute(vm_t *vm) MOV_ROUTINES[instruction.opcode](vm, instruction.operand, instruction.reg); prog->ptr++; } + else if (OPCODE_IS_POP(instruction.opcode)) + { + // TODO: Figure out what should happen to the result of this pop + // routine + POP_ROUTINES[instruction.opcode](vm); + prog->ptr++; + } else { // TODO: Error (Unknown opcode) -- cgit v1.2.3-13-gbd6f