aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-02-07 18:13:37 +0000
committerGinger Bill <bill@gingerbill.org>2017-02-07 18:13:37 +0000
commit454d0b5cf5b109fda01b3380b1fab0434d7ff51d (patch)
tree190c1793b3ded1976a30ba16f380bd5a0b5d54b1
parent219ca0ac4677235d595d9bd6e1be08eedfdf7d66 (diff)
Fix global maps and initialize the preload types before
-rw-r--r--code/demo.odin12
-rw-r--r--src/check_expr.c6
-rw-r--r--src/check_stmt.c1
-rw-r--r--src/ir.c13
-rw-r--r--src/types.c8
5 files changed, 27 insertions, 13 deletions
diff --git a/code/demo.odin b/code/demo.odin
index 45ae781a2..bc193ef1f 100644
--- a/code/demo.odin
+++ b/code/demo.odin
@@ -9,7 +9,6 @@
#import "utf8.odin";
#import ht "http_test.odin";
-
main :: proc() {
{
m: map[f32]int;
@@ -21,11 +20,18 @@ main :: proc() {
m[3.0] = 564;
c := m[3.0];
_, ok := m[3.0];
- assert(ok && c == 564);
+ // assert(ok && c == 564);
+ fmt.print("map[");
+ i := 0;
for val, key in m {
- fmt.printf("m[%f] == %v\n", key, val);
+ if i > 0 {
+ fmt.print(", ");
+ }
+ fmt.printf("%f=%v", key, val);
+ i += 1;
}
+ fmt.println("]");
}
{
m := map[string]u32{
diff --git a/src/check_expr.c b/src/check_expr.c
index a8f5fe55b..04f246532 100644
--- a/src/check_expr.c
+++ b/src/check_expr.c
@@ -1132,6 +1132,12 @@ void check_map_type(Checker *c, Type *type, AstNode *node) {
gbAllocator a = c->allocator;
{
+ // NOTE(bill): The preload types may have not been set yet
+ if (t_map_key == NULL) {
+ init_preload(c);
+ }
+ GB_ASSERT(t_map_key != NULL);
+
Type *entry_type = make_type_struct(a);
/*
diff --git a/src/check_stmt.c b/src/check_stmt.c
index a77120737..9155947fc 100644
--- a/src/check_stmt.c
+++ b/src/check_stmt.c
@@ -261,7 +261,6 @@ Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) {
case Addressing_Invalid:
return NULL;
case Addressing_Variable:
- break;
case Addressing_MapIndex:
break;
default: {
diff --git a/src/ir.c b/src/ir.c
index 084191192..117173ab3 100644
--- a/src/ir.c
+++ b/src/ir.c
@@ -1395,7 +1395,7 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index);
irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irValue *right);
irValue *ir_gen_map_header(irProcedure *proc, irValue *map_val, Type *map_type) {
- GB_ASSERT(is_type_pointer(ir_type(map_val)));
+ GB_ASSERT_MSG(is_type_pointer(ir_type(map_val)), "%s", type_to_string(ir_type(map_val)));
gbAllocator a = proc->module->allocator;
irValue *h = ir_add_local_generated(proc, t_map_header);
@@ -3027,7 +3027,7 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv
case_ast_node(cl, CompoundLit, expr);
- return ir_emit_load(proc, ir_build_addr(proc, expr).addr);
+ return ir_addr_load(proc, ir_build_addr(proc, expr));
case_end;
@@ -3597,11 +3597,11 @@ irValue *ir_build_single_expr(irProcedure *proc, AstNode *expr, TypeAndValue *tv
case_end;
case_ast_node(de, DemaybeExpr, expr);
- return ir_emit_load(proc, ir_build_addr(proc, expr).addr);
+ return ir_addr_load(proc, ir_build_addr(proc, expr));
case_end;
case_ast_node(se, SliceExpr, expr);
- return ir_emit_load(proc, ir_build_addr(proc, expr).addr);
+ return ir_addr_load(proc, ir_build_addr(proc, expr));
case_end;
case_ast_node(ie, IndexExpr, expr);
@@ -3824,17 +3824,12 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
Type *t = base_type(type_of_expr(proc->module->info, ie->expr));
gbAllocator a = proc->module->allocator;
-
bool deref = is_type_pointer(t);
t = base_type(type_deref(t));
if (is_type_map(t)) {
irAddr map_addr = ir_build_addr(proc, ie->expr);
irValue *map_val = map_addr.addr;
- if (deref) {
- map_val = ir_addr_load(proc, map_addr);
- }
-
irValue *key = ir_build_expr(proc, ie->index);
key = ir_emit_conv(proc, key, t->Map.key);
diff --git a/src/types.c b/src/types.c
index eae9ec556..dbded4a73 100644
--- a/src/types.c
+++ b/src/types.c
@@ -923,6 +923,14 @@ bool are_types_identical(Type *x, Type *y) {
are_types_identical(x->Proc.results, y->Proc.results);
}
break;
+
+ case Type_Map:
+ if (y->kind == Type_Map) {
+ return x->Map.count == y->Map.count &&
+ are_types_identical(x->Map.key, y->Map.key) &&
+ are_types_identical(x->Map.value, y->Map.value);
+ }
+ break;
}