diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-09-04 16:16:17 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-09-04 16:16:17 +0100 |
| commit | c2e3c3801acd8af32fcf6ea3ad2d3a2ddc94c870 (patch) | |
| tree | 4686866a14b65f9d9c4a37567c8593f7951b1881 /src/codegen/codegen.cpp | |
| parent | cdd8eadda172b3ced7a774dfa1f22a976b3bdb7f (diff) | |
Type match statement for tagged unions
Diffstat (limited to 'src/codegen/codegen.cpp')
| -rw-r--r-- | src/codegen/codegen.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
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<i32> 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; } } |