code wiki / _hdl_build / nx_ecodesign_gate.nx

nx_ecodesign_gate.nx source

↩ module page · 137 lines · 7592 B

1// nx_ecodesign_gate.nx -- GATE: R-ECO. The regenerative landscape calculator. Proves the operator's expanded 2// vision: T1 multi-value plant model (a non-edible can be high value), T2 "more than edibles" (medicine + 3// wildlife make a non-edible worth MORE than an edible), T3 "share with wildlife while discouraging damage" 4// (high-wildlife + deer-resistant set; deer-candy excluded), T4 climbing useful plants for the 3D-printed 5// concrete wall, T5 rainwater capture (integer, no float), T6 research-grounded, T7 sovereign design shipped. 6// license_tier: ORIGINAL 7import "nx_ecodesign.nx" 8import "nx_food_provenance.nx" 9import "nx_food_science.nx" 10import "nx_publisher.nx" 11import "nx_seg_store.nx" 12import "nx_syscalls.nx" 13import "nx_gate_verdict.nx" 14 15const EG_FOOD: *u8 = "knowledge/store/food-" 16const EG_Q: *u8 = "knowledge/publish/eco-queue.tsv" 17const EG_LED: *u8 = "knowledge/publish/eco-ledger.tsv" 18const EG_STG: *u8 = "knowledge/publish/eco-stage" 19const EG_LIVE: *u8 = "knowledge/publish/eco-live" 20const EG_STAGE_FILE: *u8 = "knowledge/staging/eco/landscape.html" 21const EG_LIVE_FILE: *u8 = "knowledge/publish/eco-live/landscape.html" 22 23func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 24func g_i(v: i64) -> i64 { 25 let bb: *u8 = sys_mmap(28); var m: i64 = v 26 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 27 let t: *u8 = sys_mmap(28); var k: i64 = 0 28 if m == 0 { t[0] = 48 as u8; k = 1 } 29 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 30 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 31} 32func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 33 34func main() -> i64 { 35 g_p("=== nx_ecodesign_gate (R-ECO: regenerative landscape -- food + medicine + wildlife + rainwater) ===\n" as *u8) 36 fd_seed(EG_FOOD) 37 let pw: i64 = ec_seed(EG_FOOD) 38 g_p("plant palette authored this run=" as *u8); g_i(pw); g_p("\n" as *u8) 39 40 var pass: i64 = 0 41 var tot: i64 = 0 42 43 // T1 multi-value model (lavender: medicinal + wildlife + deer-resistant, NOT edible) 44 tot = tot + 1 45 var ok1: i64 = 1 46 if ec_med(EG_FOOD, "lavender" as *u8) < 7 { ok1 = 0 } 47 if ec_wild(EG_FOOD, "lavender" as *u8) < 8 { ok1 = 0 } 48 if ec_deer(EG_FOOD, "lavender" as *u8) < 8 { ok1 = 0 } 49 if ec_edible(EG_FOOD, "lavender" as *u8) != 0 { ok1 = 0 } 50 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 multi-value model (lavender: non-edible, medicinal+wildlife+deer-resistant)\n" as *u8) } else { g_p("FAIL T1\n" as *u8) } 51 52 // T2 MORE THAN EDIBLES: a non-edible out-values an edible via medicine + wildlife 53 let v_ech: i64 = ec_value(EG_FOOD, "echinacea" as *u8, 8, 2, 2) 54 let v_grape: i64 = ec_value(EG_FOOD, "grape" as *u8, 8, 2, 2) 55 g_p("ecosystem value: echinacea(non-edible)=" as *u8); g_i(v_ech); g_p(" grape(edible)=" as *u8); g_i(v_grape); g_p("\n" as *u8) 56 tot = tot + 1 57 var ok2: i64 = 1 58 if ec_edible(EG_FOOD, "echinacea" as *u8) != 0 { ok2 = 0 } 59 if v_ech <= v_grape { ok2 = 0 } 60 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 more-than-edibles (a medicinal/pollinator plant out-values an edible in the calc)\n" as *u8) } else { g_p("FAIL T2\n" as *u8) } 61 62 // T3 share with wildlife while discouraging damage 63 let ids: *i64 = sys_mmap(8 * 64) as *i64 64 let nids: i64 = ec_list(EG_FOOD, ids) 65 var nsafe: i64 = 0 66 var i: i64 = 0 67 while i < nids { if ec_share_safe(EG_FOOD, ids[i] as *u8) == 1 { nsafe = nsafe + 1 } i = i + 1 } 68 g_p("share-with-wildlife-yet-deer-resistant plants=" as *u8); g_i(nsafe); g_p("\n" as *u8) 69 tot = tot + 1 70 var ok3: i64 = 1 71 if nsafe < 5 { ok3 = 0 } 72 if ec_share_safe(EG_FOOD, "hosta" as *u8) != 0 { ok3 = 0 } // deer-candy -> must NOT be in the safe set 73 if ec_share_safe(EG_FOOD, "lavender" as *u8) != 1 { ok3 = 0 } // wildlife + deer-proof -> in it 74 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 wildlife-yet-damage-resistant set (hosta the deer-candy excluded)\n" as *u8) } else { g_p("FAIL T3\n" as *u8) } 75 76 // T4 climbing useful plants for the concrete structure 77 var nclimb: i64 = 0 78 i = 0 79 while i < nids { if ec_climbing(EG_FOOD, ids[i] as *u8) == 1 { nclimb = nclimb + 1 } i = i + 1 } 80 tot = tot + 1 81 var ok4: i64 = 1 82 if nclimb < 2 { ok4 = 0 } 83 if ec_climbing(EG_FOOD, "grape" as *u8) != 1 { ok4 = 0 } 84 if ec_climbing(EG_FOOD, "jasmine" as *u8) != 1 { ok4 = 0 } 85 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 climbing useful plants for the 3D-printed concrete wall (grape, jasmine)\n" as *u8) } else { g_p("FAIL T4\n" as *u8) } 86 87 // T5 rainwater capture (integer, no float) 88 let cap: i64 = ec_capture(100, 800, 80) 89 g_p("rainwater capture(100 m2, 800 mm, 80%)=" as *u8); g_i(cap); g_p(" litres\n" as *u8) 90 tot = tot + 1 91 if cap == 64000 { pass = pass + 1; g_p("PASS T5 rainwater capture exact: 64000 litres/year (no float)\n" as *u8) } else { g_p("FAIL T5 cap=" as *u8); g_i(cap); g_p("\n" as *u8) } 92 93 // T6 research-grounded: every plant cites a real fetched source 94 var grounded: i64 = 0 95 i = 0 96 while i < nids { 97 let cite: *u8 = sys_mmap(64) 98 ec_field_str(EG_FOOD, ids[i] as *u8, 8, cite) 99 if fd_sci_cited(cite) == 1 { grounded = grounded + 1 } 100 i = i + 1 101 } 102 g_p("plants grounded in fetched research: " as *u8); g_i(grounded); g_p("/" as *u8); g_i(nids); g_p("\n" as *u8) 103 tot = tot + 1 104 if grounded == nids { if nids > 0 { pass = pass + 1; g_p("PASS T6 research-grounded (every plant cites a fetched source)\n" as *u8) } else { g_p("FAIL T6 no plants\n" as *u8) } } else { g_p("FAIL T6 ungrounded present\n" as *u8) } 105 106 // T7 sovereign design + ship 107 let page: *u8 = sys_mmap(65536) 108 let np: i64 = ec_render_design(EG_FOOD, 100, 800, page) 109 tot = tot + 1 110 var ok7: i64 = 1 111 if as_has_thirdparty_js(page, np) != 0 { ok7 = 0 } 112 if as_contains(page, np, "litres" as *u8) != 1 { ok7 = 0 } 113 if as_contains(page, np, "3D-printed concrete" as *u8) != 1 { ok7 = 0 } 114 if as_contains(page, np, "Grape" as *u8) != 1 { ok7 = 0 } 115 if as_contains(page, np, "Lavender" as *u8) != 1 { ok7 = 0 } 116 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 117 sys_mkdir("knowledge/staging/eco" as *u8, 0x1ed) 118 let sfd: i64 = sys_openat_wr(EG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) } 119 pub_init() 120 sys_mkdir(EG_STG, 0x1ed) 121 sys_mkdir(EG_LIVE, 0x1ed) 122 pub_submit_to(EG_Q, EG_STAGE_FILE, "landscape.html" as *u8, "nishifamily" as *u8, "nishi-eco" as *u8, "internal" as *u8) 123 pub_run_full(EG_Q, EG_LED, EG_STG, EG_LIVE, "publish:eco" as *u8) 124 if g_exists(EG_LIVE_FILE) != 1 { ok7 = 0 } 125 if ok7 == 1 { pass = pass + 1; g_p("PASS T7 sovereign regenerative-design page rendered + SHIPPED (" as *u8); g_i(np); g_p(" bytes)\n" as *u8) } else { g_p("FAIL T7\n" as *u8) } 126 127 g_p("nx_ecodesign_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 128 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 129 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 130 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 131 let ctr__dry: *i64 = gv_ctr() 132 ctr__dry[0] = pass 133 ctr__dry[1] = tot 134 let rc__dry: i64 = gv_verdict("ECODESIGN-GATE" as *u8, ctr__dry, "regenerative landscape: food+medicine+wildlife+rainwater+climbers, optimal+improving)" as *u8) 135 sys_exit(rc__dry) 136 return rc__dry 137}