diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-03 19:10:01 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-03 21:15:30 +0000 |
commit | 92f4f9011d431f9c197aff56a3dbb8a3963b4197 (patch) | |
tree | 8c9300348587c374132f2bf4b987e98a467972e9 | |
parent | a7588ccc6166d1fa49a37db6d2d3aba552901e9e (diff) | |
download | ovm-92f4f9011d431f9c197aff56a3dbb8a3963b4197.tar.gz ovm-92f4f9011d431f9c197aff56a3dbb8a3963b4197.tar.bz2 ovm-92f4f9011d431f9c197aff56a3dbb8a3963b4197.zip |
Refactor vm/main to use refactor to program structure
-rw-r--r-- | vm/main.c | 9 | ||||
-rw-r--r-- | vm/runtime.c | 4 |
2 files changed, 6 insertions, 7 deletions
@@ -40,14 +40,13 @@ int main(int argc, char *argv[]) printf("[" TERM_YELLOW "INTERPRETER" TERM_RESET "]: `%s`\n", filename); #endif - FILE *fp = fopen(filename, "rb"); - size_t number = 0; - inst_t *instructions = insts_read_bytecode_file(fp, &number); + FILE *fp = fopen(filename, "rb"); + prog_t *program = prog_read_file(fp); fclose(fp); #if VERBOSE >= 1 printf("\t[" TERM_GREEN "SETUP" TERM_RESET "]: Read %lu instructions\n", - number); + program->count); #endif size_t stack_size = 256; @@ -61,7 +60,7 @@ int main(int argc, char *argv[]) vm_t vm = {0}; vm_load_stack(&vm, stack, stack_size); - vm_load_program(&vm, instructions, number); + vm_load_program(&vm, program); vm_load_registers(&vm, registers); vm_load_heap(&vm, heap); vm_load_call_stack(&vm, call_stack, call_stack_size); diff --git a/vm/runtime.c b/vm/runtime.c index 16c75f9..72785c5 100644 --- a/vm/runtime.c +++ b/vm/runtime.c @@ -281,8 +281,8 @@ err_t vm_execute_all(vm_t *vm) size_t prev_pages = 0; size_t prev_cptr = 0; #endif - while (program->data->instructions[program->ptr].opcode != OP_HALT && - program->ptr < program->data->count) + while (program->ptr < program->data->count && + program->data->instructions[program->ptr].opcode != OP_HALT) { #if VERBOSE >= 2 fprintf(stdout, "[vm_execute_all]: Trace(Cycle %lu)\n", cycles); |