array reflection

This commit is contained in:
2026-07-22 10:12:12 +02:00
parent 0d04925b3a
commit 07e89e23e1
12 changed files with 675 additions and 68 deletions
+6 -4
View File
@@ -1,6 +1,8 @@
Layout :: enum {
auto
c
Layout :: enum { auto c }
ArrayInfo :: struct {
child type
len usize
}
FieldInfo :: struct {
@@ -28,7 +30,7 @@ TypeInfo :: union(enum) {
bool void
integer void
float void
array void
array ArrayInfo
pointer void
slice void
range void
+16
View File
@@ -7,6 +7,22 @@ TestTokenKind :: enum(u8) {
}
TestNames :: alias EnumFieldStruct(TestTokenKind, ?[]u8, some!(null))
TestArrayAlias :: alias [3]u16
hide array_info_matches func($Array, $Child type, $len usize) bool {
match typeinfo!(Array) {
.array |info|: return info.child == Child and info.len == len
else: return false
}
}
array_reflection_exposes_child_and_logical_length test {
try testing.expect($(array_info_matches([4]i32, i32, 4)))
try testing.expect($(array_info_matches([0]bool, bool, 0)))
try testing.expect($(array_info_matches(TestArrayAlias, u16, 3)))
try testing.expect($(array_info_matches([2]mut i64, i64, 2)))
try testing.expect($(array_info_matches([2;0]u8, u8, 2)))
}
enum_field_struct_defaults test {
names TestNames = {