code wiki / _hdl_build / nx_js_octane_regexp_ck.nx
nx_js_octane_regexp_ck.nx source
↩ module page · 44 lines · 2667 B
1// nx_js_octane_regexp_ck.nx -- AUTHORITATIVE Octane RegExp verification: run the real 126KB V8 regexp.js
2// corpus (seeded Octane base.js PRNG) ONE pass through all 12 blocks and assert the sum == V8's checksum
3// 1666109. This IS what the benchmark's run() certifies -- run() just repeats this identical, PRNG-independent
4// computation 5x (the blocks iterate FIXED pre-built variant arrays, no Math.random inside), so a 1-pass match
5// == REGEXP_OK. Preferred over nx_js_octane_regexp because the 5x harness is the longest-running test and gets
6// SIGTERM'd on an unstable WSL VM (not OOM -- 15GB free). regexp_cksum.js = head(stub+seed) + raw + a foot that
7// exposes the blocks and sums them. expect_exit: 0 license_tier: ORIGINAL
8import "nx_js_vm.nx"
9const K_MAGIC_262144: i64 = 262144
10func ow(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
11func main(argc: i64, argv: *i64) -> i64 {
12 ow("=== nx_js_octane_regexp_ck: real Octane RegExp checksum (1-pass, V8-pinned 1666109) ===\n" as *u8)
13 let fd: i64 = sys_openat_rd("knowledge/octane/regexp_cksum.js\x00" as *u8)
14 if fd < 0 { ow(" RED: cannot open regexp_cksum.js\n" as *u8); return 1 }
15 let cap: i64 = K_MAGIC_262144
16 let buf: *u8 = sys_mmap(cap + 8)
17 var total: i64 = 0
18 var done: i64 = 0
19 while done == 0 { let n: i64 = sys_read(fd, ((buf as i64) + total) as *u8, cap - total); if n <= 0 { done = 1 } else { total = total + n } }
20 sys_close(fd)
21 buf[total] = 0 as u8
22 let out: *i64 = sys_mmap(16) as *i64
23 let rc: i64 = compile_run(buf, out)
24 ow(" rc=" as *u8)
25 let bb: *u8 = sys_mmap(8); var m: i64 = rc; var kk: i64 = 0; if m==0{bb[0]=48;kk=1} while m>0{bb[kk]=(48+(m%10)) as u8;m=m/10;kk=kk+1} var q: i64=kk-1; while q>=0{sys_write(1,((bb as i64)+q) as *u8,1);q=q-1}
26 ow(" result='" as *u8)
27 if out[0] == VAL_STR { sys_write(1, ev_str_bytes((out[1]) as *i64), ev_str_len((out[1]) as *i64)) }
28 ow("'\n" as *u8)
29 // GREEN iff the result string ends with "MATCH=YES"
30 var okr: i64 = 0
31 if rc == 0 { if out[0] == VAL_STR {
32 let rb: *u8 = ev_str_bytes((out[1]) as *i64)
33 let rl: i64 = ev_str_len((out[1]) as *i64)
34 let exp: *u8 = "MATCH=YES" as *u8
35 if rl >= 9 {
36 okr = 1
37 var i: i64 = 0
38 while i < 9 { if (rb[rl - 9 + i] & 0xff) != (exp[i] & 0xff) { okr = 0; i = 9 } else { i = i + 1 } }
39 }
40 } }
41 if okr == 0 { ow("=== RED: RegExp checksum != 1666109 ===\n" as *u8); return 1 }
42 ow("=== GREEN: real Octane RegExp checksum == 1666109 BIT-EXACT with V8 (8th Octane; matching V8-exact) ===\n" as *u8)
43 return 0
44}