code wiki / (root) / nx_wasm_scratch.nx

nx_wasm_scratch.nx

buildroot/runtime/nx_wasm_scratch.nx

2373 B46 linesdepth 0pulls 0 transitivereach 1 importersview sourcekind librarytopic wasm
docsdependenciesstructsconstsfunctions

about

nx_wasm_scratch.nx -- WASM-lane framed SCRATCH allocator: the linear-memory port of nx_scratch (nx_u256.nx), which is NATIVE-ONLY because it grows via sys_mmap (no wasm shim). This gives WASM organs the SAME save/alloc/restore shadow-stack the native lane has -> native<->wasm parity for multi-word locals, matching the language's REAL idiom (nx_scratch pointers) rather than a [i64;N] stack-array compiler feature the codebase deliberately rejects (nx_types.nx:469). Backed by a fixed linear-memory arena + a cursor cell; uses ONLY i64.load/store + arithmetic, so it runs in nx_wasm_vm and the browser with no syscalls. license_tier: ORIGINAL (API + frame discipline from nx_scratch in nx_u256.nx; mmap-arena -> linear-mem arena) Memory map (within the backend's 32-page / 2 MiB linear memory): [0 .. WS_BASE) organ's own fixed-offset region (framebuffers, guest RAM, etc.) [WS_BASE .. WS_TOP) the scratch arena (grows UP) [WS_CUR_CELL .. +8) the live cursor (the single-i64 frame mark), at the very top

dependencies 0 imports · 1 importers

nx_wasm_scratch.nx nx_scratch_probe.nx

imports: none

imported by: nx_scratch_probe.nx

structs

none

consts

13const WS_BASE: i64 = 1048576 // 1 MiB
14const WS_TOP: i64 = 2097144 // arena end (just below the cursor cell)
15const WS_CUR_CELL: i64 = 2097144 // 8-byte cursor cell at the top of the 2 MiB memory

functions

18func ws_cur_load() -> i64
24func ws_cur_store(c: i64) -> i64
32func nx_scratch(n: i64) -> *u8
45func nx_scratch_save() -> i64 { return ws_cur_load() }
called by 2: sp_gapsp_probe calls 1: ws_cur_load
46func nx_scratch_restore(mark: i64) -> i64 { ws_cur_store(mark); return 0 }
called by 2: sp_gapsp_probe calls 1: ws_cur_store