From c2e3c3801acd8af32fcf6ea3ad2d3a2ddc94c870 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Sun, 4 Sep 2016 16:16:17 +0100 Subject: Type match statement for tagged unions --- src/codegen/codegen.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/codegen/codegen.cpp') diff --git a/src/codegen/codegen.cpp b/src/codegen/codegen.cpp index 735dfd580..06b6952d0 100644 --- a/src/codegen/codegen.cpp +++ b/src/codegen/codegen.cpp @@ -31,6 +31,27 @@ b32 ssa_gen_init(ssaGen *s, Checker *c) { if (err != gbFileError_None) return false; +#if 0 + Map type_map; // Key: Type * + map_init(&type_map, gb_heap_allocator()); + i32 index = 0; + gb_for_array(i, c->info.types.entries) { + TypeAndValue tav = c->info.types.entries[i].value; + Type *type = tav.type; + HashKey key = hash_pointer(type); + auto found = map_get(&type_map, key); + if (!found) { + map_set(&type_map, key, index); + index++; + } + } + gb_for_array(i, type_map.entries) { + auto *e = &type_map.entries[i]; + Type *t = cast(Type *)cast(uintptr)e->key.key; + gb_printf("%s\n", type_to_string(t)); + } +#endif + return true; } @@ -112,7 +133,10 @@ void ssa_gen_code(ssaGen *s) { p->Proc.tags = pd->tags; map_set(&m->values, hash_pointer(e), p); - map_set(&m->members, hash_string(name), p); + HashKey hash_name = hash_string(name); + if (map_get(&m->members, hash_name) == NULL) { + map_set(&m->members, hash_name, p); + } } break; } } -- cgit v1.2.3