code wiki / (root) / nx_wflow_loop_capacity_gate_t278.nx

nx_wflow_loop_capacity_gate_t278.nx source

↩ module page · 121 lines · 5581 B

1// nx_wflow_loop_gate.nx -- R11 LOOPS gate: for-each = apply-to-each over the connector plane. Step arg 2// `<listexpr>~<template>`: the list substitutes ONCE (comma-split, 32-cap loud), then per item the engine 3// binds {item} as a run variable, emits WFITER, substitutes the template, forks the connector. Any failed 4// item fails the STEP (retry/on-fail machinery applies). Empty list = zero iterations, step OK. Proves the 5// per-item argv actually varies (argecho), the last item persists as {item} for later steps, empty-list 6// no-op, item failure fail-stops, load refusals. THREE forks. license_tier: ORIGINAL expect_exit: 0 7import "nx_wflow_engine_capacity_candidate_t278.nx" 8import "nx_gate_verdict.nx" 9 10func lg_n(led: *u8, ridtok: *u8, st: *u8) -> i64 { 11 let szp: *i64 = sys_mmap(8) as *i64 12 let b: *u8 = wf_readall(led, szp) 13 if (b as i64) == 0 { return 0 - 1 } 14 return wf_lines_with2(b, szp[0], ridtok, st) 15} 16func lg_row(conf: *u8, name: *u8, elf: *u8, flag: *u8) -> i64 { 17 let ln: *u8 = sys_mmap(600) 18 var o: i64 = 0 19 o = wf_cat(ln, o, name) 20 ln[o] = 9 as u8 21 o = o + 1 22 o = wf_cat(ln, o, elf) 23 ln[o] = 9 as u8 24 o = o + 1 25 o = wf_cat(ln, o, flag) 26 ln[o] = 10 as u8 27 ln[o+1] = 0 as u8 28 return wf_append(conf, ln) 29} 30 31func main() -> i64 { 32 p("=== NX-WFLOW-LOOP GATE (R11: for-each over the connector plane; WFITER records; item var) ===\n" as *u8) 33 var ok: i64 = 1 34 let now: i64 = wf_now() 35 let led: *u8 = sys_mmap(128) 36 var lo: i64 = 0 37 lo = wf_cat(led, lo, "/tmp/wflp_" as *u8) 38 lo = wf_catn(led, lo, now) 39 lo = wf_cat(led, lo, ".log" as *u8) 40 led[lo] = 0 as u8 41 let conf: *u8 = sys_mmap(128) 42 var co: i64 = 0 43 co = wf_cat(conf, co, "/tmp/wflp_" as *u8) 44 co = wf_catn(conf, co, now) 45 co = wf_cat(conf, co, ".conf" as *u8) 46 conf[co] = 0 as u8 47 lg_row(conf, "argecho" as *u8, "./_offc/nx_tool_argecho.elf" as *u8, "GREEN" as *u8) 48 lg_row(conf, "ghost" as *u8, "/tmp/wflow_no_such_elf_ever" as *u8, "GREEN" as *u8) 49 50 let flows: *i64 = sys_mmap(8 * 4) as *i64 51 flows[0] = "fm1|invite|-" as *u8 as i64 52 flows[1] = "fm2|empty|-" as *u8 as i64 53 flows[2] = "fm3|boom|-" as *u8 as i64 54 let steps: *i64 = sys_mmap(8 * 8) as *i64 55 steps[0] = "fm1|1|for-each|argecho|{guests}~greet~{item}|1" as *u8 as i64 56 steps[1] = "fm1|2|notify|-|Last invited was {item}|1" as *u8 as i64 57 steps[2] = "fm2|1|for-each|argecho|{none}~x|1" as *u8 as i64 58 steps[3] = "fm3|1|for-each|ghost|{guests}~x|1" as *u8 as i64 59 let cx: *i64 = sys_mmap(32) as *i64 60 cx[0] = steps as i64 61 cx[1] = 4 62 cx[2] = led as i64 63 cx[3] = conf as i64 64 65 // T0 load: rows valid; missing connector or empty arg refused 66 let l0: i64 = wf_load(steps, 4) 67 let bad1: *i64 = sys_mmap(16) as *i64 68 bad1[0] = "f9|1|for-each|-|x|1" as *u8 as i64 69 let lb1: i64 = wf_load(bad1, 1) 70 let bad2: *i64 = sys_mmap(16) as *i64 71 bad2[0] = "f9|1|for-each|argecho||1" as *u8 as i64 72 let lb2: i64 = wf_load(bad2, 1) 73 p(" T0 load=" as *u8); pn(l0); p(" noConn=" as *u8); pn(lb1); p(" noArg=" as *u8); pn(lb2); p("\n" as *u8) 74 if l0 != 4 { ok = 0 } 75 if lb1 != (0 - 1) { ok = 0 } 76 if lb2 != (0 - 1) { ok = 0 } 77 78 // T1 two-item loop: WFITER x2, per-item argv varied, {item} persists into the NEXT step (last item) 79 wf_fire(cx, flows, 3, "invite~guests=Rose,Ann~id=L1" as *u8) 80 let d1: i64 = lg_n(led, " rid=L1.fm1 " as *u8, "status=DONE" as *u8) 81 let it: i64 = lg_n(led, " rid=L1.fm1 " as *u8, "WFITER" as *u8) 82 let lastv: i64 = lg_n(led, " rid=L1.fm1 " as *u8, "k=item v=Ann" as *u8) 83 let s2: i64 = lg_n(led, " rid=L1.fm1 " as *u8, " step=2 status=OK" as *u8) 84 p(" T1 loop done=" as *u8); pn(d1); p(" iters=" as *u8); pn(it); p(" lastItemAnn=" as *u8); pn(lastv); p(" nextStep=" as *u8); pn(s2); p("\n" as *u8) 85 if d1 != 1 { ok = 0 } 86 if it != 2 { ok = 0 } 87 if lastv != 1 { ok = 0 } 88 if s2 != 1 { ok = 0 } 89 90 // T2 empty list (var exists, empty value) = zero iterations, step OK, run DONE 91 wf_fire(cx, flows, 3, "empty~none=~id=L2" as *u8) 92 let d2: i64 = lg_n(led, " rid=L2.fm2 " as *u8, "status=DONE" as *u8) 93 let it2: i64 = lg_n(led, " rid=L2.fm2 " as *u8, "WFITER" as *u8) 94 p(" T2 empty done=" as *u8); pn(d2); p(" iters=" as *u8); pn(it2); p("\n" as *u8) 95 if d2 != 1 { ok = 0 } 96 if it2 != 0 { ok = 0 } 97 98 // T3 item failure (dead elf) -> step FAILED, run FAILED 99 wf_fire(cx, flows, 3, "boom~guests=Solo~id=L3" as *u8) 100 let f3: i64 = lg_n(led, " rid=L3.fm3 " as *u8, "status=FAILED" as *u8) 101 let d3: i64 = lg_n(led, " rid=L3.fm3 " as *u8, "status=DONE" as *u8) 102 p(" T3 boom failed=" as *u8); pn(f3); p(" done=" as *u8); pn(d3); p("\n" as *u8) 103 if f3 != 1 { ok = 0 } 104 if d3 != 0 { ok = 0 } 105 106 // T4 negctl 107 let ban: i64 = lg_n(led, "WFITER" as *u8, "item=BANANA" as *u8) 108 p(" T4 negctl nonsense=" as *u8); pn(ban); p("\n" as *u8) 109 if ban != 0 { ok = 0 } 110 111 p("NX-WFLOW-LOOP-GATE ledger=" as *u8); p(led); p(" forks=3 " as *u8) 112 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 113 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 114 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 115 let ctr__dry: *i64 = gv_ctr() 116 ctr__dry[0] = ok 117 ctr__dry[1] = 1 118 let rc__dry: i64 = gv_verdict("WFLOW-LOOP-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 119 sys_exit(rc__dry) 120 return rc__dry 121}