migrate to the new for-loop syntax

Drop the ':' before captures (for xs (x) / for 0..n (i)); the index
capture becomes the trailing open range (for xs, 0.. (x, i)). 136
headers across 26 files, mechanical.

Five headless tests (banner_layout, hit_test, swipe_commit,
swipe_intent, swipe_reshuffle) also gain a direct
#import "modules/ui/types.sx" — they named Point/Frame through a
transitive import, which bare visibility no longer permits.

Gates: sx build --target ios-sim main.sx links; tools/run_tests.sh
23/23.
This commit is contained in:
swipelab
2026-06-10 20:39:59 +03:00
parent 5a0627bb7c
commit a7b41ccbca
28 changed files with 141 additions and 136 deletions

View File

@@ -155,8 +155,8 @@ Board :: struct {
self.moves_made = 0;
self.move_limit = DEFAULT_MOVE_LIMIT;
self.target_score = DEFAULT_TARGET_SCORE;
for 0..BOARD_ROWS: (row) {
for 0..BOARD_COLS: (col) {
for 0..BOARD_ROWS (row) {
for 0..BOARD_COLS (col) {
self.set(col, row, pick_gem(self, @self.rng, col, row));
}
}
@@ -167,7 +167,7 @@ Board :: struct {
// upward. Pure given the board's already-placed prefix and the RNG state.
pick_gem :: (board: *Board, rng: *Rng, col: s64, row: s64) -> Gem {
forbidden : [GEM_COUNT]bool = ---;
for 0..GEM_COUNT: (t) { forbidden[t] = false; }
for 0..GEM_COUNT (t) { forbidden[t] = false; }
// Two same gems immediately to the left → a third of that type matches.
if col >= 2 {
@@ -185,11 +185,11 @@ pick_gem :: (board: *Board, rng: *Rng, col: s64, row: s64) -> Gem {
}
allowed := 0;
for 0..GEM_COUNT: (t) { if !forbidden[t] { allowed += 1; } }
for 0..GEM_COUNT (t) { if !forbidden[t] { allowed += 1; } }
// Pick the k-th still-allowed type; single RNG draw, always terminates.
k := rng.next_range(allowed);
for 0..GEM_COUNT: (t) {
for 0..GEM_COUNT (t) {
if !forbidden[t] {
if k == 0 { return cast(Gem) t; }
k -= 1;
@@ -203,9 +203,9 @@ pick_gem :: (board: *Board, rng: *Rng, col: s64, row: s64) -> Gem {
board_dump :: (self: *Board) -> string {
line_w := BOARD_COLS + 1; // 8 gem chars + newline
buf := cstring(BOARD_ROWS * line_w);
for 0..BOARD_ROWS: (row) {
for 0..BOARD_ROWS (row) {
base := row * line_w;
for 0..BOARD_COLS: (col) {
for 0..BOARD_COLS (col) {
buf[base + col] = gem_char(self.at(col, row));
}
buf[base + BOARD_COLS] = 10; // '\n'
@@ -229,7 +229,7 @@ MatchMask :: struct {
count :: (self: *MatchMask) -> s64 {
n : s64 = 0;
for 0..BOARD_CELLS: (i) { if self.cells[i] { n += 1; } }
for 0..BOARD_CELLS (i) { if self.cells[i] { n += 1; } }
n
}
}
@@ -238,7 +238,7 @@ MatchMask :: struct {
// is the constant coordinate (the row for a horizontal span, the column for a
// vertical one) and the span covers `start..end` of the moving coordinate.
mark_run :: (m: *MatchMask, vertical: bool, fixed: s64, start: s64, end: s64) {
for start..end: (i) {
for start..end (i) {
if vertical {
m.cells[Board.idx(fixed, i)] = true;
} else {
@@ -259,10 +259,10 @@ mark_run :: (m: *MatchMask, vertical: bool, fixed: s64, start: s64, end: s64) {
// break runs of real gems, since a hole differs from every gem type.
find_matches :: (b: *Board) -> MatchMask {
m : MatchMask = ---;
for 0..BOARD_CELLS: (i) { m.cells[i] = false; }
for 0..BOARD_CELLS (i) { m.cells[i] = false; }
// Horizontal: walk each row left-to-right in maximal same-type spans.
for 0..BOARD_ROWS: (row) {
for 0..BOARD_ROWS (row) {
col := 0;
while col < BOARD_COLS {
g := b.at(col, row);
@@ -276,7 +276,7 @@ find_matches :: (b: *Board) -> MatchMask {
}
// Vertical: walk each column top-to-bottom in maximal same-type spans.
for 0..BOARD_COLS: (col) {
for 0..BOARD_COLS (col) {
row := 0;
while row < BOARD_ROWS {
g := b.at(col, row);
@@ -299,9 +299,9 @@ find_matches :: (b: *Board) -> MatchMask {
dump_matches :: (b: *Board, m: *MatchMask) -> string {
line_w := BOARD_COLS + 1; // 8 cells + newline
buf := cstring(BOARD_ROWS * line_w);
for 0..BOARD_ROWS: (row) {
for 0..BOARD_ROWS (row) {
base := row * line_w;
for 0..BOARD_COLS: (col) {
for 0..BOARD_COLS (col) {
if m.at(col, row) {
buf[base + col] = gem_char(b.at(col, row));
} else {
@@ -371,8 +371,8 @@ Swap :: struct {
// the snapshot can depend on it.
legal_swaps :: (board: *Board) -> List(Swap) {
result := List(Swap).{};
for 0..BOARD_ROWS: (row) {
for 0..BOARD_COLS: (col) {
for 0..BOARD_ROWS (row) {
for 0..BOARD_COLS (col) {
here := Cell.{ col = col, row = row };
if col + 1 < BOARD_COLS {
right := Cell.{ col = col + 1, row = row };
@@ -397,7 +397,7 @@ legal_swaps :: (board: *Board) -> List(Swap) {
// as just "0 legal swaps", which reads unambiguously. Suitable for snapshotting.
dump_swaps :: (swaps: *List(Swap)) -> string {
result := format("{} legal swaps\n", swaps.len);
for 0..swaps.len: (i) {
for 0..swaps.len (i) {
s := swaps.items[i];
result = concat(result, format("({},{})-({},{})\n", s.a.col, s.a.row, s.b.col, s.b.row));
}
@@ -415,7 +415,7 @@ dump_swaps :: (swaps: *List(Swap)) -> string {
// `true` per shared cell) clear as one set with no double-counting.
clear_cells :: (board: *Board, mask: *MatchMask) -> s64 {
cleared : s64 = 0;
for 0..BOARD_CELLS: (i) {
for 0..BOARD_CELLS (i) {
if mask.cells[i] {
board.cells[i] = .empty;
cleared += 1;
@@ -449,7 +449,7 @@ clear_matches :: (board: *Board) -> s64 {
// this to know when gravity has stopped.
collapse :: (board: *Board) -> bool {
moved := false;
for 0..BOARD_COLS: (col) {
for 0..BOARD_COLS (col) {
// Pack this column's gems toward the bottom: scan it bottom-to-top and
// write each gem at the falling cursor `w`, which also descends from the
// bottom. A gem whose source row differs from `w` actually fell. `w`
@@ -492,8 +492,8 @@ collapse :: (board: *Board) -> bool {
refill :: (board: *Board) -> s64 {
rng := @board.rng;
filled : s64 = 0;
for 0..BOARD_ROWS: (row) {
for 0..BOARD_COLS: (col) {
for 0..BOARD_ROWS (row) {
for 0..BOARD_COLS (col) {
if board.at(col, row) == .empty {
board.set(col, row, cast(Gem) rng.next_range(GEM_COUNT));
filled += 1;
@@ -628,7 +628,7 @@ run_score :: (len: s64) -> s64 {
find_runs :: (b: *Board) -> List(Run) {
runs := List(Run).{};
for 0..BOARD_ROWS: (row) {
for 0..BOARD_ROWS (row) {
col := 0;
while col < BOARD_COLS {
g := b.at(col, row);
@@ -643,7 +643,7 @@ find_runs :: (b: *Board) -> List(Run) {
}
}
for 0..BOARD_COLS: (col) {
for 0..BOARD_COLS (col) {
row := 0;
while row < BOARD_ROWS {
g := b.at(col, row);
@@ -669,7 +669,7 @@ find_runs :: (b: *Board) -> List(Run) {
score_round :: (board: *Board) -> s64 {
runs := find_runs(board);
total : s64 = 0;
for 0..runs.len: (i) {
for 0..runs.len (i) {
total += run_score(runs.items[i].len);
}
total
@@ -724,7 +724,7 @@ SpecialCounts :: struct {
count_specials :: (board: *Board) -> SpecialCounts {
runs := find_runs(board);
counts := SpecialCounts.{ len4 = 0, len5_plus = 0 };
for 0..runs.len: (i) {
for 0..runs.len (i) {
len := runs.items[i].len;
if len == 4 {
counts.len4 += 1;
@@ -741,7 +741,7 @@ count_specials :: (board: *Board) -> SpecialCounts {
// "0 runs". Suitable for snapshotting.
dump_runs :: (runs: *List(Run)) -> string {
result := format("{} runs\n", runs.len);
for 0..runs.len: (i) {
for 0..runs.len (i) {
r := runs.items[i];
axis := if r.vertical then "V" else "H";
result = concat(result, format("{} len {} at fixed {} start {}\n", axis, r.len, r.fixed, r.start));
@@ -829,8 +829,8 @@ level_status :: (board: *Board) -> Status {
// a throwaway list each call. The trial swaps inside `swap_legal` are reverted,
// so the board is left unchanged.
has_legal_swap :: (board: *Board) -> bool {
for 0..BOARD_ROWS: (row) {
for 0..BOARD_COLS: (col) {
for 0..BOARD_ROWS (row) {
for 0..BOARD_COLS (col) {
here := Cell.{ col = col, row = row };
if col + 1 < BOARD_COLS {
right := Cell.{ col = col + 1, row = row };