From: Brendan Hansen Date: Thu, 4 May 2023 17:26:46 +0000 (-0500) Subject: added: preparing for adding tags to foreign block procedures X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=22f2acb5d5dd35ef8258fea3e71ed7c5e0eda452;p=onyx.git added: preparing for adding tags to foreign block procedures --- diff --git a/compiler/src/checker.c b/compiler/src/checker.c index 1011e8a0..2f6be84a 100644 --- a/compiler/src/checker.c +++ b/compiler/src/checker.c @@ -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"); diff --git a/compiler/src/symres.c b/compiler/src/symres.c index c0dd191e..214a8a41 100644 --- a/compiler/src/symres.c +++ b/compiler/src/symres.c @@ -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; } diff --git a/compiler/src/wasm_emit.c b/compiler/src/wasm_emit.c index f1d18d9b..7ae39df0 100644 --- a/compiler/src/wasm_emit.c +++ b/compiler/src/wasm_emit.c @@ -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; diff --git a/core/runtime/info/foreign_blocks.onyx b/core/runtime/info/foreign_blocks.onyx index 6d6f5035..7068cf02 100644 --- a/core/runtime/info/foreign_blocks.onyx +++ b/core/runtime/info/foreign_blocks.onyx @@ -19,6 +19,7 @@ Foreign_Block :: struct { Foreign_Function :: struct { name: str; type: type_expr; + // tags: [] any; } }