From: Brendan Hansen Date: Wed, 26 Aug 2020 03:52:00 +0000 (-0500) Subject: bug fixes with default parameters X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=41f17c9fa09b2c1046c7d38f122b71f4dcc1ab81;p=onyx.git bug fixes with default parameters --- diff --git a/onyx b/onyx index 87ede097..bccaf50a 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/wasi_test.onyx b/progs/wasi_test.onyx index 94ee0f15..1110f0d7 100644 --- a/progs/wasi_test.onyx +++ b/progs/wasi_test.onyx @@ -202,7 +202,7 @@ print_arr :: proc (sb: ^StringBuilder, arr: []i32) { sb |> sba("\n") |> string_builder_to_string() |> print(); } -make_i32_arr :: proc (a: Allocator, len: u32) -> [] i32 { +make_i32_arr :: proc (a := heap_allocator, len := 10) -> [] i32 { arr := cast(^i32) alloc(a, sizeof i32 * len); return arr[0 : len]; } @@ -247,13 +247,13 @@ main :: proc (args: []cstring) { proc_exit(1); } print("the size is: "); - print_u64_with_base(cast(u64) filelen, 10l); + print_u64_with_base(cast(u64) filelen); print("\n"); sum := 0l; for i: 0, 20000 do if is_prime(i) do sum += cast(u64) i; print("Sum of primes less than 20000 is: "); - print_u64_with_base(sum, 10l); + print_u64_with_base(sum); print("\n"); matches := string_split(heap_allocator, "This is a test string to test splitting. It surprisingly works very well.", #char " "); @@ -340,6 +340,9 @@ main :: proc (args: []cstring) { print("\n"); foobar(10, 1230); + + sl := make_i32_arr(); + print_u64_with_base(cast(u64) sl.count); } foobar :: proc (a: i32, b := 1, c := 5l) { diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 2d75f55b..b53c61ca 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -301,7 +301,7 @@ b32 check_call(AstCall* call) { if (callee->kind == Ast_Kind_Function) { if (call->arg_count < bh_arr_length(callee->params)) { AstArgument** last_arg = &call->arguments; - while (*last_arg && (*last_arg)->next != NULL) + while (*last_arg != NULL) last_arg = (AstArgument **) &(*last_arg)->next; while (call->arg_count < bh_arr_length(callee->params) @@ -314,7 +314,7 @@ b32 check_call(AstCall* call) { new_arg->type = dv->type; new_arg->next = NULL; - (*last_arg)->next = (AstNode *) new_arg; + *last_arg = new_arg; last_arg = (AstArgument **) &(*last_arg)->next; call->arg_count++;