mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-15 15:41:26 -07:00
Allow 128 bit map keys
This commit is contained in:
+18
-5
@@ -2250,6 +2250,23 @@ bool check_is_vector_elem(Checker *c, AstNode *expr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool check_is_not_addressable(Checker *c, Operand *o) {
|
||||
if (o->mode != Addressing_Variable) {
|
||||
return true;
|
||||
}
|
||||
if (is_type_bit_field_value(o->type)) {
|
||||
return true;
|
||||
}
|
||||
if (check_is_expr_vector_index(c, o->expr)) {
|
||||
return true;
|
||||
}
|
||||
if (check_is_vector_elem(c, o->expr)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) {
|
||||
switch (op.kind) {
|
||||
case Token_And: { // Pointer address
|
||||
@@ -2257,11 +2274,7 @@ void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) {
|
||||
o->type = make_type_pointer(c->allocator, o->type);
|
||||
return;
|
||||
}
|
||||
|
||||
if (o->mode != Addressing_Variable ||
|
||||
check_is_expr_vector_index(c, o->expr) ||
|
||||
check_is_vector_elem(c, o->expr) ||
|
||||
is_type_bit_field_value(o->type)) {
|
||||
if (check_is_not_addressable(c, o)) {
|
||||
if (ast_node_expect(node, AstNode_UnaryExpr)) {
|
||||
ast_node(ue, UnaryExpr, node);
|
||||
gbString str = expr_to_string(ue->expr);
|
||||
|
||||
+2
-1
@@ -310,8 +310,8 @@ typedef struct CheckerInfo {
|
||||
MapEntity uses; // Key: AstNode * | Identifier -> Entity
|
||||
MapScope scopes; // Key: AstNode * | Node -> Scope
|
||||
MapExprInfo untyped; // Key: AstNode * | Expression -> ExprInfo
|
||||
MapDeclInfo entities; // Key: Entity *
|
||||
MapEntity implicits; // Key: AstNode *
|
||||
MapDeclInfo entities; // Key: Entity *
|
||||
MapEntity foreigns; // Key: String
|
||||
MapAstFile files; // Key: String (full path)
|
||||
MapIsize type_info_map; // Key: Type *
|
||||
@@ -698,6 +698,7 @@ void init_universal_scope(void) {
|
||||
t_u8_ptr = make_type_pointer(a, t_u8);
|
||||
t_int_ptr = make_type_pointer(a, t_int);
|
||||
t_i64_ptr = make_type_pointer(a, t_i64);
|
||||
t_i128_ptr = make_type_pointer(a, t_i128);
|
||||
t_f64_ptr = make_type_pointer(a, t_f64);
|
||||
t_byte_slice = make_type_slice(a, t_byte);
|
||||
t_string_slice = make_type_slice(a, t_string);
|
||||
|
||||
@@ -17,6 +17,7 @@ gbAllocator heap_allocator(void) {
|
||||
#include "string.c"
|
||||
#include "array.c"
|
||||
#include "integer128.c"
|
||||
#include "murmurhash3.c"
|
||||
|
||||
gb_global String global_module_path = {0};
|
||||
gb_global bool global_module_path_set = false;
|
||||
|
||||
@@ -1656,24 +1656,25 @@ irValue *ir_gen_map_header(irProcedure *proc, irValue *map_val, Type *map_type)
|
||||
}
|
||||
|
||||
irValue *ir_gen_map_key(irProcedure *proc, irValue *key, Type *key_type) {
|
||||
Type *hash_type = t_u128;
|
||||
irValue *v = ir_add_local_generated(proc, t_map_key);
|
||||
Type *t = base_type(ir_type(key));
|
||||
key = ir_emit_conv(proc, key, key_type);
|
||||
if (is_type_integer(t)) {
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, v, 0), ir_emit_conv(proc, key, t_u64));
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, v, 0), ir_emit_conv(proc, key, hash_type));
|
||||
} else if (is_type_pointer(t)) {
|
||||
irValue *p = ir_emit_conv(proc, key, t_uint);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, v, 0), ir_emit_conv(proc, p, t_u64));
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, v, 0), ir_emit_conv(proc, p, hash_type));
|
||||
} else if (is_type_float(t)) {
|
||||
irValue *bits = NULL;
|
||||
i64 size = type_size_of(proc->module->allocator, t);
|
||||
switch (8*size) {
|
||||
case 32: bits = ir_emit_transmute(proc, key, t_u32); break;
|
||||
case 64: bits = ir_emit_transmute(proc, key, t_u64); break;
|
||||
case 32: bits = ir_emit_transmute(proc, key, t_u32); break;
|
||||
case 64: bits = ir_emit_transmute(proc, key, t_u64); break;
|
||||
default: GB_PANIC("Unhandled float size: %lld bits", size); break;
|
||||
}
|
||||
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, v, 0), ir_emit_conv(proc, bits, t_u64));
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, v, 0), ir_emit_conv(proc, bits, hash_type));
|
||||
} else if (is_type_string(t)) {
|
||||
irValue *str = ir_emit_conv(proc, key, t_string);
|
||||
irValue *hashed_str = NULL;
|
||||
@@ -7823,9 +7824,8 @@ void ir_gen_tree(irGen *s) {
|
||||
ExactValue value = fields[i]->Constant.value;
|
||||
|
||||
if (is_value_int) {
|
||||
i64 i = i128_to_i64(value.value_integer);
|
||||
value_ep = ir_emit_conv(proc, value_ep, t_i64_ptr);
|
||||
ir_emit_store(proc, value_ep, ir_const_i64(a, i));
|
||||
value_ep = ir_emit_conv(proc, value_ep, t_i128_ptr);
|
||||
ir_emit_store(proc, value_ep, ir_value_constant(a, t_i128, value));
|
||||
} else {
|
||||
GB_ASSERT(is_type_float(t->Record.enum_base_type));
|
||||
f64 f = value.value_float;
|
||||
|
||||
@@ -39,6 +39,8 @@ gb_inline HashKey hashing_proc(void const *data, isize len) {
|
||||
h.kind = HashKey_Default;
|
||||
// h.key = gb_murmur64(data, len);
|
||||
h.key = gb_fnv64a(data, len);
|
||||
// h.key = MurmurHash3_128(data, len, 0x3803cb8e);
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
@@ -51,6 +53,7 @@ gb_inline HashKey hash_string(String s) {
|
||||
|
||||
gb_inline HashKey hash_pointer(void *ptr) {
|
||||
HashKey h = {HashKey_Default};
|
||||
// h.key = u128_from_u64(cast(u64)cast(uintptr)ptr);
|
||||
h.key = cast(u64)cast(uintptr)ptr;
|
||||
h.ptr = ptr;
|
||||
h.kind = HashKey_Default;
|
||||
|
||||
+7
-7
@@ -304,11 +304,12 @@ gb_global Type *t_untyped_nil = &basic_types[Basic_UntypedNil];
|
||||
gb_global Type *t_byte = &basic_type_aliases[0];
|
||||
gb_global Type *t_rune = &basic_type_aliases[1];
|
||||
|
||||
gb_global Type *t_u8_ptr = NULL;
|
||||
gb_global Type *t_int_ptr = NULL;
|
||||
gb_global Type *t_i64_ptr = NULL;
|
||||
gb_global Type *t_f64_ptr = NULL;
|
||||
gb_global Type *t_byte_slice = NULL;
|
||||
gb_global Type *t_u8_ptr = NULL;
|
||||
gb_global Type *t_int_ptr = NULL;
|
||||
gb_global Type *t_i64_ptr = NULL;
|
||||
gb_global Type *t_i128_ptr = NULL;
|
||||
gb_global Type *t_f64_ptr = NULL;
|
||||
gb_global Type *t_byte_slice = NULL;
|
||||
gb_global Type *t_string_slice = NULL;
|
||||
|
||||
|
||||
@@ -874,8 +875,7 @@ bool is_type_valid_for_keys(Type *t) {
|
||||
return false;
|
||||
}
|
||||
if (is_type_integer(t)) {
|
||||
// NOTE(bill): Not (u|i)128
|
||||
return t->Basic.size <= 8;
|
||||
return true;
|
||||
}
|
||||
if (is_type_float(t)) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user