DUP implementation is now part of WORD_ROUTINES

As PUSH_REGISTER and MOV have the same signature of taking a word as
input, DUP may as well be part of it.

This leads to a larger discussion about how signatures of functions
matter: I may need to do a cleanup at some point.
This commit is contained in:
2023-11-01 21:14:04 +00:00
parent a5afaee3d0
commit 4e64f1fe23
2 changed files with 12 additions and 19 deletions

View File

@@ -68,10 +68,11 @@ err_t vm_execute(vm_t *vm)
return PUSH_ROUTINES[instruction.opcode](vm, instruction.operand);
}
else if (OPCODE_IS_TYPE(instruction.opcode, OP_MOV) ||
OPCODE_IS_TYPE(instruction.opcode, OP_PUSH_REGISTER))
OPCODE_IS_TYPE(instruction.opcode, OP_PUSH_REGISTER) ||
OPCODE_IS_TYPE(instruction.opcode, OP_DUP))
{
prog->ptr++;
return REG_ROUTINES[instruction.opcode](vm, instruction.operand.as_byte);
return WORD_ROUTINES[instruction.opcode](vm, instruction.operand.as_word);
}
else if (OPCODE_IS_TYPE(instruction.opcode, OP_POP))
{
@@ -94,11 +95,6 @@ err_t vm_execute(vm_t *vm)
}
return ERR_OK;
}
else if (OPCODE_IS_TYPE(instruction.opcode, OP_DUP))
{
prog->ptr++;
return DUP_ROUTINES[instruction.opcode](vm, instruction.operand.as_word);
}
else if (OPCODE_IS_TYPE(instruction.opcode, OP_NOT) ||
OPCODE_IS_TYPE(instruction.opcode, OP_OR) ||
OPCODE_IS_TYPE(instruction.opcode, OP_AND) ||