From f09fc426e5486968c8ed3cbb80131fc992ab0648 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 23 Oct 2021 21:58:16 -0500 Subject: [PATCH] removed foreign globals; cleaned up ast_flags --- include/astnodes.h | 68 ++++++++++++++++++++-------------------------- include/wasm.h | 1 - src/astnodes.c | 1 - src/builtins.c | 2 +- src/checker.c | 10 +++---- src/clone.c | 6 ++-- src/entities.c | 23 ++++++---------- src/parser.c | 30 ++++---------------- src/polymorph.c | 12 ++++---- src/symres.c | 27 +++++++----------- src/types.c | 6 ++-- src/utils.c | 17 ++---------- src/wasm.c | 31 ++++----------------- src/wasm_output.c | 8 ------ 14 files changed, 80 insertions(+), 162 deletions(-) diff --git a/include/astnodes.h b/include/astnodes.h index f48413fc..82e8f252 100644 --- a/include/astnodes.h +++ b/include/astnodes.h @@ -211,60 +211,41 @@ typedef enum AstKind { // only 32-bits of flags to play with typedef enum AstFlags { // Top-level flags - Ast_Flag_Exported = BH_BIT(1), - Ast_Flag_Foreign = BH_BIT(2), - Ast_Flag_Const = BH_BIT(3), - Ast_Flag_Comptime = BH_BIT(4), - Ast_Flag_Private_Package = BH_BIT(5), - Ast_Flag_Private_File = BH_BIT(6), - - // Global flags - Ast_Flag_Global_Stack_Top = BH_BIT(7), + Ast_Flag_Const = BH_BIT(1), + Ast_Flag_Comptime = BH_BIT(2), + Ast_Flag_Private_Package = BH_BIT(3), + Ast_Flag_Private_File = BH_BIT(4), // Function flags - Ast_Flag_Already_Checked = BH_BIT(8), - Ast_Flag_Intrinsic = BH_BIT(10), - Ast_Flag_Function_Used = BH_BIT(11), + Ast_Flag_Function_Used = BH_BIT(5), // Expression flags - Ast_Flag_Expr_Ignored = BH_BIT(13), - Ast_Flag_Param_Use = BH_BIT(14), // Unneeded, just use a bool on AstParam - Ast_Flag_Address_Taken = BH_BIT(15), + Ast_Flag_Expr_Ignored = BH_BIT(6), + Ast_Flag_Address_Taken = BH_BIT(7), // Type flags - Ast_Flag_Type_Is_Resolved = BH_BIT(16), - - // Enum flags - Ast_Flag_Enum_Is_Flags = BH_BIT(17), // Unneeded, just use a bool on AstEnum - - // Struct flags - Ast_Flag_Struct_Is_Union = BH_BIT(18), // Unneeded, just a usea bool on AstStruct - - Ast_Flag_No_Clone = BH_BIT(19), + Ast_Flag_Type_Is_Resolved = BH_BIT(8), - Ast_Flag_Cannot_Take_Addr = BH_BIT(20), + Ast_Flag_No_Clone = BH_BIT(9), - Ast_Flag_Struct_Mem_Used = BH_BIT(21), // Unneeded, just a usea bool on AstStructMember + Ast_Flag_Cannot_Take_Addr = BH_BIT(10), // HACK: NullProcHack - Ast_Flag_Proc_Is_Null = BH_BIT(22), + Ast_Flag_Proc_Is_Null = BH_BIT(11), - Ast_Flag_From_Polymorphism = BH_BIT(23), + Ast_Flag_From_Polymorphism = BH_BIT(12), - Ast_Flag_Incomplete_Body = BH_BIT(24), + Ast_Flag_Incomplete_Body = BH_BIT(13), - Ast_Flag_Array_Literal_Typed = BH_BIT(25), + Ast_Flag_Array_Literal_Typed = BH_BIT(14), - Ast_Flag_Has_Been_Symres = BH_BIT(26), + Ast_Flag_Has_Been_Symres = BH_BIT(15), - Ast_Flag_Has_Been_Checked = BH_BIT(27), + Ast_Flag_Has_Been_Checked = BH_BIT(16), - Ast_Flag_Static_If_Resolved = BH_BIT(28), + Ast_Flag_Static_If_Resolved = BH_BIT(17), - // :TEMPORARY - Ast_Flag_Params_Introduced = BH_BIT(29), - - Ast_Flag_Symbol_Invisible = BH_BIT(30), + Ast_Flag_Symbol_Invisible = BH_BIT(18), } AstFlags; typedef enum UnaryOp { @@ -810,12 +791,15 @@ struct AstStructType { struct Entity* entity_defaults; b32 stcache_is_valid : 1; + b32 is_union : 1; }; struct AstStructMember { AstTyped_base; AstTyped* initial_value; bh_arr(AstTyped *) meta_tags; + + b32 is_used : 1; }; struct AstPolyStructParam { AstTyped_base; @@ -850,6 +834,8 @@ struct AstEnumType { // NOTE: Used to cache the actual type for the same reason as above. Type *etcache; + + b32 is_flags : 1; }; struct AstEnumValue { AstTyped_base; AstNumLit* value; }; struct AstTypeAlias { AstType_base; AstType* to; }; @@ -893,6 +879,7 @@ struct AstParam { AstTyped *default_value; VarArgKind vararg_kind; + b32 is_used : 1; b32 use_processed : 1; b32 is_baked : 1; }; @@ -912,6 +899,7 @@ struct AstFunction { // NOTE: This is NULL, unless this function was generated from a polymorphic // procedure call. Then it is set to the token of the call node. OnyxToken* generated_from; + Scope* poly_scope; // NOTE: This is NULL, unless this function is used in a "#export" directive. // It is undefined which name it will have if there are multiple export directives @@ -930,6 +918,10 @@ struct AstFunction { struct Entity* entity_header; struct Entity* entity_body; + + b32 is_exported : 1; + b32 is_foreign : 1; + b32 is_intrinsic : 1; }; typedef struct OverloadOption OverloadOption; @@ -1018,7 +1010,6 @@ struct AstPolySolution { struct AstSolidifiedFunction { AstFunction* func; - Scope* poly_scope; b32 header_complete: 1; }; @@ -1154,7 +1145,6 @@ typedef enum EntityType { Entity_Type_Polymorphic_Proc, Entity_Type_Macro, Entity_Type_Foreign_Function_Header, - Entity_Type_Foreign_Global_Header, Entity_Type_Function_Header, Entity_Type_Global_Header, Entity_Type_Process_Directive, diff --git a/include/wasm.h b/include/wasm.h index 36f93a16..9861affa 100644 --- a/include/wasm.h +++ b/include/wasm.h @@ -662,7 +662,6 @@ typedef struct OnyxWasmModule { u32 next_tls_offset; u32 next_elem_idx; u32 foreign_function_count; - u32 foreign_global_count; i32 *stack_top_ptr; i32 *tls_size_ptr; diff --git a/src/astnodes.c b/src/astnodes.c index e8a4356c..0b246471 100644 --- a/src/astnodes.c +++ b/src/astnodes.c @@ -148,7 +148,6 @@ const char* entity_type_strings[Entity_Type_Count] = { "Polymorphic Proc", "Macro", "Foreign_Function Header", - "Foreign_Global Header", "Function Header", "Global Header", "Process Directive", diff --git a/src/builtins.c b/src/builtins.c index d49c098d..8edafcdb 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -43,7 +43,7 @@ static OnyxToken builtin_stack_top_token = { Token_Type_Symbol, 11, "__stack_to static OnyxToken builtin_tls_base_token = { Token_Type_Symbol, 10, "__tls_base ", { 0 } }; static OnyxToken builtin_tls_size_token = { Token_Type_Symbol, 10, "__tls_size ", { 0 } }; AstNumLit builtin_heap_start = { Ast_Kind_NumLit, Ast_Flag_Const, &builtin_heap_start_token, NULL, NULL, (AstType *) &basic_type_rawptr, NULL, 0 }; -AstGlobal builtin_stack_top = { Ast_Kind_Global, Ast_Flag_Global_Stack_Top, &builtin_stack_top_token, NULL, NULL, (AstType *) &basic_type_rawptr, NULL }; +AstGlobal builtin_stack_top = { Ast_Kind_Global, 0, &builtin_stack_top_token, NULL, NULL, (AstType *) &basic_type_rawptr, NULL }; AstGlobal builtin_tls_base = { Ast_Kind_Global, 0, &builtin_tls_base_token, NULL, NULL, (AstType *) &basic_type_rawptr, NULL }; AstGlobal builtin_tls_size = { Ast_Kind_Global, 0, &builtin_tls_size_token, NULL, NULL, (AstType *) &basic_type_u32, NULL }; diff --git a/src/checker.c b/src/checker.c index 39ffebe3..f0c2c4b7 100644 --- a/src/checker.c +++ b/src/checker.c @@ -540,7 +540,7 @@ CheckStatus check_call(AstCall** pcall) { // NOTE: If we are calling an intrinsic function, translate the // call into an intrinsic call node. - if (callee->flags & Ast_Flag_Intrinsic) { + if (callee->kind == Ast_Kind_Function && callee->is_intrinsic) { call->kind = Ast_Kind_Intrinsic_Call; call->callee = NULL; @@ -1852,7 +1852,7 @@ CheckStatus check_block(AstBlock* block) { } CheckStatus check_function(AstFunction* func) { - if (func->flags & Ast_Flag_Already_Checked) return Check_Success; + if (func->flags & Ast_Flag_Has_Been_Checked) return Check_Success; if (func->entity_header && func->entity_header->state < Entity_State_Code_Gen) YIELD(func->token->pos, "Waiting for procedure header to pass type-checking"); @@ -1872,7 +1872,7 @@ CheckStatus check_function(AstFunction* func) { *expected_return_type = &basic_types[Basic_Kind_Void]; } - func->flags |= Ast_Flag_Already_Checked; + func->flags |= Ast_Flag_Has_Been_Checked; return Check_Success; } @@ -2141,7 +2141,7 @@ CheckStatus check_type(AstType* type) { while (type->kind == Ast_Kind_Type_Alias) type = ((AstTypeAlias *) type)->to; - if (type->flags & Ast_Flag_Already_Checked) return Check_Success; + if (type->flags & Ast_Flag_Has_Been_Checked) return Check_Success; switch (type->kind) { case Ast_Kind_Poly_Call_Type: { @@ -2213,7 +2213,7 @@ CheckStatus check_type(AstType* type) { type = ((AstTypeAlias *) type)->to; } - type->flags |= Ast_Flag_Already_Checked; + type->flags |= Ast_Flag_Has_Been_Checked; return Check_Success; } diff --git a/src/clone.c b/src/clone.c index f0e7cdec..9c5b693c 100644 --- a/src/clone.c +++ b/src/clone.c @@ -392,7 +392,7 @@ AstNode* ast_clone(bh_allocator a, void* n) { AstFunction* df = (AstFunction *) nn; AstFunction* sf = (AstFunction *) node; - if (sf->flags & Ast_Flag_Foreign) return node; + if (sf->is_foreign) return node; df->return_type = (AstType *) ast_clone(a, sf->return_type); df->body = (AstBlock *) ast_clone(a, sf->body); @@ -405,6 +405,7 @@ AstNode* ast_clone(bh_allocator a, void* n) { new_param.local = (AstLocal *) ast_clone(a, param->local); new_param.default_value = (AstTyped *) ast_clone(a, param->default_value); new_param.vararg_kind = param->vararg_kind; + new_param.is_used = param->is_used; bh_arr_push(df->params, new_param); } @@ -483,7 +484,7 @@ AstNode* ast_clone(bh_allocator a, void* n) { AstFunction* clone_function_header(bh_allocator a, AstFunction* func) { if (func->kind != Ast_Kind_Function) return NULL; - if (func->flags & Ast_Flag_Foreign) return func; + if (func->is_foreign) return func; AstFunction* new_func = onyx_ast_node_new(a, sizeof(AstFunction), func->kind); memmove(new_func, func, sizeof(AstFunction)); @@ -497,6 +498,7 @@ AstFunction* clone_function_header(bh_allocator a, AstFunction* func) { new_param.local = (AstLocal *) ast_clone(a, param->local); new_param.default_value = (AstTyped *) ast_clone(a, param->default_value); new_param.vararg_kind = param->vararg_kind; + new_param.is_used = param->is_used; bh_arr_push(new_func->params, new_param); } diff --git a/src/entities.c b/src/entities.c index ef3236fc..9b65e84b 100644 --- a/src/entities.c +++ b/src/entities.c @@ -181,7 +181,7 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s } case Ast_Kind_Function: { - if ((node->flags & Ast_Flag_Foreign) != 0) { + if (((AstFunction *) node)->is_foreign != 0) { ent.type = Entity_Type_Foreign_Function_Header; ent.function = (AstFunction *) node; ENTITY_INSERT(ent); @@ -209,21 +209,14 @@ void add_entities_for_node(bh_arr(Entity *) *target_arr, AstNode* node, Scope* s } case Ast_Kind_Global: { - if ((node->flags & Ast_Flag_Foreign) != 0) { - ent.type = Entity_Type_Foreign_Global_Header; - ent.global = (AstGlobal *) node; - ENTITY_INSERT(ent); - - } else { - ent.type = Entity_Type_Global_Header; - ent.global = (AstGlobal *) node; - ENTITY_INSERT(ent); + ent.type = Entity_Type_Global_Header; + ent.global = (AstGlobal *) node; + ENTITY_INSERT(ent); - ent.id = entities->next_id++; - ent.type = Entity_Type_Global; - ent.global = (AstGlobal *) node; - ENTITY_INSERT(ent); - } + ent.id = entities->next_id++; + ent.type = Entity_Type_Global; + ent.global = (AstGlobal *) node; + ENTITY_INSERT(ent); break; } diff --git a/src/parser.c b/src/parser.c index 77a1ff5d..ad1388da 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1873,9 +1873,7 @@ static AstStructType* parse_struct(OnyxParser* parser) { while (parser->curr->type == '#') { if (parser->hit_unexpected_token) return NULL; - if (parse_possible_directive(parser, "union")) { - s_node->flags |= Ast_Flag_Struct_Is_Union; - } + if (parse_possible_directive(parser, "union")) s_node->is_union = 1; else if (parse_possible_directive(parser, "align")) { AstNumLit* numlit = parse_int_literal(parser); @@ -2004,7 +2002,7 @@ static AstStructType* parse_struct(OnyxParser* parser) { mem->initial_value = initial_value; mem->meta_tags = meta_tags; - if (member_is_used) mem->flags |= Ast_Flag_Struct_Mem_Used; + if (member_is_used) mem->is_used = 1; bh_arr_push(s_node->members, mem); } @@ -2057,7 +2055,7 @@ static void parse_function_params(OnyxParser* parser, AstFunction* func) { curr_param.local->kind = Ast_Kind_Param; if (param_use) { - curr_param.local->flags |= Ast_Flag_Param_Use; + curr_param.is_used = 1; param_use = 0; } @@ -2224,7 +2222,7 @@ static AstFunction* parse_function_definition(OnyxParser* parser, OnyxToken* tok while (parser->curr->type == '#') { if (parse_possible_directive(parser, "intrinsic")) { - func_def->flags |= Ast_Flag_Intrinsic; + func_def->is_intrinsic = 1; if (parser->curr->type == Token_Type_Literal_String) { func_def->intrinsic_name = expect_token(parser, Token_Type_Literal_String); @@ -2235,7 +2233,7 @@ static AstFunction* parse_function_definition(OnyxParser* parser, OnyxToken* tok func_def->foreign_module = expect_token(parser, Token_Type_Literal_String); func_def->foreign_name = expect_token(parser, Token_Type_Literal_String); - func_def->flags |= Ast_Flag_Foreign; + func_def->is_foreign = 1; } // HACK: NullProcHack @@ -2447,22 +2445,6 @@ static AstTyped* parse_global_declaration(OnyxParser* parser) { AstGlobal* global_node = make_node(AstGlobal, Ast_Kind_Global); global_node->token = expect_token(parser, Token_Type_Keyword_Global); - while (parser->curr->type == '#') { - if (parse_possible_directive(parser, "foreign")) { - global_node->foreign_module = expect_token(parser, Token_Type_Literal_String); - global_node->foreign_name = expect_token(parser, Token_Type_Literal_String); - - global_node->flags |= Ast_Flag_Foreign; - } - - else { - OnyxToken* directive_token = expect_token(parser, '#'); - OnyxToken* symbol_token = expect_token(parser, Token_Type_Symbol); - - onyx_report_error(directive_token->pos, "unknown directive '#%b'.", symbol_token->text, symbol_token->length); - } - } - global_node->type_node = parse_type(parser); ENTITY_SUBMIT(global_node); @@ -2478,7 +2460,7 @@ static AstEnumType* parse_enum_declaration(OnyxParser* parser) { while (parser->curr->type == '#') { if (parse_possible_directive(parser, "flags")) { - enum_node->flags |= Ast_Flag_Enum_Is_Flags; + enum_node->is_flags = 1; } else { OnyxToken* directive_token = expect_token(parser, '#'); OnyxToken* symbol_token = expect_token(parser, Token_Type_Symbol); diff --git a/src/polymorph.c b/src/polymorph.c index cd479e9e..2390071e 100644 --- a/src/polymorph.c +++ b/src/polymorph.c @@ -103,7 +103,7 @@ static b32 add_solidified_function_entities(AstSolidifiedFunction solidified_fun .type = Entity_Type_Function_Header, .function = solidified_func.func, .package = NULL, - .scope = solidified_func.poly_scope, + .scope = solidified_func.func->poly_scope, }; entity_bring_to_state(&func_header_entity, Entity_State_Code_Gen); @@ -114,7 +114,7 @@ static b32 add_solidified_function_entities(AstSolidifiedFunction solidified_fun .type = Entity_Type_Function, .function = solidified_func.func, .package = NULL, - .scope = solidified_func.poly_scope, + .scope = solidified_func.func->poly_scope, }; Entity* entity_header = entity_heap_insert(&context.entities, func_header_entity); @@ -143,9 +143,6 @@ static AstSolidifiedFunction generate_solidified_function( OnyxFilePos poly_scope_pos = { 0 }; if (tkn) poly_scope_pos = tkn->pos; - solidified_func.poly_scope = scope_create(context.ast_alloc, pp->poly_scope, poly_scope_pos); - insert_poly_slns_into_scope(solidified_func.poly_scope, slns); - if (header_only) { solidified_func.func = (AstFunction *) clone_function_header(context.ast_alloc, pp->base_func); solidified_func.func->flags |= Ast_Flag_Incomplete_Body; @@ -154,6 +151,9 @@ static AstSolidifiedFunction generate_solidified_function( solidified_func.func = (AstFunction *) ast_clone(context.ast_alloc, pp->base_func); } + solidified_func.func->poly_scope = scope_create(context.ast_alloc, pp->poly_scope, poly_scope_pos); + insert_poly_slns_into_scope(solidified_func.func->poly_scope, slns); + solidified_func.func->flags |= Ast_Flag_From_Polymorphism; solidified_func.func->generated_from = tkn; @@ -732,7 +732,7 @@ AstFunction* polymorphic_proc_build_only_header(AstPolyProc* pp, PolyProcLookupM .type = Entity_Type_Function_Header, .function = solidified_func.func, .package = NULL, - .scope = solidified_func.poly_scope, + .scope = solidified_func.func->poly_scope, }; // HACK: Everything with entity_bring_to_state is a big hack... diff --git a/src/symres.c b/src/symres.c index 172c6b6c..df3b8711 100644 --- a/src/symres.c +++ b/src/symres.c @@ -118,7 +118,7 @@ static SymresStatus symres_struct_type(AstStructType* s_node) { goto struct_symres_done; } - if (member->flags & Ast_Flag_Struct_Mem_Used) { + if (member->is_used) { AstType *used = (AstType *) member->type_node; while (used->kind == Ast_Kind_Type_Alias) { @@ -873,15 +873,9 @@ SymresStatus symres_function_header(AstFunction* func) { } } - if ((func->flags & Ast_Flag_Params_Introduced) == 0) { - bh_arr_each(AstParam, param, func->params) { - symbol_introduce(curr_scope, param->local->token, (AstNode *) param->local); - } - - func->flags |= Ast_Flag_Params_Introduced; - } - bh_arr_each(AstParam, param, func->params) { + symbol_introduce(curr_scope, param->local->token, (AstNode *) param->local); + if (param->local->type_node != NULL) { SYMRES(type, ¶m->local->type_node); } @@ -926,7 +920,7 @@ SymresStatus symres_function(AstFunction* func) { // The 'use t : T' member requires completely knowing the type of T, to know which // members should be brought in. At the moment, that requires completely building the // type of Foo($T). - if ((param->local->flags & Ast_Flag_Param_Use) != 0 && param->use_processed == 0) { + if (param->is_used && !param->use_processed) { if (param->local->type_node != NULL && param->local->type == NULL) { param->local->type = type_build_from_ast(context.ast_alloc, param->local->type_node); @@ -1015,7 +1009,7 @@ static SymresStatus symres_enum(AstEnumType* enum_node) { type_build_from_ast(context.ast_alloc, (AstType *) enum_node); - u64 next_assign_value = (enum_node->flags & Ast_Flag_Enum_Is_Flags) ? 1 : 0; + u64 next_assign_value = enum_node->is_flags ? 1 : 0; bh_arr_each(AstEnumValue *, value, enum_node->values) { symbol_introduce(enum_node->scope, (*value)->token, (AstNode *) *value); (*value)->type = enum_node->etcache; @@ -1043,7 +1037,7 @@ static SymresStatus symres_enum(AstEnumType* enum_node) { (*value)->flags |= Ast_Flag_Comptime; - if (enum_node->flags & Ast_Flag_Enum_Is_Flags) { + if (enum_node->is_flags) { next_assign_value <<= 1; } else { next_assign_value++; @@ -1165,19 +1159,19 @@ static SymresStatus symres_process_directive(AstNode* directive) { AstDirectiveExport *export = (AstDirectiveExport *) directive; SYMRES(expression, &export->export); - export->export->flags |= Ast_Flag_Exported; if (export->export->kind == Ast_Kind_Function) { AstFunction *func = (AstFunction *) export->export; func->exported_name = export->export_name; + func->is_exported = 1; - if ((func->flags & Ast_Flag_Exported) != 0) { - if ((func->flags & Ast_Flag_Foreign) != 0) { + if (func->is_exported) { + if (func->is_foreign) { onyx_report_error(export->token->pos, "exporting a foreign function"); return Symres_Error; } - if ((func->flags & Ast_Flag_Intrinsic) != 0) { + if (func->is_intrinsic) { onyx_report_error(export->token->pos, "exporting a intrinsic function"); return Symres_Error; } @@ -1246,7 +1240,6 @@ void symres_entity(Entity* ent) { case Entity_Type_Function_Header: ss = symres_function_header(ent->function); break; case Entity_Type_Function: ss = symres_function(ent->function); break; - case Entity_Type_Foreign_Global_Header: case Entity_Type_Global_Header: ss = symres_global(ent->global); break; case Entity_Type_Use_Package: diff --git a/src/types.c b/src/types.c index f3fbae9d..cfa606fa 100644 --- a/src/types.c +++ b/src/types.c @@ -352,7 +352,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { s_node->stcache_is_valid = 1; - b32 is_union = (s_node->flags & Ast_Flag_Struct_Is_Union) != 0; + b32 is_union = s_node->is_union; u32 size = 0; u32 offset = 0; u32 alignment = 1, mem_alignment; @@ -385,7 +385,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { .name = bh_strdup(alloc, (*member)->token->text), .initial_value = &(*member)->initial_value, .included_through_use = 0, - .used = (((*member)->flags & Ast_Flag_Struct_Mem_Used) != 0), + .used = (*member)->is_used, .meta_tags = (*member)->meta_tags, }; @@ -465,7 +465,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { enum_type->ast_type = type_node; enum_type->Enum.backing = enum_node->backing_type; enum_type->Enum.name = enum_node->name; - enum_type->Enum.is_flags = enum_node->flags & Ast_Flag_Enum_Is_Flags; + enum_type->Enum.is_flags = enum_node->is_flags; type_register(enum_type); return enum_type; diff --git a/src/utils.c b/src/utils.c index ef91b57c..537044b3 100644 --- a/src/utils.c +++ b/src/utils.c @@ -497,19 +497,8 @@ void expand_macro(AstCall** pcall, AstFunction* template) { (AstNode *) ((AstArgument *) call->args.values[i])->value); } - if (template->flags & Ast_Flag_From_Polymorphism) { - // SLOW DUMB HACKY WAY TO DO THIS!!!!! FIX IT!!!!! - - AstPolyProc* pp = (AstPolyProc *) macro->body; - bh_table_each_start(AstSolidifiedFunction, pp->concrete_funcs); - - if (value.func == template) { - scope_include(argument_scope, value.poly_scope, call->token->pos); - break; - } - - bh_table_each_end; - } + if (template->poly_scope != NULL) + scope_include(argument_scope, template->poly_scope, call->token->pos); *(AstNode **) pcall = subst; return; @@ -558,7 +547,7 @@ AstFunction* macro_resolve_header(AstMacro* macro, Arguments* args, OnyxToken* c .type = Entity_Type_Function_Header, .function = solidified_func.func, .package = NULL, - .scope = solidified_func.poly_scope, + .scope = solidified_func.func->poly_scope, }; b32 successful = entity_bring_to_state(&func_header_entity, Entity_State_Code_Gen); diff --git a/src/wasm.c b/src/wasm.c index 1d1a20f1..bcb3ae42 100644 --- a/src/wasm.c +++ b/src/wasm.c @@ -3155,12 +3155,12 @@ static i32 get_element_idx(OnyxWasmModule* mod, AstFunction* func) { static inline b32 should_emit_function(AstFunction* fd) { // NOTE: Don't output intrinsic functions - if (fd->flags & Ast_Flag_Intrinsic) return 0; + if (fd->is_intrinsic) return 0; // 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->flags & Ast_Flag_Exported) { + if (fd->is_exported) { return 1; } else { return 0; @@ -3319,27 +3319,12 @@ static void emit_global(OnyxWasmModule* module, AstGlobal* global) { default: assert(("Invalid global type", 0)); break; } - bh_arr_set_at(module->globals, global_idx - module->foreign_global_count, glob); + bh_arr_set_at(module->globals, global_idx, glob); if (global == &builtin_stack_top) - module->stack_top_ptr = &module->globals[global_idx - module->foreign_global_count].initial_value[0].data.i1; + module->stack_top_ptr = &module->globals[global_idx].initial_value[0].data.i1; if (global == &builtin_tls_size) - module->tls_size_ptr = &module->globals[global_idx - module->foreign_global_count].initial_value[0].data.i1; -} - -static void emit_foreign_global(OnyxWasmModule* module, AstGlobal* global) { - WasmType global_type = onyx_type_to_wasm_type(global->type); - - if (global->flags & Ast_Flag_Foreign) { - WasmImport import = { - .kind = WASM_FOREIGN_GLOBAL, - .idx = global_type, - .mod = bh_aprintf(global_heap_allocator, "%b", global->foreign_module->text, global->foreign_module->length), - .name = bh_aprintf(global_heap_allocator, "%b", global->foreign_name->text, global->foreign_name->length), - }; - - bh_arr_push(module->imports, import); - } + module->tls_size_ptr = &module->globals[global_idx].initial_value[0].data.i1; } static void emit_string_literal(OnyxWasmModule* mod, AstStrLit* strlit) { @@ -3673,7 +3658,6 @@ OnyxWasmModule onyx_wasm_module_create(bh_allocator alloc) { .stack_base_idx = 0, .foreign_function_count = 0, - .foreign_global_count = 0, .null_proc_func_idx = -1, }; @@ -3775,11 +3759,6 @@ void emit_entity(Entity* ent) { } break; - case Entity_Type_Foreign_Global_Header: - module->foreign_global_count++; - emit_foreign_global(module, ent->global); - // fallthrough - case Entity_Type_Global_Header: bh_imap_put(&module->index_map, (u64) ent->global, module->next_global_idx++); break; diff --git a/src/wasm_output.c b/src/wasm_output.c index 69e28f06..b4141ca6 100644 --- a/src/wasm_output.c +++ b/src/wasm_output.c @@ -244,14 +244,6 @@ static i32 output_importsection(OnyxWasmModule* module, bh_buffer* buff) { bh_buffer_append(&vec_buff, leb, leb_len); break; - case WASM_FOREIGN_GLOBAL: - leb = uint_to_uleb128((u64) import->idx, &leb_len); - bh_buffer_append(&vec_buff, leb, leb_len); - - // NOTE: All foreign globals are mutable - bh_buffer_write_byte(&vec_buff, 0x01); - break; - case WASM_FOREIGN_MEMORY: output_limits(import->min, import->max, import->shared, &vec_buff); break; -- 2.25.1