code wiki / (root) / nx_greeting_gate.nx

nx_greeting_gate.nx source

↩ module page · 151 lines · 7772 B

1// nx_greeting_gate.nx -- REFEREE for WRITING rung W-GR-1 (nx_greeting). 2// 3// [T1] whole-word: "yours" must not satisfy the address beat via "you". 4// [T2] case-insensitivity. 5// [T3] a well-formed greeting: all three beats, in order -> COMPLETE, 1000 permil. 6// [T4] ★ORDER IS LOAD-BEARING: the SAME three beats scrambled -> PARTIAL, never COMPLETE. 7// Without this tooth the organ would be a presence counter wearing a structure label. 8// [T5] two beats -> PARTIAL. 9// [T6] ★NEG-CONTROL: a flat descriptive paragraph (a character sheet) -> FLAT. 10// [T7] ★NEG-CONTROL: introduction ONLY -> FLAT, not PARTIAL (one beat is a bio line). 11// [T8] scoring is monotone: FLAT < PARTIAL(2 beats) < PARTIAL(3 scrambled) < COMPLETE. 12// [T9] positions are real: the beat finder returns WHERE, and intro precedes address in T3. 13// [T10] NEG-CONTROL: an empty greeting is FLAT and scores 0, never a divide trap. 14// 15// Fixtures are ordinary SFW prose: this gate measures STRUCTURE, and structure is register-neutral 16// by design -- the same three beats grade an explicit opening identically. 17// Evidence -> stdout + knowledge/status/greeting_gate.log. Exit 0 GREEN / 1 RED. 18// Sovereign x86_64. license_tier: ORIGINAL expect_exit: 0 19import "nx_syscalls_x86_64.nx" 20import "nx_greeting.nx" 21 22func gp(logfd: i64, s: *u8) -> i64 { 23 var n: i64 = 0 24 while s[n] != (0 as u8) { n = n + 1 } 25 sys_write(1, s, n) 26 if logfd > 0 { sys_write(logfd, s, n) } 27 return 0 28} 29func gn(logfd: i64, v: i64) -> i64 { 30 var m: i64 = v 31 if m < 0 { sys_write(1, "-\x00" as *u8, 1); if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } m = 0 - m } 32 let t: *u8 = sys_mmap(32) 33 let b: *u8 = sys_mmap(32) 34 var k: i64 = 0 35 if m == 0 { t[0] = 48 as u8; k = 1 } 36 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 37 var i: i64 = 0 38 while i < k { b[i] = t[k - 1 - i]; i = i + 1 } 39 sys_write(1, b, k) 40 if logfd > 0 { sys_write(logfd, b, k) } 41 return 0 42} 43func pr(logfd: i64, label: *u8, got: i64, exp: i64, passp: *i64, totalp: *i64) -> i64 { 44 totalp[0] = totalp[0] + 1 45 gp(logfd, label) 46 gp(logfd, " got=\x00" as *u8); gn(logfd, got) 47 gp(logfd, " exp=\x00" as *u8); gn(logfd, exp) 48 if got == exp { gp(logfd, " OK\n\x00" as *u8); passp[0] = passp[0] + 1; return 1 } 49 gp(logfd, " FAIL\n\x00" as *u8) 50 return 0 51} 52func sl(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 53 54func main() -> i64 { 55 let logfd: i64 = sys_openat_append("knowledge/status/greeting_gate.log\x00" as *u8, 0x1a4) 56 gp(logfd, "GREETING-GATE W-GR-1 (three beats: self-introduction -> scenario -> direct address; ORDER is part of the measurement)\n\x00" as *u8) 57 let pass: *i64 = sys_mmap(16) as *i64 58 let total: *i64 = sys_mmap(16) as *i64 59 pass[0] = 0 60 total[0] = 0 61 62 // operator DATA: packed marker lexicons, one per beat 63 let intro: *u8 = "i'm\x00i am\x00my name is\x00they call me\x00call me\x00\x00" as *u8 64 let INN: i64 = 5 65 let scen: *u8 = "when\x00tonight\x00the storm\x00just arrived\x00after\x00\x00" as *u8 66 let SCN: i64 = 5 67 let addr: *u8 = "you\x00your\x00tell me\x00\x00" as *u8 68 let ADN: i64 = 3 69 70 // T1 whole-word: "yours" alone must NOT satisfy the address beat 71 let t1: *u8 = "the book is yours\x00" as *u8 72 pr(logfd, "T1 whole-word (yours != you)\x00" as *u8, 73 gr_beat_pos(t1, 0, sl(t1), addr, ADN), GR_NOT_FOUND, pass, total) 74 75 // T2 case-insensitive 76 let t2: *u8 = "You there\x00" as *u8 77 pr(logfd, "T2 case-insensitive address found at 0\x00" as *u8, 78 gr_beat_pos(t2, 0, sl(t2), addr, ADN), 0, pass, total) 79 80 // T3 a well-formed greeting: intro -> scenario -> address, in order 81 let g: *u8 = "I'm Wren, the lighthouse keeper. When the storm rolled in the lamp went dark, and now you are the only other soul on this rock. Tell me what you see.\x00" as *u8 82 let gi: i64 = gr_beat_pos(g, 0, sl(g), intro, INN) 83 let gs: i64 = gr_beat_pos(g, 0, sl(g), scen, SCN) 84 let ga: i64 = gr_beat_pos(g, 0, sl(g), addr, ADN) 85 pr(logfd, "T3 well-formed greeting -> COMPLETE\x00" as *u8, 86 gr_verdict(gi, gs, ga), GR_COMPLETE, pass, total) 87 pr(logfd, "T3b scores 1000 permil\x00" as *u8, 88 gr_score_permil(gi, gs, ga), 1000, pass, total) 89 90 // ★T4 ORDER IS LOAD-BEARING: same three beats, address first -> PARTIAL, never COMPLETE 91 let sc: *u8 = "You are the only other soul on this rock. When the storm rolled in the lamp went dark. I'm Wren, the lighthouse keeper.\x00" as *u8 92 let si: i64 = gr_beat_pos(sc, 0, sl(sc), intro, INN) 93 let ss: i64 = gr_beat_pos(sc, 0, sl(sc), scen, SCN) 94 let sa: i64 = gr_beat_pos(sc, 0, sl(sc), addr, ADN) 95 pr(logfd, "T4 SAME beats scrambled -> PARTIAL (order matters)\x00" as *u8, 96 gr_verdict(si, ss, sa), GR_PARTIAL, pass, total) 97 pr(logfd, "T4b all three still PRESENT (so it is order, not absence)\x00" as *u8, 98 gr_beats_present(si, ss, sa), 3, pass, total) 99 100 // T5 two beats -> PARTIAL 101 let two: *u8 = "I'm Wren, the lighthouse keeper. Tell me what you see.\x00" as *u8 102 let ti: i64 = gr_beat_pos(two, 0, sl(two), intro, INN) 103 let ts: i64 = gr_beat_pos(two, 0, sl(two), scen, SCN) 104 let ta: i64 = gr_beat_pos(two, 0, sl(two), addr, ADN) 105 pr(logfd, "T5 two beats -> PARTIAL\x00" as *u8, gr_verdict(ti, ts, ta), GR_PARTIAL, pass, total) 106 107 // ★T6 NEG-CONTROL: a flat character sheet, no beats 108 let flat: *u8 = "A lighthouse keeper. Forty years old. Quiet, methodical, fond of birds.\x00" as *u8 109 let fi: i64 = gr_beat_pos(flat, 0, sl(flat), intro, INN) 110 let fs: i64 = gr_beat_pos(flat, 0, sl(flat), scen, SCN) 111 let fa: i64 = gr_beat_pos(flat, 0, sl(flat), addr, ADN) 112 pr(logfd, "T6 NEG flat character sheet -> FLAT\x00" as *u8, gr_verdict(fi, fs, fa), GR_FLAT, pass, total) 113 114 // ★T7 NEG-CONTROL: introduction only is a bio line, not a greeting 115 let only: *u8 = "I'm Wren, the lighthouse keeper.\x00" as *u8 116 let oi: i64 = gr_beat_pos(only, 0, sl(only), intro, INN) 117 let os: i64 = gr_beat_pos(only, 0, sl(only), scen, SCN) 118 let oa: i64 = gr_beat_pos(only, 0, sl(only), addr, ADN) 119 pr(logfd, "T7 NEG introduction only -> FLAT\x00" as *u8, gr_verdict(oi, os, oa), GR_FLAT, pass, total) 120 121 // T8 monotone scoring across the four shapes 122 total[0] = total[0] + 1 123 let s_flat: i64 = gr_score_permil(fi, fs, fa) 124 let s_two: i64 = gr_score_permil(ti, ts, ta) 125 let s_scr: i64 = gr_score_permil(si, ss, sa) 126 let s_full: i64 = gr_score_permil(gi, gs, ga) 127 if s_flat < s_two { if s_two < s_scr { if s_scr < s_full { 128 pass[0] = pass[0] + 1 129 gp(logfd, "T8 monotone \x00" as *u8); gn(logfd, s_flat); gp(logfd, " < \x00" as *u8); gn(logfd, s_two) 130 gp(logfd, " < \x00" as *u8); gn(logfd, s_scr); gp(logfd, " < \x00" as *u8); gn(logfd, s_full) 131 gp(logfd, " OK\n\x00" as *u8) 132 } } } 133 if pass[0] * 0 == 1 { gp(logfd, "unreachable\n\x00" as *u8) } 134 135 // T9 positions are real, not booleans 136 total[0] = total[0] + 1 137 if gi < ga { pass[0] = pass[0] + 1; gp(logfd, "T9 intro position precedes address position OK\n\x00" as *u8) } 138 139 // T10 NEG empty input 140 let e: *u8 = "\x00" as *u8 141 let ei: i64 = gr_beat_pos(e, 0, 0, intro, INN) 142 pr(logfd, "T10 NEG empty -> FLAT\x00" as *u8, gr_verdict(ei, ei, ei), GR_FLAT, pass, total) 143 pr(logfd, "T10b NEG empty scores 0\x00" as *u8, gr_score_permil(ei, ei, ei), 0, pass, total) 144 145 gp(logfd, "GREETINGGATE \x00" as *u8); gn(logfd, pass[0]) 146 gp(logfd, "/\x00" as *u8); gn(logfd, total[0]) 147 if pass[0] == total[0] { gp(logfd, " verdict=GREEN\n\x00" as *u8); sys_close(logfd); return 0 } 148 gp(logfd, " verdict=RED\n\x00" as *u8) 149 sys_close(logfd) 150 return 1 151}