jz 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +37 -33
  2. package/bench/README.md +176 -73
  3. package/bench/bench.svg +58 -71
  4. package/cli.js +12 -5
  5. package/dist/interop.js +1 -1
  6. package/dist/jz.js +1366 -1101
  7. package/index.js +40 -9
  8. package/interop.js +193 -138
  9. package/layout.js +29 -18
  10. package/module/array.js +49 -73
  11. package/module/collection.js +83 -25
  12. package/module/console.js +1 -1
  13. package/module/core.js +161 -15
  14. package/module/json.js +3 -3
  15. package/module/math.js +167 -117
  16. package/module/number.js +247 -13
  17. package/module/object.js +11 -5
  18. package/module/regex.js +8 -7
  19. package/module/string.js +295 -171
  20. package/module/typedarray.js +169 -105
  21. package/package.json +7 -3
  22. package/src/abi/string.js +40 -35
  23. package/src/ast.js +19 -2
  24. package/src/compile/analyze.js +64 -2
  25. package/src/compile/cse-load.js +200 -0
  26. package/src/compile/emit-assign.js +73 -14
  27. package/src/compile/emit.js +324 -34
  28. package/src/compile/index.js +204 -61
  29. package/src/compile/infer.js +8 -1
  30. package/src/compile/loop-divmod.js +12 -58
  31. package/src/compile/loop-model.js +91 -0
  32. package/src/compile/loop-recurrence.js +167 -0
  33. package/src/compile/loop-square.js +102 -0
  34. package/src/compile/narrow.js +180 -34
  35. package/src/compile/peel-stencil.js +18 -64
  36. package/src/compile/plan/common.js +29 -0
  37. package/src/compile/plan/index.js +4 -1
  38. package/src/compile/plan/inline.js +176 -21
  39. package/src/compile/plan/literals.js +93 -19
  40. package/src/ctx.js +51 -12
  41. package/src/helper-counters.js +137 -0
  42. package/src/ir.js +102 -13
  43. package/src/kind-traits.js +7 -3
  44. package/src/kind.js +14 -1
  45. package/src/op-policy.js +5 -2
  46. package/src/ops.js +119 -0
  47. package/src/optimize/index.js +1125 -136
  48. package/src/optimize/recurse.js +182 -0
  49. package/src/optimize/vectorize.js +1302 -144
  50. package/src/prepare/index.js +29 -12
  51. package/src/reps.js +4 -1
  52. package/src/type.js +53 -45
  53. package/src/wat/assemble.js +92 -9
  54. package/src/widen.js +21 -0
  55. package/src/wat/optimize.js +0 -3938
package/bench/bench.svg CHANGED
@@ -1,102 +1,89 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 474" width="720" height="474" role="img" aria-label="jz benchmark — every rival compiled to WebAssembly, run in V8 · native C = reference; geometric mean across 22 benchmark cases · lower is faster, jz = 1.00× baseline; each ball's speed is proportional to that engine's geometric-mean runtime across the corpus">
2
- <rect width="720" height="474" rx="12" fill="#ffffff"/>
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 424" width="720" height="424" style="color-scheme:light dark" role="img" aria-label="JZ benchmark — every rival compiled to WebAssembly, run in V8 · native C = reference; geometric mean across 39 benchmark cases · lower is faster, JZ = 1.00× baseline; each ball's speed is proportional to that engine's geometric-mean runtime across the corpus">
3
2
 
4
3
  <g font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif">
5
- <rect x="174" y="43.5" width="476" height="3" rx="1.5" fill="#edf0f2"/>
6
- <line x1="174" y1="38" x2="174" y2="52" stroke="#ced4da" stroke-width="2"/>
7
- <line x1="650" y1="38" x2="650" y2="52" stroke="#ced4da" stroke-width="2"/>
8
- <text x="156" y="41" text-anchor="end" font-size="14" font-weight="700" fill="#000000">jz</text>
9
- <text x="156" y="56" text-anchor="end" font-size="10" fill="#aeb4ba">-O3</text>
10
- <text x="662" y="49" font-size="13" font-weight="700" fill="#000000">1.00×</text>
11
- <circle cx="182.0" cy="45" r="8" fill="#000000">
4
+ <rect x="174" y="43.5" width="476" height="3" rx="1.5" fill="currentColor" fill-opacity="0.1"/>
5
+ <line x1="174" y1="38" x2="174" y2="52" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
6
+ <line x1="650" y1="38" x2="650" y2="52" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
7
+ <text x="156" y="41" text-anchor="end" font-size="14" font-weight="700" fill="currentColor" fill-opacity="1">JZ</text>
8
+ <text x="156" y="56" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">-O3</text>
9
+ <text x="662" y="49" font-size="13" font-weight="700" fill="currentColor" fill-opacity="1">1.00×</text>
10
+ <circle cx="182.0" cy="45" r="8" fill="currentColor" fill-opacity="1">
12
11
  <animate attributeName="cx" dur="1.6s" repeatCount="indefinite" calcMode="linear"
13
12
  keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-0.00s"/>
14
13
  </circle>
15
14
  </g>
16
15
  <g font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif">
17
- <rect x="174" y="93.5" width="476" height="3" rx="1.5" fill="#edf0f2"/>
18
- <line x1="174" y1="88" x2="174" y2="102" stroke="#ced4da" stroke-width="2"/>
19
- <line x1="650" y1="88" x2="650" y2="102" stroke="#ced4da" stroke-width="2"/>
20
- <text x="156" y="91" text-anchor="end" font-size="14" font-weight="500" fill="#343a40">native C</text>
21
- <text x="156" y="106" text-anchor="end" font-size="10" fill="#aeb4ba">clang -O3 · ref</text>
22
- <text x="662" y="99" font-size="13" font-weight="500" fill="#868e96">1.07×</text>
23
- <circle cx="182.0" cy="95" r="8" fill="#adb5bd">
24
- <animate attributeName="cx" dur="1.7120000000000002s" repeatCount="indefinite" calcMode="linear"
16
+ <rect x="174" y="93.5" width="476" height="3" rx="1.5" fill="currentColor" fill-opacity="0.1"/>
17
+ <line x1="174" y1="88" x2="174" y2="102" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
18
+ <line x1="650" y1="88" x2="650" y2="102" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
19
+ <text x="156" y="91" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">native C</text>
20
+ <text x="156" y="106" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">clang -O3 · ref</text>
21
+ <text x="662" y="99" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">1.01×</text>
22
+ <circle cx="182.0" cy="95" r="8" fill="currentColor" fill-opacity="0.4">
23
+ <animate attributeName="cx" dur="1.6146835172309477s" repeatCount="indefinite" calcMode="linear"
25
24
  keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-0.41s"/>
26
25
  </circle>
27
26
  </g>
28
27
  <g font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif">
29
- <rect x="174" y="143.5" width="476" height="3" rx="1.5" fill="#edf0f2"/>
30
- <line x1="174" y1="138" x2="174" y2="152" stroke="#ced4da" stroke-width="2"/>
31
- <line x1="650" y1="138" x2="650" y2="152" stroke="#ced4da" stroke-width="2"/>
32
- <text x="156" y="141" text-anchor="end" font-size="14" font-weight="500" fill="#343a40">C</text>
33
- <text x="156" y="156" text-anchor="end" font-size="10" fill="#aeb4ba">zig cc → wasm</text>
34
- <text x="662" y="149" font-size="13" font-weight="500" fill="#868e96">2.43×</text>
35
- <circle cx="182.0" cy="145" r="8" fill="#adb5bd">
36
- <animate attributeName="cx" dur="3.8880000000000003s" repeatCount="indefinite" calcMode="linear"
28
+ <rect x="174" y="143.5" width="476" height="3" rx="1.5" fill="currentColor" fill-opacity="0.1"/>
29
+ <line x1="174" y1="138" x2="174" y2="152" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
30
+ <line x1="650" y1="138" x2="650" y2="152" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
31
+ <text x="156" y="141" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">C</text>
32
+ <text x="156" y="156" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">clang → wasm</text>
33
+ <text x="662" y="149" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">2.03×</text>
34
+ <circle cx="182.0" cy="145" r="8" fill="currentColor" fill-opacity="0.4">
35
+ <animate attributeName="cx" dur="3.2426115177636263s" repeatCount="indefinite" calcMode="linear"
37
36
  keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-0.82s"/>
38
37
  </circle>
39
38
  </g>
40
39
  <g font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif">
41
- <rect x="174" y="193.5" width="476" height="3" rx="1.5" fill="#edf0f2"/>
42
- <line x1="174" y1="188" x2="174" y2="202" stroke="#ced4da" stroke-width="2"/>
43
- <line x1="650" y1="188" x2="650" y2="202" stroke="#ced4da" stroke-width="2"/>
44
- <text x="156" y="191" text-anchor="end" font-size="14" font-weight="500" fill="#343a40">Rust</text>
45
- <text x="156" y="206" text-anchor="end" font-size="10" fill="#aeb4ba">rustc → wasm</text>
46
- <text x="662" y="199" font-size="13" font-weight="500" fill="#868e96">2.63×</text>
47
- <circle cx="182.0" cy="195" r="8" fill="#adb5bd">
48
- <animate attributeName="cx" dur="4.208s" repeatCount="indefinite" calcMode="linear"
40
+ <rect x="174" y="193.5" width="476" height="3" rx="1.5" fill="currentColor" fill-opacity="0.1"/>
41
+ <line x1="174" y1="188" x2="174" y2="202" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
42
+ <line x1="650" y1="188" x2="650" y2="202" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
43
+ <text x="156" y="191" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">Rust</text>
44
+ <text x="156" y="206" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">rustc → wasm</text>
45
+ <text x="662" y="199" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">2.06×</text>
46
+ <circle cx="182.0" cy="195" r="8" fill="currentColor" fill-opacity="0.4">
47
+ <animate attributeName="cx" dur="3.293585213146645s" repeatCount="indefinite" calcMode="linear"
49
48
  keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-1.23s"/>
50
49
  </circle>
51
50
  </g>
52
51
  <g font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif">
53
- <rect x="174" y="243.5" width="476" height="3" rx="1.5" fill="#edf0f2"/>
54
- <line x1="174" y1="238" x2="174" y2="252" stroke="#ced4da" stroke-width="2"/>
55
- <line x1="650" y1="238" x2="650" y2="252" stroke="#ced4da" stroke-width="2"/>
56
- <text x="156" y="241" text-anchor="end" font-size="14" font-weight="500" fill="#343a40">V8</text>
57
- <text x="156" y="256" text-anchor="end" font-size="10" fill="#aeb4ba">Node (JS)</text>
58
- <text x="662" y="249" font-size="13" font-weight="500" fill="#868e96">2.69×</text>
59
- <circle cx="182.0" cy="245" r="8" fill="#adb5bd">
60
- <animate attributeName="cx" dur="4.304s" repeatCount="indefinite" calcMode="linear"
52
+ <rect x="174" y="243.5" width="476" height="3" rx="1.5" fill="currentColor" fill-opacity="0.1"/>
53
+ <line x1="174" y1="238" x2="174" y2="252" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
54
+ <line x1="650" y1="238" x2="650" y2="252" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
55
+ <text x="156" y="241" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">AssemblyScript</text>
56
+ <text x="156" y="256" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">asc -O3</text>
57
+ <text x="662" y="249" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">2.12×</text>
58
+ <circle cx="182.0" cy="245" r="8" fill="currentColor" fill-opacity="0.4">
59
+ <animate attributeName="cx" dur="3.3917031518823295s" repeatCount="indefinite" calcMode="linear"
61
60
  keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-1.64s"/>
62
61
  </circle>
63
62
  </g>
64
63
  <g font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif">
65
- <rect x="174" y="293.5" width="476" height="3" rx="1.5" fill="#edf0f2"/>
66
- <line x1="174" y1="288" x2="174" y2="302" stroke="#ced4da" stroke-width="2"/>
67
- <line x1="650" y1="288" x2="650" y2="302" stroke="#ced4da" stroke-width="2"/>
68
- <text x="156" y="291" text-anchor="end" font-size="14" font-weight="500" fill="#343a40">AssemblyScript</text>
69
- <text x="156" y="306" text-anchor="end" font-size="10" fill="#aeb4ba">asc -O3</text>
70
- <text x="662" y="299" font-size="13" font-weight="500" fill="#868e96">2.80×</text>
71
- <circle cx="182.0" cy="295" r="8" fill="#adb5bd">
72
- <animate attributeName="cx" dur="4.4799999999999995s" repeatCount="indefinite" calcMode="linear"
64
+ <rect x="174" y="293.5" width="476" height="3" rx="1.5" fill="currentColor" fill-opacity="0.1"/>
65
+ <line x1="174" y1="288" x2="174" y2="302" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
66
+ <line x1="650" y1="288" x2="650" y2="302" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
67
+ <text x="156" y="291" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">V8</text>
68
+ <text x="156" y="306" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">Node (JS)</text>
69
+ <text x="662" y="299" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">2.32×</text>
70
+ <circle cx="182.0" cy="295" r="8" fill="currentColor" fill-opacity="0.4">
71
+ <animate attributeName="cx" dur="3.7148470369678392s" repeatCount="indefinite" calcMode="linear"
73
72
  keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-2.05s"/>
74
73
  </circle>
75
74
  </g>
76
75
  <g font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif">
77
- <rect x="174" y="343.5" width="476" height="3" rx="1.5" fill="#edf0f2"/>
78
- <line x1="174" y1="338" x2="174" y2="352" stroke="#ced4da" stroke-width="2"/>
79
- <line x1="650" y1="338" x2="650" y2="352" stroke="#ced4da" stroke-width="2"/>
80
- <text x="156" y="341" text-anchor="end" font-size="14" font-weight="500" fill="#343a40">Porffor</text>
81
- <text x="156" y="356" text-anchor="end" font-size="10" fill="#aeb4ba">runs 3 / 22</text>
82
- <text x="662" y="349" font-size="13" font-weight="500" fill="#868e96">3.49×</text>
83
- <circle cx="182.0" cy="345" r="8" fill="#adb5bd">
84
- <animate attributeName="cx" dur="5.5840000000000005s" repeatCount="indefinite" calcMode="linear"
76
+ <rect x="174" y="343.5" width="476" height="3" rx="1.5" fill="currentColor" fill-opacity="0.1"/>
77
+ <line x1="174" y1="338" x2="174" y2="352" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
78
+ <line x1="650" y1="338" x2="650" y2="352" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
79
+ <text x="156" y="341" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">Porffor</text>
80
+ <text x="156" y="356" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">runs 4 / 39</text>
81
+ <text x="662" y="349" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">3.80×</text>
82
+ <circle cx="182.0" cy="345" r="8" fill="currentColor" fill-opacity="0.4">
83
+ <animate attributeName="cx" dur="6.076381324758255s" repeatCount="indefinite" calcMode="linear"
85
84
  keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-2.46s"/>
86
85
  </circle>
87
86
  </g>
88
- <g font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif">
89
- <rect x="174" y="393.5" width="476" height="3" rx="1.5" fill="#edf0f2"/>
90
- <line x1="174" y1="388" x2="174" y2="402" stroke="#ced4da" stroke-width="2"/>
91
- <line x1="650" y1="388" x2="650" y2="402" stroke="#ced4da" stroke-width="2"/>
92
- <text x="156" y="391" text-anchor="end" font-size="14" font-weight="500" fill="#343a40">Go</text>
93
- <text x="156" y="406" text-anchor="end" font-size="10" fill="#aeb4ba">gc → wasm</text>
94
- <text x="662" y="399" font-size="13" font-weight="500" fill="#868e96">4.91×</text>
95
- <circle cx="182.0" cy="395" r="8" fill="#adb5bd">
96
- <animate attributeName="cx" dur="7.856000000000001s" repeatCount="indefinite" calcMode="linear"
97
- keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-2.87s"/>
98
- </circle>
99
- </g>
100
- <text x="360" y="440" text-anchor="middle" font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif" font-size="11" font-weight="600" fill="#495057">every rival compiled to WebAssembly, run in V8 · native C = reference</text>
101
- <text x="360" y="458" text-anchor="middle" font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif" font-size="11" fill="#868e96">geometric mean across 22 benchmark cases · lower is faster, jz = 1.00× baseline</text>
87
+ <text x="360" y="390" text-anchor="middle" font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif" font-size="11" font-weight="600" fill="currentColor" fill-opacity="0.72">every rival compiled to WebAssembly, run in V8 · native C = reference</text>
88
+ <text x="360" y="408" text-anchor="middle" font-family="-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif" font-size="11" fill="currentColor" fill-opacity="0.5">geometric mean across 39 benchmark cases · lower is faster, JZ = 1.00× baseline</text>
102
89
  </svg>
package/cli.js CHANGED
@@ -4,10 +4,17 @@
4
4
  * JZ CLI - Command-line interface for JZ compiler
5
5
  */
6
6
 
7
- import { readFileSync, writeFileSync } from 'fs'
8
- import { resolve } from 'path'
7
+ import { readFileSync, writeFileSync, mkdirSync } from 'fs'
8
+ import { resolve, dirname } from 'path'
9
9
  import { pathToFileURL } from 'url'
10
10
  import jz, { compile } from './index.js'
11
+
12
+ // Write to `file`, creating its parent directory first. `jz src.js -o dist/out.wasm`
13
+ // must not fail just because `dist/` doesn't exist yet — a fresh checkout where the
14
+ // output dir is gitignored (watr's `dist/`, jz's own build dir) is the common case,
15
+ // and every compiler that takes `-o path/file` is expected to make the path. Without
16
+ // this the CLI dies with `ENOENT: open 'dist/out.wasm'` (the watr CI build failure).
17
+ const writeOut = (file, data) => { mkdirSync(dirname(resolve(file)), { recursive: true }); writeFileSync(file, data) }
11
18
  import transform from './transform.js'
12
19
  import { resolveModuleGraph } from './src/resolve.js'
13
20
  import { createRequire } from 'module'
@@ -129,7 +136,7 @@ async function handleJzify(args) {
129
136
  if (outputFile === '-') {
130
137
  process.stdout.write(out)
131
138
  } else {
132
- writeFileSync(outputFile, out)
139
+ writeOut(outputFile, out)
133
140
  console.log(`${inputFile} → ${outputFile} (${out.length} chars)`)
134
141
  }
135
142
  }
@@ -252,10 +259,10 @@ async function handleCompile(args) {
252
259
  if (outputFile === '-') {
253
260
  process.stdout.write(result)
254
261
  } else if (wat) {
255
- writeFileSync(outputFile, result)
262
+ writeOut(outputFile, result)
256
263
  console.log(`${inputFile} → ${outputFile} (${result.length} chars)`)
257
264
  } else {
258
- writeFileSync(outputFile, result)
265
+ writeOut(outputFile, result)
259
266
  console.log(`${inputFile} → ${outputFile} (${result.byteLength} bytes)`)
260
267
  }
261
268
  }
package/dist/interop.js CHANGED
@@ -1 +1 @@
1
- var fe=new TextDecoder;function Q(t={}){let e=null,a=(c,i)=>{let p=c===1?globalThis.process?.stdout:globalThis.process?.stderr;if(p&&typeof p.write=="function")try{p.write(i);return}catch{}let A=i.replace(/\n$/,"");(c===1?console.log:console.warn)(A)},l=t.write||a;return{wasi_snapshot_preview1:{fd_read(c,i,p,A){let g=new DataView(e.buffer),d=0;for(let h=0;h<p;h++){let _=g.getUint32(i+h*8,!0),T=g.getUint32(i+h*8+4,!0),U=new Uint8Array(e.buffer,_,T);d+=t.read&&t.read(c,U)||0}return g.setUint32(A,d,!0),0},fd_write(c,i,p,A){let g=new DataView(e.buffer),d=0;for(let h=0;h<p;h++){let _=g.getUint32(i+h*8,!0),T=g.getUint32(i+h*8+4,!0);l(c,fe.decode(new Uint8Array(e.buffer,_,T))),d+=T}return g.setUint32(A,d,!0),0},clock_time_get(c,i,p){let A=new DataView(e.buffer),g=BigInt(Math.round(c===0?Date.now()*1e6:performance.now()*1e6));return A.setBigInt64(p,g,!0),0},random_get(c,i){let p=new Uint8Array(e.buffer,c,i);if(globalThis.crypto?.getRandomValues)globalThis.crypto.getRandomValues(p);else for(let A=0;A<i;A++)p[A]=Math.random()*256|0;return 0},proc_exit(){},environ_sizes_get(c,i){let p=new DataView(e.buffer);return p.setUint32(c,0,!0),p.setUint32(i,0,!0),0},environ_get(){return 0}},_setMemory(c){e=c}}}var Z=t=>{if(!t.exports.__timer_tick)return;let e=t.exports.__timer_tick,a=!1,l=setInterval(()=>{let c=e();c>0&&(a=!0),a&&c<=0&&clearInterval(l)},1)};var L={PTR_ADDR:1020,START:1024},k={TAG_SHIFT:47,TAG_MASK:15,AUX_SHIFT:32,AUX_MASK:32767,OFFSET_MASK:4294967295,NAN_PREFIX:32760,NAN_PREFIX_BITS:0x7FF8000000000000n,SSO_BIT:16384,SLICE_BIT:8192,SLICE_LEN_MASK:8191},N={ATOM:0,ARRAY:1,BUFFER:2,TYPED:3,STRING:4,OBJECT:6,HASH:7,SET:8,MAP:9,CLOSURE:10,EXTERNAL:11},E={NULL:1,UNDEF:2,FALSE:4,TRUE:5},Ie=1<<N.ARRAY|1<<N.HASH|1<<N.SET|1<<N.MAP;var P=(t,e)=>(2146959360|(t&15)<<15|e&32767)>>>0,X=t=>t>>>15&15,Y=t=>t&32767;var B={[E.NULL]:P(N.ATOM,E.NULL),[E.UNDEF]:P(N.ATOM,E.UNDEF),[E.FALSE]:P(N.ATOM,E.FALSE),[E.TRUE]:P(N.ATOM,E.TRUE)};var J=new TextEncoder,le=new TextDecoder,ue=(t,e)=>{let a=WebAssembly.Module.imports(t).some(l=>l.module==="wasi_snapshot_preview1");return{needsWasi:a,wasiImports:a?Q(e):null}},me=t=>new Set(WebAssembly.Module.imports(t).filter(e=>e.module==="env"&&e.kind==="function").map(e=>e.name)),pe=(t,e)=>{let a=()=>new DataView(t.buffer),l=e?()=>e.value:()=>a().getInt32(L.PTR_ADDR,!0),c=e?d=>{e.value=d}:d=>a().setInt32(L.PTR_ADDR,d,!0),i=e?e.value:L.START;return{alloc:d=>{let h=l()+7&-8,_=h+d;return _>t.buffer.byteLength&&t.grow(Math.ceil((_-t.buffer.byteLength)/65536)),c(_),h},reset:()=>c(i),initHeapPtr:()=>{if(e)return;let d=a();d.getInt32(L.PTR_ADDR,!0)<L.START&&d.setInt32(L.PTR_ADDR,L.START,!0)}}},G=(t,e)=>{let a=WebAssembly.Module.customSections(t,e);return a.length?new Uint8Array(a[0]):null},ye=t=>{let e=new TextDecoder,a=0;return{pos:()=>a,seek:l=>{a=l},eof:()=>a>=t.length,u8:()=>t[a++],varint:()=>{let l=0,c=0;for(;;){let i=t[a++];if(l|=(i&127)<<c,!(i&128))return l;c+=7}},str:l=>{let c=e.decode(t.subarray(a,a+l));return a+=l,c},bytes:l=>{let c=t.subarray(a,a+l);return a+=l,c}}},oe=new ArrayBuffer(8),I=new Uint32Array(oe),M=new Float64Array(oe),se=(()=>{let t=new ArrayBuffer(8),e=new BigInt64Array(t),a=new Float64Array(t);return{i64ToF64:l=>(e[0]=l,a[0]),f64ToI64:l=>(a[0]=l,e[0])}})(),S=se.i64ToF64,j=se.f64ToI64;I[1]=B[E.NULL];I[0]=0;var de=M[0];I[1]=B[E.UNDEF];I[0]=0;var V=M[0];I[1]=B[E.FALSE];I[0]=0;var Ue=M[0];I[1]=B[E.TRUE];I[0]=0;var Se=M[0],R=t=>t===null?de:t===void 0?V:t,W=t=>{if(t===t)return t;if(M[0]=t,X(I[1])===4){let e=Y(I[1]);if(e&k.SSO_BIT){let a=e&7,l=I[0],c="";for(let i=0;i<a;i++)c+=String.fromCharCode(l>>>i*8&255);return c}}if(I[0]!==0)return t;if(I[1]===B[E.NULL])return null;if(I[1]!==B[E.UNDEF])return I[1]===B[E.FALSE]?!1:I[1]===B[E.TRUE]?!0:t},K=(t,e)=>{let a=S(e);return t.mem?t.mem.read(a):W(a)},O=(t,e,a)=>(I[1]=P(t,e),I[0]=a>>>0,M[0]),$=t=>(M[0]=t,I[0]),ee=t=>(M[0]=t,X(I[1])),v=t=>(M[0]=t,Y(I[1])),q={Int8Array:[0,1,"getInt8","setInt8"],Uint8Array:[1,1,"getUint8","setUint8"],Int16Array:[2,2,"getInt16","setInt16"],Uint16Array:[3,2,"getUint16","setUint16"],Int32Array:[4,4,"getInt32","setInt32"],Uint32Array:[5,4,"getUint32","setUint32"],Float32Array:[6,4,"getFloat32","setFloat32"],Float64Array:[7,8,"getFloat64","setFloat64"]},te=Object.values(q),H=new WeakSet,z=t=>{if(t instanceof WebAssembly.Memory&&H.has(t))return t;if(!t||typeof t=="object"&&!(t instanceof WebAssembly.Memory)&&!t.instance&&!t.exports&&!t.memory){let r=new WebAssembly.Memory({initial:t?.initial||1,...t?.maximum?{maximum:t.maximum}:{},...t?.shared?{shared:t.shared}:{}});return z(r)}let e,a,l,c;if(t instanceof WebAssembly.Memory)e=t,a=null,l=null,c=null;else{let r=t?.instance?.exports||t?.exports||t;if(e=t?.exports?.memory||r.memory,!e)return{read:W,wrapVal:R,scalar:!0};a={...r,memory:e},l=t.extMap||null,c=t.module||null}let i=()=>new DataView(e.buffer),{alloc:p,reset:A,initHeapPtr:g}=pe(e,a?.__heap),d=a?._alloc||p;g();let h=(r,n,m)=>{let s=d(16+m),o=i();return o.setBigInt64(s,0n,!0),o.setInt32(s+8,r,!0),o.setInt32(s+12,n,!0),s+16},_=e.schemas||[],T=c&&G(c,"jz:schema");if(T){let r=ye(T),n=()=>{let o=r.u8();return o===0?null:o===1?[null,n()]:r.str(r.varint())},m=r.varint(),s=[];for(let o=0;o<m;o++){let f=r.varint(),u=[];for(let y=0;y<f;y++)u.push(n());s.push(u)}for(let o of s){let f=o.join(",");_.some(u=>u.join(",")===f)||_.push(o)}}if(H.has(e))return e.schemas=_,a?._alloc&&(d=a._alloc,e.alloc=d),e.reset=A,l&&(e._extMap=l),e;e.schemas=_,e._extMap=l,e.Array=r=>{let n=r.length,m=h(n,n,n*8),s=new BigInt64Array(n);for(let f=0;f<n;f++)s[f]=j(e.wrapVal(r[f]));let o=new BigInt64Array(e.buffer,m,n);for(let f=0;f<n;f++)o[f]=s[f];return O(1,0,m)},e.String=r=>{if(r.length<=4&&/^[\x00-\x7f]*$/.test(r)){let u=0;for(let y=0;y<r.length;y++)u|=r.charCodeAt(y)<<y*8;return O(4,k.SSO_BIT|r.length,u)}let n=J.encode(r),m=n.length,s=d(4+m),o=i();o.setInt32(s,m,!0);let f=s+4;return n.forEach((u,y)=>o.setUint8(f+y,u)),O(4,0,f)},e.Buffer=r=>{let n=r instanceof ArrayBuffer?new Uint8Array(r):ArrayBuffer.isView(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):new Uint8Array(r),m=n.length,s=h(m,m,m);return new Uint8Array(e.buffer).set(n,s),O(2,0,s)},e.wrapVal=function(r){if(r==null)return R(r);if(typeof r=="number"||typeof r=="boolean")return Number(r);if(typeof r=="string")return e.String(r);if(typeof r=="bigint")return e.String(r.toString());if(Array.isArray(r))return e.Array(r);if(r instanceof ArrayBuffer)return e.Buffer(r);if(r instanceof DataView)return e.Buffer(r.buffer);let n=r?.constructor?.name;return n&&q[n]?e[n](r):typeof r=="object"||typeof r=="function"?e.External(r):V},e.External=function(r){if(r==null)return R(r);let n=e._extMap;if(!n)return V;let m=n.indexOf(r);return m===-1&&(m=n.length,n.push(r)),O(11,0,m)},e.Object=function(r){let n=Object.keys(r),m=n.join(","),s=e.schemas,o=s.findIndex(b=>b.join(",")===m);if(o===-1){let b=s.reduce((w,D,ae)=>D.length===n.length&&n.every(ce=>D.includes(ce))?w.concat(ae):w,[]);if(b.length===1)o=b[0];else{if(b.length>1)throw Error(`Ambiguous schema for {${m}} \u2014 pass keys in schema order`);if(e._extMap)return e.External(r);throw Error(`No schema for {${m}}`)}}let f=s[o],u=f.length,y=d(u*8),x=new BigInt64Array(u);for(let b=0;b<u;b++){let w=r[f[b]];w==null?w=R(w):typeof w=="string"?w=e.String(w):Array.isArray(w)&&(w=e.Array(w)),x[b]=j(w)}let F=new BigInt64Array(e.buffer,y,u);for(let b=0;b<u;b++)F[b]=x[b];return O(6,o,y)},e.read=function(r){if(Array.isArray(r))return r.map(o=>e.read(o));if(r===r)return r;let n=ee(r),m=v(r),s=$(r);if(n===0&&s===0){if(m===1)return null;if(m===2)return;if(m===4)return!1;if(m===5)return!0}if(n===11&&e._extMap)return e._extMap[s];if(n===1){let o=i(),f=s;for(;o.getInt32(f-4,!0)===-1;)f=o.getInt32(f-8,!0);let u=o.getInt32(f-8,!0),y=new Array(u);for(let x=0;x<u;x++)y[x]=e.read(o.getFloat64(f+x*8,!0));return y}if(n===3){let o=v(r),f=o&7,[,u]=te[f],y=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][f],x=i();if(o&8){let b=x.getInt32(s,!0),w=x.getInt32(s+4,!0);return new y(e.buffer,w,b/u)}let F=x.getInt32(s-8,!0);return new y(e.buffer,s,F/u)}if(n===2){let o=i().getInt32(s-8,!0),f=new ArrayBuffer(o);return new Uint8Array(f).set(new Uint8Array(e.buffer,s,o)),f}if(n===4){let o=v(r);if(o&k.SSO_BIT){let u=o&7,y="";for(let x=0;x<u;x++)y+=String.fromCharCode(s>>>x*8&255);return y}let f=i().getInt32(s-4,!0);return le.decode(new Uint8Array(e.buffer,s,f))}if(n===6){let o=i(),f=v(r),u=e.schemas[f];if(!u)return r;let y={};for(let x=0;x<u.length;x++)y[u[x]]=e.read(o.getFloat64(s+x*8,!0));return y}if(n===7){let o=i(),f=o.getInt32(s-8,!0),u=o.getInt32(s-4,!0),y={};for(let x=0,F=0;x<u&&F<f;x++)if(o.getFloat64(s+x*24,!0)!==0){let w=e.read(o.getFloat64(s+x*24+8,!0));y[w]=e.read(o.getFloat64(s+x*24+16,!0)),F++}return y}if(n===8){let o=i(),f=o.getInt32(s-8,!0),u=o.getInt32(s-4,!0),y=new Set;for(let x=0;x<u&&y.size<f;x++)o.getFloat64(s+x*16,!0)!==0&&y.add(e.read(o.getFloat64(s+x*16+8,!0)));return y}if(n===9){let o=i(),f=o.getInt32(s-8,!0),u=o.getInt32(s-4,!0),y=new Map;for(let x=0;x<u&&y.size<f;x++)o.getFloat64(s+x*24,!0)!==0&&y.set(e.read(o.getFloat64(s+x*24+8,!0)),e.read(o.getFloat64(s+x*24+16,!0)));return y}return r},e.write=function(r,n){let m=ee(r),s=$(r),o=i();if(m===1){let f=o.getInt32(s-4,!0);if(n.length>f)throw Error(`write: ${n.length} exceeds capacity ${f}`);o.setInt32(s-8,n.length,!0);for(let u=0;u<n.length;u++)o.setFloat64(s+u*8,R(n[u]),!0)}else if(m===3){let f=v(r),u=f&7,[,y,,x]=te[u],F=n.length*y;if(f&8){let b=o.getInt32(s,!0),w=o.getInt32(s+4,!0);if(F>b)throw Error(`write: ${F} bytes exceeds view size ${b}`);for(let D=0;D<n.length;D++)o[x](w+D*y,n[D],!0)}else{let b=o.getInt32(s-4,!0);if(F>b)throw Error(`write: ${F} bytes exceeds capacity ${b}`);o.setInt32(s-8,F,!0);for(let w=0;w<n.length;w++)o[x](s+w*y,n[w],!0)}}else if(m===6){let f=e.schemas[v(r)];if(!f)throw Error("write: unknown schema");for(let u of Object.keys(n)){let y=f.indexOf(u);y>=0&&o.setFloat64(s+y*8,R(n[u]),!0)}}else throw Error(`write: unsupported type ${m}`)},e.alloc=d,e.reset=A;let U=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];for(let[r,[n,m,,s]]of Object.entries(q))e[r]=o=>{let f=o.length,u=f*m,y=h(u,u,u);if(m>=2&&U[n]&&o instanceof U[n])new U[n](e.buffer,y,f).set(o);else{let x=i();for(let F=0;F<f;F++)x[s](y+F*m,o[F],!0)}return O(3,n,y)};return H.add(e),e},Ae=(t,e)=>{let a=new Map,l=e?t:t.module||t,c=e||t.instance||t,i=new TextDecoder,p=G(l,"jz:rest");if(p)try{for(let n of JSON.parse(i.decode(p)))a.set(typeof n=="string"?n:n.name,typeof n=="string"?0:n.fixed)}catch{}let A=new Map,g=G(l,"jz:extparam");if(g)try{for(let n of JSON.parse(i.decode(g))){let m=new Set(n.p);n.d&&(m.def=new Map(Object.entries(n.d).map(([s,o])=>[Number(s),o]))),A.set(n.name,m)}}catch{}let d=z(t),h=c.exports.__jz_last_err_bits,_=n=>{if(!(n instanceof WebAssembly.Exception)||!h)throw n;let m=h.value;I[0]=Number(m&0xffffffffn),I[1]=Number(m>>32n&0xffffffffn);let s=d?d.read(M[0]):W(M[0]);if(s instanceof Error)throw s;let o=new Error(typeof s=="string"?s:String(s));throw o.cause=n,o.thrown=s,o},T={},U=(n,m,s,o)=>n?.has(m)?s===void 0&&n.def?.has(m)?n.def.get(m):s:o(s);if(!d||d.scalar){for(let[n,m]of Object.entries(c.exports)){if(typeof m!="function"){T[n]=m;continue}let s=A.get(n),o=m.length;T[n]=(...f)=>{for(;f.length<o;)f.push(void 0);try{return W(m(...f.map((u,y)=>U(s,y,u,R))))}catch(u){_(u)}}}return T}let r=d.wrapVal.bind(d);for(let[n,m]of Object.entries(c.exports))if(a.has(n)&&typeof m=="function"){let s=a.get(n),o=A.get(n);T[n]=(...f)=>{let u=f.slice(0,s).map((y,x)=>U(o,x,y,r));for(;u.length<s;)u.push(V);u.push(d.Array(f.slice(s)));try{return d.read(m.apply(null,u))}catch(y){_(y)}}}else if(typeof m=="function"){let s=A.get(n),o=m.length;T[n]=(...f)=>{for(;f.length<o;)f.push(void 0);try{return d.read(m.apply(null,f.map((u,y)=>U(s,y,u,r))))}catch(u){_(u)}}}else T[n]=m;return T},xe=t=>{let e={extMap:[null],mem:null};return t._interp=t._interp||{},t._interp.__ext_prop=(a,l)=>{let c=S(a),i=S(l),p=e.extMap[$(c)],A=e.mem.read(i);return j(e.mem.wrapVal(typeof p[A]=="function"?p[A].bind(p):p[A]))},t._interp.__ext_has=(a,l)=>e.mem.read(S(l))in e.extMap[$(S(a))]?1:0,t._interp.__ext_set=(a,l,c)=>(e.extMap[$(S(a))][e.mem.read(S(l))]=e.mem.read(S(c)),1),t._interp.__ext_call=(a,l,c)=>{let i=e.extMap[$(S(a))],p=e.mem.read(S(l)),A=e.mem.read(S(c));return j(e.mem.wrapVal(i[p].apply(i,A)))},e},ge=(t,e,a)=>{let l=me(t);if(l.size){if(e.env||(e.env={}),l.has("print")&&!e.env.print){let c=["","",""],i=[],p=g=>{(g===2?console.error:console.log)(c[g]),c[g]=""},A=(g,d,h)=>{let _=K(a,g);c[d]+=String(_),h===32?c[d]+=" ":h===10&&p(d)};e.env.print=(g,d,h)=>{a.mem?A(g,d,h):i.push([g,d,h])},a.flushPrint=()=>{for(let g of i)A(...g);i.length=0}}if(l.has("now")&&!e.env.now&&(e.env.now=c=>c===1&&typeof performance<"u"?performance.now():Date.now()),l.has("rngSeed")&&!e.env.rngSeed&&(e.env.rngSeed=()=>{let c=new Uint32Array(1);return globalThis.crypto?.getRandomValues?globalThis.crypto.getRandomValues(c):c[0]=Math.random()*4294967296>>>0,c[0]|0}),l.has("parseFloat")&&!e.env.parseFloat&&(e.env.parseFloat=c=>{let i=K(a,c);return parseFloat(i)}),l.has("parseInt")&&!e.env.parseInt&&(e.env.parseInt=(c,i)=>{let p=K(a,c);return parseInt(p,i||void 0)}),l.has("setTimeout")||l.has("clearTimeout")){let c=new Map,i=1;l.has("setTimeout")&&!e.env.setTimeout&&(e.env.setTimeout=(p,A,g)=>{let d=i++,h=()=>a.invoke?.(p);if(g){let _=setInterval(h,A);c.set(d,()=>clearInterval(_))}else{let _=setTimeout(()=>{c.delete(d),h()},A);c.set(d,()=>clearTimeout(_))}return d}),l.has("clearTimeout")&&!e.env.clearTimeout&&(e.env.clearTimeout=p=>{let A=c.get(p);return A&&(A(),c.delete(p)),0})}}},ne={length:t=>t.length,charCodeAt:(t,e)=>t.charCodeAt(e)},re=!1,C=!1,ie=()=>{if(re)return C;re=!0;try{let t=new Uint8Array([0,97,115,109,1,0,0,0,1,6,1,96,1,111,1,127,2,24,1,15,...J.encode("wasm:js-string"),6,...J.encode("length"),0,0]),e=new WebAssembly.Module(t,{builtins:["js-string"]});new WebAssembly.Instance(e,{}),C=!0}catch{C=!1}return C},he=(t,e,a)=>{let{needsWasi:l,wasiImports:c}=ue(t,e),i=c||{};if(e._interp&&(i.env={...i.env,...e._interp}),!ie())for(let p of WebAssembly.Module.imports(t))p.module==="wasm:js-string"&&ne[p.name]&&(i["wasm:js-string"]||(i["wasm:js-string"]={}),i["wasm:js-string"][p.name]=ne[p.name]);if(e.imports)for(let[p,A]of Object.entries(e.imports)){i[p]||(i[p]={});for(let g of Object.getOwnPropertyNames(A)){let d=A[g],h=typeof d=="function"?d:d&&typeof d=="object"?d.fn:null;typeof h=="function"&&(i[p][g]=(..._)=>{let T=_.map(r=>{let n=typeof r=="bigint"?S(r):r;return a.mem?a.mem.read(n):W(n)}),U=h.call(A,...T);return j(a.mem?a.mem.wrapVal(U):R(U))})}}ge(t,i,a),e.memory instanceof WebAssembly.Memory&&(H.has(e.memory)||(e.memory=z(e.memory)),i.env||(i.env={}),i.env.memory=e.memory);for(let p of WebAssembly.Module.imports(t))if(p.kind==="global"&&p.module==="env"){let A=globalThis[p.name];if(A!==void 0){i.env||(i.env={});let g=a.extMap.indexOf(A);g===-1&&(g=a.extMap.length,a.extMap.push(A)),i.env[p.name]=new WebAssembly.Global({value:"i64",mutable:!1},j(O(11,0,g)))}}return{imports:i,needsWasi:l}},we=(t,e,a,l,c,i)=>{l&&a._setMemory(e.exports.memory),i.invoke=e.exports.__invoke_closure||null,Z(e);let p=c.memory instanceof WebAssembly.Memory?c.memory:e.exports.memory,A={module:t,instance:e,exports:{...e.exports,memory:p},extMap:i.extMap},g=z(A);return i.mem=g,i.flushPrint?.(),{exports:Ae(A),memory:g?.scalar?null:g,instance:e,module:t}},_e=t=>{if(t instanceof WebAssembly.Module)return t;if(ie())try{return new WebAssembly.Module(t,{builtins:["js-string"]})}catch{return new WebAssembly.Module(t)}return new WebAssembly.Module(t)},Me=(t,e={})=>{let a=xe(e),l=_e(t),{imports:c,needsWasi:i}=he(l,e,a),p=Object.keys(c).some(g=>g!=="_setMemory"),A=new WebAssembly.Instance(l,p?c:void 0);return we(l,A,c,i,e,a)};export{Ue as FALSE_NAN,de as NULL_NAN,Se as TRUE_NAN,V as UNDEF_NAN,v as aux,R as coerce,j as f64ToI64,S as i64ToF64,Me as instantiate,z as memory,$ as offset,O as ptr,_e as toModule,ee as type,Ae as wrap};
1
+ var ge=new TextDecoder;function ne(t={}){let e=null,a=(i,f)=>{let m=i===1?globalThis.process?.stdout:globalThis.process?.stderr;if(m&&typeof m.write=="function")try{m.write(f);return}catch{}let d=f.replace(/\n$/,"");(i===1?console.log:console.warn)(d)},u=t.write||a;return{wasi_snapshot_preview1:{fd_read(i,f,m,d){let x=new DataView(e.buffer),A=0;for(let h=0;h<m;h++){let _=x.getUint32(f+h*8,!0),S=x.getUint32(f+h*8+4,!0),E=new Uint8Array(e.buffer,_,S);A+=t.read&&t.read(i,E)||0}return x.setUint32(d,A,!0),0},fd_write(i,f,m,d){let x=new DataView(e.buffer),A=0;for(let h=0;h<m;h++){let _=x.getUint32(f+h*8,!0),S=x.getUint32(f+h*8+4,!0);u(i,ge.decode(new Uint8Array(e.buffer,_,S))),A+=S}return x.setUint32(d,A,!0),0},clock_time_get(i,f,m){let d=new DataView(e.buffer),x=BigInt(Math.round(i===0?Date.now()*1e6:performance.now()*1e6));return d.setBigInt64(m,x,!0),0},random_get(i,f){let m=new Uint8Array(e.buffer,i,f);if(globalThis.crypto?.getRandomValues)globalThis.crypto.getRandomValues(m);else for(let d=0;d<f;d++)m[d]=Math.random()*256|0;return 0},proc_exit(){},environ_sizes_get(i,f){let m=new DataView(e.buffer);return m.setUint32(i,0,!0),m.setUint32(f,0,!0),0},environ_get(){return 0}},_setMemory(i){e=i}}}var re=t=>{if(!t.exports.__timer_tick)return;let e=t.exports.__timer_tick,a=!1,u=setInterval(()=>{let i=e();i>0&&(a=!0),a&&i<=0&&clearInterval(u)},1)};var N={PTR_ADDR:1020,START:1024},T={TAG_SHIFT:47,TAG_MASK:15,AUX_SHIFT:32,AUX_MASK:32767,OFFSET_MASK:4294967295,NAN_PREFIX:32760,NAN_PREFIX_BITS:0x7FF8000000000000n,SSO_BIT:16384,SLICE_BIT:8192,SLICE_LEN_MASK:8191},U={ATOM:0,ARRAY:1,BUFFER:2,TYPED:3,STRING:4,OBJECT:6,HASH:7,SET:8,MAP:9,CLOSURE:10,EXTERNAL:11},B={NULL:1,UNDEF:2,FALSE:4,TRUE:5},Ne=1<<U.ARRAY|1<<U.HASH|1<<U.SET|1<<U.MAP,Oe=BigInt(T.TAG_SHIFT),Re=BigInt(T.TAG_MASK),Le=BigInt(T.AUX_SHIFT),De=BigInt(T.AUX_MASK),Pe=BigInt(T.OFFSET_MASK);var P=(t,e)=>(T.NAN_PREFIX<<16|(t&T.TAG_MASK)<<T.TAG_SHIFT-32|e&T.AUX_MASK)>>>0,oe=t=>t>>>T.TAG_SHIFT-32&T.TAG_MASK,J=t=>t&T.AUX_MASK;var W={[B.NULL]:P(U.ATOM,B.NULL),[B.UNDEF]:P(U.ATOM,B.UNDEF),[B.FALSE]:P(U.ATOM,B.FALSE),[B.TRUE]:P(U.ATOM,B.TRUE)};var Q=new TextEncoder,Ae=new TextDecoder,de=(t,e)=>{let a=WebAssembly.Module.imports(t).some(u=>u.module==="wasi_snapshot_preview1");return{needsWasi:a,wasiImports:a?ne(e):null}},xe=t=>new Set(WebAssembly.Module.imports(t).filter(e=>e.module==="env"&&e.kind==="function").map(e=>e.name)),Ie=(t,e)=>{let a=()=>new DataView(t.buffer),u=e?()=>e.value:()=>a().getInt32(N.PTR_ADDR,!0),i=e?A=>{e.value=A}:A=>a().setInt32(N.PTR_ADDR,A,!0),f=e?e.value:N.START;return{alloc:A=>{let h=u()+7&-8,_=h+A;return _>t.buffer.byteLength&&t.grow(Math.ceil((_-t.buffer.byteLength)/65536)),i(_),h},reset:()=>i(f),initHeapPtr:()=>{if(e)return;let A=a();A.getInt32(N.PTR_ADDR,!0)<N.START&&A.setInt32(N.PTR_ADDR,N.START,!0)}}},V=(t,e)=>{let a=WebAssembly.Module.customSections(t,e);return a.length?new Uint8Array(a[0]):null},we=t=>{let e=new TextDecoder,a=0;return{pos:()=>a,seek:u=>{a=u},eof:()=>a>=t.length,u8:()=>t[a++],varint:()=>{let u=0,i=0;for(;;){let f=t[a++];if(u|=(f&127)<<i,!(f&128))return u;i+=7}},str:u=>{let i=e.decode(t.subarray(a,a+u));return a+=u,i},bytes:u=>{let i=t.subarray(a,a+u);return a+=u,i}}},H=0xffffffffn,ae=new ArrayBuffer(8),z=new Uint32Array(ae),fe=new Float64Array(ae),C=t=>(fe[0]=t,BigInt(z[1])<<32n|BigInt(z[0]>>>0)),D=t=>(z[0]=Number(t&H),z[1]=Number(t>>32n&H),fe[0]),Y=t=>Number(t>>32n&H),Z=t=>(Y(t)&2146959360)===2146959360,R=t=>typeof t=="bigint"?t:C(t),le=BigInt(W[B.NULL])<<32n,$=BigInt(W[B.UNDEF])<<32n,he=BigInt(W[B.FALSE])<<32n,_e=BigInt(W[B.TRUE])<<32n,O=t=>t===null?le:t===void 0?$:t,be=t=>{let e=0n;for(let a=0;a<t.length;a++)e|=BigInt(t.charCodeAt(a))<<BigInt(a*7);return e|=BigInt(t.length)<<42n,M(4,Number(e>>32n)|T.SSO_BIT,Number(e&0xFFFFFFFFn))},te=t=>typeof t=="bigint"?t:C(t),M=(t,e,a)=>BigInt(P(t,e))<<32n|BigInt(a>>>0),L=t=>Number(te(t)&H),ee=t=>oe(Y(te(t))),v=t=>J(Y(te(t))),ue=t=>{let e=J(Y(t)),a=e>>>10&7,u=BigInt(e)<<32n|BigInt(Number(t&H)),i="";for(let f=0;f<a;f++)i+=String.fromCharCode(Number(u>>BigInt(f*7)&0x7fn));return i},j=t=>{if(Array.isArray(t))return t.map(j);if(typeof t=="number"){if(t===t)return t;t=C(t)}else if(typeof t!="bigint")return t;if(!Z(t))return D(t);if(ee(t)===4&&v(t)&T.SSO_BIT)return ue(t);if(L(t)===0){if(t===le)return null;if(t===$)return;if(t===he)return!1;if(t===_e)return!0}return D(t)},q=(t,e)=>t.mem?t.mem.read(e):j(e),X={Int8Array:[0,1,"getInt8","setInt8"],Uint8Array:[1,1,"getUint8","setUint8"],Int16Array:[2,2,"getInt16","setInt16"],Uint16Array:[3,2,"getUint16","setUint16"],Int32Array:[4,4,"getInt32","setInt32"],Uint32Array:[5,4,"getUint32","setUint32"],Float32Array:[6,4,"getFloat32","setFloat32"],Float64Array:[7,8,"getFloat64","setFloat64"]},se=Object.values(X),K=new WeakSet,G=t=>{if(t instanceof WebAssembly.Memory&&K.has(t))return t;if(!t||typeof t=="object"&&!(t instanceof WebAssembly.Memory)&&!t.instance&&!t.exports&&!t.memory){let r=new WebAssembly.Memory({initial:t?.initial||1,...t?.maximum?{maximum:t.maximum}:{},...t?.shared?{shared:t.shared}:{}});return G(r)}let e,a,u,i;if(t instanceof WebAssembly.Memory)e=t,a=null,u=null,i=null;else{let r=t?.instance?.exports||t?.exports||t;if(e=t?.exports?.memory||r.memory,!e)return{read:j,wrapVal:O,scalar:!0};a={...r,memory:e},u=t.extMap||null,i=t.module||null}let f=()=>new DataView(e.buffer),{alloc:m,reset:d,initHeapPtr:x}=Ie(e,a?.__heap),A=a?._alloc||m;x();let h=(r,s,p)=>{let y=A(16+p),n=f();return n.setBigInt64(y,0n,!0),n.setInt32(y+8,r,!0),n.setInt32(y+12,s,!0),y+16},_=e.schemas||[],S=i&&V(i,"jz:schema");if(S){let r=we(S),s=()=>{let n=r.u8();return n===0?null:n===1?[null,s()]:r.str(r.varint())},p=r.varint(),y=[];for(let n=0;n<p;n++){let o=r.varint(),c=[];for(let l=0;l<o;l++)c.push(s());y.push(c)}for(let n of y){let o=n.join(",");_.some(c=>c.join(",")===o)||_.push(n)}}if(K.has(e))return e.schemas=_,a?._alloc&&(A=a._alloc,e.alloc=A),e.reset=d,u&&(e._extMap=u),e;e.schemas=_,e._extMap=u,e.Array=r=>{let s=r.length,p=h(s,s,s*8),y=new BigInt64Array(s);for(let o=0;o<s;o++)y[o]=R(e.wrapVal(r[o]));let n=new BigInt64Array(e.buffer,p,s);for(let o=0;o<s;o++)n[o]=y[o];return M(1,0,p)},e.String=r=>{if(r.length<=6&&/^[\x00-\x7f]*$/.test(r)){let c=0n;for(let l=0;l<r.length;l++)c|=BigInt(r.charCodeAt(l))<<BigInt(l*7);return c|=BigInt(r.length)<<42n,M(4,Number(c>>32n)|T.SSO_BIT,Number(c&0xFFFFFFFFn))}let s=Q.encode(r),p=s.length,y=A(4+p),n=f();n.setInt32(y,p,!0);let o=y+4;return s.forEach((c,l)=>n.setUint8(o+l,c)),M(4,0,o)},e.Buffer=r=>{let s=r instanceof ArrayBuffer?new Uint8Array(r):ArrayBuffer.isView(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):new Uint8Array(r),p=s.length,y=h(p,p,p);return new Uint8Array(e.buffer).set(s,y),M(2,0,y)},e.wrapVal=function(r){if(r==null)return O(r);if(typeof r=="number"||typeof r=="boolean")return Number(r);if(typeof r=="string")return e.String(r);if(typeof r=="bigint")return Z(r)?r:e.String(r.toString());if(Array.isArray(r))return e.Array(r);if(r instanceof ArrayBuffer)return e.Buffer(r);if(r instanceof DataView)return e.Buffer(r.buffer);let s=r?.constructor?.name;return s&&X[s]?e[s](r):typeof r=="object"||typeof r=="function"?e.External(r):$},e.External=function(r){if(r==null)return O(r);let s=e._extMap;if(!s)return $;let p=s.indexOf(r);return p===-1&&(p=s.length,s.push(r)),M(11,0,p)},e.Object=function(r){let s=Object.keys(r),p=s.join(","),y=e.schemas,n=y.findIndex(I=>I.join(",")===p);if(n===-1){let I=y.reduce((b,F,pe)=>F.length===s.length&&s.every(ye=>F.includes(ye))?b.concat(pe):b,[]);if(I.length===1)n=I[0];else{if(I.length>1)throw Error(`Ambiguous schema for {${p}} \u2014 pass keys in schema order`);if(e._extMap)return e.External(r);throw Error(`No schema for {${p}}`)}}let o=y[n],c=o.length,l=A(c*8),g=new BigInt64Array(c);for(let I=0;I<c;I++){let b=r[o[I]];b==null?b=O(b):typeof b=="string"?b=e.String(b):Array.isArray(b)&&(b=e.Array(b)),g[I]=R(b)}let w=new BigInt64Array(e.buffer,l,c);for(let I=0;I<c;I++)w[I]=g[I];return M(6,n,l)},e.read=function(r){if(Array.isArray(r))return r.map(o=>e.read(o));if(typeof r=="number"){if(r===r)return r;r=C(r)}else if(typeof r!="bigint")return r;if(!Z(r))return D(r);let s=f(),p=ee(r),y=v(r),n=L(r);if(p===0&&n===0){if(y===1)return null;if(y===2)return;if(y===4)return!1;if(y===5)return!0}if(p===11&&e._extMap)return e._extMap[n];if(p===1){let o=n;for(;s.getInt32(o-4,!0)===-1;)o=s.getInt32(o-8,!0);let c=s.getInt32(o-8,!0),l=new Array(c);for(let g=0;g<c;g++)l[g]=e.read(s.getBigInt64(o+g*8,!0));return l}if(p===3){let o=y&7,[,c]=se[o],l=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][o];if(y&8){let w=s.getInt32(n,!0),I=s.getInt32(n+4,!0);return new l(e.buffer,I,w/c)}let g=s.getInt32(n-8,!0);return new l(e.buffer,n,g/c)}if(p===2){let o=s.getInt32(n-8,!0),c=new ArrayBuffer(o);return new Uint8Array(c).set(new Uint8Array(e.buffer,n,o)),c}if(p===4){if(y&T.SSO_BIT)return ue(r);let o=s.getInt32(n-4,!0);return Ae.decode(new Uint8Array(e.buffer,n,o))}if(p===6){let o=e.schemas[y];if(!o)return r;let c={};for(let l=0;l<o.length;l++)c[o[l]]=e.read(s.getBigInt64(n+l*8,!0));return c}if(p===7){let o=s.getInt32(n-8,!0),c=s.getInt32(n-4,!0),l={};for(let g=0,w=0;g<c&&w<o;g++)s.getBigInt64(n+g*24,!0)!==0n&&(l[e.read(s.getBigInt64(n+g*24+8,!0))]=e.read(s.getBigInt64(n+g*24+16,!0)),w++);return l}if(p===8){let o=s.getInt32(n-8,!0),c=s.getInt32(n-4,!0),l=new Set;for(let g=0;g<c&&l.size<o;g++)s.getBigInt64(n+g*16,!0)!==0n&&l.add(e.read(s.getBigInt64(n+g*16+8,!0)));return l}if(p===9){let o=s.getInt32(n-8,!0),c=s.getInt32(n-4,!0),l=new Map;for(let g=0;g<c&&l.size<o;g++)s.getBigInt64(n+g*24,!0)!==0n&&l.set(e.read(s.getBigInt64(n+g*24+8,!0)),e.read(s.getBigInt64(n+g*24+16,!0)));return l}return D(r)},e.write=function(r,s){let p=ee(r),y=L(r),n=f();if(p===1){let o=n.getInt32(y-4,!0);if(s.length>o)throw Error(`write: ${s.length} exceeds capacity ${o}`);n.setInt32(y-8,s.length,!0);for(let c=0;c<s.length;c++)n.setBigInt64(y+c*8,R(O(s[c])),!0)}else if(p===3){let o=v(r),c=o&7,[,l,,g]=se[c],w=s.length*l;if(o&8){let I=n.getInt32(y,!0),b=n.getInt32(y+4,!0);if(w>I)throw Error(`write: ${w} bytes exceeds view size ${I}`);for(let F=0;F<s.length;F++)n[g](b+F*l,s[F],!0)}else{let I=n.getInt32(y-4,!0);if(w>I)throw Error(`write: ${w} bytes exceeds capacity ${I}`);n.setInt32(y-8,w,!0);for(let b=0;b<s.length;b++)n[g](y+b*l,s[b],!0)}}else if(p===6){let o=e.schemas[v(r)];if(!o)throw Error("write: unknown schema");for(let c of Object.keys(s)){let l=o.indexOf(c);l>=0&&n.setBigInt64(y+l*8,R(O(s[c])),!0)}}else throw Error(`write: unsupported type ${p}`)},e.alloc=A,e.reset=d;let E=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];for(let[r,[s,p,,y]]of Object.entries(X))e[r]=n=>{let o=n.length,c=o*p,l=h(c,c,c);if(E[s]&&n instanceof E[s])new E[s](e.buffer,l,o).set(n);else{let g=f();for(let w=0;w<o;w++)g[y](l+w*p,n[w],!0)}return M(3,s,l)};return e.allocTyped=(r,s)=>{let p=X[r?.name];if(!p)throw Error(`allocTyped: unsupported type ${r?.name??r}`);let[y,n]=p,o=s*n,c=h(o,o,o);return{view:new r(e.buffer,c,s),box:M(3,y,c)}},K.add(e),e},Te=(t,e)=>{let a=new Map,u=e?t:t.module||t,i=e||t.instance||t,f=new TextDecoder,m=V(u,"jz:rest");if(m)try{for(let n of JSON.parse(f.decode(m)))a.set(typeof n=="string"?n:n.name,typeof n=="string"?0:n.fixed)}catch{}let d=new Map,x=V(u,"jz:extparam");if(x)try{for(let n of JSON.parse(f.decode(x))){let o=new Set(n.p);n.d&&(o.def=new Map(Object.entries(n.d).map(([c,l])=>[Number(c),l]))),d.set(n.name,o)}}catch{}let A=new Map,h=V(u,"jz:i64exp");if(h)try{for(let n of JSON.parse(f.decode(h)))A.set(n.name,{p:new Set(n.p||[]),r:!!n.r})}catch{}let _=G(t),S=i.exports.__jz_last_err_bits,E=n=>{if(!(n instanceof WebAssembly.Exception)||!S)throw n;let o=S.value,c=_?_.read(o):j(o);if(c instanceof Error)throw c;let l=new Error(typeof c=="string"?c:String(c));throw l.cause=n,l.thrown=c,l},r={},s=(n,o,c,l)=>n?.has(o)?c===void 0&&n.def?.has(o)?n.def.get(o):c:l(c),p=(n,o,c)=>(l,g)=>{let w=s(o,g,l,c);if(n&&n.p.has(g)){if(typeof w=="string"){if(w.length>6||!/^[\x00-\x7f]*$/.test(w))throw new Error("jz: string arg too long or non-ASCII for memoryless module \u2014 compile with a string operation to enable heap marshaling");return be(w)}return R(w)}return typeof w=="bigint"?D(w):w};if(!_||_.scalar){for(let[n,o]of Object.entries(i.exports)){if(typeof o!="function"){r[n]=o;continue}let c=d.get(n),l=A.get(n),g=o.length;r[n]=(...w)=>{for(;w.length<g;)w.push(void 0);try{let I=o(...w.map(p(l,c,O)));return typeof I=="bigint"&&!(l&&l.r)?I:j(I)}catch(I){E(I)}}}return r}let y=_.wrapVal.bind(_);for(let[n,o]of Object.entries(i.exports))if(a.has(n)&&typeof o=="function"){let c=a.get(n),l=d.get(n),g=A.get(n);r[n]=(...w)=>{let I=w.slice(0,c).map(p(g,l,y));for(;I.length<c;){let F=I.length;I.push(g&&g.p.has(F)?$:D($))}let b=_.Array(w.slice(c));I.push(g&&g.p.has(c)?b:D(b));try{let F=o.apply(null,I);return typeof F=="bigint"&&!(g&&g.r)?F:_.read(F)}catch(F){E(F)}}}else if(typeof o=="function"){let c=d.get(n),l=A.get(n),g=o.length;r[n]=(...w)=>{for(;w.length<g;)w.push(void 0);try{let I=o.apply(null,w.map(p(l,c,y)));return typeof I=="bigint"&&!(l&&l.r)?I:_.read(I)}catch(I){E(I)}}}else r[n]=o;return r},Fe=t=>{let e={extMap:[null],mem:null};return t._interp=t._interp||{},t._interp.__ext_prop=(a,u)=>{let i=e.extMap[L(a)],f=e.mem.read(u);return R(e.mem.wrapVal(typeof i[f]=="function"?i[f].bind(i):i[f]))},t._interp.__ext_has=(a,u)=>e.mem.read(u)in e.extMap[L(a)]?1:0,t._interp.__ext_set=(a,u,i)=>(e.extMap[L(a)][e.mem.read(u)]=e.mem.read(i),1),t._interp.__ext_call=(a,u,i)=>{let f=e.extMap[L(a)],m=e.mem.read(u),d=e.mem.read(i);return R(e.mem.wrapVal(f[m].apply(f,d)))},e},Be=(t,e,a)=>{let u=xe(t);if(u.size){if(e.env||(e.env={}),u.has("print")&&!e.env.print){let i=["","",""],f=[],m=x=>{(x===2?console.error:console.log)(i[x]),i[x]=""},d=(x,A,h)=>{let _=q(a,x);i[A]+=String(_),h===32?i[A]+=" ":h===10&&m(A)};e.env.print=(x,A,h)=>{a.mem?d(x,A,h):f.push([x,A,h])},a.flushPrint=()=>{for(let x of f)d(...x);f.length=0}}if(u.has("now")&&!e.env.now&&(e.env.now=i=>i===1&&typeof performance<"u"?performance.now():Date.now()),u.has("rngSeed")&&!e.env.rngSeed&&(e.env.rngSeed=()=>{let i=new Uint32Array(1);return globalThis.crypto?.getRandomValues?globalThis.crypto.getRandomValues(i):i[0]=Math.random()*4294967296>>>0,i[0]|0}),u.has("parseFloat")&&!e.env.parseFloat&&(e.env.parseFloat=i=>{let f=q(a,i);return parseFloat(f)}),u.has("parseInt")&&!e.env.parseInt&&(e.env.parseInt=(i,f)=>{let m=q(a,i);return parseInt(m,f||void 0)}),u.has("setTimeout")||u.has("clearTimeout")){let i=new Map,f=1;u.has("setTimeout")&&!e.env.setTimeout&&(e.env.setTimeout=(m,d,x)=>{let A=f++,h=()=>a.invoke?.(m);if(x){let _=setInterval(h,d);i.set(A,()=>clearInterval(_))}else{let _=setTimeout(()=>{i.delete(A),h()},d);i.set(A,()=>clearTimeout(_))}return A}),u.has("clearTimeout")&&!e.env.clearTimeout&&(e.env.clearTimeout=m=>{let d=i.get(m);return d&&(d(),i.delete(m)),0})}}},ie={length:t=>t.length,charCodeAt:(t,e)=>t.charCodeAt(e)},ce=!1,k=!1,me=()=>{if(ce)return k;ce=!0;try{let t=new Uint8Array([0,97,115,109,1,0,0,0,1,6,1,96,1,111,1,127,2,24,1,15,...Q.encode("wasm:js-string"),6,...Q.encode("length"),0,0]),e=new WebAssembly.Module(t,{builtins:["js-string"]});new WebAssembly.Instance(e,{}),k=!0}catch{k=!1}return k},Se=(t,e,a)=>{let{needsWasi:u,wasiImports:i}=de(t,e),f=i||{};if(e._interp&&(f.env={...f.env,...e._interp}),!me())for(let m of WebAssembly.Module.imports(t))m.module==="wasm:js-string"&&ie[m.name]&&(f["wasm:js-string"]||(f["wasm:js-string"]={}),f["wasm:js-string"][m.name]=ie[m.name]);if(e.imports)for(let[m,d]of Object.entries(e.imports)){f[m]||(f[m]={});for(let x of Object.getOwnPropertyNames(d)){let A=d[x],h=typeof A=="function"?A:A&&typeof A=="object"?A.fn:null;typeof h=="function"&&(f[m][x]=(..._)=>{let S=_.map(r=>a.mem?a.mem.read(r):j(r)),E=h.call(d,...S);return R(a.mem?a.mem.wrapVal(E):O(E))})}}Be(t,f,a),e.memory instanceof WebAssembly.Memory&&(K.has(e.memory)||(e.memory=G(e.memory)),f.env||(f.env={}),f.env.memory=e.memory);for(let m of WebAssembly.Module.imports(t))if(m.kind==="global"&&m.module==="env"){let d=globalThis[m.name];if(d!==void 0){f.env||(f.env={});let x=a.extMap.indexOf(d);x===-1&&(x=a.extMap.length,a.extMap.push(d)),f.env[m.name]=new WebAssembly.Global({value:"i64",mutable:!1},M(11,0,x))}}return{imports:f,needsWasi:u}},Ee=(t,e,a,u,i,f)=>{u&&a._setMemory(e.exports.memory),f.invoke=e.exports.__invoke_closure||null,re(e);let m=i.memory instanceof WebAssembly.Memory?i.memory:e.exports.memory,d={module:t,instance:e,exports:{...e.exports,memory:m},extMap:f.extMap},x=G(d);return f.mem=x,f.flushPrint?.(),{exports:Te(d),memory:x?.scalar?null:x,instance:e,module:t}},Me=t=>{if(t instanceof WebAssembly.Module)return t;if(me())try{return new WebAssembly.Module(t,{builtins:["js-string"]})}catch{return new WebAssembly.Module(t)}return new WebAssembly.Module(t)},He=(t,e={})=>{let a=Fe(e),u=Me(t),{imports:i,needsWasi:f}=Se(u,e,a),m=Object.keys(i).some(x=>x!=="_setMemory"),d=new WebAssembly.Instance(u,m?i:void 0);return Ee(u,d,i,f,e,a)};export{he as FALSE_NAN,le as NULL_NAN,_e as TRUE_NAN,$ as UNDEF_NAN,v as aux,O as coerce,C as f64ToI64,D as i64ToF64,He as instantiate,G as memory,L as offset,M as ptr,Me as toModule,ee as type,Te as wrap};