aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vm/runtime.c10
-rw-r--r--vm/runtime.h21
2 files changed, 12 insertions, 19 deletions
diff --git a/vm/runtime.c b/vm/runtime.c
index 0fbea05..ce8281a 100644
--- a/vm/runtime.c
+++ b/vm/runtime.c
@@ -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) ||
diff --git a/vm/runtime.h b/vm/runtime.h
index 6c6042a..c4d28d8 100644
--- a/vm/runtime.h
+++ b/vm/runtime.h
@@ -96,26 +96,23 @@ err_t vm_mov_byte(vm_t *, word);
err_t vm_mov_hword(vm_t *, word);
err_t vm_mov_word(vm_t *, word);
-typedef err_t (*reg_f)(vm_t *, word);
-static const reg_f REG_ROUTINES[] = {
+err_t vm_dup_byte(vm_t *, word);
+err_t vm_dup_hword(vm_t *, word);
+err_t vm_dup_word(vm_t *, word);
+
+typedef err_t (*word_f)(vm_t *, word);
+static const word_f WORD_ROUTINES[] = {
[OP_PUSH_REGISTER_BYTE] = vm_push_byte_register,
[OP_PUSH_REGISTER_HWORD] = vm_push_hword_register,
[OP_PUSH_REGISTER_WORD] = vm_push_word_register,
[OP_MOV_BYTE] = vm_mov_byte,
[OP_MOV_HWORD] = vm_mov_hword,
[OP_MOV_WORD] = vm_mov_word,
+ [OP_DUP_BYTE] = vm_dup_byte,
+ [OP_DUP_HWORD] = vm_dup_hword,
+ [OP_DUP_WORD] = vm_dup_word,
};
-err_t vm_dup_byte(vm_t *, word);
-err_t vm_dup_hword(vm_t *, word);
-err_t vm_dup_word(vm_t *, word);
-
-typedef err_t (*dup_f)(vm_t *, word);
-static const dup_f DUP_ROUTINES[] = {
- [OP_DUP_BYTE] = vm_dup_byte,
- [OP_DUP_HWORD] = vm_dup_hword,
- [OP_DUP_WORD] = vm_dup_word,
-};
err_t vm_not_byte(vm_t *);
err_t vm_not_hword(vm_t *);