code wiki / _hdl_build / dep_pipeline.nx
dep_pipeline.nx source
↩ module page · 25 lines · 1582 B
1// AUTHORED BY nx_compose_builder (X-AUTH-EXT-001 composition shape) from a DATA spec.
2// Fail-fast pipeline sequencer: run stages in order; 0 if all exit 0, else 1-based index
3// of the first failure (the abort/rollback point). KAT computed from the step count.
4import "nx_syscalls.nx"
5import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
6func dep_pipeline_run(codes: *i64, n: i64) -> i64 { var i: i64 = 0; while i < n { if codes[i] != 0 { return i + 1 } i = i + 1 } return 0 }
7func dep_pipeline_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
8// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
9// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
10// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
11// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
12func dep_pipeline_pn(v: i64) -> i64 { nxi_out(v); return 0 }
13func main() -> i64 {
14 let a: *i64 = sys_mmap(8 * 5) as *i64
15 var i: i64 = 0
16 while i < 5 { a[i] = 0; i = i + 1 }
17 let all_ok: i64 = dep_pipeline_run(a, 5)
18 a[2] = 1
19 let fail_at: i64 = dep_pipeline_run(a, 5)
20 dep_pipeline_p("PIPEGATE all_ok=" as *u8); dep_pipeline_pn(all_ok)
21 dep_pipeline_p(" fail_at=" as *u8); dep_pipeline_pn(fail_at); dep_pipeline_p(" steps=5" as *u8)
22 if all_ok == 0 { if fail_at == 3 { dep_pipeline_p(" verdict=GREEN\n" as *u8); return 0 } }
23 dep_pipeline_p(" verdict=RED\n" as *u8)
24 return 1
25}