code wiki / _hdl_build / nx_js_octane_earley.nx

nx_js_octane_earley.nx source

↩ module page · 62 lines · 3717 B

1// nx_js_octane_earley.nx -- run the REAL Octane EarleyBoyer benchmark (unmodified scheme2js source, harness 2// stubbed) on our sovereign VM/JIT. Self-validates: RunBenchmark throws on wrong rewrite count, so a clean 3// "EARLEY_BOYER_OK" return means the Earley parser + Boyer theorem-prover both produced correct results. 4// This is THE GC-stress benchmark (deep closures + cons-list allocation) -- proves the default-on GC on real 5// heavy-allocation code. PARSE-first to split syntax gaps from runtime gaps. expect_exit: 0 license_tier: ORIGINAL 6import "nx_js_vm.nx" 7const K_MAGIC_524288: i64 = 524288 8func ow(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 9func on(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(24); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } let o: *u8=sys_mmap(24); var q: i64=k-1; var x: i64=0; while q>=0 { o[x]=t[q]; x=x+1; q=q-1 } sys_write(1,o,x); return 0 } 10func main(argc: i64, argv: *i64) -> i64 { 11 ow("=== nx_js_octane_earley: real Octane EarleyBoyer on our sovereign VM/JIT + default-on GC ===\n" as *u8) 12 let fd: i64 = sys_openat_rd("knowledge/octane/earley_eng.js\x00" as *u8) 13 if fd < 0 { ow(" RED: cannot open knowledge/octane/earley_eng.js\n" as *u8); return 1 } 14 let cap: i64 = K_MAGIC_524288 15 let buf: *u8 = sys_mmap(cap + 8) 16 var total: i64 = 0 17 var done: i64 = 0 18 while done == 0 { 19 let n: i64 = sys_read(fd, ((buf as i64) + total) as *u8, cap - total) 20 if n <= 0 { done = 1 } else { total = total + n } 21 } 22 sys_close(fd) 23 buf[total] = 0 as u8 24 ow(" loaded earley_eng.js: "); on(total); ow(" bytes\n" as *u8) 25 26 // PARSE-ONLY first: syntax gap vs runtime feature gap. 27 let ctxbox: *i64 = sys_mmap(16) as *i64 28 let prog: i64 = jp_parse_source(buf, total, ctxbox) 29 let pctx: *i64 = (ctxbox[0]) as *i64 30 let pst: *i64 = jp_pst(pctx) 31 if pst[PST_ERR] == 1 { 32 let eb: i64 = jp_tok_start(pctx, pst[PST_CUR]) 33 ow(" PARSE ERROR at cursor "); on(pst[PST_CUR]); ow(" byte "); on(eb); ow(" context: '"); 34 var ci: i64 = eb - 20; if ci < 0 { ci = 0 } 35 var ce: i64 = eb + 24 36 while ci < ce { sys_write(1, ((buf as i64) + ci) as *u8, 1); ci = ci + 1 } 37 ow("'\n" as *u8) 38 } else { ow(" PARSE OK -> any failure is a RUNTIME feature\n" as *u8) } 39 40 let out: *i64 = sys_mmap(16) as *i64 41 let t0: i64 = sys_now_us() 42 let gc0: i64 = gc_collection_count() 43 js_set_rt_dbg(1) // print the failing top-level statement + thrown error to stderr 44 let rc: i64 = compile_run(buf, out) 45 let t1: i64 = sys_now_us() 46 ow(" compile_run rc="); on(rc); ow(" result tag="); on(out[0]); ow(" +GCs="); on(gc_collection_count() - gc0) 47 if out[0] == VAL_STR { ow(" '"); sys_write(1, ev_str_bytes((out[1]) as *i64), ev_str_len((out[1]) as *i64)); ow("'") } 48 ow("\n" as *u8) 49 50 var okr: i64 = 0 51 if rc == 0 { if out[0] == VAL_STR { 52 let rb: *u8 = ev_str_bytes((out[1]) as *i64) 53 let rl: i64 = ev_str_len((out[1]) as *i64) 54 if rl == 15 { okr = 1; var i: i64 = 0; let exp: *u8 = "EARLEY_BOYER_OK" as *u8; while i < 15 { if (rb[i] & 0xff) != (exp[i] & 0xff) { okr = 0; i = 15 } else { i = i + 1 } } } 55 } } 56 if okr == 0 { ow("=== RED: EarleyBoyer did not complete (feature gap or self-validation throw) ===\n" as *u8); return 1 } 57 var us: i64 = t1 - t0 58 if us < 1 { us = 1 } 59 ow(" ours(parse+1 run)="); on(us); ow("us\n" as *u8) 60 ow("=== GREEN: we RAN real Octane EarleyBoyer -- Earley+Boyer self-validated under default-on GC ===\n" as *u8) 61 return 0 62}