mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Fix #210
This commit is contained in:
@@ -5584,7 +5584,6 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
|||||||
error(node, "Expected %lld values for this array literal, got %lld", cast(long long)t->Array.count, cast(long long)max);
|
error(node, "Expected %lld values for this array literal, got %lld", cast(long long)t->Array.count, cast(long long)max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1876,7 +1876,7 @@ void GB_JOIN2(FUNC,rehash)(NAME *h, isize new_count) { \
|
|||||||
gbHashTableFindResult fr; \
|
gbHashTableFindResult fr; \
|
||||||
if (gb_array_count(nh.hashes) == 0) \
|
if (gb_array_count(nh.hashes) == 0) \
|
||||||
GB_JOIN2(FUNC,grow)(&nh); \
|
GB_JOIN2(FUNC,grow)(&nh); \
|
||||||
e = &nh.entries[i]; \
|
e = &h->entries[i]; \
|
||||||
fr = GB_JOIN2(FUNC,_find)(&nh, e->key); \
|
fr = GB_JOIN2(FUNC,_find)(&nh, e->key); \
|
||||||
j = GB_JOIN2(FUNC,_add_entry)(&nh, e->key); \
|
j = GB_JOIN2(FUNC,_add_entry)(&nh, e->key); \
|
||||||
if (fr.entry_prev < 0) \
|
if (fr.entry_prev < 0) \
|
||||||
|
|||||||
@@ -680,6 +680,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
GB_ASSERT_MSG(elem_count == type->Array.count, "%td != %td", elem_count, type->Array.count);
|
||||||
|
|
||||||
ir_write_byte(f, '[');
|
ir_write_byte(f, '[');
|
||||||
|
|
||||||
|
|||||||
@@ -700,7 +700,6 @@ int main(int arg_count, char **arg_ptr) {
|
|||||||
init_string_buffer_memory();
|
init_string_buffer_memory();
|
||||||
init_scratch_memory(gb_megabytes(10));
|
init_scratch_memory(gb_megabytes(10));
|
||||||
init_global_error_collector();
|
init_global_error_collector();
|
||||||
init_cached_type_maps();
|
|
||||||
|
|
||||||
array_init(&library_collections, heap_allocator());
|
array_init(&library_collections, heap_allocator());
|
||||||
// NOTE(bill): 'core' cannot be (re)defined by the user
|
// NOTE(bill): 'core' cannot be (re)defined by the user
|
||||||
|
|||||||
@@ -408,75 +408,6 @@ gb_global Type *t_map_header = nullptr;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
NOTE(bill): This caching system is to reduce allocation clutter - inspired by Per Vogensen's Bitwise
|
|
||||||
*/
|
|
||||||
enum CachedTypeKind {
|
|
||||||
CachedType_Invalid,
|
|
||||||
|
|
||||||
CachedType_Pointer,
|
|
||||||
CachedType_Array,
|
|
||||||
CachedType_Slice,
|
|
||||||
CachedType_DynamicArray,
|
|
||||||
CachedType_Map,
|
|
||||||
|
|
||||||
CachedType_COUNT
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CachedType {
|
|
||||||
CachedTypeKind kind;
|
|
||||||
Type *type;
|
|
||||||
};
|
|
||||||
|
|
||||||
HashKey hash_cache_type_elem(Type *elem) {
|
|
||||||
return hash_ptr_and_id(elem, 0);
|
|
||||||
}
|
|
||||||
HashKey hash_cache_type_array(Type *elem, i64 count) {
|
|
||||||
return hash_ptr_and_id(elem, cast(u64)count);
|
|
||||||
}
|
|
||||||
HashKey hash_cache_type_map(Type *key, Type *value) {
|
|
||||||
HashKey hkey = {};
|
|
||||||
if ((key != nullptr) == (value != nullptr)) {
|
|
||||||
u64 v = cast(u64)cast(uintptr)value;
|
|
||||||
hkey = hash_ptr_and_id(key, v);
|
|
||||||
}
|
|
||||||
return hkey;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Key: elem/elem+count/key+value
|
|
||||||
gb_global Map<CachedType> cached_type_maps[CachedType_COUNT] = {};
|
|
||||||
|
|
||||||
void init_cached_type_maps() {
|
|
||||||
for (isize i = 1; i < CachedType_COUNT; i++) {
|
|
||||||
map_init(&cached_type_maps[i], heap_allocator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CachedType *find_cached_type(CachedTypeKind kind, HashKey key) {
|
|
||||||
GB_ASSERT(key.kind == HashKey_PtrAndId);
|
|
||||||
if (key.ptr_and_id.ptr == nullptr) {
|
|
||||||
// NOTE(bill): uncachable types
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
auto *m = &cached_type_maps[kind];
|
|
||||||
return map_get(m, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_cached_type(CachedTypeKind kind, HashKey key, Type *type) {
|
|
||||||
GB_ASSERT(key.kind == HashKey_PtrAndId);
|
|
||||||
if (key.ptr_and_id.ptr == nullptr) {
|
|
||||||
// NOTE(bill): uncachable types
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CachedType ct = {};
|
|
||||||
ct.kind = kind;
|
|
||||||
ct.type = type;
|
|
||||||
map_set(&cached_type_maps[kind], key, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
i64 type_size_of (Type *t);
|
i64 type_size_of (Type *t);
|
||||||
i64 type_align_of (Type *t);
|
i64 type_align_of (Type *t);
|
||||||
i64 type_offset_of (Type *t, i32 index);
|
i64 type_offset_of (Type *t, i32 index);
|
||||||
@@ -560,15 +491,8 @@ Type *alloc_type_generic(Scope *scope, i64 id, String name, Type *specialized) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Type *alloc_type_pointer(Type *elem) {
|
Type *alloc_type_pointer(Type *elem) {
|
||||||
auto hkey = hash_cache_type_elem(elem);
|
|
||||||
if (auto found = find_cached_type(CachedType_Pointer, hkey)) {
|
|
||||||
return found->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
Type *t = alloc_type(Type_Pointer);
|
Type *t = alloc_type(Type_Pointer);
|
||||||
t->Pointer.elem = elem;
|
t->Pointer.elem = elem;
|
||||||
|
|
||||||
add_cached_type(CachedType_Pointer, hkey, t);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,36 +504,21 @@ Type *alloc_type_array(Type *elem, i64 count, Type *generic_count = nullptr) {
|
|||||||
t->Array.generic_count = generic_count;
|
t->Array.generic_count = generic_count;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
auto hkey = hash_cache_type_array(elem, count);
|
|
||||||
if (auto found = find_cached_type(CachedType_Array, hkey)) {
|
|
||||||
return found->type;
|
|
||||||
}
|
|
||||||
Type *t = alloc_type(Type_Array);
|
Type *t = alloc_type(Type_Array);
|
||||||
t->Array.elem = elem;
|
t->Array.elem = elem;
|
||||||
t->Array.count = count;
|
t->Array.count = count;
|
||||||
add_cached_type(CachedType_Array, hkey, t);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type *alloc_type_slice(Type *elem) {
|
Type *alloc_type_slice(Type *elem) {
|
||||||
auto hkey = hash_cache_type_elem(elem);
|
|
||||||
if (auto found = find_cached_type(CachedType_Slice, hkey)) {
|
|
||||||
return found->type;
|
|
||||||
}
|
|
||||||
Type *t = alloc_type(Type_Slice);
|
Type *t = alloc_type(Type_Slice);
|
||||||
t->Array.elem = elem;
|
t->Array.elem = elem;
|
||||||
add_cached_type(CachedType_Slice, hkey, t);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type *alloc_type_dynamic_array(Type *elem) {
|
Type *alloc_type_dynamic_array(Type *elem) {
|
||||||
auto hkey = hash_cache_type_elem(elem);
|
|
||||||
if (auto found = find_cached_type(CachedType_DynamicArray, hkey)) {
|
|
||||||
return found->type;
|
|
||||||
}
|
|
||||||
Type *t = alloc_type(Type_DynamicArray);
|
Type *t = alloc_type(Type_DynamicArray);
|
||||||
t->DynamicArray.elem = elem;
|
t->DynamicArray.elem = elem;
|
||||||
add_cached_type(CachedType_DynamicArray, hkey, t);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,14 +587,9 @@ Type *alloc_type_map(i64 count, Type *key, Type *value) {
|
|||||||
GB_ASSERT(is_type_valid_for_keys(key));
|
GB_ASSERT(is_type_valid_for_keys(key));
|
||||||
GB_ASSERT(value != nullptr);
|
GB_ASSERT(value != nullptr);
|
||||||
}
|
}
|
||||||
auto hkey = hash_cache_type_map(key, value);
|
|
||||||
if (auto found = find_cached_type(CachedType_Map, hkey)) {
|
|
||||||
return found->type;
|
|
||||||
}
|
|
||||||
Type *t = alloc_type(Type_Map);
|
Type *t = alloc_type(Type_Map);
|
||||||
t->Map.key = key;
|
t->Map.key = key;
|
||||||
t->Map.value = value;
|
t->Map.value = value;
|
||||||
add_cached_type(CachedType_Map, hkey, t);
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user