union #no_nil

This commit is contained in:
gingerBill
2019-07-09 10:28:13 +01:00
parent c5b3d7a736
commit 4ab9edeb53
7 changed files with 34 additions and 9 deletions
+7 -1
View File
@@ -1326,8 +1326,14 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
case i64: tag = i64(i);
case: panic("Invalid union tag type");
}
assert(tag >= 0);
if v.data == nil || tag == 0 {
if v.data == nil {
strings.write_string(fi.buf, "nil");
} else if info.no_nil {
id := info.variants[tag].id;
fmt_arg(fi, any{v.data, id}, verb);
} else if tag == 0 {
strings.write_string(fi.buf, "nil");
} else {
id := info.variants[tag-1].id;
+4 -3
View File
@@ -86,10 +86,11 @@ Type_Info_Struct :: struct {
custom_align: bool,
};
Type_Info_Union :: struct {
variants: []^Type_Info,
tag_offset: uintptr,
tag_type: ^Type_Info,
variants: []^Type_Info,
tag_offset: uintptr,
tag_type: ^Type_Info,
custom_align: bool,
no_nil: bool,
};
Type_Info_Enum :: struct {
base: ^Type_Info,