started adding argument parsing to run_tests
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 4 Dec 2021 01:47:33 +0000 (19:47 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 4 Dec 2021 01:47:33 +0000 (19:47 -0600)
scripts/run_tests.onyx
src/checker.c
src/wasm_runtime.c

index 0c2b53a10f7a21a3fa2deafac19a7d60d0f201b0..1adad07ba7908a72c3ea7af633f617fa4cd9d75c 100644 (file)
@@ -154,32 +154,87 @@ test_cases :: (cases) => {
 // The executable to use when compiling
 onyx_cmd: str;
 
+
+Settings :: struct {
+    ["--debug", "-d"]
+    debug := false;
+
+    ["--threads"]
+    threads := 3;
+
+    ["--no-color"]
+    no_color := false;
+
+    ["--tests"]
+    test_folder := "./tests";
+}
+
+// #export "args_parse" args_parse
+args_parse :: (c_args: [] cstr, output: ^$ArgType) -> bool {
+    arg_iter := iter.as_iterator(c_args)
+            |> iter.map((x) => string.from_cstr(*x));
+
+    use type_info;
+
+    arg_type := cast(^Type_Info_Struct) get_type_info(ArgType);
+    if arg_type.kind != .Struct do return false;
+    
+    for #no_close arg: arg_iter {
+        for ^member: arg_type.members {
+            for ^tag: member.tags {
+                if tag.type != str do continue;
+
+                to_match := *cast(^str) tag.data;
+                if arg != to_match do continue;
+
+                switch member.type {
+                    case bool {
+                        // Should there be a way to specify a variable to be false?
+                        *(cast(^bool) (cast(^u8) output + member.offset)) = true;
+                    }
+
+                    case i32 {
+                        value_str, success := iter.take_one(arg_iter);
+                        if !success do return false;
+
+                        value := conv.str_to_i64(value_str);
+                        *(cast(^i32) (cast(^u8) output + member.offset)) = ~~value;
+                    }
+
+                    case #default {
+                        printf("Unsupported argument type.");
+                        return false;
+                    }
+                }
+            }
+        }
+    }
+
+    // This has to be done explicitly beacuse the iter.take_one function
+    // can close the iterator if it runs out during the taking.
+    arg_iter->close();
+    return true;
+}
+
 main :: (args) => {
+    settings := Settings.{};
+    args_parse(args, ^settings);
+    println(settings);
+
     test_folder := "./tests";
 
     switch runtime.OS {
         case runtime.OS_Linux {
             onyx_cmd = "./bin/onyx";
-            if args.count > 1 {
-                if string.from_cstr(args[1]) == "debug" do onyx_cmd = "./bin/onyx-debug";
-            }
+            if settings.debug do onyx_cmd = "./bin/onyx-debug";
         }
         case runtime.OS_Windows do onyx_cmd = "onyx.exe";
     }
 
-    cases := array.make(Test_Case);
+    cases := array.make(Test_Case, capacity=256);
     find_onyx_files(test_folder, ^cases);
 
-    thread_count := 3;
-    for args {
-        arg := string.from_cstr(it);
-        if string.starts_with(arg, "--threads=") {
-            string.read_until(^arg, #char "=");
-
-            thread_count = ~~ conv.str_to_i64(arg[1 .. arg.count]);
-        }
-    }
-
+    thread_count := settings.threads;
     case_iterator := distributor(cases);
 
     if thread_count > 0 {
index 2078bc389f8b47c463c62be7d6034c10fd942fc8..72d2350cbf47f99808ed3ededf1754eccab0a3c3 100644 (file)
@@ -892,8 +892,8 @@ CheckStatus check_binaryop_compare(AstBinaryOp** pbinop) {
             TYPE_CHECK(&binop->right, ltype) {
                 ERROR_(binop->token->pos,
                         "Cannot compare '%s' to '%s'.",
-                        type_get_name(ltype),
-                        type_get_name(rtype));
+                        type_get_name(binop->left->type),
+                        type_get_name(binop->right->type));
             }
         }
     }
index 8d22038d2ca35859cc4fd254c3e1dfea439b1918..6a5d3dfb52e82a893f26a9b63d68d11368a894fc 100644 (file)
@@ -688,6 +688,17 @@ b32 onyx_run_wasm(bh_buffer wasm_bytes) {
 
     run_trap = wasm_func_call(start_func, &args, &results);
 
+#if 0
+    if (run_trap != NULL) {
+        wasm_message_t msg;
+        wasm_trap_message(run_trap, &msg);
+        bh_printf("TRAP: %b\n", msg.data, msg.size);
+
+        wasm_frame_t *origin = wasm_trap_origin(run_trap);
+        bh_printf("HERE: func[%d] at %p.\n", wasm_frame_func_index(origin), wasm_frame_module_offset(origin));
+    }
+#endif
+
     goto cleanup;
 
 error_handling: