code wiki / _hdl_build / nx_household_gate.nx

nx_household_gate.nx source

↩ module page · 139 lines · 7213 B

1// nx_household_gate.nx -- GATE: R-HOME. The household command center -- one dashboard, every engine. Proves: 2// T1 tonight's dinner (live from the pantry), T2 expiring tile, T3 shopping-list tile, T4 grow-&-save tile, 3// T5 estate net-worth tile, T6 sovereign, T7 SHIPPED via publisher. license_tier: ORIGINAL 4import "nx_household.nx" 5import "nx_inventory.nx" 6import "nx_garden.nx" 7import "nx_publisher.nx" 8import "nx_food_science.nx" 9import "nx_syscalls.nx" 10import "nx_gate_verdict.nx" 11 12const HG_FOOD: *u8 = "knowledge/store/food-" 13const HG_INV: *u8 = "knowledge/store/inv-" 14const HG_PAN: *u8 = "household" 15const HG_EST: *u8 = "hhestate" 16const HG_Q: *u8 = "knowledge/publish/home-queue.tsv" 17const HG_LED: *u8 = "knowledge/publish/home-ledger.tsv" 18const HG_STG: *u8 = "knowledge/publish/home-stage" 19const HG_LIVE: *u8 = "knowledge/publish/home-live" 20const HG_STAGE_FILE: *u8 = "knowledge/staging/home/dashboard.html" 21const HG_LIVE_FILE: *u8 = "knowledge/publish/home-live/dashboard.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 } 33func hg_stock(id: *u8, name: *u8, qty: i64, unit: *u8, expiry: i64, par: i64) -> i64 { 34 iv_add(HG_INV, HG_PAN, id, name, "food" as *u8, qty, unit, "kitchen" as *u8, 0, expiry, "-" as *u8) 35 iv_set_par(HG_INV, HG_PAN, id, par) 36 return 0 37} 38 39func main() -> i64 { 40 g_p("=== nx_household_gate (R-HOME: the household command center) ===\n" as *u8) 41 fd_seed(HG_FOOD) 42 gd_seed(HG_FOOD) 43 44 // a realistic household kitchen (today = day 0) 45 hg_stock("chicken" as *u8, "Chicken" as *u8, 2, "lb" as *u8, 3, 2) 46 hg_stock("tofu" as *u8, "Tofu" as *u8, 1, "block" as *u8, 2, 2) 47 hg_stock("broccoli" as *u8, "Broccoli" as *u8, 2, "head" as *u8, 5, 2) 48 hg_stock("onion" as *u8, "Onion" as *u8, 3, "ea" as *u8, 20, 2) 49 hg_stock("garlic" as *u8, "Garlic" as *u8, 2, "bulb" as *u8, 60, 1) 50 hg_stock("ginger" as *u8, "Ginger" as *u8, 2, "knob" as *u8, 14, 1) 51 hg_stock("soy" as *u8, "Soy Sauce" as *u8, 2, "bottle" as *u8, 365, 1) 52 hg_stock("oyster" as *u8, "Oyster Sauce" as *u8, 1, "bottle" as *u8, 200, 1) 53 hg_stock("rice" as *u8, "Rice" as *u8, 2, "bag" as *u8, 0, 1) 54 hg_stock("eggs" as *u8, "Eggs" as *u8, 1, "dozen" as *u8, 10, 3) 55 hg_stock("milk" as *u8, "Milk" as *u8, 0, "carton" as *u8, 7, 2) 56 // a small estate cataloged for the will 57 iv_add(HG_INV, HG_EST, "clock" as *u8, "Grandfather clock" as *u8, "heirloom" as *u8, 1, "ea" as *u8, "living room" as *u8, 250000, 0, "Sarah" as *u8) 58 iv_add(HG_INV, HG_EST, "ring" as *u8, "Wedding ring" as *u8, "jewelry" as *u8, 1, "ea" as *u8, "safe" as *u8, 800000, 0, "Emma" as *u8) 59 60 let dash: *u8 = sys_mmap(65536) 61 let nd: i64 = hh_render_dashboard(HG_FOOD, HG_INV, HG_PAN, HG_EST, "The Family Home" as *u8, dash) 62 g_p("dashboard = " as *u8); g_i(nd); g_p(" bytes\n" as *u8) 63 64 // derive tonight's protein for the assertion 65 let world: *i64 = fd_world_open(HG_FOOD) 66 let nmarr: *i64 = world[4] as *i64 67 let avail: *i64 = sys_mmap(8 * 64) as *i64 68 fp_pantry_avail(world, HG_INV, HG_PAN, avail) 69 let b: *i64 = sys_mmap(8 * 16) as *i64; let r: *i64 = sys_mmap(8 * 16) as *i64 70 let nb: i64 = fp_choose(HG_FOOD, world, avail, b, r) 71 let protein: *u8 = nmarr[b[0]] as *u8 72 73 var pass: i64 = 0 74 var tot: i64 = 0 75 76 // T1 tonight's dinner 77 tot = tot + 1 78 var ok1: i64 = 1 79 if as_contains(dash, nd, "Tonight you can make" as *u8) != 1 { ok1 = 0 } 80 if nb != 5 { ok1 = 0 } 81 if as_contains(dash, nd, protein) != 1 { ok1 = 0 } 82 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 tonight's dinner tile (live: protein=" as *u8); g_p(protein); g_p(")\n" as *u8) } else { g_p("FAIL T1\n" as *u8) } 83 84 // T2 expiring tile (tofu d2 + chicken d3) 85 tot = tot + 1 86 var ok2: i64 = 1 87 if as_contains(dash, nd, "expiring" as *u8) != 1 { ok2 = 0 } 88 if as_contains(dash, nd, "Tofu" as *u8) != 1 { ok2 = 0 } 89 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 expiring tile (Tofu flagged to use soon)\n" as *u8) } else { g_p("FAIL T2\n" as *u8) } 90 91 // T3 shopping-list tile (milk q0, eggs q1<3) 92 tot = tot + 1 93 var ok3: i64 = 1 94 if as_contains(dash, nd, "Shopping list" as *u8) != 1 { ok3 = 0 } 95 if as_contains(dash, nd, "Milk" as *u8) != 1 { ok3 = 0 } 96 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 shopping-list tile (Milk to buy)\n" as *u8) } else { g_p("FAIL T3\n" as *u8) } 97 98 // T4 grow-&-save tile 99 tot = tot + 1 100 var ok4: i64 = 1 101 if as_contains(dash, nd, "Grow" as *u8) != 1 { ok4 = 0 } 102 if as_contains(dash, nd, "/ year" as *u8) != 1 { ok4 = 0 } 103 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 grow-and-save tile (annual savings)\n" as *u8) } else { g_p("FAIL T4\n" as *u8) } 104 105 // T5 estate tile (net worth $10500.00) 106 tot = tot + 1 107 var ok5: i64 = 1 108 if as_contains(dash, nd, "Estate" as *u8) != 1 { ok5 = 0 } 109 if as_contains(dash, nd, "$10500.00" as *u8) != 1 { ok5 = 0 } 110 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 estate tile (net worth $10500.00)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) } 111 112 // T6 sovereign 113 tot = tot + 1 114 if as_has_thirdparty_js(dash, nd) == 0 { pass = pass + 1; g_p("PASS T6 sovereign (0 third-party JS in the dashboard)\n" as *u8) } else { g_p("FAIL T6\n" as *u8) } 115 116 // T7 ship 117 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 118 sys_mkdir("knowledge/staging/home" as *u8, 0x1ed) 119 let sfd: i64 = sys_openat_wr(HG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, dash, nd); sys_close(sfd) } 120 pub_init() 121 sys_mkdir(HG_STG, 0x1ed) 122 sys_mkdir(HG_LIVE, 0x1ed) 123 pub_submit_to(HG_Q, HG_STAGE_FILE, "dashboard.html" as *u8, "nishifamily" as *u8, "nishi-home" as *u8, "internal" as *u8) 124 let pubd: i64 = pub_run_full(HG_Q, HG_LED, HG_STG, HG_LIVE, "publish:home" as *u8) 125 g_p(" pub_run_full -> published_this_pass=" as *u8); g_i(pubd); g_p("\n" as *u8) 126 tot = tot + 1 127 if g_exists(HG_LIVE_FILE) == 1 { pass = pass + 1; g_p("PASS T7 SHIPPED the command center to liveroot\n" as *u8) } else { g_p("FAIL T7\n" as *u8) } 128 129 g_p("nx_household_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 130 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 131 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 132 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 133 let ctr__dry: *i64 = gv_ctr() 134 ctr__dry[0] = pass 135 ctr__dry[1] = tot 136 let rc__dry: i64 = gv_verdict("HOUSEHOLD-GATE" as *u8, ctr__dry, "the household command center: every engine, one sovereign dashboard)" as *u8) 137 sys_exit(rc__dry) 138 return rc__dry 139}