From: Brendan Hansen Date: Thu, 26 Oct 2023 03:20:41 +0000 (-0500) Subject: bugfix: many minor bugs X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=7bbbe4c1eaf9a61a0f60e7f448f9aaced0447927;p=onyx.git bugfix: many minor bugs --- diff --git a/compiler/src/wasm_runtime.c b/compiler/src/wasm_runtime.c index cb68f7cd..c90b395d 100644 --- a/compiler/src/wasm_runtime.c +++ b/compiler/src/wasm_runtime.c @@ -586,6 +586,7 @@ void onyx_run_initialize(b32 debug_enabled) { wasm_runtime.wasm_extern_as_func = &wasm_extern_as_func; wasm_runtime.wasm_func_call = &wasm_func_call; wasm_runtime.wasm_instance_new = &wasm_instance_new; + wasm_runtime.wasm_instance_delete = &wasm_instance_delete; wasm_runtime.wasm_store_new = &wasm_store_new; wasm_runtime.wasm_store_delete = &wasm_store_delete; wasm_runtime.onyx_print_trap = &onyx_print_trap; diff --git a/interpreter/build.sh b/interpreter/build.sh index 80e05b94..d1ab9254 100755 --- a/interpreter/build.sh +++ b/interpreter/build.sh @@ -2,7 +2,7 @@ . ../settings.sh -# FLAGS="-g3 -DOVM_DEBUG=1 -fno-stack-protector" +# FLAGS="-g3 -O2 -DOVM_DEBUG=1 -fno-stack-protector" # FLAGS="-g3 -DOVM_VERBOSE=1" FLAGS="-Ofast -fno-stack-protector" LIBS="-pthread" diff --git a/interpreter/include/vm.h b/interpreter/include/vm.h index c6b3c6d1..633a6434 100644 --- a/interpreter/include/vm.h +++ b/interpreter/include/vm.h @@ -164,6 +164,7 @@ struct ovm_state_t { ovm_value_t *__frame_values; debug_thread_state_t *debug; + i32 call_depth; }; ovm_state_t *ovm_state_new(ovm_engine_t *engine, ovm_program_t *program); diff --git a/interpreter/src/debug/debug_thread.c b/interpreter/src/debug/debug_thread.c index 78aa4e73..89a60d66 100644 --- a/interpreter/src/debug/debug_thread.c +++ b/interpreter/src/debug/debug_thread.c @@ -25,7 +25,6 @@ #define EVT_NOP 0 #define EVT_BRK_HIT 1 #define EVT_PAUSE 2 -#define EVT_NEW_THREAD 3 // Not Implemented #define EVT_RESPONSE 0xffffffff struct msg_parse_ctx_t { @@ -609,6 +608,15 @@ void *__debug_thread_entry(void * data) { while (debug->debug_thread_running) { poll(poll_fds, 2, 1000); + // + // If there are no functions on the main thread, + // assume the program has exited and do not continue to + // do anything. + if (debug->threads[0]->ovm_state->call_depth <= 0) { + debug->debug_thread_running = false; + break; + } + // // Try to read commands from the client. // If an error was returned, bail out of this thread. diff --git a/interpreter/src/vm/vm.c b/interpreter/src/vm/vm.c index 04c2d00b..7f0495f9 100644 --- a/interpreter/src/vm/vm.c +++ b/interpreter/src/vm/vm.c @@ -353,6 +353,8 @@ ovm_value_t ovm_func_call(ovm_engine_t *engine, ovm_state_t *state, ovm_program_ ovm_func_t *func = &program->funcs[func_idx]; ovm_assert(func->value_number_count >= func->param_count); + state->call_depth += 1; + switch (func->kind) { case OVM_FUNC_INTERNAL: { ovm__func_setup_stack_frame(state, func, 0); @@ -364,6 +366,7 @@ ovm_value_t ovm_func_call(ovm_engine_t *engine, ovm_state_t *state, ovm_program_ state->pc = func->start_instr; ovm_value_t result = ovm_run_code(engine, state, program); + state->call_depth -= 1; return result; } @@ -375,6 +378,8 @@ ovm_value_t ovm_func_call(ovm_engine_t *engine, ovm_state_t *state, ovm_program_ external_func.native_func(external_func.userdata, params, &result); ovm__func_teardown_stack_frame(state); + + state->call_depth -= 1; return result; } diff --git a/misc/vscode/package.json b/misc/vscode/package.json index e9088665..0d7fa3a1 100644 --- a/misc/vscode/package.json +++ b/misc/vscode/package.json @@ -98,7 +98,7 @@ "onyxFiles": { "type": "array", "description": "The Onyx files for compiling.", - "default": "[]" + "default": [] }, "workingDir": { "type": "string", diff --git a/runtime/src/ort_threads.h b/runtime/src/ort_threads.h index 8af6fc06..c0ef8d74 100644 --- a/runtime/src/ort_threads.h +++ b/runtime/src/ort_threads.h @@ -78,6 +78,7 @@ static i32 onyx_run_thread(void *data) { trap = runtime->wasm_func_call(exit_func, &args_array, &results); } + runtime->wasm_instance_delete(thread->instance); runtime->wasm_store_delete(wasm_store); return 0; diff --git a/shared/include/onyx_library.h b/shared/include/onyx_library.h index f0046724..1e2ef235 100644 --- a/shared/include/onyx_library.h +++ b/shared/include/onyx_library.h @@ -40,6 +40,8 @@ typedef struct OnyxRuntime { // for this function to exist, yet. wasm_table_t *wasm_func_table; void (*(*wasm_func_from_idx)(wasm_table_t *table, unsigned int index, char *signature))(void); + + void (*wasm_instance_delete)(wasm_instance_t *instance); } OnyxRuntime; OnyxRuntime* runtime;