aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-06-05 18:01:41 +0100
committerGinger Bill <bill@gingerbill.org>2017-06-05 18:01:41 +0100
commiteba2c74bff8f987e4bec7572cb3b2031261c237d (patch)
tree5751a6c8f4cfddb4938621f49861b9392b427292 /src
parentebe5beaafd90bccaee2ece8510e61d2cbf7a81c2 (diff)
Allow 128 bit map keys
Diffstat (limited to 'src')
-rw-r--r--src/check_expr.c23
-rw-r--r--src/checker.c3
-rw-r--r--src/common.c1
-rw-r--r--src/ir.c16
-rw-r--r--src/map.c3
-rw-r--r--src/types.c14
6 files changed, 39 insertions, 21 deletions
diff --git a/src/check_expr.c b/src/check_expr.c
index 866a5f1a4..667ae48fd 100644
--- a/src/check_expr.c
+++ b/src/check_expr.c
@@ -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);
diff --git a/src/checker.c b/src/checker.c
index a7f8ec950..8aafccb73 100644
--- a/src/checker.c
+++ b/src/checker.c
@@ -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);
diff --git a/src/common.c b/src/common.c
index 77c9876b7..f7d16cf8a 100644
--- a/src/common.c
+++ b/src/common.c
@@ -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;
diff --git a/src/ir.c b/src/ir.c
index f2b75b88d..f5f48ec9c 100644
--- a/src/ir.c
+++ b/src/ir.c
@@ -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;
diff --git a/src/map.c b/src/map.c
index 83c9ce95a..e0d091e93 100644
--- a/src/map.c
+++ b/src/map.c
@@ -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;
diff --git a/src/types.c b/src/types.c
index 91d8dc4eb..1364191d8 100644
--- a/src/types.c
+++ b/src/types.c
@@ -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;