mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-12 22:31:25 -07:00
Map type info and fmt printing
This commit is contained in:
+7
-9
@@ -1097,8 +1097,8 @@ Type *make_map_tuple_type(gbAllocator a, Type *value) {
|
||||
Type *t = make_type_tuple(a);
|
||||
t->Tuple.variables = gb_alloc_array(a, Entity *, 2);
|
||||
t->Tuple.variable_count = 2;
|
||||
t->Tuple.variables[0] = make_entity_param(a, NULL, blank_token, value, false, false);
|
||||
t->Tuple.variables[1] = make_entity_param(a, NULL, blank_token, t_bool, false, false);
|
||||
t->Tuple.variables[0] = make_entity_field(a, NULL, blank_token, value, false, 0);
|
||||
t->Tuple.variables[1] = make_entity_field(a, NULL, blank_token, t_bool, false, 1);
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -1148,9 +1148,9 @@ void check_map_type(Checker *c, Type *type, AstNode *node) {
|
||||
|
||||
isize field_count = 3;
|
||||
Entity **fields = gb_alloc_array(a, Entity *, field_count);
|
||||
fields[0] = make_entity_field(a, c->context.scope, make_token_ident(str_lit("key")), t_map_key, false, false);
|
||||
fields[1] = make_entity_field(a, c->context.scope, make_token_ident(str_lit("next")), t_int, false, false);
|
||||
fields[2] = make_entity_field(a, c->context.scope, make_token_ident(str_lit("value")), value, false, false);
|
||||
fields[0] = make_entity_field(a, c->context.scope, make_token_ident(str_lit("key")), t_map_key, false, 0);
|
||||
fields[1] = make_entity_field(a, c->context.scope, make_token_ident(str_lit("next")), t_int, false, 1);
|
||||
fields[2] = make_entity_field(a, c->context.scope, make_token_ident(str_lit("value")), value, false, 2);
|
||||
|
||||
check_close_scope(c);
|
||||
|
||||
@@ -1159,7 +1159,6 @@ void check_map_type(Checker *c, Type *type, AstNode *node) {
|
||||
entry_type->Record.field_count = field_count;
|
||||
|
||||
type_set_offsets(c->sizes, a, entry_type);
|
||||
|
||||
type->Map.entry_type = entry_type;
|
||||
}
|
||||
|
||||
@@ -1181,8 +1180,8 @@ void check_map_type(Checker *c, Type *type, AstNode *node) {
|
||||
|
||||
isize field_count = 2;
|
||||
Entity **fields = gb_alloc_array(a, Entity *, field_count);
|
||||
fields[0] = make_entity_field(a, c->context.scope, make_token_ident(str_lit("hashes")), hashes_type, false, false);
|
||||
fields[1] = make_entity_field(a, c->context.scope, make_token_ident(str_lit("entries")), entries_type, false, false);
|
||||
fields[0] = make_entity_field(a, c->context.scope, make_token_ident(str_lit("hashes")), hashes_type, false, 0);
|
||||
fields[1] = make_entity_field(a, c->context.scope, make_token_ident(str_lit("entries")), entries_type, false, 1);
|
||||
|
||||
check_close_scope(c);
|
||||
|
||||
@@ -1191,7 +1190,6 @@ void check_map_type(Checker *c, Type *type, AstNode *node) {
|
||||
generated_struct_type->Record.field_count = field_count;
|
||||
|
||||
type_set_offsets(c->sizes, a, generated_struct_type);
|
||||
|
||||
type->Map.generated_struct_type = generated_struct_type;
|
||||
}
|
||||
|
||||
|
||||
+11
-3
@@ -958,6 +958,12 @@ void add_type_info_type(Checker *c, Type *t) {
|
||||
}
|
||||
} break;
|
||||
|
||||
case Type_Map: {
|
||||
add_type_info_type(c, bt->Map.key);
|
||||
add_type_info_type(c, bt->Map.value);
|
||||
add_type_info_type(c, bt->Map.generated_struct_type);
|
||||
} break;
|
||||
|
||||
case Type_Tuple:
|
||||
for (isize i = 0; i < bt->Tuple.variable_count; i++) {
|
||||
Entity *var = bt->Tuple.variables[i];
|
||||
@@ -1093,7 +1099,7 @@ void init_preload(Checker *c) {
|
||||
|
||||
|
||||
|
||||
if (record->field_count != 19) {
|
||||
if (record->field_count != 20) {
|
||||
compiler_error("Invalid `Type_Info` layout");
|
||||
}
|
||||
t_type_info_named = record->fields[ 1]->type;
|
||||
@@ -1114,6 +1120,7 @@ void init_preload(Checker *c) {
|
||||
t_type_info_union = record->fields[16]->type;
|
||||
t_type_info_raw_union = record->fields[17]->type;
|
||||
t_type_info_enum = record->fields[18]->type;
|
||||
t_type_info_map = record->fields[19]->type;
|
||||
|
||||
t_type_info_named_ptr = make_type_pointer(heap_allocator(), t_type_info_named);
|
||||
t_type_info_integer_ptr = make_type_pointer(heap_allocator(), t_type_info_integer);
|
||||
@@ -1133,6 +1140,7 @@ void init_preload(Checker *c) {
|
||||
t_type_info_union_ptr = make_type_pointer(heap_allocator(), t_type_info_union);
|
||||
t_type_info_raw_union_ptr = make_type_pointer(heap_allocator(), t_type_info_raw_union);
|
||||
t_type_info_enum_ptr = make_type_pointer(heap_allocator(), t_type_info_enum);
|
||||
t_type_info_map_ptr = make_type_pointer(heap_allocator(), t_type_info_map);
|
||||
}
|
||||
|
||||
if (t_allocator == NULL) {
|
||||
@@ -1155,12 +1163,12 @@ void init_preload(Checker *c) {
|
||||
}
|
||||
|
||||
if (t_map_key == NULL) {
|
||||
Entity *e = find_core_entity(c, str_lit("Map_Key"));
|
||||
Entity *e = find_core_entity(c, str_lit("__Map_Key"));
|
||||
t_map_key = e->type;
|
||||
}
|
||||
|
||||
if (t_map_header == NULL) {
|
||||
Entity *e = find_core_entity(c, str_lit("Map_Header"));
|
||||
Entity *e = find_core_entity(c, str_lit("__Map_Header"));
|
||||
t_map_header = e->type;
|
||||
}
|
||||
|
||||
|
||||
@@ -6286,14 +6286,16 @@ void ir_gen_tree(irGen *s) {
|
||||
tag = ir_emit_conv(proc, ti_ptr, t_type_info_struct_ptr);
|
||||
|
||||
{
|
||||
irValue *packed = ir_make_const_bool(a, t->Record.struct_is_packed);
|
||||
irValue *ordered = ir_make_const_bool(a, t->Record.struct_is_ordered);
|
||||
irValue *size = ir_make_const_int(a, type_size_of(m->sizes, a, t));
|
||||
irValue *align = ir_make_const_int(a, type_align_of(m->sizes, a, t));
|
||||
irValue *size = ir_make_const_int(a, type_size_of(m->sizes, a, t));
|
||||
irValue *align = ir_make_const_int(a, type_align_of(m->sizes, a, t));
|
||||
irValue *packed = ir_make_const_bool(a, t->Record.struct_is_packed);
|
||||
irValue *ordered = ir_make_const_bool(a, t->Record.struct_is_ordered);
|
||||
irValue *custom_align = ir_make_const_bool(a, t->Record.custom_align);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 1), size);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 2), align);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 3), packed);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 4), ordered);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 5), custom_align);
|
||||
}
|
||||
|
||||
irValue *memory = ir_type_info_member_offset(proc, type_info_member_data, t->Record.field_count, &type_info_member_index);
|
||||
@@ -6516,6 +6518,20 @@ void ir_gen_tree(irGen *s) {
|
||||
|
||||
// TODO(bill): Type_Info for procedures
|
||||
} break;
|
||||
|
||||
case Type_Map: {
|
||||
tag = ir_emit_conv(proc, ti_ptr, t_type_info_map_ptr);
|
||||
|
||||
irValue *key = ir_emit_struct_ep(proc, tag, 0);
|
||||
irValue *value = ir_emit_struct_ep(proc, tag, 1);
|
||||
irValue *generated_struct = ir_emit_struct_ep(proc, tag, 2);
|
||||
irValue *count = ir_emit_struct_ep(proc, tag, 3);
|
||||
|
||||
ir_emit_store(proc, key, ir_get_type_info_ptr(proc, type_info_data, t->Map.key));
|
||||
ir_emit_store(proc, value, ir_get_type_info_ptr(proc, type_info_data, t->Map.value));
|
||||
ir_emit_store(proc, generated_struct, ir_get_type_info_ptr(proc, type_info_data, t->Map.generated_struct_type));
|
||||
ir_emit_store(proc, count, ir_make_const_int(a, t->Map.count));
|
||||
} break;
|
||||
}
|
||||
|
||||
if (tag != NULL) {
|
||||
|
||||
+4
-4
@@ -300,6 +300,7 @@ gb_global Type *t_type_info_struct = NULL;
|
||||
gb_global Type *t_type_info_union = NULL;
|
||||
gb_global Type *t_type_info_raw_union = NULL;
|
||||
gb_global Type *t_type_info_enum = NULL;
|
||||
gb_global Type *t_type_info_map = NULL;
|
||||
|
||||
|
||||
gb_global Type *t_type_info_named_ptr = NULL;
|
||||
@@ -320,6 +321,7 @@ gb_global Type *t_type_info_struct_ptr = NULL;
|
||||
gb_global Type *t_type_info_union_ptr = NULL;
|
||||
gb_global Type *t_type_info_raw_union_ptr = NULL;
|
||||
gb_global Type *t_type_info_enum_ptr = NULL;
|
||||
gb_global Type *t_type_info_map_ptr = NULL;
|
||||
|
||||
|
||||
|
||||
@@ -1561,8 +1563,7 @@ i64 type_align_of_internal(BaseTypeSizes s, gbAllocator allocator, Type *t, Type
|
||||
|
||||
case Type_Map: {
|
||||
if (t->Map.count == 0) { // Dynamic
|
||||
// NOTE(bill): same as a dynamic array
|
||||
return s.word_size;
|
||||
return type_align_of_internal(s, allocator, t->Map.generated_struct_type, path);
|
||||
}
|
||||
GB_PANIC("TODO(bill): Fixed map alignment");
|
||||
} break;
|
||||
@@ -1778,8 +1779,7 @@ i64 type_size_of_internal(BaseTypeSizes s, gbAllocator allocator, Type *t, TypeP
|
||||
|
||||
case Type_Map: {
|
||||
if (t->Map.count == 0) { // Dynamic
|
||||
// NOTE(bill): same as a two dynamic arrays
|
||||
return 2 * type_size_of_internal(s, allocator, t_raw_dynamic_array, path);
|
||||
return type_size_of_internal(s, allocator, t->Map.generated_struct_type, path);
|
||||
}
|
||||
GB_PANIC("TODO(bill): Fixed map size");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user