nx_ladder.nx source
↩ module page · 192 lines · 9461 B
1// nx_ladder.nx -- CLI over nx_ladder_lib: does this board say what best-in-class and the frontier are (dated), and what
2// every rung is FOR on the way there? One domain, or `all` over regen.list for the estate-wide census.
3// nx_ladder <domain> per target and per rung lines, the partition, verdict LAST
4// nx_ladder all one line per domain in regen.list, then the estate partition; exit 1 if any PARTIAL
5// exit: 0 LADDERED | 1 PARTIAL (declared and broken: the hard fail) | 2 usage | 3 NO-LADDER or NO-PLAN
6// license_tier: ORIGINAL No hw writes (Rule 26).
7import "nx_syscalls.nx"
8import "nx_barfresh_lib.nx"
9import "nx_ladder_lib.nx"
10
11const LDC_ARG_DOMAIN: i64 = 1
12const LDC_EXIT_USAGE: i64 = 2
13const LDC_NUM_CAP: i64 = 24
14const LDC_STDOUT: i64 = 1
15const LDC_ALL: *u8 = "all"
16const LDC_REGEN_DOM: *u8 = "regen"
17const LDC_REGEN_SUFFIX: *u8 = ".list"
18const LDC_NAME_CAP: i64 = 128
19const LDC_EXIT_NOPLAN: i64 = 3
20
21func ldc_w(s: *u8) -> i64 {
22 return sys_write(LDC_STDOUT, s, bf_slen(s))
23}
24func ldc_wn(v: i64) -> i64 {
25 let b: *u8 = sys_mmap(LDC_NUM_CAP)
26 var x: i64 = v
27 var neg: i64 = 0
28 if x < 0 { neg = 1; x = 0 - x }
29 var o: i64 = LDC_NUM_CAP - 1
30 b[o] = 0 as u8
31 o = o - 1
32 if x == 0 { b[o] = BF_DIGIT0 as u8; o = o - 1 }
33 while x > 0 { b[o] = (x - (x / 10) * 10 + BF_DIGIT0) as u8; o = o - 1; x = x / 10 }
34 if neg == 1 { b[o] = BF_DASH as u8; o = o - 1 }
35 return ldc_w((b as i64 + o + 1) as *u8)
36}
37func ldc_wspan(buf: *u8, off: i64, len: i64) -> i64 {
38 if len <= 0 { return 0 }
39 return sys_write(LDC_STDOUT, (buf as i64 + off) as *u8, len)
40}
41
42// classify one plan buffer, print the census line prefixed by label; returns the verdict
43func ldc_report(dom: *u8, buf: *u8, n: i64, verbose: i64) -> i64 {
44 let nt: i64 = bf_count_rows(buf, n, LD_TARGET_TAG)
45 let nr: i64 = bf_count_rows(buf, n, LD_RUNG_TAG)
46 let toff: *i64 = sys_mmap((nt + 1) * LD_I64) as *i64
47 let tcls: *i64 = sys_mmap((nt + 1) * LD_I64) as *i64
48 let tst: *i64 = sys_mmap((nt + 1) * LD_I64) as *i64
49 let roff: *i64 = sys_mmap((nr + 1) * LD_I64) as *i64
50 let rrole: *i64 = sys_mmap((nr + 1) * LD_I64) as *i64
51 let rtgt: *i64 = sys_mmap((nr + 1) * LD_I64) as *i64
52 let rst: *i64 = sys_mmap((nr + 1) * LD_I64) as *i64
53 let c: *i64 = sys_mmap(LD_N_COUNT * LD_I64) as *i64
54 let tclimb: *i64 = sys_mmap((nt + 1) * LD_I64) as *i64
55 ld_classify(buf, n, toff, tcls, tst, roff, rrole, rtgt, rst, c)
56 // TARGET-to-RUNG coverage: ld_classify only ever asked RUNG-to-TARGET, so a declared target with no
57 // climber read as a fully laddered board. Announced and counted here; the verdict is untouched.
58 ld_target_climbers(c[LD_N_TARGETS], c[LD_N_RUNGS], rtgt, rst, tclimb, c)
59 let fo: *i64 = sys_mmap(LD_I64) as *i64
60 if verbose == 1 {
61 var i: i64 = 0
62 while i < c[LD_N_TARGETS] {
63 let p: i64 = toff[i]
64 let e: i64 = bf_line_end(buf, n, p)
65 ldc_w(" TARGET " as *u8)
66 var l: i64 = bf_field(buf, p, e, LD_F_T_ID, fo); ldc_wspan(buf, fo[0], l)
67 ldc_w(" class=" as *u8); ldc_w(ld_class_name(tcls[i]))
68 ldc_w(" bar=" as *u8); l = bf_field(buf, p, e, LD_F_T_BAR, fo); ldc_wspan(buf, fo[0], l)
69 ldc_w(" state=" as *u8); ldc_w(ld_tstate_name(tst[i]))
70 ldc_w(" climbers=" as *u8); ldc_wn(tclimb[i])
71 if tclimb[i] == 0 { ldc_w(" UNCLIMBED(declared target, ZERO rungs climb it: this board STATES this goal and no work ADVANCES it -- declare a rungrole row against it, or retire the target)" as *u8) }
72 ldc_w(" | " as *u8); l = bf_field(buf, p, e, LD_F_T_STATEMENT, fo); ldc_wspan(buf, fo[0], l)
73 ldc_w("\n" as *u8)
74 i = i + 1
75 }
76 var r: i64 = 0
77 while r < c[LD_N_RUNGS] {
78 let p2: i64 = roff[r]
79 let e2: i64 = bf_line_end(buf, n, p2)
80 ldc_w(" RUNG " as *u8)
81 var l2: i64 = bf_field(buf, p2, e2, LD_F_R_ID, fo); ldc_wspan(buf, fo[0], l2)
82 ldc_w(" state=" as *u8); ldc_w(ld_place_name(rst[r]))
83 ldc_w(" role=" as *u8)
84 if rrole[r] == LD_NONE { ldc_w("-" as *u8) } else { ldc_w(ld_role_name(rrole[r])) }
85 ldc_w(" target=" as *u8)
86 if rtgt[r] == LD_NONE { ldc_w("-" as *u8) } else {
87 let tp: i64 = toff[rtgt[r]]
88 let te: i64 = bf_line_end(buf, n, tp)
89 let tl: i64 = bf_field(buf, tp, te, LD_F_T_ID, fo); ldc_wspan(buf, fo[0], tl)
90 }
91 ldc_w(" deps=" as *u8); l2 = bf_field(buf, p2, e2, LD_F_R_DEPS, fo); ldc_wspan(buf, fo[0], l2)
92 ldc_w(" | " as *u8); l2 = bf_field(buf, p2, e2, LD_F_R_TITLE, fo); ldc_wspan(buf, fo[0], l2)
93 ldc_w("\n" as *u8)
94 r = r + 1
95 }
96 }
97 let v: i64 = ld_verdict(c)
98 if v == LD_EXIT_PARTIAL { ldc_w("REFUSAL-RULE: " as *u8); ldc_w(ld_refusal_rule(c)); ldc_w("\n" as *u8) }
99 ldc_w("LADDER domain=" as *u8); ldc_w(dom)
100 ldc_w(" targets=" as *u8); ldc_wn(c[LD_N_TARGETS])
101 ldc_w(" best_in_class=" as *u8); ldc_wn(c[LD_N_BIC])
102 ldc_w(" frontier=" as *u8); ldc_wn(c[LD_N_FRONTIER])
103 ldc_w(" undated=" as *u8); ldc_wn(c[LD_N_UNDATED])
104 ldc_w(" badclass=" as *u8); ldc_wn(c[LD_N_BADCLASS])
105 ldc_w(" rungs=" as *u8); ldc_wn(c[LD_N_RUNGS])
106 ldc_w(" placed=" as *u8); ldc_wn(c[LD_N_PLACED])
107 ldc_w(" unplaced=" as *u8); ldc_wn(c[LD_N_UNPLACED])
108 ldc_w(" badrole=" as *u8); ldc_wn(c[LD_N_BADROLE])
109 ldc_w(" badtarget=" as *u8); ldc_wn(c[LD_N_BADTARGET])
110 ldc_w(" sum=" as *u8); ldc_wn(ld_partition_sum(c))
111 ldc_w(" substrate=" as *u8); ldc_wn(c[LD_N_SUBSTRATE])
112 ldc_w(" arm=" as *u8); ldc_wn(c[LD_N_ARM])
113 ldc_w(" contender=" as *u8); ldc_wn(c[LD_N_CONTENDER])
114 ldc_w(" superseded=" as *u8); ldc_wn(c[LD_N_SUPERSEDED])
115 ldc_w(" duptarget=" as *u8); ldc_wn(c[LD_N_DUPTARGET])
116 ldc_w(" duprole=" as *u8); ldc_wn(c[LD_N_DUPROLE])
117 ldc_w(" orphan_ladder_rows=" as *u8); ldc_wn(c[LD_N_ORPHANS])
118 ldc_w(" targets_unclimbed=" as *u8); ldc_wn(c[LD_N_UNCLIMBED])
119 ldc_w(" verdict=" as *u8); ldc_w(ld_verdict_name(v)); ldc_w("\n" as *u8)
120 return v
121}
122
123func main(argc: i64, argv: *i64) -> i64 {
124 if argc <= LDC_ARG_DOMAIN {
125 ldc_w("usage: nx_ladder <domain> | all -- exit 0 LADDERED | 1 PARTIAL | 3 NO-LADDER or NO-PLAN\n" as *u8)
126 return LDC_EXIT_USAGE
127 }
128 let dom: *u8 = argv[LDC_ARG_DOMAIN] as *u8
129 let lenp: *i64 = sys_mmap(LD_I64) as *i64
130 let which: *i64 = sys_mmap(LD_I64) as *i64
131 if ld_span_is(dom, 0, bf_slen(dom), LDC_ALL) == 1 {
132 // the population is regen.list (one domain per line), read through the same two trees as the plans
133 let path: *u8 = sys_mmap(CT_PATH_CAP)
134 ct_build_path(ct_first_published(), LDC_REGEN_DOM, LDC_REGEN_SUFFIX, path)
135 lenp[0] = 0
136 var lst: *u8 = sys_read_file(path, lenp)
137 if lenp[0] <= 0 {
138 ct_build_path(ct_second_published(), LDC_REGEN_DOM, LDC_REGEN_SUFFIX, path)
139 lst = sys_read_file(path, lenp)
140 }
141 if lenp[0] <= 0 { ldc_w("LADDER-ALL regen.list UNREADABLE in both trees verdict=NO-POPULATION\n" as *u8); return LDC_EXIT_NOPLAN }
142 let ln: i64 = lenp[0]
143 var domains: i64 = 0
144 var laddered: i64 = 0
145 var partial: i64 = 0
146 var noladder: i64 = 0
147 var noplan: i64 = 0
148 let name: *u8 = sys_mmap(LDC_NAME_CAP)
149 var p: i64 = 0
150 while p < ln {
151 let e: i64 = bf_line_end(lst, ln, p)
152 var l: i64 = e - p
153 if l >= LDC_NAME_CAP { l = LDC_NAME_CAP - 1 }
154 if l > 0 {
155 var i: i64 = 0
156 while i < l { name[i] = lst[p + i]; i = i + 1 }
157 name[l] = 0 as u8
158 domains = domains + 1
159 let plp: *i64 = sys_mmap(LD_I64) as *i64
160 plp[0] = 0
161 let pbuf: *u8 = bf_read_plan(ct_first_published(), ct_second_published(), name, plp, which)
162 if plp[0] <= 0 {
163 ldc_w("LADDER domain=" as *u8); ldc_w(name); ldc_w(" verdict=NO-PLAN\n" as *u8)
164 noplan = noplan + 1
165 } else {
166 let v: i64 = ldc_report(name, pbuf, plp[0], 0)
167 if v == LD_EXIT_LADDERED { laddered = laddered + 1 }
168 if v == LD_EXIT_PARTIAL { partial = partial + 1 }
169 if v == LD_EXIT_NOLADDER { noladder = noladder + 1 }
170 }
171 }
172 p = e + 1
173 }
174 ldc_w("LADDER-ALL domains=" as *u8); ldc_wn(domains)
175 ldc_w(" laddered=" as *u8); ldc_wn(laddered)
176 ldc_w(" partial=" as *u8); ldc_wn(partial)
177 ldc_w(" no_ladder=" as *u8); ldc_wn(noladder)
178 ldc_w(" no_plan=" as *u8); ldc_wn(noplan)
179 ldc_w(" sum=" as *u8); ldc_wn(laddered + partial + noladder + noplan)
180 ldc_w(" verdict=" as *u8)
181 if partial > 0 { ldc_w("PARTIAL\n" as *u8); return LD_EXIT_PARTIAL }
182 ldc_w("CLEAN (no_ladder domains are LABELED, they opt in by declaring a target row)\n" as *u8)
183 return LD_EXIT_LADDERED
184 }
185 lenp[0] = 0
186 let buf: *u8 = bf_read_plan(ct_first_published(), ct_second_published(), dom, lenp, which)
187 if lenp[0] <= 0 {
188 ldc_w("LADDER domain=" as *u8); ldc_w(dom); ldc_w(" plan=UNREADABLE-IN-BOTH-TREES verdict=NO-PLAN\n" as *u8)
189 return LDC_EXIT_NOPLAN
190 }
191 return ldc_report(dom, buf, lenp[0], 1)
192}