diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 8 | ||||
-rw-r--r-- | src/runtime.c | 11 | ||||
-rw-r--r-- | src/runtime.h | 1 |
3 files changed, 13 insertions, 7 deletions
@@ -28,13 +28,7 @@ int interpret_bytecode(const char *filepath) vm_t vm = {0}; vm_load_stack(&vm, stack, ARR_SIZE(stack)); vm_load_program(&vm, instructions, number); - for (size_t i = 0; i < number; ++i) - { - vm_execute(&vm); - printf("Cycle %lu\n", i); - vm_print_all(&vm, stdout); - printf("\n"); - } + vm_execute_all(&vm); free(instructions); return 0; } diff --git a/src/runtime.c b/src/runtime.c index 218bba7..57101e0 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -50,6 +50,10 @@ void vm_execute(vm_t *vm) vm->registers.ret = d.as_word; // will do type punning for me prog->ptr++; } + else if (instruction.opcode == OP_HALT) + { + // Do nothing here. Should be caught by callers of vm_execute + } else { // TODO: Error (Unknown opcode) @@ -57,6 +61,13 @@ void vm_execute(vm_t *vm) } } +void vm_execute_all(vm_t *vm) +{ + struct Program *program = &vm->program; + while (program->instructions[program->ptr].opcode != OP_HALT) + vm_execute(vm); +} + void vm_load_stack(vm_t *vm, byte *bytes, size_t size) { vm->stack.data = bytes; diff --git a/src/runtime.h b/src/runtime.h index e588541..8ff0142 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -44,6 +44,7 @@ typedef struct #define VM_REG_WORD(REG) ((REG)) void vm_execute(vm_t *); +void vm_execute_all(vm_t *); void vm_load_stack(vm_t *, byte *, size_t); void vm_load_program(vm_t *, inst_t *, size_t); |