From: Brendan Hansen Date: Thu, 9 Sep 2021 03:44:23 +0000 (-0500) Subject: memres bugfix and renamed poorly named function X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=8bae15fb5414d74b75f6377ad8bb18586b20f021;p=onyx.git memres bugfix and renamed poorly named function --- diff --git a/bin/onyx b/bin/onyx index 89f94976..0dd04a8b 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/random.onyx b/core/random.onyx index 85ba22c0..bd8ba8b3 100644 --- a/core/random.onyx +++ b/core/random.onyx @@ -1,6 +1,6 @@ package core.random -#private_file seed : i64 = 867530932187 +#private_file seed : i64 = 8675309 #private_file RANDOM_MULTIPLIER :: 25214903917 #private_file RANDOM_INCREMENT :: cast(i64) 11 diff --git a/include/astnodes.h b/include/astnodes.h index c11c782f..a3d0c4b9 100644 --- a/include/astnodes.h +++ b/include/astnodes.h @@ -1370,7 +1370,7 @@ void arguments_deep_clone(bh_allocator a, Arguments* dest, Arguments* src); void arguments_remove_baked(Arguments* args); b32 check_arguments_against_type(Arguments* args, TypeFunction* func_type, VarArgKind* va_kind, OnyxToken* location, char* func_name, struct OnyxError* error); -i32 function_get_minimum_argument_count(TypeFunction* type, Arguments* args); +i32 get_argument_buffer_size(TypeFunction* type, Arguments* args); // GROSS: Using void* to avoid having to cast everything. const char* node_get_type_name(void* node); diff --git a/src/checker.c b/src/checker.c index 3340b2e6..b7674fcd 100644 --- a/src/checker.c +++ b/src/checker.c @@ -518,7 +518,7 @@ CheckStatus check_call(AstCall** pcall) { AstFunction* callee=NULL; CHECK(resolve_callee, call, (AstTyped **) &callee); - i32 arg_count = function_get_minimum_argument_count(&callee->type->Function, &call->args); + i32 arg_count = get_argument_buffer_size(&callee->type->Function, &call->args); arguments_ensure_length(&call->args, arg_count); char* err_msg = NULL; @@ -2050,7 +2050,6 @@ CheckStatus check_memres_type(AstMemRes* memres) { CheckStatus check_memres(AstMemRes* memres) { if (memres->initial_value != NULL) { CHECK(expression, &memres->initial_value); - resolve_expression_type(memres->initial_value); if ((memres->initial_value->flags & Ast_Flag_Comptime) == 0) { ERROR(memres->initial_value->token->pos, "Top level expressions must be compile time known."); @@ -2066,6 +2065,7 @@ CheckStatus check_memres(AstMemRes* memres) { } } else { + resolve_expression_type(memres->initial_value); if (memres->initial_value->type == NULL && memres->initial_value->entity != NULL && memres->initial_value->entity->state <= Entity_State_Check_Types) { YIELD(memres->token->pos, "Waiting for global type to be constructed."); } diff --git a/src/utils.c b/src/utils.c index 7c63d9c9..2b2feb1f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -368,7 +368,7 @@ AstTyped* find_matching_overload_by_arguments(bh_arr(OverloadOption) overloads, assert(overload->type->kind == Type_Kind_Function); arguments_remove_baked(&args); - arguments_ensure_length(&args, function_get_minimum_argument_count(&overload->type->Function, &args)); + arguments_ensure_length(&args, get_argument_buffer_size(&overload->type->Function, &args)); // NOTE: If the arguments cannot be placed successfully in the parameters list if (!fill_in_arguments(&args, (AstNode *) overload, NULL)) continue; @@ -690,10 +690,12 @@ static i32 non_baked_argument_count(Arguments* args) { return count; } -i32 function_get_minimum_argument_count(TypeFunction* type, Arguments* args) { +i32 get_argument_buffer_size(TypeFunction* type, Arguments* args) { i32 non_vararg_param_count = (i32) type->param_count; - if (non_vararg_param_count > 0 && type->params[type->param_count - 1] == builtin_vararg_type_type) - non_vararg_param_count--; + if (non_vararg_param_count > 0) { + if (type->params[type->param_count - 1] == builtin_vararg_type_type) non_vararg_param_count--; + if (type->params[type->param_count - 1]->kind == Type_Kind_VarArgs) non_vararg_param_count--; + } return bh_max(non_vararg_param_count, non_baked_argument_count(args)); } @@ -792,7 +794,7 @@ b32 check_arguments_against_type(Arguments* args, TypeFunction* func_type, VarAr if (func_name == NULL) func_name = "UNKNOWN FUNCTION"; bh_arr(AstArgument *) arg_arr = (bh_arr(AstArgument *)) args->values; - i32 arg_count = function_get_minimum_argument_count(func_type, args); + i32 arg_count = get_argument_buffer_size(func_type, args); Type **formal_params = func_type->params; Type* variadic_type = NULL;