Files
sx/examples/163-pack-runtime-index.sx
agra dadf80b3f1 ffi M5.A.next.2b.fu34.A: bare args + runtime index — lock in unresolved/LLVM errors
Lock-ins for follow-ups #3 (bare `args` reference) and #4
(`args[<runtime_int>]`) from step 2b. Both share the same root
cause: the pack-mono does not materialise an `[]Any` slice
value for the pack name, so any body that needs `args` as a
value at runtime fails.

`examples/162-pack-bare-args.sx` — pack-fn body forwards `args`
to a `[]Any`-typed helper. Today: "unresolved 'args' (in
... fn forward__pack_s64_string_f64)".

`examples/163-pack-runtime-index.sx` — pack-fn body indexes
`args[i]` with a runtime `i`. Today: LLVM verifier crash —
"GEP base pointer is not a vector or a vector of pointers" —
because `args` resolves to a junk Ref via the scope-lookup
fall-through, and the slice-indexing path emits a GEP off
that.

Next commit materialises an `[]Any` slice on demand inside the
mono: each pack param is boxed into Any, stored in a stack
[N x Any] array, and the slice {data_ptr, len} is bound to the
pack name. `args` then resolves as a runtime value the same way
the pre-2b inline path used to. `args[i]` runtime indexing goes
through the standard slice index path; element type is `Any`
(lossy on per-position types — inherent to runtime indexing
into a heterogeneous pack).

202/202 example tests + `zig build test` green.
2026-05-27 16:38:01 +03:00

36 lines
1.1 KiB
Plaintext

// Variadic heterogeneous type packs — follow-up #4 (runtime
// pack indexing).
//
// `args[<literal>]` substitutes through `pack_arg_nodes` (step
// 2a.B). But `args[<runtime_int>]` — a loop counter, an
// expression — falls through to the standard slice-indexing
// path, which fails because the pack-mono doesn't materialise
// the `args` slice. Output today: "unresolved 'args'".
//
// Pairs with follow-up #3: the same `[]Any` slice
// materialisation handles both `args` bare and `args[i]`
// runtime. Element type becomes `Any` (lossy on per-position
// types — that's the inherent trade-off of runtime indexing
// into a heterogeneous pack).
#import "modules/std.sx";
count_anys :: (..$args) -> s64 {
total : s64 = 0;
i : s64 = 0;
while i < args.len {
// Runtime index — should resolve through the
// materialised slice once #3+#4 lands.
x : Any = args[i];
_ = x;
total = total + 1;
i = i + 1;
}
return total;
}
main :: () -> s32 {
print("{}\n", count_anys(10, "hi", 2.5, true));
return 0;
}