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
+2 -2
View File
@@ -1086,7 +1086,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
return;
};
is_soa := b.soa_base_type != nil;
is_soa := b.soa_kind != .None;
strings.write_string(fi.buf, info.name);
strings.write_byte(fi.buf, is_soa ? '[' : '{');
@@ -1329,7 +1329,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
return;
}
is_soa := info.soa_base_type != nil;
is_soa := info.soa_kind != .None;
strings.write_byte(fi.buf, is_soa ? '[' : '{');
defer strings.write_byte(fi.buf, is_soa ? ']' : '}');
+19 -3
View File
@@ -162,6 +162,11 @@ are_types_identical :: proc(a, b: ^rt.Type_Info) -> bool {
y, ok := b.variant.(rt.Type_Info_Opaque);
if !ok do return false;
return x.elem == y.elem;
case rt.Type_Info_Simd_Vector:
y, ok := b.variant.(rt.Type_Info_Simd_Vector);
if !ok do return false;
return x.count == y.count && x.elem == y.elem;
}
return false;
@@ -394,13 +399,24 @@ write_type :: proc(buf: ^strings.Builder, ti: ^rt.Type_Info) {
write_type(buf, info.value);
case rt.Type_Info_Struct:
if info.soa_base_type != nil {
#complete switch info.soa_kind {
case .None: // Ignore
case .Fixed:
write_string(buf, "#soa[");
write_i64(buf, i64(info.soa_len));
write_byte(buf, ']');
write_type(buf, info.soa_base_type);
break;
}
return;
case .Slice:
write_string(buf, "#soa[]");
write_type(buf, info.soa_base_type);
return;
case .Dynamic:
write_string(buf, "#soa[dynamic]");
write_type(buf, info.soa_base_type);
return;
}
write_string(buf, "struct ");
if info.is_packed do write_string(buf, "#packed ");
if info.is_raw_union do write_string(buf, "#raw_union ");
+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);