Files
sx/examples/comptime/0621-comptime-metatype-make-enum-sliced.sx
agra 66bdc70bf1 test: group examples into per-category folders
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.
2026-06-21 14:41:34 +03:00

31 lines
1.2 KiB
Plaintext

// Comptime slice over a non-string AGGREGATE: assemble a pool of candidate
// variants in a local array, then mint an enum from a SUBSLICE of it. This
// exercises the interp's `subslice` op on an array VALUE (`dirs[0..2]`) — which
// used to bail ("slice over non-string aggregates not yet supported") — now
// yielding a real `[]EnumVariant` the `define` decoder reads.
//
// `Axis` is built from only the first two of four directions, so `.south` /
// `.west` are NOT variants of it.
#import "modules/std.sx";
#import "modules/std/meta.sx";
build_axis :: () -> Type {
dirs := EnumVariant.[
EnumVariant.{ name = "north", payload = void },
EnumVariant.{ name = "east", payload = i64 }, // carries a bearing
EnumVariant.{ name = "south", payload = void },
EnumVariant.{ name = "west", payload = void },
];
return make_enum("Axis", dirs[0..2]); // first two only — a comptime subslice
}
Axis :: build_axis();
main :: () -> i32 {
a : Axis = .north;
b : Axis = .east(90);
if a == { case .north: { print("north\n"); } case .east: (d) { print("east {}\n", d); } }
if b == { case .north: { print("north\n"); } case .east: (d) { print("east {}\n", d); } }
return 0;
}