reflection foundation, tuples, debug.print

This commit is contained in:
2026-07-14 23:45:30 +02:00
parent 267947e79d
commit 0b2055d64b
24 changed files with 126598 additions and 115394 deletions
+87
View File
@@ -0,0 +1,87 @@
debug :: import "@std/debug"
meta :: import "@std/meta"
Numbers :: struct { i8, i16, i32 }
Row :: struct { value i32 }
format func() []u8 {
return "tuple={d}/{s}, limits={d}/{d}"
}
sum func($T type, value T) i32 {
total i32 = 0
match typeinfo!(T) {
.record |record|: inline for record.fields |field| {
total += i32(field!(value, field.name))
}
else: compile_error!("sum requires a record")
}
return total
}
static_control func($T type, value T) i32 {
total i32 = 0
match typeinfo!(T) {
.record |record|: inline for record.fields |field| {
{
if field.index == 1 {
continue
}
total += i32(field!(value, field.name))
match typeinfo!(field.type) {
.integer: {
if field.index == 2 {
break
}
}
else: _ = 0
}
}
total += 100
}
else: compile_error!("static_control requires a record")
}
return total
}
row_value func(row Row) i32 {
return row.value
}
static_aggregates func() i32 {
total i32 = 0
inline for {Row {value = 2}, Row {value = 40}} |row| {
total += row_value(row)
}
return total
}
main func() i32 {
numbers Numbers = Numbers {1, 2, 39}
singleton :: {42,}
empty :: {}
block_value :: {
yield 42
}
_ = empty
if singleton.0 != block_value {
return 2
}
if sum(Numbers, numbers) != 42 {
return 1
}
if static_control(Numbers, numbers) != 140 {
return 3
}
if static_aggregates() != 42 {
return 4
}
field!(&numbers, "2") += 1
debug.print(format(), {
numbers.2,
"bro",
minval!(i64),
maxval!(u64),
})
return 0
}