code wiki / _hdl_build / nx_self_model_regen.nx

nx_self_model_regen.nx source

↩ module page · 25 lines · 1537 B

1// nx_self_model_regen.nx -- the LIBRARIAN regenerates the self-model count FROM the registry (data), instead 2// of Claude hand-editing a 229-cap inline main() that overruns the compiler's register allocator and 3// segfaults (operator: "keep building the team and dont do the work yourself"). The registry is DATA (one 4// CAPREG line per cap, written by nx_cap_register); this reader LOOPS over it -- a SMALL main, no reg 5// pressure, scales to thousands. This is the fix for the fat-main crash AND removes Claude from self-model 6// upkeep: the team registers caps -> the registry grows -> the Librarian regenerates the count. license_tier: ORIGINAL 7 8import "nx_syscalls.nx" 9 10// count non-overlapping occurrences of a marker (e.g. "status=2 " = PROVEN) in the registry text. 11func smr_count(buf: *u8, n: i64, mark: *u8) -> i64 { 12 var ml: i64 = 0; while mark[ml] != (0 as u8) { ml = ml + 1 } 13 var c: i64 = 0; var i: i64 = 0 14 while i <= n - ml { 15 var j: i64 = 0; var ok: i64 = 1 16 while j < ml { if buf[i+j] != mark[j] { ok = 0; j = ml } j = j + 1 } 17 if ok == 1 { c = c + 1; i = i + ml } else { i = i + 1 } 18 } 19 return c 20} 21 22// regenerate the counts from a registry buffer: PROVEN (status=2), building (status=1), planned (status=0). 23func smr_proven(buf: *u8, n: i64) -> i64 { return smr_count(buf, n, "status=2 " as *u8) } 24func smr_building(buf: *u8, n: i64) -> i64 { return smr_count(buf, n, "status=1 " as *u8) } 25func smr_total(buf: *u8, n: i64) -> i64 { return smr_count(buf, n, "CAPREG idx=" as *u8) }