code wiki / _hdl_build / nx_js_octane_next_diag.nx

nx_js_octane_next_diag.nx source

↩ module page · 69 lines · 3984 B

1// nx_js_octane_next_diag.nx -- PARSE-FIRST diagnostic for the next Octane targets (DeltaBlue/RayTrace/Crypto). 2// Imports ONLY the parser (not eval/vm) so it is independent of the concurrent regex-value lane in nx_js_eval. 3// Answers: which targets have LEXER/PARSER-level gaps vs runtime-native gaps -- directing the next shared-core 4// batch. Drivers V8-validated first (DELTABLUE_OK 4.8ms / RAYTRACE_OK 10.3ms / CRYPTO_OK 13.1ms on this box). 5// expect_exit: 0 (diagnostic: reports, never fails the build) license_tier: ORIGINAL 6import "nx_js_parse.nx" 7const K_MAGIC_262144: i64 = 262144 8const K_MAGIC_65536: i64 = 65536 9func dw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 10func dn(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 } 11func diag_one(path: *u8, label: *u8) -> i64 { 12 let fd: i64 = sys_openat_rd(path) 13 if fd < 0 { dw(" " as *u8); dw(label); dw(": CANNOT OPEN\n" as *u8); return 0 } 14 let cap: i64 = K_MAGIC_262144 15 let buf: *u8 = sys_mmap(cap + 8) 16 var total: i64 = 0 17 var done: i64 = 0 18 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 } } 19 sys_close(fd) 20 buf[total] = 0 as u8 21 let ctxbox: *i64 = sys_mmap(16) as *i64 22 let prog: i64 = jp_parse_source(buf, total, ctxbox) 23 let pctx: *i64 = (ctxbox[0]) as *i64 24 let pst: *i64 = jp_pst(pctx) 25 dw(" " as *u8); dw(label); dw(" (" as *u8); dn(total); dw("B): " as *u8) 26 if pst[PST_ERR] == 1 { 27 dw("PARSE ERROR -> lexer/parser gap\n" as *u8) 28 // the cursor sits at/near the offending token: print +/-60 source bytes of context. 29 let ts: i64 = jp_tok_start(pctx) 30 var lo: i64 = ts - 60 31 if lo < 0 { lo = 0 } 32 var hi: i64 = ts + 60 33 if hi > total { hi = total } 34 dw(" around byte " as *u8); dn(ts); dw(": [" as *u8) 35 sys_write(1, ((buf as i64) + lo) as *u8, hi - lo) 36 dw("]\n" as *u8) 37 // ALSO lex-scan: the first JS_TOK_ERROR token pinpoints a LEXER-level failure (stride-3 toks). 38 let toks: *i64 = sys_mmap(8 * 3 * K_MAGIC_65536) as *i64 39 let nb: *i64 = sys_mmap(16) as *i64 40 nb[0] = 0 41 js_lex(buf, total, toks, K_MAGIC_65536, nb) 42 var ti: i64 = 0 43 var hit: i64 = 0 - 1 44 while ti < nb[0] { if toks[ti * 3] == JS_TOK_ERROR { hit = ti; ti = nb[0] } else { ti = ti + 1 } } 45 if hit >= 0 { 46 let es: i64 = toks[hit * 3 + 1] 47 var l2: i64 = es - 70 48 if l2 < 0 { l2 = 0 } 49 var h2: i64 = es + 70 50 if h2 > total { h2 = total } 51 dw(" FIRST LEX ERROR tok#" as *u8); dn(hit); dw(" at byte " as *u8); dn(es); dw(": [" as *u8) 52 sys_write(1, ((buf as i64) + l2) as *u8, h2 - l2) 53 dw("]\n" as *u8) 54 } 55 return 0 56 } 57 dw("PARSE OK -> gaps are RUNTIME natives only\n" as *u8) 58 return 1 59} 60func main(argc: i64, argv: *i64) -> i64 { 61 dw("=== nx_js_octane_next_diag: parse-first map of the next Octane targets ===\n" as *u8) 62 var ok: i64 = 0 63 ok = ok + diag_one("knowledge/octane/deltablue_eng.js\x00" as *u8, "DeltaBlue" as *u8) 64 ok = ok + diag_one("knowledge/octane/raytrace_eng.js\x00" as *u8, "RayTrace" as *u8) 65 ok = ok + diag_one("knowledge/octane/crypto_eng.js\x00" as *u8, "Crypto" as *u8) 66 dw(" --- " as *u8); dn(ok); dw("/3 parse clean ---\n" as *u8) 67 dw("=== DIAG COMPLETE (static gap map: Crypto needs charCodeAt/fromCharCode/parseInt-radix; DeltaBlue needs defineProperty+Object.prototype chain+alert; RayTrace needs arguments+apply+Object.extend statics) ===\n" as *u8) 68 return 0 69}