bugfix with cbindgen; added ovm_print_stack_trace
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 6 Dec 2022 02:17:19 +0000 (20:17 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 6 Dec 2022 02:17:19 +0000 (20:17 -0600)
core/alloc/gc.onyx
core/onyx/cbindgen.onyx
core/string/string.onyx
interpreter/src/vm/vm.c
shared/lib/linux_x86_64/lib/libovmwasm.so

index f85ac2714b50ea413dd2947f65c4e378374d87d3..ac44b7b4524b02a9bdc30eac9160a9d2685f1e77 100644 (file)
@@ -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;
         }
     }
index 7b0dc7491a5bf6ec0f259160d57f3136ce31b230..d77857d0103c306483e28d6677ac9e2be62a101b 100644 (file)
@@ -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 {
index ef901b8e1795a00fccffab48c4d204ebcc40deeb..c039af6272b400253153170337d201afa78e836d 100644 (file)
@@ -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];
+}
+
index adb2247d89556f704c3a9f5698eaf3544b3872b2..d9d062f7619ca1eeabdc4501ba1bfaae2c32937a 100644 (file)
@@ -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);
+    }
+}
+
index a05e2c83189ccbbc5702662a6b5d116ce60cd66e..91bbd0468340e3040e5551e4a970a8fa1a81c89e 100755 (executable)
Binary files a/shared/lib/linux_x86_64/lib/libovmwasm.so and b/shared/lib/linux_x86_64/lib/libovmwasm.so differ