bugfixes with how constraints are applied to functions
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 6 May 2022 01:17:24 +0000 (20:17 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 6 May 2022 01:17:24 +0000 (20:17 -0500)
modules/glfw3/build.onyx
modules/glfw3/onyx_glfw3.c
modules/glfw3/onyx_glfw3.so
src/checker.c
src/symres.c

index f202fdb88d812ae86a98e4c7178032184e2b93bb..50fa0eca449fffbcb950980c0fa31eae55d6d541 100644 (file)
@@ -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), ()) { \
index 5b6669fcc434a399d213bba8a3dc52bc04114f80..02e77ef25b917583a21dba1c161a1afc5faf230b 100644 (file)
@@ -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), ()) { \
index 618f6307f7b136e3200015e23ae9bcd5e7339852..dd2da0c0230868b6b6aae460358cbaf94a02df92 100755 (executable)
Binary files a/modules/glfw3/onyx_glfw3.so and b/modules/glfw3/onyx_glfw3.so differ
index 645e8a7bfd94979c4bbf0eab33865d4cc00f997b..e99aadf987cf86272b0f23aa52fdb5eaa0570c87 100644 (file)
@@ -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");
 
index 3cd5ddb58280f594cbf365bba1573def629accc0..8999a4f2a4f48d2d8997aeef78a50c6d908a03e5 100644 (file)
@@ -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, &param->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;