code wiki / _hdl_build / nx_js_fnprop_diag.nx

nx_js_fnprop_diag.nx source

↩ module page · 27 lines · 1955 B

1// pinpoint Splay's runtime gap: fn-static-property + String(). Minimal calls (avoid arena flake). expect_exit: 0 2// license_tier: ORIGINAL 3import "nx_js_vm.nx" 4func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 5func 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 } 6func show(label: *u8, src: *u8) -> i64 { 7 let ot: *i64 = sys_mmap(16) as *i64 8 let ov: *i64 = sys_mmap(16) as *i64 9 let rt: i64 = js_run_source(src, bsl(src), ot) 10 let rv: i64 = compile_run(src, ov) 11 w(label); w(" TREE rc="); nn(rt); w(" val="); nn(ot[1]); w(" | VM rc="); nn(rv); w(" val="); nn(ov[1]) 12 if rt == rv { if ot[1] == ov[1] { w(" (match)\n" as *u8); return 0 } } 13 w(" <-- MISMATCH\n" as *u8); return 0 14} 15func main(argc: i64, argv: *i64) -> i64 { 16 w("=== fn-static-prop + String diagnostic (TREE only, minimal) ===\n" as *u8) 17 show("A0 fn.prop=int; read" as *u8, "function F(){}F.G=42;F.G" as *u8) 18 show("A1 fn.prop=fn; call via var" as *u8, "function F(){}F.G=function(x){return x+1;};var g=F.G;g(6)" as *u8) 19 show("A fn.prop=fn; new fn.prop()" as *u8, "function F(){}F.G=function(x){this.x=x;};var o=new F.G(7);o.x" as *u8) 20 show("B fn.prop.prototype method" as *u8, "function F(){}F.G=function(x){this.x=x;};F.G.prototype.get=function(){return this.x;};var o=new F.G(9);o.get()" as *u8) 21 show("C0 String(42) raw" as *u8, "String(42)" as *u8) 22 show("C String(int)" as *u8, "String(42).length" as *u8) 23 show("D String(float)" as *u8, "String(7/2).length" as *u8) 24 show("E array.push" as *u8, "var a=[];a.push(3);a.push(5);a.length" as *u8) 25 w("DONE\n" as *u8) 26 return 0 27}