mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 06:38:47 +00:00
Change union layout to store type info rather than an integer; ternary expression for types with constant condition
This commit is contained in:
+2
-1
@@ -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
@@ -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
@@ -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)");
|
||||
|
||||
Reference in New Issue
Block a user