code wiki / _hdl_build / nx_orchestration2_test.nx
nx_orchestration2_test.nx source
↩ module page · 54 lines · 4067 B
1// nx_orchestration2_test.nx -- prove the research-driven upgrades: the SPECULATIVE FIFO merge queue
2// (disjoint land in parallel, overlap drops without cascading) + the BRANCHING lineage archive (a LOW
3// ancestor seeds a breakthrough that hill-climbing would miss). Exit 0 on 11/11. license_tier: ORIGINAL
4
5import "nx_merge_queue.nx"
6import "nx_lineage_archive.nx"
7import "nx_syscalls.nx"
8
9func o2_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 o2_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 o2_puts("=== SPECULATIVE MERGE QUEUE + BRANCHING LINEAGE ARCHIVE ===\n" as *u8)
14
15 // ---- merge queue: A=0b0001 B=0b0010 C=0b0001(overlaps A) D=0b0100 ----
16 let masks: *i64 = sys_mmap(8*4) as *i64; masks[0]=1; masks[1]=2; masks[2]=1; masks[3]=4
17 let stat: *i64 = sys_mmap(8*4) as *i64
18 let merged: i64 = mq_process(masks, 4, stat)
19 o2_puts(" queue: A=" as *u8); o2_puts(mq_status_label(stat[0])); o2_puts(" B=" as *u8); o2_puts(mq_status_label(stat[1])); o2_puts(" C=" as *u8); o2_puts(mq_status_label(stat[2])); o2_puts(" D=" as *u8); o2_puts(mq_status_label(stat[3])); o2_puts(" merged=" as *u8); o2_num(merged); o2_puts("\n" as *u8)
20
21 // ---- branching archive: clone1 is LOW (8 < parent 10) but seeds clone2 (15 > frontier) ----
22 let parents: *i64 = sys_mmap(8*8) as *i64
23 let scores: *i64 = sys_mmap(8*8) as *i64
24 var cnt: i64 = 0
25 la_archive(parents, scores, cnt, 0 - 1, 10); cnt = cnt + 1 // clone0 root, score 10
26 la_archive(parents, scores, cnt, 0, 8); cnt = cnt + 1 // clone1 from clone0, score 8 (LOW)
27 let frontier_before: i64 = la_frontier(scores, cnt) // = 10 (best so far)
28 la_archive(parents, scores, cnt, 1, 15); cnt = cnt + 1 // clone2 from the LOW clone1, score 15
29 let frontier_after: i64 = la_frontier(scores, cnt)
30 let seeded: i64 = la_seeded_breakthrough(scores[1], scores[2], frontier_before)
31 o2_puts(" archive: frontier " as *u8); o2_num(frontier_before); o2_puts("->" as *u8); o2_num(frontier_after); o2_puts(" clone2 from LOW clone1(8) -> seeded-breakthrough=" as *u8); o2_num(seeded); o2_puts(" best=clone" as *u8); o2_num(la_best(scores, cnt)); o2_puts("\n" as *u8)
32
33 let r: *i64 = sys_mmap(16*8) as *i64
34 r[0]=0; if stat[0]==MQ_MERGED { r[0]=1 }
35 r[1]=0; if stat[1]==MQ_MERGED { r[1]=1 } // disjoint -> parallel land
36 r[2]=0; if stat[2]==MQ_DROPPED { r[2]=1 } // overlap -> dropped (serialize/rebase)
37 r[3]=0; if stat[3]==MQ_MERGED { r[3]=1 } // NO cascade: D merges after C dropped
38 r[4]=0; if merged==3 { r[4]=1 }
39 r[5]=0; if mq_clean(1,2)==1 { if mq_clean(1,1)==0 { r[5]=1 } } // disjoint clean, overlap not
40 r[6]=0; if frontier_after==15 { r[6]=1 } // frontier advanced
41 r[7]=0; if seeded==1 { r[7]=1 } // a LOW ancestor seeded the breakthrough
42 r[8]=0; if la_can_branch_from(1, cnt)==1 { r[8]=1 } // can branch from the low ancestor (not just best)
43 r[9]=0; if la_best(scores, cnt)==2 { r[9]=1 } // best is clone2
44 r[10]=0; if la_no_deletion(2, cnt)==1 { r[10]=1 } // archive only grows (additive-only)
45 var pass: i64 = 0; var i: i64 = 0
46 while i < 11 { pass = pass + r[i]; i = i + 1 }
47 o2_puts("---- passed " as *u8); o2_num(pass); o2_puts("/11 ----\n" as *u8)
48 if pass == 11 {
49 o2_puts(" S-class integration: disjoint changes land together, conflicts drop+rebase (no false cascade);\n" as *u8)
50 o2_puts(" and the hub ARCHIVES every clone -- a low ancestor seeded a breakthrough hill-climbing would miss.\n" as *u8)
51 sys_exit(0); return 0
52 }
53 o2_puts(" FAIL\n" as *u8); sys_exit(1); return 1
54}