code wiki / _hdl_build / nx_js_probes_vm.nx

nx_js_probes_vm.nx source

↩ module page · 22 lines · 1525 B

1// run knowledge/octane/jsprobes.js on the VM/JIT ONLY (tree-walker skipped: call-heavy probes SIGTERM it), 2// printing rc + tag + value/string. expect_exit: 0 license_tier: ORIGINAL 3import "nx_js_vm.nx" 4const K_MAGIC_262144: i64 = 262144 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 nn(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 } 7func main(argc: i64, argv: *i64) -> i64 { 8 let fd: i64 = sys_openat_rd("knowledge/octane/jsprobes.js\x00" as *u8) 9 if fd < 0 { w("RED: no jsprobes.js\n" as *u8); return 1 } 10 let buf: *u8 = sys_mmap(K_MAGIC_262144) 11 var total: i64 = 0 12 var done: i64 = 0 13 while done == 0 { let n: i64 = sys_read(fd, ((buf as i64) + total) as *u8, K_MAGIC_262144 - total); if n <= 0 { done = 1 } else { total = total + n } } 14 sys_close(fd) 15 buf[total] = 0 as u8 16 let out: *i64 = sys_mmap(16) as *i64 17 let rc: i64 = compile_run(buf, out) 18 w("VM rc=" as *u8); nn(rc); w(" tag=" as *u8); nn(out[0]); w(" " as *u8) 19 if out[0] == VAL_STR { w("'" as *u8); sys_write(1, ev_str_bytes((out[1]) as *i64), ev_str_len((out[1]) as *i64)); w("'" as *u8) } else { w("val=" as *u8); nn(out[1]) } 20 w("\n" as *u8) 21 return 0 22}