lang F1: range-based for + inline-for unroll over packs

Add range loop syntax:
- runtime  for start..end (i) { }   counting loop, cursor optional, end exclusive
- comptime inline for start..end (i) { }   comptime-unrolled body

The inline form binds the cursor as an int_val comptime constant per
iteration, so xs[i] over a heterogeneous pack substitutes the concrete
per-position element -- the canonical's pack-iteration vehicle
(inline for 0..sources.len (i) { sources[i].addListener(...) }).

- AST: ForExpr.range_end, ForExpr.is_inline
- parser: parseForExpr range vs collection form; suppress_call flag so
  N (i) is not read as a call N(i) while parsing a range bound
- lower: lowerRuntimeRangeFor / lowerInlineRangeFor; evalComptimeInt;
  comptimeIndexOf extends pack-index resolution beyond int literals

Revises spec's inline for i in 0..N to the no-in, range-first, paren-cursor
form. Regression: examples/200-for-range.sx.
This commit is contained in:
agra
2026-05-29 21:36:17 +03:00
parent 27fd5e1e6a
commit 27c88d4d26
7 changed files with 305 additions and 29 deletions

View File

@@ -482,6 +482,13 @@ pub const ForExpr = struct {
body: *Node,
capture_name: []const u8,
index_name: ?[]const u8 = null,
/// Range form `for start..end (i) { }`: `iterable` is the start, `range_end`
/// the (exclusive) end. Null for the iterate-a-collection form
/// (`for coll : (x) { }`). For the range form `capture_name` is the cursor
/// (empty when omitted, `for 0..N { }`).
range_end: ?*Node = null,
/// `inline for` — comptime-unrolled (range bounds must be comptime).
is_inline: bool = false,
};
pub const SpreadExpr = struct {