static string map
This commit is contained in:
+9
-7
@@ -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
|
||||
@@ -44,9 +46,9 @@ TypeInfo :: union(enum) {
|
||||
EnumFieldStruct func($E, $Field type, $default ?Field) type {
|
||||
match typeinfo!(E) {
|
||||
.enum |info|: {
|
||||
names [info.fields.len]mut []u8 = undefined
|
||||
field_types [info.fields.len]mut type = undefined
|
||||
defaults [info.fields.len]mut ?Field = undefined
|
||||
names [info.fields.len]mut []u8 = undefined
|
||||
field_types [info.fields.len]mut type = undefined
|
||||
defaults [info.fields.len]mut ?Field = undefined
|
||||
expand for info.fields |field, index| {
|
||||
names[index] = field.name
|
||||
field_types[index] = Field
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user