From 96a71164f335689ffc15be9b4ed246c5aa277f9e Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Fri, 3 Dec 2021 19:47:33 -0600 Subject: [PATCH] started adding argument parsing to run_tests --- scripts/run_tests.onyx | 83 +++++++++++++++++++++++++++++++++++------- src/checker.c | 4 +- src/wasm_runtime.c | 11 ++++++ 3 files changed, 82 insertions(+), 16 deletions(-) diff --git a/scripts/run_tests.onyx b/scripts/run_tests.onyx index 0c2b53a1..1adad07b 100644 --- a/scripts/run_tests.onyx +++ b/scripts/run_tests.onyx @@ -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 { diff --git a/src/checker.c b/src/checker.c index 2078bc38..72d2350c 100644 --- a/src/checker.c +++ b/src/checker.c @@ -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)); } } } diff --git a/src/wasm_runtime.c b/src/wasm_runtime.c index 8d22038d..6a5d3dfb 100644 --- a/src/wasm_runtime.c +++ b/src/wasm_runtime.c @@ -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: -- 2.25.1