code wiki / _hdl_build / nx_js_vm_bench.nx

nx_js_vm_bench.nx

buildroot/runtime/_hdl_build/nx_js_vm_bench.nx

5487 B92 linesdepth 7pulls 22 transitivereach 0 importersview sourcekind benchtopic js
docsdependenciesstructsconstsfunctions

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

nx_js_eval.nx nx_js_vm_bench.nx

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

main bw sys_now_us sys_mmap sys_clock_gettime_mono bsl emit vm_run bn

structs

none

consts

7const BC_MAGIC_100000: i64 = 100000
8const BC_MAGIC_4999950000: i64 = 4999950000
9const BC_MAGIC_200000: i64 = 200000
10const BC_MAGIC_1000000: i64 = 1000000
17const BC_PUSH: i64 = 1 // push imm arg
18const BC_LOAD: i64 = 2 // push vars[arg]
19const BC_STORE: i64 = 3 // vars[arg] = pop
20const BC_ADD: i64 = 4 // b=pop; a=pop; push a+b
21const BC_LT: i64 = 5 // b=pop; a=pop; push (a<b)?1:0
22const BC_JMPF: i64 = 6 // c=pop; if c==0 pc=arg else pc+=2
23const BC_JMP: i64 = 7 // pc=arg
24const BC_RET: i64 = 8 // return top of stack

functions

12func 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
13func 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
14func bsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 1: main
27func vm_run(code: *i64, vars: *i64, stack: *i64) -> i64
called by 1: main
47func 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
49func main(argc: i64, argv: *i64) -> i64