code wiki / _hdl_build / nx_js_probes_run.nx
nx_js_probes_run.nx source
↩ module page · 26 lines · 1314 B
1// run knowledge/octane/jsprobes.js on the VM/JIT and print its result string (differential vs node). expect_exit: 0
2// license_tier: ORIGINAL
3import "nx_js_vm.nx"
4const K_MAGIC_65536: i64 = 65536
5func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
6func main(argc: i64, argv: *i64) -> i64 {
7 let fd: i64 = sys_openat_rd("knowledge/octane/jsprobes.js\x00" as *u8)
8 if fd < 0 { w("RED: no jsprobes.js\n" as *u8); return 1 }
9 let buf: *u8 = sys_mmap(K_MAGIC_65536)
10 var total: i64 = 0
11 var done: i64 = 0
12 while done == 0 { let n: i64 = sys_read(fd, ((buf as i64) + total) as *u8, K_MAGIC_65536 - total); if n <= 0 { done = 1 } else { total = total + n } }
13 sys_close(fd)
14 buf[total] = 0 as u8
15 let out: *i64 = sys_mmap(16) as *i64
16 let rc: i64 = compile_run(buf, out)
17 w("OURS(vm): " as *u8)
18 if out[0] == VAL_STR { sys_write(1, ev_str_bytes((out[1]) as *i64), ev_str_len((out[1]) as *i64)) } else { w("<non-string rc>" as *u8) }
19 w("\n" as *u8)
20 let ot: *i64 = sys_mmap(16) as *i64
21 js_run_source(buf, total, ot)
22 w("OURS(tree): " as *u8)
23 if ot[0] == VAL_STR { sys_write(1, ev_str_bytes((ot[1]) as *i64), ev_str_len((ot[1]) as *i64)) } else { w("<non-string rc>" as *u8) }
24 w("\n" as *u8)
25 return 0
26}