nx_langsem_lib.nx source
↩ module page · 29 lines · 1814 B
1// nx_langsem_lib.nx -- the OTHER MODULE for nx_langsem_gate. It exists so the gate can ask a
2// question no single-file test can ask: when an importer assigns a static declared HERE, does THIS
3// module see the same storage, or did each module get its own copy?
4//
5// That question was answered by accident on 2026-08-28 while extracting nx_worldpipe_core: the
6// extraction only works because nx_worldpipe's wp_init still assigns WP_SEED, WP_TEMP_BIAS,
7// WP_CONT_BIAS and WP_MOUNT_SCALE from OUTSIDE the module that declares them. It compiled and ran,
8// so the semantics hold -- but nothing in the estate ASSERTED it, which means the whole
9// shared-core/base-class pattern rested on a fact no gate protected. This lib is the other half of
10// that assertion.
11// license_tier: ORIGINAL No hw writes (Rule 26).
12import "nx_syscalls.nx"
13
14// a const the importer must be able to read (cross-module const visibility)
15const LS_CONST_ANSWER: i64 = 424242
16// a static the importer must be able to WRITE, and which this module must then see (single storage)
17static LS_SHARED: i64
18// a second static that NOBODY assigns: its value is the zero-initialisation claim
19static LS_UNTOUCHED: i64
20
21// read the shared static FROM INSIDE the declaring module -- the whole point of the lib
22func ls_get() -> i64 { return LS_SHARED }
23// write it from inside, so the gate can prove the channel works in both directions
24func ls_set(v: i64) -> i64 { LS_SHARED = v; return 0 }
25// read the never-assigned static from inside
26func ls_untouched() -> i64 { return LS_UNTOUCHED }
27// a pure function whose arithmetic the gate pins (division/modulo sign behaviour crosses modules
28// too -- a compiler that changed it would change this lib's answers, not just the gate's)
29func ls_divmod_probe(a: i64, b: i64) -> i64 { return (a/b)*100 + (a%b) }