From: Brendan Hansen Date: Thu, 7 Jul 2022 14:35:19 +0000 (-0500) Subject: tiny change = all test cases pass! X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=85766135e05538482569b4a453bb29e7274b5353;p=onyx-embedder.git tiny change = all test cases pass! --- diff --git a/build.sh b/build.sh index e4095d8..97d881a 100755 --- a/build.sh +++ b/build.sh @@ -2,6 +2,7 @@ CC="gcc" WARNINGS='-Wimplicit -Wmisleading-indentation -Wparentheses -Wsequence-point -Wreturn-type -Wshift-negative-value -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wmaybe-uninitialized -Wsign-compare -Wstrict-overflow -Wduplicated-branches -Wduplicated-cond -Wtrigraphs -Waddress -Wlogical-op' +# FLAGS="-g3 -DOVM_VERBOSE=1" FLAGS="-O3" LIBS="-pthread" INCLUDES="-I include" diff --git a/src/vm/code_builder.c b/src/vm/code_builder.c index 41dd1af..fa252fa 100644 --- a/src/vm/code_builder.c +++ b/src/vm/code_builder.c @@ -206,7 +206,7 @@ void ovm_code_builder_add_branch_table(ovm_code_builder_t *builder, i32 count, i instrs[0].r = tmp_register; instrs[0].i = count; - instrs[1].full_instr = OVM_TYPED_INSTR(OVMI_LE, OVM_TYPE_I32); + instrs[1].full_instr = OVM_TYPED_INSTR(OVMI_LT, OVM_TYPE_I32); instrs[1].r = tmp_register; instrs[1].a = index_register; instrs[1].b = tmp_register; diff --git a/src/vm/vm.c b/src/vm/vm.c index 6ce7cef..12dab85 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -485,6 +485,10 @@ ovm_state_t *ovm_state_new(ovm_engine_t *engine, ovm_program_t *program) { state->external_funcs = NULL; bh_arr_new(store->heap_allocator, state->external_funcs, 8); +#ifdef OVM_VERBOSE + ovm_program_print_instructions(program, 0, bh_arr_length(program->code)); +#endif + return state; } @@ -645,7 +649,10 @@ ovm_value_t ovm_run_code(ovm_engine_t *engine, ovm_state_t *state, ovm_program_t ovm_value_t tmp_val; while (state->pc < bh_arr_length(program->code)) { - // ovm_program_print_instructions(program, state->pc, 1); +#ifdef OVM_VERBOSE + ovm_program_print_instructions(program, state->pc, 1); +#endif + tmp_val.type = OVM_TYPE_NONE; tmp_val.u64 = 0; @@ -917,7 +924,11 @@ ovm_value_t ovm_run_code(ovm_engine_t *engine, ovm_state_t *state, ovm_program_t case OVMI_MOV: VAL(instr.r) = VAL(instr.a); - // printf("$%d = %lx\n", instr.r, VAL(instr.r).u64); + +#ifdef OVM_VERBOSE + printf("$%d = %lx\n", instr.r, VAL(instr.r).u64); +#endif + break; #define OVM_LOAD(type_, stype) \ @@ -984,8 +995,11 @@ ovm_value_t ovm_run_code(ovm_engine_t *engine, ovm_state_t *state, ovm_program_t } case OVMI_IDX_ARR: { + ovm_static_integer_array_t data_elem = program->static_data[instr.a]; + assert(VAL(instr.b).u32 < (u32) data_elem.len); + tmp_val.type = OVM_TYPE_I32; - tmp_val.i32 = program->static_integers[program->static_data[instr.a].start_idx + VAL(instr.b).u32]; + tmp_val.i32 = program->static_integers[data_elem.start_idx + VAL(instr.b).u32]; VAL(instr.r) = tmp_val; break; } @@ -1011,9 +1025,11 @@ ovm_value_t ovm_run_code(ovm_engine_t *engine, ovm_state_t *state, ovm_program_t VAL(frame.return_number_value) = val; } - // printf("Returning from %s to %s: ", frame.func->name, bh_arr_last(state->stack_frames).func->name); - // ovm_print_val(val); - // printf("\n\n"); +#ifdef OVM_VERBOSE + printf("Returning from %s to %s: ", frame.func->name, bh_arr_last(state->stack_frames).func->name); + ovm_print_val(val); + printf("\n\n"); +#endif state->pc = frame.return_address; break;