code wiki / _hdl_build / nx_ecodesign_gate.nx

nx_ecodesign_gate.nx source

↩ module page · 130 lines · 7194 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" 13 14const EG_FOOD: *u8 = "knowledge/store/food-" 15const EG_Q: *u8 = "knowledge/publish/eco-queue.tsv" 16const EG_LED: *u8 = "knowledge/publish/eco-ledger.tsv" 17const EG_STG: *u8 = "knowledge/publish/eco-stage" 18const EG_LIVE: *u8 = "knowledge/publish/eco-live" 19const EG_STAGE_FILE: *u8 = "knowledge/staging/eco/landscape.html" 20const EG_LIVE_FILE: *u8 = "knowledge/publish/eco-live/landscape.html" 21 22func 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 } 23func g_i(v: i64) -> i64 { 24 let bb: *u8 = sys_mmap(28); var m: i64 = v 25 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 26 let t: *u8 = sys_mmap(28); var k: i64 = 0 27 if m == 0 { t[0] = 48 as u8; k = 1 } 28 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 29 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 30} 31func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 32 33func main() -> i64 { 34 g_p("=== nx_ecodesign_gate (R-ECO: regenerative landscape -- food + medicine + wildlife + rainwater) ===\n" as *u8) 35 fd_seed(EG_FOOD) 36 let pw: i64 = ec_seed(EG_FOOD) 37 g_p("plant palette authored this run=" as *u8); g_i(pw); g_p("\n" as *u8) 38 39 var pass: i64 = 0 40 var tot: i64 = 0 41 42 // T1 multi-value model (lavender: medicinal + wildlife + deer-resistant, NOT edible) 43 tot = tot + 1 44 var ok1: i64 = 1 45 if ec_med(EG_FOOD, "lavender" as *u8) < 7 { ok1 = 0 } 46 if ec_wild(EG_FOOD, "lavender" as *u8) < 8 { ok1 = 0 } 47 if ec_deer(EG_FOOD, "lavender" as *u8) < 8 { ok1 = 0 } 48 if ec_edible(EG_FOOD, "lavender" as *u8) != 0 { ok1 = 0 } 49 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) } 50 51 // T2 MORE THAN EDIBLES: a non-edible out-values an edible via medicine + wildlife 52 let v_ech: i64 = ec_value(EG_FOOD, "echinacea" as *u8, 8, 2, 2) 53 let v_grape: i64 = ec_value(EG_FOOD, "grape" as *u8, 8, 2, 2) 54 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) 55 tot = tot + 1 56 var ok2: i64 = 1 57 if ec_edible(EG_FOOD, "echinacea" as *u8) != 0 { ok2 = 0 } 58 if v_ech <= v_grape { ok2 = 0 } 59 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) } 60 61 // T3 share with wildlife while discouraging damage 62 let ids: *i64 = sys_mmap(8 * 64) as *i64 63 let nids: i64 = ec_list(EG_FOOD, ids) 64 var nsafe: i64 = 0 65 var i: i64 = 0 66 while i < nids { if ec_share_safe(EG_FOOD, ids[i] as *u8) == 1 { nsafe = nsafe + 1 } i = i + 1 } 67 g_p("share-with-wildlife-yet-deer-resistant plants=" as *u8); g_i(nsafe); g_p("\n" as *u8) 68 tot = tot + 1 69 var ok3: i64 = 1 70 if nsafe < 5 { ok3 = 0 } 71 if ec_share_safe(EG_FOOD, "hosta" as *u8) != 0 { ok3 = 0 } // deer-candy -> must NOT be in the safe set 72 if ec_share_safe(EG_FOOD, "lavender" as *u8) != 1 { ok3 = 0 } // wildlife + deer-proof -> in it 73 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) } 74 75 // T4 climbing useful plants for the concrete structure 76 var nclimb: i64 = 0 77 i = 0 78 while i < nids { if ec_climbing(EG_FOOD, ids[i] as *u8) == 1 { nclimb = nclimb + 1 } i = i + 1 } 79 tot = tot + 1 80 var ok4: i64 = 1 81 if nclimb < 2 { ok4 = 0 } 82 if ec_climbing(EG_FOOD, "grape" as *u8) != 1 { ok4 = 0 } 83 if ec_climbing(EG_FOOD, "jasmine" as *u8) != 1 { ok4 = 0 } 84 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) } 85 86 // T5 rainwater capture (integer, no float) 87 let cap: i64 = ec_capture(100, 800, 80) 88 g_p("rainwater capture(100 m2, 800 mm, 80%)=" as *u8); g_i(cap); g_p(" litres\n" as *u8) 89 tot = tot + 1 90 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) } 91 92 // T6 research-grounded: every plant cites a real fetched source 93 var grounded: i64 = 0 94 i = 0 95 while i < nids { 96 let cite: *u8 = sys_mmap(64) 97 ec_field_str(EG_FOOD, ids[i] as *u8, 8, cite) 98 if fd_sci_cited(cite) == 1 { grounded = grounded + 1 } 99 i = i + 1 100 } 101 g_p("plants grounded in fetched research: " as *u8); g_i(grounded); g_p("/" as *u8); g_i(nids); g_p("\n" as *u8) 102 tot = tot + 1 103 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) } 104 105 // T7 sovereign design + ship 106 let page: *u8 = sys_mmap(65536) 107 let np: i64 = ec_render_design(EG_FOOD, 100, 800, page) 108 tot = tot + 1 109 var ok7: i64 = 1 110 if as_has_thirdparty_js(page, np) != 0 { ok7 = 0 } 111 if as_contains(page, np, "litres" as *u8) != 1 { ok7 = 0 } 112 if as_contains(page, np, "3D-printed concrete" as *u8) != 1 { ok7 = 0 } 113 if as_contains(page, np, "Grape" as *u8) != 1 { ok7 = 0 } 114 if as_contains(page, np, "Lavender" as *u8) != 1 { ok7 = 0 } 115 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 116 sys_mkdir("knowledge/staging/eco" as *u8, 0x1ed) 117 let sfd: i64 = sys_openat_wr(EG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) } 118 pub_init() 119 sys_mkdir(EG_STG, 0x1ed) 120 sys_mkdir(EG_LIVE, 0x1ed) 121 pub_submit_to(EG_Q, EG_STAGE_FILE, "landscape.html" as *u8, "nishifamily" as *u8, "nishi-eco" as *u8, "internal" as *u8) 122 pub_run_full(EG_Q, EG_LED, EG_STG, EG_LIVE, "publish:eco" as *u8) 123 if g_exists(EG_LIVE_FILE) != 1 { ok7 = 0 } 124 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) } 125 126 g_p("nx_ecodesign_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 127 if pass == tot { g_p(" verdict=GREEN (regenerative landscape: food+medicine+wildlife+rainwater+climbers, optimal+improving)\n" as *u8); return 0 } 128 g_p(" verdict=RED\n" as *u8) 129 return 1 130}