code wiki / _hdl_build / nx_js_vm_bench.nx
nx_js_vm_bench.nx
buildroot/runtime/_hdl_build/nx_js_vm_bench.nx
about
nx_js_vm_bench.nx -- KEYSTONE of the bytecode-VM arc: a minimal stack-based BYTECODE VM (tight dispatch
loop, no AST walk / no recursion / no per-node kind-dispatch) runs the SAME hot loop as the tree-walker,
and we MEASURE the speedup. Integer-only for the proof (the hot path is arithmetic); tagged values +
full opcodes + an AST->bytecode compiler are the next rungs. Same result + faster = the architecture is
proven, de-risking the arc. license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_js_eval.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 7 | const BC_MAGIC_100000: i64 = 100000 |
| 8 | const BC_MAGIC_4999950000: i64 = 4999950000 |
| 9 | const BC_MAGIC_200000: i64 = 200000 |
| 10 | const BC_MAGIC_1000000: i64 = 1000000 |
| 17 | const BC_PUSH: i64 = 1 // push imm arg |
| 18 | const BC_LOAD: i64 = 2 // push vars[arg] |
| 19 | const BC_STORE: i64 = 3 // vars[arg] = pop |
| 20 | const BC_ADD: i64 = 4 // b=pop; a=pop; push a+b |
| 21 | const BC_LT: i64 = 5 // b=pop; a=pop; push (a<b)?1:0 |
| 22 | const BC_JMPF: i64 = 6 // c=pop; if c==0 pc=arg else pc+=2 |
| 23 | const BC_JMP: i64 = 7 // pc=arg |
| 24 | const BC_RET: i64 = 8 // return top of stack |
functions
| 12 | func bw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } called by 1: main |
| 13 | func bn(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(32); 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(32); 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 } called by 1: main |
| 14 | func bsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } called by 1: main |
| 27 | func vm_run(code: *i64, vars: *i64, stack: *i64) -> i64 called by 1: main |
| 47 | func emit(code: *i64, i: i64, op: i64, arg: i64) -> i64 { code[i * 2] = op; code[i * 2 + 1] = arg; return 0 } called by 1: main |
| 49 | func main(argc: i64, argv: *i64) -> i64 |