Change union layout to store type info rather than an integer; ternary expression for types with constant condition

This commit is contained in:
Ginger Bill
2017-07-19 12:15:21 +01:00
parent 4db462a703
commit 6113164211
9 changed files with 222 additions and 85 deletions
+2 -1
View File
@@ -82,7 +82,8 @@ TypeInfo :: struct #ordered {
Struct :: Record;
RawUnion :: Record;
Union :: struct #ordered {
variants: []^TypeInfo;
variants: []^TypeInfo;
tag_offset: int;
};
Enum :: struct #ordered {
base: ^TypeInfo;
+41
View File
@@ -0,0 +1,41 @@
CHAR_BIT :: 8;
c_bool :: bool;
c_char :: u8;
c_schar :: i8;
c_uchar :: i8;
c_short :: i16;
c_ushort :: i16;
c_int :: i32;
c_uint :: u32;
c_long :: ODIN_OS == "windows" ?
i32 :
(size_of(int) == 4) ?
i32 :
i64;
c_ulong :: ODIN_OS == "windows" ?
u32 :
(size_of(int) == 4) ?
u32 :
u64;
c_longlong :: i64;
c_ulonglong :: u64;
c_float :: f32;
c_double :: f64;
c_complex_float :: complex64;
c_complex_double :: complex128;
c_size_t :: uint;
c_ssize_t :: int;
c_ptrdiff_t :: int;
c_uintptr_t :: uint;
c_intptr_t :: int;
+9 -1
View File
@@ -866,7 +866,15 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
}
case Union:
write_string(fi.buf, "(union)");
data := cast(^u8)v.data;
tipp := cast(^^TypeInfo)(data + info.tag_offset);
if data == nil || tipp == nil {
write_string(fi.buf, "(union)");
} else {
ti := tipp^;
fmt_arg(fi, any{data, ti}, verb);
}
case RawUnion:
write_string(fi.buf, "(raw_union)");