map type internal reorganization

This commit is contained in:
gingerBill
2020-11-23 16:56:31 +00:00
parent 67bc35e882
commit 4762d2f2d1
7 changed files with 66 additions and 67 deletions

View File

@@ -2784,24 +2784,23 @@ void init_map_entry_type(Type *type) {
if (type->Map.entry_type != nullptr) return;
// NOTE(bill): The preload types may have not been set yet
GB_ASSERT(t_map_key != nullptr);
GB_ASSERT(t_map_hash != nullptr);
Type *entry_type = alloc_type_struct();
/*
struct {
hash: __MapKey;
next: int;
key: Key;
value: Value;
key: runtime.Map_Key,
next: int,
value: Value,
}
*/
Ast *dummy_node = alloc_ast_node(nullptr, Ast_Invalid);
Scope *s = create_scope(builtin_pkg->scope);
auto fields = array_make<Entity *>(permanent_allocator(), 0, 3);
array_add(&fields, alloc_entity_field(s, make_token_ident(str_lit("key")), t_map_key, false, 0, EntityState_Resolved));
array_add(&fields, alloc_entity_field(s, make_token_ident(str_lit("next")), t_int, false, 1, EntityState_Resolved));
array_add(&fields, alloc_entity_field(s, make_token_ident(str_lit("value")), type->Map.value, false, 2, EntityState_Resolved));
auto fields = array_make<Entity *>(permanent_allocator(), 0, 4);
array_add(&fields, alloc_entity_field(s, make_token_ident(str_lit("key")), t_map_hash, false, cast(i32)fields.count, EntityState_Resolved));
array_add(&fields, alloc_entity_field(s, make_token_ident(str_lit("next")), t_int, false, cast(i32)fields.count, EntityState_Resolved));
array_add(&fields, alloc_entity_field(s, make_token_ident(str_lit("value")), type->Map.value, false, cast(i32)fields.count, EntityState_Resolved));
entry_type->Struct.fields = fields;

View File

@@ -2278,14 +2278,14 @@ void init_core_source_code_location(Checker *c) {
}
void init_core_map_type(Checker *c) {
if (t_map_key == nullptr) {
Entity *e = find_core_entity(c, str_lit("Map_Key"));
if (t_map_hash == nullptr) {
Entity *e = find_core_entity(c, str_lit("Map_Hash"));
if (e->state == EntityState_Unresolved) {
auto ctx = c->init_ctx;
check_entity_decl(&ctx, e, nullptr, nullptr);
}
t_map_key = e->type;
GB_ASSERT(t_map_key != nullptr);
t_map_hash = e->type;
GB_ASSERT(t_map_hash != nullptr);
}
if (t_map_header == nullptr) {

View File

@@ -3608,7 +3608,7 @@ irValue *ir_gen_map_header(irProcedure *proc, irValue *map_val_ptr, Type *map_ty
irValue *ir_gen_map_key(irProcedure *proc, irValue *key, Type *key_type) {
Type *hash_type = t_u64;
irValue *v = ir_add_local_generated(proc, t_map_key, true);
irValue *v = ir_add_local_generated(proc, t_map_hash, true);
Type *t = base_type(ir_type(key));
key = ir_emit_conv(proc, key, key_type);

View File

@@ -10259,7 +10259,7 @@ lbValue lb_gen_map_header(lbProcedure *p, lbValue map_val_ptr, Type *map_type) {
lbValue lb_gen_map_key(lbProcedure *p, lbValue key, Type *key_type) {
Type *hash_type = t_u64;
lbAddr v = lb_add_local_generated(p, t_map_key, true);
lbAddr v = lb_add_local_generated(p, t_map_hash, true);
lbValue vp = lb_addr_get_ptr(p, v);
Type *t = base_type(key.type);
key = lb_emit_conv(p, key, key_type);

View File

@@ -684,7 +684,7 @@ gb_global Type *t_context_ptr = nullptr;
gb_global Type *t_source_code_location = nullptr;
gb_global Type *t_source_code_location_ptr = nullptr;
gb_global Type *t_map_key = nullptr;
gb_global Type *t_map_hash = nullptr;
gb_global Type *t_map_header = nullptr;
gb_global Type *t_vector_x86_mmx = nullptr;