Prepare SOA Struct code for slices and dynamic arrays *to be implemented*

This commit is contained in:
gingerBill
2019-11-19 23:54:36 +00:00
parent 0839dccfdc
commit 44e0e96612
9 changed files with 112 additions and 37 deletions
+8
View File
@@ -47,6 +47,13 @@ Platform_Endianness :: enum u8 {
Big = 2,
}
Type_Info_Struct_Soa_Kind :: enum u8 {
None = 0,
Fixed = 1,
Slice = 2,
Dynamic = 3,
}
// Variant Types
Type_Info_Named :: struct {name: string, base: ^Type_Info};
Type_Info_Integer :: struct {signed: bool, endianness: Platform_Endianness};
@@ -88,6 +95,7 @@ Type_Info_Struct :: struct {
is_raw_union: bool,
custom_align: bool,
// These are only set iff this structure is an SOA structure
soa_kind: Type_Info_Struct_Soa_Kind,
soa_base_type: ^Type_Info,
soa_len: int,
};
+26 -7
View File
@@ -137,7 +137,7 @@ print_type :: proc(fd: os.Handle, ti: ^Type_Info) {
os.write_string(fd, "()");
} else {
t := info.params.variant.(Type_Info_Tuple);
os.write_string(fd, "(");
os.write_byte(fd, '(');
for t, i in t.types {
if i > 0 do os.write_string(fd, ", ");
print_type(fd, t);
@@ -150,7 +150,7 @@ print_type :: proc(fd: os.Handle, ti: ^Type_Info) {
}
case Type_Info_Tuple:
count := len(info.names);
if count != 1 do os.write_string(fd, "(");
if count != 1 do os.write_byte(fd, '(');
for name, i in info.names {
if i > 0 do os.write_string(fd, ", ");
@@ -165,9 +165,9 @@ print_type :: proc(fd: os.Handle, ti: ^Type_Info) {
if count != 1 do os.write_string(fd, ")");
case Type_Info_Array:
os.write_string(fd, "[");
os.write_byte(fd, '[');
print_u64(fd, u64(info.count));
os.write_string(fd, "]");
os.write_byte(fd, ']');
print_type(fd, info.elem);
case Type_Info_Dynamic_Array:
os.write_string(fd, "[dynamic]");
@@ -183,13 +183,24 @@ print_type :: proc(fd: os.Handle, ti: ^Type_Info) {
print_type(fd, info.value);
case Type_Info_Struct:
if info.soa_base_type != nil {
#complete switch info.soa_kind {
case .None: // Ignore
case .Fixed:
os.write_string(fd, "#soa[");
print_u64(fd, u64(info.soa_len));
os.write_byte(fd, ']');
print_type(fd, info.soa_base_type);
break;
return;
case .Slice:
os.write_string(fd, "#soa[]");
print_type(fd, info.soa_base_type);
return;
case .Dynamic:
os.write_string(fd, "#soa[dynamic]");
print_type(fd, info.soa_base_type);
return;
}
os.write_string(fd, "struct ");
if info.is_packed do os.write_string(fd, "#packed ");
if info.is_raw_union do os.write_string(fd, "#raw_union ");
@@ -208,7 +219,15 @@ print_type :: proc(fd: os.Handle, ti: ^Type_Info) {
os.write_byte(fd, '}');
case Type_Info_Union:
os.write_string(fd, "union {");
os.write_string(fd, "union ");
if info.custom_align {
os.write_string(fd, "#align ");
print_u64(fd, u64(ti.align));
}
if info.no_nil {
os.write_string(fd, "#no_nil ");
}
os.write_byte(fd, '{');
for variant, i in info.variants {
if i > 0 do os.write_string(fd, ", ");
print_type(fd, variant);