From cd19f1e1d30f52c073b6871c436e770ce2ffdda0 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 15 Oct 2023 22:16:31 +0100 Subject: Better checking of opcode types Introduced an enum (opcode_type_t) for the masks and values of each opcode, which allows defining a single enum which checks an opcode by a opcode_type_t. --- src/runtime.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/runtime.c') diff --git a/src/runtime.c b/src/runtime.c index b9870de..9d78b09 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -23,26 +23,26 @@ void vm_execute(vm_t *vm) return; inst_t instruction = prog->instructions[prog->ptr]; - if (OPCODE_IS_PUSH(instruction.opcode)) + if (OPCODE_IS_TYPE(instruction.opcode, OP_TYPE_PUSH)) { PUSH_ROUTINES[instruction.opcode](vm, instruction.operand); vm->registers.ret = instruction.operand.as_word; prog->ptr++; } - else if (OPCODE_IS_PUSH_REG(instruction.opcode)) + else if (OPCODE_IS_TYPE(instruction.opcode, OP_TYPE_PUSH_REGISTER)) { PUSH_REG_ROUTINES[instruction.opcode](vm, instruction.reg); vm->registers.ret = instruction.operand.as_word; prog->ptr++; } - else if (OPCODE_IS_POP(instruction.opcode)) + else if (OPCODE_IS_TYPE(instruction.opcode, OP_TYPE_POP)) { // NOTE: We use the `ret` register for the result of this pop data_t d = POP_ROUTINES[instruction.opcode](vm); vm->registers.ret = d.as_word; prog->ptr++; } - else if (OPCODE_IS_MOV(instruction.opcode)) + else if (OPCODE_IS_TYPE(instruction.opcode, OP_TYPE_MOV)) { MOV_ROUTINES[instruction.opcode](vm, instruction.operand, instruction.reg); vm->registers.ret = instruction.operand.as_word; -- cgit v1.2.3-13-gbd6f