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.
This commit is contained in:
4
board.sx
4
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.
|
// single gem character per cell. Suitable for snapshotting.
|
||||||
board_dump :: (self: *Board) -> string {
|
board_dump :: (self: *Board) -> string {
|
||||||
line_w := BOARD_COLS + 1; // 8 gem chars + newline
|
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) {
|
for 0..BOARD_ROWS (row) {
|
||||||
base := row * line_w;
|
base := row * line_w;
|
||||||
for 0..BOARD_COLS (col) {
|
for 0..BOARD_COLS (col) {
|
||||||
@@ -298,7 +298,7 @@ find_matches :: (b: *Board) -> MatchMask {
|
|||||||
// unambiguously as the empty set. Suitable for snapshotting.
|
// unambiguously as the empty set. Suitable for snapshotting.
|
||||||
dump_matches :: (b: *Board, m: *MatchMask) -> string {
|
dump_matches :: (b: *Board, m: *MatchMask) -> string {
|
||||||
line_w := BOARD_COLS + 1; // 8 cells + newline
|
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) {
|
for 0..BOARD_ROWS (row) {
|
||||||
base := row * line_w;
|
base := row * line_w;
|
||||||
for 0..BOARD_COLS (col) {
|
for 0..BOARD_COLS (col) {
|
||||||
|
|||||||
11
main.sx
11
main.sx
@@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
// libc is the implicit foreign-library handle the std allocators bind against;
|
// libc is the implicit foreign-library handle the std allocators bind against;
|
||||||
// reused here to read the deterministic-capture environment variables at startup.
|
// 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
|
// 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.
|
// as a snapshot, so the on-screen layout matches that golden gem-for-gem.
|
||||||
@@ -116,14 +114,7 @@ build_ui :: () -> View {
|
|||||||
// M3TE_SELECT=<cellIndex 0..63> forces a selection so the select-pop reaction can
|
// M3TE_SELECT=<cellIndex 0..63> forces a selection so the select-pop reaction can
|
||||||
// be captured without injecting a tap. Absent → normal live behaviour.
|
// be captured without injecting a tap. Absent → normal live behaviour.
|
||||||
read_env :: (name: [:0]u8) -> ?string {
|
read_env :: (name: [:0]u8) -> ?string {
|
||||||
p := getenv(name);
|
process.env(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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Digit arithmetic runs entirely in i64; the result converts to f32 only once at
|
// Digit arithmetic runs entirely in i64; the result converts to f32 only once at
|
||||||
|
|||||||
Reference in New Issue
Block a user