From 39740a1d36b3c09f068f0c8c0a077b54345af3f9 Mon Sep 17 00:00:00 2001 From: swipelab Date: Fri, 12 Jun 2026 14:57:59 +0300 Subject: [PATCH] migrate to sx cstring era: std env() replaces local getenv/strlen, alloc_string rename sx 1d17b0a reserves 'cstring' as the C-boundary string type and renames std's cstring(size) allocator to alloc_string; std getenv is now (cstring) -> ?cstring, so the local conflicting binding (caught by the new same-symbol diagnostic) and its strlen/copy loop collapse into a process.env delegation. iOS-sim build + 22/22 snapshots green. --- board.sx | 4 ++-- main.sx | 11 +---------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/board.sx b/board.sx index 912a0f8..7bc76ca 100644 --- a/board.sx +++ b/board.sx @@ -202,7 +202,7 @@ pick_gem :: (board: *Board, rng: *Rng, col: i64, row: i64) -> Gem { // single gem character per cell. Suitable for snapshotting. board_dump :: (self: *Board) -> string { line_w := BOARD_COLS + 1; // 8 gem chars + newline - buf := cstring(BOARD_ROWS * line_w); + buf := alloc_string(BOARD_ROWS * line_w); for 0..BOARD_ROWS (row) { base := row * line_w; for 0..BOARD_COLS (col) { @@ -298,7 +298,7 @@ find_matches :: (b: *Board) -> MatchMask { // unambiguously as the empty set. Suitable for snapshotting. dump_matches :: (b: *Board, m: *MatchMask) -> string { line_w := BOARD_COLS + 1; // 8 cells + newline - buf := cstring(BOARD_ROWS * line_w); + buf := alloc_string(BOARD_ROWS * line_w); for 0..BOARD_ROWS (row) { base := row * line_w; for 0..BOARD_COLS (col) { diff --git a/main.sx b/main.sx index 520b61b..f1aba31 100644 --- a/main.sx +++ b/main.sx @@ -24,8 +24,6 @@ // libc is the implicit foreign-library handle the std allocators bind against; // reused here to read the deterministic-capture environment variables at startup. -getenv :: (name: [:0]u8) -> *u8 #foreign libc "getenv"; -strlen :: (s: *u8) -> usize #foreign libc "strlen"; // Fixed seed for the rendered board — the same seed tests/board_init.sx locks // as a snapshot, so the on-screen layout matches that golden gem-for-gem. @@ -116,14 +114,7 @@ build_ui :: () -> View { // M3TE_SELECT= forces a selection so the select-pop reaction can // be captured without injecting a tap. Absent → normal live behaviour. read_env :: (name: [:0]u8) -> ?string { - p := getenv(name); - addr : i64 = xx p; - if addr == 0 { return null; } - n := cast(i64) strlen(p); - if n == 0 { return ""; } - buf := cstring(n); - memcpy(buf.ptr, xx p, n); - buf + process.env(name) } // Digit arithmetic runs entirely in i64; the result converts to f32 only once at