mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-14 15:11:25 -07:00
Update internals of a Union and Tuple
This commit is contained in:
+14
-13
@@ -44,15 +44,6 @@ TypeInfo :: struct #ordered {
|
||||
u8, u16, u32, u64, u128, uint,
|
||||
f32, f64,
|
||||
};
|
||||
Record :: struct #ordered {
|
||||
types: []^TypeInfo;
|
||||
names: []string;
|
||||
offsets: []int; // offsets may not be used in tuples
|
||||
usings: []bool; // usings may not be used in tuples
|
||||
packed: bool;
|
||||
ordered: bool;
|
||||
custom_align: bool;
|
||||
}
|
||||
|
||||
// Variant Types
|
||||
Named :: struct #ordered {name: string; base: ^TypeInfo};
|
||||
@@ -80,9 +71,20 @@ TypeInfo :: struct #ordered {
|
||||
DynamicArray :: struct #ordered {elem: ^TypeInfo; elem_size: int};
|
||||
Slice :: struct #ordered {elem: ^TypeInfo; elem_size: int};
|
||||
Vector :: struct #ordered {elem: ^TypeInfo; elem_size, count: int};
|
||||
Tuple :: Record; // Only really used for procedures
|
||||
Struct :: Record;
|
||||
RawUnion :: Record;
|
||||
Tuple :: struct #ordered { // Only really used for procedures
|
||||
types: []^TypeInfo;
|
||||
names: []string;
|
||||
};
|
||||
Struct :: struct #ordered {
|
||||
types: []^TypeInfo;
|
||||
names: []string;
|
||||
offsets: []int; // offsets may not be used in tuples
|
||||
usings: []bool; // usings may not be used in tuples
|
||||
is_packed: bool;
|
||||
is_ordered: bool;
|
||||
is_raw_union: bool;
|
||||
custom_align: bool;
|
||||
};
|
||||
Union :: struct #ordered {
|
||||
variants: []^TypeInfo;
|
||||
tag_offset: int;
|
||||
@@ -126,7 +128,6 @@ TypeInfo :: struct #ordered {
|
||||
Vector,
|
||||
Tuple,
|
||||
Struct,
|
||||
RawUnion,
|
||||
Union,
|
||||
Enum,
|
||||
Map,
|
||||
|
||||
+9
-16
@@ -274,8 +274,9 @@ write_type :: proc(buf: ^StringBuffer, ti: ^TypeInfo) {
|
||||
|
||||
case Struct:
|
||||
write_string(buf, "struct ");
|
||||
if info.packed do write_string(buf, "#packed ");
|
||||
if info.ordered do write_string(buf, "#ordered ");
|
||||
if info.is_packed do write_string(buf, "#packed ");
|
||||
if info.is_ordered do write_string(buf, "#ordered ");
|
||||
if info.is_raw_union do write_string(buf, "#raw_union ");
|
||||
if info.custom_align {
|
||||
write_string(buf, "#align ");
|
||||
write_int(buf, i64(ti.align), 10);
|
||||
@@ -298,16 +299,6 @@ write_type :: proc(buf: ^StringBuffer, ti: ^TypeInfo) {
|
||||
}
|
||||
write_string(buf, "}");
|
||||
|
||||
case RawUnion:
|
||||
write_string(buf, "raw_union {");
|
||||
for name, i in info.names {
|
||||
if i > 0 do write_string(buf, ", ");
|
||||
write_string(buf, name);
|
||||
write_string(buf, ": ");
|
||||
write_type(buf, info.types[i]);
|
||||
}
|
||||
write_string(buf, "}");
|
||||
|
||||
case Enum:
|
||||
write_string(buf, "enum ");
|
||||
write_type(buf, info.base);
|
||||
@@ -317,6 +308,7 @@ write_type :: proc(buf: ^StringBuffer, ti: ^TypeInfo) {
|
||||
write_string(buf, name);
|
||||
}
|
||||
write_string(buf, "}");
|
||||
|
||||
case BitField:
|
||||
write_string(buf, "bit_field ");
|
||||
if ti.align != 1 {
|
||||
@@ -864,6 +856,11 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
|
||||
|
||||
case Struct:
|
||||
if info.is_raw_union {
|
||||
write_string(fi.buf, "(raw_union)");
|
||||
return;
|
||||
}
|
||||
|
||||
write_byte(fi.buf, '{');
|
||||
defer write_byte(fi.buf, '}');
|
||||
|
||||
@@ -891,10 +888,6 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
fmt_arg(fi, any{data, ti}, verb);
|
||||
}
|
||||
|
||||
|
||||
case RawUnion:
|
||||
write_string(fi.buf, "(raw_union)");
|
||||
|
||||
case Enum:
|
||||
fmt_enum(fi, v, verb);
|
||||
|
||||
|
||||
@@ -245,8 +245,6 @@ align_of_type_info :: proc(type_info: ^TypeInfo) -> int {
|
||||
return type_info.align;
|
||||
case Union:
|
||||
return type_info.align;
|
||||
case RawUnion:
|
||||
return type_info.align;
|
||||
case Enum:
|
||||
return align_of_type_info(info.base);
|
||||
case Map:
|
||||
@@ -305,8 +303,6 @@ size_of_type_info :: proc(type_info: ^TypeInfo) -> int {
|
||||
return type_info.size;
|
||||
case Union:
|
||||
return type_info.size;
|
||||
case RawUnion:
|
||||
return type_info.size;
|
||||
case Enum:
|
||||
return size_of_type_info(info.base);
|
||||
case Map:
|
||||
|
||||
+7
-7
@@ -83,19 +83,19 @@ is_tuple :: proc(info: ^TypeInfo) -> bool {
|
||||
}
|
||||
is_struct :: proc(info: ^TypeInfo) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(TypeInfo.Struct);
|
||||
return ok;
|
||||
s, ok := type_info_base(info).variant.(TypeInfo.Struct);
|
||||
return ok && !s.is_raw_union;
|
||||
}
|
||||
is_raw_union :: proc(info: ^TypeInfo) -> bool {
|
||||
if info == nil do return false;
|
||||
s, ok := type_info_base(info).variant.(TypeInfo.Struct);
|
||||
return ok && s.is_raw_union;
|
||||
}
|
||||
is_union :: proc(info: ^TypeInfo) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(TypeInfo.Union);
|
||||
return ok;
|
||||
}
|
||||
is_raw_union :: proc(info: ^TypeInfo) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(TypeInfo.RawUnion);
|
||||
return ok;
|
||||
}
|
||||
is_enum :: proc(info: ^TypeInfo) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(TypeInfo.Enum);
|
||||
|
||||
Reference in New Issue
Block a user