Added vm_execute support for mov routines
Similar to push routines support. Easy to extend by adding items to the MOV_ROUTINES array.
This commit is contained in:
13
src/main.c
13
src/main.c
@@ -148,6 +148,7 @@ f64 vm_pop_float(vm_t *vm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef void (*push_f)(vm_t *, data_t);
|
typedef void (*push_f)(vm_t *, data_t);
|
||||||
|
typedef void (*mov_f)(vm_t *, data_t, word);
|
||||||
|
|
||||||
static const push_f PUSH_ROUTINES[] = {
|
static const push_f PUSH_ROUTINES[] = {
|
||||||
[OP_PUSH_BYTE] = vm_push_byte,
|
[OP_PUSH_BYTE] = vm_push_byte,
|
||||||
@@ -155,6 +156,12 @@ static const push_f PUSH_ROUTINES[] = {
|
|||||||
[OP_PUSH_FLOAT] = vm_push_float,
|
[OP_PUSH_FLOAT] = vm_push_float,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const mov_f MOV_ROUTINES[] = {
|
||||||
|
[OP_MOV_BYTE] = vm_mov_byte,
|
||||||
|
[OP_MOV_WORD] = vm_mov_word,
|
||||||
|
[OP_MOV_FLOAT] = vm_mov_float,
|
||||||
|
};
|
||||||
|
|
||||||
void vm_execute(vm_t *vm)
|
void vm_execute(vm_t *vm)
|
||||||
{
|
{
|
||||||
struct Program *prog = &vm->program;
|
struct Program *prog = &vm->program;
|
||||||
@@ -163,12 +170,16 @@ void vm_execute(vm_t *vm)
|
|||||||
return;
|
return;
|
||||||
inst_t instruction = prog->instructions[prog->ptr];
|
inst_t instruction = prog->instructions[prog->ptr];
|
||||||
|
|
||||||
// Check if opcode is PUSH_LIKE
|
|
||||||
if (OPCODE_IS_PUSH(instruction.opcode))
|
if (OPCODE_IS_PUSH(instruction.opcode))
|
||||||
{
|
{
|
||||||
PUSH_ROUTINES[instruction.opcode](vm, instruction.operand);
|
PUSH_ROUTINES[instruction.opcode](vm, instruction.operand);
|
||||||
prog->ptr++;
|
prog->ptr++;
|
||||||
}
|
}
|
||||||
|
else if (OPCODE_IS_MOV(instruction.opcode))
|
||||||
|
{
|
||||||
|
MOV_ROUTINES[instruction.opcode](vm, instruction.operand, instruction.reg);
|
||||||
|
prog->ptr++;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: Error (Unknown opcode)
|
// TODO: Error (Unknown opcode)
|
||||||
|
|||||||
Reference in New Issue
Block a user