jz 0.9.1 → 0.9.2
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.
- package/README.md +19 -7
- package/bench/bench.svg +20 -20
- package/dist/interop.js +1 -1
- package/dist/jz.js +1642 -1045
- package/interop.js +73 -6
- package/jzify/index.js +7 -1
- package/jzify/transform.js +21 -2
- package/jzify/webrt.js +145 -0
- package/layout.js +13 -3
- package/module/array.js +49 -42
- package/module/collection.js +222 -111
- package/module/console.js +4 -0
- package/module/core.js +86 -7
- package/module/crypto.js +124 -0
- package/module/index.js +3 -1
- package/module/math.js +5 -0
- package/module/navigator.js +26 -0
- package/module/schema.js +11 -3
- package/module/string.js +433 -28
- package/module/timer.js +42 -1
- package/module/typedarray.js +370 -60
- package/package.json +3 -3
- package/src/abi/array.js +24 -16
- package/src/abi/index.js +2 -2
- package/src/abi/object.js +17 -0
- package/src/ast.js +53 -0
- package/src/autoload.js +19 -3
- package/src/compile/analyze.js +190 -21
- package/src/compile/emit-assign.js +111 -7
- package/src/compile/emit.js +84 -20
- package/src/compile/index.js +37 -4
- package/src/compile/inplace-store.js +10 -9
- package/src/compile/narrow.js +71 -1
- package/src/compile/plan/index.js +5 -0
- package/src/compile/plan/literals.js +11 -2
- package/src/ctx.js +14 -0
- package/src/ir.js +26 -1
- package/src/optimize/index.js +1 -0
- package/src/optimize/vectorize.js +80 -6
- package/src/prepare/index.js +6 -0
- package/src/static.js +31 -0
- package/src/type.js +356 -47
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
 [](http://npmjs.org/package/jz) [](https://github.com/dy/jz/actions/workflows/test.yml) [](https://github.com/dy/jz/actions/workflows/bench.yml)
|
|
4
4
|
|
|
5
|
-
**JZ** (_javascript zero_)
|
|
5
|
+
**JZ** (_javascript zero_) compiles the **numeric JavaScript you already test** to fast, GC-free WASM — same source, no type annotations, no runtime.
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
8
|
import jz from 'jz'
|
|
@@ -16,7 +16,11 @@ dist(3, 4) // 5
|
|
|
16
16
|
|
|
17
17
|
## Why?
|
|
18
18
|
|
|
19
|
-
JZ distills **"the good parts"** ([Crockford](https://www.youtube.com/watch?v=_DKkVvOt6dk)) and
|
|
19
|
+
Keep one codebase. JZ distills **"the good parts"** ([Crockford](https://www.youtube.com/watch?v=_DKkVvOt6dk)) and compiles its numeric core ahead-of-time to WASM: no runtime, no GC, no legacy, no spec creep, near-native performance with unlocked SIMD. **Valid JZ is valid JS** — your existing JS tests remain the compiler's tests, and removing JZ leaves the same source and fallback intact.
|
|
20
|
+
|
|
21
|
+
Rust, Go, and C are excellent when a rewrite and a second toolchain make sense. JZ is for the hot path you want to keep in JavaScript — one source, one test suite, a JS fallback, and comparable WASM or native performance.
|
|
22
|
+
|
|
23
|
+
The performance bar is uncompromising: on the published cross-target corpus, JZ is **over 2× faster than V8 and Rust→WASM** by geomean. Every rival win remains visible and is treated as a bug to close, never an exception to hide.
|
|
20
24
|
|
|
21
25
|
| Good for | Not for |
|
|
22
26
|
|------------------------------|---------------------------|
|
|
@@ -27,8 +31,9 @@ JZ distills **"the good parts"** ([Crockford](https://www.youtube.com/watch?v=_D
|
|
|
27
31
|
| Scientific, numeric, ML | Security crypto, big-ints |
|
|
28
32
|
| Hashing, checksums, RNG | Glue, plumbing, orchestration |
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
## Used by
|
|
31
35
|
|
|
36
|
+
[**color-space v3**](https://github.com/colorjs/color-space) uses JZ to build its 27-space [`color-space/wasm`](https://github.com/colorjs/color-space#wasm) backend from valid JavaScript. The published module is precompiled, import-free, and parity-tested against the library's scalar implementation.
|
|
32
37
|
|
|
33
38
|
## Usage
|
|
34
39
|
|
|
@@ -169,8 +174,12 @@ JZ is a **strict modern JS subset**. Built-in jzify transform extends support to
|
|
|
169
174
|
│ │ operators strings booleans numbers arrays objects `${}` │ │
|
|
170
175
|
│ │ Math Number String Array Object JSON RegExp Symbol null │ │
|
|
171
176
|
│ │ ArrayBuffer DataView TypedArray Map Set Atomics │ │
|
|
172
|
-
│ │
|
|
173
|
-
│ │
|
|
177
|
+
│ │ Float16Array Uint8ClampedArray Math.f16round get/setFloat16 │ │
|
|
178
|
+
│ │ parseInt parseFloat encodeURI(Component) Error BigInt │ │
|
|
179
|
+
│ │ Uint8Array.fromBase64/toBase64/fromHex/toHex atob btoa │ │
|
|
180
|
+
│ │ crypto.getRandomValues crypto.randomUUID TextEncoder(Into) │ │
|
|
181
|
+
│ │ console setTimeout/setInterval requestAnimationFrame Date │ │
|
|
182
|
+
│ │ performance navigator.hardwareConcurrency │ │
|
|
174
183
|
│ │ structuredClone groupBy Set algebra iterator helpers │ │
|
|
175
184
|
│ │ fs.read/write (WASI hosts) fetch via async host imports │ │
|
|
176
185
|
│ └────────────────────────────────────────────────────────────────────┘ │
|
|
@@ -179,6 +188,7 @@ JZ is a **strict modern JS subset**. Built-in jzify transform extends support to
|
|
|
179
188
|
│ class new this extends super static #private │
|
|
180
189
|
│ function* yield yield* Foo.prototype.m = … │
|
|
181
190
|
│ async/await async function* for await Promise using │
|
|
191
|
+
│ queueMicrotask URLSearchParams │
|
|
182
192
|
│ Symbol.iterator Symbol.asyncIterator Symbol.dispose │
|
|
183
193
|
│ SharedArrayBuffer (→ ArrayBuffer) │
|
|
184
194
|
│ == != instanceof undefined WeakMap WeakSet │
|
|
@@ -187,7 +197,7 @@ JZ is a **strict modern JS subset**. Built-in jzify transform extends support to
|
|
|
187
197
|
Not supported
|
|
188
198
|
delete getters/setters eval Function with
|
|
189
199
|
Proxy Reflect
|
|
190
|
-
import() DOM
|
|
200
|
+
import() DOM Intl Node APIs
|
|
191
201
|
```
|
|
192
202
|
|
|
193
203
|
|
|
@@ -221,7 +231,9 @@ Each follows one rule: **JZ takes WASM/native conventions over JS edge-cases whe
|
|
|
221
231
|
- **`String(number)` is ES-spec exact** — shortest round-trip digits via a built-in Ryū formatter (`String(0.1 + 0.2)` → `"0.30000000000000004"`, `String(Math.PI)` → `"3.141592653589793"`), including exponential notation and subnormals; its ~9.7 KB power-of-5 table is lazily included only in modules that stringify floats.
|
|
222
232
|
- **Errors are just their message** — a caught error is the value you threw (no `.message`, not `instanceof Error`), and `null.x` yields `undefined` instead of throwing. It keeps `throw` and member reads free of object machinery and per-access checks.
|
|
223
233
|
- **`Date` getters return UTC** (`getHours` ≡ `getUTCHours`) – the IANA timezone database is hundreds of KB.
|
|
224
|
-
- **`Math.random` is seedable** — default draws host entropy; pass `randomSeed: n` for a reproducible stream.
|
|
234
|
+
- **`Math.random` is seedable** — default draws host entropy; pass `randomSeed: n` for a reproducible stream. `crypto.getRandomValues`/`randomUUID` ride the same switch: default entropy mode IS the host CSPRNG (WASI `random_get` / `env.random`), a numeric `randomSeed` makes both deterministic — reproducible sims, explicitly not cryptographic.
|
|
235
|
+
- **Float16Array is exactly rounded** — stores round ties-to-even straight off the f64 value (no f32 double-rounding), `Math.f16round` and `DataView.getFloat16/setFloat16` included; `Uint8ClampedArray` stores are spec `ToUint8Clamp` (round-half-even). Neither kind auto-vectorizes in v1 (conversion is a call, not a lane op).
|
|
236
|
+
- **Web codecs & friends are byte-string exact** — `atob`/`btoa` work on byte-strings (`charCodeAt` reads the byte, so binary-string consumers match JS exactly; non-ASCII text encodes its UTF-8 bytes instead of throwing). `Uint8Array.fromBase64/toBase64/fromHex/toHex` + `setFrom*` follow the ES2026 spec with compile-time-literal options and `lastChunkHandling: 'loose'` (the default; others reject cleanly). `URLSearchParams` is WHATWG-faithful (forgiving decode, form-urlencoded escaping) except: `keys()/values()/entries()` return arrays (iterable, not live iterators), `sort()` compares UTF-8 bytes, and the object itself isn't iterable — iterate `.entries()`. `queueMicrotask` enqueues on the promise runtime's job queue (drains at host boundaries, same granularity as promise jobs). `requestAnimationFrame` binds the host's rAF; hosts without one (Node) fall back to a 16 ms timer with a real timestamp.
|
|
225
237
|
</details>
|
|
226
238
|
|
|
227
239
|
<details>
|
package/bench/bench.svg
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
<line x1="650" y1="38" x2="650" y2="52" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
|
|
7
7
|
<text x="156" y="41" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">native C</text>
|
|
8
8
|
<text x="156" y="56" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">clang -O3 · ref</text>
|
|
9
|
-
<text x="662" y="49" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">0.
|
|
9
|
+
<text x="662" y="49" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">0.79×</text>
|
|
10
10
|
<circle cx="182.0" cy="45" r="8" fill="currentColor" fill-opacity="0.4">
|
|
11
|
-
<animate attributeName="cx" dur="1.
|
|
11
|
+
<animate attributeName="cx" dur="1.267616466803277s" repeatCount="indefinite" calcMode="linear"
|
|
12
12
|
keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-0.00s"/>
|
|
13
13
|
</circle>
|
|
14
14
|
</g>
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
<line x1="650" y1="138" x2="650" y2="152" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
|
|
31
31
|
<text x="156" y="141" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">C</text>
|
|
32
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">1.
|
|
33
|
+
<text x="662" y="149" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">1.90×</text>
|
|
34
34
|
<circle cx="182.0" cy="145" r="8" fill="currentColor" fill-opacity="0.4">
|
|
35
|
-
<animate attributeName="cx" dur="
|
|
35
|
+
<animate attributeName="cx" dur="3.0357106104522025s" repeatCount="indefinite" calcMode="linear"
|
|
36
36
|
keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-0.82s"/>
|
|
37
37
|
</circle>
|
|
38
38
|
</g>
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
<rect x="174" y="193.5" width="476" height="3" rx="1.5" fill="currentColor" fill-opacity="0.1"/>
|
|
41
41
|
<line x1="174" y1="188" x2="174" y2="202" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
|
|
42
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">
|
|
44
|
-
<text x="156" y="206" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">
|
|
45
|
-
<text x="662" y="199" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">
|
|
43
|
+
<text x="156" y="191" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">AssemblyScript</text>
|
|
44
|
+
<text x="156" y="206" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">asc -O3</text>
|
|
45
|
+
<text x="662" y="199" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">2.01×</text>
|
|
46
46
|
<circle cx="182.0" cy="195" r="8" fill="currentColor" fill-opacity="0.4">
|
|
47
|
-
<animate attributeName="cx" dur="
|
|
47
|
+
<animate attributeName="cx" dur="3.2124794017682934s" repeatCount="indefinite" calcMode="linear"
|
|
48
48
|
keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-1.23s"/>
|
|
49
49
|
</circle>
|
|
50
50
|
</g>
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
<rect x="174" y="243.5" width="476" height="3" rx="1.5" fill="currentColor" fill-opacity="0.1"/>
|
|
53
53
|
<line x1="174" y1="238" x2="174" y2="252" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
|
|
54
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">
|
|
56
|
-
<text x="156" y="256" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">
|
|
57
|
-
<text x="662" y="249" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">
|
|
55
|
+
<text x="156" y="241" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">V8</text>
|
|
56
|
+
<text x="156" y="256" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">Node (JS)</text>
|
|
57
|
+
<text x="662" y="249" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">2.08×</text>
|
|
58
58
|
<circle cx="182.0" cy="245" r="8" fill="currentColor" fill-opacity="0.4">
|
|
59
|
-
<animate attributeName="cx" dur="
|
|
59
|
+
<animate attributeName="cx" dur="3.3225427019796743s" repeatCount="indefinite" calcMode="linear"
|
|
60
60
|
keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-1.64s"/>
|
|
61
61
|
</circle>
|
|
62
62
|
</g>
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
<rect x="174" y="293.5" width="476" height="3" rx="1.5" fill="currentColor" fill-opacity="0.1"/>
|
|
65
65
|
<line x1="174" y1="288" x2="174" y2="302" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
|
|
66
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">
|
|
68
|
-
<text x="156" y="306" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">
|
|
69
|
-
<text x="662" y="299" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">
|
|
67
|
+
<text x="156" y="291" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">Porffor</text>
|
|
68
|
+
<text x="156" y="306" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">runs 4 / 45</text>
|
|
69
|
+
<text x="662" y="299" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">3.99×</text>
|
|
70
70
|
<circle cx="182.0" cy="295" r="8" fill="currentColor" fill-opacity="0.4">
|
|
71
|
-
<animate attributeName="cx" dur="
|
|
71
|
+
<animate attributeName="cx" dur="6.379281377701994s" repeatCount="indefinite" calcMode="linear"
|
|
72
72
|
keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-2.05s"/>
|
|
73
73
|
</circle>
|
|
74
74
|
</g>
|
|
@@ -76,11 +76,11 @@
|
|
|
76
76
|
<rect x="174" y="343.5" width="476" height="3" rx="1.5" fill="currentColor" fill-opacity="0.1"/>
|
|
77
77
|
<line x1="174" y1="338" x2="174" y2="352" stroke="currentColor" stroke-opacity="0.3" stroke-width="2"/>
|
|
78
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">
|
|
80
|
-
<text x="156" y="356" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">
|
|
81
|
-
<text x="662" y="349" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">
|
|
79
|
+
<text x="156" y="341" text-anchor="end" font-size="14" font-weight="500" fill="currentColor" fill-opacity="0.82">Go</text>
|
|
80
|
+
<text x="156" y="356" text-anchor="end" font-size="10" fill="currentColor" fill-opacity="0.46">gc → wasm</text>
|
|
81
|
+
<text x="662" y="349" font-size="13" font-weight="500" fill="currentColor" fill-opacity="0.6">4.13×</text>
|
|
82
82
|
<circle cx="182.0" cy="345" r="8" fill="currentColor" fill-opacity="0.4">
|
|
83
|
-
<animate attributeName="cx" dur="
|
|
83
|
+
<animate attributeName="cx" dur="6.6000841533019425s" repeatCount="indefinite" calcMode="linear"
|
|
84
84
|
keyTimes="0;0.5;1" values="182.0;642.0;182.0" begin="-2.46s"/>
|
|
85
85
|
</circle>
|
|
86
86
|
</g>
|
package/dist/interop.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Se=new TextDecoder;function ye(t={}){let e=null,i=(r,o)=>{let g=r===1?globalThis.process?.stdout:globalThis.process?.stderr;if(g&&typeof g.write=="function")try{g.write(o);return}catch{}let A=o.replace(/\n$/,"");(r===1?console.log:console.warn)(A)},u=t.write||i;return{wasi_snapshot_preview1:{fd_read(r,o,g,A){let h=new DataView(e.buffer),_=0;for(let b=0;b<g;b++){let E=h.getUint32(o+b*8,!0),S=h.getUint32(o+b*8+4,!0),P=new Uint8Array(e.buffer,E,S);_+=t.read&&t.read(r,P)||0}return h.setUint32(A,_,!0),0},fd_write(r,o,g,A){let h=new DataView(e.buffer),_=0;for(let b=0;b<g;b++){let E=h.getUint32(o+b*8,!0),S=h.getUint32(o+b*8+4,!0);u(r,Se.decode(new Uint8Array(e.buffer,E,S))),_+=S}return h.setUint32(A,_,!0),0},clock_time_get(r,o,g){let A=new DataView(e.buffer),h=BigInt(Math.round(r===0?Date.now()*1e6:performance.now()*1e6));return A.setBigInt64(g,h,!0),0},random_get(r,o){let g=new Uint8Array(e.buffer,r,o);if(globalThis.crypto?.getRandomValues)globalThis.crypto.getRandomValues(g);else for(let A=0;A<o;A++)g[A]=Math.random()*256|0;return 0},proc_exit(){},environ_sizes_get(r,o){let g=new DataView(e.buffer);return g.setUint32(r,0,!0),g.setUint32(o,0,!0),0},environ_get(){return 0}},_setMemory(r){e=r}}}var de=t=>{if(!t.exports.__timer_tick)return;let e=t.exports.__timer_tick,i=!1,u=setInterval(()=>{let r=e();r>0&&(i=!0),i&&r<=0&&clearInterval(u)},1)};var H={PTR_ADDR:1020,START:1024},N={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},W={ATOM:0,ARRAY:1,BUFFER:2,TYPED:3,STRING:4,OBJECT:6,HASH:7,SET:8,MAP:9,CLOSURE:10,EXTERNAL:11},L={NULL:1,UNDEF:2,FALSE:4,TRUE:5},Ce=1<<W.ARRAY|1<<W.HASH|1<<W.SET|1<<W.MAP,Xe=BigInt(N.TAG_SHIFT),ze=BigInt(N.TAG_MASK),Ke=BigInt(N.AUX_SHIFT),Ge=BigInt(N.AUX_MASK),Ye=BigInt(N.OFFSET_MASK);var z=(t,e)=>(N.NAN_PREFIX<<16|(t&N.TAG_MASK)<<N.TAG_SHIFT-32|e&N.AUX_MASK)>>>0,Ae=t=>t>>>N.TAG_SHIFT-32&N.TAG_MASK,ae=t=>t&N.AUX_MASK;var Y={[L.NULL]:z(W.ATOM,L.NULL),[L.UNDEF]:z(W.ATOM,L.UNDEF),[L.FALSE]:z(W.ATOM,L.FALSE),[L.TRUE]:z(W.ATOM,L.TRUE)};var le=new TextEncoder,Ee=new TextDecoder,Me=(t,e)=>{let i=WebAssembly.Module.imports(t).some(u=>u.module==="wasi_snapshot_preview1");return{needsWasi:i,wasiImports:i?ye(e):null}},Ue=t=>new Set(WebAssembly.Module.imports(t).filter(e=>e.module==="env"&&e.kind==="function").map(e=>e.name)),Ne=(t,e)=>{let i=()=>new DataView(t.buffer),u=e?()=>e.value>>>0:()=>i().getUint32(H.PTR_ADDR,!0),r=e?_=>{e.value=_}:_=>i().setInt32(H.PTR_ADDR,_,!0),o=e?e.value>>>0:H.START;return{alloc:_=>{let b=u(),E=b-b%8,S=E+_;return S>t.buffer.byteLength&&t.grow(Math.ceil((S-t.buffer.byteLength)/65536)),r(S),E},reset:()=>r(o),initHeapPtr:()=>{if(e)return;let _=i();_.getUint32(H.PTR_ADDR,!0)<H.START&&_.setInt32(H.PTR_ADDR,H.START,!0)}}},te=(t,e)=>{let i=WebAssembly.Module.customSections(t,e);return i.length?new Uint8Array(i[0]):null},Oe=t=>{let e=new TextDecoder,i=0;return{pos:()=>i,seek:u=>{i=u},eof:()=>i>=t.length,u8:()=>t[i++],varint:()=>{let u=0,r=0;for(;;){let o=t[i++];if(u|=(o&127)<<r,!(o&128))return u;r+=7}},str:u=>{let r=e.decode(t.subarray(i,i+u));return i+=u,r},bytes:u=>{let r=t.subarray(i,i+u);return i+=u,r}}},J=0xffffffffn,Ie=new ArrayBuffer(8),se=new Uint32Array(Ie),be=new Float64Array(Ie),q=t=>(be[0]=t,BigInt(se[1])<<32n|BigInt(se[0]>>>0)),j=t=>(se[0]=Number(t&J),se[1]=Number(t>>32n&J),be[0]),ie=t=>Number(t>>32n&J),ue=t=>(ie(t)&2146959360)===2146959360,R=t=>typeof t=="bigint"?t:q(t),we=BigInt(Y[L.NULL])<<32n,K=BigInt(Y[L.UNDEF])<<32n,Re=BigInt(Y[L.FALSE])<<32n,Le=BigInt(Y[L.TRUE])<<32n,k=t=>t===null?we:t===void 0?K:t,Pe=t=>{let e=0n;for(let i=0;i<t.length;i++)e|=BigInt(t.charCodeAt(i))<<BigInt(i*7);return e|=BigInt(t.length)<<42n,D(4,Number(e>>32n)|N.SSO_BIT,Number(e&0xFFFFFFFFn))},pe=t=>typeof t=="bigint"?t:q(t),D=(t,e,i)=>BigInt(z(t,e))<<32n|BigInt(i>>>0),C=t=>Number(pe(t)&J),me=t=>Ae(ie(pe(t))),ne=t=>ae(ie(pe(t))),Fe=t=>{let e=ae(ie(t)),i=e>>>10&7,u=BigInt(e)<<32n|BigInt(Number(t&J)),r="";for(let o=0;o<i;o++)r+=String.fromCharCode(Number(u>>BigInt(o*7)&0x7fn));return r},V=t=>{if(Array.isArray(t))return t.map(V);if(typeof t=="number"){if(t===t)return t;t=q(t)}else if(typeof t!="bigint")return t;if(!ue(t))return j(t);if(me(t)===4&&ne(t)&N.SSO_BIT)return Fe(t);if(C(t)===0){if(t===we)return null;if(t===K)return;if(t===Re)return!1;if(t===Le)return!0}return j(t)},fe=(t,e)=>t.mem?t.mem.read(e):V(e),re={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"]},xe=Object.values(re),oe=new WeakSet,ce=t=>{if(t instanceof WebAssembly.Memory&&oe.has(t))return t;if(!t||typeof t=="object"&&!(t instanceof WebAssembly.Memory)&&!t.instance&&!t.exports&&!t.memory){let n=new WebAssembly.Memory({initial:t?.initial||1,...t?.maximum?{maximum:t.maximum}:{},...t?.shared?{shared:t.shared}:{}});return ce(n)}let e,i,u,r;if(t instanceof WebAssembly.Memory)e=t,i=null,u=null,r=null;else{let n=t?.instance?.exports||t?.exports||t;if(e=t?.exports?.memory||n.memory,!e)return{read:V,wrapVal:k,scalar:!0};i={...n,memory:e},u=t.extMap||null,r=t.module||null}let o=()=>new DataView(e.buffer),{alloc:g,reset:A,initHeapPtr:h}=Ne(e,i?.__heap),_=i?._alloc&&(n=>i._alloc(n)>>>0),b=_||g;h();let E=(n,s,m)=>{let p=b(16+m),c=o();return c.setBigInt64(p,0n,!0),c.setInt32(p+8,n,!0),c.setInt32(p+12,s,!0),p+16},S=e.schemas||[],P=r&&te(r,"jz:schema");if(P){let n=Oe(P),s=()=>{let c=n.u8();return c===0?null:c===1?[null,s()]:n.str(n.varint())},m=n.varint(),p=[];for(let c=0;c<m;c++){let a=n.varint(),l=[];for(let y=0;y<a;y++)l.push(s());p.push(l)}for(let c of p){let a=c.join(",");S.some(l=>l.join(",")===a)||S.push(c)}}if(oe.has(e))return e.schemas=S,_&&(b=_,e.alloc=b),e.reset=A,u&&(e._extMap=u),e;e.schemas=S,e._extMap=u,e.Array=n=>{let s=n.length,m=E(s,s,s*8),p=new BigInt64Array(s);for(let a=0;a<s;a++)p[a]=R(e.wrapVal(n[a]));let c=new BigInt64Array(e.buffer,m,s);for(let a=0;a<s;a++)c[a]=p[a];return D(1,0,m)},e.String=n=>{if(n.length<=6&&/^[\x00-\x7f]*$/.test(n)){let l=0n;for(let y=0;y<n.length;y++)l|=BigInt(n.charCodeAt(y))<<BigInt(y*7);return l|=BigInt(n.length)<<42n,D(4,Number(l>>32n)|N.SSO_BIT,Number(l&0xFFFFFFFFn))}let s=le.encode(n),m=s.length,p=b(4+m),c=o();c.setInt32(p,m,!0);let a=p+4;return s.forEach((l,y)=>c.setUint8(a+y,l)),D(4,0,a)},e.Buffer=n=>{let s=n instanceof ArrayBuffer?new Uint8Array(n):ArrayBuffer.isView(n)?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):new Uint8Array(n),m=s.length,p=E(m,m,m);return new Uint8Array(e.buffer).set(s,p),D(2,0,p)},e.wrapVal=function(n){if(n==null)return k(n);if(typeof n=="number"||typeof n=="boolean")return Number(n);if(typeof n=="string")return e.String(n);if(typeof n=="bigint")return ue(n)?n:e.String(n.toString());if(Array.isArray(n))return e.Array(n);if(n instanceof ArrayBuffer)return e.Buffer(n);if(n instanceof DataView)return e.Buffer(n.buffer);let s=n?.constructor?.name;return s&&re[s]?e[s](n):typeof n=="object"||typeof n=="function"?e.External(n):K},e.External=function(n){if(n==null)return k(n);let s=e._extMap;if(!s)return K;let m=s.indexOf(n);return m===-1&&(m=s.length,s.push(n)),D(11,0,m)};let G=n=>n<=1?n+2|0:n,Q=n=>{let s=R(n);if(s>>32n&BigInt(N.SSO_BIT)){let l=Number(s&0xFFFFFFFFn)|0,y=Number(s>>32n&0x1FFFn)|0,x=Math.imul(y^2654435769,2246822507);return x=Math.imul(l^x,3266489909),x=x^x>>>15|0,G(x)>>>0}let m=Number(s&0xFFFFFFFFn),p=o(),c=p.getInt32(m-4,!0),a=-2128831035;for(let l=0;l<c;l++)a=Math.imul(a^p.getUint8(m+l),16777619)|0;return G(a)>>>0};e.Hash=function(n){let s=Object.entries(n),m=8;for(;s.length*4>=m*3;)m<<=1;let p=E(s.length,m,m*24),c=new BigInt64Array(m*3);return s.forEach(([l,y],x)=>{let T=e.String(l),B=Q(T),w=B&m-1;for(;c[w*3]!==0n;)w=w+1&m-1;c[w*3]=BigInt(x)<<32n|BigInt(B>>>0),c[w*3+1]=R(T),c[w*3+2]=R(e.wrapVal(y))}),new BigInt64Array(e.buffer,p,m*3).set(c),D(7,0,p)},e.Object=function(n){let s=Object.keys(n),m=s.join(","),p=e.schemas,c=p.findIndex(B=>B.join(",")===m);if(c===-1){let B=p.reduce((w,$,f)=>$.length===s.length&&s.every(d=>$.includes(d))?w.concat(f):w,[]);if(B.length===1)c=B[0];else{if(B.length>1)throw Error(`Ambiguous schema for {${m}} \u2014 pass keys in schema order`);return e.Hash(n)}}let a=p[c],l=a.length,y=b(l*8),x=new BigInt64Array(l);for(let B=0;B<l;B++){let w=n[a[B]];w==null?w=k(w):typeof w=="string"?w=e.String(w):Array.isArray(w)&&(w=e.Array(w)),x[B]=R(w)}let T=new BigInt64Array(e.buffer,y,l);for(let B=0;B<l;B++)T[B]=x[B];return D(6,c,y)},e.read=function(n){if(Array.isArray(n))return n.map(a=>e.read(a));if(typeof n=="number"){if(n===n)return n;n=q(n)}else if(typeof n!="bigint")return n;if(!ue(n))return j(n);let s=o(),m=me(n),p=ne(n),c=C(n);if(m===0&&c===0){if(p===1)return null;if(p===2)return;if(p===4)return!1;if(p===5)return!0}if(m===11&&e._extMap)return e._extMap[c];if(m===1){let a=c;for(;s.getInt32(a-4,!0)===-1;)a=s.getInt32(a-8,!0);let l=s.getInt32(a-8,!0),y=new Array(l);for(let x=0;x<l;x++)y[x]=e.read(s.getBigInt64(a+x*8,!0));return y}if(m===3){let a=p&7,[,l]=xe[a],y=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][a];if(p&8){let T=s.getInt32(c,!0),B=s.getInt32(c+4,!0);return new y(e.buffer,B,T/l)}let x=s.getInt32(c-8,!0);return new y(e.buffer,c,x/l)}if(m===2){let a=s.getInt32(c-8,!0),l=new ArrayBuffer(a);return new Uint8Array(l).set(new Uint8Array(e.buffer,c,a)),l}if(m===4){if(p&N.SSO_BIT)return Fe(n);let a=s.getInt32(c-4,!0);return Ee.decode(new Uint8Array(e.buffer,c,a))}if(m===6){let a=e.schemas[p];if(!a)return n;let l={};for(let y=0;y<a.length;y++)l[a[y]]=e.read(s.getBigInt64(c+y*8,!0));return l}if(m===7){let a=s.getInt32(c-8,!0),l=s.getInt32(c-4,!0),y={};for(let x=0,T=0;x<l&&T<a;x++)s.getBigInt64(c+x*24,!0)!==0n&&(y[e.read(s.getBigInt64(c+x*24+8,!0))]=e.read(s.getBigInt64(c+x*24+16,!0)),T++);return y}if(m===8){let a=s.getInt32(c-8,!0),l=s.getInt32(c-4,!0),y=new Set;for(let x=0;x<l&&y.size<a;x++)s.getBigInt64(c+x*16,!0)!==0n&&y.add(e.read(s.getBigInt64(c+x*16+8,!0)));return y}if(m===9){let a=s.getInt32(c-8,!0),l=s.getInt32(c-4,!0),y=new Map;for(let x=0;x<l&&y.size<a;x++)s.getBigInt64(c+x*24,!0)!==0n&&y.set(e.read(s.getBigInt64(c+x*24+8,!0)),e.read(s.getBigInt64(c+x*24+16,!0)));return y}return j(n)},e.write=function(n,s){let m=me(n),p=C(n),c=o();if(m===1){let a=c.getInt32(p-4,!0);if(s.length>a)throw Error(`write: ${s.length} exceeds capacity ${a}`);c.setInt32(p-8,s.length,!0);for(let l=0;l<s.length;l++)c.setBigInt64(p+l*8,R(k(s[l])),!0)}else if(m===3){let a=ne(n),l=a&7,[,y,,x]=xe[l],T=s.length*y;if(a&8){let B=c.getInt32(p,!0),w=c.getInt32(p+4,!0);if(T>B)throw Error(`write: ${T} bytes exceeds view size ${B}`);for(let $=0;$<s.length;$++)c[x](w+$*y,s[$],!0)}else{let B=c.getInt32(p-4,!0);if(T>B)throw Error(`write: ${T} bytes exceeds capacity ${B}`);c.setInt32(p-8,T,!0);for(let w=0;w<s.length;w++)c[x](p+w*y,s[w],!0)}}else if(m===6){let a=e.schemas[ne(n)];if(!a)throw Error("write: unknown schema");for(let l of Object.keys(s)){let y=a.indexOf(l);y>=0&&c.setBigInt64(p+y*8,R(k(s[l])),!0)}}else throw Error(`write: unsupported type ${m}`)},e.alloc=b,e.reset=A;let X=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];for(let[n,[s,m,,p]]of Object.entries(re))e[n]=c=>{let a=c.length,l=a*m,y=E(l,l,l);if(X[s]&&c instanceof X[s])new X[s](e.buffer,y,a).set(c);else{let x=o();for(let T=0;T<a;T++)x[p](y+T*m,c[T],!0)}return D(3,s,y)};return e.allocTyped=(n,s)=>{let m=re[n?.name];if(!m)throw Error(`allocTyped: unsupported type ${n?.name??n}`);let[p,c]=m,a=s*c,l=E(a,a,a);return{view:new n(e.buffer,l,s),box:D(3,p,l)}},oe.add(e),e},De=(t,e,i)=>{let u=new Map,r=e?t:t.module||t,o=e||t.instance||t,g=new TextDecoder,A=te(r,"jz:rest");if(A)try{for(let f of JSON.parse(g.decode(A)))u.set(typeof f=="string"?f:f.name,typeof f=="string"?0:f.fixed)}catch{}let h=new Map,_=te(r,"jz:extparam");if(_)try{for(let f of JSON.parse(g.decode(_))){let d=new Set(f.p);f.d&&(d.def=new Map(Object.entries(f.d).map(([I,F])=>[Number(I),F]))),h.set(f.name,d)}}catch{}let b=new Map,E=te(r,"jz:i64exp");if(E)try{for(let f of JSON.parse(g.decode(E)))b.set(f.name,{p:new Set(f.p||[]),r:!!f.r})}catch{}let S=ce(t),P=o.exports.__mt_drain,G=o.exports.__p_state,Q=o.exports.__p_value,X=!!(P&&G&&Q),n=[],s=(f,d,I)=>{let F=b.get(d);return f(typeof I=="bigint"?F?.p?.has(0)?I:j(I):F?.p?.has(0)?R(I):I)},m=f=>{let d=s(G,"__p_state",f);return typeof d=="bigint"?j(d):d},p=f=>{let d=s(Q,"__p_value",f);return S?S.read(d):V(d)},c=()=>{P();for(let f=n.length-1;f>=0;f--){let d=n[f],I=m(d.raw);I<1||(n.splice(f,1),I===1?d.resolve(p(d.raw)):d.reject(p(d.raw)))}},a=(f,d)=>{P();let I=m(f);return I<0?d(f):I===1?Promise.resolve(p(f)):I===2?Promise.reject(p(f)):new Promise((F,U)=>n.push({raw:f,resolve:F,reject:U}))};if(X&&i){i.afterTick=c;let f=o.exports.__p_make,d=o.exports.__p_finish;if(f&&d){let I=b.get("__p_finish");i.pmake=()=>f(),i.pfinish=(F,U,M)=>d(I?.p?.has(0)?typeof F=="bigint"?F:R(F):typeof F=="bigint"?j(F):F,I?.p?.has(1)?q(U):U,I?.p?.has(2)?M:j(M))}}let l=(f,d)=>X?a(f,d):d(f),y=o.exports.__jz_last_err_bits,x=f=>{if(!(f instanceof WebAssembly.Exception)||!y)throw f;let d=y.value,I=S?S.read(d):V(d);if(I instanceof Error)throw I;let F=new Error(typeof I=="string"?I:String(I));throw F.cause=f,F.thrown=I,F},T={},B=(f,d,I,F)=>f?.has(d)?I===void 0&&f.def?.has(d)?f.def.get(d):I:F(I),w=(f,d,I)=>(F,U)=>{let M=B(d,U,F,I);if(f&&f.p.has(U)){if(typeof M=="string"){if(M.length>6||!/^[\x00-\x7f]*$/.test(M))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 Pe(M)}return R(M)}return typeof M=="bigint"?j(M):M};if(!S||S.scalar){for(let[f,d]of Object.entries(o.exports)){if(typeof d!="function"){T[f]=d;continue}let I=h.get(f),F=b.get(f),U=d.length;T[f]=(...M)=>{for(;M.length<U;)M.push(void 0);try{let O=d(...M.map(w(F,I,k)));return typeof O=="bigint"&&!(F&&F.r)?O:V(O)}catch(O){x(O)}}}return T}let $=S.wrapVal.bind(S);for(let[f,d]of Object.entries(o.exports))if(u.has(f)&&typeof d=="function"){let I=u.get(f),F=h.get(f),U=b.get(f);T[f]=(...M)=>{let O=M.slice(0,I).map(w(U,F,$));for(;O.length<I;){let v=O.length;O.push(U&&U.p.has(v)?K:j(K))}let Z=S.Array(M.slice(I));O.push(U&&U.p.has(I)?Z:j(Z));try{let v=d.apply(null,O);return typeof v=="bigint"&&!(U&&U.r)?v:l(v,Be=>S.read(Be))}catch(v){x(v)}}}else if(typeof d=="function"){let I=h.get(f),F=b.get(f),U=d.length;T[f]=(...M)=>{for(;M.length<U;)M.push(void 0);try{let O=d.apply(null,M.map(w(F,I,$)));return typeof O=="bigint"&&!(F&&F.r)?O:l(O,Z=>S.read(Z))}catch(O){x(O)}}}else T[f]=d;return T},ge=(t,e)=>{if(e!=null&&typeof e.then=="function"&&t.pmake){let i=t.pmake(),u=r=>R(t.mem?t.mem.wrapVal(r):k(r));return e.then(r=>{t.pfinish(i,1,u(r)),t.afterTick?.()},r=>{t.pfinish(i,2,u(r instanceof Error?r.message:r)),t.afterTick?.()}),typeof i=="bigint"?i:R(i)}return R(t.mem?t.mem.wrapVal(e):k(e))},je=new Set(["fetch"]),$e=t=>{let e={extMap:[null],mem:null};return t._interp=t._interp||{},t._interp.__ext_prop=(i,u)=>{let r=e.extMap[C(i)],o=e.mem.read(u);return R(e.mem.wrapVal(typeof r[o]=="function"?r[o].bind(r):r[o]))},t._interp.__ext_has=(i,u)=>e.mem.read(u)in e.extMap[C(i)]?1:0,t._interp.__ext_set=(i,u,r)=>{let o=e.mem.read(r);return ArrayBuffer.isView(o)&&(o=o.slice()),e.extMap[C(i)][e.mem.read(u)]=o,1},t._interp.__ext_call=(i,u,r)=>{let o=e.extMap[C(i)],g=e.mem.read(u),A=e.mem.read(r);return ge(e,o[g].apply(o,A))},e},ke=(t,e,i)=>{let u=Ue(t);if(u.size){e.env||(e.env={});for(let r of u){if(e.env[r]||!je.has(r))continue;let o=globalThis[r];typeof o=="function"&&(e.env[r]=(...g)=>ge(i,o(...g.map(A=>i.mem?i.mem.read(A):V(A)))))}if(u.has("print")&&!e.env.print){let r=["","",""],o=[],g=h=>{(h===2?console.error:console.log)(r[h]),r[h]=""},A=(h,_,b)=>{let E=fe(i,h);r[_]+=String(E),b===32?r[_]+=" ":b===10&&g(_)};e.env.print=(h,_,b)=>{i.mem?A(h,_,b):o.push([h,_,b])},i.flushPrint=()=>{for(let h of o)A(...h);o.length=0}}if(u.has("now")&&!e.env.now&&(e.env.now=r=>r===1&&typeof performance<"u"?performance.now():Date.now()),u.has("rngSeed")&&!e.env.rngSeed&&(e.env.rngSeed=()=>{let r=new Uint32Array(1);return globalThis.crypto?.getRandomValues?globalThis.crypto.getRandomValues(r):r[0]=Math.random()*4294967296>>>0,r[0]|0}),u.has("parseFloat")&&!e.env.parseFloat&&(e.env.parseFloat=r=>{let o=fe(i,r);return parseFloat(o)}),u.has("parseInt")&&!e.env.parseInt&&(e.env.parseInt=(r,o)=>{let g=fe(i,r);return parseInt(g,o||void 0)}),u.has("setTimeout")||u.has("clearTimeout")){let r=new Map,o=1;u.has("setTimeout")&&!e.env.setTimeout&&(e.env.setTimeout=(g,A,h)=>{let _=o++,b=()=>{i.invoke?.(g),i.afterTick?.()};if(h){let E=setInterval(b,A);r.set(_,()=>clearInterval(E))}else{let E=setTimeout(()=>{r.delete(_),b()},A);r.set(_,()=>clearTimeout(E))}return _}),u.has("clearTimeout")&&!e.env.clearTimeout&&(e.env.clearTimeout=g=>{let A=r.get(g);return A&&(A(),r.delete(g)),0})}}},he={length:t=>t.length,charCodeAt:(t,e)=>t.charCodeAt(e)},_e=!1,ee=!1,Te=()=>{if(_e)return ee;_e=!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,...le.encode("wasm:js-string"),6,...le.encode("length"),0,0]),e=new WebAssembly.Module(t,{builtins:["js-string"]});new WebAssembly.Instance(e,{}),ee=!0}catch{ee=!1}return ee},We=(t,e,i)=>{let{needsWasi:u,wasiImports:r}=Me(t,e),o=r||{};if(e._interp&&(o.env={...o.env,...e._interp}),!Te())for(let g of WebAssembly.Module.imports(t))g.module==="wasm:js-string"&&he[g.name]&&(o["wasm:js-string"]||(o["wasm:js-string"]={}),o["wasm:js-string"][g.name]=he[g.name]);if(e.imports)for(let[g,A]of Object.entries(e.imports)){o[g]||(o[g]={});for(let h of Object.getOwnPropertyNames(A)){let _=A[h],b=typeof _=="function"?_:_&&typeof _=="object"?_.fn:null;typeof b=="function"&&(o[g][h]=(...E)=>{let S=E.map(P=>i.mem?i.mem.read(P):V(P));return ge(i,b.call(A,...S))})}}ke(t,o,i),e.memory instanceof WebAssembly.Memory&&(oe.has(e.memory)||(e.memory=ce(e.memory)),o.env||(o.env={}),o.env.memory=e.memory);for(let g of WebAssembly.Module.imports(t))if(g.kind==="global"&&g.module==="env"){let A=globalThis[g.name];if(A!==void 0){o.env||(o.env={});let h=i.extMap.indexOf(A);h===-1&&(h=i.extMap.length,i.extMap.push(A)),o.env[g.name]=new WebAssembly.Global({value:"i64",mutable:!1},D(11,0,h))}}return{imports:o,needsWasi:u}},He=(t,e,i,u,r,o)=>{u&&i._setMemory(e.exports.memory),e.exports._initialize?.(),o.invoke=e.exports.__invoke_closure||null,de(e);let g=r.memory instanceof WebAssembly.Memory?r.memory:e.exports.memory,A={module:t,instance:e,exports:{...e.exports,memory:g},extMap:o.extMap},h=ce(A);return o.mem=h,o.flushPrint?.(),{exports:De(A,void 0,o),memory:h?.scalar?null:h,instance:e,module:t}},Ve=t=>{if(t instanceof WebAssembly.Module)return t;if(Te())try{return new WebAssembly.Module(t,{builtins:["js-string"]})}catch{return new WebAssembly.Module(t)}return new WebAssembly.Module(t)},Ze=(t,e={})=>{let i=$e(e),u=Ve(t),{imports:r,needsWasi:o}=We(u,e,i),g=Object.keys(r).some(h=>h!=="_setMemory"),A=new WebAssembly.Instance(u,g?r:void 0);return He(u,A,r,o,e,i)};export{Re as FALSE_NAN,we as NULL_NAN,Le as TRUE_NAN,K as UNDEF_NAN,ne as aux,k as coerce,q as f64ToI64,j as i64ToF64,Ze as instantiate,ce as memory,C as offset,D as ptr,Ve as toModule,me as type,De as wrap};
|
|
1
|
+
var Ee=new TextDecoder;function ge(t={}){let e=null,i=(r,o)=>{let a=r===1?globalThis.process?.stdout:globalThis.process?.stderr;if(a&&typeof a.write=="function")try{a.write(o);return}catch{}let m=o.replace(/\n$/,"");(r===1?console.log:console.warn)(m)},l=t.write||i;return{wasi_snapshot_preview1:{fd_read(r,o,a,m){let A=new DataView(e.buffer),I=0;for(let x=0;x<a;x++){let S=A.getUint32(o+x*8,!0),B=A.getUint32(o+x*8+4,!0),j=new Uint8Array(e.buffer,S,B);I+=t.read&&t.read(r,j)||0}return A.setUint32(m,I,!0),0},fd_write(r,o,a,m){let A=new DataView(e.buffer),I=0;for(let x=0;x<a;x++){let S=A.getUint32(o+x*8,!0),B=A.getUint32(o+x*8+4,!0);l(r,Ee.decode(new Uint8Array(e.buffer,S,B))),I+=B}return A.setUint32(m,I,!0),0},clock_time_get(r,o,a){let m=new DataView(e.buffer),A=BigInt(Math.round(r===0?Date.now()*1e6:performance.now()*1e6));return m.setBigInt64(a,A,!0),0},random_get(r,o){let a=new Uint8Array(e.buffer,r,o);if(globalThis.crypto?.getRandomValues)globalThis.crypto.getRandomValues(a);else for(let m=0;m<o;m++)a[m]=Math.random()*256|0;return 0},proc_exit(){},environ_sizes_get(r,o){let a=new DataView(e.buffer);return a.setUint32(r,0,!0),a.setUint32(o,0,!0),0},environ_get(){return 0}},_setMemory(r){e=r}}}var de=t=>{if(!t.exports.__timer_tick)return;let e=t.exports.__timer_tick,i=!1,l=setInterval(()=>{let r=e();r>0&&(i=!0),i&&r<=0&&clearInterval(l)},1)};var H={PTR_ADDR:1020,START:1024},O={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},W={ATOM:0,ARRAY:1,BUFFER:2,TYPED:3,STRING:4,OBJECT:6,HASH:7,SET:8,MAP:9,CLOSURE:10,EXTERNAL:11},P={NULL:1,UNDEF:2,FALSE:4,TRUE:5},Ve=1<<W.ARRAY|1<<W.HASH|1<<W.SET|1<<W.MAP,ze=BigInt(O.TAG_SHIFT),Xe=BigInt(O.TAG_MASK),Ke=BigInt(O.AUX_SHIFT),Ge=BigInt(O.AUX_MASK),Ye=BigInt(O.OFFSET_MASK);var z=(t,e)=>(O.NAN_PREFIX<<16|(t&O.TAG_MASK)<<O.TAG_SHIFT-32|e&O.AUX_MASK)>>>0,Ae=t=>t>>>O.TAG_SHIFT-32&O.TAG_MASK,ae=t=>t&O.AUX_MASK;var G={[P.NULL]:z(W.ATOM,P.NULL),[P.UNDEF]:z(W.ATOM,P.UNDEF),[P.FALSE]:z(W.ATOM,P.FALSE),[P.TRUE]:z(W.ATOM,P.TRUE)};var le=new TextEncoder,Se=new TextDecoder,Me=(t,e)=>{let i=WebAssembly.Module.imports(t).some(l=>l.module==="wasi_snapshot_preview1");return{needsWasi:i,wasiImports:i?ge(e):null}},Ue=t=>new Set(WebAssembly.Module.imports(t).filter(e=>e.module==="env"&&e.kind==="function").map(e=>e.name)),Ne=(t,e)=>{let i=()=>new DataView(t.buffer),l=e?()=>e.value>>>0:()=>i().getUint32(H.PTR_ADDR,!0),r=e?I=>{e.value=I}:I=>i().setInt32(H.PTR_ADDR,I,!0),o=e?e.value>>>0:H.START;return{alloc:I=>{let x=l(),S=x-x%8,B=S+I;return B>t.buffer.byteLength&&t.grow(Math.ceil((B-t.buffer.byteLength)/65536)),r(B),S},reset:()=>r(o),initHeapPtr:()=>{if(e)return;let I=i();I.getUint32(H.PTR_ADDR,!0)<H.START&&I.setInt32(H.PTR_ADDR,H.START,!0)}}},ee=(t,e)=>{let i=WebAssembly.Module.customSections(t,e);return i.length?new Uint8Array(i[0]):null},Oe=t=>{let e=new TextDecoder,i=0;return{pos:()=>i,seek:l=>{i=l},eof:()=>i>=t.length,u8:()=>t[i++],varint:()=>{let l=0,r=0;for(;;){let o=t[i++];if(l|=(o&127)<<r,!(o&128))return l;r+=7}},str:l=>{let r=e.decode(t.subarray(i,i+l));return i+=l,r},bytes:l=>{let r=t.subarray(i,i+l);return i+=l,r}}},Y=0xffffffffn,Ie=new ArrayBuffer(8),oe=new Uint32Array(Ie),we=new Float64Array(Ie),q=t=>(we[0]=t,BigInt(oe[1])<<32n|BigInt(oe[0]>>>0)),$=t=>(oe[0]=Number(t&Y),oe[1]=Number(t>>32n&Y),we[0]),ie=t=>Number(t>>32n&Y),ue=t=>(ie(t)&2146959360)===2146959360,L=t=>typeof t=="bigint"?t:q(t),be=BigInt(G[P.NULL])<<32n,X=BigInt(G[P.UNDEF])<<32n,Re=BigInt(G[P.FALSE])<<32n,Le=BigInt(G[P.TRUE])<<32n,v=t=>t===null?be:t===void 0?X:t,Pe=t=>{let e=0n;for(let i=0;i<t.length;i++)e|=BigInt(t.charCodeAt(i))<<BigInt(i*7);return e|=BigInt(t.length)<<42n,D(4,Number(e>>32n)|O.SSO_BIT,Number(e&0xFFFFFFFFn))},pe=t=>typeof t=="bigint"?t:q(t),D=(t,e,i)=>BigInt(z(t,e))<<32n|BigInt(i>>>0),se=t=>Number(pe(t)&Y),me=t=>Ae(ie(pe(t))),te=t=>ae(ie(pe(t))),Fe=t=>{let e=ae(ie(t)),i=e>>>10&7,l=BigInt(e)<<32n|BigInt(Number(t&Y)),r="";for(let o=0;o<i;o++)r+=String.fromCharCode(Number(l>>BigInt(o*7)&0x7fn));return r},C=t=>{if(Array.isArray(t))return t.map(C);if(typeof t=="number"){if(t===t)return t;t=q(t)}else if(typeof t!="bigint")return t;if(!ue(t))return $(t);if(me(t)===4&&te(t)&O.SSO_BIT)return Fe(t);if(se(t)===0){if(t===be)return null;if(t===X)return;if(t===Re)return!1;if(t===Le)return!0}return $(t)},fe=(t,e)=>t.mem?t.mem.read(e):C(e),ne={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"],Float16Array:[35,2,"getFloat16","setFloat16"],Uint8ClampedArray:[65,1,"getUint8","setUint8"]},he=Object.values(ne),re=new WeakSet,ce=t=>{if(t instanceof WebAssembly.Memory&&re.has(t))return t;if(!t||typeof t=="object"&&!(t instanceof WebAssembly.Memory)&&!t.instance&&!t.exports&&!t.memory){let n=new WebAssembly.Memory({initial:t?.initial||1,...t?.maximum?{maximum:t.maximum}:{},...t?.shared?{shared:t.shared}:{}});return ce(n)}let e,i,l,r;if(t instanceof WebAssembly.Memory)e=t,i=null,l=null,r=null;else{let n=t?.instance?.exports||t?.exports||t;if(e=t?.exports?.memory||n.memory,!e)return{read:C,wrapVal:v,scalar:!0};i={...n,memory:e},l=t.extMap||null,r=t.module||null}let o=()=>new DataView(e.buffer),{alloc:a,reset:m,initHeapPtr:A}=Ne(e,i?.__heap),I=i?._alloc&&(n=>i._alloc(n)>>>0),x=I||a;A();let S=(n,s,y)=>{let g=x(16+y),c=o();return c.setBigInt64(g,0n,!0),c.setInt32(g+8,n,!0),c.setInt32(g+12,s,!0),g+16},B=e.schemas||[],j=r&&ee(r,"jz:schema");if(j){let n=Oe(j),s=()=>{let c=n.u8();return c===0?null:c===1?[null,s()]:n.str(n.varint())},y=n.varint(),g=[];for(let c=0;c<y;c++){let f=n.varint(),p=[];for(let d=0;d<f;d++)p.push(s());g.push(p)}for(let c of g){let f=c.join(",");B.some(p=>p.join(",")===f)||B.push(c)}}if(re.has(e))return e.schemas=B,I&&(x=I,e.alloc=x),e.reset=m,l&&(e._extMap=l),e;e.schemas=B,e._extMap=l,e.Array=n=>{let s=n.length,y=S(s,s,s*8),g=new BigInt64Array(s);for(let f=0;f<s;f++)g[f]=L(e.wrapVal(n[f]));let c=new BigInt64Array(e.buffer,y,s);for(let f=0;f<s;f++)c[f]=g[f];return D(1,0,y)},e.String=n=>{if(n.length<=6&&/^[\x00-\x7f]*$/.test(n)){let p=0n;for(let d=0;d<n.length;d++)p|=BigInt(n.charCodeAt(d))<<BigInt(d*7);return p|=BigInt(n.length)<<42n,D(4,Number(p>>32n)|O.SSO_BIT,Number(p&0xFFFFFFFFn))}let s=le.encode(n),y=s.length,g=x(4+y),c=o();c.setInt32(g,y,!0);let f=g+4;return s.forEach((p,d)=>c.setUint8(f+d,p)),D(4,0,f)},e.Buffer=n=>{let s=n instanceof ArrayBuffer?new Uint8Array(n):ArrayBuffer.isView(n)?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):new Uint8Array(n),y=s.length,g=S(y,y,y);return new Uint8Array(e.buffer).set(s,g),D(2,0,g)},e.wrapVal=function(n){if(n==null)return v(n);if(typeof n=="number"||typeof n=="boolean")return Number(n);if(typeof n=="string")return e.String(n);if(typeof n=="bigint")return ue(n)?n:e.String(n.toString());if(Array.isArray(n))return e.Array(n);if(n instanceof ArrayBuffer)return e.Buffer(n);if(n instanceof DataView)return e.Buffer(n.buffer);let s=n?.constructor?.name;return s&&ne[s]?e[s](n):typeof n=="object"||typeof n=="function"?e.External(n):X},e.External=function(n){if(n==null)return v(n);let s=e._extMap;if(!s)return X;let y=s.indexOf(n);return y===-1&&(y=s.length,s.push(n)),D(11,0,y)};let K=n=>n<=1?n+2|0:n,J=n=>{let s=L(n);if(s>>32n&BigInt(O.SSO_BIT)){let p=Number(s&0xFFFFFFFFn)|0,d=Number(s>>32n&0x1FFFn)|0,_=Math.imul(d^2654435769,2246822507);return _=Math.imul(p^_,3266489909),_=_^_>>>15|0,K(_)>>>0}let y=Number(s&0xFFFFFFFFn),g=o(),c=g.getInt32(y-4,!0),f=-2128831035;for(let p=0;p<c;p++)f=Math.imul(f^g.getUint8(y+p),16777619)|0;return K(f)>>>0};e.Hash=function(n){let s=Object.entries(n),y=8;for(;s.length*4>=y*3;)y<<=1;let g=S(s.length,y,y*28),c=new BigInt64Array(y*3),f=new Int32Array(y);return s.forEach(([d,_],E)=>{let T=e.String(d),F=J(T),N=F&y-1;for(;c[N*3]!==0n;)N=N+1&y-1;c[N*3]=BigInt(E)<<32n|BigInt(F>>>0),c[N*3+1]=L(T),c[N*3+2]=L(e.wrapVal(_)),f[N]=F|0}),new BigInt64Array(e.buffer,g,y*3).set(c),new Int32Array(e.buffer,g+y*24,y).set(f),D(7,0,g)},e.Object=function(n){let s=Object.keys(n),y=s.join(","),g=e.schemas,c=g.findIndex(T=>T.join(",")===y);if(c===-1){let T=g.reduce((F,N,u)=>N.length===s.length&&s.every(h=>N.includes(h))?F.concat(u):F,[]);if(T.length===1)c=T[0];else{if(T.length>1)throw Error(`Ambiguous schema for {${y}} \u2014 pass keys in schema order`);return e.Hash(n)}}let f=g[c],p=f.length,d=x(p*8),_=new BigInt64Array(p);for(let T=0;T<p;T++){let F=n[f[T]];F==null?F=v(F):typeof F=="string"?F=e.String(F):Array.isArray(F)&&(F=e.Array(F)),_[T]=L(F)}let E=new BigInt64Array(e.buffer,d,p);for(let T=0;T<p;T++)E[T]=_[T];return D(6,c,d)},e.read=function(n){if(Array.isArray(n))return n.map(f=>e.read(f));if(typeof n=="number"){if(n===n)return n;n=q(n)}else if(typeof n!="bigint")return n;if(!ue(n))return $(n);let s=o(),y=me(n),g=te(n),c=se(n);if(y===0&&c===0){if(g===1)return null;if(g===2)return;if(g===4)return!1;if(g===5)return!0}if(y===11&&e._extMap)return e._extMap[c];if(y===1){let f=c;for(;s.getInt32(f-4,!0)===-1;)f=s.getInt32(f-8,!0);let p=s.getInt32(f-8,!0),d=new Array(p);for(let _=0;_<p;_++)d[_]=e.read(s.getBigInt64(f+_*8,!0));return d}if(y===3){let f=g&7,[,p]=he[f],d=g&32?globalThis.Float16Array??(()=>{throw new Error("decoding a Float16Array result needs a host with Float16Array (Node \u2265 24 / modern browsers)")})():g&64?Uint8ClampedArray:[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][f];if(g&8){let E=s.getInt32(c,!0),T=s.getInt32(c+4,!0);return new d(e.buffer,T,E/p)}let _=s.getInt32(c-8,!0);return new d(e.buffer,c,_/p)}if(y===2){let f=s.getInt32(c-8,!0),p=new ArrayBuffer(f);return new Uint8Array(p).set(new Uint8Array(e.buffer,c,f)),p}if(y===4){if(g&O.SSO_BIT)return Fe(n);let f=s.getInt32(c-4,!0);return Se.decode(new Uint8Array(e.buffer,c,f))}if(y===6){let f=e.schemas[g];if(!f)return n;let p={};for(let d=0;d<f.length;d++)p[f[d]]=e.read(s.getBigInt64(c+d*8,!0));return p}if(y===7){let f=s.getInt32(c-8,!0),p=s.getInt32(c-4,!0),d={};for(let _=0,E=0;_<p&&E<f;_++)s.getBigInt64(c+_*24,!0)!==0n&&(d[e.read(s.getBigInt64(c+_*24+8,!0))]=e.read(s.getBigInt64(c+_*24+16,!0)),E++);return d}if(y===8){let f=s.getInt32(c-8,!0),p=s.getInt32(c-4,!0),d=new Set;for(let _=0;_<p&&d.size<f;_++)s.getBigInt64(c+_*16,!0)!==0n&&d.add(e.read(s.getBigInt64(c+_*16+8,!0)));return d}if(y===9){let f=s.getInt32(c-8,!0),p=s.getInt32(c-4,!0),d=new Map;for(let _=0;_<p&&d.size<f;_++)s.getBigInt64(c+_*24,!0)!==0n&&d.set(e.read(s.getBigInt64(c+_*24+8,!0)),e.read(s.getBigInt64(c+_*24+16,!0)));return d}return $(n)},e.write=function(n,s){let y=me(n),g=se(n),c=o();if(y===1){let f=c.getInt32(g-4,!0);if(s.length>f)throw Error(`write: ${s.length} exceeds capacity ${f}`);c.setInt32(g-8,s.length,!0);for(let p=0;p<s.length;p++)c.setBigInt64(g+p*8,L(v(s[p])),!0)}else if(y===3){let f=te(n),p=f&7,[,d,,_]=he[p],E=s.length*d;if(f&8){let T=c.getInt32(g,!0),F=c.getInt32(g+4,!0);if(E>T)throw Error(`write: ${E} bytes exceeds view size ${T}`);for(let N=0;N<s.length;N++)c[_](F+N*d,s[N],!0)}else{let T=c.getInt32(g-4,!0);if(E>T)throw Error(`write: ${E} bytes exceeds capacity ${T}`);c.setInt32(g-8,E,!0);for(let F=0;F<s.length;F++)c[_](g+F*d,s[F],!0)}}else if(y===6){let f=e.schemas[te(n)];if(!f)throw Error("write: unknown schema");for(let p of Object.keys(s)){let d=f.indexOf(p);d>=0&&c.setBigInt64(g+d*8,L(v(s[p])),!0)}}else throw Error(`write: unsupported type ${y}`)},e.alloc=x,e.reset=m;let k=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];k[65]=Uint8ClampedArray,globalThis.Float16Array&&(k[35]=globalThis.Float16Array);for(let[n,[s,y,,g]]of Object.entries(ne))e[n]=c=>{let f=c.length,p=f*y,d=S(p,p,p);if(k[s]&&c instanceof k[s])new k[s](e.buffer,d,f).set(c);else{let _=o();for(let E=0;E<f;E++)_[g](d+E*y,c[E],!0)}return D(3,s,d)};return e.allocTyped=(n,s)=>{let y=ne[n?.name];if(!y)throw Error(`allocTyped: unsupported type ${n?.name??n}`);let[g,c]=y,f=s*c,p=S(f,f,f);return{view:new n(e.buffer,p,s),box:D(3,g,p)}},re.add(e),e},je=(t,e,i)=>{let l=new Map,r=e?t:t.module||t,o=e||t.instance||t,a=new TextDecoder,m=ee(r,"jz:rest");if(m)try{for(let u of JSON.parse(a.decode(m)))l.set(typeof u=="string"?u:u.name,typeof u=="string"?0:u.fixed)}catch{}let A=new Map,I=ee(r,"jz:extparam");if(I)try{for(let u of JSON.parse(a.decode(I))){let h=new Set(u.p);u.d&&(h.def=new Map(Object.entries(u.d).map(([w,b])=>[Number(w),b]))),A.set(u.name,h)}}catch{}let x=new Map,S=ee(r,"jz:i64exp");if(S)try{for(let u of JSON.parse(a.decode(S)))x.set(u.name,{p:new Set(u.p||[]),r:!!u.r})}catch{}let B=ce(t),j=o.exports.__mt_drain,K=o.exports.__p_state,J=o.exports.__p_value,k=!!(j&&K&&J),n=[],s=(u,h,w)=>{let b=x.get(h);return u(typeof w=="bigint"?b?.p?.has(0)?w:$(w):b?.p?.has(0)?L(w):w)},y=u=>{let h=s(K,"__p_state",u);return typeof h=="bigint"?$(h):h},g=u=>{let h=s(J,"__p_value",u);return B?B.read(h):C(h)},c=()=>{j();for(let u=n.length-1;u>=0;u--){let h=n[u],w=y(h.raw);w<1||(n.splice(u,1),w===1?h.resolve(g(h.raw)):h.reject(g(h.raw)))}},f=(u,h)=>{j();let w=y(u);return w<0?h(u):w===1?Promise.resolve(g(u)):w===2?Promise.reject(g(u)):new Promise((b,U)=>n.push({raw:u,resolve:b,reject:U}))};if(k&&i){i.afterTick=c;let u=o.exports.__p_make,h=o.exports.__p_finish;if(u&&h){let w=x.get("__p_finish");i.pmake=()=>u(),i.pfinish=(b,U,M)=>h(w?.p?.has(0)?typeof b=="bigint"?b:L(b):typeof b=="bigint"?$(b):b,w?.p?.has(1)?q(U):U,w?.p?.has(2)?M:$(M))}}let p=(u,h)=>k?f(u,h):h(u),d=o.exports.__jz_last_err_bits,_=u=>{if(!(u instanceof WebAssembly.Exception)||!d)throw u;let h=d.value,w=B?B.read(h):C(h);if(w instanceof Error)throw w;let b=new Error(typeof w=="string"?w:String(w));throw b.cause=u,b.thrown=w,b},E={},T=(u,h,w,b)=>u?.has(h)?w===void 0&&u.def?.has(h)?u.def.get(h):w:b(w),F=(u,h,w)=>(b,U)=>{let M=T(h,U,b,w);if(u&&u.p.has(U)){if(typeof M=="string"){if(M.length>6||!/^[\x00-\x7f]*$/.test(M))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 Pe(M)}return L(M)}return typeof M=="bigint"?$(M):M};if(!B||B.scalar){for(let[u,h]of Object.entries(o.exports)){if(typeof h!="function"){E[u]=h;continue}let w=A.get(u),b=x.get(u),U=h.length;E[u]=(...M)=>{for(;M.length<U;)M.push(void 0);try{let R=h(...M.map(F(b,w,v)));return typeof R=="bigint"&&!(b&&b.r)?R:C(R)}catch(R){_(R)}}}return E}let N=B.wrapVal.bind(B);for(let[u,h]of Object.entries(o.exports))if(l.has(u)&&typeof h=="function"){let w=l.get(u),b=A.get(u),U=x.get(u);E[u]=(...M)=>{let R=M.slice(0,w).map(F(U,b,N));for(;R.length<w;){let V=R.length;R.push(U&&U.p.has(V)?X:$(X))}let Q=B.Array(M.slice(w));R.push(U&&U.p.has(w)?Q:$(Q));try{let V=h.apply(null,R);return typeof V=="bigint"&&!(U&&U.r)?V:p(V,Be=>B.read(Be))}catch(V){_(V)}}}else if(typeof h=="function"){let w=A.get(u),b=x.get(u),U=h.length;E[u]=(...M)=>{for(;M.length<U;)M.push(void 0);try{let R=h.apply(null,M.map(F(b,w,N)));return typeof R=="bigint"&&!(b&&b.r)?R:p(R,Q=>B.read(Q))}catch(R){_(R)}}}else E[u]=h;return E},ye=(t,e)=>{if(e!=null&&typeof e.then=="function"&&t.pmake){let i=t.pmake(),l=r=>L(t.mem?t.mem.wrapVal(r):v(r));return e.then(r=>{t.pfinish(i,1,l(r)),t.afterTick?.()},r=>{t.pfinish(i,2,l(r instanceof Error?r.message:r)),t.afterTick?.()}),typeof i=="bigint"?i:L(i)}return L(t.mem?t.mem.wrapVal(e):v(e))},De=new Set(["fetch"]),$e=t=>{let e={extMap:[null],mem:null};t._interp=t._interp||{};let i=(l,r,o)=>{let a=e.extMap[se(l)];if(a==null)throw new Error(`'${r}' \u2014 jz dispatched this ${o} to the host, but the receiver is not a host object (an unsupported builtin method, or a receiver type jz couldn't resolve)`);return a};return t._interp.__ext_prop=(l,r)=>{let o=e.mem.read(r),a=i(l,o,"property read");return L(e.mem.wrapVal(typeof a[o]=="function"?a[o].bind(a):a[o]))},t._interp.__ext_has=(l,r)=>{let o=e.mem.read(r);return o in i(l,o,"membership test")?1:0},t._interp.__ext_set=(l,r,o)=>{let a=e.mem.read(o);ArrayBuffer.isView(a)&&(a=a.slice());let m=e.mem.read(r);return i(l,m,"property write")[m]=a,1},t._interp.__ext_call=(l,r,o)=>{let a=e.mem.read(r),m=i(l,a,"method call"),A=e.mem.read(o);if(typeof m[a]!="function")throw new Error(`'${a}' is not a function on this host ${m?.constructor?.name??"object"}`);return ye(e,m[a].apply(m,A))},e},ve=(t,e,i)=>{let l=Ue(t);if(l.size){e.env||(e.env={});for(let r of l){if(e.env[r]||!De.has(r))continue;let o=globalThis[r];typeof o=="function"&&(e.env[r]=(...a)=>ye(i,o(...a.map(m=>i.mem?i.mem.read(m):C(m)))))}if(l.has("print")&&!e.env.print){let r=["","",""],o=[],a=A=>{(A===2?console.error:console.log)(r[A]),r[A]=""},m=(A,I,x)=>{let S=fe(i,A);r[I]+=String(S),x===32?r[I]+=" ":x===10&&a(I)};e.env.print=(A,I,x)=>{i.mem?m(A,I,x):o.push([A,I,x])},i.flushPrint=()=>{for(let A of o)m(...A);o.length=0}}if(l.has("now")&&!e.env.now&&(e.env.now=r=>r===1&&typeof performance<"u"?performance.now():Date.now()),l.has("rngSeed")&&!e.env.rngSeed&&(e.env.rngSeed=()=>{let r=new Uint32Array(1);return globalThis.crypto?.getRandomValues?globalThis.crypto.getRandomValues(r):r[0]=Math.random()*4294967296>>>0,r[0]|0}),l.has("random")&&!e.env.random&&(e.env.random=(r,o)=>{let a=new Uint8Array(i.mem.buffer,r,o);if(globalThis.crypto?.getRandomValues)globalThis.crypto.getRandomValues(a);else for(let m=0;m<o;m++)a[m]=Math.random()*256>>>0}),l.has("hardwareConcurrency")&&!e.env.hardwareConcurrency&&(e.env.hardwareConcurrency=()=>globalThis.navigator?.hardwareConcurrency??1),l.has("parseFloat")&&!e.env.parseFloat&&(e.env.parseFloat=r=>{let o=fe(i,r);return parseFloat(o)}),l.has("parseInt")&&!e.env.parseInt&&(e.env.parseInt=(r,o)=>{let a=fe(i,r);return parseInt(a,o||void 0)}),l.has("setTimeout")||l.has("clearTimeout")){let r=new Map,o=1;l.has("setTimeout")&&!e.env.setTimeout&&(e.env.setTimeout=(a,m,A)=>{let I=o++,x=()=>{i.invoke?.(a),i.afterTick?.()};if(A){let S=setInterval(x,m);r.set(I,()=>clearInterval(S))}else{let S=setTimeout(()=>{r.delete(I),x()},m);r.set(I,()=>clearTimeout(S))}return I}),l.has("clearTimeout")&&!e.env.clearTimeout&&(e.env.clearTimeout=a=>{let m=r.get(a);return m&&(m(),r.delete(a)),0})}if(l.has("requestAnimationFrame")||l.has("cancelAnimationFrame")){let r=new Map,o=1;l.has("requestAnimationFrame")&&!e.env.requestAnimationFrame&&(e.env.requestAnimationFrame=a=>{let m=o++,A=x=>{r.delete(m),i.invoke1?.(a,x),i.afterTick?.()},I=globalThis.requestAnimationFrame;if(typeof I=="function"){let x=I(A);r.set(m,()=>globalThis.cancelAnimationFrame?.(x))}else{let x=setTimeout(()=>A(typeof performance<"u"?performance.now():Date.now()),16);r.set(m,()=>clearTimeout(x))}return m}),l.has("cancelAnimationFrame")&&!e.env.cancelAnimationFrame&&(e.env.cancelAnimationFrame=a=>{let m=r.get(a);return m&&(m(),r.delete(a)),0})}}},xe={length:t=>t.length,charCodeAt:(t,e)=>t.charCodeAt(e)},_e=!1,Z=!1,Te=()=>{if(_e)return Z;_e=!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,...le.encode("wasm:js-string"),6,...le.encode("length"),0,0]),e=new WebAssembly.Module(t,{builtins:["js-string"]});new WebAssembly.Instance(e,{}),Z=!0}catch{Z=!1}return Z},ke=(t,e,i)=>{let{needsWasi:l,wasiImports:r}=Me(t,e),o=r||{};if(e._interp&&(o.env={...o.env,...e._interp}),!Te())for(let a of WebAssembly.Module.imports(t))a.module==="wasm:js-string"&&xe[a.name]&&(o["wasm:js-string"]||(o["wasm:js-string"]={}),o["wasm:js-string"][a.name]=xe[a.name]);if(e.imports)for(let[a,m]of Object.entries(e.imports)){o[a]||(o[a]={});for(let A of Object.getOwnPropertyNames(m)){let I=m[A],x=typeof I=="function"?I:I&&typeof I=="object"?I.fn:null;typeof x=="function"&&(o[a][A]=(...S)=>{let B=S.map(j=>i.mem?i.mem.read(j):C(j));return ye(i,x.call(m,...B))})}}ve(t,o,i),e.memory instanceof WebAssembly.Memory&&(re.has(e.memory)||(e.memory=ce(e.memory)),o.env||(o.env={}),o.env.memory=e.memory);for(let a of WebAssembly.Module.imports(t))if(a.kind==="global"&&a.module==="env"){let m=globalThis[a.name];if(m!==void 0){o.env||(o.env={});let A=i.extMap.indexOf(m);A===-1&&(A=i.extMap.length,i.extMap.push(m)),o.env[a.name]=new WebAssembly.Global({value:"i64",mutable:!1},D(11,0,A))}}return{imports:o,needsWasi:l}},We=(t,e,i,l,r,o)=>{l&&i._setMemory(e.exports.memory),e.exports._initialize?.(),o.invoke=e.exports.__invoke_closure||null,o.invoke1=e.exports.__invoke_closure1||null,de(e);let a=r.memory instanceof WebAssembly.Memory?r.memory:e.exports.memory,m={module:t,instance:e,exports:{...e.exports,memory:a},extMap:o.extMap},A=ce(m);return o.mem=A,o.flushPrint?.(),{exports:je(m,void 0,o),memory:A?.scalar?null:A,instance:e,module:t}},He=t=>{if(t instanceof WebAssembly.Module)return t;if(Te())try{return new WebAssembly.Module(t,{builtins:["js-string"]})}catch{return new WebAssembly.Module(t)}return new WebAssembly.Module(t)},Ze=(t,e={})=>{let i=$e(e),l=He(t),{imports:r,needsWasi:o}=ke(l,e,i),a=Object.keys(r).some(A=>A!=="_setMemory"),m=new WebAssembly.Instance(l,a?r:void 0);return We(l,m,r,o,e,i)};export{Re as FALSE_NAN,be as NULL_NAN,Le as TRUE_NAN,X as UNDEF_NAN,te as aux,v as coerce,q as f64ToI64,$ as i64ToF64,Ze as instantiate,ce as memory,se as offset,D as ptr,He as toModule,me as type,je as wrap};
|