code wiki / (root) / nx_tier_swap_demo.nx

nx_tier_swap_demo.nx

buildroot/runtime/nx_tier_swap_demo.nx

1951 B62 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind sketch/demotopic tier
docsdependenciesstructsconstsfunctions

about

nx_tier_swap_demo.nx -- proof that nx_tier.nx swap is real. Computes the triangular sum 1 + 2 + ... + N where N is chosen to overflow signed 32-bit int but fit signed 64-bit. sum(N) = N * (N+1) / 2 N = 100000 -> sum = 5,000,050,000 (~5e9) int32 max = 2,147,483,647 (~2.1e9) -> overflows int64 max = 9.2e18 -> fits With nx_int = i64: prints "5000050000" and exits 0 With nx_int = i32: would wrap to a negative number and exit 1 (after editing nx_tier.nx to swap the alias). Substrate-level proof that one edit to nx_tier.nx propagates.

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_runtime.nx nx_tier.nx nx_tier_swap_demo.nx

imports: nx_syscalls.nxnx_runtime.nxnx_tier.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main triangular_sum sys_write strlen print_i64 sys_mmap nxa_die sys_write ↻ sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ itoa sys_mmap ↻ sys_write ↻

structs

none

consts

26const K_MAGIC_100000: i64 = 100000
27const K_MAGIC_5000050000: i64 = 5000050000
29const STDOUT: i64 = 1

functions

31func triangular_sum(n: nx_int) -> nx_int
called by 1: main
41func main() -> i64