code wiki / (root) / nx_market_ladder.nx

nx_market_ladder.nx source

↩ module page · 98 lines · 5326 B

1// nx_market_ladder.nx -- THE MARKET-ENTRY VERDICT CLI over nx_market_ladder_lib (2026-08-24, /compare PT6). 2// license_tier: ORIGINAL No hw writes (Rule 26). 3// nx_market_ladder <domain> [compare_dir] (default buildroot/knowledge/compare/ -- the tree the regen reads; 4// the nishihost twin is NOT the publish source, see the two-trees law) 5// Prints one row per ladder level: the authored verdict word, the computed verdict, required/landed/unresolved 6// counts and the binding rung, then a canonical LAST line `verdict=ML ...`. 7// EXIT: 0 every authored verdict agrees with the computed one | 1 a DISAGREE exists (the page's prose is wrong: a 8// defect, printed by name) | 2 usage | 3 no ladder rows (nothing to judge -- never a pass) 9import "nx_syscalls.nx" 10import "nx_market_ladder_lib.nx" 11 12const MC_EXIT_OK: i64 = 0 13const MC_EXIT_DISAGREE: i64 = 1 14const MC_EXIT_USAGE: i64 = 2 15const MC_EXIT_NONE: i64 = 3 16const MC_DIR_DEFAULT: *u8 = "buildroot/knowledge/compare/" 17const MC_PATH_CAP: i64 = 1024 18const MC_FIELD_CAP: i64 = 4096 19const MC_F_LEVEL: i64 = 1 20const MC_F_VERDICT: i64 = 5 21const MC_F_REQ: i64 = 6 22const MC_SLOT: i64 = 8 23const MC_LADDER_KW_LEN: i64 = 6 24 25func mc_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 26func mc_wn(v: i64) -> i64 { 27 var m: i64 = v 28 if m < 0 { mc_w("-" as *u8); m = 0 - m } 29 let t: *u8 = sys_mmap(32) 30 var k: i64 = 0 31 if m == 0 { t[0] = 48 as u8; k = 1 } 32 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 33 let o: *u8 = sys_mmap(32) 34 var i: i64 = 0 35 while i < k { o[i] = t[k - 1 - i]; i = i + 1 } 36 sys_write(1, o, k) 37 return 0 38} 39func mc_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; var p: i64 = o; while s[i] != (0 as u8) { d[p] = s[i]; p = p + 1; i = i + 1 } d[p] = 0 as u8; return p } 40 41func main(argc: i64, argv: *i64) -> i64 { 42 if argc < 2 { mc_w("usage: nx_market_ladder <domain> [compare_dir]\n" as *u8); return MC_EXIT_USAGE } 43 let dom: *u8 = argv[1] as *u8 44 var dir: *u8 = MC_DIR_DEFAULT 45 if argc >= 3 { dir = argv[2] as *u8 } 46 let plan_path: *u8 = sys_mmap(MC_PATH_CAP) 47 var o: i64 = mc_cat(plan_path, 0, dir) 48 o = mc_cat(plan_path, o, dom) 49 o = mc_cat(plan_path, o, ".plan" as *u8) 50 let matrix_path: *u8 = sys_mmap(MC_PATH_CAP) 51 ml_sibling_matrix(plan_path, matrix_path, MC_PATH_CAP) 52 mc_w("=== NX-MARKET-LADDER domain=" as *u8); mc_w(dom); mc_w(" plan=" as *u8); mc_w(plan_path); mc_w(" matrix=" as *u8); mc_w(matrix_path); mc_w("\n" as *u8) 53 let lp: *i64 = sys_mmap(MC_SLOT * 2) as *i64 54 let plan: *u8 = sys_read_file(plan_path, lp) 55 if (plan as i64) == 0 { mc_w("verdict=ML levels=0 (plan unreadable)\n" as *u8); return MC_EXIT_NONE } 56 let n: i64 = lp[0] 57 let box: *i64 = sys_mmap(MC_SLOT * 2) as *i64 58 let out: *i64 = sys_mmap(MC_SLOT * ML_OUT_SLOTS) as *i64 59 let level: *u8 = sys_mmap(MC_FIELD_CAP) 60 let verdict: *u8 = sys_mmap(MC_FIELD_CAP) 61 let req: *u8 = sys_mmap(MC_FIELD_CAP) 62 var levels: i64 = 0 63 var agree: i64 = 0 64 var disagree: i64 = 0 65 var prose: i64 = 0 66 var p: i64 = 0 67 while p < n { 68 var e: i64 = p 69 while e < n { if (plan[e] as i64) == ML_NL { break } e = e + 1 } 70 if e > p { if (plan[p] as i64) != ML_HASH { 71 ml_field(plan, p, e, 0, box) 72 if box[1] == MC_LADDER_KW_LEN { if ml_span_starts(plan, box[0], box[1], "ladder" as *u8) == 1 { 73 ml_field(plan, p, e, MC_F_LEVEL, box); ml_span_cstr(plan, box[0], box[1], level, MC_FIELD_CAP) 74 ml_field(plan, p, e, MC_F_VERDICT, box); ml_span_cstr(plan, box[0], box[1], verdict, MC_FIELD_CAP) 75 req[0] = 0 as u8 76 if ml_field(plan, p, e, MC_F_REQ, box) == 1 { ml_span_cstr(plan, box[0], box[1], req, MC_FIELD_CAP) } 77 let code: i64 = ml_entry_verdict(matrix_path, plan_path, req, out) 78 let authored: i64 = ml_authored_code(verdict) 79 let ag: i64 = ml_agrees(authored, code) 80 mc_w(" level=" as *u8); mc_w(level); mc_w(" authored=" as *u8); mc_w(ml_code_text(authored)) 81 mc_w(" computed=" as *u8); mc_w(ml_code_text(code)) 82 mc_w(" required=" as *u8); mc_wn(out[ML_OUT_REQUIRED]); mc_w(" landed=" as *u8); mc_wn(out[ML_OUT_LANDED]) 83 mc_w(" unresolved=" as *u8); mc_wn(out[ML_OUT_UNRESOLVED]) 84 if out[ML_OUT_BINDING_LEN] > 0 { mc_w(" binding=" as *u8); sys_write(1, (req as i64 + out[ML_OUT_BINDING_OFF]) as *u8, out[ML_OUT_BINDING_LEN]) } 85 if authored == ML_PROSE { mc_w(" agreement=PROSE" as *u8); prose = prose + 1 } 86 else { if ag == 1 { mc_w(" agreement=AGREE" as *u8); agree = agree + 1 } else { mc_w(" agreement=DISAGREE" as *u8); disagree = disagree + 1 } } 87 mc_w("\n" as *u8) 88 levels = levels + 1 89 } } 90 } } 91 p = e + 1 92 } 93 mc_w("verdict=ML domain=" as *u8); mc_w(dom); mc_w(" levels=" as *u8); mc_wn(levels); mc_w(" agree=" as *u8); mc_wn(agree) 94 mc_w(" disagree=" as *u8); mc_wn(disagree); mc_w(" prose=" as *u8); mc_wn(prose); mc_w("\n" as *u8) 95 if levels == 0 { return MC_EXIT_NONE } 96 if disagree > 0 { return MC_EXIT_DISAGREE } 97 return MC_EXIT_OK 98}