Simplify OP_JUMP_IF implementation

Same method as when simplifying OP_POP's implementation: use the
lookup table along with OPCODE_DATA_TYPE abuse.  In this case I made a
lookup table called OP_POP for this method to work, but it wasn't difficult.
This commit is contained in:
2024-04-25 03:01:59 +05:30
parent 81caa577fe
commit c378591e3f
2 changed files with 14 additions and 7 deletions

View File

@@ -139,13 +139,13 @@ err_t vm_execute(vm_t *vm)
else if (UNSIGNED_OPCODE_IS_TYPE(instruction.opcode, OP_JUMP_IF))
{
data_t datum = {0};
err_t err = ERR_OK;
if (instruction.opcode == OP_JUMP_IF_BYTE)
err = vm_pop_byte(vm, &datum);
else if (instruction.opcode == OP_JUMP_IF_HWORD)
err = vm_pop_hword(vm, &datum);
else if (instruction.opcode == OP_JUMP_IF_WORD)
err = vm_pop_word(vm, &datum);
// Here we add OP_POP_BYTE and the data_type_t of the opcode to
// get the right typed OP_POP opcode.
opcode_t pop_opcode =
OPCODE_DATA_TYPE(instruction.opcode, OP_JUMP_IF) + OP_POP_BYTE;
err_t err = POP_ROUTINES[pop_opcode](vm, &datum);
if (err)
return err;