nx_retire_onto.nx source
↩ module page · 54 lines · 3306 B
1// nx_retire_onto.nx -- CLI for retiring a private function onto its shared owner (global tooling, 2026-08-24).
2// Thin main only; every function lives in nx_retire_onto_lib.nx so nx_retire_onto_gate composes them in-process.
3//
4// nx_retire_onto one <file.nx> <private_fn> <owner_lib.nx> <owner_fn> [dry|prove|apply]
5// nx_retire_onto sweep <plane-prefix> <symbol-suffix> <owner_lib.nx> <owner_fn> [dry|prove|apply]
6// prove = generate a differential probe (private vs owner over a declared input ladder), build it with the
7// estate's builder, run it; apply = the same, and write ONLY on a PASS. Nothing writes unproven.
8// plane-prefix is the libindex row plane, spelled IN FULL (knowledge/store/libindex-); every library symbol
9// ending in <symbol-suffix> is a candidate. Dry by default. Prints one line per candidate and a partition
10// that sums: retirable + already + applied + refused = candidates.
11// exit 0 = ran (dry, applied, already) · 1 = a sweep saw at least one REFUSED · 2 = usage or a single REFUSED
12// license_tier: ORIGINAL
13
14import "nx_retire_onto_lib.nx"
15
16func rom_usage() -> i64 {
17 ro_out("usage: nx_retire_onto one <file.nx> <private_fn> <owner_lib.nx> <owner_fn> [apply]\n" as *u8)
18 ro_out(" nx_retire_onto sweep <plane-prefix> <symbol-suffix> <owner_lib.nx> <owner_fn> [apply]\n" as *u8)
19 ro_out(" Rewrites the private function's BODY to one call of the owner (name, arity, types, return type must\n" as *u8)
20 ro_out(" match; refuses by name otherwise) and inserts the owner's import if absent. Dry unless `apply`.\n" as *u8)
21 ro_out(" The proof of neutrality is the consumer rebuild and its gates; a changed floor is a NAMED delta.\n" as *u8)
22 return 2
23}
24
25func main(argc: i64, argv: *i64) -> i64 {
26 if argc < 6 { return rom_usage() }
27 let op: *u8 = argv[1] as *u8
28 // mode: absent or `dry` = signature check only; `prove` = plus the differential probe, no write;
29 // `apply` = probe, then write only on PASS. There is no way to write without the probe.
30 var mode: i64 = RO_MODE_DRY
31 if argc >= 7 {
32 if ro_streq(argv[6] as *u8, "apply" as *u8) == 1 { mode = RO_MODE_APPLY }
33 if ro_streq(argv[6] as *u8, "prove" as *u8) == 1 { mode = RO_MODE_PROVE }
34 }
35 if ro_streq(op, "one" as *u8) == 1 {
36 let code: i64 = ro_one(argv[2] as *u8, argv[3] as *u8, argv[4] as *u8, argv[5] as *u8, mode, 0)
37 if code == RO_REFUSED { return 2 }
38 if code == RO_REFUSED_DIFFER { return 2 }
39 if code == RO_REFUSED_UNBUILDABLE { return 2 }
40 if code == RO_REFUSED_UNSUPPORTED { return 2 }
41 return 0
42 }
43 if ro_streq(op, "sweep" as *u8) == 1 {
44 let tally: *i64 = sys_mmap(RO_T_N * 8) as *i64
45 let rc: i64 = ro_sweep(argv[2] as *u8, argv[3] as *u8, argv[4] as *u8, argv[5] as *u8, mode, tally)
46 if rc < 0 { return 2 }
47 if tally[RO_REFUSED] + tally[RO_REFUSED_DIFFER] + tally[RO_REFUSED_UNBUILDABLE] + tally[RO_REFUSED_UNSUPPORTED] > 0 { return 1 }
48 // a deferred candidate is UNKNOWN, not refused: the sweep is INCOMPLETE and says so with exit 3
49 if tally[RO_DEFERRED_ADMISSION] > 0 { return 3 }
50 return 0
51 }
52 ro_out("NX-RETIRE-ONTO unknown verb -- expected one or sweep\n" as *u8)
53 return rom_usage()
54}