aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas T Jonsson <mail@andreasjonsson.se>2024-05-13 09:21:32 +0200
committerAndreas T Jonsson <mail@andreasjonsson.se>2024-05-13 09:21:32 +0200
commit5d82f0cad5e0500d577bb03e1c175716d4d8b995 (patch)
tree86b4662246c85cfa2a58ee22d101cc8ffc14df54 /src
parentf428e30211c3113ac7c7918f9a0f5c03cc7b4669 (diff)
parent1183f4794b5bd3f1afddbb351c941a8a617a085f (diff)
Merge branch 'master' into netbsd
Diffstat (limited to 'src')
-rw-r--r--src/check_decl.cpp2
-rw-r--r--src/check_expr.cpp1
-rw-r--r--src/check_stmt.cpp34
-rw-r--r--src/check_type.cpp9
-rw-r--r--src/docs_writer.cpp34
-rw-r--r--src/llvm_backend_expr.cpp4
-rw-r--r--src/llvm_backend_proc.cpp10
-rw-r--r--src/parser.cpp2
-rw-r--r--src/ptr_map.cpp438
-rw-r--r--src/types.cpp4
10 files changed, 497 insertions, 41 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index 441c8000d..1ec366ae7 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -1619,7 +1619,7 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
if (e->kind != Entity_Variable) {
continue;
}
- if (is_type_polymorphic(e->type)) {
+ if (is_type_polymorphic(e->type) && is_type_polymorphic_record_unspecialized(e->type)) {
gbString s = type_to_string(e->type);
char const *msg = "Unspecialized polymorphic types are not allowed in procedure parameters, got %s";
if (e->Variable.type_expr) {
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index f0c33d9d8..08f488642 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -10788,6 +10788,7 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast
return Expr_Expr;
case_end;
+ case Ast_DistinctType:
case Ast_TypeidType:
case Ast_PolyType:
case Ast_ProcType:
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index cccbab4f6..c018077f9 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -161,8 +161,7 @@ gb_internal bool check_is_terminating_list(Slice<Ast *> const &stmts, String con
}
gb_internal bool check_has_break_list(Slice<Ast *> const &stmts, String const &label, bool implicit) {
- for_array(i, stmts) {
- Ast *stmt = stmts[i];
+ for (Ast *stmt : stmts) {
if (check_has_break(stmt, label, implicit)) {
return true;
}
@@ -170,6 +169,14 @@ gb_internal bool check_has_break_list(Slice<Ast *> const &stmts, String const &l
return false;
}
+gb_internal bool check_has_break_expr_list(Slice<Ast *> const &exprs, String const &label) {
+ for (Ast *expr : exprs) {
+ if (expr && expr->viral_state_flags & ViralStateFlag_ContainsOrBreak) {
+ return true;
+ }
+ }
+ return false;
+}
gb_internal bool check_has_break(Ast *stmt, String const &label, bool implicit) {
switch (stmt->kind) {
@@ -227,6 +234,20 @@ gb_internal bool check_has_break(Ast *stmt, String const &label, bool implicit)
return true;
}
break;
+
+ case Ast_ValueDecl:
+ if (stmt->ValueDecl.is_mutable && check_has_break_expr_list(stmt->ValueDecl.values, label)) {
+ return true;
+ }
+ break;
+ case Ast_AssignStmt:
+ if (check_has_break_expr_list(stmt->AssignStmt.lhs, label)) {
+ return true;
+ }
+ if (check_has_break_expr_list(stmt->AssignStmt.rhs, label)) {
+ return true;
+ }
+ break;
}
return false;
@@ -250,6 +271,15 @@ gb_internal bool check_is_terminating(Ast *node, String const &label) {
return check_is_terminating(unparen_expr(es->expr), label);
case_end;
+ case_ast_node(vd, ValueDecl, node);
+ return check_has_break_expr_list(vd->values, label);
+ case_end;
+
+ case_ast_node(as, AssignStmt, node);
+ return check_has_break_expr_list(as->lhs, label) ||
+ check_has_break_expr_list(as->rhs, label);
+ case_end;
+
case_ast_node(bs, BranchStmt, node);
return bs->token.kind == Token_fallthrough;
case_end;
diff --git a/src/check_type.cpp b/src/check_type.cpp
index 11e332757..4df0c5d19 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -1133,18 +1133,21 @@ gb_internal void check_bit_field_type(CheckerContext *ctx, Type *bit_field_type,
return Endian_Native;
};
- EndianKind backing_type_endian_kind = determine_endian_kind(core_array_type(backing_type));
+ Type *backing_type_elem = core_array_type(backing_type);
+ i64 backing_type_elem_size = type_size_of(backing_type_elem);
+ EndianKind backing_type_endian_kind = determine_endian_kind(backing_type_elem);
EndianKind endian_kind = Endian_Unknown;
for (Entity *f : fields) {
EndianKind field_kind = determine_endian_kind(f->type);
+ i64 field_size = type_size_of(f->type);
- if (field_kind && backing_type_endian_kind != field_kind) {
+ if (field_kind && backing_type_endian_kind != field_kind && field_size > 1 && backing_type_elem_size > 1) {
error(f->token, "All 'bit_field' field types must match the same endian kind as the backing type, i.e. all native, all little, or all big");
}
if (endian_kind == Endian_Unknown) {
endian_kind = field_kind;
- } else if (field_kind && endian_kind != field_kind) {
+ } else if (field_kind && endian_kind != field_kind && field_size > 1) {
error(f->token, "All 'bit_field' field types must be of the same endian variety, i.e. all native, all little, or all big");
}
}
diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp
index ba71eae4d..ad8d9d245 100644
--- a/src/docs_writer.cpp
+++ b/src/docs_writer.cpp
@@ -26,11 +26,11 @@ struct OdinDocWriter {
StringMap<OdinDocString> string_cache;
- PtrMap<AstFile *, OdinDocFileIndex> file_cache;
- PtrMap<AstPackage *, OdinDocPkgIndex> pkg_cache;
- PtrMap<Entity *, OdinDocEntityIndex> entity_cache;
- PtrMap<Type *, OdinDocTypeIndex> type_cache;
- PtrMap<Type *, Type *> stable_type_cache;
+ OrderedInsertPtrMap<AstFile *, OdinDocFileIndex> file_cache;
+ OrderedInsertPtrMap<AstPackage *, OdinDocPkgIndex> pkg_cache;
+ OrderedInsertPtrMap<Entity *, OdinDocEntityIndex> entity_cache;
+ OrderedInsertPtrMap<Type *, OdinDocTypeIndex> type_cache;
+ OrderedInsertPtrMap<Type *, Type *> stable_type_cache;
OdinDocWriterItemTracker<OdinDocFile> files;
OdinDocWriterItemTracker<OdinDocPkg> pkgs;
@@ -57,11 +57,11 @@ gb_internal void odin_doc_writer_prepare(OdinDocWriter *w) {
string_map_init(&w->string_cache);
- map_init(&w->file_cache);
- map_init(&w->pkg_cache);
- map_init(&w->entity_cache);
- map_init(&w->type_cache);
- map_init(&w->stable_type_cache);
+ map_init(&w->file_cache, 1<<10);
+ map_init(&w->pkg_cache, 1<<10);
+ map_init(&w->entity_cache, 1<<18);
+ map_init(&w->type_cache, 1<<18);
+ map_init(&w->stable_type_cache, 1<<18);
odin_doc_writer_item_tracker_init(&w->files, 1);
odin_doc_writer_item_tracker_init(&w->pkgs, 1);
@@ -485,6 +485,13 @@ gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
return 0;
}
+ if (type->kind == Type_Named) {
+ Entity *e = type->Named.type_name;
+ if (e->TypeName.is_type_alias) {
+ type = type->Named.base;
+ }
+ }
+
// Type **mapped_type = map_get(&w->stable_type_cache, type); // may map to itself
// if (mapped_type && *mapped_type) {
// type = *mapped_type;
@@ -506,13 +513,6 @@ gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
if (!x | !y) {
continue;
}
-
- if (x->kind == Type_Named) {
- Entity *e = x->Named.type_name;
- if (e->TypeName.is_type_alias) {
- x = x->Named.base;
- }
- }
if (y->kind == Type_Named) {
Entity *e = y->Named.type_name;
if (e->TypeName.is_type_alias) {
diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp
index 030926079..ad02ff7dd 100644
--- a/src/llvm_backend_expr.cpp
+++ b/src/llvm_backend_expr.cpp
@@ -2514,7 +2514,7 @@ gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left
case Token_Lt: runtime_procedure = "cstring_lt"; break;
case Token_Gt: runtime_procedure = "cstring_gt"; break;
case Token_LtEq: runtime_procedure = "cstring_le"; break;
- case Token_GtEq: runtime_procedure = "cstring_gt"; break;
+ case Token_GtEq: runtime_procedure = "cstring_ge"; break;
}
GB_ASSERT(runtime_procedure != nullptr);
@@ -2537,7 +2537,7 @@ gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left
case Token_Lt: runtime_procedure = "string_lt"; break;
case Token_Gt: runtime_procedure = "string_gt"; break;
case Token_LtEq: runtime_procedure = "string_le"; break;
- case Token_GtEq: runtime_procedure = "string_gt"; break;
+ case Token_GtEq: runtime_procedure = "string_ge"; break;
}
GB_ASSERT(runtime_procedure != nullptr);
diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp
index 898c9ac31..736c54e52 100644
--- a/src/llvm_backend_proc.cpp
+++ b/src/llvm_backend_proc.cpp
@@ -2835,8 +2835,7 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
{
GB_ASSERT(arg_count <= 7);
- char asm_string_default[] = "int $$0x80";
- char *asm_string = asm_string_default;
+ char asm_string[] = "int $$0x80";
gbString constraints = gb_string_make(heap_allocator(), "={eax}");
for (unsigned i = 0; i < gb_min(arg_count, 6); i++) {
@@ -2848,16 +2847,11 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
"edx",
"esi",
"edi",
+ "ebp",
};
constraints = gb_string_appendc(constraints, regs[i]);
constraints = gb_string_appendc(constraints, "}");
}
- if (arg_count == 7) {
- char asm_string7[] = "push %[arg6]\npush %%ebp\nmov 4(%%esp), %%ebp\nint $0x80\npop %%ebp\nadd $4, %%esp";
- asm_string = asm_string7;
-
- constraints = gb_string_appendc(constraints, ",rm");
- }
inline_asm = llvm_get_inline_asm(func_type, make_string_c(asm_string), make_string_c(constraints));
}
diff --git a/src/parser.cpp b/src/parser.cpp
index 6e859fe32..ee3c56daf 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -3883,10 +3883,12 @@ gb_internal Ast *parse_proc_type(AstFile *f, Token proc_token) {
expect_token(f, Token_OpenParen);
+ f->expr_level += 1;
params = parse_field_list(f, nullptr, FieldFlag_Signature, Token_CloseParen, true, true);
if (file_allow_newline(f)) {
skip_possible_newline(f);
}
+ f->expr_level -= 1;
expect_token_after(f, Token_CloseParen, "parameter list");
results = parse_results(f, &diverging);
diff --git a/src/ptr_map.cpp b/src/ptr_map.cpp
index 362e412ba..1c157c386 100644
--- a/src/ptr_map.cpp
+++ b/src/ptr_map.cpp
@@ -9,12 +9,6 @@ enum {
};
-struct MapFindResult {
- MapIndex hash_index;
- MapIndex entry_prev;
- MapIndex entry_index;
-};
-
enum : MapIndex { MAP_SENTINEL = ~(MapIndex)0 };
static void *const MAP_TOMBSTONE = (void *)~(uintptr)0;
@@ -433,3 +427,435 @@ gb_internal PtrMapIterator<K, V> const begin(PtrMap<K, V> const &m) noexcept {
}
return PtrMapIterator<K, V>{&m, index};
}
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+struct MapFindResult {
+ MapIndex hash_index;
+ MapIndex entry_prev;
+ MapIndex entry_index;
+};
+
+template <typename K, typename V>
+struct OrderedInsertPtrMapEntry {
+ static_assert(sizeof(K) == sizeof(void *), "Key size must be pointer size");
+
+ K key;
+ V value;
+ MapIndex next;
+};
+
+template <typename K, typename V>
+struct OrderedInsertPtrMap {
+ MapIndex *hashes;
+ usize hashes_count;
+ OrderedInsertPtrMapEntry<K, V> *entries;
+ u32 count;
+ u32 entries_capacity;
+};
+
+
+template <typename K, typename V> gb_internal void map_destroy (OrderedInsertPtrMap<K, V> *h);
+template <typename K, typename V> gb_internal V * map_get (OrderedInsertPtrMap<K, V> *h, K key);
+template <typename K, typename V> gb_internal void map_set (OrderedInsertPtrMap<K, V> *h, K key, V const &value);
+template <typename K, typename V> gb_internal bool map_set_if_not_previously_exists(OrderedInsertPtrMap<K, V> *h, K key, V const &value); // returns true if it previously existed
+template <typename K, typename V> gb_internal void map_remove (OrderedInsertPtrMap<K, V> *h, K key);
+template <typename K, typename V> gb_internal void map_clear (OrderedInsertPtrMap<K, V> *h);
+template <typename K, typename V> gb_internal void map_grow (OrderedInsertPtrMap<K, V> *h);
+template <typename K, typename V> gb_internal void map_rehash (OrderedInsertPtrMap<K, V> *h, isize new_count);
+template <typename K, typename V> gb_internal void map_reserve (OrderedInsertPtrMap<K, V> *h, isize cap);
+
+// Mutlivalued map procedure
+template <typename K, typename V> gb_internal OrderedInsertPtrMapEntry<K, V> * multi_map_find_first(OrderedInsertPtrMap<K, V> *h, K key);
+template <typename K, typename V> gb_internal OrderedInsertPtrMapEntry<K, V> * multi_map_find_next (OrderedInsertPtrMap<K, V> *h, OrderedInsertPtrMapEntry<K, V> *e);
+
+template <typename K, typename V> gb_internal isize multi_map_count (OrderedInsertPtrMap<K, V> *h, K key);
+template <typename K, typename V> gb_internal void multi_map_get_all (OrderedInsertPtrMap<K, V> *h, K key, V *items);
+template <typename K, typename V> gb_internal void multi_map_insert (OrderedInsertPtrMap<K, V> *h, K key, V const &value);
+template <typename K, typename V> gb_internal void multi_map_remove (OrderedInsertPtrMap<K, V> *h, K key, OrderedInsertPtrMapEntry<K, V> *e);
+template <typename K, typename V> gb_internal void multi_map_remove_all(OrderedInsertPtrMap<K, V> *h, K key);
+
+template <typename K, typename V>
+gb_internal gb_inline void map_init(OrderedInsertPtrMap<K, V> *h, isize capacity) {
+ capacity = next_pow2_isize(capacity);
+ map_reserve(h, capacity);
+}
+
+template <typename K, typename V>
+gb_internal gb_inline void map_destroy(OrderedInsertPtrMap<K, V> *h) {
+ gbAllocator a = map_allocator();
+ gb_free(a, h->hashes);
+ gb_free(a, h->entries);
+}
+
+template <typename K, typename V>
+gb_internal void map__resize_hashes(OrderedInsertPtrMap<K, V> *h, usize count) {
+ h->hashes_count = cast(u32)resize_array_raw(&h->hashes, map_allocator(), h->hashes_count, count, MAP_CACHE_LINE_SIZE);
+}
+
+template <typename K, typename V>
+gb_internal void map__reserve_entries(OrderedInsertPtrMap<K, V> *h, usize capacity) {
+ h->entries_capacity = cast(u32)resize_array_raw(&h->entries, map_allocator(), h->entries_capacity, capacity, MAP_CACHE_LINE_SIZE);
+}
+
+
+template <typename K, typename V>
+gb_internal MapIndex map__add_entry(OrderedInsertPtrMap<K, V> *h, K key) {
+ OrderedInsertPtrMapEntry<K, V> e = {};
+ e.key = key;
+ e.next = MAP_SENTINEL;
+ if (h->count+1 >= h->entries_capacity) {
+ map__reserve_entries(h, gb_max(h->entries_capacity*2, 4));
+ }
+ h->entries[h->count++] = e;
+ return cast(MapIndex)(h->count-1);
+}
+
+template <typename K, typename V>
+gb_internal MapFindResult map__find(OrderedInsertPtrMap<K, V> *h, K key) {
+ MapFindResult fr = {MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL};
+ if (h->hashes_count == 0) {
+ return fr;
+ }
+ u32 hash = ptr_map_hash_key(key);
+ fr.hash_index = cast(MapIndex)(hash & (h->hashes_count-1));
+ fr.entry_index = h->hashes[fr.hash_index];
+ while (fr.entry_index != MAP_SENTINEL) {
+ auto *entry = &h->entries[fr.entry_index];
+ if (entry->key == key) {
+ return fr;
+ }
+ fr.entry_prev = fr.entry_index;
+ fr.entry_index = entry->next;
+ }
+ return fr;
+}
+
+template <typename K, typename V>
+gb_internal MapFindResult map__find_from_entry(OrderedInsertPtrMap<K, V> *h, OrderedInsertPtrMapEntry<K, V> *e) {
+ MapFindResult fr = {MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL};
+ if (h->hashes_count == 0) {
+ return fr;
+ }
+ u32 hash = ptr_map_hash_key(e->key);
+ fr.hash_index = cast(MapIndex)(hash & (h->hashes_count-1));
+ fr.entry_index = h->hashes[fr.hash_index];
+ while (fr.entry_index != MAP_SENTINEL) {
+ if (&h->entries[fr.entry_index] == e) {
+ return fr;
+ }
+ fr.entry_prev = fr.entry_index;
+ fr.entry_index = h->entries[fr.entry_index].next;
+ }
+ return fr;
+}
+
+template <typename K, typename V>
+gb_internal b32 map__full(OrderedInsertPtrMap<K, V> *h) {
+ return 0.75f * h->hashes_count <= h->count;
+}
+
+template <typename K, typename V>
+gb_internal gb_inline void map_grow(OrderedInsertPtrMap<K, V> *h) {
+ isize new_count = gb_max(h->hashes_count<<1, 16);
+ map_rehash(h, new_count);
+}
+
+template <typename K, typename V>
+gb_internal void map_reset_entries(OrderedInsertPtrMap<K, V> *h) {
+ for (usize i = 0; i < h->hashes_count; i++) {
+ h->hashes[i] = MAP_SENTINEL;
+ }
+ for (usize i = 0; i < h->count; i++) {
+ MapFindResult fr;
+ OrderedInsertPtrMapEntry<K, V> *e = &h->entries[i];
+ e->next = MAP_SENTINEL;
+ fr = map__find_from_entry(h, e);
+ if (fr.entry_prev == MAP_SENTINEL) {
+ h->hashes[fr.hash_index] = cast(MapIndex)i;
+ } else {
+ h->entries[fr.entry_prev].next = cast(MapIndex)i;
+ }
+ }
+}
+
+template <typename K, typename V>
+gb_internal void map_reserve(OrderedInsertPtrMap<K, V> *h, isize cap) {
+ if (h->count*2 < h->hashes_count) {
+ return;
+ }
+ map__reserve_entries(h, cap);
+ map__resize_hashes(h, cap*2);
+ map_reset_entries(h);
+}
+
+
+template <typename K, typename V>
+gb_internal void map_rehash(OrderedInsertPtrMap<K, V> *h, isize new_count) {
+ map_reserve(h, new_count);
+}
+
+template <typename K, typename V>
+gb_internal V *map_get(OrderedInsertPtrMap<K, V> *h, K key) {
+ MapIndex hash_index = MAP_SENTINEL;
+ MapIndex entry_prev = MAP_SENTINEL;
+ MapIndex entry_index = MAP_SENTINEL;
+ if (h->hashes_count != 0) {
+ u32 hash = ptr_map_hash_key(key);
+ hash_index = cast(MapIndex)(hash & (h->hashes_count-1));
+ entry_index = h->hashes[hash_index];
+ while (entry_index != MAP_SENTINEL) {
+ auto *entry = &h->entries[entry_index];
+ if (entry->key == key) {
+ return &entry->value;
+ }
+ entry_prev = entry_index;
+ entry_index = entry->next;
+ }
+ }
+ return nullptr;
+}
+template <typename K, typename V>
+gb_internal V *map_try_get(OrderedInsertPtrMap<K, V> *h, K key, MapFindResult *fr_) {
+ MapFindResult fr = {MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL};
+ if (h->hashes_count != 0) {
+ u32 hash = ptr_map_hash_key(key);
+ fr.hash_index = cast(MapIndex)(hash & (h->hashes_count-1));
+ fr.entry_index = h->hashes[fr.hash_index];
+ while (fr.entry_index != MAP_SENTINEL) {
+ auto *entry = &h->entries[fr.entry_index];
+ if (entry->key == key) {
+ return &entry->value;
+ }
+ fr.entry_prev = fr.entry_index;
+ fr.entry_index = entry->next;
+ }
+ }
+ if (h->hashes_count == 0 || map__full(h)) {
+ map_grow(h);
+ }
+ if (fr_) *fr_ = fr;
+ return nullptr;
+}
+
+
+template <typename K, typename V>
+gb_internal void map_set_internal_from_try_get(OrderedInsertPtrMap<K, V> *h, K key, V const &value, MapFindResult const &fr) {
+ MapIndex index = map__add_entry(h, key);
+ if (fr.entry_prev != MAP_SENTINEL) {
+ h->entries[fr.entry_prev].next = index;
+ } else {
+ h->hashes[fr.hash_index] = index;
+ }
+ h->entries[index].value = value;
+}
+
+template <typename K, typename V>
+gb_internal V &map_must_get(OrderedInsertPtrMap<K, V> *h, K key) {
+ V *ptr = map_get(h, key);
+ GB_ASSERT(ptr != nullptr);
+ return *ptr;
+}
+
+template <typename K, typename V>
+gb_internal void map_set(OrderedInsertPtrMap<K, V> *h, K key, V const &value) {
+ MapIndex index;
+ MapFindResult fr;
+ if (h->hashes_count == 0) {
+ map_grow(h);
+ }
+ fr = map__find(h, key);
+ if (fr.entry_index != MAP_SENTINEL) {
+ index = fr.entry_index;
+ } else {
+ index = map__add_entry(h, key);
+ if (fr.entry_prev != MAP_SENTINEL) {
+ h->entries[fr.entry_prev].next = index;
+ } else {
+ h->hashes[fr.hash_index] = index;
+ }
+ }
+ h->entries[index].value = value;
+
+ if (map__full(h)) {
+ map_grow(h);
+ }
+}
+
+// returns true if it previously existed
+template <typename K, typename V>
+gb_internal bool map_set_if_not_previously_exists(OrderedInsertPtrMap<K, V> *h, K key, V const &value) {
+ MapIndex index;
+ MapFindResult fr;
+ if (h->hashes_count == 0) {
+ map_grow(h);
+ }
+ fr = map__find(h, key);
+ if (fr.entry_index != MAP_SENTINEL) {
+ return true;
+ } else {
+ index = map__add_entry(h, key);
+ if (fr.entry_prev != MAP_SENTINEL) {
+ h->entries[fr.entry_prev].next = index;
+ } else {
+ h->hashes[fr.hash_index] = index;
+ }
+ }
+ h->entries[index].value = value;
+
+ if (map__full(h)) {
+ map_grow(h);
+ }
+ return false;
+}
+
+
+template <typename K, typename V>
+gb_internal void map__erase(OrderedInsertPtrMap<K, V> *h, MapFindResult const &fr) {
+ MapFindResult last;
+ if (fr.entry_prev == MAP_SENTINEL) {
+ h->hashes[fr.hash_index] = h->entries[fr.entry_index].next;
+ } else {
+ h->entries[fr.entry_prev].next = h->entries[fr.entry_index].next;
+ }
+ if (fr.entry_index == h->count-1) {
+ h->count--;
+ return;
+ }
+ h->entries[fr.entry_index] = h->entries[h->count-1];
+ h->count--;
+
+ last = map__find(h, h->entries[fr.entry_index].key);
+ if (last.entry_prev != MAP_SENTINEL) {
+ h->entries[last.entry_prev].next = fr.entry_index;
+ } else {
+ h->hashes[last.hash_index] = fr.entry_index;
+ }
+}
+
+template <typename K, typename V>
+gb_internal void map_remove(OrderedInsertPtrMap<K, V> *h, K key) {
+ MapFindResult fr = map__find(h, key);
+ if (fr.entry_index != MAP_SENTINEL) {
+ map__erase(h, fr);
+ }
+}
+
+template <typename K, typename V>
+gb_internal gb_inline void map_clear(OrderedInsertPtrMap<K, V> *h) {
+ h->count = 0;
+ for (usize i = 0; i < h->hashes_count; i++) {
+ h->hashes[i] = MAP_SENTINEL;
+ }
+}
+
+
+template <typename K, typename V>
+gb_internal OrderedInsertPtrMapEntry<K, V> *multi_map_find_first(OrderedInsertPtrMap<K, V> *h, K key) {
+ MapIndex i = map__find(h, key).entry_index;
+ if (i == MAP_SENTINEL) {
+ return nullptr;
+ }
+ return &h->entries[i];
+}
+
+template <typename K, typename V>
+gb_internal OrderedInsertPtrMapEntry<K, V> *multi_map_find_next(OrderedInsertPtrMap<K, V> *h, OrderedInsertPtrMapEntry<K, V> *e) {
+ MapIndex i = e->next;
+ while (i != MAP_SENTINEL) {
+ if (h->entries[i].key == e->key) {
+ return &h->entries[i];
+ }
+ i = h->entries[i].next;
+ }
+ return nullptr;
+}
+
+template <typename K, typename V>
+gb_internal isize multi_map_count(OrderedInsertPtrMap<K, V> *h, K key) {
+ isize count = 0;
+ OrderedInsertPtrMapEntry<K, V> *e = multi_map_find_first(h, key);
+ while (e != nullptr) {
+ count++;
+ e = multi_map_find_next(h, e);
+ }
+ return count;
+}
+
+template <typename K, typename V>
+gb_internal void multi_map_get_all(OrderedInsertPtrMap<K, V> *h, K key, V *items) {
+ usize i = 0;
+ OrderedInsertPtrMapEntry<K, V> *e = multi_map_find_first(h, key);
+ while (e != nullptr) {
+ items[i++] = e->value;
+ e = multi_map_find_next(h, e);
+ }
+}
+
+template <typename K, typename V>
+gb_internal void multi_map_insert(OrderedInsertPtrMap<K, V> *h, K key, V const &value) {
+ MapFindResult fr;
+ MapIndex i;
+ if (h->hashes_count == 0) {
+ map_grow(h);
+ }
+ // Make
+ fr = map__find(h, key);
+ i = map__add_entry(h, key);
+ if (fr.entry_prev == MAP_SENTINEL) {
+ h->hashes[fr.hash_index] = i;
+ } else {
+ h->entries[fr.entry_prev].next = i;
+ }
+ h->entries[i].next = fr.entry_index;
+ h->entries[i].value = value;
+ // Grow if needed
+ if (map__full(h)) {
+ map_grow(h);
+ }
+}
+
+template <typename K, typename V>
+gb_internal void multi_map_remove(OrderedInsertPtrMap<K, V> *h, K key, OrderedInsertPtrMapEntry<K, V> *e) {
+ MapFindResult fr = map__find_from_entry(h, e);
+ if (fr.entry_index != MAP_SENTINEL) {
+ map__erase(h, fr);
+ }
+}
+
+template <typename K, typename V>
+gb_internal void multi_map_remove_all(OrderedInsertPtrMap<K, V> *h, K key) {
+ while (map_get(h, key) != nullptr) {
+ map_remove(h, key);
+ }
+}
+
+
+template <typename K, typename V>
+gb_internal OrderedInsertPtrMapEntry<K, V> *begin(OrderedInsertPtrMap<K, V> &m) {
+ return m.entries;
+}
+template <typename K, typename V>
+gb_internal OrderedInsertPtrMapEntry<K, V> const *begin(OrderedInsertPtrMap<K, V> const &m) {
+ return m.entries;
+}
+
+
+template <typename K, typename V>
+gb_internal OrderedInsertPtrMapEntry<K, V> *end(OrderedInsertPtrMap<K, V> &m) {
+ return m.entries + m.count;
+}
+
+template <typename K, typename V>
+gb_internal OrderedInsertPtrMapEntry<K, V> const *end(OrderedInsertPtrMap<K, V> const &m) {
+ return m.entries + m.count;
+} \ No newline at end of file
diff --git a/src/types.cpp b/src/types.cpp
index 30e009086..47ed86f7a 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -2100,8 +2100,8 @@ gb_internal bool is_type_polymorphic_record_unspecialized(Type *t) {
t = base_type(t);
if (t->kind == Type_Struct) {
return t->Struct.is_polymorphic && !t->Struct.is_poly_specialized;
- } else if (t->kind == Type_Struct) {
- return t->Struct.is_polymorphic && !t->Struct.is_poly_specialized;
+ } else if (t->kind == Type_Union) {
+ return t->Union.is_polymorphic && !t->Union.is_poly_specialized;
}
return false;
}