From: Brendan Hansen Date: Mon, 4 Jan 2021 15:26:22 +0000 (-0600) Subject: struct member defaults are processed later in the pipeline X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=33e3ef6a26a412e35bb0d8f4c94c9a9ffd5356b5;p=onyx.git struct member defaults are processed later in the pipeline --- diff --git a/bin/onyx b/bin/onyx index bd63eb03..6ea6feeb 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/build.sh b/build.sh index 7d326e92..9462fc75 100644 --- a/build.sh +++ b/build.sh @@ -3,9 +3,14 @@ C_FILES="onyx onyxbuiltins onyxchecker onyxclone onyxdoc onyxentities onyxerrors onyxlex onyxparser onyxsempass onyxsymres onyxtypes onyxutils onyxwasm" TARGET='./bin/onyx' CC='gcc' -FLAGS='-O3 -I./include' -BUILD_DIR='./build' +if [ "$1" = "debug" ]; then + FLAGS='-g3 -I./include' +else + FLAGS='-O3 -I./include' +fi + +BUILD_DIR='./build' mkdir -p "$BUILD_DIR" for file in $C_FILES ; do diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 315ab55b..57ebca9a 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -807,6 +807,7 @@ typedef enum EntityType { Entity_Type_Foreign_Global_Header, Entity_Type_Function_Header, Entity_Type_Global_Header, + Entity_Type_Struct_Member_Default, Entity_Type_Memory_Reservation, Entity_Type_Expression, Entity_Type_Global, diff --git a/src/onyx.c b/src/onyx.c index 9f787456..87ef6ebb 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -338,9 +338,14 @@ static void merge_parse_results(CompilerState* compiler_state, ParseResults* res break; } - case Ast_Kind_Type_Alias: case Ast_Kind_Struct_Type: case Ast_Kind_Poly_Struct_Type: { + ent.type = Entity_Type_Struct_Member_Default; + ent.type_alias = (AstType *) node; + entity_heap_insert(&compiler_state->prog_info.entities, ent); + // fallthrough + } + case Ast_Kind_Type_Alias: { ent.type = Entity_Type_Type_Alias; ent.type_alias = (AstType *) node; entity_heap_insert(&compiler_state->prog_info.entities, ent); diff --git a/src/onyxsymres.c b/src/onyxsymres.c index 97749ccf..a4d0a52a 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -33,6 +33,7 @@ static void symres_use_package(AstUsePackage* package); static void symres_enum(AstEnumType* enum_node); static void symres_memres_type(AstMemRes** memres); static void symres_memres(AstMemRes** memres); +static void symres_struct_defaults(AstType* st); static AstFieldAccess* make_field_access(AstTyped* node, char* field) { AstFieldAccess* fa = onyx_ast_node_new(semstate.node_allocator, sizeof(AstFieldAccess), Ast_Kind_Field_Access); @@ -147,10 +148,6 @@ AstType* symres_type(AstType* type) { return type; } } - - if (member->initial_value != NULL) { - symres_expression(&member->initial_value); - } } return type; @@ -897,6 +894,32 @@ static void symres_memres(AstMemRes** memres) { } } +static void symres_struct_defaults(AstType* t) { + switch (t->kind) { + case Ast_Kind_Struct_Type: { + AstStructType* st = (AstStructType *) t; + bh_arr_each(AstStructMember *, smem, st->members) { + if ((*smem)->initial_value != NULL) { + symres_expression(&(*smem)->initial_value); + } + } + break; + } + + case Ast_Kind_Poly_Struct_Type: { + AstPolyStructType* st = (AstPolyStructType *) t; + bh_arr_each(AstStructMember *, smem, st->base_struct->members) { + if ((*smem)->initial_value != NULL) { + symres_expression(&(*smem)->initial_value); + } + } + break; + } + + default: break; + } +} + static void symres_polyproc(AstPolyProc* pp) { pp->poly_scope = semstate.curr_scope; } @@ -933,6 +956,7 @@ void symres_entity(Entity* ent) { case Entity_Type_Memory_Reservation: symres_memres(&ent->mem_res); break; case Entity_Type_Polymorphic_Proc: symres_polyproc(ent->poly_proc); break; case Entity_Type_String_Literal: symres_expression(&ent->expr); break; + case Entity_Type_Struct_Member_Default: symres_struct_defaults((AstType *) ent->type_alias); break; default: break; } diff --git a/src/onyxutils.c b/src/onyxutils.c index 4a2c57bd..51530275 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -122,6 +122,7 @@ const char* entity_type_strings[Entity_Type_Count] = { "Foreign_Global Header", "Function Header", "Global Header", + "Struct Member Default", "Memory Reservation", "Expression", "Global",