added: preparing for adding tags to foreign block procedures
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 4 May 2023 17:26:46 +0000 (12:26 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 4 May 2023 17:26:46 +0000 (12:26 -0500)
compiler/src/checker.c
compiler/src/symres.c
compiler/src/wasm_emit.c
core/runtime/info/foreign_blocks.onyx

index 1011e8a0e86fd0052d645c3db32150e28e75ec95..2f6be84acca79f03ddb70028265d1c52fe5d0ec5 100644 (file)
@@ -2547,14 +2547,6 @@ CheckStatus check_function(AstFunction* func) {
     if (func->entity_header && func->entity_header->state < Entity_State_Code_Gen)
         YIELD(func->token->pos, "Waiting for procedure header to pass type-checking");
 
-    bh_arr_each(AstTyped *, pexpr, func->tags) {
-        CHECK(expression, pexpr);
-
-        if (((*pexpr)->flags & Ast_Flag_Comptime) == 0) {
-            ERROR((*pexpr)->token->pos, "#tag expressions should be compile time known.");
-        }
-    }
-
     bh_arr_clear(context.checker.expected_return_type_stack);
     bh_arr_push(context.checker.expected_return_type_stack, &func->type->Function.return_type);
 
@@ -2950,6 +2942,14 @@ CheckStatus check_function_header(AstFunction* func) {
         }
     }
 
+    bh_arr_each(AstTyped *, pexpr, func->tags) {
+        CHECK(expression, pexpr);
+
+        if (((*pexpr)->flags & Ast_Flag_Comptime) == 0) {
+            ERROR((*pexpr)->token->pos, "#tag expressions should be compile time known.");
+        }
+    }
+
     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 c0dd191e0e5d273d985afdee6d4baf785628df31..214a8a410539a14910e08988fe32aa8b87f11fa5 100644 (file)
@@ -1055,6 +1055,10 @@ SymresStatus symres_function_header(AstFunction* func) {
     if (func->deprecated_warning) {
         SYMRES(expression, (AstTyped **) &func->deprecated_warning);
     }
+    
+    bh_arr_each(AstTyped *, pexpr, func->tags) {
+        SYMRES(expression, pexpr);
+    }
 
     if (func->foreign.import_name) {
         SYMRES(expression, &func->foreign.module_name);
@@ -1137,10 +1141,6 @@ SymresStatus symres_function(AstFunction* func) {
             }
         }
 
-        bh_arr_each(AstTyped *, pexpr, func->tags) {
-            SYMRES(expression, pexpr);
-        }
-
         func->flags |= Ast_Flag_Has_Been_Symres;
     }
 
index f1d18d9bd783c96d94a06f308ebbc8d62c89797c..7ae39df01117d3e09127f0259217c0368cc766b7 100644 (file)
@@ -201,7 +201,7 @@ static inline b32 should_emit_function(AstFunction* fd) {
     // NOTE: Don't output functions that are not used, only if
     // they are also not exported.
     if ((fd->flags & Ast_Flag_Function_Used) == 0) {
-        if (fd->is_exported || bh_arr_length(fd->tags) > 0) {
+        if (fd->is_exported || (bh_arr_length(fd->tags) > 0 && !fd->is_foreign)) {
             return 1;
         } else {
             return 0;
index 6d6f503548d896d7f2318178ad5b8c64f81502e7..7068cf02232321e09d81edfe06fb6a44f0ba573d 100644 (file)
@@ -19,6 +19,7 @@ Foreign_Block :: struct {
     Foreign_Function :: struct {
         name: str;
         type: type_expr;
+        // tags: [] any;
     }
 }