diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index 8bc718a..c42f418 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -980,16 +980,17 @@ compile_to_c_code() { } break; case TYPE_LAMBDA: { gen(".lambda_return = %d, ", t->func.ret->type_id); - gen(".lambda_argument_count = %d, ", t->func.args.len); - gen(".lambda_arguments = (Type_Info[%d]){", t->func.args.len); + gen(".lambda_arguments.len = %d, ", t->func.args.len); + gen(".lambda_arguments.data = (Type_Info[%d]){", t->func.args.len); For_Named(t->func.args, arg) { gen("{.type = %d}, ", arg->type_id); } gen("}"); } break; + case TYPE_UNION: case TYPE_STRUCT: { - gen(".struct_member_count = %d, ", t->agg.members.len); - gen(".struct_members = (Type_Info_Struct_Member[]){"); + gen(".struct_members.len = %d, ", t->agg.members.len); + gen(".struct_members.data = (Type_Info_Struct_Member[]){"); For_Named(t->agg.members, m) { gen("{.name = (%Q){(uint8_t *)\"%Q\", %d}, .type = %d, .offset = %d}, ", prefixed_string_type, m.name, m.name.len, m.type->type_id, m.offset); } diff --git a/core_compiler.cpp b/core_compiler.cpp index a9e4e07..bb19652 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -356,10 +356,8 @@ Type_Info :: struct base_type: Type array_size: S64 - struct_member_count: S64 - struct_members: *Type_Info_Struct_Member - lambda_argument_count: S64 - lambda_arguments: *Type_Info + struct_members: []Type_Info_Struct_Member + lambda_arguments: []Type_Info lambda_return: Type type_infos_len: S64 #foreign diff --git a/core_typechecking.cpp b/core_typechecking.cpp index acacb50..f10547b 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -1171,9 +1171,9 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str Operand type = resolve_expr(node->base, AST_CANT_BE_NULL, 0, 0); Operand expr = require_const_int(node->expr, AST_CAN_BE_NULL); if (type.type != pctx->type_type) compiler_error(node->pos, "Prefix array operator is only allowed on types"); - type_complete(type.type_val); if (node->expr) { + type_complete(type.type_val); type.type_val = type_array(type.type_val, bigint_as_unsigned(&expr.big_int_val)); } else { @@ -1181,7 +1181,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str } // If this is a type we want to rewrite that type - // int o an integer constant which should be an id + // into an integer constant which should be an id // of that type if (!is_flag_set(flags, RESOLVE_TYPESPEC)) { rewrite_into_const(node, Ast_Array, type.value); @@ -1287,7 +1287,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str // Make sure it's a type but also not a type id Ast_Type *type = left.type; if (type == pctx->type_type && left.type_val) { - if (is_enum(left.type_val) || is_struct(left.type_val)) { + if (is_enum(left.type_val) || is_struct(left.type_val) || is_union(left.type_val)) { type = left.type_val; } } diff --git a/core_types.cpp b/core_types.cpp index fa9199e..c2ffc4c 100644 --- a/core_types.cpp +++ b/core_types.cpp @@ -272,12 +272,10 @@ type_struct_complete(Ast_Type *type, Ast_Decl *node) { assert(it->type->kind != TYPE_INCOMPLETE); assert(is_pow2(it->type->align)); - Ast_Resolved_Member m = {}; - m.offset = type->size; - type->align = max(type->align, it->type->align); type->size = max(it->type->size, type->size); + Ast_Resolved_Member m = {}; m.name = it->name; m.value = it->value; members.add(m); diff --git a/examples/unions.core b/examples/unions.core index d491a51..185fc44 100644 --- a/examples/unions.core +++ b/examples/unions.core @@ -7,9 +7,6 @@ C :: struct a: int b: int -Test :: struct - a: int - main :: (argc: int, argv: **char): int memes: U memes.b = 10 @@ -17,7 +14,14 @@ main :: (argc: int, argv: **char): int Assert(memes.a != 0) compound: U = {b = 10.0} - c2: C = {b = 10} + Assert(compound.b == 10) + + t := U + ti := GetTypeInfo(t) + Assert(ti.size == SizeOf(U)) + + + /* @reproduction @todo ``` diff --git a/modules/Language.core b/modules/Language.core index 1c3d322..808c64e 100644 --- a/modules/Language.core +++ b/modules/Language.core @@ -1,4 +1,4 @@ - +/* Any :: struct data: *void type: Type @@ -43,10 +43,10 @@ Type_Info :: struct base_type: Type array_size: S64 - struct_member_count: S64 struct_members: *Type_Info_Struct_Member - lambda_argument_count: S64 + struct_member_count: S64 lambda_arguments: *Type_Info + lambda_argument_count: S64 lambda_return: Type type_infos_len: S64 #foreign @@ -56,4 +56,5 @@ GetTypeInfo :: (type: Type): *Type_Info id := type->S64 if id >= type_infos_len return 0 - return type_infos + id \ No newline at end of file + return type_infos + id + */ \ No newline at end of file