lang F1 4.2: (..F(Ts)) per-element type application in pack-shaped fields

packTypeElems now handles a parameterized spread operand F(Ts): for each pack
element T_i it temporarily binds the pack name to T_i and resolves F(T_i),
yielding (VL(T0), VL(T1), ...). Combined with parameterized-protocol value
types, the canonical Combined struct field sources: (..VL(Ts)) now resolves to
a tuple of real protocol values.

End-to-end (examples/207): instantiate Combined(s64, s64, string), whole-store
c.sources = (xx IntCell, xx StrCell), and per-element dispatch c.sources.0.get()
/ c.sources.1.get() all work. 242 examples + unit green.
This commit is contained in:
agra
2026-05-30 02:45:46 +03:00
parent 2f27f93bcf
commit a922814ba3
4 changed files with 61 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
// Phase 4.2 — the canonical `Combined` struct's storage layer: a generic
// struct whose field is a pack of PARAMETERIZED-protocol values,
// `sources: (..VL(Ts))` → `(VL(T0), VL(T1), …)`. Each `VL(Ti)` is a real
// 16-byte protocol value (issue: parameterized-protocol value types), and
// `(..VL(Ts))` applies `VL` per pack element. Instantiate + whole-tuple store
// of `xx`-erased values + per-element method dispatch all work.
#import "modules/std.sx";
VL :: protocol(T: Type) { get :: () -> T; }
IntCell :: struct { v: s64; }
StrCell :: struct { s: string; }
impl VL(s64) for IntCell { get :: (self: *IntCell) -> s64 => self.v; }
impl VL(string) for StrCell { get :: (self: *StrCell) -> string => self.s; }
Combined :: struct($R: Type, ..$Ts: []Type) {
sources: (..VL(Ts)); // (VL(T0), VL(T1), …) — tuple of protocol values
value: $R;
}
main :: () -> s32 {
// Combined(s64, s64, string): R=s64, Ts=[s64, string],
// sources: (VL(s64), VL(string)).
c : Combined(s64, s64, string) = ---;
c.sources = (xx IntCell.{ v = 10 }, xx StrCell.{ s = "hi" });
c.value = 99;
print("{} {} {}\n", c.sources.0.get(), c.sources.1.get(), c.value); // 10 hi 99
0;
}