code wiki / _hdl_build / nx_charter_test.nx

nx_charter_test.nx source

↩ module page · 62 lines · 4801 B

1// nx_charter_test.nx -- prove the charter ladder + the four-pillar guard + their UNION: a complete 2// four-pillar guard (Engineer-owned) keeps a REPRODUCIBLE artifact reproducible against drift. Also grades, 3// honestly, that the ad-hoc self-model lint was only 3/4 pillars. Exit 0 on 13/13. license_tier: ORIGINAL 4 5import "nx_charter.nx" 6import "nx_four_pillars.nx" 7import "nx_syscalls.nx" 8 9func ht_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 ht_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 ht_puts("=== CHARTER (unstructured->reproducible) + FOUR-PILLAR GUARD ===\n" as *u8) 14 15 let s_un: i64 = ch_stage(0,0,0,0,0) 16 let s_st: i64 = ch_stage(1,0,0,0,0) 17 let s_me: i64 = ch_stage(1,1,0,0,0) 18 let s_ac: i64 = ch_stage(1,1,1,0,0) 19 let s_re: i64 = ch_stage(1,1,1,1,1) 20 ht_puts(" ladder: " as *u8); ht_puts(ch_stage_name(s_un)); ht_puts(" -> " as *u8); ht_puts(ch_stage_name(s_st)); ht_puts(" -> " as *u8); ht_puts(ch_stage_name(s_me)); ht_puts(" -> " as *u8); ht_puts(ch_stage_name(s_ac)); ht_puts(" -> " as *u8); ht_puts(ch_stage_name(s_re)); ht_puts("\n" as *u8) 21 22 // four-pillar grading: a COMPLETE guard vs the ad-hoc self-model lint (gate+KAT+prevention, NO probe) 23 let full: i64 = fp_complete(1,1,1,1) 24 let lint_pillars: i64 = fp_pillar_count(1, 0, 1, 1) // gate=1 probe=0 kat=1 prevention=1 25 let lint_complete: i64 = fp_complete(1, 0, 1, 1) 26 let valid_full: i64 = fp_valid(1,1,1,1, 1, 0) // complete + intelligent + additive 27 let valid_clobber: i64 = fp_valid(1,1,1,1, 1, 1) // clobbers -> not additive -> invalid 28 let valid_hardcoded: i64 = fp_valid(1,1,1,1, 0, 0) // not learned -> not intelligent -> invalid 29 ht_puts(" four-pillar: complete=" as *u8); ht_num(full); ht_puts(" ad-hoc lint had " as *u8); ht_num(lint_pillars); ht_puts("/4 (missing PROBE) -> complete=" as *u8); ht_num(lint_complete); ht_puts(" valid-full=" as *u8); ht_num(valid_full); ht_puts("\n" as *u8) 30 31 // the UNION: a complete guard keeps a reproducible artifact reproducible against drift 32 let drift_demote: i64 = ch_on_drift(1, 0) // was reproducible, re-run differs -> demote 33 let drift_hold: i64 = ch_on_drift(1, 1) // re-run same -> stays reproducible 34 let protected: i64 = ch_drift_protected(fp_prevents_recurrence(valid_full)) 35 ht_puts(" drift: demote-to=" as *u8); ht_puts(ch_stage_name(drift_demote)); ht_puts(" complete-guard-protects=" as *u8); ht_num(protected); ht_puts("\n" as *u8) 36 37 let r: *i64 = sys_mmap(16*8) as *i64 38 r[0]=0; if s_un==CH_UNSTRUCTURED { if s_st==CH_STRUCTURED { if s_me==CH_MEANINGFUL { r[0]=1 } } } 39 r[1]=0; if s_ac==CH_ACTIONABLE { if s_re==CH_REPRODUCIBLE { r[1]=1 } } 40 r[2]=0; if ch_reproducible(1,1)==1 { if ch_reproducible(1,0)==0 { if ch_reproducible(0,1)==0 { r[2]=1 } } } // dual gate: needs BOTH 41 r[3]=0; if drift_demote==CH_ACTIONABLE { r[3]=1 } // reproducibility drifts (not permanent) 42 r[4]=0; if drift_hold==CH_REPRODUCIBLE { r[4]=1 } 43 r[5]=0; if full==1 { r[5]=1 } 44 r[6]=0; if lint_pillars==3 { if lint_complete==0 { r[6]=1 } } // HONEST: the ad-hoc lint was only 3/4 45 r[7]=0; if valid_full==1 { r[7]=1 } 46 r[8]=0; if valid_clobber==0 { r[8]=1 } // not additive -> invalid 47 r[9]=0; if valid_hardcoded==0 { r[9]=1 } // not intelligent -> invalid 48 r[10]=0; if protected==1 { r[10]=1 } // complete guard protects reproducibility 49 r[11]=0; if fp_owner()==FP_R_ENGINEER { r[11]=1 } // the Engineer owns the four-pillar guard 50 r[12]=0; if ch_advancement(0,4)==4 { if ch_advancement(4,3)==(0-1) { r[12]=1 } } // climb vs drift-regress 51 var pass: i64 = 0; var i: i64 = 0 52 while i < 13 { pass = pass + r[i]; i = i + 1 } 53 ht_puts("---- passed " as *u8); ht_num(pass); ht_puts("/13 ----\n" as *u8) 54 if pass == 13 { 55 ht_puts(" CHARTER + GUARD UNITED: the team drives work unstructured->reproducible; REPRODUCIBLE is the\n" as *u8) 56 ht_puts(" layer-0 outcome (deterministic + a real machine/human driver), and it DRIFTS -- so the Engineer's\n" as *u8) 57 ht_puts(" complete four-pillar guard (gate+probe+kat+prevention, intelligent+additive) is what keeps it\n" as *u8) 58 ht_puts(" reproducible. (The ad-hoc lint was only 3/4 -- the four-pillar discipline caught my own gap.)\n" as *u8) 59 sys_exit(0); return 0 60 } 61 ht_puts(" FAIL\n" as *u8); sys_exit(1); return 1 62}