From: Brendan Hansen Date: Fri, 6 May 2022 01:17:24 +0000 (-0500) Subject: bugfixes with how constraints are applied to functions X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=5f2320706a6081acd836f593f82fe3f02436ffc3;p=onyx.git bugfixes with how constraints are applied to functions --- diff --git a/modules/glfw3/build.onyx b/modules/glfw3/build.onyx index f202fdb8..50fa0eca 100644 --- a/modules/glfw3/build.onyx +++ b/modules/glfw3/build.onyx @@ -28,7 +28,7 @@ main :: () { static void __glfw_##callback_name (GLFWwindow *window, _EXPAND c_args) { \ wasm_val_t args[] = { WASM_I64_VAL((unsigned long long) window), _EXPAND wasm_args }; \ wasm_val_vec_t args_array = WASM_ARRAY_VEC(args); \ - wasm_val_vec_t results; \ + wasm_val_vec_t results = WASM_EMPTY_VEC; \ runtime->wasm_func_call(__glfw_callback_##callback_name , &args_array, &results); \ } \ ONYX_DEF(callback_name, (LONG, PTR, INT), ()) { \ diff --git a/modules/glfw3/onyx_glfw3.c b/modules/glfw3/onyx_glfw3.c index 5b6669fc..02e77ef2 100644 --- a/modules/glfw3/onyx_glfw3.c +++ b/modules/glfw3/onyx_glfw3.c @@ -12,7 +12,7 @@ static void __glfw_##callback_name (GLFWwindow *window, _EXPAND c_args) { \ wasm_val_t args[] = { WASM_I64_VAL((unsigned long long) window), _EXPAND wasm_args }; \ wasm_val_vec_t args_array = WASM_ARRAY_VEC(args); \ - wasm_val_vec_t results; \ + wasm_val_vec_t results = WASM_EMPTY_VEC; \ runtime->wasm_func_call(__glfw_callback_##callback_name , &args_array, &results); \ } \ ONYX_DEF(callback_name, (LONG, PTR, INT), ()) { \ diff --git a/modules/glfw3/onyx_glfw3.so b/modules/glfw3/onyx_glfw3.so index 618f6307..dd2da0c0 100755 Binary files a/modules/glfw3/onyx_glfw3.so and b/modules/glfw3/onyx_glfw3.so differ diff --git a/src/checker.c b/src/checker.c index 645e8a7b..e99aadf9 100644 --- a/src/checker.c +++ b/src/checker.c @@ -2313,6 +2313,15 @@ CheckStatus check_function_header(AstFunction* func) { b32 expect_default_param = 0; b32 has_had_varargs = 0; + if (func->constraints.constraints != NULL && func->constraints.constraints_met == 0) { + func->constraints.produce_errors = (func->flags & Ast_Flag_Header_Check_No_Error) == 0; + CHECK(constraint_context, &func->constraints, func->scope, func->token->pos); + + // All constraints have been met. Return to symbol resolution to finish + // looking up all symbols in the function. + return Check_Return_To_Symres; + } + bh_arr_each(AstParam, param, func->params) { AstLocal* local = param->local; @@ -2396,11 +2405,6 @@ CheckStatus check_function_header(AstFunction* func) { if (func->return_type != NULL) CHECK(type, &func->return_type); - if (func->constraints.constraints != NULL) { - func->constraints.produce_errors = (func->flags & Ast_Flag_Header_Check_No_Error) == 0; - CHECK(constraint_context, &func->constraints, func->scope, func->token->pos); - } - func->type = type_build_function_type(context.ast_alloc, func); if (func->type == NULL) YIELD(func->token->pos, "Waiting for function type to be constructed"); diff --git a/src/symres.c b/src/symres.c index 3cd5ddb5..8999a4f2 100644 --- a/src/symres.c +++ b/src/symres.c @@ -1019,6 +1019,16 @@ SymresStatus symres_function_header(AstFunction* func) { scope_enter(func->scope); + if (func->constraints.constraints != NULL && func->constraints.constraints_met == 0) { + bh_arr_each(AstConstraint *, constraint, func->constraints.constraints) { + SYMRES(constraint, *constraint); + } + + // Return early here to finish checking constraints in the checker. + // Will resume here after constraints have been met. + return Symres_Success; + } + bh_arr_each(AstParam, param, func->params) { if (param->default_value != NULL) { SYMRES(expression, ¶m->default_value); @@ -1040,7 +1050,7 @@ SymresStatus symres_function_header(AstFunction* func) { return Symres_Complete; } - if (func->nodes_that_need_entities_after_clone && bh_arr_length(func->nodes_that_need_entities_after_clone) > 0) { + if (func->nodes_that_need_entities_after_clone && bh_arr_length(func->nodes_that_need_entities_after_clone) > 0 && func->entity) { bh_arr_each(AstNode *, node, func->nodes_that_need_entities_after_clone) { // This makes a lot of assumptions about how these nodes are being processed, // and I don't want to start using this with other nodes without considering @@ -1069,12 +1079,6 @@ SymresStatus symres_function_header(AstFunction* func) { SYMRES(type, &func->return_type); - if (func->constraints.constraints != NULL) { - bh_arr_each(AstConstraint *, constraint, func->constraints.constraints) { - SYMRES(constraint, *constraint); - } - } - scope_leave(); return Symres_Success;