code wiki / _hdl_build / nx_lineage_deep_gate.nx
nx_lineage_deep_gate.nx source
↩ module page · 124 lines · 8732 B
1// nx_lineage_deep_gate.nx -- GATE: deeper provenance (R-DEEP). T1 multi-parent CROSS detected (hybrid has two
2// distinct parents; single-parent is not a cross). T2 cross label names both parents. T3 a harvest LOT from a
3// plant. T4 SPLIT into many child lots + conservation (can't split beyond what remains). T5 DEEP TRACE: a jar
4// split from the sauce traces back through the chain to the harvest -> the exact plant (superior). T6 lot
5// provenance page renders + ships. license_tier: ORIGINAL
6import "nx_lineage_deep.nx"
7import "nx_publisher.nx"
8import "nx_seg_store.nx"
9import "nx_syscalls.nx"
10
11const LD_BIO: *u8 = "knowledge/store/ldeep-bio-"
12const LD_STAGE_FILE: *u8 = "knowledge/staging/ldeep/jar.html"
13const LD_LIVE_FILE: *u8 = "knowledge/publish/ldeep-live/jar.html"
14
15func 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 }
16func g_i(v: i64) -> i64 {
17 let bb: *u8 = sys_mmap(28); var m: i64 = v
18 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
19 let t: *u8 = sys_mmap(28); var k: i64 = 0
20 if m == 0 { t[0] = 48 as u8; k = 1 }
21 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
22 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
23}
24func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
25
26func main() -> i64 {
27 g_p("=== nx_lineage_deep_gate (R-DEEP: crosses + harvest-lot splitting) ===\n" as *u8)
28 ln_seed_config(LD_BIO)
29
30 // a hybrid cross: Sungold = Sungold Red x Sungold Yellow
31 ln_add(LD_BIO, "sg_a" as *u8, "Sungold Red" as *u8, "plant" as *u8, "Sungold Red" as *u8, 1, "-" as *u8, "-" as *u8, "saved" as *u8, "self" as *u8, "perma_a8_regenerative_ag" as *u8)
32 ln_add(LD_BIO, "sg_b" as *u8, "Sungold Yellow" as *u8, "plant" as *u8, "Sungold Yellow" as *u8, 1, "-" as *u8, "-" as *u8, "saved" as *u8, "self" as *u8, "perma_a8_regenerative_ag" as *u8)
33 ln_add(LD_BIO, "sungold" as *u8, "Sungold" as *u8, "plant" as *u8, "Sungold F1" as *u8, 2, "sg_a" as *u8, "sg_b" as *u8, "crossed" as *u8, "self" as *u8, "perma_a8_regenerative_ag" as *u8)
34 ln_set_gene(LD_BIO, "sungold" as *u8, 94, 90, 92, 88, 91, "Nishi field trial" as *u8, "perma_a8_regenerative_ag" as *u8)
35 // a single-parent (not a cross)
36 ln_add(LD_BIO, "bw_gp" as *u8, "Brandywine founder" as *u8, "plant" as *u8, "Brandywine" as *u8, 1, "-" as *u8, "-" as *u8, "saved" as *u8, "self" as *u8, "perma_a8_regenerative_ag" as *u8)
37 ln_add(LD_BIO, "brandywine" as *u8, "Brandywine" as *u8, "plant" as *u8, "Brandywine" as *u8, 2, "bw_gp" as *u8, "-" as *u8, "saved" as *u8, "self" as *u8, "perma_a8_regenerative_ag" as *u8)
38
39 var pass: i64 = 0
40 var tot: i64 = 0
41
42 // T1 cross detection
43 let a: *u8 = sys_mmap(64); let b: *u8 = sys_mmap(64); ld_parents(LD_BIO, "sungold" as *u8, a, b)
44 g_p("sungold parents: " as *u8); g_p(a); g_p(" x " as *u8); g_p(b); g_p(" cross=" as *u8); g_i(ld_is_cross(LD_BIO, "sungold" as *u8)); g_p(" | brandywine cross=" as *u8); g_i(ld_is_cross(LD_BIO, "brandywine" as *u8)); g_p("\n" as *u8)
45 tot = tot + 1
46 var ok1: i64 = 1
47 if ld_is_cross(LD_BIO, "sungold" as *u8) != 1 { ok1 = 0 }
48 if ld_is_cross(LD_BIO, "brandywine" as *u8) != 0 { ok1 = 0 }
49 if fd_streq(a, "sg_a" as *u8) != 1 { ok1 = 0 }
50 if fd_streq(b, "sg_b" as *u8) != 1 { ok1 = 0 }
51 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 multi-parent cross detected (Sungold = two distinct parents); single-parent is not a cross\n" as *u8) } else { g_p("FAIL T1\n" as *u8) }
52
53 // T2 cross label
54 let cl: *u8 = sys_mmap(256); ld_cross_label(LD_BIO, "sungold" as *u8, cl)
55 g_p("cross label: " as *u8); g_p(cl); g_p("\n" as *u8)
56 tot = tot + 1
57 var ok2: i64 = 1
58 if as_contains(cl, as_len(cl), "Sungold Red" as *u8) != 1 { ok2 = 0 }
59 if as_contains(cl, as_len(cl), "Sungold Yellow" as *u8) != 1 { ok2 = 0 }
60 if as_contains(cl, as_len(cl), " x " as *u8) != 1 { ok2 = 0 }
61 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 cross label names both parents (Sungold = Sungold Red x Sungold Yellow)\n" as *u8) } else { g_p("FAIL T2\n" as *u8) }
62
63 // T3 harvest lot
64 ld_create_lot(LD_BIO, "harvest1" as *u8, "sungold" as *u8, 50, "lb" as *u8, 100)
65 let oh: *u8 = sys_mmap(64); ld_lot_origin_org(LD_BIO, "harvest1" as *u8, oh)
66 g_p("harvest1 origin org=" as *u8); g_p(oh); g_p(" qty=" as *u8); g_i(ld_lot_int(LD_BIO, "harvest1" as *u8, 2)); g_p("\n" as *u8)
67 tot = tot + 1
68 if fd_streq(oh, "sungold" as *u8) == 1 { if ld_lot_int(LD_BIO, "harvest1" as *u8, 2) == 50 { pass = pass + 1; g_p("PASS T3 harvest lot from the plant (50 lb of Sungold)\n" as *u8) } else { g_p("FAIL T3 qty\n" as *u8) } } else { g_p("FAIL T3 origin\n" as *u8) }
69
70 // T4 split + conservation
71 let s1: i64 = ld_split_lot(LD_BIO, "harvest1" as *u8, "sauce1" as *u8, 20, "lb" as *u8, "sauce" as *u8, 101)
72 ld_split_lot(LD_BIO, "harvest1" as *u8, "fresh1" as *u8, 15, "lb" as *u8, "fresh" as *u8, 101)
73 ld_split_lot(LD_BIO, "harvest1" as *u8, "seed1" as *u8, 5, "lb" as *u8, "seed" as *u8, 101)
74 let overshoot: i64 = ld_split_lot(LD_BIO, "harvest1" as *u8, "toomuch" as *u8, 100, "lb" as *u8, "x" as *u8, 101)
75 let rem: i64 = ld_lot_remaining(LD_BIO, "harvest1" as *u8)
76 let sp: *u8 = sys_mmap(48); ld_lot_str(LD_BIO, "sauce1" as *u8, 1, sp)
77 g_p("splits ok; overshoot=" as *u8); g_i(overshoot); g_p(" remaining=" as *u8); g_i(rem); g_p(" sauce1.parent=" as *u8); g_p(sp); g_p("\n" as *u8)
78 tot = tot + 1
79 var ok4: i64 = 1
80 if s1 != 1 { ok4 = 0 }
81 if overshoot != 0 { ok4 = 0 } // conservation: can't split beyond what remains
82 if rem != 10 { ok4 = 0 } // 50 - (20+15+5)
83 if fd_streq(sp, "harvest1" as *u8) != 1 { ok4 = 0 }
84 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 split into sauce/fresh/seed (40 of 50); over-split refused (conservation), 10 remain\n" as *u8) } else { g_p("FAIL T4\n" as *u8) }
85
86 // T5 deep trace: a jar from the sauce traces to the plant
87 ld_split_lot(LD_BIO, "sauce1" as *u8, "jar1" as *u8, 5, "jar" as *u8, "canned" as *u8, 102)
88 let oj: *u8 = sys_mmap(64); ld_lot_origin_org(LD_BIO, "jar1" as *u8, oj)
89 let tr: *u8 = sys_mmap(256); ld_lot_trace(LD_BIO, "jar1" as *u8, tr)
90 g_p("jar1 trace: " as *u8); g_p(tr); g_p(" -> origin=" as *u8); g_p(oj); g_p(" superior=" as *u8); g_i(ln_is_superior(LD_BIO, "sungold" as *u8)); g_p("\n" as *u8)
91 tot = tot + 1
92 var ok5: i64 = 1
93 if fd_streq(oj, "sungold" as *u8) != 1 { ok5 = 0 }
94 if fd_streq(tr, "jar1 <- sauce1 <- harvest1" as *u8) != 1 { ok5 = 0 }
95 if ln_is_superior(LD_BIO, "sungold" as *u8) != 1 { ok5 = 0 }
96 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 deep trace: jar -> sauce -> harvest -> the exact plant (superior Sungold)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) }
97
98 // T6 render + ship
99 let page: *u8 = sys_mmap(65536)
100 let np: i64 = ld_render_lot(LD_BIO, "jar1" as *u8, page)
101 g_p("lot page = " as *u8); g_i(np); g_p(" bytes\n" as *u8)
102 tot = tot + 1
103 var ok6: i64 = 1
104 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 }
105 if as_contains(page, np, "harvest1" as *u8) != 1 { ok6 = 0 } // the chain
106 if as_contains(page, np, "Sungold" as *u8) != 1 { ok6 = 0 } // the plant
107 if as_contains(page, np, "superior strain" as *u8) != 1 { ok6 = 0 }
108 if as_contains(page, np, "Sungold Red" as *u8) != 1 { ok6 = 0 } // the cross
109 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
110 sys_mkdir("knowledge/staging/ldeep" as *u8, 0x1ed)
111 let sfd: i64 = sys_openat_wr(LD_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) }
112 pub_init()
113 sys_mkdir("knowledge/publish/ldeep-stage" as *u8, 0x1ed)
114 sys_mkdir("knowledge/publish/ldeep-live" as *u8, 0x1ed)
115 pub_submit_to("knowledge/publish/ldeep-queue.tsv" as *u8, LD_STAGE_FILE, "jar.html" as *u8, "nishifoodfamily" as *u8, "nishi-ldeep" as *u8, "internal" as *u8)
116 pub_run_full("knowledge/publish/ldeep-queue.tsv" as *u8, "knowledge/publish/ldeep-ledger.tsv" as *u8, "knowledge/publish/ldeep-stage" as *u8, "knowledge/publish/ldeep-live" as *u8, "publish:ldeep" as *u8)
117 if g_exists(LD_LIVE_FILE) != 1 { ok6 = 0 }
118 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 lot provenance page (chain + plant + genetics + cross) renders sovereign + ships\n" as *u8) } else { g_p("FAIL T6\n" as *u8) }
119
120 g_p("nx_lineage_deep_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
121 if pass == tot { g_p(" verdict=GREEN (hybrids trace to both parents; one harvest -> many plates, each traceable to the exact plant + seed)\n" as *u8); return 0 }
122 g_p(" verdict=RED\n" as *u8)
123 return 1
124}