Type info uses slices now! Fixed a case of slice needing to have a completed type
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
@@ -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
|
||||
@@ -57,3 +57,4 @@ GetTypeInfo :: (type: Type): *Type_Info
|
||||
if id >= type_infos_len
|
||||
return 0
|
||||
return type_infos + id
|
||||
*/
|
||||
Reference in New Issue
Block a user