code wiki / _hdl_build / nx_genealogist2_test.nx
nx_genealogist2_test.nx source
↩ module page · 47 lines · 3606 B
1// nx_genealogist2_test.nx -- the Genealogist's M2 upgrade (the teammate the growth loop picked):
2// near-duplicate detection, whole-registry sprawl scan, and supersession detection that feeds the
3// Caretaker. Proves the organ grew from one-query exact-match to scanning + reporting + wiring to the
4// gardener. Exit 0 if all hold. license_tier: ORIGINAL
5
6import "nx_genealogist.nx"
7import "nx_syscalls.nx"
8
9func gt_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
10func gt_num(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 }
11
12func main() -> i64 {
13 gt_puts("=== GENEALOGIST M2: near-dup + sprawl scan + supersession (the loop's growth pick) ===\n" as *u8)
14 // a registry with: an exact dup, a near-dup (importance ~ distortion), and distinct caps
15 let ra: *i64 = sys_mmap(8*16) as *i64; let ro: *i64 = sys_mmap(8*16) as *i64
16 ra[0]=ART_ALLOC; ro[0]=OBJ_IMPORTANCE // imatrix
17 ra[1]=ART_ALLOC; ro[1]=OBJ_DISTORTION // near-dup of [0] (importance ~ distortion)
18 ra[2]=ART_ALLOC; ro[2]=OBJ_PERCEPTION // distinct (new objective)
19 ra[3]=ART_FIDELITY; ro[3]=OBJ_DISTORTION // unrelated artifact
20 ra[4]=ART_ALLOC; ro[4]=OBJ_IMPORTANCE // EXACT dup of [0]
21 let RN: i64 = 5
22
23 let rel_exact: i64 = gen_relatedness(ART_ALLOC, OBJ_IMPORTANCE, ART_ALLOC, OBJ_IMPORTANCE)
24 let rel_near: i64 = gen_relatedness(ART_ALLOC, OBJ_IMPORTANCE, ART_ALLOC, OBJ_DISTORTION)
25 let rel_dist: i64 = gen_relatedness(ART_ALLOC, OBJ_IMPORTANCE, ART_ALLOC, OBJ_PERCEPTION)
26 let rel_unrel: i64 = gen_relatedness(ART_ALLOC, OBJ_IMPORTANCE, ART_FIDELITY, OBJ_DISTORTION)
27 gt_puts(" relatedness: exact=" as *u8); gt_num(rel_exact); gt_puts(" near=" as *u8); gt_num(rel_near); gt_puts(" distinct=" as *u8); gt_num(rel_dist); gt_puts(" unrelated=" as *u8); gt_num(rel_unrel); gt_puts("\n" as *u8)
28
29 let ex: *i64 = sys_mmap(8) as *i64; let nr: *i64 = sys_mmap(8) as *i64
30 gen_sprawl_scan(RN, ra, ro, ex, nr)
31 gt_puts(" sprawl scan: exact-dup pairs=" as *u8); gt_num(ex[0]); gt_puts(" near-dup pairs=" as *u8); gt_num(nr[0]); gt_puts("\n" as *u8)
32
33 // supersession: a better fidelity (score 90) over the old PSNR-only fidelity (score 50), same sig
34 let sup: i64 = gen_supersedes(ART_FIDELITY, OBJ_DISTORTION, 90, ART_FIDELITY, OBJ_DISTORTION, 50)
35 gt_puts(" supersession (new>old, same sig) -> feed Caretaker = " as *u8); gt_num(sup); gt_puts("\n" as *u8)
36
37 let r: *i64 = sys_mmap(8*8) as *i64
38 r[0] = 0; if rel_exact == 3 { if rel_near == 2 { if rel_dist == 1 { if rel_unrel == 0 { r[0] = 1 } } } } // relatedness ladder
39 r[1] = 0; if ex[0] == 1 { r[1] = 1 } // found the one exact-dup pair ([0],[4])
40 r[2] = 0; if nr[0] == 2 { r[2] = 1 } // found the near-dup pairs ([0]~[1] and [4]~[1])
41 r[3] = 0; if sup == 1 { r[3] = 1 } // supersession detection wired to Caretaker
42 var pass: i64 = 0; var i: i64 = 0
43 while i < 4 { pass = pass + r[i]; i = i + 1 }
44 gt_puts("----\n passed " as *u8); gt_num(pass); gt_puts("/4\n" as *u8)
45 if pass == 4 { gt_puts(" GENEALOGIST LEVELED UP (M1->M2): scans the whole registry, flags near-dups, detects supersession -> feeds the Caretaker. No regression.\n" as *u8); sys_exit(0); return 0 }
46 gt_puts(" FAIL\n" as *u8); sys_exit(1); return 1
47}