From: Brendan Hansen Date: Tue, 6 Dec 2022 02:17:19 +0000 (-0600) Subject: bugfix with cbindgen; added ovm_print_stack_trace X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=ad34adbabe7562bd69d96e3e642f6174f0c6a4ec;p=onyx.git bugfix with cbindgen; added ovm_print_stack_trace --- diff --git a/core/alloc/gc.onyx b/core/alloc/gc.onyx index f85ac271..ac44b7b4 100644 --- a/core/alloc/gc.onyx +++ b/core/alloc/gc.onyx @@ -83,11 +83,13 @@ GC_Link_Magic_Number :: 0x1337face } if aa == .Resize || aa == .Free { - if data.first == old { - data.first = data.first.next; - - } else { + if old.prev { old.prev.next = old.next; + } else { + data.first = old.next; + } + + if old.next { old.next.prev = old.prev; } } diff --git a/core/onyx/cbindgen.onyx b/core/onyx/cbindgen.onyx index 7b0dc749..d77857d0 100644 --- a/core/onyx/cbindgen.onyx +++ b/core/onyx/cbindgen.onyx @@ -235,7 +235,7 @@ compile_c_file :: ( use runtime.info; callw, call := io.string_builder(); defer io.buffer_stream_free(call); - defer delete(cast(rawptr) call); + defer cfree(call); param_num := 0; for method_info.parameter_types { diff --git a/core/string/string.onyx b/core/string/string.onyx index ef901b8e..c039af62 100644 --- a/core/string/string.onyx +++ b/core/string/string.onyx @@ -236,6 +236,9 @@ is_empty :: (s: str) -> bool #deprecated "Use 'string.empty' instead." { s.count == 0 || s.data == null; } +index_of :: #match #local {} + +#overload index_of :: (s: str, c: u8) -> i32 { for s.count { if s[it] == c do return it; @@ -243,6 +246,25 @@ index_of :: (s: str, c: u8) -> i32 { return -1; } +#overload +index_of :: (s: str, substr: str) -> i32 { + while i := 0; i < s.count { + start := i; + while j := 0; j < substr.count { + if s[i + j] != substr[j] { + i += j + 1; + continue continue; + } + + j += 1; + } + + return start; + } + + return -1; +} + last_index_of :: (s: str, c: u8) -> i32 { for range.{s.count, 0, -1} { if s[it] == c do return it; @@ -565,6 +587,9 @@ split_iter :: (s: str, delim: u8) -> Iterator(str) { // character occurs at the very beginning or end of // the string, or if it does not occur at all. // +bisect :: #match #local {} + +#overload bisect :: (s: str, c: u8) -> (str, str) { index := index_of(s, c); if index == -1 { @@ -574,3 +599,13 @@ bisect :: (s: str, c: u8) -> (str, str) { return s[0 .. index], s[index+1 .. s.length]; } +#overload +bisect :: (s: str, substr: str) -> (str, str) { + index := index_of(s, substr); + if index == -1 { + return s, ""; + } + + return s[0 .. index], s[index+1 .. s.length]; +} + diff --git a/interpreter/src/vm/vm.c b/interpreter/src/vm/vm.c index adb2247d..d9d062f7 100644 --- a/interpreter/src/vm/vm.c +++ b/interpreter/src/vm/vm.c @@ -1274,3 +1274,13 @@ ovm_value_t ovm_run_code(ovm_engine_t *engine, ovm_state_t *state, ovm_program_t return ((ovm_value_t) {0}); } + + +void ovm_print_stack_trace(ovm_engine_t *engine, ovm_state_t *state, ovm_program_t *program) { + int i = 0; + bh_arr_rev_each(ovm_stack_frame_t, frame, state->stack_frames) { + ovm_func_t *func = frame->func; + printf("[%03d] %s\n", i++, func->name); + } +} + diff --git a/shared/lib/linux_x86_64/lib/libovmwasm.so b/shared/lib/linux_x86_64/lib/libovmwasm.so index a05e2c83..91bbd046 100755 Binary files a/shared/lib/linux_x86_64/lib/libovmwasm.so and b/shared/lib/linux_x86_64/lib/libovmwasm.so differ