Move examples/*.sx and their expected/ snapshots into per-category subfolders (examples/<category>/...). Folder = leading filename token, with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus runner and LSP sweep now discover each category's expected/ dir, while issues/ stays flat. Example 1058's repo-root-relative companion import is made file-relative. Path strings embedded in 164 snapshots were regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
35 lines
1.1 KiB
Plaintext
35 lines
1.1 KiB
Plaintext
// Comptime reflection — `type_info($T)`: reflect a SOURCE enum INTO a `TypeInfo`
|
|
// value, then feed that value straight back to `define` to mint a byte-identical
|
|
// copy. This is the inverse of `define`'s decode: `type_info` reads a type's
|
|
// variants (name + payload type) out of the type table and constructs the same
|
|
// `.enum(EnumInfo{ variants })` value the `define` examples write by hand.
|
|
//
|
|
// Round-trip: `ShapeCopy` is reconstructed purely from `type_info(Shape)` — no
|
|
// literal variant list — and constructs/matches like the original.
|
|
#import "modules/std.sx";
|
|
#import "modules/std/meta.sx";
|
|
|
|
Shape :: enum {
|
|
circle: f64;
|
|
rect: i64;
|
|
empty;
|
|
}
|
|
|
|
// Reflect Shape → TypeInfo, then reconstruct an identical nominal enum.
|
|
ShapeCopy :: define(declare("ShapeCopy"), type_info(Shape));
|
|
|
|
describe :: (s: ShapeCopy) {
|
|
if s == {
|
|
case .circle: (r) { print("circle r={}\n", r); }
|
|
case .rect: (n) { print("rect n={}\n", n); }
|
|
case .empty: { print("empty\n"); }
|
|
}
|
|
}
|
|
|
|
main :: () -> i32 {
|
|
describe(.circle(2.5));
|
|
describe(.rect(7));
|
|
describe(.empty);
|
|
return 0;
|
|
}
|