watr 4.6.0 → 4.6.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.
- package/dist/watr.js +133 -10
- package/dist/watr.min.js +6 -6
- package/dist/watr.wasm +0 -0
- package/package.json +1 -1
- package/src/optimize.js +153 -10
- package/types/src/optimize.d.ts +43 -4
- package/types/src/optimize.d.ts.map +1 -1
package/dist/watr.js
CHANGED
|
@@ -3084,6 +3084,8 @@ var OPTS = {
|
|
|
3084
3084
|
// fold add+const into load/store offset
|
|
3085
3085
|
unbranch: true,
|
|
3086
3086
|
// remove redundant br at end of own block
|
|
3087
|
+
loopify: true,
|
|
3088
|
+
// collapse block+loop+brif while-idiom into loop+if
|
|
3087
3089
|
stripmut: true,
|
|
3088
3090
|
// strip mut from never-written globals
|
|
3089
3091
|
brif: true,
|
|
@@ -3312,6 +3314,28 @@ var treeshake = (ast) => {
|
|
|
3312
3314
|
return result;
|
|
3313
3315
|
};
|
|
3314
3316
|
var roundEven = (x) => x - Math.floor(x) !== 0.5 ? Math.round(x) : 2 * Math.round(x / 2);
|
|
3317
|
+
var _rb8 = new ArrayBuffer(8);
|
|
3318
|
+
var _rf64 = new Float64Array(_rb8);
|
|
3319
|
+
var _ri64 = new BigInt64Array(_rb8);
|
|
3320
|
+
var _rb4 = new ArrayBuffer(4);
|
|
3321
|
+
var _rf32 = new Float32Array(_rb4);
|
|
3322
|
+
var _ri32 = new Int32Array(_rb4);
|
|
3323
|
+
var i64FromF64 = (x) => {
|
|
3324
|
+
_rf64[0] = x;
|
|
3325
|
+
return _ri64[0];
|
|
3326
|
+
};
|
|
3327
|
+
var f64FromI64 = (x) => {
|
|
3328
|
+
_ri64[0] = BigInt.asIntN(64, x);
|
|
3329
|
+
return _rf64[0];
|
|
3330
|
+
};
|
|
3331
|
+
var i32FromF32 = (x) => {
|
|
3332
|
+
_rf32[0] = x;
|
|
3333
|
+
return _ri32[0];
|
|
3334
|
+
};
|
|
3335
|
+
var f32FromI32 = (x) => {
|
|
3336
|
+
_ri32[0] = x | 0;
|
|
3337
|
+
return _rf32[0];
|
|
3338
|
+
};
|
|
3315
3339
|
var i32c = (fn) => (a, b) => fn(a, b) ? 1 : 0;
|
|
3316
3340
|
var u32c = (fn) => (a, b) => fn(a >>> 0, b >>> 0) ? 1 : 0;
|
|
3317
3341
|
var i64c = (fn) => (a, b) => fn(a, b) ? 1 : 0;
|
|
@@ -3415,7 +3439,23 @@ var FOLDABLE = {
|
|
|
3415
3439
|
"f64.ceil": [Math.ceil, "f64"],
|
|
3416
3440
|
"f64.floor": [Math.floor, "f64"],
|
|
3417
3441
|
"f64.trunc": [Math.trunc, "f64"],
|
|
3418
|
-
"f64.nearest": [roundEven, "f64"]
|
|
3442
|
+
"f64.nearest": [roundEven, "f64"],
|
|
3443
|
+
// Bit-exact reinterprets (preserve NaN payloads)
|
|
3444
|
+
"i32.reinterpret_f32": [i32FromF32, "i32"],
|
|
3445
|
+
"f32.reinterpret_i32": [f32FromI32, "f32"],
|
|
3446
|
+
"i64.reinterpret_f64": [i64FromF64, "i64"],
|
|
3447
|
+
"f64.reinterpret_i64": [f64FromI64, "f64"],
|
|
3448
|
+
// Numeric conversions (value-preserving where representable)
|
|
3449
|
+
"f32.convert_i32_s": [(a) => Math.fround(a | 0), "f32"],
|
|
3450
|
+
"f32.convert_i32_u": [(a) => Math.fround(a >>> 0), "f32"],
|
|
3451
|
+
"f32.convert_i64_s": [(a) => Math.fround(Number(BigInt.asIntN(64, a))), "f32"],
|
|
3452
|
+
"f32.convert_i64_u": [(a) => Math.fround(Number(BigInt.asUintN(64, a))), "f32"],
|
|
3453
|
+
"f64.convert_i32_s": [(a) => a | 0, "f64"],
|
|
3454
|
+
"f64.convert_i32_u": [(a) => a >>> 0, "f64"],
|
|
3455
|
+
"f64.convert_i64_s": [(a) => Number(BigInt.asIntN(64, a)), "f64"],
|
|
3456
|
+
"f64.convert_i64_u": [(a) => Number(BigInt.asUintN(64, a)), "f64"],
|
|
3457
|
+
"f32.demote_f64": [(a) => Math.fround(a), "f32"],
|
|
3458
|
+
"f64.promote_f32": [(a) => Math.fround(a), "f64"]
|
|
3419
3459
|
};
|
|
3420
3460
|
var getConst = (node) => {
|
|
3421
3461
|
if (!Array.isArray(node) || node.length !== 2) return null;
|
|
@@ -4154,6 +4194,35 @@ var targetsLabel = (body, label) => {
|
|
|
4154
4194
|
return found;
|
|
4155
4195
|
};
|
|
4156
4196
|
var mergeBlocks = (ast) => {
|
|
4197
|
+
walkPost2(ast, (node) => {
|
|
4198
|
+
if (!Array.isArray(node) || node[0] !== "block") return;
|
|
4199
|
+
let bi = 1, label = null;
|
|
4200
|
+
if (typeof node[1] === "string" && node[1][0] === "$") {
|
|
4201
|
+
label = node[1];
|
|
4202
|
+
bi = 2;
|
|
4203
|
+
}
|
|
4204
|
+
let hasResult = false;
|
|
4205
|
+
while (bi < node.length) {
|
|
4206
|
+
const c = node[bi];
|
|
4207
|
+
if (Array.isArray(c) && (c[0] === "param" || c[0] === "type")) {
|
|
4208
|
+
bi++;
|
|
4209
|
+
continue;
|
|
4210
|
+
}
|
|
4211
|
+
if (Array.isArray(c) && c[0] === "result") {
|
|
4212
|
+
hasResult = true;
|
|
4213
|
+
bi++;
|
|
4214
|
+
continue;
|
|
4215
|
+
}
|
|
4216
|
+
break;
|
|
4217
|
+
}
|
|
4218
|
+
const body = node.slice(bi);
|
|
4219
|
+
if (!hasResult || body.length !== 1) return;
|
|
4220
|
+
const only = body[0];
|
|
4221
|
+
if (!Array.isArray(only)) return;
|
|
4222
|
+
if (label && targetsLabel(body, label)) return;
|
|
4223
|
+
node.length = 0;
|
|
4224
|
+
for (const tok of only) node.push(tok);
|
|
4225
|
+
});
|
|
4157
4226
|
walk2(ast, (node) => {
|
|
4158
4227
|
if (!isScopeNode(node)) return;
|
|
4159
4228
|
let i = 1;
|
|
@@ -4168,17 +4237,13 @@ var mergeBlocks = (ast) => {
|
|
|
4168
4237
|
label = child[1];
|
|
4169
4238
|
bi = 2;
|
|
4170
4239
|
}
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
const c = child[j];
|
|
4240
|
+
while (bi < child.length) {
|
|
4241
|
+
const c = child[bi];
|
|
4174
4242
|
if (Array.isArray(c) && (c[0] === "param" || c[0] === "result" || c[0] === "type")) {
|
|
4175
|
-
|
|
4176
|
-
|
|
4243
|
+
bi++;
|
|
4244
|
+
continue;
|
|
4177
4245
|
}
|
|
4178
|
-
|
|
4179
|
-
if (typed) {
|
|
4180
|
-
i++;
|
|
4181
|
-
continue;
|
|
4246
|
+
break;
|
|
4182
4247
|
}
|
|
4183
4248
|
const body = child.slice(bi);
|
|
4184
4249
|
if (label && targetsLabel(body, label)) {
|
|
@@ -4540,6 +4605,63 @@ var unbranch = (ast) => {
|
|
|
4540
4605
|
});
|
|
4541
4606
|
return ast;
|
|
4542
4607
|
};
|
|
4608
|
+
var loopify = (ast) => {
|
|
4609
|
+
walk2(ast, (node) => {
|
|
4610
|
+
if (!Array.isArray(node) || node[0] !== "block") return;
|
|
4611
|
+
let bi = 1, label = null;
|
|
4612
|
+
if (typeof node[1] === "string" && node[1][0] === "$") {
|
|
4613
|
+
label = node[1];
|
|
4614
|
+
bi = 2;
|
|
4615
|
+
}
|
|
4616
|
+
if (!label) return;
|
|
4617
|
+
while (bi < node.length) {
|
|
4618
|
+
const c = node[bi];
|
|
4619
|
+
if (Array.isArray(c) && c[0] === "type") {
|
|
4620
|
+
bi++;
|
|
4621
|
+
continue;
|
|
4622
|
+
}
|
|
4623
|
+
if (Array.isArray(c) && (c[0] === "param" || c[0] === "result")) return;
|
|
4624
|
+
break;
|
|
4625
|
+
}
|
|
4626
|
+
if (node.length - bi !== 1) return;
|
|
4627
|
+
const loop = node[bi];
|
|
4628
|
+
if (!Array.isArray(loop) || loop[0] !== "loop") return;
|
|
4629
|
+
let li = 1, loopLabel = null;
|
|
4630
|
+
if (typeof loop[1] === "string" && loop[1][0] === "$") {
|
|
4631
|
+
loopLabel = loop[1];
|
|
4632
|
+
li = 2;
|
|
4633
|
+
}
|
|
4634
|
+
const loopHeader = [];
|
|
4635
|
+
while (li < loop.length) {
|
|
4636
|
+
const c = loop[li];
|
|
4637
|
+
if (Array.isArray(c) && c[0] === "type") {
|
|
4638
|
+
loopHeader.push(c);
|
|
4639
|
+
li++;
|
|
4640
|
+
continue;
|
|
4641
|
+
}
|
|
4642
|
+
if (Array.isArray(c) && (c[0] === "param" || c[0] === "result")) return;
|
|
4643
|
+
break;
|
|
4644
|
+
}
|
|
4645
|
+
const body = loop.slice(li);
|
|
4646
|
+
if (body.length < 2) return;
|
|
4647
|
+
const head = body[0];
|
|
4648
|
+
const tail = body[body.length - 1];
|
|
4649
|
+
if (!Array.isArray(head) || head[0] !== "br_if" || head[1] !== label || head.length !== 3) return;
|
|
4650
|
+
if (!Array.isArray(tail) || tail[0] !== "br" || tail[1] !== loopLabel || tail.length !== 2) return;
|
|
4651
|
+
const inner = body.slice(1, -1);
|
|
4652
|
+
if (targetsLabel(inner, label)) return;
|
|
4653
|
+
let cond = head[2];
|
|
4654
|
+
if (Array.isArray(cond) && cond[0] === "i32.eqz" && cond.length === 2) cond = cond[1];
|
|
4655
|
+
else cond = ["i32.eqz", cond];
|
|
4656
|
+
const newLoop = ["loop"];
|
|
4657
|
+
if (loopLabel) newLoop.push(loopLabel);
|
|
4658
|
+
for (const h of loopHeader) newLoop.push(h);
|
|
4659
|
+
newLoop.push(["if", cond, ["then", ...inner, tail]]);
|
|
4660
|
+
node.length = 0;
|
|
4661
|
+
for (const tok of newLoop) node.push(tok);
|
|
4662
|
+
});
|
|
4663
|
+
return ast;
|
|
4664
|
+
};
|
|
4543
4665
|
var stripmut = (ast) => {
|
|
4544
4666
|
if (!Array.isArray(ast) || ast[0] !== "module") return ast;
|
|
4545
4667
|
const written = /* @__PURE__ */ new Set();
|
|
@@ -5006,6 +5128,7 @@ function optimize(ast, opts = true) {
|
|
|
5006
5128
|
if (opts.inline) ast = inline(ast);
|
|
5007
5129
|
if (opts.offset) ast = offset(ast);
|
|
5008
5130
|
if (opts.unbranch) ast = unbranch(ast);
|
|
5131
|
+
if (opts.loopify) ast = loopify(ast);
|
|
5009
5132
|
if (opts.brif) ast = brif(ast);
|
|
5010
5133
|
if (opts.foldarms) ast = foldarms(ast);
|
|
5011
5134
|
if (opts.deadcode) ast = deadcode(ast);
|
package/dist/watr.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
`?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)};var Vt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Yt=/^[+-]?(?:0x[\da-f]+|\d+)$/i,Se=new TextEncoder,Ne=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),Ht={n:10,r:13,t:9,'"':34,"'":39,"\\":92},dt=t=>{let e=[],r=1,i,s,n="",l=()=>(n&&e.push(...Se.encode(n)),n="");for(;r<t.length-1;)s=t[r++],i=null,s==="\\"&&(t[r]==="u"?(r++,r++,s=String.fromCodePoint(parseInt(t.slice(r,r=t.indexOf("}",r)),16)),r++):Ht[t[r]]?i=Ht[t[r++]]:isNaN(i=parseInt(t[r]+t[r+1],16))?s+=t[r]:(r++,r++)),i!=null?(l(),e.push(i)):n+=s;return l(),e.valueOf=()=>t,e},Xt=t=>Ne.decode(new Uint8Array(dt(t)));var g=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):H.parse(t)),typeof t=="bigint"){for(;;){let i=Number(t&0x7Fn);if(t>>=7n,t===0n){e.push(i);break}e.push(i|128)}return e}let r=t&127;return t>>>=7,t===0?(e.push(r),e):(e.push(r|128),g(t,e))};function ze(t){let e=[];for(let r=0;r<5;r++){let i=t&127;t>>>=7,r<4&&(i|=128),e.push(i)}return e}function H(t,e=[]){for(typeof t=="string"&&(t=H.parse(t));;){let r=Number(t&127);if(t>>=7,t===0&&!(r&64)||t===-1&&r&64){e.push(r);break}e.push(r|128)}return e}var Zt=t=>!Vt.test(t)&&Yt.test(t=t.replaceAll("_",""))?t:S(`Bad int ${t}`),Te=H,Ee=H;H.parse=t=>(t=parseInt(Zt(t)),(t<-2147483648||t>4294967295)&&S("i32 constant out of range"),t);function ct(t,e=[]){for(typeof t=="string"?t=ct.parse(t):typeof t=="number"&&(t=BigInt(t)),typeof t=="bigint"&&t>0x7fffffffffffffffn&&(t=t-0x10000000000000000n);;){let r=Number(t&0x7Fn);if(t>>=7n,t===0n&&!(r&64)||t===-1n&&r&64){e.push(r);break}e.push(r|128)}return e}var gt=new ArrayBuffer(8),X=new Uint8Array(gt),Ue=new Int32Array(gt),qe=new Float32Array(gt),Oe=new Float64Array(gt),Ot=new BigInt64Array(gt);ct.parse=t=>{t=Zt(t);let e=t[0]==="-",r=e?t.slice(1):t,i;if(r[0]==="0"&&(r[1]==="x"||r[1]==="X")){let n=r.slice(2).replace(/^0+/,"")||"0";i=e?"8000000000000000":"ffffffffffffffff",(n.length>16||n.length===16&&n.toLowerCase()>i)&&S("i64 constant out of range")}else{let n=r.replace(/^0+/,"")||"0";i=e?"9223372036854775808":"18446744073709551615",(n.length>i.length||n.length===i.length&&n>i)&&S("i64 constant out of range")}let s=BigInt(r);return e&&(s=0n-s),Ot[0]=s,Ot[0]};var Fe=2147483648,Ce=2139095040,Le=4194304;function ut(t,e,r){return typeof t=="string"&&(r=t.indexOf("nan"))>=0?(e=t[r+3]===":"?H.parse(t.slice(r+4)):Le,e|=Ce,t[0]==="-"&&(e|=Fe),Ue[0]=e):(e=typeof t=="string"?ut.parse(t):t,qe[0]=e),[X[0],X[1],X[2],X[3]]}var De=0x8000000000000000n,We=0x7ff0000000000000n,Re=0x8000000000000n;function ot(t,e,r){return typeof t=="string"&&(r=t.indexOf("nan"))>=0?(e=t[r+3]===":"?ct.parse(t.slice(r+4)):Re,e|=We,t[0]==="-"&&(e|=De),Ot[0]=e):(e=typeof t=="string"?ot.parse(t):t,Oe[0]=e),[X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7]]}ot.parse=(t,e=Number.MAX_VALUE)=>{t=t.replaceAll("_","");let r=1;if(t[0]==="-"?(r=-1,t=t.slice(1)):t[0]==="+"&&(t=t.slice(1)),t[1]==="x"){let[i,s="0"]=t.split(/p/i),[n,l=""]=i.split("."),f=l.length??0,o=0;for(let y=n.length-1;y>=2;y--){let m=parseInt(n[y],16);o+=m*16**(n.length-1-y)}let a=l?parseInt("0x"+l)/16**f:0;s=parseInt(s,10);let c=r*(o+a)*2**s;return c=Math.max(-e,Math.min(e,c)),c}return t.includes("nan")?r<0?NaN:NaN:t.includes("inf")?r*(1/0):r*parseFloat(t)};ut.parse=t=>ot.parse(t,34028234663852886e22);var Ft=t=>{let e=BigInt(typeof t=="string"?t.replaceAll("_",""):t),r=new Uint8Array(16);for(let i=0;i<16;i++)r[i]=Number(e&0xffn),e>>=8n;return[...r]};var ht=["unreachable","nop","block block","loop block","if block","else null","then null",,"throw tagidx",,"throw_ref","end end","br labelidx","br_if labelidx","br_table br_table","return","call funcidx","call_indirect call_indirect","return_call funcidx","return_call_indirect call_indirect","call_ref typeidx","return_call_ref typeidx",,,,,"drop","select select","",,,"try_table try_table","local.get localidx","local.set localidx","local.tee localidx","global.get globalidx","global.set globalidx","table.get tableidx","table.set tableidx",,"i32.load memarg","i64.load memarg","f32.load memarg","f64.load memarg","i32.load8_s memarg","i32.load8_u memarg","i32.load16_s memarg","i32.load16_u memarg","i64.load8_s memarg","i64.load8_u memarg","i64.load16_s memarg","i64.load16_u memarg","i64.load32_s memarg","i64.load32_u memarg","i32.store memarg","i64.store memarg","f32.store memarg","f64.store memarg","i32.store8 memarg","i32.store16 memarg","i64.store8 memarg","i64.store16 memarg","i64.store32 memarg","memory.size opt_memory","memory.grow opt_memory","i32.const i32","i64.const i64","f32.const f32","f64.const f64","i32.eqz","i32.eq","i32.ne","i32.lt_s","i32.lt_u","i32.gt_s","i32.gt_u","i32.le_s","i32.le_u","i32.ge_s","i32.ge_u","i64.eqz","i64.eq","i64.ne","i64.lt_s","i64.lt_u","i64.gt_s","i64.gt_u","i64.le_s","i64.le_u","i64.ge_s","i64.ge_u","f32.eq","f32.ne","f32.lt","f32.gt","f32.le","f32.ge","f64.eq","f64.ne","f64.lt","f64.gt","f64.le","f64.ge","i32.clz","i32.ctz","i32.popcnt","i32.add","i32.sub","i32.mul","i32.div_s","i32.div_u","i32.rem_s","i32.rem_u","i32.and","i32.or","i32.xor","i32.shl","i32.shr_s","i32.shr_u","i32.rotl","i32.rotr","i64.clz","i64.ctz","i64.popcnt","i64.add","i64.sub","i64.mul","i64.div_s","i64.div_u","i64.rem_s","i64.rem_u","i64.and","i64.or","i64.xor","i64.shl","i64.shr_s","i64.shr_u","i64.rotl","i64.rotr","f32.abs","f32.neg","f32.ceil","f32.floor","f32.trunc","f32.nearest","f32.sqrt","f32.add","f32.sub","f32.mul","f32.div","f32.min","f32.max","f32.copysign","f64.abs","f64.neg","f64.ceil","f64.floor","f64.trunc","f64.nearest","f64.sqrt","f64.add","f64.sub","f64.mul","f64.div","f64.min","f64.max","f64.copysign","i32.wrap_i64","i32.trunc_f32_s","i32.trunc_f32_u","i32.trunc_f64_s","i32.trunc_f64_u","i64.extend_i32_s","i64.extend_i32_u","i64.trunc_f32_s","i64.trunc_f32_u","i64.trunc_f64_s","i64.trunc_f64_u","f32.convert_i32_s","f32.convert_i32_u","f32.convert_i64_s","f32.convert_i64_u","f32.demote_f64","f64.convert_i32_s","f64.convert_i32_u","f64.convert_i64_s","f64.convert_i64_u","f64.promote_f32","i32.reinterpret_f32","i64.reinterpret_f64","f32.reinterpret_i32","f64.reinterpret_i64","i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s",,,,,,,,,,,,"ref.null ref_null","ref.is_null","ref.func funcidx","ref.eq","ref.as_non_null","br_on_null labelidx","br_on_non_null labelidx",,,,,,,,,,"cont.new typeidx","cont.bind cont_bind","suspend tagidx","resume resume","resume_throw resume_throw","resume_throw_ref resume_throw_ref","switch switch_cont",,,,,,,,,,,,,,,,,,,,,["struct.new typeidx","struct.new_default typeidx","struct.get typeidx_field","struct.get_s typeidx_field","struct.get_u typeidx_field","struct.set typeidx_field","array.new typeidx","array.new_default typeidx","array.new_fixed typeidx_multi","array.new_data typeidx_dataidx","array.new_elem typeidx_elemidx","array.get typeidx","array.get_s typeidx","array.get_u typeidx","array.set typeidx","array.len","array.fill typeidx","array.copy typeidx_typeidx","array.init_data typeidx_dataidx","array.init_elem typeidx_elemidx","ref.test reftype","ref.test_null reftype","ref.cast reftype","ref.cast_null reftype","br_on_cast reftype2","br_on_cast_fail reftype2","any.convert_extern","extern.convert_any","ref.i31","i31.get_s","i31.get_u",,"struct.new_desc typeidx","struct.new_default_desc typeidx","ref.get_desc typeidx","ref.cast_desc_eq reftype",,"br_on_cast_desc_eq reftype2","br_on_cast_desc_eq_fail reftype2",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"string.new_utf8 memoryidx?","string.new_wtf16 memoryidx?","string.const stringidx","string.measure_utf8","string.measure_wtf8","string.measure_wtf16","string.encode_utf8 memoryidx?","string.encode_wtf16 memoryidx?","string.concat","string.eq","string.is_usv_sequence","string.new_lossy_utf8 memoryidx?","string.new_wtf8 memoryidx?","string.encode_lossy_utf8 memoryidx?","string.encode_wtf8 memoryidx?",,"string.as_wtf8","stringview_wtf8.advance","stringview_wtf8.encode_utf8 memoryidx?","stringview_wtf8.slice","stringview_wtf8.encode_lossy_utf8 memoryidx?","stringview_wtf8.encode_wtf8 memoryidx?",,,"string.as_wtf16","stringview_wtf16.length","stringview_wtf16.get_codeunit","stringview_wtf16.encode memoryidx?","stringview_wtf16.slice",,,,"string.as_iter","stringview_iter.next","stringview_iter.advance","stringview_iter.rewind","stringview_iter.slice",,,,,,,,,,,,"string.new_utf8_array","string.new_wtf16_array","string.encode_utf8_array","string.encode_wtf16_array","string.new_lossy_utf8_array","string.new_wtf8_array","string.encode_lossy_utf8_array","string.encode_wtf8_array"],["i32.trunc_sat_f32_s","i32.trunc_sat_f32_u","i32.trunc_sat_f64_s","i32.trunc_sat_f64_u","i64.trunc_sat_f32_s","i64.trunc_sat_f32_u","i64.trunc_sat_f64_s","i64.trunc_sat_f64_u","memory.init dataidx_memoryidx","data.drop dataidx","memory.copy memoryidx_memoryidx","memory.fill memoryidx?","table.init reversed","elem.drop elemidx","table.copy tableidx_tableidx","table.grow tableidx","table.size tableidx","table.fill tableidx",,"i64.add128","i64.sub128","i64.mul_wide_s","i64.mul_wide_u",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"f32.sqrt_ceil","f32.add_ceil","f32.sub_ceil","f32.mul_ceil","f32.div_ceil","f64.sqrt_ceil","f64.add_ceil","f64.sub_ceil","f64.mul_ceil","f64.div_ceil","f32.convert_ceil_i32_s","f32.convert_ceil_i32_u","f32.convert_ceil_i64_s","f32.convert_ceil_i64_u","f32.demote_ceil_f64","f64.convert_ceil_i32_s","f64.convert_ceil_i32_u","f64.convert_ceil_i64_s","f64.convert_ceil_i64_u","f64.promote_ceil_f32","f32.sqrt_floor","f32.add_floor","f32.sub_floor","f32.mul_floor","f32.div_floor","f64.sqrt_floor","f64.add_floor","f64.sub_floor","f64.mul_floor","f64.div_floor","f32.convert_floor_i32_s","f32.convert_floor_i32_u","f32.convert_floor_i64_s","f32.convert_floor_i64_u","f32.demote_floor_f64","f64.convert_floor_i32_s","f64.convert_floor_i32_u","f64.convert_floor_i64_s","f64.convert_floor_i64_u","f64.promote_floor_f32","f32.sqrt_trunc","f32.add_trunc","f32.sub_trunc","f32.mul_trunc","f32.div_trunc","f64.sqrt_trunc","f64.add_trunc","f64.sub_trunc","f64.mul_trunc","f64.div_trunc","f32.convert_trunc_i32_s","f32.convert_trunc_i32_u","f32.convert_trunc_i64_s","f32.convert_trunc_i64_u","f32.demote_trunc_f64","f64.convert_trunc_i32_s","f64.convert_trunc_i32_u","f64.convert_trunc_i64_s","f64.convert_trunc_i64_u","f64.promote_trunc_f32"],["v128.load memarg","v128.load8x8_s memarg","v128.load8x8_u memarg","v128.load16x4_s memarg","v128.load16x4_u memarg","v128.load32x2_s memarg","v128.load32x2_u memarg","v128.load8_splat memarg","v128.load16_splat memarg","v128.load32_splat memarg","v128.load64_splat memarg","v128.store memarg","v128.const v128const","i8x16.shuffle shuffle","i8x16.swizzle","i8x16.splat","i16x8.splat","i32x4.splat","i64x2.splat","f32x4.splat","f64x2.splat","i8x16.extract_lane_s laneidx","i8x16.extract_lane_u laneidx","i8x16.replace_lane laneidx","i16x8.extract_lane_s laneidx","i16x8.extract_lane_u laneidx","i16x8.replace_lane laneidx","i32x4.extract_lane laneidx","i32x4.replace_lane laneidx","i64x2.extract_lane laneidx","i64x2.replace_lane laneidx","f32x4.extract_lane laneidx","f32x4.replace_lane laneidx","f64x2.extract_lane laneidx","f64x2.replace_lane laneidx","i8x16.eq","i8x16.ne","i8x16.lt_s","i8x16.lt_u","i8x16.gt_s","i8x16.gt_u","i8x16.le_s","i8x16.le_u","i8x16.ge_s","i8x16.ge_u","i16x8.eq","i16x8.ne","i16x8.lt_s","i16x8.lt_u","i16x8.gt_s","i16x8.gt_u","i16x8.le_s","i16x8.le_u","i16x8.ge_s","i16x8.ge_u","i32x4.eq","i32x4.ne","i32x4.lt_s","i32x4.lt_u","i32x4.gt_s","i32x4.gt_u","i32x4.le_s","i32x4.le_u","i32x4.ge_s","i32x4.ge_u","f32x4.eq","f32x4.ne","f32x4.lt","f32x4.gt","f32x4.le","f32x4.ge","f64x2.eq","f64x2.ne","f64x2.lt","f64x2.gt","f64x2.le","f64x2.ge","v128.not","v128.and","v128.andnot","v128.or","v128.xor","v128.bitselect","v128.any_true","v128.load8_lane memlane","v128.load16_lane memlane","v128.load32_lane memlane","v128.load64_lane memlane","v128.store8_lane memlane","v128.store16_lane memlane","v128.store32_lane memlane","v128.store64_lane memlane","v128.load32_zero memarg","v128.load64_zero memarg","f32x4.demote_f64x2_zero","f64x2.promote_low_f32x4","i8x16.abs","i8x16.neg","i8x16.popcnt","i8x16.all_true","i8x16.bitmask","i8x16.narrow_i16x8_s","i8x16.narrow_i16x8_u","f32x4.ceil","f32x4.floor","f32x4.trunc","f32x4.nearest","i8x16.shl","i8x16.shr_s","i8x16.shr_u","i8x16.add","i8x16.add_sat_s","i8x16.add_sat_u","i8x16.sub","i8x16.sub_sat_s","i8x16.sub_sat_u","f64x2.ceil","f64x2.floor","i8x16.min_s","i8x16.min_u","i8x16.max_s","i8x16.max_u","f64x2.trunc","i8x16.avgr_u","i16x8.extadd_pairwise_i8x16_s","i16x8.extadd_pairwise_i8x16_u","i32x4.extadd_pairwise_i16x8_s","i32x4.extadd_pairwise_i16x8_u","i16x8.abs","i16x8.neg","i16x8.q15mulr_sat_s","i16x8.all_true","i16x8.bitmask","i16x8.narrow_i32x4_s","i16x8.narrow_i32x4_u","i16x8.extend_low_i8x16_s","i16x8.extend_high_i8x16_s","i16x8.extend_low_i8x16_u","i16x8.extend_high_i8x16_u","i16x8.shl","i16x8.shr_s","i16x8.shr_u","i16x8.add","i16x8.add_sat_s","i16x8.add_sat_u","i16x8.sub","i16x8.sub_sat_s","i16x8.sub_sat_u","f64x2.nearest","i16x8.mul","i16x8.min_s","i16x8.min_u","i16x8.max_s","i16x8.max_u",,"i16x8.avgr_u","i16x8.extmul_low_i8x16_s","i16x8.extmul_high_i8x16_s","i16x8.extmul_low_i8x16_u","i16x8.extmul_high_i8x16_u","i32x4.abs","i32x4.neg",,"i32x4.all_true","i32x4.bitmask",,,"i32x4.extend_low_i16x8_s","i32x4.extend_high_i16x8_s","i32x4.extend_low_i16x8_u","i32x4.extend_high_i16x8_u","i32x4.shl","i32x4.shr_s","i32x4.shr_u","i32x4.add",,,"i32x4.sub",,,,"i32x4.mul","i32x4.min_s","i32x4.min_u","i32x4.max_s","i32x4.max_u","i32x4.dot_i16x8_s",,"i32x4.extmul_low_i16x8_s","i32x4.extmul_high_i16x8_s","i32x4.extmul_low_i16x8_u","i32x4.extmul_high_i16x8_u","i64x2.abs","i64x2.neg",,"i64x2.all_true","i64x2.bitmask",,,"i64x2.extend_low_i32x4_s","i64x2.extend_high_i32x4_s","i64x2.extend_low_i32x4_u","i64x2.extend_high_i32x4_u","i64x2.shl","i64x2.shr_s","i64x2.shr_u","i64x2.add",,,"i64x2.sub",,,,"i64x2.mul","i64x2.eq","i64x2.ne","i64x2.lt_s","i64x2.gt_s","i64x2.le_s","i64x2.ge_s","i64x2.extmul_low_i32x4_s","i64x2.extmul_high_i32x4_s","i64x2.extmul_low_i32x4_u","i64x2.extmul_high_i32x4_u","f32x4.abs","f32x4.neg",,"f32x4.sqrt","f32x4.add","f32x4.sub","f32x4.mul","f32x4.div","f32x4.min","f32x4.max","f32x4.pmin","f32x4.pmax","f64x2.abs","f64x2.neg",,"f64x2.sqrt","f64x2.add","f64x2.sub","f64x2.mul","f64x2.div","f64x2.min","f64x2.max","f64x2.pmin","f64x2.pmax","i32x4.trunc_sat_f32x4_s","i32x4.trunc_sat_f32x4_u","f32x4.convert_i32x4_s","f32x4.convert_i32x4_u","i32x4.trunc_sat_f64x2_s_zero","i32x4.trunc_sat_f64x2_u_zero","f64x2.convert_low_i32x4_s","f64x2.convert_low_i32x4_u","i8x16.relaxed_swizzle","i32x4.relaxed_trunc_f32x4_s","i32x4.relaxed_trunc_f32x4_u","i32x4.relaxed_trunc_f64x2_s_zero","i32x4.relaxed_trunc_f64x2_u_zero","f32x4.relaxed_madd","f32x4.relaxed_nmadd","f64x2.relaxed_madd","f64x2.relaxed_nmadd","i8x16.relaxed_laneselect","i16x8.relaxed_laneselect","i32x4.relaxed_laneselect","i64x2.relaxed_laneselect","f32x4.relaxed_min","f32x4.relaxed_max","f64x2.relaxed_min","f64x2.relaxed_max","i16x8.relaxed_q15mulr_s","i16x8.relaxed_dot_i8x16_i7x16_s","i32x4.relaxed_dot_i8x16_i7x16_add_s"],["memory.atomic.notify memarg","memory.atomic.wait32 memarg","memory.atomic.wait64 memarg","atomic.fence opt_memory",,,,,,,,,,,,,"i32.atomic.load memarg","i64.atomic.load memarg","i32.atomic.load8_u memarg","i32.atomic.load16_u memarg","i64.atomic.load8_u memarg","i64.atomic.load16_u memarg","i64.atomic.load32_u memarg","i32.atomic.store memarg","i64.atomic.store memarg","i32.atomic.store8 memarg","i32.atomic.store16 memarg","i64.atomic.store8 memarg","i64.atomic.store16 memarg","i64.atomic.store32 memarg","i32.atomic.rmw.add memarg","i64.atomic.rmw.add memarg","i32.atomic.rmw8.add_u memarg","i32.atomic.rmw16.add_u memarg","i64.atomic.rmw8.add_u memarg","i64.atomic.rmw16.add_u memarg","i64.atomic.rmw32.add_u memarg","i32.atomic.rmw.sub memarg","i64.atomic.rmw.sub memarg","i32.atomic.rmw8.sub_u memarg","i32.atomic.rmw16.sub_u memarg","i64.atomic.rmw8.sub_u memarg","i64.atomic.rmw16.sub_u memarg","i64.atomic.rmw32.sub_u memarg","i32.atomic.rmw.and memarg","i64.atomic.rmw.and memarg","i32.atomic.rmw8.and_u memarg","i32.atomic.rmw16.and_u memarg","i64.atomic.rmw8.and_u memarg","i64.atomic.rmw16.and_u memarg","i64.atomic.rmw32.and_u memarg","i32.atomic.rmw.or memarg","i64.atomic.rmw.or memarg","i32.atomic.rmw8.or_u memarg","i32.atomic.rmw16.or_u memarg","i64.atomic.rmw8.or_u memarg","i64.atomic.rmw16.or_u memarg","i64.atomic.rmw32.or_u memarg","i32.atomic.rmw.xor memarg","i64.atomic.rmw.xor memarg","i32.atomic.rmw8.xor_u memarg","i32.atomic.rmw16.xor_u memarg","i64.atomic.rmw8.xor_u memarg","i64.atomic.rmw16.xor_u memarg","i64.atomic.rmw32.xor_u memarg","i32.atomic.rmw.xchg memarg","i64.atomic.rmw.xchg memarg","i32.atomic.rmw8.xchg_u memarg","i32.atomic.rmw16.xchg_u memarg","i64.atomic.rmw8.xchg_u memarg","i64.atomic.rmw16.xchg_u memarg","i64.atomic.rmw32.xchg_u memarg","i32.atomic.rmw.cmpxchg memarg","i64.atomic.rmw.cmpxchg memarg","i32.atomic.rmw8.cmpxchg_u memarg","i32.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw8.cmpxchg_u memarg","i64.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw32.cmpxchg_u memarg"]],C={custom:0,type:1,import:2,func:3,table:4,memory:5,tag:13,strings:14,global:6,export:7,start:8,elem:9,datacount:12,code:10,data:11},D={i8:120,i16:119,i32:127,i64:126,f32:125,f64:124,void:64,v128:123,exn:105,noexn:116,nofunc:115,noextern:114,none:113,func:112,extern:111,any:110,eq:109,i31:108,struct:107,array:106,data:107,cont:104,nocont:117,string:103,stringview_wtf8:102,stringview_wtf16:96,stringview_iter:97,nullfuncref:115,nullexternref:114,nullexnref:116,nullref:113,funcref:112,externref:111,exnref:105,anyref:110,eqref:109,i31ref:108,structref:107,arrayref:106,contref:104,nocontref:117,stringref:103,ref:100,refnull:99,sub:80,subfinal:79,rec:78},lt={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},Ct={func:0,table:1,memory:2,global:3,tag:4};var Z=t=>{let e=0,r=[],i="",s=0,n=0,l=()=>i&&(r.push(i),i=""),f=o=>{r.loc=o;for(let a,c,y;e<t.length;)if(a=t.charCodeAt(e),s===34)i+=t[e++],a===92?i+=t[e++]:a===34&&(l(),s=0);else if(s>59)a===40&&t.charCodeAt(e+1)===59?(s++,i+=t[e++]+t[e++]):a===59&&t.charCodeAt(e+1)===41?(i+=t[e++]+t[e++],--s===59&&(l(),s=0)):i+=t[e++];else if(s<0)a===10||a===13?(i+=t[e++],l(),s=0):s===-2&&a===41?(l(),s=0):i+=t[e++];else if(a===34)i!=="$"&&l(),s=34,i+=t[e++];else if(a===40&&t.charCodeAt(e+1)===59)l(),s=60,i=t[e++]+t[e++];else if(a===59&&t.charCodeAt(e+1)===59)l(),s=t.indexOf(`
|
|
3
|
-
`,e)<0?-2:-1,i=t[e++]+t[e++];else if(a===40&&t.charCodeAt(e+1)===64)l(),y=e,e+=2,i="@",n++,(c=r).push(r=[]),f(y),r=c;else if(a===40)l(),y=e++,n++,(c=r).push(r=[]),f(y),r=c;else{if(a===41)return l(),e++,n--;a<=32?(l(),e++):i+=t[e++]}s<0&&l(),l()};return f(0),s===34&&S("Unclosed quote",e),s>59&&S("Unclosed block comment",e),n>0&&S("Unclosed parenthesis",e),e<t.length&&S("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var Jt=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(Jt).filter(r=>r!=null),e.loc=t.loc,e.length===1&&e[0]?.[0]==="module"?e[0]:e):typeof t!="string"?t:t[0]===";"||t[1]===";"?null:t[0]==="$"&&t[1]==='"'?t.includes("\\")?"$"+Xt(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?dt(t):t;function at(t){typeof t=="string"?(S.src=t,t=Z(t)||[]):S.src="",S.loc=0,t=Jt(t)||[];let e=0;if(t[0]==="module"?(e++,G(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return at(t.slice(++e).map(y=>y.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((y,m)=>{if(m<e||!Array.isArray(y)||y[0]!=="import")return[y];let[,u,...A]=y;if(!A.some(_=>Array.isArray(_)&&_[0]==="item"))return[y];if(Array.isArray(A.at(-1))&&A.at(-1)[0]!=="item"){let _=A.at(-1);return A.slice(0,-1).filter(b=>b[0]==="item").map(([,b])=>["import",u,b,_])}return A.filter(_=>_[0]==="item").map(([,_,b])=>["import",u,_,b])});let r=[];for(let y in C)(r[C[y]]=r[y]=[]).name=y;r.metadata={},t.slice(e).filter(y=>{if(!Array.isArray(y)){let A=S.loc,p=S.src,_;for(;(A=p.indexOf(y,A))>=0;){if(_=p.charCodeAt(A-1),A>0&&(_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95||_===36)){A++;continue}if(_=p.charCodeAt(A+y.length),_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95){A++;continue}break}A>=0&&(S.loc=A),S(`Unexpected token ${y}`)}let[m,...u]=y;if(S.loc=y.loc,m==="@custom")r.custom.push(u);else if(m==="rec")for(let A=0;A<u.length;A++){let[,...p]=u[A];Lt(p,r.type);let _=[];for(;p[0]?.[0]==="descriptor"||p[0]?.[0]==="describes";)_.push(p.shift());(p=Kt(p,r)).push(A?!0:[r.type.length,u.length]),_.length&&(p.desc=p.desc?[..._,...p.desc]:_),r.type.push(p)}else if(m==="type"){Lt(u,r.type);let A=[];for(;u[0]?.[0]==="descriptor"||u[0]?.[0]==="describes";)A.push(u.shift());let p=Kt(u,r);A.length&&(p.desc=p.desc?[...A,...p.desc]:A),r.type.push(p)}else if(m==="start"||m==="export")r[m].push(u);else return!0}).forEach(y=>{let[m,...u]=y;S.loc=y.loc;let A;m==="import"&&([m,...u]=(A=u).pop());let p=r[m];for(p||S(`Unknown section ${m}`),Lt(u,p);u[0]?.[0]==="export";)r.export.push([u.shift()[1],[m,p?.length]]);if(u[0]?.[0]==="import"&&([,...A]=u.shift()),m==="table"){let _=u[0]==="i64",b=_?1:0;if(u[b+1]?.[0]==="elem"){let[$,[,...w]]=[u[b],u[b+1]];u=_?["i64",w.length,w.length,$]:[w.length,w.length,$],r.elem.push([["table",p.length],["offset",[_?"i64.const":"i32.const",_?0n:0]],$,...w])}}else if(m==="memory"){let _=u[0]==="i64",b=_?1:0;if(u[b]?.[0]==="data"){let $=u.find(I=>Array.isArray(I)&&I[0]==="pagesize")?.[1]??65536,[,...w]=u.splice(b,1)[0],N=""+Math.ceil(w.reduce((I,k)=>I+k.length,0)/$);r.data.push([["memory",p.length],[_?"i64.const":"i32.const",_?0n:0],...w]),u=_?["i64",N,N]:[N,N]}}else if(m==="func"){let[_,b,$]=Mt(u,r);_??=kt(b,$,r),!A&&r.code.push([[_,b,$],...nt(u,r)]),u=[["type",_]]}else if(m==="tag"){let[_,b]=Mt(u,r);_??=kt(b,[],r),u=[["type",_]]}A&&(r.import.push([...A,[m,...u]]),u=null),p.push(u)});let i=(y,m=!0)=>{let u=r[y].filter(Boolean).map(A=>te[y](A,r)).filter(Boolean);return y===C.custom?u.flatMap(A=>[y,...q(A)]):u.length?[y,...q(m?q(u):u.flat())]:[]},s=()=>{let y=[];for(let m in r.metadata){let u=q(dt(`"metadata.code.${m}"`)),A=q(r.metadata[m].map(([p,_])=>[...g(p),...q(_.map(([b,$])=>[...g(b),...q($)]))]));y.push(0,...q([...u,...A]))}return y},n=i(C.global),l=i(C.elem),f=i(C.code),o=s(),a=i(C.data),c=r.strings.length?[C.strings,...q([0,...q(r.strings.map(y=>q(y)))])]:[];return Uint8Array.from([0,97,115,109,1,0,0,0,...i(C.custom),...i(C.type),...i(C.import),...i(C.func),...i(C.table),...i(C.memory),...i(C.tag),...c,...n,...i(C.export),...i(C.start,!1),...l,...i(C.datacount,!1),...f,...o,...a])}var K=t=>t?.[0]==="$"||!isNaN(t),G=t=>t?.[0]==="$",Dt=t=>t?.[0]==="a"||t?.[0]==="o";function nt(t,e){let r=[];for(t=[...t];t.length;){let i=t.shift();if(typeof i=="string")if(r.push(i),i==="block"||i==="if"||i==="loop")G(t[0])&&r.push(t.shift()),r.push(bt(t,e));else if(i==="else"||i==="end")G(t[0])&&t.shift();else if(i==="select")r.push(Bt(t)[1]);else if(i.endsWith("call_indirect")){let s=K(t[0])?t.shift():0,[n,l,f]=Mt(t,e);r.push(s,["type",n??kt(l,f,e)])}else i==="table.init"?r.push(K(t[1])?t.shift():0,t.shift()):i==="table.copy"||i==="memory.copy"?r.push(K(t[0])?t.shift():0,K(t[0])?t.shift():0):i.startsWith("table.")?r.push(K(t[0])?t.shift():0):i==="memory.init"?(r.push(...K(t[1])?[t.shift(),t.shift()].reverse():[t.shift(),0]),e.datacount&&(e.datacount[0]=!0)):i==="data.drop"||i==="array.new_data"||i==="array.init_data"?(i==="data.drop"&&r.push(t.shift()),e.datacount&&(e.datacount[0]=!0)):(i.startsWith("memory.")||i.endsWith("load")||i.endsWith("store"))&&K(t[0])&&r.push(t.shift());else if(Array.isArray(i)){let s=i[0];if(i.loc!=null&&(S.loc=i.loc),s?.startsWith?.("@metadata.code.")){let l=s.slice(15);r.push(["@metadata",l,i[1]]);continue}if(typeof s!="string"||!Array.isArray(ht[s])){r.push(i);continue}let n=i.slice(1);if(s==="block"||s==="loop")r.push(s),G(n[0])&&r.push(n.shift()),r.push(bt(n,e),...nt(n,e),"end");else if(s==="if"){let l=[],f=[];n.at(-1)?.[0]==="else"&&(f=nt(n.pop().slice(1),e)),n.at(-1)?.[0]==="then"&&(l=nt(n.pop().slice(1),e));let o=[s];G(n[0])&&o.push(n.shift()),o.push(bt(n,e)),r.push(...nt(n,e),...o,...l),f.length&&r.push("else",...f),r.push("end")}else if(s==="try_table"){for(r.push(s),G(n[0])&&r.push(n.shift()),r.push(bt(n,e));n[0]?.[0]==="catch"||n[0]?.[0]==="catch_ref"||n[0]?.[0]==="catch_all"||n[0]?.[0]==="catch_all_ref";)r.push(n.shift());r.push(...nt(n,e),"end")}else if(s==="ref.test"||s==="ref.cast"){let l=n[0];(!Array.isArray(l)||l[1]==="null"||l[0]!=="ref")&&(s+="_null"),r.push(...nt(n.slice(1),e),s,l),t.unshift(...r.splice(r.length-2))}else{let l=[];for(;n.length&&(!Array.isArray(n[0])||n[0].valueOf!==Array.prototype.valueOf||"type,param,result,ref,exact,on".includes(n[0][0]));)l.push(n.shift());r.push(...nt(n,e),s,...l),t.unshift(...r.splice(r.length-1-l.length))}}else r.push(i)}return r}var kt=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),Wt=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=G(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},Bt=t=>{let e=Wt(t,"param"),r=Wt(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},Mt=(t,e)=>{if(t[0]?.[0]!=="type")return[,...Bt(t)];let[,r]=t.shift(),[i,s]=Bt(t),n=e.type[typeof r=="string"&&isNaN(r)?e.type[r]:+r];if(!n)throw Error(`Unknown type ${r}`);if((i.length||s.length)&&n[1].join(">")!==i+">"+s)throw Error(`Type ${r} mismatch`);return[r,...n[1]]},bt=(t,e)=>{let[r,i,s]=Mt(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??kt(i,s,e)]},Lt=(t,e)=>{let r=G(t[0])&&t.shift();return r&&(r in e?S(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},Kt=([t],e)=>{let r="subfinal",i=[],s,n=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(i=t).pop(),i=i.filter(f=>Array.isArray(f)&&(f[0]==="descriptor"||f[0]==="describes")?(n.push(f),!1):!0)),[s,...t]=t,s==="func"?(t=Bt(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=Wt(t,"field"):s==="array"&&([t]=t);let l=[s,t,r,i];return n.length&&(l.desc=n),l},te=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...q(t),...i.flat()]},(t,e)=>{let[r,i,s,n,l]=t;if(l===!0)return;let f=(t.desc??[]).flatMap(([a,c])=>[a==="descriptor"?77:76,...g(v(c,e.type))]),o=(a,c)=>a==="func"?[lt.func,...q(c[0].map(y=>Y(y,e))),...q(c[1].map(y=>Y(y,e)))]:a==="array"?[lt.array,...wt(c,e)]:a==="struct"?[lt.struct,...q(c.map(y=>wt(y,e)))]:a==="cont"?[lt.cont,...g(v(c[0]??c,e.type))]:[lt[a]];if(l){let[a,c]=l,y=Array.from({length:c},(m,u)=>{let A=e.type[a+u],p=A.slice(0,4);return A.desc&&(p.desc=A.desc),te[C.type](p,e)});return[lt.rec,...q(y)]}else if(s==="sub"||n?.length)return[lt[s],...q(n.map(a=>v(a,e.type))),...f,...o(r,i)];return[...f,...o(r,i)]},([t,e,[r,...i]],s)=>{let n,l=Ct[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(l=32);let[[,o]]=i;n=g(v(o,s.type))}else if(r==="tag"){let[[,f]]=i;n=[0,...g(v(f,s.type))]}else r==="memory"?n=vt(i):r==="global"?n=wt(i[0],s):r==="table"?n=[...Y(i.pop(),s),...vt(i)]:S(`Unknown kind ${r}`);return[...q(t),...q(e),l,...n]},([[,t]],e)=>g(v(t,e.type)),(t,e)=>{let r=vt(t),i=Y(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...yt(s,e)]:[...i,...r]},(t,e)=>vt(t),([t,e],r)=>[...wt(t,r),...yt(e,r)],([t,[e,r]],i)=>[...q(t),Ct[e],...g(v(r,i[e]))],([t],e)=>g(v(t,e.func)),(t,e)=>{let r=0,i=0,s=0,n=0,l,f,o;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,l]=t.shift(),l=v(l,e.table)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&t[1][0]!=="item"&&!t[1][0]?.startsWith("ref"))&&(l=v(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(f=t.shift(),f[0]==="offset"&&([,f]=f),f=yt(f,e)):i||(r=1),D[t[0]]||t[0]?.[0]==="ref"?o=Y(t.shift(),e):t[0]==="func"?o=[D[t.shift()]]:o=[D.func],t=t.map(c=>(c[0]==="item"&&(c=c.length===3&&c[1]==="ref.func"?c[2]:c[1]),c[0]==="ref.func"&&([,c]=c),typeof c!="string"&&(s=1),c)),o[0]!==D.funcref&&(n=1,s=1);let a=s<<2|(r||i?i:!!l||n)<<1|(r||i);return[a,...a===0?f:a===1?[0]:a===2?[...g(l||0),...f,0]:a===3?[0]:a===4?f:a===5?o:a===6?[...g(l||0),...f,...o]:o,...q(t.map(s?c=>yt(typeof c=="string"?["ref.func",c]:c,e):c=>g(v(c,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[v(r,e.type)]),e.local=Object.create(i),e.block=[],e.local.name="local",e.block.name="block",e._codeIdx===void 0&&(e._codeIdx=0);let s=e._codeIdx++;for(;t[0]?.[0]==="local";){let[,...o]=t.shift();if(G(o[0])){let a=o.shift();a in e.local?S(`Duplicate local ${a}`):e.local[a]=e.local.length}e.local.push(...o)}e.meta={};let n=re(t,e),l=e.import.filter(o=>o[2][0]==="func").length+s;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([l,e.meta[o]]);let f=e.local.slice(i.length).reduce((o,a)=>(a==o[o.length-1]?.[1]?o[o.length-1][0]++:o.push([1,a]),o),[]);return e.local=e.block=e.meta=null,q([...q(f.map(([o,a])=>[...g(o),...Y(a,e)])),...n])},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=v(i,e.memory)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&typeof t[1][0]=="string")&&(i=v(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??S("Bad offset",r)),[...i?[2,...g(i),...yt(r,e)]:r?[0,...yt(r,e)]:[1],...q(t.flatMap(s=>Ge(s)??[...s]))]},(t,e)=>g(e.data.length),([[,t]],e)=>[0,...g(v(t,e.type))]],Y=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[D.refnull,98,...g(v(t[2][1],e.type))]:D[t[2]]?[D[t[2]]]:[D.refnull,...g(v(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[D.ref,98,...g(v(t[1][1],e.type))]:[D.ref,...g(D[t[t.length-1]]||v(t[t.length-1],e.type))]:[D[t]??S(`Unknown type ${t}`)],wt=(t,e,r=t[0]==="mut"?1:0)=>[...Y(r?t[1]:t,e),r],ee={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...g(v(i,e.elem)),...g(v(r,e.table))]},block:(t,e)=>{e.block.push(1),G(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?Y(r[1],e):g(v(r[1],e.type)):[D.void]},try_table:(t,e)=>{G(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?Y(r[1],e):g(v(r[1],e.type)):[D.void],s=[],n=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let l=t.shift(),f=l[0]==="catch"?0:l[0]==="catch_ref"?1:l[0]==="catch_all"?2:3;f<=1?s.push(f,...g(v(l[1],e.tag)),...g(ft(l[2],e.block))):s.push(f,...g(ft(l[1],e.block))),n++}return e.block.push(1),[...i,...g(n),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...g(v(i,e.type)),...g(v(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||G(t[0]));)r.push(...g(ft(t.shift(),e.block))),i++;return[...g(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?q(r.map(i=>Y(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...g(v(r[1],e.type))]:D[r]?[D[r]]:g(v(r,e.type))},memarg:(t,e,r)=>Qt(t,r,K(t[0])&&!Dt(t[0])?v(t.shift(),e.memory):0),opt_memory:(t,e)=>g(v(K(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=Y(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=ft(t.shift(),e.block),i=Y(t.shift(),e),s=Y(t.shift(),e),n=l=>l.length>1?l.slice(1):l;return[(s[0]!==D.ref)<<1|i[0]!==D.ref,...g(r),...n(i),...n(s)]},v128const:t=>{let[e,r]=t.shift().split("x"),i=+e.slice(1),s=i>>>3;if(r=+r,e[0]==="i"){let l=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let f=0;f<r;f++)l[f]=At[e].parse(t.shift());return[...new Uint8Array(l.buffer)]}let n=new Uint8Array(16);for(let l=0;l<r;l++)n.set(At[e](t.shift()),l*s);return[...n]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(It(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&S("invalid lane length"),e},memlane:(t,e,r)=>{let i=G(t[0])||K(t[0])&&(Dt(t[1])||K(t[1]))?v(t.shift(),e.memory):0;return[...Qt(t,r,i),...g(It(t.shift()))]},"*":t=>g(t.shift()),labelidx:(t,e)=>g(ft(t.shift(),e.block)),laneidx:t=>[It(t.shift(),255)],funcidx:(t,e)=>g(v(t.shift(),e.func)),typeidx:(t,e)=>g(v(t.shift(),e.type)),tableidx:(t,e)=>g(v(t.shift(),e.table)),memoryidx:(t,e)=>g(v(t.shift(),e.memory)),globalidx:(t,e)=>g(v(t.shift(),e.global)),localidx:(t,e)=>g(v(t.shift(),e.local)),dataidx:(t,e)=>g(v(t.shift(),e.data)),elemidx:(t,e)=>g(v(t.shift(),e.elem)),tagidx:(t,e)=>g(v(t.shift(),e.tag)),"memoryidx?":(t,e)=>g(v(K(t[0])?t.shift():0,e.memory)),stringidx:(t,e)=>{let r=t.shift(),i=r.valueOf(),s=e.strings.findIndex(n=>n.valueOf()===i);return s<0&&(s=e.strings.push(r)-1),g(s)},i32:t=>H(t.shift()),i64:t=>ct(t.shift()),f32:t=>ut(t.shift()),f64:t=>ot(t.shift()),v128:t=>Ft(t.shift()),typeidx_field:(t,e)=>{let r=v(t.shift(),e.type);return[...g(r),...g(v(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...g(v(t.shift(),e.type)),...g(t.shift())],typeidx_dataidx:(t,e)=>[...g(v(t.shift(),e.type)),...g(v(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...g(v(t.shift(),e.type)),...g(v(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...g(v(t.shift(),e.type)),...g(v(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...g(v(t.shift(),e.data)),...g(v(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...g(v(t.shift(),e.memory)),...g(v(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...g(v(t.shift(),e.table)),...g(v(t.shift(),e.table))],cont_bind:(t,e)=>[...g(v(t.shift(),e.type)),...g(v(t.shift(),e.type))],switch_cont:(t,e)=>[...g(v(t.shift(),e.type)),...g(v(t.shift(),e.tag))],resume:(t,e)=>{let r=g(v(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...g(v(n,e.tag))):i.push(0,...g(v(n,e.tag)),...g(ft(l,e.block))),s++}return[...r,...g(s),...i]},resume_throw:(t,e)=>{let r=g(v(t.shift(),e.type)),i=g(v(t.shift(),e.tag)),s=[],n=0;for(;t[0]?.[0]==="on";){let[,l,f]=t.shift();f==="switch"?s.push(1,...g(v(l,e.tag))):s.push(0,...g(v(l,e.tag)),...g(ft(f,e.block))),n++}return[...r,...i,...g(n),...s]},resume_throw_ref:(t,e)=>{let r=g(v(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...g(v(n,e.tag))):i.push(0,...g(v(n,e.tag)),...g(ft(l,e.block))),s++}return[...r,...g(s),...i]}},$t={};(function t(e,r){for(let i=0,s,n,l;i<e.length;i++)(s=e[i])&&(Array.isArray(s)?t(s,i):([n,l]=s.split(" "),ht[n]=r?[r,...g(i)]:[i],l&&($t[n]=ee[l])))})(ht);var re=(t,e)=>{let r=[],i=[];for(;t?.length;){let s=t.shift();if(s?.[0]==="@metadata"){i.push(s.slice(1));continue}Array.isArray(s)&&(s.loc!=null&&(S.loc=s.loc),S(`Unknown instruction ${s[0]}`));let[...n]=ht[s]||S(`Unknown instruction ${s}`);$t[s]&&(s==="select"&&t[0]?.length?n[0]++:$t[s]===ee.reftype&&!s.endsWith("_null")&&(t[0][1]==="null"||t[0][0]!=="ref")&&n[n.length-1]++,n.push(...$t[s](t,e,s)));for(let[l,f]of i)(e.meta[l]??=[]).push([r.length,f]);r.push(...n)}return r.push(11),r},yt=(t,e)=>re(nt([t],e),e),v=(t,e,r)=>(r=G(t)?e[t]:+t,r in e?r:S(`Unknown ${e.name} ${t}`)),ft=(t,e,r)=>(r=G(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?S(`Bad label ${t}`):r),Pe=t=>{let e,r,i,s;for(;Dt(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:S(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&S(`Bad offset ${r}`),(e<=0||e>4294967295)&&S(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&S(`Bad align ${e}`),[e,r]},Qt=(t,e,r=0)=>{let[i,s]=Pe(t),n=(i??je(e))|(r&&64);return r?[...g(n),...g(r),...g(s??0)]:[...g(n),...g(s??0)]},je=t=>{let e=t.indexOf(".",3)+1,r=t.slice(1,t[0]==="v"?4:3);if(t[e]==="a"&&(e=t.indexOf(".",e)+1),t[0]==="m")return t.includes("64")?3:2;if(t[e]==="r"){let n=t.slice(e,e+6).match(/\d+/);return Math.log2(n?n[0]/8:+r/8)}let i=t[e]==="l"?e+4:e+5,s=t.slice(i).match(/(\d+)(x|_|$)/);return Math.log2(s?s[2]==="x"?8:s[1]/8:+r/8)},Ge=t=>{if(!Array.isArray(t))return null;let[e,...r]=t;if(e!=="i8"&&e!=="i16"&&e!=="i32"&&e!=="i64"&&e!=="f32"&&e!=="f64")return null;let i=[],s=new DataView(new ArrayBuffer(8));for(let n of r)e==="i8"?i.push(H.parse(n)&511&255):e==="i16"?(s.setInt16(0,H.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,H.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,4))):e==="i64"?(s.setBigInt64(0,BigInt(n),!0),i.push(...new Uint8Array(s.buffer,0,8))):e==="f32"?i.push(...ut(n)):e==="f64"&&i.push(...ot(n));return i},vt=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(a=>Array.isArray(a)&&a[0]==="pagesize"),s=-1;i>=0&&(s=Math.log2(+t.splice(i,1)[0][1]));let n=!isNaN(parseInt(t[1])),l=(s>=0?8:0)|(e?4:0)|(r?2:0)|(n?1:0),f=e?a=>{if(typeof a=="bigint")return a;let c=typeof a=="string"?a.replaceAll("_",""):String(a);return BigInt(c)}:It,o=s>=0?g(s):[];return n?[l,...g(f(t.shift())),...g(f(t.shift())),...o]:[l,...g(f(t.shift())),...o]},It=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?H.parse(t):typeof t=="number"?t:S(`Bad int ${t}`);return r>e?S(`Value out of range ${t}`):r},q=t=>[...g(t.length),...t.flat()];function ie(t,e={}){typeof t=="string"&&(t=Z(t));let{indent:r=" ",newline:i=`
|
|
4
|
-
`,comments:s=!0}=e;if(r||="",i||="",typeof t[0]=="string"&&t[0][0]!==";")return l(t);return t.filter(f=>s||!n(f)).map(f=>l(f)).join(i);function n(f){return typeof f=="string"&&f[1]===";"}function l(f,o=0){if(!Array.isArray(f))return f;let a=f[0];if(!a)return"";let c=!1;if(a==="try_table"){let u=1;for(typeof f[u]=="string"&&f[u][0]==="$"&&(a+=" "+f[u++]),Array.isArray(f[u])&&(f[u][0]==="result"||f[u][0]==="type")&&(a+=" "+l(f[u++],o));Array.isArray(f[u])&&/^catch/.test(f[u][0]);)a+=" "+l(f[u++],o).trim();for(;u<f.length;u++)a+=Array.isArray(f[u])?i+r.repeat(o+1)+l(f[u],o+1):" "+f[u];return`(${a+i+r.repeat(o)})`}let
|
|
5
|
-
`}else{let p=a[a.length-1];p&&p!==" "&&p!=="("&&(a+=" "),a+=
|
|
6
|
-
`?a+="":(p&&p!==")"&&p!==" "||i||p===")")&&(a+=" "),a+=A,c=!1}}return y?`(${a.replaceAll(i+m+"("," (")})`:`(${a+i+r.repeat(o)})`}}var ne={funcref:["ref.func","call_ref","return_call_ref"],sign_ext:["i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s"],nontrapping:["i32.trunc_sat_f32_s","i32.trunc_sat_f32_u","i32.trunc_sat_f64_s","i32.trunc_sat_f64_u","i64.trunc_sat_f32_s","i64.trunc_sat_f32_u","i64.trunc_sat_f64_s","i64.trunc_sat_f64_u"],bulk_memory:["memory.copy","memory.fill"],return_call:["return_call","return_call_indirect"],i31ref:["ref.i31","i31.get_s","i31.get_u"],extended_const:["global.get"],multi_value:[],gc:["struct.new","struct.get","struct.set","array.new","array.get","array.set","array.len","struct.new_default","array.new_default","array.new_fixed","array.copy"],ref_cast:["ref.test","ref.cast","br_on_cast","br_on_cast_fail"]},Rt=Object.keys(ne),He=t=>{if(t===!0)return Object.fromEntries(Rt.map(e=>[e,!0]));if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return Object.fromEntries(Rt.map(r=>[r,e.has(r)||e.has("all")]))}return{...t}},P=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)P(t[s],e,t,s)},et=(t,e,r,i)=>{if(Array.isArray(t))for(let s=0;s<t.length;s++)et(t[s],e,t,s);e(t,r,i)},Ve=t=>{let e=new Set;return P(t,r=>{if(typeof r=="string")for(let[i,s]of Object.entries(ne))s.some(n=>r===n||r.startsWith(n+" "))&&e.add(i)}),P(t,r=>{if(!(!Array.isArray(r)||r[0]!=="global"))for(let i of r)Array.isArray(i)&&(i[0]==="i32.add"||i[0]==="i32.sub"||i[0]==="i32.mul"||i[0]==="i64.add"||i[0]==="i64.sub"||i[0]==="i64.mul")&&P(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),P(t,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=0;for(let s of r)Array.isArray(s)&&s[0]==="result"&&(i+=s.length-1);i>1&&e.add("multi_value")}),e},le=t=>Array.isArray(t)?t.map(le):t,fe=(t,e)=>{let r=[],i=t[0]==="module"?1:0;for(let s=i;s<t.length;s++)Array.isArray(t[s])&&t[s][0]===e&&r.push({node:t[s],idx:s});return r},St=(t,e,r)=>t.splice(e,0,r),Ye=0,rt=t=>`$__${t}${Ye++}`,Xe=(t,e)=>{let r=new Set;if(P(t,a=>{Array.isArray(a)&&a[0]==="ref.func"&&r.add(a[1])}),!r.size)return t;let i=rt("fntbl"),s=[...r],n=Object.fromEntries(s.map((a,c)=>[a,c])),l=fe(t,"func"),f=l.length?l[0].idx:t[0]==="module"?1:0;St(t,f,["table",i,"funcref",["elem",...s]]);let o={};return P(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!c)return;let y=[],m=[];for(let u of a){if(Array.isArray(u)&&u[0]==="param")for(let A=1;A<u.length;A++)u[A][0]!=="$"&&y.push(u[A]);if(Array.isArray(u)&&u[0]==="result")for(let A=1;A<u.length;A++)m.push(u[A])}o[c]={params:y,results:m}}),et(t,(a,c,y)=>{if(!(!Array.isArray(a)||!c)){if(a[0]==="ref.func"&&n[a[1]]!==void 0&&(c[y]=["i32.const",n[a[1]]]),a[0]==="call_ref"){let m=a[1],u=a.slice(2);c[y]=["call_indirect",i,["type",m],...u]}if(a[0]==="return_call_ref"){let m=a[1],u=a.slice(2);c[y]=["return_call_indirect",i,["type",m],...u]}}}),t},tt={funcref:Xe},Ze={"i32.extend8_s":["i32",24],"i32.extend16_s":["i32",16],"i64.extend8_s":["i64",56n],"i64.extend16_s":["i64",48n],"i64.extend32_s":["i64",32n]},Ke=(t,e)=>(et(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let n=Ze[r[0]];if(!n)return;let[l,f]=n,o=r.slice(1);i[s]=[`${l}.shr_s`,[`${l}.shl`,...o,[`${l}.const`,f]],[`${l}.const`,f]]}),t);tt.sign_ext=Ke;var se={"i32.trunc_sat_f32_s":{itype:"i32",ftype:"f32",signed:!0,min:-2147483648,max:2147483647},"i32.trunc_sat_f32_u":{itype:"i32",ftype:"f32",signed:!1,min:0,max:4294967295},"i32.trunc_sat_f64_s":{itype:"i32",ftype:"f64",signed:!0,min:-2147483648,max:2147483647},"i32.trunc_sat_f64_u":{itype:"i32",ftype:"f64",signed:!1,min:0,max:4294967295},"i64.trunc_sat_f32_s":{itype:"i64",ftype:"f32",signed:!0,min:-9223372036854775808n,max:9223372036854775807n},"i64.trunc_sat_f32_u":{itype:"i64",ftype:"f32",signed:!1,min:0n,max:18446744073709551615n},"i64.trunc_sat_f64_s":{itype:"i64",ftype:"f64",signed:!0,min:-9223372036854775808n,max:9223372036854775807n},"i64.trunc_sat_f64_u":{itype:"i64",ftype:"f64",signed:!1,min:0n,max:18446744073709551615n}},Qe=(t,e)=>{let r=new Set;if(P(t,s=>{Array.isArray(s)&&se[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:n,ftype:l,signed:f,min:o,max:a}=se[s],c=rt(`trunc_${n}_${l}_${f?"s":"u"}`);i[s]=c;let y=`${n}.trunc_${l}_${f?"s":"u"}`,m=n==="i64"?0n:0,u=["func",c,["param","$v",l],["result",n],["if",["result",n],[`${l}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${n}.const`,m]],["else",["if",["result",n],[`${l}.lt`,["local.get","$v"],[`${l}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${n}.const`,o]],["else",["if",["result",n],[`${l}.gt`,["local.get","$v"],[`${l}.const`,typeof a=="bigint"?Number(a):a]],["then",[`${n}.const`,a]],["else",[y,["local.get","$v"]]]]]]]]];t.push(u)}return et(t,(s,n,l)=>{!Array.isArray(s)||!n||i[s[0]]&&(n[l]=["call",i[s[0]],...s.slice(1)])}),t};tt.nontrapping=Qe;var Je=(t,e)=>{let r=new Set,i=new Set;P(t,l=>{if(Array.isArray(l)){if(l[0]==="memory.copy"){let f=typeof l[1]=="number"?l[1]:0,o=typeof l[2]=="number"?l[2]:0;r.add(`${f}_${o}`)}if(l[0]==="memory.fill"){let f=typeof l[1]=="number"?l[1]:0;i.add(f)}}});let s={},n={};for(let l of r){let[f,o]=l.split("_").map(Number),a=rt(`memcpy${l==="0_0"?"":"_"+l}`);s[l]=a;let c=f?["i32.store8",f]:["i32.store8"],y=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",a,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...y,["i32.add",["local.get","$src"],["local.get","$i"]]]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}for(let l of i){let f=rt(`memset${l===0?"":"_"+l}`);n[l]=f;let o=l?["i32.store8",l]:["i32.store8"];t.push(["func",f,["param","$dst","i32"],["param","$val","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...o,["i32.add",["local.get","$dst"],["local.get","$i"]],["local.get","$val"]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}return et(t,(l,f,o)=>{if(!(!Array.isArray(l)||!f)){if(l[0]==="memory.copy"){let a=typeof l[1]=="number"?l[1]:0,c=typeof l[2]=="number"?l[2]:0,y=l.filter(m=>Array.isArray(m)||typeof m=="string"&&m[0]==="$");f[o]=["call",s[`${a}_${c}`],...y]}if(l[0]==="memory.fill"){let a=typeof l[1]=="number"?l[1]:0,c=l.filter(y=>Array.isArray(y)||typeof y=="string"&&y[0]==="$");f[o]=["call",n[a],...c]}}}),t};tt.bulk_memory=Je;var tr=(t,e)=>{let r=!1;return P(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&et(t,(i,s,n)=>{!Array.isArray(i)||!s||(i[0]==="return_call"&&(s[n]=["return",["call",...i.slice(1)]]),i[0]==="return_call_indirect"&&(s[n]=["return",["call_indirect",...i.slice(1)]]))}),t};tt.return_call=tr;var er=(t,e)=>(et(t,(r,i,s)=>{if(!(!Array.isArray(r)||!i)&&(r[0]==="ref.i31"&&(i[s]=["i32.and",...r.slice(1),["i32.const",2147483647]]),r[0]==="i31.get_u"&&(i[s]=r.length>1?r[1]:["drop"]),r[0]==="i31.get_s")){let n=r.slice(1);i[s]=["i32.shr_s",["i32.shl",...n,["i32.const",1]],["i32.const",1]]}}),t);tt.i31ref=er;var rr=(t,e)=>{let r={};P(t,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l=s.length-1;l>=0;l--){let f=s[l];if(Array.isArray(f)&&(f[0]==="i32.const"||f[0]==="i64.const"||f[0]==="f32.const"||f[0]==="f64.const")){r[n]={type:f[0].split(".")[0],value:f[1]};break}}});let i=s=>{if(!Array.isArray(s))return s;let n=s[0];if(n==="global.get"&&r[s[1]]){let l=r[s[1]];return[`${l.type}.const`,l.value]}if(n==="i32.add"||n==="i64.add"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a+c]}}if(n==="i32.sub"||n==="i64.sub"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a-c]}}if(n==="i32.mul"||n==="i64.mul"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a*c]}}return s};return et(t,(s,n,l)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!n)){for(let f=2;f<s.length;f++)if(Array.isArray(s[f])){let o=i(s[f]);o!==s[f]&&(s[f]=o)}}}),t};tt.extended_const=rr;var ir=(t,e)=>{let r=new Map,i=[];if(P(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let o=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null,a=[];for(let c of f)if(Array.isArray(c)&&c[0]==="result")for(let y=1;y<c.length;y++)a.push(c[y]);a.length>1&&o&&r.set(o,a)}),!r.size)return t;let s=Math.max(...[...r.values()].map(f=>f.length)),n={};for(let[f,o]of r)for(let a=1;a<o.length;a++){let c=o[a];if(n[c]||(n[c]=[]),n[c].length<a){let y=rt(`ret_${c}_${n[c].length}`);n[c].push(y),i.push(["global",y,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let l=t[0]==="module"?1:0;for(let f of i.reverse())St(t,l,f);return et(t,(f,o,a)=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c||!r.has(c))return;let y=r.get(c);for(let m=0;m<f.length;m++)if(Array.isArray(f[m])&&f[m][0]==="result"){f[m]=["result",y[0]];break}}),t};tt.multi_value=ir;var xt={i32:4,i64:8,f32:4,f64:8},sr=(t,e)=>{let r=new Map,i=new Map,s=1;if(P(t,p=>{if(!Array.isArray(p)||p[0]!=="type")return;let _=typeof p[1]=="string"&&p[1][0]==="$"?p[1]:null;if(_){for(let b of p)if(Array.isArray(b)){if(b[0]==="struct"){let $=[];for(let w of b)if(Array.isArray(w)&&w[0]==="field"){let N=typeof w[1]=="string"&&w[1][0]==="$"?w[1]:null,I=N?w[2]:w[1],k=Array.isArray(I)&&I[0]==="mut"?I[1]:I;$.push({name:N,type:k})}r.set(_,{kind:"struct",fields:$}),i.set(_,s++)}if(b[0]==="array"){let $=b[1],w=Array.isArray($)&&$[0]==="mut"?$[1]:$;r.set(_,{kind:"array",elemType:w}),i.set(_,s++)}}}}),!r.size)return t;let n=fe(t,"memory").length>0,l=rt("alloc"),f=rt("heap_ptr"),o=t[0]==="module"?1:0;n||St(t,o,["memory",1]),St(t,o+1,["global",f,["mut","i32"],["i32.const",1024]]);let a=["func",l,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",f]],["global.set",f,["i32.add",["global.get",f],["local.get","$size"]]],["local.get","$ptr"]];t.push(a);let c=p=>{let _=4;for(let b of p.fields)_+=xt[b.type]||4;return _},y=(p,_)=>{let b=4;for(let $=0;$<_;$++)b+=xt[p.fields[$].type]||4;return b},m=(p,_)=>{for(let b=0;b<p.fields.length;b++)if(p.fields[b].name===_)return b;return-1},u=0,A=()=>`$__gc_tmp${u++}`;return P(t,p=>{if(!Array.isArray(p)||p[0]!=="func")return;let _=!1,b=!1,$=!1,w=!1;if(P(p,I=>{Array.isArray(I)&&((I[0]==="struct.new"||I[0]==="struct.new_default")&&(_=!0),(I[0]==="array.new"||I[0]==="array.new_default")&&(b=!0,$=!0,w=!0))}),!_&&!b)return;let N=1;for(let I=1;I<p.length;I++){let k=p[I];if(Array.isArray(k)&&(k[0]==="param"||k[0]==="result"||k[0]==="local"||k[0]==="export"||k[0]==="type"))N=I+1;else if(typeof k=="string"&&k[0]==="$")N=I+1;else if(!Array.isArray(k))N=I+1;else break}_&&p.splice(N++,0,["local","$__gc_ptr","i32"]),b&&p.splice(N++,0,["local","$__gc_aptr","i32"]),$&&p.splice(N++,0,["local","$__gc_alen","i32"]),w&&p.splice(N++,0,["local","$__gc_aidx","i32"])}),et(t,(p,_,b)=>{if(!(!Array.isArray(p)||!_)){if(p[0]==="struct.new"||p[0]==="struct.new_default"){let $=p[1],w=r.get($);if(!w||w.kind!=="struct")return;let N=c(w),I=i.get($),k=p.slice(2),O="$__gc_ptr",U=[["local.set",O,["call",l,["i32.const",N]]],["i32.store",["local.get",O],["i32.const",I]]];if(p[0]==="struct.new")for(let E=0;E<w.fields.length;E++){let d=w.fields[E],x=y(w,E),M=d.type==="i64"?"i64.store":d.type==="f32"?"f32.store":d.type==="f64"?"f64.store":"i32.store";U.push([M,["i32.add",["local.get",O],["i32.const",x]],k[E]||[`${d.type}.const`,0]])}else for(let E=0;E<w.fields.length;E++){let d=w.fields[E],x=y(w,E),M=d.type==="i64"?"i64.store":d.type==="f32"?"f32.store":d.type==="f64"?"f64.store":"i32.store",h=d.type==="i64"?["i64.const",0n]:d.type==="f32"?["f32.const",0]:d.type==="f64"?["f64.const",0]:["i32.const",0];U.push([M,["i32.add",["local.get",O],["i32.const",x]],h])}U.push(["local.get",O]),_[b]=["block",["result","i32"],...U]}if(p[0]==="struct.get"){let $=p[1],w=p[2],N=p[3],I=r.get($);if(!I||I.kind!=="struct")return;let k=typeof w=="string"&&w[0]==="$"?m(I,w):parseInt(w);if(k<0)return;let O=I.fields[k],U=y(I,k),E=O.type==="i64"?"i64.load":O.type==="f32"?"f32.load":O.type==="f64"?"f64.load":"i32.load";_[b]=[E,["i32.add",N,["i32.const",U]]]}if(p[0]==="struct.set"){let $=p[1],w=p[2],N=p[3],I=p[4],k=r.get($);if(!k||k.kind!=="struct")return;let O=typeof w=="string"&&w[0]==="$"?m(k,w):parseInt(w);if(O<0)return;let U=k.fields[O],E=y(k,O),d=U.type==="i64"?"i64.store":U.type==="f32"?"f32.store":U.type==="f64"?"f64.store":"i32.store";_[b]=[d,["i32.add",N,["i32.const",E]],I]}if(p[0]==="array.new"||p[0]==="array.new_default"){let $=p[1],w=r.get($);if(!w||w.kind!=="array")return;let N=i.get($),I=xt[w.elemType]||4,k=p[0]==="array.new"?p[2]:null,O=p[0]==="array.new"?p[3]:p[2],U="$__gc_aptr",E="$__gc_alen",d="$__gc_aidx",x=w.elemType==="i64"?"i64.store":w.elemType==="f32"?"f32.store":w.elemType==="f64"?"f64.store":"i32.store",M=[["local.set",E,O],["local.set",U,["call",l,["i32.add",["i32.const",8],["i32.mul",["local.get",E],["i32.const",I]]]]],["i32.store",["local.get",U],["i32.const",N]],["i32.store",["i32.add",["local.get",U],["i32.const",4]],["local.get",E]]];k&&M.push(["local.set",d,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",d],["local.get",E]]],[x,["i32.add",["i32.add",["local.get",U],["i32.const",8]],["i32.mul",["local.get",d],["i32.const",I]]],k],["local.set",d,["i32.add",["local.get",d],["i32.const",1]]],["br","$loop"]]]),M.push(["local.get",U]),_[b]=["block",["result","i32"],...M]}if(p[0]==="array.get"){let $=p[1],w=p[2],N=p[3],I=r.get($);if(!I||I.kind!=="array")return;let k=xt[I.elemType]||4,O=I.elemType==="i64"?"i64.load":I.elemType==="f32"?"f32.load":I.elemType==="f64"?"f64.load":"i32.load";_[b]=[O,["i32.add",["i32.add",w,["i32.const",8]],["i32.mul",N,["i32.const",k]]]]}if(p[0]==="array.set"){let $=p[1],w=p[2],N=p[3],I=p[4],k=r.get($);if(!k||k.kind!=="array")return;let O=xt[k.elemType]||4,U=k.elemType==="i64"?"i64.store":k.elemType==="f32"?"f32.store":k.elemType==="f64"?"f64.store":"i32.store";_[b]=[U,["i32.add",["i32.add",w,["i32.const",8]],["i32.mul",N,["i32.const",O]]],I]}if(p[0]==="array.len"){let $=p[1];_[b]=["i32.load",["i32.add",$,["i32.const",4]]]}}}),t};tt.gc=sr;var nr=(t,e)=>{let r=new Map,i=1;return P(t,s=>{if(!Array.isArray(s)||s[0]!=="type")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l of s)Array.isArray(l)&&(l[0]==="struct"||l[0]==="array")&&r.set(n,i++)}),r.size&&et(t,(s,n,l)=>{if(!(!Array.isArray(s)||!n)){if(s[0]==="ref.test"){let f=s[1],o=null;Array.isArray(f)&&f[0]==="ref"&&(o=f[1]==="null"?f[2]:f[1]);let a=s[2],c=r.get(o);c!==void 0&&(n[l]=["if",["result","i32"],["i32.eqz",a],["then",["i32.const",0]],["else",["i32.eq",["i32.load",a],["i32.const",c]]]])}if(s[0]==="ref.cast"){let f=s[1],o=null,a=!1;Array.isArray(f)&&f[0]==="ref"&&(f[1]==="null"?(a=!0,o=f[2]):o=f[1]);let c=s[2],y=r.get(o);if(y!==void 0){let m=rt("cast");a?n[l]=["block",["result","i32"],["local",m,"i32"],["local.set",m,c],["if",["i32.and",["i32.ne",["local.get",m],["i32.const",0]],["i32.ne",["i32.load",["local.get",m]],["i32.const",y]]],["then",["unreachable"]]],["local.get",m]]:n[l]=["block",["result","i32"],["local",m,"i32"],["local.set",m,c],["if",["i32.or",["i32.eqz",["local.get",m]],["i32.ne",["i32.load",["local.get",m]],["i32.const",y]]],["then",["unreachable"]]],["local.get",m]]}}if(s[0]==="br_on_cast"){let f=s[1],o=s[2],a=s[3],c=s[4],y=null;Array.isArray(a)&&a[0]==="ref"&&(y=a[1]==="null"?a[2]:a[1]);let m=r.get(y);if(m!==void 0){let u=rt("brcast");n[l]=["block",["result","i32"],["local",u,"i32"],["local.set",u,c],["br_if",f,["i32.and",["i32.ne",["local.get",u],["i32.const",0]],["i32.eq",["i32.load",["local.get",u]],["i32.const",m]]]],["local.get",u]]}}if(s[0]==="br_on_cast_fail"){let f=s[1],o=s[2],a=s[3],c=s[4],y=null;Array.isArray(a)&&a[0]==="ref"&&(y=a[1]==="null"?a[2]:a[1]);let m=r.get(y);if(m!==void 0){let u=rt("brfail");n[l]=["block",["result","i32"],["local",u,"i32"],["local.set",u,c],["br_if",f,["i32.or",["i32.eqz",["local.get",u]],["i32.ne",["i32.load",["local.get",u]],["i32.const",m]]]],["local.get",u]]}}}}),t};tt.ref_cast=nr;function Nt(t,e=!0){typeof t=="string"&&(t=Z(t)),t=le(t),e=He(e);let r=Ve(t),i={uid:0};for(let s of Rt)r.has(s)&&e[s]!==!1&&tt[s]&&(t=tt[s](t,i));return t}var Pt={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!1,inlineOnce:!0,vacuum:!0,mergeBlocks:!0,coalesce:!0,peephole:!0,globals:!0,offset:!0,unbranch:!0,stripmut:!0,brif:!0,foldarms:!1,dedupe:!0,reorder:!1,dedupTypes:!0,packData:!0,minifyImports:!1},ae=Object.keys(Pt);var oe=t=>{try{return at(t).length}catch{return 1/0}},T=(t,e)=>{if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="bigint")return t===e;if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!T(t[r],e[r]))return!1;return!0},lr=t=>{if(t===!0)return{...Pt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.has("all")?Object.fromEntries(ae.map(r=>[r,!0])):Object.fromEntries(ae.map(r=>[r,e.has(r)]))}return{...Pt,...t}},J=t=>Array.isArray(t)?t.map(J):t,L=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)L(t[s],e,t,s)},W=(t,e,r,i)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++){let l=W(t[n],e,t,n);l!==void 0&&(t[n]=l)}let s=e(t,r,i);return s!==void 0?s:t},Ut=t=>{let e=1;for(;e<t.length;){let s=t[e];if(Array.isArray(s)&&(s[0]==="then"||s[0]==="else"||s[0]==="result"||s[0]==="param")){e++;continue}break}let r=null,i=null;for(let s=e+1;s<t.length;s++){let n=t[s];Array.isArray(n)&&(n[0]==="then"?r=n:n[0]==="else"&&(i=n))}return{condIdx:e,cond:t[e],thenBranch:r,elseBranch:i}},fr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=new Map,n=new Map,l=new Map,f=(d,x,M,h=!1)=>{let B=typeof x[1]=="string"&&x[1][0]==="$",F=B?x[1]:M,st=!h&&x.some(R=>Array.isArray(R)&&R[0]==="export"),j={node:x,idx:M,used:st,isImport:h};return d.set(F,j),B&&d.set(M,j),l.set(x,j),j},o=0,a=0,c=0,y=0,m=0,u=[],A=[],p=[],_=[];for(let d of t.slice(1)){if(!Array.isArray(d))continue;let x=d[0];if(x==="type")f(i,d,c++);else if(x==="func")f(e,d,o++);else if(x==="global")f(r,d,a++);else if(x==="table")f(s,d,y++);else if(x==="memory")f(n,d,m++);else if(x==="import")for(let M of d)Array.isArray(M)&&(M[0]==="func"?f(e,M,o++,!0):M[0]==="global"?f(r,M,a++,!0):M[0]==="table"?f(s,M,y++,!0):M[0]==="memory"&&f(n,M,m++,!0));else x==="export"?p.push(d):x==="start"?_.push(d):x==="elem"?u.push(d):x==="data"&&A.push(d)}let b=[],$=d=>{d&&!d.scanned&&b.push(d)},w=d=>{let x=e.get(d);x&&(x.used||(x.used=!0),$(x))},N=d=>{let x=r.get(d);x&&(x.used=!0)},I=d=>{let x=s.get(d);x&&(x.used=!0)},k=d=>{typeof d=="string"&&d[0]!=="$"&&(d=+d);let x=n.get(d);x&&(x.used=!0)},O=d=>{let x=i.get(d);x&&(x.used=!0)};for(let d of p)for(let x of d){if(!Array.isArray(x))continue;let[M,h]=x;M==="func"?w(h):M==="global"?N(h):M==="table"?I(h):M==="memory"&&k(h)}for(let d of _){let x=d[1];typeof x=="string"&&x[0]!=="$"&&(x=+x),w(x)}for(let d of u)L(d,x=>{Array.isArray(x)&&x[0]==="ref.func"?w(x[1]):typeof x=="string"&&x[0]==="$"&&w(x)});for(let d of A){let x=d[1];Array.isArray(x)&&x[0]==="memory"?k(x[1]):typeof x=="string"&&x[0]==="$"?k(x):Array.isArray(x)&&k(0)}for(let d of[e,r,s,n])for(let x of d.values())x.used&&$(x);if(!(p.length>0||_.length>0||u.length>0||b.length>0)){for(let d of[e,r,s,n])for(let x of d.values())x.used=!0;return t}for(;b.length;){let d=b.pop();d.scanned||(d.scanned=!0,!d.isImport&&L(d.node,x=>{if(!Array.isArray(x)){typeof x=="string"&&x[0]==="$"&&w(x);return}let[M,h]=x;if(M==="call"||M==="return_call"||M==="ref.func")w(h);else if(M==="global.get"||M==="global.set")N(h);else if(M==="type")O(h);else if(M==="call_indirect"||M==="return_call_indirect")for(let B of x)typeof B=="string"&&B[0]==="$"&&I(B);typeof M=="string"&&(M.startsWith("memory.")||M.includes(".load")||M.includes(".store"))&&k(0)}))}let E=["module"];for(let d of t.slice(1)){if(!Array.isArray(d)){E.push(d);continue}let x=d[0];if(x==="func"||x==="global"||x==="type")l.get(d)?.used&&E.push(d);else if(x==="import"){let M=!1;for(let h of d){if(!Array.isArray(h))continue;if(l.get(h)?.used){M=!0;break}}M&&E.push(d)}else E.push(d)}return E},ce=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),mt=t=>(e,r)=>t(e,r)?1:0,zt=t=>(e,r)=>t(e>>>0,r>>>0)?1:0,pt=t=>(e,r)=>t(e,r)?1:0,Tt=t=>(e,r)=>t(BigInt.asUintN(64,e),BigInt.asUintN(64,r))?1:0,ar={"i32.add":[(t,e)=>t+e|0,"i32"],"i32.sub":[(t,e)=>t-e|0,"i32"],"i32.mul":[(t,e)=>Math.imul(t,e),"i32"],"i32.div_s":[(t,e)=>e!==0?t/e|0:null,"i32"],"i32.div_u":[(t,e)=>e!==0?(t>>>0)/(e>>>0)|0:null,"i32"],"i32.rem_s":[(t,e)=>e!==0?t%e|0:null,"i32"],"i32.rem_u":[(t,e)=>e!==0?(t>>>0)%(e>>>0)|0:null,"i32"],"i32.and":[(t,e)=>t&e,"i32"],"i32.or":[(t,e)=>t|e,"i32"],"i32.xor":[(t,e)=>t^e,"i32"],"i32.shl":[(t,e)=>t<<(e&31),"i32"],"i32.shr_s":[(t,e)=>t>>(e&31),"i32"],"i32.shr_u":[(t,e)=>t>>>(e&31),"i32"],"i32.rotl":[(t,e)=>(e&=31,t<<e|t>>>32-e|0),"i32"],"i32.rotr":[(t,e)=>(e&=31,t>>>e|t<<32-e|0),"i32"],"i32.eq":[mt((t,e)=>t===e),"i32"],"i32.ne":[mt((t,e)=>t!==e),"i32"],"i32.lt_s":[mt((t,e)=>t<e),"i32"],"i32.lt_u":[zt((t,e)=>t<e),"i32"],"i32.gt_s":[mt((t,e)=>t>e),"i32"],"i32.gt_u":[zt((t,e)=>t>e),"i32"],"i32.le_s":[mt((t,e)=>t<=e),"i32"],"i32.le_u":[zt((t,e)=>t<=e),"i32"],"i32.ge_s":[mt((t,e)=>t>=e),"i32"],"i32.ge_u":[zt((t,e)=>t>=e),"i32"],"i32.eqz":[t=>t===0?1:0,"i32"],"i32.clz":[t=>Math.clz32(t),"i32"],"i32.ctz":[t=>t===0?32:31-Math.clz32(t&-t),"i32"],"i32.popcnt":[t=>{let e=0;for(;t;)e+=t&1,t>>>=1;return e},"i32"],"i32.wrap_i64":[t=>Number(BigInt.asIntN(32,t)),"i32"],"i32.extend8_s":[t=>t<<24>>24,"i32"],"i32.extend16_s":[t=>t<<16>>16,"i32"],"i64.add":[(t,e)=>BigInt.asIntN(64,t+e),"i64"],"i64.sub":[(t,e)=>BigInt.asIntN(64,t-e),"i64"],"i64.mul":[(t,e)=>BigInt.asIntN(64,t*e),"i64"],"i64.div_s":[(t,e)=>e!==0n?BigInt.asIntN(64,t/e):null,"i64"],"i64.div_u":[(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)/BigInt.asUintN(64,e)):null,"i64"],"i64.rem_s":[(t,e)=>e!==0n?BigInt.asIntN(64,t%e):null,"i64"],"i64.rem_u":[(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)%BigInt.asUintN(64,e)):null,"i64"],"i64.and":[(t,e)=>BigInt.asIntN(64,t&e),"i64"],"i64.or":[(t,e)=>BigInt.asIntN(64,t|e),"i64"],"i64.xor":[(t,e)=>BigInt.asIntN(64,t^e),"i64"],"i64.shl":[(t,e)=>BigInt.asIntN(64,t<<(e&63n)),"i64"],"i64.shr_s":[(t,e)=>BigInt.asIntN(64,t>>(e&63n)),"i64"],"i64.shr_u":[(t,e)=>BigInt.asUintN(64,BigInt.asUintN(64,t)>>(e&63n)),"i64"],"i64.eq":[pt((t,e)=>t===e),"i32"],"i64.ne":[pt((t,e)=>t!==e),"i32"],"i64.lt_s":[pt((t,e)=>t<e),"i32"],"i64.lt_u":[Tt((t,e)=>t<e),"i32"],"i64.gt_s":[pt((t,e)=>t>e),"i32"],"i64.gt_u":[Tt((t,e)=>t>e),"i32"],"i64.le_s":[pt((t,e)=>t<=e),"i32"],"i64.le_u":[Tt((t,e)=>t<=e),"i32"],"i64.ge_s":[pt((t,e)=>t>=e),"i32"],"i64.ge_u":[Tt((t,e)=>t>=e),"i32"],"i64.eqz":[t=>t===0n?1:0,"i32"],"i64.extend_i32_s":[t=>BigInt(t),"i64"],"i64.extend_i32_u":[t=>BigInt(t>>>0),"i64"],"i64.extend8_s":[t=>BigInt.asIntN(64,BigInt.asIntN(8,t)),"i64"],"i64.extend16_s":[t=>BigInt.asIntN(64,BigInt.asIntN(16,t)),"i64"],"i64.extend32_s":[t=>BigInt.asIntN(64,BigInt.asIntN(32,t)),"i64"],"f32.add":[(t,e)=>Math.fround(t+e),"f32"],"f32.sub":[(t,e)=>Math.fround(t-e),"f32"],"f32.mul":[(t,e)=>Math.fround(t*e),"f32"],"f32.div":[(t,e)=>Math.fround(t/e),"f32"],"f32.neg":[t=>Math.fround(-t),"f32"],"f32.abs":[t=>Math.fround(Math.abs(t)),"f32"],"f32.sqrt":[t=>Math.fround(Math.sqrt(t)),"f32"],"f32.ceil":[t=>Math.fround(Math.ceil(t)),"f32"],"f32.floor":[t=>Math.fround(Math.floor(t)),"f32"],"f32.trunc":[t=>Math.fround(Math.trunc(t)),"f32"],"f32.nearest":[t=>Math.fround(ce(t)),"f32"],"f64.add":[(t,e)=>t+e,"f64"],"f64.sub":[(t,e)=>t-e,"f64"],"f64.mul":[(t,e)=>t*e,"f64"],"f64.div":[(t,e)=>t/e,"f64"],"f64.neg":[t=>-t,"f64"],"f64.abs":[Math.abs,"f64"],"f64.sqrt":[Math.sqrt,"f64"],"f64.ceil":[Math.ceil,"f64"],"f64.floor":[Math.floor,"f64"],"f64.trunc":[Math.trunc,"f64"],"f64.nearest":[ce,"f64"]},z=t=>{if(!Array.isArray(t)||t.length!==2)return null;let[e,r]=t;return e==="i32.const"?{type:"i32",value:Number(r)|0}:e==="i64.const"?{type:"i64",value:BigInt(r)}:e==="f32.const"?{type:"f32",value:Math.fround(Number(r))}:e==="f64.const"?{type:"f64",value:Number(r)}:null},ue=(t,e)=>t==="i32"?["i32.const",e|0]:t==="i64"?["i64.const",e]:t==="f32"?["f32.const",Math.fround(e)]:t==="f64"?["f64.const",e]:null,or=t=>W(t,e=>{if(!Array.isArray(e))return;let r=ar[e[0]];if(!r)return;let[i,s]=r;if(i.length===1&&e.length===2){let n=z(e[1]);if(!n)return;let l=i(n.value);return l===null?void 0:ue(s,l)}if(i.length===2&&e.length===3){let n=z(e[1]),l=z(e[2]);if(!n||!l)return;let f=i(n.value,l.value);return f===null?void 0:ue(s,f)}}),it=t=>(e,r)=>{let i=z(e),s=z(r);return i?.value===t?r:s?.value===t?e:null},Q=t=>(e,r)=>z(r)?.value===t?e:null,cr={"i32.add":it(0),"i64.add":it(0n),"i32.sub":Q(0),"i64.sub":Q(0n),"i32.mul":it(1),"i64.mul":it(1n),"i32.div_s":Q(1),"i32.div_u":Q(1),"i64.div_s":Q(1n),"i64.div_u":Q(1n),"i32.and":it(-1),"i64.and":it(-1n),"i32.or":it(0),"i64.or":it(0n),"i32.xor":it(0),"i64.xor":it(0n),"i32.shl":Q(0),"i32.shr_s":Q(0),"i32.shr_u":Q(0),"i64.shl":Q(0n),"i64.shr_s":Q(0n),"i64.shr_u":Q(0n)},ur=t=>W(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=cr[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),yr=t=>W(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1)){let f=Math.log2(n.value);if(Number.isInteger(f))return["i32.shl",i,["i32.const",f]]}let l=z(i);if(l&&l.value>0&&!(l.value&l.value-1)){let f=Math.log2(l.value);if(Number.isInteger(f))return["i32.shl",s,["i32.const",f]]}}if(r==="i64.mul"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let f=BigInt(n.value.toString(2).length-1);return["i64.shl",i,["i64.const",f]]}let l=z(i);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let f=BigInt(l.value.toString(2).length-1);return["i64.shl",s,["i64.const",f]]}}if(r==="i32.div_u"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1)){let l=Math.log2(n.value);if(Number.isInteger(l))return["i32.shr_u",i,["i32.const",l]]}}if(r==="i64.div_u"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let l=BigInt(n.value.toString(2).length-1);return["i64.shr_u",i,["i64.const",l]]}}if(r==="i32.rem_u"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1))return["i32.and",i,["i32.const",n.value-1]]}if(r==="i64.rem_u"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n)return["i64.and",i,["i64.const",n.value-1n]]}}),mr=t=>W(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Ut(e),l=z(i);if(!l)return;let f=l.value!==0&&l.value!==0n?s:n;if(f&&f.length>1){let o=f.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=z(i);return s?s.value===0||s.value===0n?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let i=e[e.length-1],s=z(i);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),ye=new Set(["unreachable","return","br","br_table"]),pr=t=>(L(t,e=>{if(!Array.isArray(e))return;let r=e[0];if((r==="func"||r==="block"||r==="loop")&&me(e),r==="if")for(let i=1;i<e.length;i++)Array.isArray(e[i])&&(e[i][0]==="then"||e[i][0]==="else")&&me(e[i])}),t),me=t=>{let e=!1,r=-1;for(let i=1;i<t.length;i++){let s=t[i];if(Array.isArray(s)){let n=s[0];if(n==="param"||n==="result"||n==="local"||n==="type"||n==="export")continue;e&&r===-1&&(r=i),ye.has(n)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),ye.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},_r=t=>(L(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=[],i=new Map,s=new Set;for(let n=1;n<e.length;n++){let l=e[n];Array.isArray(l)&&(l[0]==="local"&&(r.push({node:l,idx:n}),typeof l[1]=="string"&&l[1][0]==="$"&&i.set(l[1],l[2])),l[0]==="param"&&typeof l[1]=="string"&&l[1][0]==="$"&&(i.set(l[1],l[2]),s.add(l[1])))}L(e,n=>{if(!Array.isArray(n))return;let l=n[0];if(l==="local.get"||l==="local.set"||l==="local.tee"){let f=n[1];typeof f=="string"&&s.add(f)}});for(let n=r.length-1;n>=0;n--){let{idx:l,node:f}=r[n],o=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;o&&!s.has(o)&&e.splice(l,1)}}),t),gr=new Set(["call","call_indirect","return_call","return_call_indirect","table.set","table.grow","table.fill","table.copy","table.init","struct.set","struct.new","array.set","array.new","array.new_fixed","array.new_data","array.new_elem","array.init_data","array.init_elem","ref.i31","global.set","local.set","local.tee","unreachable","return","br","br_if","br_table","br_on_null","br_on_non_null","br_on_cast","br_on_cast_fail","throw","rethrow","throw_ref","try_table","data.drop","elem.drop"]),hr=[".store","memory.",".atomic."],_t=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||gr.has(e))return!1;for(let r of hr)if(e.includes(r))return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!_t(t[r]))return!1;return!0},xr=t=>{let e=new Map,r=i=>(e.has(i)||e.set(i,{gets:0,sets:0,tees:0}),e.get(i));return L(t,i=>{!Array.isArray(i)||i.length<2||typeof i[1]!="string"||(i[0]==="local.get"?r(i[1]).gets++:i[0]==="local.set"?r(i[1]).sets++:i[0]==="local.tee"&&r(i[1]).tees++)}),e},dr=t=>{let e=z(t);if(!e)return!1;if(e.type==="i32"){let r=e.value|0;return r>=-64&&r<=63}if(e.type==="i64"){let r=typeof e.value=="bigint"?e.value:BigInt(e.value);return r>=-64n&&r<=63n}return!1},de=t=>t.pure&&t.singleUse||dr(t.val),pe=(t,e)=>{for(let[r,i]of t){let s=!1;L(i.val,n=>{Array.isArray(n)&&(n[0]==="local.get"||n[0]==="local.tee")&&n[1]===e&&(s=!0)}),s&&t.delete(r)}},_e=(t,e)=>W(t,r=>{if(!Array.isArray(r)||r[0]!=="local.get"||r.length!==2)return;let i=typeof r[1]=="string"&&e.get(r[1]);if(i&&de(i))return J(i.val)}),Ar=(t,e,r)=>{let i=!1,s=l=>r.get(l)||{gets:0,sets:0,tees:0},n=new Map;for(let l=1;l<t.length;l++){let f=t[l];if(!Array.isArray(f))continue;let o=f[0];if(!(o==="param"||o==="result"||o==="local"||o==="type"||o==="export")){if((o==="local.set"||o==="local.tee")&&f.length===3&&typeof f[1]=="string"){_e(f[2],n);let a=s(f[1]);pe(n,f[1]),n.set(f[1],{val:f[2],pure:_t(f[2]),singleUse:a.gets<=1&&a.sets<=1&&a.tees===0});continue}if((o==="block"||o==="loop"||o==="if")&&n.clear(),o==="call"||o==="call_indirect"||o==="return_call"||o==="return_call_indirect")for(let[a,c]of n)z(c.val)||n.delete(a);if(o==="local.get"&&f.length===2&&typeof f[1]=="string"){let a=n.get(f[1]);if(a&&de(a)){let c=J(a.val);f.length=0,f.push(...Array.isArray(c)?c:[c]),i=!0;continue}}if(o!=="block"&&o!=="loop"&&o!=="if"){let a=J(f);_e(f,n),T(a,f)||(i=!0),L(f,c=>{Array.isArray(c)&&(c[0]==="local.set"||c[0]==="local.tee")&&typeof c[1]=="string"&&(n.delete(c[1]),pe(n,c[1]))})}}}return i},br=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let f=n[1];if(l[1]!==f||e.has(f))continue;let o=r.get(f)||{gets:0,sets:0,tees:0};if(o.sets!==1||o.gets!==1||o.tees!==0)continue;let a=J(n[2]);t.splice(s,2,...Array.isArray(a)?[a]:[a]),i=!0,s--}return i},wr=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let f=n[1];if(l[1]!==f||e.has(f))continue;let o=r.get(f)||{gets:0,sets:0,tees:0};o.sets+o.gets+o.tees<=2||(t.splice(s,2,["local.tee",f,J(n[2])]),i=!0)}return i},vr=(t,e,r)=>{let i=!1,s=n=>r.get(n)||{gets:0,sets:0,tees:0};for(let n=t.length-1;n>=1;n--){let l=t[n];if(!Array.isArray(l))continue;let f=typeof l[1]=="string"?l[1]:null;if(!f||e.has(f))continue;let o=s(f);(l[0]==="local.set"&&o.gets===0&&o.tees===0&&_t(l[2])||l[0]==="local"&&f[0]==="$"&&o.gets===0&&o.sets===0&&o.tees===0)&&(t.splice(n,1),i=!0)}return i},Ae=t=>Array.isArray(t)&&(t[0]==="func"||t[0]==="block"||t[0]==="loop"||t[0]==="then"||t[0]==="else"),ge=t=>(L(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Set;for(let s of e)Array.isArray(s)&&s[0]==="param"&&typeof s[1]=="string"&&r.add(s[1]);let i=[];W(e,s=>{Ae(s)&&i.push(s)});for(let s=0;s<6;s++){let n=xr(e),l=!1;for(let f of i)Ar(f,r,n)&&(l=!0),br(f,r,n)&&(l=!0),wr(f,r,n)&&(l=!0),vr(f,r,n)&&(l=!0);if(!l)break}}),t),$r=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map;for(let r of t.slice(1)){if(!Array.isArray(r)||r[0]!=="func")continue;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i)continue;let s=[],n=[],l=!1,f=!1;for(let o=1;o<r.length;o++){let a=r[o];if(Array.isArray(a))if(a[0]==="param")if(typeof a[1]=="string"&&a[1][0]==="$")s.push({name:a[1],type:a[2]});else{s=null;break}else a[0]==="local"?l=!0:a[0]==="export"?f=!0:a[0]!=="result"&&a[0]!=="type"&&n.push(a)}if(s&&!l&&!f&&s.length<=4&&n.length===1){let o=new Set(s.map(y=>y.name)),a=!1,c=!1;L(n[0],y=>{Array.isArray(y)&&((y[0]==="local.set"||y[0]==="local.tee")&&o.has(y[1])&&(a=!0),(y[0]==="return"||y[0]==="return_call"||y[0]==="return_call_indirect")&&(c=!0))}),!a&&!c&&e.set(i,{body:n[0],params:s})}}return e.size===0||W(t,r=>{if(!Array.isArray(r)||r[0]!=="call")return;let i=r[1];if(!e.has(i))return;let{body:s,params:n}=e.get(i),l=r.slice(2);if(n.length===0)return J(s);let f=J(s);return W(f,o=>{if(!Array.isArray(o)||o[0]!=="local.get")return;let a=o[1],c=n.findIndex(y=>y.name===a);if(c!==-1&&l[c])return J(l[c])}),f}),t},Ir=0,kr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set(["export","type","param","result","local"]),r=f=>{let o=2;for(;o<f.length&&(typeof f[o]=="string"||Array.isArray(f[o])&&e.has(f[o][0]));)o++;return o},i=f=>f==="br"||f==="br_if"||f==="br_table",s=f=>{if(!Array.isArray(f))return!1;let o=f[0];if(o==="return_call"||o==="return_call_indirect"||o==="return_call_ref"||o==="try"||o==="try_table"||o==="delegate"||o==="rethrow")return!0;if(i(o)){for(let a=1;a<f.length;a++)if(typeof f[a]=="number"||typeof f[a]=="string"&&/^\d+$/.test(f[a]))return!0}for(let a=1;a<f.length;a++)if(s(f[a]))return!0;return!1},n=(f,o)=>{if(!Array.isArray(f))return!1;if((f[0]==="call"||f[0]==="return_call")&&f[1]===o)return!0;for(let a=1;a<f.length;a++)if(n(f[a],o))return!0;return!1},l=(f,o)=>{if(!Array.isArray(f))return;let a=f[0];if(a==="export"&&Array.isArray(f[2])&&f[2][0]==="func"&&typeof f[2][1]=="string")o.add(f[2][1]);else if(a==="start"&&typeof f[1]=="string")o.add(f[1]);else if(a==="ref.func"&&typeof f[1]=="string")o.add(f[1]);else if(a==="elem")for(let c of f)typeof c=="string"&&c[0]==="$"&&o.add(c);for(let c of f)l(c,o)};for(let f=0;f<16;f++){let o=t.filter(h=>Array.isArray(h)&&h[0]==="func"),a=new Map;for(let h of o)typeof h[1]=="string"&&a.set(h[1],h);let c=new Map,y=new Set,m=h=>{if(!Array.isArray(h))return;let B=h[0];B==="call"&&typeof h[1]=="string"?c.set(h[1],(c.get(h[1])||0)+1):B==="return_call"&&typeof h[1]=="string"&&y.add(h[1]);for(let F=1;F<h.length;F++)m(h[F])};m(t);let u=new Set;for(let h of t)(!Array.isArray(h)||h[0]!=="func")&&l(h,u);let A=null;for(let[h,B]of a){if(u.has(h)||y.has(h)||c.get(h)!==1||n(B,h))continue;let F=!0,st=0;for(let R=2;R<B.length;R++){let V=B[R];if(typeof V!="string"){if(!Array.isArray(V)){F=!1;break}if(V[0]==="param"||V[0]==="local"){if(typeof V[1]!="string"||V[1][0]!=="$"){F=!1;break}}else if(V[0]==="result")st+=V.length-1;else if(V[0]==="export"){F=!1;break}else{if(V[0]==="type")continue;break}}}if(!F||st>1)continue;let j=!1;for(let R=r(B);R<B.length;R++)if(s(B[R])){j=!0;break}if(!j){A=h;break}}if(!A)break;let p=a.get(A),_=[],b=[],$=null;for(let h=2;h<p.length;h++){let B=p[h];if(!(typeof B=="string"||!Array.isArray(B)))if(B[0]==="param")_.push({name:B[1],type:B[2]});else if(B[0]==="result")B.length>1&&($=B[1]);else if(B[0]==="local")b.push({name:B[1],type:B[2]});else{if(B[0]==="export"||B[0]==="type")continue;break}}let w=p.slice(r(p)),N=++Ir,I=`$__inl${N}`,k=new Map;for(let h of _)k.set(h.name,`$__inl${N}_${h.name.slice(1)}`);for(let h of b)k.set(h.name,`$__inl${N}_${h.name.slice(1)}`);let O=h=>h==="block"||h==="loop"||h==="if",U=new Map,E=h=>{if(Array.isArray(h)){O(h[0])&&typeof h[1]=="string"&&h[1][0]==="$"&&!U.has(h[1])&&U.set(h[1],`$__inl${N}L_${h[1].slice(1)}`);for(let B=1;B<h.length;B++)E(h[B])}};for(let h of w)E(h);let d=h=>{if(!Array.isArray(h))return h;let B=h[0];return(B==="local.get"||B==="local.set"||B==="local.tee")&&typeof h[1]=="string"&&k.has(h[1])?[B,k.get(h[1]),...h.slice(2).map(d)]:B==="return"?["br",I,...h.slice(1).map(d)]:O(B)&&typeof h[1]=="string"&&U.has(h[1])?[B,U.get(h[1]),...h.slice(2).map(d)]:i(B)?[B,...h.slice(1).map(F=>typeof F=="string"&&U.has(F)?U.get(F):d(F))]:h.map((F,st)=>st===0?F:d(F))},x=!1;for(let h of o){if(h===p||x)continue;let B=r(h);for(let F=B;F<h.length;F++){let st=W(h[F],j=>{if(x||!Array.isArray(j)||j[0]!=="call"||j[1]!==A)return;let R=j.slice(2);if(R.length!==_.length)return;let V=_.map((Ie,ke)=>["local.set",k.get(Ie.name),R[ke]]),Gt=w.map(d);return x=!0,$?["block",I,["result",$],...V,...Gt]:["block",I,...V,...Gt]});if(st!==h[F]&&(h[F]=st),x){let j=[..._,...b].map(R=>["local",k.get(R.name),R.type]);j.length&&h.splice(r(h),0,...j);break}}if(x)break}if(!x)break;let M=t.indexOf(p);M>=0&&t.splice(M,1)}return t},Br=(t,e)=>{let r=!1,i=(s,n)=>{if(r||!Array.isArray(s))return;let l=s[0],f=n;if((l==="block"||l==="loop")&&typeof s[1]=="string"&&s[1]===e&&(f=!0),!n){if(l==="br"||l==="br_if"||l==="br_on_null"||l==="br_on_non_null"||l==="br_on_cast"||l==="br_on_cast_fail"){if(s[1]===e){r=!0;return}}else if(l==="br_table"){for(let o=1;o<s.length&&typeof s[o]=="string";o++)if(s[o]===e){r=!0;return}}}for(let o=1;o<s.length;o++)i(s[o],f)};for(let s of t)i(s,!1);return r},Mr=t=>(L(t,e=>{if(!Ae(e))return;let r=1;for(;r<e.length;){let i=e[r];if(!Array.isArray(i)||i[0]!=="block"){r++;continue}let s=1,n=null;typeof i[1]=="string"&&i[1][0]==="$"&&(n=i[1],s=2);let l=!1;for(let o=s;o<i.length;o++){let a=i[o];if(Array.isArray(a)&&(a[0]==="param"||a[0]==="result"||a[0]==="type")){l=!0;break}}if(l){r++;continue}let f=i.slice(s);if(n&&Br(f,n)){r++;continue}e.splice(r,1,...f),r+=f.length}}),t),Sr=t=>(L(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Map;for(let m of e)Array.isArray(m)&&m[0]==="local"&&typeof m[1]=="string"&&m[1][0]==="$"&&typeof m[2]=="string"&&r.set(m[1],m[2]);if(r.size<2)return;let i=new Map,s=[],n=0,l=!1,f=0,o=m=>{if(l||!Array.isArray(m))return;let u=m[0],A=u==="loop";A&&s.push({start:n,end:n});let p=u==="local.set"||u==="local.tee";if(p||u==="local.get"){let _=m[1];if(typeof _!="string"||_[0]!=="$"){l=!0;return}if(p)for(let $=2;$<m.length;$++)o(m[$]);let b=n++;if(r.has(_)){let $=i.get(_);$||($={start:b,end:b,firstOp:u,firstCond:f>0,loops:new Set},i.set(_,$)),b>$.end&&($.end=b);for(let w of s)$.loops.add(w)}}else{n++;let _=u==="if";for(let b=1;b<m.length;b++){let $=m[b],w=_&&Array.isArray($)&&($[0]==="then"||$[0]==="else");w&&f++,o($),w&&f--}}if(A){let _=s.pop();_.end=n}};if(o(e),l)return;for(let m of i.values())for(let u of m.loops)u.start<m.start&&(m.start=u.start),u.end>m.end&&(m.end=u.end);let a=[...i.entries()].sort((m,u)=>m[1].start-u[1].start),c=new Map,y=[];for(let[m,u]of a){let A=u.firstOp==="local.get"||u.firstCond,p=r.get(m),_=A?null:y.find(b=>b.type===p&&b.end<u.start);_?(c.set(m,_.primary),u.end>_.end&&(_.end=u.end)):y.push({primary:m,type:p,end:u.end})}c.size!==0&&L(e,m=>{Array.isArray(m)&&(m[0]==="local.get"||m[0]==="local.set"||m[0]==="local.tee")&&c.has(m[1])&&(m[1]=c.get(m[1]))})}),t),Nr=t=>W(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="nop")return["nop"];if(r==="drop"&&e.length===2&&_t(e[1]))return["nop"];if(r==="select"&&e.length>=4&&T(e[1],e[2]))return e[1];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Ut(e),l=!s||s.length<=1,f=!n||n.length<=1;if(l&&f)return _t(i)?["nop"]:["drop",i];if(n&&f&&!l)return e.filter(o=>o!==n)}if(r==="func"||r==="block"||r==="loop"||r==="then"||r==="else"){let i=[r];for(let s=1;s<e.length;s++){let n=e[s];if(n==="nop"||Array.isArray(n)&&n[0]==="nop")continue;let l=e[s+1],f=l==="drop"||Array.isArray(l)&&l[0]==="drop"&&l.length===1;if(Array.isArray(n)&&_t(n)&&f){s++;continue}i.push(n)}if(i.length!==e.length)return i}}),zr={"i32.sub":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.sub":(t,e)=>T(t,e)?["i64.const",0n]:null,"i32.xor":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.xor":(t,e)=>T(t,e)?["i64.const",0n]:null,"i32.and":(t,e)=>T(t,e)?t:null,"i64.and":(t,e)=>T(t,e)?t:null,"i32.or":(t,e)=>T(t,e)?t:null,"i64.or":(t,e)=>T(t,e)?t:null,"i32.eq":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.eq":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ne":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.ne":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.lt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.lt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.gt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.gt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.le_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.le_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ge_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ge_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.lt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.lt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.gt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.gt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.le_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.le_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.ge_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.ge_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.mul":(t,e)=>{let r=z(t),i=z(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.mul":(t,e)=>{let r=z(t),i=z(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.and":(t,e)=>{let r=z(t),i=z(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.and":(t,e)=>{let r=z(t),i=z(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.or":(t,e)=>{let r=z(t),i=z(e);return r?.value===-1||i?.value===-1?["i32.const",-1]:null},"i64.or":(t,e)=>{let r=z(t),i=z(e);return r?.value===-1n||i?.value===-1n?["i64.const",-1n]:null},"local.set":(t,e)=>Array.isArray(e)&&e[0]==="local.get"&&e[1]===t?["nop"]:null},Tr=t=>W(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=zr[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Er=t=>{let e=typeof t=="bigint"?t:BigInt(Math.trunc(Number(t)||0)),r=1;for(;;){let i=e&0x7fn;if(e>>=7n,e===0n&&(i&0x40n)===0n||e===-1n&&(i&0x40n)!==0n)return r;r++}},Ur=t=>{if(!Array.isArray(t))return 4;switch(t[0]){case"i32.const":case"i64.const":return 1+Er(t[1]);case"f32.const":return 5;case"f64.const":return 9;case"v128.const":return 18;default:return 4}},qr=2,Or=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Set;for(let n of t.slice(1)){if(!Array.isArray(n))continue;if(n[0]==="export"&&Array.isArray(n[2])&&n[2][0]==="global"&&typeof n[2][1]=="string"){r.add(n[2][1]);continue}if(n[0]!=="global")continue;let l=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null;if(!l)continue;n.some(a=>Array.isArray(a)&&a[0]==="export")&&r.add(l);let f=n[2];if(Array.isArray(f)&&f[0]==="mut"||Array.isArray(f)&&f[0]==="import")continue;let o=n[3];z(o)&&e.set(l,o)}if(e.size===0)return t;let i=new Map;L(t,n=>{if(!Array.isArray(n))return;let l=n[1];typeof l!="string"||l[0]!=="$"||(n[0]==="global.set"?e.delete(l):n[0]==="global.get"&&i.set(l,(i.get(l)||0)+1))});let s=new Set;for(let[n,l]of e){let f=i.get(n)||0;if(f===0)continue;let o=Ur(l),a=o+2,c=f*qr+a;f*o+(r.has(n)?a:0)<=c&&s.add(n)}if(s.size===0)return t;W(t,n=>{if(!(!Array.isArray(n)||n[0]!=="global.get"||n.length!==2)&&s.has(n[1]))return J(e.get(n[1]))});for(let n=t.length-1;n>=1;n--){let l=t[n];Array.isArray(l)&&l[0]==="global"&&typeof l[1]=="string"&&s.has(l[1])&&!r.has(l[1])&&t.splice(n,1)}return t},Fr=t=>W(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(typeof r!="string"||!r.endsWith("load")&&!r.endsWith("store"))return;let i=r.endsWith("store"),s=0,n=null,l=1;for(typeof e[1]=="string"&&(e[1][0]==="$"||!isNaN(e[1]))&&(n=e[1],l=2);l<e.length&&typeof e[l]=="string"&&(e[l].startsWith("offset=")||e[l].startsWith("align="));)e[l].startsWith("offset=")&&(s=+e[l].slice(7)),l++;let f=i?e.length-2:e.length-1,o=i?e.length-1:-1;if(f<l)return;let a=e[f];if(!Array.isArray(a)||a[0]!=="i32.add"||a.length!==3)return;let c=a[1],y=a[2],m=z(c),u=z(y),A=null,p=null;if(m&&m.type==="i32"?(p=m.value,A=y):u&&u.type==="i32"&&(p=u.value,A=c),A===null||p===null)return;let _=s+p,b=[r];n!==null&&b.push(n),b.push(`offset=${_}`);let $=null;for(let w=l;w<f;w++)typeof e[w]=="string"&&e[w].startsWith("align=")&&($=e[w]);return $&&b.push($),b.push(A),i&&b.push(e[o]),b}),Cr=t=>(L(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let i=1,s=null;if(typeof e[1]=="string"&&e[1][0]==="$"&&(s=e[1],i=2),!s)return;let n=-1;for(let f=e.length-1;f>=i;f--){let o=e[f];if(!Array.isArray(o)){o!=="nop"&&o!=="end"&&(n=f);continue}let a=o[0];if(!(a==="param"||a==="result"||a==="local"||a==="type"||a==="export")){n=f;break}}if(n<0)return;let l=e[n];Array.isArray(l)&&l[0]==="br"&&l[1]===s&&e.splice(n,1,...l.slice(2))}),t),Lr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set;return L(t,r=>{Array.isArray(r)&&r[0]==="global.set"&&typeof r[1]=="string"&&e.add(r[1])}),W(t,r=>{if(!Array.isArray(r)||r[0]!=="global")return;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i||e.has(i))return;let s=typeof r[1]=="string"&&r[1][0]==="$",n=s?r[2]:r[1];if(Array.isArray(n)&&n[0]==="mut"){let l=[...r];return l[s?2:1]=n[1],l}})},Dr=t=>W(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{cond:r,thenBranch:i,elseBranch:s}=Ut(e),n=!i||i.length<=1,l=!s||s.length<=1;if(!n&&l&&i.length===2){let f=i[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],r]}if(n&&!l&&s.length===2){let f=s[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],["i32.eqz",r]]}}),Wr=t=>W(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{thenBranch:r,elseBranch:i}=Ut(e);if(!r||!i||r.length<=1||i.length<=1||!e.some(m=>Array.isArray(m)&&m[0]==="result"))return;let n=0,l=Math.min(r.length,i.length);for(let m=1;m<l&&T(r[r.length-m],i[i.length-m]);m++)n++;if(n===0)return;let f=r.slice(r.length-n),o=r.slice(0,r.length-n),a=i.slice(0,i.length-n),c=["block"];for(let m=1;m<e.length;m++){let u=e[m];if(Array.isArray(u)&&(u[0]==="then"||u[0]==="else"))break;Array.isArray(u)&&(u[0]==="result"||u[0]==="type")&&c.push(u)}let y=["if"];for(let m=1;m<e.length;m++){let u=e[m];if(Array.isArray(u)&&(u[0]==="then"||u[0]==="else"))break;Array.isArray(u)&&(u[0]==="result"||u[0]==="type")||y.push(u)}return y.push(o.length>1?o:["then"]),y.push(a.length>1?a:["else"]),c.push(y,...f),c}),be=(t,e)=>{let r=[],i=[t];for(;i.length;){let s=i.pop();if(Array.isArray(s)){i.push("|");for(let n=s.length-1;n>=0;n--)i.push(s[n]);i.push("[")}else typeof s=="string"?r.push(e.has(s)?"$__L":s):typeof s=="bigint"?r.push(s.toString()+"n"):typeof s=="number"?r.push(s.toString()):s===null?r.push("null"):s===!0?r.push("t"):s===!1?r.push("f"):r.push(String(s))}return r.join(",")},Rr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="func")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=new Set;typeof i[1]=="string"&&i[1][0]==="$"&&n.add(i[1]),L(i,f=>{if(!Array.isArray(f)||typeof f[1]!="string"||f[1][0]!=="$")return;let o=f[0];(o==="param"||o==="local"||o==="block"||o==="loop"||o==="if")&&n.add(f[1])});let l=be(i,n);e.has(l)?r.set(s,e.get(l)):e.set(l,s)}return r.size===0||W(t,i=>{if(!Array.isArray(i))return;let s=i[0];if((s==="call"||s==="return_call")&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(s==="ref.func"&&r.has(i[1]))return["ref.func",r.get(i[1])];if(s==="elem"){let n=i[i.length-1];if(Array.isArray(n))return[...i.slice(0,-1),n.map(l=>r.get(l)||l)]}if(s==="call_indirect"&&i.length>=3){let n=i[1];if(typeof n=="string"&&r.has(n))return["call_indirect",r.get(n),...i.slice(2)]}}),t},Pr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="type")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=be(i,new Set([s]));e.has(n)?r.set(s,e.get(n)):e.set(n,s)}if(r.size===0)return t;for(let i=t.length-1;i>=0;i--){let s=t[i];if(Array.isArray(s)&&s[0]==="type"){let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;n&&r.has(n)&&t.splice(i,1)}}return W(t,i=>{if(!Array.isArray(i))return;let s=i[0];if(s==="func")for(let n=1;n<i.length;n++){let l=i[n];Array.isArray(l)&&l[0]==="type"&&typeof l[1]=="string"&&r.has(l[1])&&(i[n]=["type",r.get(l[1])])}if(s==="import")for(let n=1;n<i.length;n++){let l=i[n];if(Array.isArray(l))for(let f=1;f<l.length;f++){let o=l[f];Array.isArray(o)&&o[0]==="type"&&typeof o[1]=="string"&&r.has(o[1])&&(l[f]=["type",r.get(o[1])])}}if(s==="call_indirect"||s==="return_call_indirect"){if(typeof i[1]=="string"&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(Array.isArray(i[1])&&i[1][0]==="type"&&typeof i[1][1]=="string"&&r.has(i[1][1]))return[s,["type",r.get(i[1][1])],...i.slice(2)]}}),t},Et=t=>{if(typeof t!="string"||t.length<2||t[0]!=='"')return new Uint8Array;let e=t.slice(1,-1),r=[];for(let i=0;i<e.length;i++)if(e[i]==="\\"){let s=e[++i];s==="x"||s==="X"?(r.push(parseInt(e.slice(i+1,i+3),16)),i+=2):/[0-9a-fA-F]/.test(s)&&/[0-9a-fA-F]/.test(e[i+1])?(r.push(parseInt(e.slice(i,i+2),16)),i++):s==="n"?r.push(10):s==="t"?r.push(9):s==="r"?r.push(13):s==="\\"?r.push(92):s==='"'?r.push(34):r.push(s.charCodeAt(0))}else r.push(e.charCodeAt(i));return new Uint8Array(r)},we=t=>{let e='"';for(let r=0;r<t.length;r++){let i=t[r];i>=32&&i<127&&i!==34&&i!==92?e+=String.fromCharCode(i):e+="\\"+i.toString(16).padStart(2,"0")}return e+'"'},jr=t=>{let e=[];for(let i of t)if(typeof i=="string")e.push(...Et(i));else if(Array.isArray(i)&&i[0]==="i8")for(let s=1;s<i.length;s++)e.push(Number(i[s])&255);else return t;let r=e.length;for(;r>0&&e[r-1]===0;)r--;return r===e.length?t:r===0?[]:[we(new Uint8Array(e.slice(0,r)))]},Gr=t=>{let e=1;if(typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"){let i=t[e][1];e++;let s=t[e];return Array.isArray(s)&&(s[0]==="i32.const"||s[0]==="i64.const")?{memidx:i,offset:Number(s[1])}:null}let r=t[e];return Array.isArray(r)&&(r[0]==="i32.const"||r[0]==="i64.const")?{memidx:0,offset:Number(r[1])}:null},he=t=>{let e=1;typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"&&e++,Array.isArray(t[e])&&typeof t[e][0]=="string"&&!t[e][0].startsWith('"')&&e++;let r=0;for(let i=e;i<t.length;i++){let s=t[i];if(typeof s=="string")r+=Et(s).length;else if(Array.isArray(s)&&s[0]==="i8")r+=s.length-1;else return null}return r},Hr=(t,e)=>{let r=1;typeof t[r]=="string"&&t[r][0]==="$"&&r++,Array.isArray(t[r])&&t[r][0]==="memory"&&r++,Array.isArray(t[r])&&typeof t[r][0]=="string"&&!t[r][0].startsWith('"')&&r++;let i=1;typeof e[i]=="string"&&e[i][0]==="$"&&i++,Array.isArray(e[i])&&e[i][0]==="memory"&&i++,Array.isArray(e[i])&&typeof e[i][0]=="string"&&!e[i][0].startsWith('"')&&i++;let s=t.slice(r),n=e.slice(i);if(s.length===1&&n.length===1&&typeof s[0]=="string"&&typeof n[0]=="string"){let l=Et(s[0]),f=Et(n[0]),o=new Uint8Array(l.length+f.length);return o.set(l),o.set(f,l.length),t.length=r,t.push(we(o)),!0}return t.length=r,t.push(...s,...n),!0},Vr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;for(let i of t){if(!Array.isArray(i)||i[0]!=="data")continue;let s=1;typeof i[1]=="string"&&i[1][0]==="$"&&(s=2),s<i.length&&Array.isArray(i[s])&&typeof i[s][0]=="string"&&!i[s][0].startsWith('"')&&s++;let n=i.slice(s);if(n.length===0)continue;let l=jr(n);(l.length!==n.length||l.length>0&&l[0]!==n[0])&&(i.length=s,i.push(...l))}let e=[];for(let i=0;i<t.length;i++){let s=t[i];if(Array.isArray(s)&&s[0]==="data"){let n=Gr(s);if(n){let l=he(s);l!==null&&e.push({...n,node:s,index:i,len:l})}}}e.sort((i,s)=>{let n=String(i.memidx),l=String(s.memidx);return n!==l?n.localeCompare(l):i.offset-s.offset});let r=new Set;for(let i=0;i<e.length-1;i++){let s=e[i],n=e[i+1];r.has(s.index)||String(s.memidx)!==String(n.memidx)||s.offset+s.len===n.offset&&Hr(s.node,n.node)&&(r.add(n.index),s.len=he(s.node))}return r.size>0&&(t=t.filter((i,s)=>!r.has(s))),t},xe=()=>{let t=new Map,e=0;return r=>{if(!t.has(r)){let i="",s=e++;do i=String.fromCharCode(97+s%26)+i,s=Math.floor(s/26)-1;while(s>=0);t.set(r,i||"a")}return t.get(r)}},Yr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=xe(),r=xe();for(let i of t)!Array.isArray(i)||i[0]!=="import"||(typeof i[1]=="string"&&i[1][0]==='"'&&(i[1]='"'+e(i[1].slice(1,-1))+'"'),typeof i[2]=="string"&&i[2][0]==='"'&&(i[2]='"'+r(i[2].slice(1,-1))+'"'));return t},Xr=t=>{let e=!0;return L(t,r=>{if(!e||!Array.isArray(r))return;let i=r[0];if(i==="func"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if((i==="call"||i==="return_call"||i==="ref.func")&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="start"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="elem")for(let s of r){if(typeof s=="string"&&s[0]!=="$"&&/^\d/.test(s)){e=!1;break}if(Array.isArray(s)&&s[0]==="ref.func"&&(typeof s[1]!="string"||s[1][0]!=="$")){e=!1;break}}}),e},Zr=t=>{if(!Array.isArray(t)||t[0]!=="module"||!Xr(t))return t;let e=new Map;L(t,n=>{Array.isArray(n)&&(n[0]==="call"||n[0]==="return_call")&&e.set(n[1],(e.get(n[1])||0)+1)});let r=[],i=[],s=[];for(let n of t.slice(1)){if(!Array.isArray(n)){s.push(n);continue}n[0]==="import"?r.push(n):n[0]==="func"?i.push(n):s.push(n)}return i.sort((n,l)=>(e.get(l[1])||0)-(e.get(n[1])||0)),["module",...r,...i,...s]};function qt(t,e=!0){typeof t=="string"&&(t=Z(t));let r=e===!0;e=lr(e);let i=e.log?(l,f)=>e.log(l,f):()=>{},s=e.verbose||e.log;t=J(t);let n=null;for(let l=0;l<3;l++){n=J(t);let f=oe(t);e.stripmut&&(t=Lr(t)),e.globals&&(t=Or(t)),e.fold&&(t=or(t)),e.identity&&(t=ur(t)),e.peephole&&(t=Tr(t)),e.strength&&(t=yr(t)),e.branch&&(t=mr(t)),e.propagate&&(t=ge(t)),e.inlineOnce&&(t=kr(t)),e.inline&&(t=$r(t)),e.offset&&(t=Fr(t)),e.unbranch&&(t=Cr(t)),e.brif&&(t=Dr(t)),e.foldarms&&(t=Wr(t)),e.deadcode&&(t=pr(t)),e.vacuum&&(t=Nr(t)),e.mergeBlocks&&(t=Mr(t)),e.coalesce&&(t=Sr(t)),e.locals&&(t=_r(t)),e.dedupe&&(t=Rr(t)),e.dedupTypes&&(t=Pr(t)),e.packData&&(t=Vr(t)),e.reorder&&(t=Zr(t)),e.treeshake&&(t=fr(t)),e.minifyImports&&(t=Yr(t)),e.propagate&&(e.inlineOnce||e.inline)&&(t=ge(t));let a=oe(t)-f;if((s||a!==0)&&i(` round ${l+1}: ${a>0?"+":""}${a} bytes`,a),a>(r?0:16)){s&&i(` \u26A0 round ${l+1} inflated by ${a} bytes, reverting`,a),t=n;break}if(T(n,t))break}return t}var ve="\uE000",$e=t=>{if(!t||typeof t!="string")return null;let e=t.split(".")[0];return/^[if](32|64)|v128/.test(e)?e:/\.(eq|ne|[lg][te]|eqz)/.test(t)||t==="memory.size"||t==="memory.grow"?"i32":null},Kr=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t;return $e(r)?$e(r):r==="local.get"&&e.locals?.[i[0]]?e.locals[i[0]]:r==="call"&&e.funcs?.[i[0]]?e.funcs[i[0]].result?.[0]:null};function jt(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=jt(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function Qr(t,e){let r=[],i=new Map;return jt(t,s=>{if(!Array.isArray(s))return s;if(s[0]==="call"&&typeof s[1]=="function"){let n=s[1];if(!i.has(n)){let f=[];for(let c=2;c<s.length;c++){let y=Kr(s[c]);y&&f.push(y)}let o=r.length,a=n.name||`$fn${o}`;i.set(n,{idx:o,name:a.startsWith("$")?a:"$"+a,params:f,fn:n}),r.push(i.get(n))}let l=i.get(n);s[1]=l.name}return s}),r}function Jr(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function ti(t,...e){let r={};if(!Array.isArray(t)&&e.length&&typeof e[e.length-1]=="object"&&e[e.length-1]!==null&&!e[e.length-1].byteLength&&(r=e.pop()),Array.isArray(t)&&t.raw){let i=t[0];for(let a=0;a<e.length;a++)i+=ve+t[a+1];let s=Z(i),n=[],l=0;s=jt(s,a=>{if(a===ve){let c=e[l++];if(typeof c=="function")return n.push(c),c;if(typeof c=="string"&&(c[0]==="("||/^\s*\(/.test(c))){let y=Z(c);return Array.isArray(y)&&Array.isArray(y[0])&&(y._splice=!0),y}return c.byteLength!==void 0?[...c]:c}return a});let f=null;if(n.length){let a=Qr(s,n);if(a.length){let c=Jr(a);s[0]==="module"?s.splice(1,0,...c):typeof s[0]=="string"?s=[...c,s]:s.unshift(...c),f={env:{}};for(let y of a)f.env[y.name.slice(1)]=y.fn}}r.polyfill&&(s=Nt(s,r.polyfill)),r.optimize&&(s=qt(s,r.optimize));let o=at(s);return f&&(o._imports=f),o}if(r.polyfill||r.optimize){let i=typeof t=="string"?Z(t):t;return r.polyfill&&(i=Nt(i,r.polyfill)),r.optimize&&(i=qt(i,r.optimize)),at(i)}return at(t)}function ei(t,...e){let r=ti(t,...e),i=new WebAssembly.Module(r);return new WebAssembly.Instance(i,r._imports).exports}var ki=ei;export{ti as compile,ki as default,qt as optimize,Z as parse,Nt as polyfill,ie as print,ei as watr};
|
|
1
|
+
var Ue=Object.defineProperty;var qe=(t,e)=>{for(var r in e)Ue(t,r,{get:e[r],enumerable:!0})};var At={};qe(At,{f32:()=>ut,f64:()=>ot,i16:()=>De,i32:()=>H,i64:()=>ct,i8:()=>Ce,uleb:()=>g,uleb5:()=>Le,v128:()=>Ft});var N=(t,e=N.loc)=>{if(e!=null&&N.src){let r=1,i=1;for(let s=0;s<e&&s<N.src.length;s++)N.src[s]===`
|
|
2
|
+
`?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)};var Yt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Xt=/^[+-]?(?:0x[\da-f]+|\d+)$/i,Oe=new TextEncoder,Fe=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),Vt={n:10,r:13,t:9,'"':34,"'":39,"\\":92},dt=t=>{let e=[],r=1,i,s,n="",l=()=>(n&&e.push(...Oe.encode(n)),n="");for(;r<t.length-1;)s=t[r++],i=null,s==="\\"&&(t[r]==="u"?(r++,r++,s=String.fromCodePoint(parseInt(t.slice(r,r=t.indexOf("}",r)),16)),r++):Vt[t[r]]?i=Vt[t[r++]]:isNaN(i=parseInt(t[r]+t[r+1],16))?s+=t[r]:(r++,r++)),i!=null?(l(),e.push(i)):n+=s;return l(),e.valueOf=()=>t,e},Zt=t=>Fe.decode(new Uint8Array(dt(t)));var g=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):H.parse(t)),typeof t=="bigint"){for(;;){let i=Number(t&0x7Fn);if(t>>=7n,t===0n){e.push(i);break}e.push(i|128)}return e}let r=t&127;return t>>>=7,t===0?(e.push(r),e):(e.push(r|128),g(t,e))};function Le(t){let e=[];for(let r=0;r<5;r++){let i=t&127;t>>>=7,r<4&&(i|=128),e.push(i)}return e}function H(t,e=[]){for(typeof t=="string"&&(t=H.parse(t));;){let r=Number(t&127);if(t>>=7,t===0&&!(r&64)||t===-1&&r&64){e.push(r);break}e.push(r|128)}return e}var Kt=t=>!Yt.test(t)&&Xt.test(t=t.replaceAll("_",""))?t:N(`Bad int ${t}`),Ce=H,De=H;H.parse=t=>(t=parseInt(Kt(t)),(t<-2147483648||t>4294967295)&&N("i32 constant out of range"),t);function ct(t,e=[]){for(typeof t=="string"?t=ct.parse(t):typeof t=="number"&&(t=BigInt(t)),typeof t=="bigint"&&t>0x7fffffffffffffffn&&(t=t-0x10000000000000000n);;){let r=Number(t&0x7Fn);if(t>>=7n,t===0n&&!(r&64)||t===-1n&&r&64){e.push(r);break}e.push(r|128)}return e}var gt=new ArrayBuffer(8),X=new Uint8Array(gt),Re=new Int32Array(gt),We=new Float32Array(gt),Pe=new Float64Array(gt),Ot=new BigInt64Array(gt);ct.parse=t=>{t=Kt(t);let e=t[0]==="-",r=e?t.slice(1):t,i;if(r[0]==="0"&&(r[1]==="x"||r[1]==="X")){let n=r.slice(2).replace(/^0+/,"")||"0";i=e?"8000000000000000":"ffffffffffffffff",(n.length>16||n.length===16&&n.toLowerCase()>i)&&N("i64 constant out of range")}else{let n=r.replace(/^0+/,"")||"0";i=e?"9223372036854775808":"18446744073709551615",(n.length>i.length||n.length===i.length&&n>i)&&N("i64 constant out of range")}let s=BigInt(r);return e&&(s=0n-s),Ot[0]=s,Ot[0]};var je=2147483648,Ge=2139095040,He=4194304;function ut(t,e,r){return typeof t=="string"&&(r=t.indexOf("nan"))>=0?(e=t[r+3]===":"?H.parse(t.slice(r+4)):He,e|=Ge,t[0]==="-"&&(e|=je),Re[0]=e):(e=typeof t=="string"?ut.parse(t):t,We[0]=e),[X[0],X[1],X[2],X[3]]}var Ve=0x8000000000000000n,Ye=0x7ff0000000000000n,Xe=0x8000000000000n;function ot(t,e,r){return typeof t=="string"&&(r=t.indexOf("nan"))>=0?(e=t[r+3]===":"?ct.parse(t.slice(r+4)):Xe,e|=Ye,t[0]==="-"&&(e|=Ve),Ot[0]=e):(e=typeof t=="string"?ot.parse(t):t,Pe[0]=e),[X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7]]}ot.parse=(t,e=Number.MAX_VALUE)=>{t=t.replaceAll("_","");let r=1;if(t[0]==="-"?(r=-1,t=t.slice(1)):t[0]==="+"&&(t=t.slice(1)),t[1]==="x"){let[i,s="0"]=t.split(/p/i),[n,l=""]=i.split("."),f=l.length??0,o=0;for(let m=n.length-1;m>=2;m--){let y=parseInt(n[m],16);o+=y*16**(n.length-1-m)}let a=l?parseInt("0x"+l)/16**f:0;s=parseInt(s,10);let c=r*(o+a)*2**s;return c=Math.max(-e,Math.min(e,c)),c}return t.includes("nan")?r<0?NaN:NaN:t.includes("inf")?r*(1/0):r*parseFloat(t)};ut.parse=t=>ot.parse(t,34028234663852886e22);var Ft=t=>{let e=BigInt(typeof t=="string"?t.replaceAll("_",""):t),r=new Uint8Array(16);for(let i=0;i<16;i++)r[i]=Number(e&0xffn),e>>=8n;return[...r]};var ht=["unreachable","nop","block block","loop block","if block","else null","then null",,"throw tagidx",,"throw_ref","end end","br labelidx","br_if labelidx","br_table br_table","return","call funcidx","call_indirect call_indirect","return_call funcidx","return_call_indirect call_indirect","call_ref typeidx","return_call_ref typeidx",,,,,"drop","select select","",,,"try_table try_table","local.get localidx","local.set localidx","local.tee localidx","global.get globalidx","global.set globalidx","table.get tableidx","table.set tableidx",,"i32.load memarg","i64.load memarg","f32.load memarg","f64.load memarg","i32.load8_s memarg","i32.load8_u memarg","i32.load16_s memarg","i32.load16_u memarg","i64.load8_s memarg","i64.load8_u memarg","i64.load16_s memarg","i64.load16_u memarg","i64.load32_s memarg","i64.load32_u memarg","i32.store memarg","i64.store memarg","f32.store memarg","f64.store memarg","i32.store8 memarg","i32.store16 memarg","i64.store8 memarg","i64.store16 memarg","i64.store32 memarg","memory.size opt_memory","memory.grow opt_memory","i32.const i32","i64.const i64","f32.const f32","f64.const f64","i32.eqz","i32.eq","i32.ne","i32.lt_s","i32.lt_u","i32.gt_s","i32.gt_u","i32.le_s","i32.le_u","i32.ge_s","i32.ge_u","i64.eqz","i64.eq","i64.ne","i64.lt_s","i64.lt_u","i64.gt_s","i64.gt_u","i64.le_s","i64.le_u","i64.ge_s","i64.ge_u","f32.eq","f32.ne","f32.lt","f32.gt","f32.le","f32.ge","f64.eq","f64.ne","f64.lt","f64.gt","f64.le","f64.ge","i32.clz","i32.ctz","i32.popcnt","i32.add","i32.sub","i32.mul","i32.div_s","i32.div_u","i32.rem_s","i32.rem_u","i32.and","i32.or","i32.xor","i32.shl","i32.shr_s","i32.shr_u","i32.rotl","i32.rotr","i64.clz","i64.ctz","i64.popcnt","i64.add","i64.sub","i64.mul","i64.div_s","i64.div_u","i64.rem_s","i64.rem_u","i64.and","i64.or","i64.xor","i64.shl","i64.shr_s","i64.shr_u","i64.rotl","i64.rotr","f32.abs","f32.neg","f32.ceil","f32.floor","f32.trunc","f32.nearest","f32.sqrt","f32.add","f32.sub","f32.mul","f32.div","f32.min","f32.max","f32.copysign","f64.abs","f64.neg","f64.ceil","f64.floor","f64.trunc","f64.nearest","f64.sqrt","f64.add","f64.sub","f64.mul","f64.div","f64.min","f64.max","f64.copysign","i32.wrap_i64","i32.trunc_f32_s","i32.trunc_f32_u","i32.trunc_f64_s","i32.trunc_f64_u","i64.extend_i32_s","i64.extend_i32_u","i64.trunc_f32_s","i64.trunc_f32_u","i64.trunc_f64_s","i64.trunc_f64_u","f32.convert_i32_s","f32.convert_i32_u","f32.convert_i64_s","f32.convert_i64_u","f32.demote_f64","f64.convert_i32_s","f64.convert_i32_u","f64.convert_i64_s","f64.convert_i64_u","f64.promote_f32","i32.reinterpret_f32","i64.reinterpret_f64","f32.reinterpret_i32","f64.reinterpret_i64","i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s",,,,,,,,,,,,"ref.null ref_null","ref.is_null","ref.func funcidx","ref.eq","ref.as_non_null","br_on_null labelidx","br_on_non_null labelidx",,,,,,,,,,"cont.new typeidx","cont.bind cont_bind","suspend tagidx","resume resume","resume_throw resume_throw","resume_throw_ref resume_throw_ref","switch switch_cont",,,,,,,,,,,,,,,,,,,,,["struct.new typeidx","struct.new_default typeidx","struct.get typeidx_field","struct.get_s typeidx_field","struct.get_u typeidx_field","struct.set typeidx_field","array.new typeidx","array.new_default typeidx","array.new_fixed typeidx_multi","array.new_data typeidx_dataidx","array.new_elem typeidx_elemidx","array.get typeidx","array.get_s typeidx","array.get_u typeidx","array.set typeidx","array.len","array.fill typeidx","array.copy typeidx_typeidx","array.init_data typeidx_dataidx","array.init_elem typeidx_elemidx","ref.test reftype","ref.test_null reftype","ref.cast reftype","ref.cast_null reftype","br_on_cast reftype2","br_on_cast_fail reftype2","any.convert_extern","extern.convert_any","ref.i31","i31.get_s","i31.get_u",,"struct.new_desc typeidx","struct.new_default_desc typeidx","ref.get_desc typeidx","ref.cast_desc_eq reftype",,"br_on_cast_desc_eq reftype2","br_on_cast_desc_eq_fail reftype2",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"string.new_utf8 memoryidx?","string.new_wtf16 memoryidx?","string.const stringidx","string.measure_utf8","string.measure_wtf8","string.measure_wtf16","string.encode_utf8 memoryidx?","string.encode_wtf16 memoryidx?","string.concat","string.eq","string.is_usv_sequence","string.new_lossy_utf8 memoryidx?","string.new_wtf8 memoryidx?","string.encode_lossy_utf8 memoryidx?","string.encode_wtf8 memoryidx?",,"string.as_wtf8","stringview_wtf8.advance","stringview_wtf8.encode_utf8 memoryidx?","stringview_wtf8.slice","stringview_wtf8.encode_lossy_utf8 memoryidx?","stringview_wtf8.encode_wtf8 memoryidx?",,,"string.as_wtf16","stringview_wtf16.length","stringview_wtf16.get_codeunit","stringview_wtf16.encode memoryidx?","stringview_wtf16.slice",,,,"string.as_iter","stringview_iter.next","stringview_iter.advance","stringview_iter.rewind","stringview_iter.slice",,,,,,,,,,,,"string.new_utf8_array","string.new_wtf16_array","string.encode_utf8_array","string.encode_wtf16_array","string.new_lossy_utf8_array","string.new_wtf8_array","string.encode_lossy_utf8_array","string.encode_wtf8_array"],["i32.trunc_sat_f32_s","i32.trunc_sat_f32_u","i32.trunc_sat_f64_s","i32.trunc_sat_f64_u","i64.trunc_sat_f32_s","i64.trunc_sat_f32_u","i64.trunc_sat_f64_s","i64.trunc_sat_f64_u","memory.init dataidx_memoryidx","data.drop dataidx","memory.copy memoryidx_memoryidx","memory.fill memoryidx?","table.init reversed","elem.drop elemidx","table.copy tableidx_tableidx","table.grow tableidx","table.size tableidx","table.fill tableidx",,"i64.add128","i64.sub128","i64.mul_wide_s","i64.mul_wide_u",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"f32.sqrt_ceil","f32.add_ceil","f32.sub_ceil","f32.mul_ceil","f32.div_ceil","f64.sqrt_ceil","f64.add_ceil","f64.sub_ceil","f64.mul_ceil","f64.div_ceil","f32.convert_ceil_i32_s","f32.convert_ceil_i32_u","f32.convert_ceil_i64_s","f32.convert_ceil_i64_u","f32.demote_ceil_f64","f64.convert_ceil_i32_s","f64.convert_ceil_i32_u","f64.convert_ceil_i64_s","f64.convert_ceil_i64_u","f64.promote_ceil_f32","f32.sqrt_floor","f32.add_floor","f32.sub_floor","f32.mul_floor","f32.div_floor","f64.sqrt_floor","f64.add_floor","f64.sub_floor","f64.mul_floor","f64.div_floor","f32.convert_floor_i32_s","f32.convert_floor_i32_u","f32.convert_floor_i64_s","f32.convert_floor_i64_u","f32.demote_floor_f64","f64.convert_floor_i32_s","f64.convert_floor_i32_u","f64.convert_floor_i64_s","f64.convert_floor_i64_u","f64.promote_floor_f32","f32.sqrt_trunc","f32.add_trunc","f32.sub_trunc","f32.mul_trunc","f32.div_trunc","f64.sqrt_trunc","f64.add_trunc","f64.sub_trunc","f64.mul_trunc","f64.div_trunc","f32.convert_trunc_i32_s","f32.convert_trunc_i32_u","f32.convert_trunc_i64_s","f32.convert_trunc_i64_u","f32.demote_trunc_f64","f64.convert_trunc_i32_s","f64.convert_trunc_i32_u","f64.convert_trunc_i64_s","f64.convert_trunc_i64_u","f64.promote_trunc_f32"],["v128.load memarg","v128.load8x8_s memarg","v128.load8x8_u memarg","v128.load16x4_s memarg","v128.load16x4_u memarg","v128.load32x2_s memarg","v128.load32x2_u memarg","v128.load8_splat memarg","v128.load16_splat memarg","v128.load32_splat memarg","v128.load64_splat memarg","v128.store memarg","v128.const v128const","i8x16.shuffle shuffle","i8x16.swizzle","i8x16.splat","i16x8.splat","i32x4.splat","i64x2.splat","f32x4.splat","f64x2.splat","i8x16.extract_lane_s laneidx","i8x16.extract_lane_u laneidx","i8x16.replace_lane laneidx","i16x8.extract_lane_s laneidx","i16x8.extract_lane_u laneidx","i16x8.replace_lane laneidx","i32x4.extract_lane laneidx","i32x4.replace_lane laneidx","i64x2.extract_lane laneidx","i64x2.replace_lane laneidx","f32x4.extract_lane laneidx","f32x4.replace_lane laneidx","f64x2.extract_lane laneidx","f64x2.replace_lane laneidx","i8x16.eq","i8x16.ne","i8x16.lt_s","i8x16.lt_u","i8x16.gt_s","i8x16.gt_u","i8x16.le_s","i8x16.le_u","i8x16.ge_s","i8x16.ge_u","i16x8.eq","i16x8.ne","i16x8.lt_s","i16x8.lt_u","i16x8.gt_s","i16x8.gt_u","i16x8.le_s","i16x8.le_u","i16x8.ge_s","i16x8.ge_u","i32x4.eq","i32x4.ne","i32x4.lt_s","i32x4.lt_u","i32x4.gt_s","i32x4.gt_u","i32x4.le_s","i32x4.le_u","i32x4.ge_s","i32x4.ge_u","f32x4.eq","f32x4.ne","f32x4.lt","f32x4.gt","f32x4.le","f32x4.ge","f64x2.eq","f64x2.ne","f64x2.lt","f64x2.gt","f64x2.le","f64x2.ge","v128.not","v128.and","v128.andnot","v128.or","v128.xor","v128.bitselect","v128.any_true","v128.load8_lane memlane","v128.load16_lane memlane","v128.load32_lane memlane","v128.load64_lane memlane","v128.store8_lane memlane","v128.store16_lane memlane","v128.store32_lane memlane","v128.store64_lane memlane","v128.load32_zero memarg","v128.load64_zero memarg","f32x4.demote_f64x2_zero","f64x2.promote_low_f32x4","i8x16.abs","i8x16.neg","i8x16.popcnt","i8x16.all_true","i8x16.bitmask","i8x16.narrow_i16x8_s","i8x16.narrow_i16x8_u","f32x4.ceil","f32x4.floor","f32x4.trunc","f32x4.nearest","i8x16.shl","i8x16.shr_s","i8x16.shr_u","i8x16.add","i8x16.add_sat_s","i8x16.add_sat_u","i8x16.sub","i8x16.sub_sat_s","i8x16.sub_sat_u","f64x2.ceil","f64x2.floor","i8x16.min_s","i8x16.min_u","i8x16.max_s","i8x16.max_u","f64x2.trunc","i8x16.avgr_u","i16x8.extadd_pairwise_i8x16_s","i16x8.extadd_pairwise_i8x16_u","i32x4.extadd_pairwise_i16x8_s","i32x4.extadd_pairwise_i16x8_u","i16x8.abs","i16x8.neg","i16x8.q15mulr_sat_s","i16x8.all_true","i16x8.bitmask","i16x8.narrow_i32x4_s","i16x8.narrow_i32x4_u","i16x8.extend_low_i8x16_s","i16x8.extend_high_i8x16_s","i16x8.extend_low_i8x16_u","i16x8.extend_high_i8x16_u","i16x8.shl","i16x8.shr_s","i16x8.shr_u","i16x8.add","i16x8.add_sat_s","i16x8.add_sat_u","i16x8.sub","i16x8.sub_sat_s","i16x8.sub_sat_u","f64x2.nearest","i16x8.mul","i16x8.min_s","i16x8.min_u","i16x8.max_s","i16x8.max_u",,"i16x8.avgr_u","i16x8.extmul_low_i8x16_s","i16x8.extmul_high_i8x16_s","i16x8.extmul_low_i8x16_u","i16x8.extmul_high_i8x16_u","i32x4.abs","i32x4.neg",,"i32x4.all_true","i32x4.bitmask",,,"i32x4.extend_low_i16x8_s","i32x4.extend_high_i16x8_s","i32x4.extend_low_i16x8_u","i32x4.extend_high_i16x8_u","i32x4.shl","i32x4.shr_s","i32x4.shr_u","i32x4.add",,,"i32x4.sub",,,,"i32x4.mul","i32x4.min_s","i32x4.min_u","i32x4.max_s","i32x4.max_u","i32x4.dot_i16x8_s",,"i32x4.extmul_low_i16x8_s","i32x4.extmul_high_i16x8_s","i32x4.extmul_low_i16x8_u","i32x4.extmul_high_i16x8_u","i64x2.abs","i64x2.neg",,"i64x2.all_true","i64x2.bitmask",,,"i64x2.extend_low_i32x4_s","i64x2.extend_high_i32x4_s","i64x2.extend_low_i32x4_u","i64x2.extend_high_i32x4_u","i64x2.shl","i64x2.shr_s","i64x2.shr_u","i64x2.add",,,"i64x2.sub",,,,"i64x2.mul","i64x2.eq","i64x2.ne","i64x2.lt_s","i64x2.gt_s","i64x2.le_s","i64x2.ge_s","i64x2.extmul_low_i32x4_s","i64x2.extmul_high_i32x4_s","i64x2.extmul_low_i32x4_u","i64x2.extmul_high_i32x4_u","f32x4.abs","f32x4.neg",,"f32x4.sqrt","f32x4.add","f32x4.sub","f32x4.mul","f32x4.div","f32x4.min","f32x4.max","f32x4.pmin","f32x4.pmax","f64x2.abs","f64x2.neg",,"f64x2.sqrt","f64x2.add","f64x2.sub","f64x2.mul","f64x2.div","f64x2.min","f64x2.max","f64x2.pmin","f64x2.pmax","i32x4.trunc_sat_f32x4_s","i32x4.trunc_sat_f32x4_u","f32x4.convert_i32x4_s","f32x4.convert_i32x4_u","i32x4.trunc_sat_f64x2_s_zero","i32x4.trunc_sat_f64x2_u_zero","f64x2.convert_low_i32x4_s","f64x2.convert_low_i32x4_u","i8x16.relaxed_swizzle","i32x4.relaxed_trunc_f32x4_s","i32x4.relaxed_trunc_f32x4_u","i32x4.relaxed_trunc_f64x2_s_zero","i32x4.relaxed_trunc_f64x2_u_zero","f32x4.relaxed_madd","f32x4.relaxed_nmadd","f64x2.relaxed_madd","f64x2.relaxed_nmadd","i8x16.relaxed_laneselect","i16x8.relaxed_laneselect","i32x4.relaxed_laneselect","i64x2.relaxed_laneselect","f32x4.relaxed_min","f32x4.relaxed_max","f64x2.relaxed_min","f64x2.relaxed_max","i16x8.relaxed_q15mulr_s","i16x8.relaxed_dot_i8x16_i7x16_s","i32x4.relaxed_dot_i8x16_i7x16_add_s"],["memory.atomic.notify memarg","memory.atomic.wait32 memarg","memory.atomic.wait64 memarg","atomic.fence opt_memory",,,,,,,,,,,,,"i32.atomic.load memarg","i64.atomic.load memarg","i32.atomic.load8_u memarg","i32.atomic.load16_u memarg","i64.atomic.load8_u memarg","i64.atomic.load16_u memarg","i64.atomic.load32_u memarg","i32.atomic.store memarg","i64.atomic.store memarg","i32.atomic.store8 memarg","i32.atomic.store16 memarg","i64.atomic.store8 memarg","i64.atomic.store16 memarg","i64.atomic.store32 memarg","i32.atomic.rmw.add memarg","i64.atomic.rmw.add memarg","i32.atomic.rmw8.add_u memarg","i32.atomic.rmw16.add_u memarg","i64.atomic.rmw8.add_u memarg","i64.atomic.rmw16.add_u memarg","i64.atomic.rmw32.add_u memarg","i32.atomic.rmw.sub memarg","i64.atomic.rmw.sub memarg","i32.atomic.rmw8.sub_u memarg","i32.atomic.rmw16.sub_u memarg","i64.atomic.rmw8.sub_u memarg","i64.atomic.rmw16.sub_u memarg","i64.atomic.rmw32.sub_u memarg","i32.atomic.rmw.and memarg","i64.atomic.rmw.and memarg","i32.atomic.rmw8.and_u memarg","i32.atomic.rmw16.and_u memarg","i64.atomic.rmw8.and_u memarg","i64.atomic.rmw16.and_u memarg","i64.atomic.rmw32.and_u memarg","i32.atomic.rmw.or memarg","i64.atomic.rmw.or memarg","i32.atomic.rmw8.or_u memarg","i32.atomic.rmw16.or_u memarg","i64.atomic.rmw8.or_u memarg","i64.atomic.rmw16.or_u memarg","i64.atomic.rmw32.or_u memarg","i32.atomic.rmw.xor memarg","i64.atomic.rmw.xor memarg","i32.atomic.rmw8.xor_u memarg","i32.atomic.rmw16.xor_u memarg","i64.atomic.rmw8.xor_u memarg","i64.atomic.rmw16.xor_u memarg","i64.atomic.rmw32.xor_u memarg","i32.atomic.rmw.xchg memarg","i64.atomic.rmw.xchg memarg","i32.atomic.rmw8.xchg_u memarg","i32.atomic.rmw16.xchg_u memarg","i64.atomic.rmw8.xchg_u memarg","i64.atomic.rmw16.xchg_u memarg","i64.atomic.rmw32.xchg_u memarg","i32.atomic.rmw.cmpxchg memarg","i64.atomic.rmw.cmpxchg memarg","i32.atomic.rmw8.cmpxchg_u memarg","i32.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw8.cmpxchg_u memarg","i64.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw32.cmpxchg_u memarg"]],C={custom:0,type:1,import:2,func:3,table:4,memory:5,tag:13,strings:14,global:6,export:7,start:8,elem:9,datacount:12,code:10,data:11},R={i8:120,i16:119,i32:127,i64:126,f32:125,f64:124,void:64,v128:123,exn:105,noexn:116,nofunc:115,noextern:114,none:113,func:112,extern:111,any:110,eq:109,i31:108,struct:107,array:106,data:107,cont:104,nocont:117,string:103,stringview_wtf8:102,stringview_wtf16:96,stringview_iter:97,nullfuncref:115,nullexternref:114,nullexnref:116,nullref:113,funcref:112,externref:111,exnref:105,anyref:110,eqref:109,i31ref:108,structref:107,arrayref:106,contref:104,nocontref:117,stringref:103,ref:100,refnull:99,sub:80,subfinal:79,rec:78},lt={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},Lt={func:0,table:1,memory:2,global:3,tag:4};var Z=t=>{let e=0,r=[],i="",s=0,n=0,l=()=>i&&(r.push(i),i=""),f=o=>{r.loc=o;for(let a,c,m;e<t.length;)if(a=t.charCodeAt(e),s===34)i+=t[e++],a===92?i+=t[e++]:a===34&&(l(),s=0);else if(s>59)a===40&&t.charCodeAt(e+1)===59?(s++,i+=t[e++]+t[e++]):a===59&&t.charCodeAt(e+1)===41?(i+=t[e++]+t[e++],--s===59&&(l(),s=0)):i+=t[e++];else if(s<0)a===10||a===13?(i+=t[e++],l(),s=0):s===-2&&a===41?(l(),s=0):i+=t[e++];else if(a===34)i!=="$"&&l(),s=34,i+=t[e++];else if(a===40&&t.charCodeAt(e+1)===59)l(),s=60,i=t[e++]+t[e++];else if(a===59&&t.charCodeAt(e+1)===59)l(),s=t.indexOf(`
|
|
3
|
+
`,e)<0?-2:-1,i=t[e++]+t[e++];else if(a===40&&t.charCodeAt(e+1)===64)l(),m=e,e+=2,i="@",n++,(c=r).push(r=[]),f(m),r=c;else if(a===40)l(),m=e++,n++,(c=r).push(r=[]),f(m),r=c;else{if(a===41)return l(),e++,n--;a<=32?(l(),e++):i+=t[e++]}s<0&&l(),l()};return f(0),s===34&&N("Unclosed quote",e),s>59&&N("Unclosed block comment",e),n>0&&N("Unclosed parenthesis",e),e<t.length&&N("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var te=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(te).filter(r=>r!=null),e.loc=t.loc,e.length===1&&e[0]?.[0]==="module"?e[0]:e):typeof t!="string"?t:t[0]===";"||t[1]===";"?null:t[0]==="$"&&t[1]==='"'?t.includes("\\")?"$"+Zt(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?dt(t):t;function at(t){typeof t=="string"?(N.src=t,t=Z(t)||[]):N.src="",N.loc=0,t=te(t)||[];let e=0;if(t[0]==="module"?(e++,G(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return at(t.slice(++e).map(m=>m.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((m,y)=>{if(y<e||!Array.isArray(m)||m[0]!=="import")return[m];let[,u,...h]=m;if(!h.some(_=>Array.isArray(_)&&_[0]==="item"))return[m];if(Array.isArray(h.at(-1))&&h.at(-1)[0]!=="item"){let _=h.at(-1);return h.slice(0,-1).filter(b=>b[0]==="item").map(([,b])=>["import",u,b,_])}return h.filter(_=>_[0]==="item").map(([,_,b])=>["import",u,_,b])});let r=[];for(let m in C)(r[C[m]]=r[m]=[]).name=m;r.metadata={},t.slice(e).filter(m=>{if(!Array.isArray(m)){let h=N.loc,p=N.src,_;for(;(h=p.indexOf(m,h))>=0;){if(_=p.charCodeAt(h-1),h>0&&(_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95||_===36)){h++;continue}if(_=p.charCodeAt(h+m.length),_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95){h++;continue}break}h>=0&&(N.loc=h),N(`Unexpected token ${m}`)}let[y,...u]=m;if(N.loc=m.loc,y==="@custom")r.custom.push(u);else if(y==="rec")for(let h=0;h<u.length;h++){let[,...p]=u[h];Ct(p,r.type);let _=[];for(;p[0]?.[0]==="descriptor"||p[0]?.[0]==="describes";)_.push(p.shift());(p=Qt(p,r)).push(h?!0:[r.type.length,u.length]),_.length&&(p.desc=p.desc?[..._,...p.desc]:_),r.type.push(p)}else if(y==="type"){Ct(u,r.type);let h=[];for(;u[0]?.[0]==="descriptor"||u[0]?.[0]==="describes";)h.push(u.shift());let p=Qt(u,r);h.length&&(p.desc=p.desc?[...h,...p.desc]:h),r.type.push(p)}else if(y==="start"||y==="export")r[y].push(u);else return!0}).forEach(m=>{let[y,...u]=m;N.loc=m.loc;let h;y==="import"&&([y,...u]=(h=u).pop());let p=r[y];for(p||N(`Unknown section ${y}`),Ct(u,p);u[0]?.[0]==="export";)r.export.push([u.shift()[1],[y,p?.length]]);if(u[0]?.[0]==="import"&&([,...h]=u.shift()),y==="table"){let _=u[0]==="i64",b=_?1:0;if(u[b+1]?.[0]==="elem"){let[$,[,...w]]=[u[b],u[b+1]];u=_?["i64",w.length,w.length,$]:[w.length,w.length,$],r.elem.push([["table",p.length],["offset",[_?"i64.const":"i32.const",_?0n:0]],$,...w])}}else if(y==="memory"){let _=u[0]==="i64",b=_?1:0;if(u[b]?.[0]==="data"){let $=u.find(I=>Array.isArray(I)&&I[0]==="pagesize")?.[1]??65536,[,...w]=u.splice(b,1)[0],S=""+Math.ceil(w.reduce((I,k)=>I+k.length,0)/$);r.data.push([["memory",p.length],[_?"i64.const":"i32.const",_?0n:0],...w]),u=_?["i64",S,S]:[S,S]}}else if(y==="func"){let[_,b,$]=Mt(u,r);_??=kt(b,$,r),!h&&r.code.push([[_,b,$],...nt(u,r)]),u=[["type",_]]}else if(y==="tag"){let[_,b]=Mt(u,r);_??=kt(b,[],r),u=[["type",_]]}h&&(r.import.push([...h,[y,...u]]),u=null),p.push(u)});let i=(m,y=!0)=>{let u=r[m].filter(Boolean).map(h=>ee[m](h,r)).filter(Boolean);return m===C.custom?u.flatMap(h=>[m,...q(h)]):u.length?[m,...q(y?q(u):u.flat())]:[]},s=()=>{let m=[];for(let y in r.metadata){let u=q(dt(`"metadata.code.${y}"`)),h=q(r.metadata[y].map(([p,_])=>[...g(p),...q(_.map(([b,$])=>[...g(b),...q($)]))]));m.push(0,...q([...u,...h]))}return m},n=i(C.global),l=i(C.elem),f=i(C.code),o=s(),a=i(C.data),c=r.strings.length?[C.strings,...q([0,...q(r.strings.map(m=>q(m)))])]:[];return Uint8Array.from([0,97,115,109,1,0,0,0,...i(C.custom),...i(C.type),...i(C.import),...i(C.func),...i(C.table),...i(C.memory),...i(C.tag),...c,...n,...i(C.export),...i(C.start,!1),...l,...i(C.datacount,!1),...f,...o,...a])}var K=t=>t?.[0]==="$"||!isNaN(t),G=t=>t?.[0]==="$",Dt=t=>t?.[0]==="a"||t?.[0]==="o";function nt(t,e){let r=[];for(t=[...t];t.length;){let i=t.shift();if(typeof i=="string")if(r.push(i),i==="block"||i==="if"||i==="loop")G(t[0])&&r.push(t.shift()),r.push(bt(t,e));else if(i==="else"||i==="end")G(t[0])&&t.shift();else if(i==="select")r.push(Bt(t)[1]);else if(i.endsWith("call_indirect")){let s=K(t[0])?t.shift():0,[n,l,f]=Mt(t,e);r.push(s,["type",n??kt(l,f,e)])}else i==="table.init"?r.push(K(t[1])?t.shift():0,t.shift()):i==="table.copy"||i==="memory.copy"?r.push(K(t[0])?t.shift():0,K(t[0])?t.shift():0):i.startsWith("table.")?r.push(K(t[0])?t.shift():0):i==="memory.init"?(r.push(...K(t[1])?[t.shift(),t.shift()].reverse():[t.shift(),0]),e.datacount&&(e.datacount[0]=!0)):i==="data.drop"||i==="array.new_data"||i==="array.init_data"?(i==="data.drop"&&r.push(t.shift()),e.datacount&&(e.datacount[0]=!0)):(i.startsWith("memory.")||i.endsWith("load")||i.endsWith("store"))&&K(t[0])&&r.push(t.shift());else if(Array.isArray(i)){let s=i[0];if(i.loc!=null&&(N.loc=i.loc),s?.startsWith?.("@metadata.code.")){let l=s.slice(15);r.push(["@metadata",l,i[1]]);continue}if(typeof s!="string"||!Array.isArray(ht[s])){r.push(i);continue}let n=i.slice(1);if(s==="block"||s==="loop")r.push(s),G(n[0])&&r.push(n.shift()),r.push(bt(n,e),...nt(n,e),"end");else if(s==="if"){let l=[],f=[];n.at(-1)?.[0]==="else"&&(f=nt(n.pop().slice(1),e)),n.at(-1)?.[0]==="then"&&(l=nt(n.pop().slice(1),e));let o=[s];G(n[0])&&o.push(n.shift()),o.push(bt(n,e)),r.push(...nt(n,e),...o,...l),f.length&&r.push("else",...f),r.push("end")}else if(s==="try_table"){for(r.push(s),G(n[0])&&r.push(n.shift()),r.push(bt(n,e));n[0]?.[0]==="catch"||n[0]?.[0]==="catch_ref"||n[0]?.[0]==="catch_all"||n[0]?.[0]==="catch_all_ref";)r.push(n.shift());r.push(...nt(n,e),"end")}else if(s==="ref.test"||s==="ref.cast"){let l=n[0];(!Array.isArray(l)||l[1]==="null"||l[0]!=="ref")&&(s+="_null"),r.push(...nt(n.slice(1),e),s,l),t.unshift(...r.splice(r.length-2))}else{let l=[];for(;n.length&&(!Array.isArray(n[0])||n[0].valueOf!==Array.prototype.valueOf||"type,param,result,ref,exact,on".includes(n[0][0]));)l.push(n.shift());r.push(...nt(n,e),s,...l),t.unshift(...r.splice(r.length-1-l.length))}}else r.push(i)}return r}var kt=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),Rt=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=G(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},Bt=t=>{let e=Rt(t,"param"),r=Rt(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},Mt=(t,e)=>{if(t[0]?.[0]!=="type")return[,...Bt(t)];let[,r]=t.shift(),[i,s]=Bt(t),n=e.type[typeof r=="string"&&isNaN(r)?e.type[r]:+r];if(!n)throw Error(`Unknown type ${r}`);if((i.length||s.length)&&n[1].join(">")!==i+">"+s)throw Error(`Type ${r} mismatch`);return[r,...n[1]]},bt=(t,e)=>{let[r,i,s]=Mt(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??kt(i,s,e)]},Ct=(t,e)=>{let r=G(t[0])&&t.shift();return r&&(r in e?N(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},Qt=([t],e)=>{let r="subfinal",i=[],s,n=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(i=t).pop(),i=i.filter(f=>Array.isArray(f)&&(f[0]==="descriptor"||f[0]==="describes")?(n.push(f),!1):!0)),[s,...t]=t,s==="func"?(t=Bt(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=Rt(t,"field"):s==="array"&&([t]=t);let l=[s,t,r,i];return n.length&&(l.desc=n),l},ee=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...q(t),...i.flat()]},(t,e)=>{let[r,i,s,n,l]=t;if(l===!0)return;let f=(t.desc??[]).flatMap(([a,c])=>[a==="descriptor"?77:76,...g(v(c,e.type))]),o=(a,c)=>a==="func"?[lt.func,...q(c[0].map(m=>Y(m,e))),...q(c[1].map(m=>Y(m,e)))]:a==="array"?[lt.array,...wt(c,e)]:a==="struct"?[lt.struct,...q(c.map(m=>wt(m,e)))]:a==="cont"?[lt.cont,...g(v(c[0]??c,e.type))]:[lt[a]];if(l){let[a,c]=l,m=Array.from({length:c},(y,u)=>{let h=e.type[a+u],p=h.slice(0,4);return h.desc&&(p.desc=h.desc),ee[C.type](p,e)});return[lt.rec,...q(m)]}else if(s==="sub"||n?.length)return[lt[s],...q(n.map(a=>v(a,e.type))),...f,...o(r,i)];return[...f,...o(r,i)]},([t,e,[r,...i]],s)=>{let n,l=Lt[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(l=32);let[[,o]]=i;n=g(v(o,s.type))}else if(r==="tag"){let[[,f]]=i;n=[0,...g(v(f,s.type))]}else r==="memory"?n=vt(i):r==="global"?n=wt(i[0],s):r==="table"?n=[...Y(i.pop(),s),...vt(i)]:N(`Unknown kind ${r}`);return[...q(t),...q(e),l,...n]},([[,t]],e)=>g(v(t,e.type)),(t,e)=>{let r=vt(t),i=Y(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...yt(s,e)]:[...i,...r]},(t,e)=>vt(t),([t,e],r)=>[...wt(t,r),...yt(e,r)],([t,[e,r]],i)=>[...q(t),Lt[e],...g(v(r,i[e]))],([t],e)=>g(v(t,e.func)),(t,e)=>{let r=0,i=0,s=0,n=0,l,f,o;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,l]=t.shift(),l=v(l,e.table)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&t[1][0]!=="item"&&!t[1][0]?.startsWith("ref"))&&(l=v(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(f=t.shift(),f[0]==="offset"&&([,f]=f),f=yt(f,e)):i||(r=1),R[t[0]]||t[0]?.[0]==="ref"?o=Y(t.shift(),e):t[0]==="func"?o=[R[t.shift()]]:o=[R.func],t=t.map(c=>(c[0]==="item"&&(c=c.length===3&&c[1]==="ref.func"?c[2]:c[1]),c[0]==="ref.func"&&([,c]=c),typeof c!="string"&&(s=1),c)),o[0]!==R.funcref&&(n=1,s=1);let a=s<<2|(r||i?i:!!l||n)<<1|(r||i);return[a,...a===0?f:a===1?[0]:a===2?[...g(l||0),...f,0]:a===3?[0]:a===4?f:a===5?o:a===6?[...g(l||0),...f,...o]:o,...q(t.map(s?c=>yt(typeof c=="string"?["ref.func",c]:c,e):c=>g(v(c,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[v(r,e.type)]),e.local=Object.create(i),e.block=[],e.local.name="local",e.block.name="block",e._codeIdx===void 0&&(e._codeIdx=0);let s=e._codeIdx++;for(;t[0]?.[0]==="local";){let[,...o]=t.shift();if(G(o[0])){let a=o.shift();a in e.local?N(`Duplicate local ${a}`):e.local[a]=e.local.length}e.local.push(...o)}e.meta={};let n=ie(t,e),l=e.import.filter(o=>o[2][0]==="func").length+s;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([l,e.meta[o]]);let f=e.local.slice(i.length).reduce((o,a)=>(a==o[o.length-1]?.[1]?o[o.length-1][0]++:o.push([1,a]),o),[]);return e.local=e.block=e.meta=null,q([...q(f.map(([o,a])=>[...g(o),...Y(a,e)])),...n])},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=v(i,e.memory)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&typeof t[1][0]=="string")&&(i=v(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??N("Bad offset",r)),[...i?[2,...g(i),...yt(r,e)]:r?[0,...yt(r,e)]:[1],...q(t.flatMap(s=>Qe(s)??[...s]))]},(t,e)=>g(e.data.length),([[,t]],e)=>[0,...g(v(t,e.type))]],Y=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[R.refnull,98,...g(v(t[2][1],e.type))]:R[t[2]]?[R[t[2]]]:[R.refnull,...g(v(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[R.ref,98,...g(v(t[1][1],e.type))]:[R.ref,...g(R[t[t.length-1]]||v(t[t.length-1],e.type))]:[R[t]??N(`Unknown type ${t}`)],wt=(t,e,r=t[0]==="mut"?1:0)=>[...Y(r?t[1]:t,e),r],re={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...g(v(i,e.elem)),...g(v(r,e.table))]},block:(t,e)=>{e.block.push(1),G(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?Y(r[1],e):g(v(r[1],e.type)):[R.void]},try_table:(t,e)=>{G(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?Y(r[1],e):g(v(r[1],e.type)):[R.void],s=[],n=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let l=t.shift(),f=l[0]==="catch"?0:l[0]==="catch_ref"?1:l[0]==="catch_all"?2:3;f<=1?s.push(f,...g(v(l[1],e.tag)),...g(ft(l[2],e.block))):s.push(f,...g(ft(l[1],e.block))),n++}return e.block.push(1),[...i,...g(n),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...g(v(i,e.type)),...g(v(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||G(t[0]));)r.push(...g(ft(t.shift(),e.block))),i++;return[...g(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?q(r.map(i=>Y(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...g(v(r[1],e.type))]:R[r]?[R[r]]:g(v(r,e.type))},memarg:(t,e,r)=>Jt(t,r,K(t[0])&&!Dt(t[0])?v(t.shift(),e.memory):0),opt_memory:(t,e)=>g(v(K(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=Y(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=ft(t.shift(),e.block),i=Y(t.shift(),e),s=Y(t.shift(),e),n=l=>l.length>1?l.slice(1):l;return[(s[0]!==R.ref)<<1|i[0]!==R.ref,...g(r),...n(i),...n(s)]},v128const:t=>{let[e,r]=t.shift().split("x"),i=+e.slice(1),s=i>>>3;if(r=+r,e[0]==="i"){let l=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let f=0;f<r;f++)l[f]=At[e].parse(t.shift());return[...new Uint8Array(l.buffer)]}let n=new Uint8Array(16);for(let l=0;l<r;l++)n.set(At[e](t.shift()),l*s);return[...n]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(It(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&N("invalid lane length"),e},memlane:(t,e,r)=>{let i=G(t[0])||K(t[0])&&(Dt(t[1])||K(t[1]))?v(t.shift(),e.memory):0;return[...Jt(t,r,i),...g(It(t.shift()))]},"*":t=>g(t.shift()),labelidx:(t,e)=>g(ft(t.shift(),e.block)),laneidx:t=>[It(t.shift(),255)],funcidx:(t,e)=>g(v(t.shift(),e.func)),typeidx:(t,e)=>g(v(t.shift(),e.type)),tableidx:(t,e)=>g(v(t.shift(),e.table)),memoryidx:(t,e)=>g(v(t.shift(),e.memory)),globalidx:(t,e)=>g(v(t.shift(),e.global)),localidx:(t,e)=>g(v(t.shift(),e.local)),dataidx:(t,e)=>g(v(t.shift(),e.data)),elemidx:(t,e)=>g(v(t.shift(),e.elem)),tagidx:(t,e)=>g(v(t.shift(),e.tag)),"memoryidx?":(t,e)=>g(v(K(t[0])?t.shift():0,e.memory)),stringidx:(t,e)=>{let r=t.shift(),i=r.valueOf(),s=e.strings.findIndex(n=>n.valueOf()===i);return s<0&&(s=e.strings.push(r)-1),g(s)},i32:t=>H(t.shift()),i64:t=>ct(t.shift()),f32:t=>ut(t.shift()),f64:t=>ot(t.shift()),v128:t=>Ft(t.shift()),typeidx_field:(t,e)=>{let r=v(t.shift(),e.type);return[...g(r),...g(v(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...g(v(t.shift(),e.type)),...g(t.shift())],typeidx_dataidx:(t,e)=>[...g(v(t.shift(),e.type)),...g(v(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...g(v(t.shift(),e.type)),...g(v(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...g(v(t.shift(),e.type)),...g(v(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...g(v(t.shift(),e.data)),...g(v(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...g(v(t.shift(),e.memory)),...g(v(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...g(v(t.shift(),e.table)),...g(v(t.shift(),e.table))],cont_bind:(t,e)=>[...g(v(t.shift(),e.type)),...g(v(t.shift(),e.type))],switch_cont:(t,e)=>[...g(v(t.shift(),e.type)),...g(v(t.shift(),e.tag))],resume:(t,e)=>{let r=g(v(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...g(v(n,e.tag))):i.push(0,...g(v(n,e.tag)),...g(ft(l,e.block))),s++}return[...r,...g(s),...i]},resume_throw:(t,e)=>{let r=g(v(t.shift(),e.type)),i=g(v(t.shift(),e.tag)),s=[],n=0;for(;t[0]?.[0]==="on";){let[,l,f]=t.shift();f==="switch"?s.push(1,...g(v(l,e.tag))):s.push(0,...g(v(l,e.tag)),...g(ft(f,e.block))),n++}return[...r,...i,...g(n),...s]},resume_throw_ref:(t,e)=>{let r=g(v(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...g(v(n,e.tag))):i.push(0,...g(v(n,e.tag)),...g(ft(l,e.block))),s++}return[...r,...g(s),...i]}},$t={};(function t(e,r){for(let i=0,s,n,l;i<e.length;i++)(s=e[i])&&(Array.isArray(s)?t(s,i):([n,l]=s.split(" "),ht[n]=r?[r,...g(i)]:[i],l&&($t[n]=re[l])))})(ht);var ie=(t,e)=>{let r=[],i=[];for(;t?.length;){let s=t.shift();if(s?.[0]==="@metadata"){i.push(s.slice(1));continue}Array.isArray(s)&&(s.loc!=null&&(N.loc=s.loc),N(`Unknown instruction ${s[0]}`));let[...n]=ht[s]||N(`Unknown instruction ${s}`);$t[s]&&(s==="select"&&t[0]?.length?n[0]++:$t[s]===re.reftype&&!s.endsWith("_null")&&(t[0][1]==="null"||t[0][0]!=="ref")&&n[n.length-1]++,n.push(...$t[s](t,e,s)));for(let[l,f]of i)(e.meta[l]??=[]).push([r.length,f]);r.push(...n)}return r.push(11),r},yt=(t,e)=>ie(nt([t],e),e),v=(t,e,r)=>(r=G(t)?e[t]:+t,r in e?r:N(`Unknown ${e.name} ${t}`)),ft=(t,e,r)=>(r=G(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?N(`Bad label ${t}`):r),Ze=t=>{let e,r,i,s;for(;Dt(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:N(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&N(`Bad offset ${r}`),(e<=0||e>4294967295)&&N(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&N(`Bad align ${e}`),[e,r]},Jt=(t,e,r=0)=>{let[i,s]=Ze(t),n=(i??Ke(e))|(r&&64);return r?[...g(n),...g(r),...g(s??0)]:[...g(n),...g(s??0)]},Ke=t=>{let e=t.indexOf(".",3)+1,r=t.slice(1,t[0]==="v"?4:3);if(t[e]==="a"&&(e=t.indexOf(".",e)+1),t[0]==="m")return t.includes("64")?3:2;if(t[e]==="r"){let n=t.slice(e,e+6).match(/\d+/);return Math.log2(n?n[0]/8:+r/8)}let i=t[e]==="l"?e+4:e+5,s=t.slice(i).match(/(\d+)(x|_|$)/);return Math.log2(s?s[2]==="x"?8:s[1]/8:+r/8)},Qe=t=>{if(!Array.isArray(t))return null;let[e,...r]=t;if(e!=="i8"&&e!=="i16"&&e!=="i32"&&e!=="i64"&&e!=="f32"&&e!=="f64")return null;let i=[],s=new DataView(new ArrayBuffer(8));for(let n of r)e==="i8"?i.push(H.parse(n)&511&255):e==="i16"?(s.setInt16(0,H.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,H.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,4))):e==="i64"?(s.setBigInt64(0,BigInt(n),!0),i.push(...new Uint8Array(s.buffer,0,8))):e==="f32"?i.push(...ut(n)):e==="f64"&&i.push(...ot(n));return i},vt=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(a=>Array.isArray(a)&&a[0]==="pagesize"),s=-1;i>=0&&(s=Math.log2(+t.splice(i,1)[0][1]));let n=!isNaN(parseInt(t[1])),l=(s>=0?8:0)|(e?4:0)|(r?2:0)|(n?1:0),f=e?a=>{if(typeof a=="bigint")return a;let c=typeof a=="string"?a.replaceAll("_",""):String(a);return BigInt(c)}:It,o=s>=0?g(s):[];return n?[l,...g(f(t.shift())),...g(f(t.shift())),...o]:[l,...g(f(t.shift())),...o]},It=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?H.parse(t):typeof t=="number"?t:N(`Bad int ${t}`);return r>e?N(`Value out of range ${t}`):r},q=t=>[...g(t.length),...t.flat()];function se(t,e={}){typeof t=="string"&&(t=Z(t));let{indent:r=" ",newline:i=`
|
|
4
|
+
`,comments:s=!0}=e;if(r||="",i||="",typeof t[0]=="string"&&t[0][0]!==";")return l(t);return t.filter(f=>s||!n(f)).map(f=>l(f)).join(i);function n(f){return typeof f=="string"&&f[1]===";"}function l(f,o=0){if(!Array.isArray(f))return f;let a=f[0];if(!a)return"";let c=!1;if(a==="try_table"){let u=1;for(typeof f[u]=="string"&&f[u][0]==="$"&&(a+=" "+f[u++]),Array.isArray(f[u])&&(f[u][0]==="result"||f[u][0]==="type")&&(a+=" "+l(f[u++],o));Array.isArray(f[u])&&/^catch/.test(f[u][0]);)a+=" "+l(f[u++],o).trim();for(;u<f.length;u++)a+=Array.isArray(f[u])?i+r.repeat(o+1)+l(f[u],o+1):" "+f[u];return`(${a+i+r.repeat(o)})`}let m=!!i&&f.length<4&&!f.some(u=>typeof u=="string"&&u[0]===";"&&u[1]===";"),y=r.repeat(o+1);for(let u=1;u<f.length;u++){let h=f[u].valueOf();if(typeof h=="string"&&h[1]===";"){if(!s)continue;if(h[0]===";")if(i)a+=i+y+h.trimEnd(),c=!0;else{let p=a[a.length-1];p&&p!==" "&&p!=="("&&(a+=" "),a+=h.trimEnd()+`
|
|
5
|
+
`}else{let p=a[a.length-1];p&&p!==" "&&p!=="("&&(a+=" "),a+=h.trimEnd()}}else if(Array.isArray(h))m&&(m=h.every(p=>!Array.isArray(p))),a+=i+y+l(h,o+1),c=!1;else if(f[0]==="data")m=!1,(i||a[a.length-1]!==")")&&(a+=i||" "),a+=y+h,c=!1;else{let p=a[a.length-1];c&&i?a+=i+y:p===`
|
|
6
|
+
`?a+="":(p&&p!==")"&&p!==" "||i||p===")")&&(a+=" "),a+=h,c=!1}}return m?`(${a.replaceAll(i+y+"("," (")})`:`(${a+i+r.repeat(o)})`}}var le={funcref:["ref.func","call_ref","return_call_ref"],sign_ext:["i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s"],nontrapping:["i32.trunc_sat_f32_s","i32.trunc_sat_f32_u","i32.trunc_sat_f64_s","i32.trunc_sat_f64_u","i64.trunc_sat_f32_s","i64.trunc_sat_f32_u","i64.trunc_sat_f64_s","i64.trunc_sat_f64_u"],bulk_memory:["memory.copy","memory.fill"],return_call:["return_call","return_call_indirect"],i31ref:["ref.i31","i31.get_s","i31.get_u"],extended_const:["global.get"],multi_value:[],gc:["struct.new","struct.get","struct.set","array.new","array.get","array.set","array.len","struct.new_default","array.new_default","array.new_fixed","array.copy"],ref_cast:["ref.test","ref.cast","br_on_cast","br_on_cast_fail"]},Wt=Object.keys(le),Je=t=>{if(t===!0)return Object.fromEntries(Wt.map(e=>[e,!0]));if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return Object.fromEntries(Wt.map(r=>[r,e.has(r)||e.has("all")]))}return{...t}},P=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)P(t[s],e,t,s)},et=(t,e,r,i)=>{if(Array.isArray(t))for(let s=0;s<t.length;s++)et(t[s],e,t,s);e(t,r,i)},tr=t=>{let e=new Set;return P(t,r=>{if(typeof r=="string")for(let[i,s]of Object.entries(le))s.some(n=>r===n||r.startsWith(n+" "))&&e.add(i)}),P(t,r=>{if(!(!Array.isArray(r)||r[0]!=="global"))for(let i of r)Array.isArray(i)&&(i[0]==="i32.add"||i[0]==="i32.sub"||i[0]==="i32.mul"||i[0]==="i64.add"||i[0]==="i64.sub"||i[0]==="i64.mul")&&P(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),P(t,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=0;for(let s of r)Array.isArray(s)&&s[0]==="result"&&(i+=s.length-1);i>1&&e.add("multi_value")}),e},fe=t=>Array.isArray(t)?t.map(fe):t,ae=(t,e)=>{let r=[],i=t[0]==="module"?1:0;for(let s=i;s<t.length;s++)Array.isArray(t[s])&&t[s][0]===e&&r.push({node:t[s],idx:s});return r},Nt=(t,e,r)=>t.splice(e,0,r),er=0,rt=t=>`$__${t}${er++}`,rr=(t,e)=>{let r=new Set;if(P(t,a=>{Array.isArray(a)&&a[0]==="ref.func"&&r.add(a[1])}),!r.size)return t;let i=rt("fntbl"),s=[...r],n=Object.fromEntries(s.map((a,c)=>[a,c])),l=ae(t,"func"),f=l.length?l[0].idx:t[0]==="module"?1:0;Nt(t,f,["table",i,"funcref",["elem",...s]]);let o={};return P(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!c)return;let m=[],y=[];for(let u of a){if(Array.isArray(u)&&u[0]==="param")for(let h=1;h<u.length;h++)u[h][0]!=="$"&&m.push(u[h]);if(Array.isArray(u)&&u[0]==="result")for(let h=1;h<u.length;h++)y.push(u[h])}o[c]={params:m,results:y}}),et(t,(a,c,m)=>{if(!(!Array.isArray(a)||!c)){if(a[0]==="ref.func"&&n[a[1]]!==void 0&&(c[m]=["i32.const",n[a[1]]]),a[0]==="call_ref"){let y=a[1],u=a.slice(2);c[m]=["call_indirect",i,["type",y],...u]}if(a[0]==="return_call_ref"){let y=a[1],u=a.slice(2);c[m]=["return_call_indirect",i,["type",y],...u]}}}),t},tt={funcref:rr},ir={"i32.extend8_s":["i32",24],"i32.extend16_s":["i32",16],"i64.extend8_s":["i64",56n],"i64.extend16_s":["i64",48n],"i64.extend32_s":["i64",32n]},sr=(t,e)=>(et(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let n=ir[r[0]];if(!n)return;let[l,f]=n,o=r.slice(1);i[s]=[`${l}.shr_s`,[`${l}.shl`,...o,[`${l}.const`,f]],[`${l}.const`,f]]}),t);tt.sign_ext=sr;var ne={"i32.trunc_sat_f32_s":{itype:"i32",ftype:"f32",signed:!0,min:-2147483648,max:2147483647},"i32.trunc_sat_f32_u":{itype:"i32",ftype:"f32",signed:!1,min:0,max:4294967295},"i32.trunc_sat_f64_s":{itype:"i32",ftype:"f64",signed:!0,min:-2147483648,max:2147483647},"i32.trunc_sat_f64_u":{itype:"i32",ftype:"f64",signed:!1,min:0,max:4294967295},"i64.trunc_sat_f32_s":{itype:"i64",ftype:"f32",signed:!0,min:-9223372036854775808n,max:9223372036854775807n},"i64.trunc_sat_f32_u":{itype:"i64",ftype:"f32",signed:!1,min:0n,max:18446744073709551615n},"i64.trunc_sat_f64_s":{itype:"i64",ftype:"f64",signed:!0,min:-9223372036854775808n,max:9223372036854775807n},"i64.trunc_sat_f64_u":{itype:"i64",ftype:"f64",signed:!1,min:0n,max:18446744073709551615n}},nr=(t,e)=>{let r=new Set;if(P(t,s=>{Array.isArray(s)&&ne[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:n,ftype:l,signed:f,min:o,max:a}=ne[s],c=rt(`trunc_${n}_${l}_${f?"s":"u"}`);i[s]=c;let m=`${n}.trunc_${l}_${f?"s":"u"}`,y=n==="i64"?0n:0,u=["func",c,["param","$v",l],["result",n],["if",["result",n],[`${l}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${n}.const`,y]],["else",["if",["result",n],[`${l}.lt`,["local.get","$v"],[`${l}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${n}.const`,o]],["else",["if",["result",n],[`${l}.gt`,["local.get","$v"],[`${l}.const`,typeof a=="bigint"?Number(a):a]],["then",[`${n}.const`,a]],["else",[m,["local.get","$v"]]]]]]]]];t.push(u)}return et(t,(s,n,l)=>{!Array.isArray(s)||!n||i[s[0]]&&(n[l]=["call",i[s[0]],...s.slice(1)])}),t};tt.nontrapping=nr;var lr=(t,e)=>{let r=new Set,i=new Set;P(t,l=>{if(Array.isArray(l)){if(l[0]==="memory.copy"){let f=typeof l[1]=="number"?l[1]:0,o=typeof l[2]=="number"?l[2]:0;r.add(`${f}_${o}`)}if(l[0]==="memory.fill"){let f=typeof l[1]=="number"?l[1]:0;i.add(f)}}});let s={},n={};for(let l of r){let[f,o]=l.split("_").map(Number),a=rt(`memcpy${l==="0_0"?"":"_"+l}`);s[l]=a;let c=f?["i32.store8",f]:["i32.store8"],m=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",a,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...m,["i32.add",["local.get","$src"],["local.get","$i"]]]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}for(let l of i){let f=rt(`memset${l===0?"":"_"+l}`);n[l]=f;let o=l?["i32.store8",l]:["i32.store8"];t.push(["func",f,["param","$dst","i32"],["param","$val","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...o,["i32.add",["local.get","$dst"],["local.get","$i"]],["local.get","$val"]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}return et(t,(l,f,o)=>{if(!(!Array.isArray(l)||!f)){if(l[0]==="memory.copy"){let a=typeof l[1]=="number"?l[1]:0,c=typeof l[2]=="number"?l[2]:0,m=l.filter(y=>Array.isArray(y)||typeof y=="string"&&y[0]==="$");f[o]=["call",s[`${a}_${c}`],...m]}if(l[0]==="memory.fill"){let a=typeof l[1]=="number"?l[1]:0,c=l.filter(m=>Array.isArray(m)||typeof m=="string"&&m[0]==="$");f[o]=["call",n[a],...c]}}}),t};tt.bulk_memory=lr;var fr=(t,e)=>{let r=!1;return P(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&et(t,(i,s,n)=>{!Array.isArray(i)||!s||(i[0]==="return_call"&&(s[n]=["return",["call",...i.slice(1)]]),i[0]==="return_call_indirect"&&(s[n]=["return",["call_indirect",...i.slice(1)]]))}),t};tt.return_call=fr;var ar=(t,e)=>(et(t,(r,i,s)=>{if(!(!Array.isArray(r)||!i)&&(r[0]==="ref.i31"&&(i[s]=["i32.and",...r.slice(1),["i32.const",2147483647]]),r[0]==="i31.get_u"&&(i[s]=r.length>1?r[1]:["drop"]),r[0]==="i31.get_s")){let n=r.slice(1);i[s]=["i32.shr_s",["i32.shl",...n,["i32.const",1]],["i32.const",1]]}}),t);tt.i31ref=ar;var or=(t,e)=>{let r={};P(t,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l=s.length-1;l>=0;l--){let f=s[l];if(Array.isArray(f)&&(f[0]==="i32.const"||f[0]==="i64.const"||f[0]==="f32.const"||f[0]==="f64.const")){r[n]={type:f[0].split(".")[0],value:f[1]};break}}});let i=s=>{if(!Array.isArray(s))return s;let n=s[0];if(n==="global.get"&&r[s[1]]){let l=r[s[1]];return[`${l.type}.const`,l.value]}if(n==="i32.add"||n==="i64.add"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a+c]}}if(n==="i32.sub"||n==="i64.sub"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a-c]}}if(n==="i32.mul"||n==="i64.mul"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a*c]}}return s};return et(t,(s,n,l)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!n)){for(let f=2;f<s.length;f++)if(Array.isArray(s[f])){let o=i(s[f]);o!==s[f]&&(s[f]=o)}}}),t};tt.extended_const=or;var cr=(t,e)=>{let r=new Map,i=[];if(P(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let o=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null,a=[];for(let c of f)if(Array.isArray(c)&&c[0]==="result")for(let m=1;m<c.length;m++)a.push(c[m]);a.length>1&&o&&r.set(o,a)}),!r.size)return t;let s=Math.max(...[...r.values()].map(f=>f.length)),n={};for(let[f,o]of r)for(let a=1;a<o.length;a++){let c=o[a];if(n[c]||(n[c]=[]),n[c].length<a){let m=rt(`ret_${c}_${n[c].length}`);n[c].push(m),i.push(["global",m,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let l=t[0]==="module"?1:0;for(let f of i.reverse())Nt(t,l,f);return et(t,(f,o,a)=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c||!r.has(c))return;let m=r.get(c);for(let y=0;y<f.length;y++)if(Array.isArray(f[y])&&f[y][0]==="result"){f[y]=["result",m[0]];break}}),t};tt.multi_value=cr;var xt={i32:4,i64:8,f32:4,f64:8},ur=(t,e)=>{let r=new Map,i=new Map,s=1;if(P(t,p=>{if(!Array.isArray(p)||p[0]!=="type")return;let _=typeof p[1]=="string"&&p[1][0]==="$"?p[1]:null;if(_){for(let b of p)if(Array.isArray(b)){if(b[0]==="struct"){let $=[];for(let w of b)if(Array.isArray(w)&&w[0]==="field"){let S=typeof w[1]=="string"&&w[1][0]==="$"?w[1]:null,I=S?w[2]:w[1],k=Array.isArray(I)&&I[0]==="mut"?I[1]:I;$.push({name:S,type:k})}r.set(_,{kind:"struct",fields:$}),i.set(_,s++)}if(b[0]==="array"){let $=b[1],w=Array.isArray($)&&$[0]==="mut"?$[1]:$;r.set(_,{kind:"array",elemType:w}),i.set(_,s++)}}}}),!r.size)return t;let n=ae(t,"memory").length>0,l=rt("alloc"),f=rt("heap_ptr"),o=t[0]==="module"?1:0;n||Nt(t,o,["memory",1]),Nt(t,o+1,["global",f,["mut","i32"],["i32.const",1024]]);let a=["func",l,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",f]],["global.set",f,["i32.add",["global.get",f],["local.get","$size"]]],["local.get","$ptr"]];t.push(a);let c=p=>{let _=4;for(let b of p.fields)_+=xt[b.type]||4;return _},m=(p,_)=>{let b=4;for(let $=0;$<_;$++)b+=xt[p.fields[$].type]||4;return b},y=(p,_)=>{for(let b=0;b<p.fields.length;b++)if(p.fields[b].name===_)return b;return-1},u=0,h=()=>`$__gc_tmp${u++}`;return P(t,p=>{if(!Array.isArray(p)||p[0]!=="func")return;let _=!1,b=!1,$=!1,w=!1;if(P(p,I=>{Array.isArray(I)&&((I[0]==="struct.new"||I[0]==="struct.new_default")&&(_=!0),(I[0]==="array.new"||I[0]==="array.new_default")&&(b=!0,$=!0,w=!0))}),!_&&!b)return;let S=1;for(let I=1;I<p.length;I++){let k=p[I];if(Array.isArray(k)&&(k[0]==="param"||k[0]==="result"||k[0]==="local"||k[0]==="export"||k[0]==="type"))S=I+1;else if(typeof k=="string"&&k[0]==="$")S=I+1;else if(!Array.isArray(k))S=I+1;else break}_&&p.splice(S++,0,["local","$__gc_ptr","i32"]),b&&p.splice(S++,0,["local","$__gc_aptr","i32"]),$&&p.splice(S++,0,["local","$__gc_alen","i32"]),w&&p.splice(S++,0,["local","$__gc_aidx","i32"])}),et(t,(p,_,b)=>{if(!(!Array.isArray(p)||!_)){if(p[0]==="struct.new"||p[0]==="struct.new_default"){let $=p[1],w=r.get($);if(!w||w.kind!=="struct")return;let S=c(w),I=i.get($),k=p.slice(2),O="$__gc_ptr",U=[["local.set",O,["call",l,["i32.const",S]]],["i32.store",["local.get",O],["i32.const",I]]];if(p[0]==="struct.new")for(let E=0;E<w.fields.length;E++){let A=w.fields[E],d=m(w,E),M=A.type==="i64"?"i64.store":A.type==="f32"?"f32.store":A.type==="f64"?"f64.store":"i32.store";U.push([M,["i32.add",["local.get",O],["i32.const",d]],k[E]||[`${A.type}.const`,0]])}else for(let E=0;E<w.fields.length;E++){let A=w.fields[E],d=m(w,E),M=A.type==="i64"?"i64.store":A.type==="f32"?"f32.store":A.type==="f64"?"f64.store":"i32.store",x=A.type==="i64"?["i64.const",0n]:A.type==="f32"?["f32.const",0]:A.type==="f64"?["f64.const",0]:["i32.const",0];U.push([M,["i32.add",["local.get",O],["i32.const",d]],x])}U.push(["local.get",O]),_[b]=["block",["result","i32"],...U]}if(p[0]==="struct.get"){let $=p[1],w=p[2],S=p[3],I=r.get($);if(!I||I.kind!=="struct")return;let k=typeof w=="string"&&w[0]==="$"?y(I,w):parseInt(w);if(k<0)return;let O=I.fields[k],U=m(I,k),E=O.type==="i64"?"i64.load":O.type==="f32"?"f32.load":O.type==="f64"?"f64.load":"i32.load";_[b]=[E,["i32.add",S,["i32.const",U]]]}if(p[0]==="struct.set"){let $=p[1],w=p[2],S=p[3],I=p[4],k=r.get($);if(!k||k.kind!=="struct")return;let O=typeof w=="string"&&w[0]==="$"?y(k,w):parseInt(w);if(O<0)return;let U=k.fields[O],E=m(k,O),A=U.type==="i64"?"i64.store":U.type==="f32"?"f32.store":U.type==="f64"?"f64.store":"i32.store";_[b]=[A,["i32.add",S,["i32.const",E]],I]}if(p[0]==="array.new"||p[0]==="array.new_default"){let $=p[1],w=r.get($);if(!w||w.kind!=="array")return;let S=i.get($),I=xt[w.elemType]||4,k=p[0]==="array.new"?p[2]:null,O=p[0]==="array.new"?p[3]:p[2],U="$__gc_aptr",E="$__gc_alen",A="$__gc_aidx",d=w.elemType==="i64"?"i64.store":w.elemType==="f32"?"f32.store":w.elemType==="f64"?"f64.store":"i32.store",M=[["local.set",E,O],["local.set",U,["call",l,["i32.add",["i32.const",8],["i32.mul",["local.get",E],["i32.const",I]]]]],["i32.store",["local.get",U],["i32.const",S]],["i32.store",["i32.add",["local.get",U],["i32.const",4]],["local.get",E]]];k&&M.push(["local.set",A,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",A],["local.get",E]]],[d,["i32.add",["i32.add",["local.get",U],["i32.const",8]],["i32.mul",["local.get",A],["i32.const",I]]],k],["local.set",A,["i32.add",["local.get",A],["i32.const",1]]],["br","$loop"]]]),M.push(["local.get",U]),_[b]=["block",["result","i32"],...M]}if(p[0]==="array.get"){let $=p[1],w=p[2],S=p[3],I=r.get($);if(!I||I.kind!=="array")return;let k=xt[I.elemType]||4,O=I.elemType==="i64"?"i64.load":I.elemType==="f32"?"f32.load":I.elemType==="f64"?"f64.load":"i32.load";_[b]=[O,["i32.add",["i32.add",w,["i32.const",8]],["i32.mul",S,["i32.const",k]]]]}if(p[0]==="array.set"){let $=p[1],w=p[2],S=p[3],I=p[4],k=r.get($);if(!k||k.kind!=="array")return;let O=xt[k.elemType]||4,U=k.elemType==="i64"?"i64.store":k.elemType==="f32"?"f32.store":k.elemType==="f64"?"f64.store":"i32.store";_[b]=[U,["i32.add",["i32.add",w,["i32.const",8]],["i32.mul",S,["i32.const",O]]],I]}if(p[0]==="array.len"){let $=p[1];_[b]=["i32.load",["i32.add",$,["i32.const",4]]]}}}),t};tt.gc=ur;var yr=(t,e)=>{let r=new Map,i=1;return P(t,s=>{if(!Array.isArray(s)||s[0]!=="type")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l of s)Array.isArray(l)&&(l[0]==="struct"||l[0]==="array")&&r.set(n,i++)}),r.size&&et(t,(s,n,l)=>{if(!(!Array.isArray(s)||!n)){if(s[0]==="ref.test"){let f=s[1],o=null;Array.isArray(f)&&f[0]==="ref"&&(o=f[1]==="null"?f[2]:f[1]);let a=s[2],c=r.get(o);c!==void 0&&(n[l]=["if",["result","i32"],["i32.eqz",a],["then",["i32.const",0]],["else",["i32.eq",["i32.load",a],["i32.const",c]]]])}if(s[0]==="ref.cast"){let f=s[1],o=null,a=!1;Array.isArray(f)&&f[0]==="ref"&&(f[1]==="null"?(a=!0,o=f[2]):o=f[1]);let c=s[2],m=r.get(o);if(m!==void 0){let y=rt("cast");a?n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["if",["i32.and",["i32.ne",["local.get",y],["i32.const",0]],["i32.ne",["i32.load",["local.get",y]],["i32.const",m]]],["then",["unreachable"]]],["local.get",y]]:n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["if",["i32.or",["i32.eqz",["local.get",y]],["i32.ne",["i32.load",["local.get",y]],["i32.const",m]]],["then",["unreachable"]]],["local.get",y]]}}if(s[0]==="br_on_cast"){let f=s[1],o=s[2],a=s[3],c=s[4],m=null;Array.isArray(a)&&a[0]==="ref"&&(m=a[1]==="null"?a[2]:a[1]);let y=r.get(m);if(y!==void 0){let u=rt("brcast");n[l]=["block",["result","i32"],["local",u,"i32"],["local.set",u,c],["br_if",f,["i32.and",["i32.ne",["local.get",u],["i32.const",0]],["i32.eq",["i32.load",["local.get",u]],["i32.const",y]]]],["local.get",u]]}}if(s[0]==="br_on_cast_fail"){let f=s[1],o=s[2],a=s[3],c=s[4],m=null;Array.isArray(a)&&a[0]==="ref"&&(m=a[1]==="null"?a[2]:a[1]);let y=r.get(m);if(y!==void 0){let u=rt("brfail");n[l]=["block",["result","i32"],["local",u,"i32"],["local.set",u,c],["br_if",f,["i32.or",["i32.eqz",["local.get",u]],["i32.ne",["i32.load",["local.get",u]],["i32.const",y]]]],["local.get",u]]}}}}),t};tt.ref_cast=yr;function St(t,e=!0){typeof t=="string"&&(t=Z(t)),t=fe(t),e=Je(e);let r=tr(t),i={uid:0};for(let s of Wt)r.has(s)&&e[s]!==!1&&tt[s]&&(t=tt[s](t,i));return t}var Pt={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!1,inlineOnce:!0,vacuum:!0,mergeBlocks:!0,coalesce:!0,peephole:!0,globals:!0,offset:!0,unbranch:!0,loopify:!0,stripmut:!0,brif:!0,foldarms:!1,dedupe:!0,reorder:!1,dedupTypes:!0,packData:!0,minifyImports:!1},oe=Object.keys(Pt);var ce=t=>{try{return at(t).length}catch{return 1/0}},T=(t,e)=>{if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="bigint")return t===e;if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!T(t[r],e[r]))return!1;return!0},mr=t=>{if(t===!0)return{...Pt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.has("all")?Object.fromEntries(oe.map(r=>[r,!0])):Object.fromEntries(oe.map(r=>[r,e.has(r)]))}return{...Pt,...t}},J=t=>Array.isArray(t)?t.map(J):t,L=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)L(t[s],e,t,s)},D=(t,e,r,i)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++){let l=D(t[n],e,t,n);l!==void 0&&(t[n]=l)}let s=e(t,r,i);return s!==void 0?s:t},Ut=t=>{let e=1;for(;e<t.length;){let s=t[e];if(Array.isArray(s)&&(s[0]==="then"||s[0]==="else"||s[0]==="result"||s[0]==="param")){e++;continue}break}let r=null,i=null;for(let s=e+1;s<t.length;s++){let n=t[s];Array.isArray(n)&&(n[0]==="then"?r=n:n[0]==="else"&&(i=n))}return{condIdx:e,cond:t[e],thenBranch:r,elseBranch:i}},pr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=new Map,n=new Map,l=new Map,f=(A,d,M,x=!1)=>{let B=typeof d[1]=="string"&&d[1][0]==="$",F=B?d[1]:M,st=!x&&d.some(W=>Array.isArray(W)&&W[0]==="export"),j={node:d,idx:M,used:st,isImport:x};return A.set(F,j),B&&A.set(M,j),l.set(d,j),j},o=0,a=0,c=0,m=0,y=0,u=[],h=[],p=[],_=[];for(let A of t.slice(1)){if(!Array.isArray(A))continue;let d=A[0];if(d==="type")f(i,A,c++);else if(d==="func")f(e,A,o++);else if(d==="global")f(r,A,a++);else if(d==="table")f(s,A,m++);else if(d==="memory")f(n,A,y++);else if(d==="import")for(let M of A)Array.isArray(M)&&(M[0]==="func"?f(e,M,o++,!0):M[0]==="global"?f(r,M,a++,!0):M[0]==="table"?f(s,M,m++,!0):M[0]==="memory"&&f(n,M,y++,!0));else d==="export"?p.push(A):d==="start"?_.push(A):d==="elem"?u.push(A):d==="data"&&h.push(A)}let b=[],$=A=>{A&&!A.scanned&&b.push(A)},w=A=>{let d=e.get(A);d&&(d.used||(d.used=!0),$(d))},S=A=>{let d=r.get(A);d&&(d.used=!0)},I=A=>{let d=s.get(A);d&&(d.used=!0)},k=A=>{typeof A=="string"&&A[0]!=="$"&&(A=+A);let d=n.get(A);d&&(d.used=!0)},O=A=>{let d=i.get(A);d&&(d.used=!0)};for(let A of p)for(let d of A){if(!Array.isArray(d))continue;let[M,x]=d;M==="func"?w(x):M==="global"?S(x):M==="table"?I(x):M==="memory"&&k(x)}for(let A of _){let d=A[1];typeof d=="string"&&d[0]!=="$"&&(d=+d),w(d)}for(let A of u)L(A,d=>{Array.isArray(d)&&d[0]==="ref.func"?w(d[1]):typeof d=="string"&&d[0]==="$"&&w(d)});for(let A of h){let d=A[1];Array.isArray(d)&&d[0]==="memory"?k(d[1]):typeof d=="string"&&d[0]==="$"?k(d):Array.isArray(d)&&k(0)}for(let A of[e,r,s,n])for(let d of A.values())d.used&&$(d);if(!(p.length>0||_.length>0||u.length>0||b.length>0)){for(let A of[e,r,s,n])for(let d of A.values())d.used=!0;return t}for(;b.length;){let A=b.pop();A.scanned||(A.scanned=!0,!A.isImport&&L(A.node,d=>{if(!Array.isArray(d)){typeof d=="string"&&d[0]==="$"&&w(d);return}let[M,x]=d;if(M==="call"||M==="return_call"||M==="ref.func")w(x);else if(M==="global.get"||M==="global.set")S(x);else if(M==="type")O(x);else if(M==="call_indirect"||M==="return_call_indirect")for(let B of d)typeof B=="string"&&B[0]==="$"&&I(B);typeof M=="string"&&(M.startsWith("memory.")||M.includes(".load")||M.includes(".store"))&&k(0)}))}let E=["module"];for(let A of t.slice(1)){if(!Array.isArray(A)){E.push(A);continue}let d=A[0];if(d==="func"||d==="global"||d==="type")l.get(A)?.used&&E.push(A);else if(d==="import"){let M=!1;for(let x of A){if(!Array.isArray(x))continue;if(l.get(x)?.used){M=!0;break}}M&&E.push(A)}else E.push(A)}return E},ue=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),Ae=new ArrayBuffer(8),be=new Float64Array(Ae),we=new BigInt64Array(Ae),ve=new ArrayBuffer(4),$e=new Float32Array(ve),Ie=new Int32Array(ve),_r=t=>(be[0]=t,we[0]),gr=t=>(we[0]=BigInt.asIntN(64,t),be[0]),hr=t=>($e[0]=t,Ie[0]),xr=t=>(Ie[0]=t|0,$e[0]),mt=t=>(e,r)=>t(e,r)?1:0,zt=t=>(e,r)=>t(e>>>0,r>>>0)?1:0,pt=t=>(e,r)=>t(e,r)?1:0,Tt=t=>(e,r)=>t(BigInt.asUintN(64,e),BigInt.asUintN(64,r))?1:0,dr={"i32.add":[(t,e)=>t+e|0,"i32"],"i32.sub":[(t,e)=>t-e|0,"i32"],"i32.mul":[(t,e)=>Math.imul(t,e),"i32"],"i32.div_s":[(t,e)=>e!==0?t/e|0:null,"i32"],"i32.div_u":[(t,e)=>e!==0?(t>>>0)/(e>>>0)|0:null,"i32"],"i32.rem_s":[(t,e)=>e!==0?t%e|0:null,"i32"],"i32.rem_u":[(t,e)=>e!==0?(t>>>0)%(e>>>0)|0:null,"i32"],"i32.and":[(t,e)=>t&e,"i32"],"i32.or":[(t,e)=>t|e,"i32"],"i32.xor":[(t,e)=>t^e,"i32"],"i32.shl":[(t,e)=>t<<(e&31),"i32"],"i32.shr_s":[(t,e)=>t>>(e&31),"i32"],"i32.shr_u":[(t,e)=>t>>>(e&31),"i32"],"i32.rotl":[(t,e)=>(e&=31,t<<e|t>>>32-e|0),"i32"],"i32.rotr":[(t,e)=>(e&=31,t>>>e|t<<32-e|0),"i32"],"i32.eq":[mt((t,e)=>t===e),"i32"],"i32.ne":[mt((t,e)=>t!==e),"i32"],"i32.lt_s":[mt((t,e)=>t<e),"i32"],"i32.lt_u":[zt((t,e)=>t<e),"i32"],"i32.gt_s":[mt((t,e)=>t>e),"i32"],"i32.gt_u":[zt((t,e)=>t>e),"i32"],"i32.le_s":[mt((t,e)=>t<=e),"i32"],"i32.le_u":[zt((t,e)=>t<=e),"i32"],"i32.ge_s":[mt((t,e)=>t>=e),"i32"],"i32.ge_u":[zt((t,e)=>t>=e),"i32"],"i32.eqz":[t=>t===0?1:0,"i32"],"i32.clz":[t=>Math.clz32(t),"i32"],"i32.ctz":[t=>t===0?32:31-Math.clz32(t&-t),"i32"],"i32.popcnt":[t=>{let e=0;for(;t;)e+=t&1,t>>>=1;return e},"i32"],"i32.wrap_i64":[t=>Number(BigInt.asIntN(32,t)),"i32"],"i32.extend8_s":[t=>t<<24>>24,"i32"],"i32.extend16_s":[t=>t<<16>>16,"i32"],"i64.add":[(t,e)=>BigInt.asIntN(64,t+e),"i64"],"i64.sub":[(t,e)=>BigInt.asIntN(64,t-e),"i64"],"i64.mul":[(t,e)=>BigInt.asIntN(64,t*e),"i64"],"i64.div_s":[(t,e)=>e!==0n?BigInt.asIntN(64,t/e):null,"i64"],"i64.div_u":[(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)/BigInt.asUintN(64,e)):null,"i64"],"i64.rem_s":[(t,e)=>e!==0n?BigInt.asIntN(64,t%e):null,"i64"],"i64.rem_u":[(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)%BigInt.asUintN(64,e)):null,"i64"],"i64.and":[(t,e)=>BigInt.asIntN(64,t&e),"i64"],"i64.or":[(t,e)=>BigInt.asIntN(64,t|e),"i64"],"i64.xor":[(t,e)=>BigInt.asIntN(64,t^e),"i64"],"i64.shl":[(t,e)=>BigInt.asIntN(64,t<<(e&63n)),"i64"],"i64.shr_s":[(t,e)=>BigInt.asIntN(64,t>>(e&63n)),"i64"],"i64.shr_u":[(t,e)=>BigInt.asUintN(64,BigInt.asUintN(64,t)>>(e&63n)),"i64"],"i64.eq":[pt((t,e)=>t===e),"i32"],"i64.ne":[pt((t,e)=>t!==e),"i32"],"i64.lt_s":[pt((t,e)=>t<e),"i32"],"i64.lt_u":[Tt((t,e)=>t<e),"i32"],"i64.gt_s":[pt((t,e)=>t>e),"i32"],"i64.gt_u":[Tt((t,e)=>t>e),"i32"],"i64.le_s":[pt((t,e)=>t<=e),"i32"],"i64.le_u":[Tt((t,e)=>t<=e),"i32"],"i64.ge_s":[pt((t,e)=>t>=e),"i32"],"i64.ge_u":[Tt((t,e)=>t>=e),"i32"],"i64.eqz":[t=>t===0n?1:0,"i32"],"i64.extend_i32_s":[t=>BigInt(t),"i64"],"i64.extend_i32_u":[t=>BigInt(t>>>0),"i64"],"i64.extend8_s":[t=>BigInt.asIntN(64,BigInt.asIntN(8,t)),"i64"],"i64.extend16_s":[t=>BigInt.asIntN(64,BigInt.asIntN(16,t)),"i64"],"i64.extend32_s":[t=>BigInt.asIntN(64,BigInt.asIntN(32,t)),"i64"],"f32.add":[(t,e)=>Math.fround(t+e),"f32"],"f32.sub":[(t,e)=>Math.fround(t-e),"f32"],"f32.mul":[(t,e)=>Math.fround(t*e),"f32"],"f32.div":[(t,e)=>Math.fround(t/e),"f32"],"f32.neg":[t=>Math.fround(-t),"f32"],"f32.abs":[t=>Math.fround(Math.abs(t)),"f32"],"f32.sqrt":[t=>Math.fround(Math.sqrt(t)),"f32"],"f32.ceil":[t=>Math.fround(Math.ceil(t)),"f32"],"f32.floor":[t=>Math.fround(Math.floor(t)),"f32"],"f32.trunc":[t=>Math.fround(Math.trunc(t)),"f32"],"f32.nearest":[t=>Math.fround(ue(t)),"f32"],"f64.add":[(t,e)=>t+e,"f64"],"f64.sub":[(t,e)=>t-e,"f64"],"f64.mul":[(t,e)=>t*e,"f64"],"f64.div":[(t,e)=>t/e,"f64"],"f64.neg":[t=>-t,"f64"],"f64.abs":[Math.abs,"f64"],"f64.sqrt":[Math.sqrt,"f64"],"f64.ceil":[Math.ceil,"f64"],"f64.floor":[Math.floor,"f64"],"f64.trunc":[Math.trunc,"f64"],"f64.nearest":[ue,"f64"],"i32.reinterpret_f32":[hr,"i32"],"f32.reinterpret_i32":[xr,"f32"],"i64.reinterpret_f64":[_r,"i64"],"f64.reinterpret_i64":[gr,"f64"],"f32.convert_i32_s":[t=>Math.fround(t|0),"f32"],"f32.convert_i32_u":[t=>Math.fround(t>>>0),"f32"],"f32.convert_i64_s":[t=>Math.fround(Number(BigInt.asIntN(64,t))),"f32"],"f32.convert_i64_u":[t=>Math.fround(Number(BigInt.asUintN(64,t))),"f32"],"f64.convert_i32_s":[t=>t|0,"f64"],"f64.convert_i32_u":[t=>t>>>0,"f64"],"f64.convert_i64_s":[t=>Number(BigInt.asIntN(64,t)),"f64"],"f64.convert_i64_u":[t=>Number(BigInt.asUintN(64,t)),"f64"],"f32.demote_f64":[t=>Math.fround(t),"f32"],"f64.promote_f32":[t=>Math.fround(t),"f64"]},z=t=>{if(!Array.isArray(t)||t.length!==2)return null;let[e,r]=t;return e==="i32.const"?{type:"i32",value:Number(r)|0}:e==="i64.const"?{type:"i64",value:BigInt(r)}:e==="f32.const"?{type:"f32",value:Math.fround(Number(r))}:e==="f64.const"?{type:"f64",value:Number(r)}:null},ye=(t,e)=>t==="i32"?["i32.const",e|0]:t==="i64"?["i64.const",e]:t==="f32"?["f32.const",Math.fround(e)]:t==="f64"?["f64.const",e]:null,Ar=t=>D(t,e=>{if(!Array.isArray(e))return;let r=dr[e[0]];if(!r)return;let[i,s]=r;if(i.length===1&&e.length===2){let n=z(e[1]);if(!n)return;let l=i(n.value);return l===null?void 0:ye(s,l)}if(i.length===2&&e.length===3){let n=z(e[1]),l=z(e[2]);if(!n||!l)return;let f=i(n.value,l.value);return f===null?void 0:ye(s,f)}}),it=t=>(e,r)=>{let i=z(e),s=z(r);return i?.value===t?r:s?.value===t?e:null},Q=t=>(e,r)=>z(r)?.value===t?e:null,br={"i32.add":it(0),"i64.add":it(0n),"i32.sub":Q(0),"i64.sub":Q(0n),"i32.mul":it(1),"i64.mul":it(1n),"i32.div_s":Q(1),"i32.div_u":Q(1),"i64.div_s":Q(1n),"i64.div_u":Q(1n),"i32.and":it(-1),"i64.and":it(-1n),"i32.or":it(0),"i64.or":it(0n),"i32.xor":it(0),"i64.xor":it(0n),"i32.shl":Q(0),"i32.shr_s":Q(0),"i32.shr_u":Q(0),"i64.shl":Q(0n),"i64.shr_s":Q(0n),"i64.shr_u":Q(0n)},wr=t=>D(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=br[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),vr=t=>D(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1)){let f=Math.log2(n.value);if(Number.isInteger(f))return["i32.shl",i,["i32.const",f]]}let l=z(i);if(l&&l.value>0&&!(l.value&l.value-1)){let f=Math.log2(l.value);if(Number.isInteger(f))return["i32.shl",s,["i32.const",f]]}}if(r==="i64.mul"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let f=BigInt(n.value.toString(2).length-1);return["i64.shl",i,["i64.const",f]]}let l=z(i);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let f=BigInt(l.value.toString(2).length-1);return["i64.shl",s,["i64.const",f]]}}if(r==="i32.div_u"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1)){let l=Math.log2(n.value);if(Number.isInteger(l))return["i32.shr_u",i,["i32.const",l]]}}if(r==="i64.div_u"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let l=BigInt(n.value.toString(2).length-1);return["i64.shr_u",i,["i64.const",l]]}}if(r==="i32.rem_u"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1))return["i32.and",i,["i32.const",n.value-1]]}if(r==="i64.rem_u"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n)return["i64.and",i,["i64.const",n.value-1n]]}}),$r=t=>D(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Ut(e),l=z(i);if(!l)return;let f=l.value!==0&&l.value!==0n?s:n;if(f&&f.length>1){let o=f.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=z(i);return s?s.value===0||s.value===0n?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let i=e[e.length-1],s=z(i);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),me=new Set(["unreachable","return","br","br_table"]),Ir=t=>(L(t,e=>{if(!Array.isArray(e))return;let r=e[0];if((r==="func"||r==="block"||r==="loop")&&pe(e),r==="if")for(let i=1;i<e.length;i++)Array.isArray(e[i])&&(e[i][0]==="then"||e[i][0]==="else")&&pe(e[i])}),t),pe=t=>{let e=!1,r=-1;for(let i=1;i<t.length;i++){let s=t[i];if(Array.isArray(s)){let n=s[0];if(n==="param"||n==="result"||n==="local"||n==="type"||n==="export")continue;e&&r===-1&&(r=i),me.has(n)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),me.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},kr=t=>(L(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=[],i=new Map,s=new Set;for(let n=1;n<e.length;n++){let l=e[n];Array.isArray(l)&&(l[0]==="local"&&(r.push({node:l,idx:n}),typeof l[1]=="string"&&l[1][0]==="$"&&i.set(l[1],l[2])),l[0]==="param"&&typeof l[1]=="string"&&l[1][0]==="$"&&(i.set(l[1],l[2]),s.add(l[1])))}L(e,n=>{if(!Array.isArray(n))return;let l=n[0];if(l==="local.get"||l==="local.set"||l==="local.tee"){let f=n[1];typeof f=="string"&&s.add(f)}});for(let n=r.length-1;n>=0;n--){let{idx:l,node:f}=r[n],o=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;o&&!s.has(o)&&e.splice(l,1)}}),t),Br=new Set(["call","call_indirect","return_call","return_call_indirect","table.set","table.grow","table.fill","table.copy","table.init","struct.set","struct.new","array.set","array.new","array.new_fixed","array.new_data","array.new_elem","array.init_data","array.init_elem","ref.i31","global.set","local.set","local.tee","unreachable","return","br","br_if","br_table","br_on_null","br_on_non_null","br_on_cast","br_on_cast_fail","throw","rethrow","throw_ref","try_table","data.drop","elem.drop"]),Mr=[".store","memory.",".atomic."],_t=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||Br.has(e))return!1;for(let r of Mr)if(e.includes(r))return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!_t(t[r]))return!1;return!0},Nr=t=>{let e=new Map,r=i=>(e.has(i)||e.set(i,{gets:0,sets:0,tees:0}),e.get(i));return L(t,i=>{!Array.isArray(i)||i.length<2||typeof i[1]!="string"||(i[0]==="local.get"?r(i[1]).gets++:i[0]==="local.set"?r(i[1]).sets++:i[0]==="local.tee"&&r(i[1]).tees++)}),e},Sr=t=>{let e=z(t);if(!e)return!1;if(e.type==="i32"){let r=e.value|0;return r>=-64&&r<=63}if(e.type==="i64"){let r=typeof e.value=="bigint"?e.value:BigInt(e.value);return r>=-64n&&r<=63n}return!1},ke=t=>t.pure&&t.singleUse||Sr(t.val),_e=(t,e)=>{for(let[r,i]of t){let s=!1;L(i.val,n=>{Array.isArray(n)&&(n[0]==="local.get"||n[0]==="local.tee")&&n[1]===e&&(s=!0)}),s&&t.delete(r)}},ge=(t,e)=>D(t,r=>{if(!Array.isArray(r)||r[0]!=="local.get"||r.length!==2)return;let i=typeof r[1]=="string"&&e.get(r[1]);if(i&&ke(i))return J(i.val)}),zr=(t,e,r)=>{let i=!1,s=l=>r.get(l)||{gets:0,sets:0,tees:0},n=new Map;for(let l=1;l<t.length;l++){let f=t[l];if(!Array.isArray(f))continue;let o=f[0];if(!(o==="param"||o==="result"||o==="local"||o==="type"||o==="export")){if((o==="local.set"||o==="local.tee")&&f.length===3&&typeof f[1]=="string"){ge(f[2],n);let a=s(f[1]);_e(n,f[1]),n.set(f[1],{val:f[2],pure:_t(f[2]),singleUse:a.gets<=1&&a.sets<=1&&a.tees===0});continue}if((o==="block"||o==="loop"||o==="if")&&n.clear(),o==="call"||o==="call_indirect"||o==="return_call"||o==="return_call_indirect")for(let[a,c]of n)z(c.val)||n.delete(a);if(o==="local.get"&&f.length===2&&typeof f[1]=="string"){let a=n.get(f[1]);if(a&&ke(a)){let c=J(a.val);f.length=0,f.push(...Array.isArray(c)?c:[c]),i=!0;continue}}if(o!=="block"&&o!=="loop"&&o!=="if"){let a=J(f);ge(f,n),T(a,f)||(i=!0),L(f,c=>{Array.isArray(c)&&(c[0]==="local.set"||c[0]==="local.tee")&&typeof c[1]=="string"&&(n.delete(c[1]),_e(n,c[1]))})}}}return i},Tr=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let f=n[1];if(l[1]!==f||e.has(f))continue;let o=r.get(f)||{gets:0,sets:0,tees:0};if(o.sets!==1||o.gets!==1||o.tees!==0)continue;let a=J(n[2]);t.splice(s,2,...Array.isArray(a)?[a]:[a]),i=!0,s--}return i},Er=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let f=n[1];if(l[1]!==f||e.has(f))continue;let o=r.get(f)||{gets:0,sets:0,tees:0};o.sets+o.gets+o.tees<=2||(t.splice(s,2,["local.tee",f,J(n[2])]),i=!0)}return i},Ur=(t,e,r)=>{let i=!1,s=n=>r.get(n)||{gets:0,sets:0,tees:0};for(let n=t.length-1;n>=1;n--){let l=t[n];if(!Array.isArray(l))continue;let f=typeof l[1]=="string"?l[1]:null;if(!f||e.has(f))continue;let o=s(f);(l[0]==="local.set"&&o.gets===0&&o.tees===0&&_t(l[2])||l[0]==="local"&&f[0]==="$"&&o.gets===0&&o.sets===0&&o.tees===0)&&(t.splice(n,1),i=!0)}return i},Be=t=>Array.isArray(t)&&(t[0]==="func"||t[0]==="block"||t[0]==="loop"||t[0]==="then"||t[0]==="else"),he=t=>(L(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Set;for(let s of e)Array.isArray(s)&&s[0]==="param"&&typeof s[1]=="string"&&r.add(s[1]);let i=[];D(e,s=>{Be(s)&&i.push(s)});for(let s=0;s<6;s++){let n=Nr(e),l=!1;for(let f of i)zr(f,r,n)&&(l=!0),Tr(f,r,n)&&(l=!0),Er(f,r,n)&&(l=!0),Ur(f,r,n)&&(l=!0);if(!l)break}}),t),qr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map;for(let r of t.slice(1)){if(!Array.isArray(r)||r[0]!=="func")continue;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i)continue;let s=[],n=[],l=!1,f=!1;for(let o=1;o<r.length;o++){let a=r[o];if(Array.isArray(a))if(a[0]==="param")if(typeof a[1]=="string"&&a[1][0]==="$")s.push({name:a[1],type:a[2]});else{s=null;break}else a[0]==="local"?l=!0:a[0]==="export"?f=!0:a[0]!=="result"&&a[0]!=="type"&&n.push(a)}if(s&&!l&&!f&&s.length<=4&&n.length===1){let o=new Set(s.map(m=>m.name)),a=!1,c=!1;L(n[0],m=>{Array.isArray(m)&&((m[0]==="local.set"||m[0]==="local.tee")&&o.has(m[1])&&(a=!0),(m[0]==="return"||m[0]==="return_call"||m[0]==="return_call_indirect")&&(c=!0))}),!a&&!c&&e.set(i,{body:n[0],params:s})}}return e.size===0||D(t,r=>{if(!Array.isArray(r)||r[0]!=="call")return;let i=r[1];if(!e.has(i))return;let{body:s,params:n}=e.get(i),l=r.slice(2);if(n.length===0)return J(s);let f=J(s);return D(f,o=>{if(!Array.isArray(o)||o[0]!=="local.get")return;let a=o[1],c=n.findIndex(m=>m.name===a);if(c!==-1&&l[c])return J(l[c])}),f}),t},Or=0,Fr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set(["export","type","param","result","local"]),r=f=>{let o=2;for(;o<f.length&&(typeof f[o]=="string"||Array.isArray(f[o])&&e.has(f[o][0]));)o++;return o},i=f=>f==="br"||f==="br_if"||f==="br_table",s=f=>{if(!Array.isArray(f))return!1;let o=f[0];if(o==="return_call"||o==="return_call_indirect"||o==="return_call_ref"||o==="try"||o==="try_table"||o==="delegate"||o==="rethrow")return!0;if(i(o)){for(let a=1;a<f.length;a++)if(typeof f[a]=="number"||typeof f[a]=="string"&&/^\d+$/.test(f[a]))return!0}for(let a=1;a<f.length;a++)if(s(f[a]))return!0;return!1},n=(f,o)=>{if(!Array.isArray(f))return!1;if((f[0]==="call"||f[0]==="return_call")&&f[1]===o)return!0;for(let a=1;a<f.length;a++)if(n(f[a],o))return!0;return!1},l=(f,o)=>{if(!Array.isArray(f))return;let a=f[0];if(a==="export"&&Array.isArray(f[2])&&f[2][0]==="func"&&typeof f[2][1]=="string")o.add(f[2][1]);else if(a==="start"&&typeof f[1]=="string")o.add(f[1]);else if(a==="ref.func"&&typeof f[1]=="string")o.add(f[1]);else if(a==="elem")for(let c of f)typeof c=="string"&&c[0]==="$"&&o.add(c);for(let c of f)l(c,o)};for(let f=0;f<16;f++){let o=t.filter(x=>Array.isArray(x)&&x[0]==="func"),a=new Map;for(let x of o)typeof x[1]=="string"&&a.set(x[1],x);let c=new Map,m=new Set,y=x=>{if(!Array.isArray(x))return;let B=x[0];B==="call"&&typeof x[1]=="string"?c.set(x[1],(c.get(x[1])||0)+1):B==="return_call"&&typeof x[1]=="string"&&m.add(x[1]);for(let F=1;F<x.length;F++)y(x[F])};y(t);let u=new Set;for(let x of t)(!Array.isArray(x)||x[0]!=="func")&&l(x,u);let h=null;for(let[x,B]of a){if(u.has(x)||m.has(x)||c.get(x)!==1||n(B,x))continue;let F=!0,st=0;for(let W=2;W<B.length;W++){let V=B[W];if(typeof V!="string"){if(!Array.isArray(V)){F=!1;break}if(V[0]==="param"||V[0]==="local"){if(typeof V[1]!="string"||V[1][0]!=="$"){F=!1;break}}else if(V[0]==="result")st+=V.length-1;else if(V[0]==="export"){F=!1;break}else{if(V[0]==="type")continue;break}}}if(!F||st>1)continue;let j=!1;for(let W=r(B);W<B.length;W++)if(s(B[W])){j=!0;break}if(!j){h=x;break}}if(!h)break;let p=a.get(h),_=[],b=[],$=null;for(let x=2;x<p.length;x++){let B=p[x];if(!(typeof B=="string"||!Array.isArray(B)))if(B[0]==="param")_.push({name:B[1],type:B[2]});else if(B[0]==="result")B.length>1&&($=B[1]);else if(B[0]==="local")b.push({name:B[1],type:B[2]});else{if(B[0]==="export"||B[0]==="type")continue;break}}let w=p.slice(r(p)),S=++Or,I=`$__inl${S}`,k=new Map;for(let x of _)k.set(x.name,`$__inl${S}_${x.name.slice(1)}`);for(let x of b)k.set(x.name,`$__inl${S}_${x.name.slice(1)}`);let O=x=>x==="block"||x==="loop"||x==="if",U=new Map,E=x=>{if(Array.isArray(x)){O(x[0])&&typeof x[1]=="string"&&x[1][0]==="$"&&!U.has(x[1])&&U.set(x[1],`$__inl${S}L_${x[1].slice(1)}`);for(let B=1;B<x.length;B++)E(x[B])}};for(let x of w)E(x);let A=x=>{if(!Array.isArray(x))return x;let B=x[0];return(B==="local.get"||B==="local.set"||B==="local.tee")&&typeof x[1]=="string"&&k.has(x[1])?[B,k.get(x[1]),...x.slice(2).map(A)]:B==="return"?["br",I,...x.slice(1).map(A)]:O(B)&&typeof x[1]=="string"&&U.has(x[1])?[B,U.get(x[1]),...x.slice(2).map(A)]:i(B)?[B,...x.slice(1).map(F=>typeof F=="string"&&U.has(F)?U.get(F):A(F))]:x.map((F,st)=>st===0?F:A(F))},d=!1;for(let x of o){if(x===p||d)continue;let B=r(x);for(let F=B;F<x.length;F++){let st=D(x[F],j=>{if(d||!Array.isArray(j)||j[0]!=="call"||j[1]!==h)return;let W=j.slice(2);if(W.length!==_.length)return;let V=_.map((Te,Ee)=>["local.set",k.get(Te.name),W[Ee]]),Ht=w.map(A);return d=!0,$?["block",I,["result",$],...V,...Ht]:["block",I,...V,...Ht]});if(st!==x[F]&&(x[F]=st),d){let j=[..._,...b].map(W=>["local",k.get(W.name),W.type]);j.length&&x.splice(r(x),0,...j);break}}if(d)break}if(!d)break;let M=t.indexOf(p);M>=0&&t.splice(M,1)}return t},jt=(t,e)=>{let r=!1,i=(s,n)=>{if(r||!Array.isArray(s))return;let l=s[0],f=n;if((l==="block"||l==="loop")&&typeof s[1]=="string"&&s[1]===e&&(f=!0),!n){if(l==="br"||l==="br_if"||l==="br_on_null"||l==="br_on_non_null"||l==="br_on_cast"||l==="br_on_cast_fail"){if(s[1]===e){r=!0;return}}else if(l==="br_table"){for(let o=1;o<s.length&&typeof s[o]=="string";o++)if(s[o]===e){r=!0;return}}}for(let o=1;o<s.length;o++)i(s[o],f)};for(let s of t)i(s,!1);return r},Lr=t=>(D(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let r=1,i=null;typeof e[1]=="string"&&e[1][0]==="$"&&(i=e[1],r=2);let s=!1;for(;r<e.length;){let f=e[r];if(Array.isArray(f)&&(f[0]==="param"||f[0]==="type")){r++;continue}if(Array.isArray(f)&&f[0]==="result"){s=!0,r++;continue}break}let n=e.slice(r);if(!s||n.length!==1)return;let l=n[0];if(Array.isArray(l)&&!(i&&jt(n,i))){e.length=0;for(let f of l)e.push(f)}}),L(t,e=>{if(!Be(e))return;let r=1;for(;r<e.length;){let i=e[r];if(!Array.isArray(i)||i[0]!=="block"){r++;continue}let s=1,n=null;for(typeof i[1]=="string"&&i[1][0]==="$"&&(n=i[1],s=2);s<i.length;){let f=i[s];if(Array.isArray(f)&&(f[0]==="param"||f[0]==="result"||f[0]==="type")){s++;continue}break}let l=i.slice(s);if(n&&jt(l,n)){r++;continue}e.splice(r,1,...l),r+=l.length}}),t),Cr=t=>(L(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Map;for(let y of e)Array.isArray(y)&&y[0]==="local"&&typeof y[1]=="string"&&y[1][0]==="$"&&typeof y[2]=="string"&&r.set(y[1],y[2]);if(r.size<2)return;let i=new Map,s=[],n=0,l=!1,f=0,o=y=>{if(l||!Array.isArray(y))return;let u=y[0],h=u==="loop";h&&s.push({start:n,end:n});let p=u==="local.set"||u==="local.tee";if(p||u==="local.get"){let _=y[1];if(typeof _!="string"||_[0]!=="$"){l=!0;return}if(p)for(let $=2;$<y.length;$++)o(y[$]);let b=n++;if(r.has(_)){let $=i.get(_);$||($={start:b,end:b,firstOp:u,firstCond:f>0,loops:new Set},i.set(_,$)),b>$.end&&($.end=b);for(let w of s)$.loops.add(w)}}else{n++;let _=u==="if";for(let b=1;b<y.length;b++){let $=y[b],w=_&&Array.isArray($)&&($[0]==="then"||$[0]==="else");w&&f++,o($),w&&f--}}if(h){let _=s.pop();_.end=n}};if(o(e),l)return;for(let y of i.values())for(let u of y.loops)u.start<y.start&&(y.start=u.start),u.end>y.end&&(y.end=u.end);let a=[...i.entries()].sort((y,u)=>y[1].start-u[1].start),c=new Map,m=[];for(let[y,u]of a){let h=u.firstOp==="local.get"||u.firstCond,p=r.get(y),_=h?null:m.find(b=>b.type===p&&b.end<u.start);_?(c.set(y,_.primary),u.end>_.end&&(_.end=u.end)):m.push({primary:y,type:p,end:u.end})}c.size!==0&&L(e,y=>{Array.isArray(y)&&(y[0]==="local.get"||y[0]==="local.set"||y[0]==="local.tee")&&c.has(y[1])&&(y[1]=c.get(y[1]))})}),t),Dr=t=>D(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="nop")return["nop"];if(r==="drop"&&e.length===2&&_t(e[1]))return["nop"];if(r==="select"&&e.length>=4&&T(e[1],e[2]))return e[1];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Ut(e),l=!s||s.length<=1,f=!n||n.length<=1;if(l&&f)return _t(i)?["nop"]:["drop",i];if(n&&f&&!l)return e.filter(o=>o!==n)}if(r==="func"||r==="block"||r==="loop"||r==="then"||r==="else"){let i=[r];for(let s=1;s<e.length;s++){let n=e[s];if(n==="nop"||Array.isArray(n)&&n[0]==="nop")continue;let l=e[s+1],f=l==="drop"||Array.isArray(l)&&l[0]==="drop"&&l.length===1;if(Array.isArray(n)&&_t(n)&&f){s++;continue}i.push(n)}if(i.length!==e.length)return i}}),Rr={"i32.sub":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.sub":(t,e)=>T(t,e)?["i64.const",0n]:null,"i32.xor":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.xor":(t,e)=>T(t,e)?["i64.const",0n]:null,"i32.and":(t,e)=>T(t,e)?t:null,"i64.and":(t,e)=>T(t,e)?t:null,"i32.or":(t,e)=>T(t,e)?t:null,"i64.or":(t,e)=>T(t,e)?t:null,"i32.eq":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.eq":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ne":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.ne":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.lt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.lt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.gt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.gt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.le_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.le_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ge_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ge_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.lt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.lt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.gt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.gt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.le_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.le_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.ge_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.ge_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.mul":(t,e)=>{let r=z(t),i=z(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.mul":(t,e)=>{let r=z(t),i=z(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.and":(t,e)=>{let r=z(t),i=z(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.and":(t,e)=>{let r=z(t),i=z(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.or":(t,e)=>{let r=z(t),i=z(e);return r?.value===-1||i?.value===-1?["i32.const",-1]:null},"i64.or":(t,e)=>{let r=z(t),i=z(e);return r?.value===-1n||i?.value===-1n?["i64.const",-1n]:null},"local.set":(t,e)=>Array.isArray(e)&&e[0]==="local.get"&&e[1]===t?["nop"]:null},Wr=t=>D(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=Rr[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Pr=t=>{let e=typeof t=="bigint"?t:BigInt(Math.trunc(Number(t)||0)),r=1;for(;;){let i=e&0x7fn;if(e>>=7n,e===0n&&(i&0x40n)===0n||e===-1n&&(i&0x40n)!==0n)return r;r++}},jr=t=>{if(!Array.isArray(t))return 4;switch(t[0]){case"i32.const":case"i64.const":return 1+Pr(t[1]);case"f32.const":return 5;case"f64.const":return 9;case"v128.const":return 18;default:return 4}},Gr=2,Hr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Set;for(let n of t.slice(1)){if(!Array.isArray(n))continue;if(n[0]==="export"&&Array.isArray(n[2])&&n[2][0]==="global"&&typeof n[2][1]=="string"){r.add(n[2][1]);continue}if(n[0]!=="global")continue;let l=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null;if(!l)continue;n.some(a=>Array.isArray(a)&&a[0]==="export")&&r.add(l);let f=n[2];if(Array.isArray(f)&&f[0]==="mut"||Array.isArray(f)&&f[0]==="import")continue;let o=n[3];z(o)&&e.set(l,o)}if(e.size===0)return t;let i=new Map;L(t,n=>{if(!Array.isArray(n))return;let l=n[1];typeof l!="string"||l[0]!=="$"||(n[0]==="global.set"?e.delete(l):n[0]==="global.get"&&i.set(l,(i.get(l)||0)+1))});let s=new Set;for(let[n,l]of e){let f=i.get(n)||0;if(f===0)continue;let o=jr(l),a=o+2,c=f*Gr+a;f*o+(r.has(n)?a:0)<=c&&s.add(n)}if(s.size===0)return t;D(t,n=>{if(!(!Array.isArray(n)||n[0]!=="global.get"||n.length!==2)&&s.has(n[1]))return J(e.get(n[1]))});for(let n=t.length-1;n>=1;n--){let l=t[n];Array.isArray(l)&&l[0]==="global"&&typeof l[1]=="string"&&s.has(l[1])&&!r.has(l[1])&&t.splice(n,1)}return t},Vr=t=>D(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(typeof r!="string"||!r.endsWith("load")&&!r.endsWith("store"))return;let i=r.endsWith("store"),s=0,n=null,l=1;for(typeof e[1]=="string"&&(e[1][0]==="$"||!isNaN(e[1]))&&(n=e[1],l=2);l<e.length&&typeof e[l]=="string"&&(e[l].startsWith("offset=")||e[l].startsWith("align="));)e[l].startsWith("offset=")&&(s=+e[l].slice(7)),l++;let f=i?e.length-2:e.length-1,o=i?e.length-1:-1;if(f<l)return;let a=e[f];if(!Array.isArray(a)||a[0]!=="i32.add"||a.length!==3)return;let c=a[1],m=a[2],y=z(c),u=z(m),h=null,p=null;if(y&&y.type==="i32"?(p=y.value,h=m):u&&u.type==="i32"&&(p=u.value,h=c),h===null||p===null)return;let _=s+p,b=[r];n!==null&&b.push(n),b.push(`offset=${_}`);let $=null;for(let w=l;w<f;w++)typeof e[w]=="string"&&e[w].startsWith("align=")&&($=e[w]);return $&&b.push($),b.push(h),i&&b.push(e[o]),b}),Yr=t=>(L(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let i=1,s=null;if(typeof e[1]=="string"&&e[1][0]==="$"&&(s=e[1],i=2),!s)return;let n=-1;for(let f=e.length-1;f>=i;f--){let o=e[f];if(!Array.isArray(o)){o!=="nop"&&o!=="end"&&(n=f);continue}let a=o[0];if(!(a==="param"||a==="result"||a==="local"||a==="type"||a==="export")){n=f;break}}if(n<0)return;let l=e[n];Array.isArray(l)&&l[0]==="br"&&l[1]===s&&e.splice(n,1,...l.slice(2))}),t),Xr=t=>(L(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let r=1,i=null;if(typeof e[1]=="string"&&e[1][0]==="$"&&(i=e[1],r=2),!i)return;for(;r<e.length;){let h=e[r];if(Array.isArray(h)&&h[0]==="type"){r++;continue}if(Array.isArray(h)&&(h[0]==="param"||h[0]==="result"))return;break}if(e.length-r!==1)return;let s=e[r];if(!Array.isArray(s)||s[0]!=="loop")return;let n=1,l=null;typeof s[1]=="string"&&s[1][0]==="$"&&(l=s[1],n=2);let f=[];for(;n<s.length;){let h=s[n];if(Array.isArray(h)&&h[0]==="type"){f.push(h),n++;continue}if(Array.isArray(h)&&(h[0]==="param"||h[0]==="result"))return;break}let o=s.slice(n);if(o.length<2)return;let a=o[0],c=o[o.length-1];if(!Array.isArray(a)||a[0]!=="br_if"||a[1]!==i||a.length!==3||!Array.isArray(c)||c[0]!=="br"||c[1]!==l||c.length!==2)return;let m=o.slice(1,-1);if(jt(m,i))return;let y=a[2];Array.isArray(y)&&y[0]==="i32.eqz"&&y.length===2?y=y[1]:y=["i32.eqz",y];let u=["loop"];l&&u.push(l);for(let h of f)u.push(h);u.push(["if",y,["then",...m,c]]),e.length=0;for(let h of u)e.push(h)}),t),Zr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set;return L(t,r=>{Array.isArray(r)&&r[0]==="global.set"&&typeof r[1]=="string"&&e.add(r[1])}),D(t,r=>{if(!Array.isArray(r)||r[0]!=="global")return;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i||e.has(i))return;let s=typeof r[1]=="string"&&r[1][0]==="$",n=s?r[2]:r[1];if(Array.isArray(n)&&n[0]==="mut"){let l=[...r];return l[s?2:1]=n[1],l}})},Kr=t=>D(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{cond:r,thenBranch:i,elseBranch:s}=Ut(e),n=!i||i.length<=1,l=!s||s.length<=1;if(!n&&l&&i.length===2){let f=i[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],r]}if(n&&!l&&s.length===2){let f=s[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],["i32.eqz",r]]}}),Qr=t=>D(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{thenBranch:r,elseBranch:i}=Ut(e);if(!r||!i||r.length<=1||i.length<=1||!e.some(y=>Array.isArray(y)&&y[0]==="result"))return;let n=0,l=Math.min(r.length,i.length);for(let y=1;y<l&&T(r[r.length-y],i[i.length-y]);y++)n++;if(n===0)return;let f=r.slice(r.length-n),o=r.slice(0,r.length-n),a=i.slice(0,i.length-n),c=["block"];for(let y=1;y<e.length;y++){let u=e[y];if(Array.isArray(u)&&(u[0]==="then"||u[0]==="else"))break;Array.isArray(u)&&(u[0]==="result"||u[0]==="type")&&c.push(u)}let m=["if"];for(let y=1;y<e.length;y++){let u=e[y];if(Array.isArray(u)&&(u[0]==="then"||u[0]==="else"))break;Array.isArray(u)&&(u[0]==="result"||u[0]==="type")||m.push(u)}return m.push(o.length>1?o:["then"]),m.push(a.length>1?a:["else"]),c.push(m,...f),c}),Me=(t,e)=>{let r=[],i=[t];for(;i.length;){let s=i.pop();if(Array.isArray(s)){i.push("|");for(let n=s.length-1;n>=0;n--)i.push(s[n]);i.push("[")}else typeof s=="string"?r.push(e.has(s)?"$__L":s):typeof s=="bigint"?r.push(s.toString()+"n"):typeof s=="number"?r.push(s.toString()):s===null?r.push("null"):s===!0?r.push("t"):s===!1?r.push("f"):r.push(String(s))}return r.join(",")},Jr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="func")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=new Set;typeof i[1]=="string"&&i[1][0]==="$"&&n.add(i[1]),L(i,f=>{if(!Array.isArray(f)||typeof f[1]!="string"||f[1][0]!=="$")return;let o=f[0];(o==="param"||o==="local"||o==="block"||o==="loop"||o==="if")&&n.add(f[1])});let l=Me(i,n);e.has(l)?r.set(s,e.get(l)):e.set(l,s)}return r.size===0||D(t,i=>{if(!Array.isArray(i))return;let s=i[0];if((s==="call"||s==="return_call")&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(s==="ref.func"&&r.has(i[1]))return["ref.func",r.get(i[1])];if(s==="elem"){let n=i[i.length-1];if(Array.isArray(n))return[...i.slice(0,-1),n.map(l=>r.get(l)||l)]}if(s==="call_indirect"&&i.length>=3){let n=i[1];if(typeof n=="string"&&r.has(n))return["call_indirect",r.get(n),...i.slice(2)]}}),t},ti=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="type")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=Me(i,new Set([s]));e.has(n)?r.set(s,e.get(n)):e.set(n,s)}if(r.size===0)return t;for(let i=t.length-1;i>=0;i--){let s=t[i];if(Array.isArray(s)&&s[0]==="type"){let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;n&&r.has(n)&&t.splice(i,1)}}return D(t,i=>{if(!Array.isArray(i))return;let s=i[0];if(s==="func")for(let n=1;n<i.length;n++){let l=i[n];Array.isArray(l)&&l[0]==="type"&&typeof l[1]=="string"&&r.has(l[1])&&(i[n]=["type",r.get(l[1])])}if(s==="import")for(let n=1;n<i.length;n++){let l=i[n];if(Array.isArray(l))for(let f=1;f<l.length;f++){let o=l[f];Array.isArray(o)&&o[0]==="type"&&typeof o[1]=="string"&&r.has(o[1])&&(l[f]=["type",r.get(o[1])])}}if(s==="call_indirect"||s==="return_call_indirect"){if(typeof i[1]=="string"&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(Array.isArray(i[1])&&i[1][0]==="type"&&typeof i[1][1]=="string"&&r.has(i[1][1]))return[s,["type",r.get(i[1][1])],...i.slice(2)]}}),t},Et=t=>{if(typeof t!="string"||t.length<2||t[0]!=='"')return new Uint8Array;let e=t.slice(1,-1),r=[];for(let i=0;i<e.length;i++)if(e[i]==="\\"){let s=e[++i];s==="x"||s==="X"?(r.push(parseInt(e.slice(i+1,i+3),16)),i+=2):/[0-9a-fA-F]/.test(s)&&/[0-9a-fA-F]/.test(e[i+1])?(r.push(parseInt(e.slice(i,i+2),16)),i++):s==="n"?r.push(10):s==="t"?r.push(9):s==="r"?r.push(13):s==="\\"?r.push(92):s==='"'?r.push(34):r.push(s.charCodeAt(0))}else r.push(e.charCodeAt(i));return new Uint8Array(r)},Ne=t=>{let e='"';for(let r=0;r<t.length;r++){let i=t[r];i>=32&&i<127&&i!==34&&i!==92?e+=String.fromCharCode(i):e+="\\"+i.toString(16).padStart(2,"0")}return e+'"'},ei=t=>{let e=[];for(let i of t)if(typeof i=="string")e.push(...Et(i));else if(Array.isArray(i)&&i[0]==="i8")for(let s=1;s<i.length;s++)e.push(Number(i[s])&255);else return t;let r=e.length;for(;r>0&&e[r-1]===0;)r--;return r===e.length?t:r===0?[]:[Ne(new Uint8Array(e.slice(0,r)))]},ri=t=>{let e=1;if(typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"){let i=t[e][1];e++;let s=t[e];return Array.isArray(s)&&(s[0]==="i32.const"||s[0]==="i64.const")?{memidx:i,offset:Number(s[1])}:null}let r=t[e];return Array.isArray(r)&&(r[0]==="i32.const"||r[0]==="i64.const")?{memidx:0,offset:Number(r[1])}:null},xe=t=>{let e=1;typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"&&e++,Array.isArray(t[e])&&typeof t[e][0]=="string"&&!t[e][0].startsWith('"')&&e++;let r=0;for(let i=e;i<t.length;i++){let s=t[i];if(typeof s=="string")r+=Et(s).length;else if(Array.isArray(s)&&s[0]==="i8")r+=s.length-1;else return null}return r},ii=(t,e)=>{let r=1;typeof t[r]=="string"&&t[r][0]==="$"&&r++,Array.isArray(t[r])&&t[r][0]==="memory"&&r++,Array.isArray(t[r])&&typeof t[r][0]=="string"&&!t[r][0].startsWith('"')&&r++;let i=1;typeof e[i]=="string"&&e[i][0]==="$"&&i++,Array.isArray(e[i])&&e[i][0]==="memory"&&i++,Array.isArray(e[i])&&typeof e[i][0]=="string"&&!e[i][0].startsWith('"')&&i++;let s=t.slice(r),n=e.slice(i);if(s.length===1&&n.length===1&&typeof s[0]=="string"&&typeof n[0]=="string"){let l=Et(s[0]),f=Et(n[0]),o=new Uint8Array(l.length+f.length);return o.set(l),o.set(f,l.length),t.length=r,t.push(Ne(o)),!0}return t.length=r,t.push(...s,...n),!0},si=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;for(let i of t){if(!Array.isArray(i)||i[0]!=="data")continue;let s=1;typeof i[1]=="string"&&i[1][0]==="$"&&(s=2),s<i.length&&Array.isArray(i[s])&&typeof i[s][0]=="string"&&!i[s][0].startsWith('"')&&s++;let n=i.slice(s);if(n.length===0)continue;let l=ei(n);(l.length!==n.length||l.length>0&&l[0]!==n[0])&&(i.length=s,i.push(...l))}let e=[];for(let i=0;i<t.length;i++){let s=t[i];if(Array.isArray(s)&&s[0]==="data"){let n=ri(s);if(n){let l=xe(s);l!==null&&e.push({...n,node:s,index:i,len:l})}}}e.sort((i,s)=>{let n=String(i.memidx),l=String(s.memidx);return n!==l?n.localeCompare(l):i.offset-s.offset});let r=new Set;for(let i=0;i<e.length-1;i++){let s=e[i],n=e[i+1];r.has(s.index)||String(s.memidx)!==String(n.memidx)||s.offset+s.len===n.offset&&ii(s.node,n.node)&&(r.add(n.index),s.len=xe(s.node))}return r.size>0&&(t=t.filter((i,s)=>!r.has(s))),t},de=()=>{let t=new Map,e=0;return r=>{if(!t.has(r)){let i="",s=e++;do i=String.fromCharCode(97+s%26)+i,s=Math.floor(s/26)-1;while(s>=0);t.set(r,i||"a")}return t.get(r)}},ni=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=de(),r=de();for(let i of t)!Array.isArray(i)||i[0]!=="import"||(typeof i[1]=="string"&&i[1][0]==='"'&&(i[1]='"'+e(i[1].slice(1,-1))+'"'),typeof i[2]=="string"&&i[2][0]==='"'&&(i[2]='"'+r(i[2].slice(1,-1))+'"'));return t},li=t=>{let e=!0;return L(t,r=>{if(!e||!Array.isArray(r))return;let i=r[0];if(i==="func"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if((i==="call"||i==="return_call"||i==="ref.func")&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="start"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="elem")for(let s of r){if(typeof s=="string"&&s[0]!=="$"&&/^\d/.test(s)){e=!1;break}if(Array.isArray(s)&&s[0]==="ref.func"&&(typeof s[1]!="string"||s[1][0]!=="$")){e=!1;break}}}),e},fi=t=>{if(!Array.isArray(t)||t[0]!=="module"||!li(t))return t;let e=new Map;L(t,n=>{Array.isArray(n)&&(n[0]==="call"||n[0]==="return_call")&&e.set(n[1],(e.get(n[1])||0)+1)});let r=[],i=[],s=[];for(let n of t.slice(1)){if(!Array.isArray(n)){s.push(n);continue}n[0]==="import"?r.push(n):n[0]==="func"?i.push(n):s.push(n)}return i.sort((n,l)=>(e.get(l[1])||0)-(e.get(n[1])||0)),["module",...r,...i,...s]};function qt(t,e=!0){typeof t=="string"&&(t=Z(t));let r=e===!0;e=mr(e);let i=e.log?(l,f)=>e.log(l,f):()=>{},s=e.verbose||e.log;t=J(t);let n=null;for(let l=0;l<3;l++){n=J(t);let f=ce(t);e.stripmut&&(t=Zr(t)),e.globals&&(t=Hr(t)),e.fold&&(t=Ar(t)),e.identity&&(t=wr(t)),e.peephole&&(t=Wr(t)),e.strength&&(t=vr(t)),e.branch&&(t=$r(t)),e.propagate&&(t=he(t)),e.inlineOnce&&(t=Fr(t)),e.inline&&(t=qr(t)),e.offset&&(t=Vr(t)),e.unbranch&&(t=Yr(t)),e.loopify&&(t=Xr(t)),e.brif&&(t=Kr(t)),e.foldarms&&(t=Qr(t)),e.deadcode&&(t=Ir(t)),e.vacuum&&(t=Dr(t)),e.mergeBlocks&&(t=Lr(t)),e.coalesce&&(t=Cr(t)),e.locals&&(t=kr(t)),e.dedupe&&(t=Jr(t)),e.dedupTypes&&(t=ti(t)),e.packData&&(t=si(t)),e.reorder&&(t=fi(t)),e.treeshake&&(t=pr(t)),e.minifyImports&&(t=ni(t)),e.propagate&&(e.inlineOnce||e.inline)&&(t=he(t));let a=ce(t)-f;if((s||a!==0)&&i(` round ${l+1}: ${a>0?"+":""}${a} bytes`,a),a>(r?0:16)){s&&i(` \u26A0 round ${l+1} inflated by ${a} bytes, reverting`,a),t=n;break}if(T(n,t))break}return t}var Se="\uE000",ze=t=>{if(!t||typeof t!="string")return null;let e=t.split(".")[0];return/^[if](32|64)|v128/.test(e)?e:/\.(eq|ne|[lg][te]|eqz)/.test(t)||t==="memory.size"||t==="memory.grow"?"i32":null},ai=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t;return ze(r)?ze(r):r==="local.get"&&e.locals?.[i[0]]?e.locals[i[0]]:r==="call"&&e.funcs?.[i[0]]?e.funcs[i[0]].result?.[0]:null};function Gt(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=Gt(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function oi(t,e){let r=[],i=new Map;return Gt(t,s=>{if(!Array.isArray(s))return s;if(s[0]==="call"&&typeof s[1]=="function"){let n=s[1];if(!i.has(n)){let f=[];for(let c=2;c<s.length;c++){let m=ai(s[c]);m&&f.push(m)}let o=r.length,a=n.name||`$fn${o}`;i.set(n,{idx:o,name:a.startsWith("$")?a:"$"+a,params:f,fn:n}),r.push(i.get(n))}let l=i.get(n);s[1]=l.name}return s}),r}function ci(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function ui(t,...e){let r={};if(!Array.isArray(t)&&e.length&&typeof e[e.length-1]=="object"&&e[e.length-1]!==null&&!e[e.length-1].byteLength&&(r=e.pop()),Array.isArray(t)&&t.raw){let i=t[0];for(let a=0;a<e.length;a++)i+=Se+t[a+1];let s=Z(i),n=[],l=0;s=Gt(s,a=>{if(a===Se){let c=e[l++];if(typeof c=="function")return n.push(c),c;if(typeof c=="string"&&(c[0]==="("||/^\s*\(/.test(c))){let m=Z(c);return Array.isArray(m)&&Array.isArray(m[0])&&(m._splice=!0),m}return c.byteLength!==void 0?[...c]:c}return a});let f=null;if(n.length){let a=oi(s,n);if(a.length){let c=ci(a);s[0]==="module"?s.splice(1,0,...c):typeof s[0]=="string"?s=[...c,s]:s.unshift(...c),f={env:{}};for(let m of a)f.env[m.name.slice(1)]=m.fn}}r.polyfill&&(s=St(s,r.polyfill)),r.optimize&&(s=qt(s,r.optimize));let o=at(s);return f&&(o._imports=f),o}if(r.polyfill||r.optimize){let i=typeof t=="string"?Z(t):t;return r.polyfill&&(i=St(i,r.polyfill)),r.optimize&&(i=qt(i,r.optimize)),at(i)}return at(t)}function yi(t,...e){let r=ui(t,...e),i=new WebAssembly.Module(r);return new WebAssembly.Instance(i,r._imports).exports}var Fi=yi;export{ui as compile,Fi as default,qt as optimize,Z as parse,St as polyfill,se as print,yi as watr};
|
package/dist/watr.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/src/optimize.js
CHANGED
|
@@ -28,6 +28,7 @@ const OPTS = {
|
|
|
28
28
|
globals: true, // propagate immutable global constants
|
|
29
29
|
offset: true, // fold add+const into load/store offset
|
|
30
30
|
unbranch: true, // remove redundant br at end of own block
|
|
31
|
+
loopify: true, // collapse block+loop+brif while-idiom into loop+if
|
|
31
32
|
stripmut: true, // strip mut from never-written globals
|
|
32
33
|
brif: true, // if-then-br → br_if
|
|
33
34
|
foldarms: false, // merge identical trailing if arms — can add block wrapper
|
|
@@ -321,6 +322,18 @@ const treeshake = (ast) => {
|
|
|
321
322
|
/** IEEE 754 roundTiesToEven (bankers' rounding) */
|
|
322
323
|
const roundEven = (x) => x - Math.floor(x) !== 0.5 ? Math.round(x) : 2 * Math.round(x / 2)
|
|
323
324
|
|
|
325
|
+
// Bit-exact reinterpret helpers (preserve NaN payloads).
|
|
326
|
+
const _rb8 = new ArrayBuffer(8)
|
|
327
|
+
const _rf64 = new Float64Array(_rb8)
|
|
328
|
+
const _ri64 = new BigInt64Array(_rb8)
|
|
329
|
+
const _rb4 = new ArrayBuffer(4)
|
|
330
|
+
const _rf32 = new Float32Array(_rb4)
|
|
331
|
+
const _ri32 = new Int32Array(_rb4)
|
|
332
|
+
const i64FromF64 = (x) => { _rf64[0] = x; return _ri64[0] }
|
|
333
|
+
const f64FromI64 = (x) => { _ri64[0] = BigInt.asIntN(64, x); return _rf64[0] }
|
|
334
|
+
const i32FromF32 = (x) => { _rf32[0] = x; return _ri32[0] }
|
|
335
|
+
const f32FromI32 = (x) => { _ri32[0] = x | 0; return _rf32[0] }
|
|
336
|
+
|
|
324
337
|
/** Build i32 comparison folder: returns 1/0 */
|
|
325
338
|
const i32c = (fn) => (a, b) => fn(a, b) ? 1 : 0
|
|
326
339
|
/** Build unsigned i32 comparison folder */
|
|
@@ -424,6 +437,24 @@ const FOLDABLE = {
|
|
|
424
437
|
'f64.floor': [Math.floor, 'f64'],
|
|
425
438
|
'f64.trunc': [Math.trunc, 'f64'],
|
|
426
439
|
'f64.nearest': [roundEven, 'f64'],
|
|
440
|
+
|
|
441
|
+
// Bit-exact reinterprets (preserve NaN payloads)
|
|
442
|
+
'i32.reinterpret_f32': [i32FromF32, 'i32'],
|
|
443
|
+
'f32.reinterpret_i32': [f32FromI32, 'f32'],
|
|
444
|
+
'i64.reinterpret_f64': [i64FromF64, 'i64'],
|
|
445
|
+
'f64.reinterpret_i64': [f64FromI64, 'f64'],
|
|
446
|
+
|
|
447
|
+
// Numeric conversions (value-preserving where representable)
|
|
448
|
+
'f32.convert_i32_s': [(a) => Math.fround(a | 0), 'f32'],
|
|
449
|
+
'f32.convert_i32_u': [(a) => Math.fround(a >>> 0), 'f32'],
|
|
450
|
+
'f32.convert_i64_s': [(a) => Math.fround(Number(BigInt.asIntN(64, a))), 'f32'],
|
|
451
|
+
'f32.convert_i64_u': [(a) => Math.fround(Number(BigInt.asUintN(64, a))), 'f32'],
|
|
452
|
+
'f64.convert_i32_s': [(a) => (a | 0), 'f64'],
|
|
453
|
+
'f64.convert_i32_u': [(a) => (a >>> 0), 'f64'],
|
|
454
|
+
'f64.convert_i64_s': [(a) => Number(BigInt.asIntN(64, a)), 'f64'],
|
|
455
|
+
'f64.convert_i64_u': [(a) => Number(BigInt.asUintN(64, a)), 'f64'],
|
|
456
|
+
'f32.demote_f64': [(a) => Math.fround(a), 'f32'],
|
|
457
|
+
'f64.promote_f32': [(a) => Math.fround(a), 'f64'],
|
|
427
458
|
}
|
|
428
459
|
|
|
429
460
|
/**
|
|
@@ -1427,14 +1458,47 @@ const targetsLabel = (body, label) => {
|
|
|
1427
1458
|
}
|
|
1428
1459
|
|
|
1429
1460
|
/**
|
|
1430
|
-
* Unwrap redundant
|
|
1431
|
-
*
|
|
1432
|
-
*
|
|
1433
|
-
*
|
|
1461
|
+
* Unwrap redundant blocks whose label is never targeted. The block's stack
|
|
1462
|
+
* effect is determined entirely by its body, so removing the `block`/`end`
|
|
1463
|
+
* framing is sound as long as no `br` reaches into the block from inside.
|
|
1464
|
+
*
|
|
1465
|
+
* Two complementary patterns:
|
|
1466
|
+
*
|
|
1467
|
+
* 1. **Block at scope level** (sibling in `func`/`block`/`loop`/`then`/`else`):
|
|
1468
|
+
* splice body into the parent scope. Works for untyped, `(result T)`-typed,
|
|
1469
|
+
* or even `(param …)`-typed blocks — in all cases the body produces the
|
|
1470
|
+
* same net stack effect as the framed block did, at the same position.
|
|
1471
|
+
* 2. **Result-typed block in expression position** (`(block (result T) expr)`
|
|
1472
|
+
* as the value of some operand): collapse to `expr` if the body is a
|
|
1473
|
+
* single value expression. Catches the wrappers jz codegen leaves around
|
|
1474
|
+
* arena allocations once `propagate` has folded the intermediate
|
|
1475
|
+
* set/get pairs to a single call.
|
|
1476
|
+
*
|
|
1477
|
+
* Pattern 2 runs first (post-order) so pattern 1 sees the cleaned-up parents.
|
|
1434
1478
|
* @param {Array} ast
|
|
1435
1479
|
* @returns {Array}
|
|
1436
1480
|
*/
|
|
1437
1481
|
const mergeBlocks = (ast) => {
|
|
1482
|
+
walkPost(ast, (node) => {
|
|
1483
|
+
if (!Array.isArray(node) || node[0] !== 'block') return
|
|
1484
|
+
let bi = 1, label = null
|
|
1485
|
+
if (typeof node[1] === 'string' && node[1][0] === '$') { label = node[1]; bi = 2 }
|
|
1486
|
+
let hasResult = false
|
|
1487
|
+
while (bi < node.length) {
|
|
1488
|
+
const c = node[bi]
|
|
1489
|
+
if (Array.isArray(c) && (c[0] === 'param' || c[0] === 'type')) { bi++; continue }
|
|
1490
|
+
if (Array.isArray(c) && c[0] === 'result') { hasResult = true; bi++; continue }
|
|
1491
|
+
break
|
|
1492
|
+
}
|
|
1493
|
+
const body = node.slice(bi)
|
|
1494
|
+
if (!hasResult || body.length !== 1) return
|
|
1495
|
+
const only = body[0]
|
|
1496
|
+
if (!Array.isArray(only)) return
|
|
1497
|
+
if (label && targetsLabel(body, label)) return
|
|
1498
|
+
node.length = 0
|
|
1499
|
+
for (const tok of only) node.push(tok)
|
|
1500
|
+
})
|
|
1501
|
+
|
|
1438
1502
|
walk(ast, (node) => {
|
|
1439
1503
|
if (!isScopeNode(node)) return
|
|
1440
1504
|
let i = 1
|
|
@@ -1443,12 +1507,13 @@ const mergeBlocks = (ast) => {
|
|
|
1443
1507
|
if (!Array.isArray(child) || child[0] !== 'block') { i++; continue }
|
|
1444
1508
|
let bi = 1, label = null
|
|
1445
1509
|
if (typeof child[1] === 'string' && child[1][0] === '$') { label = child[1]; bi = 2 }
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1510
|
+
// Skip leading typing annotations; they describe the block's stack effect,
|
|
1511
|
+
// which the body already produces verbatim, so they're discarded on splice.
|
|
1512
|
+
while (bi < child.length) {
|
|
1513
|
+
const c = child[bi]
|
|
1514
|
+
if (Array.isArray(c) && (c[0] === 'param' || c[0] === 'result' || c[0] === 'type')) { bi++; continue }
|
|
1515
|
+
break
|
|
1450
1516
|
}
|
|
1451
|
-
if (typed) { i++; continue }
|
|
1452
1517
|
const body = child.slice(bi)
|
|
1453
1518
|
if (label && targetsLabel(body, label)) { i++; continue }
|
|
1454
1519
|
node.splice(i, 1, ...body)
|
|
@@ -1928,6 +1993,83 @@ const unbranch = (ast) => {
|
|
|
1928
1993
|
return ast
|
|
1929
1994
|
}
|
|
1930
1995
|
|
|
1996
|
+
// ==================== WHILE-LOOP CANONICALIZATION ====================
|
|
1997
|
+
|
|
1998
|
+
/**
|
|
1999
|
+
* Collapse the `while`-emit idiom into a single loop.
|
|
2000
|
+
*
|
|
2001
|
+
* (block $A
|
|
2002
|
+
* (loop $B
|
|
2003
|
+
* (br_if $A (i32.eqz cond)) ;; exit when cond is false
|
|
2004
|
+
* …body…
|
|
2005
|
+
* (br $B) ;; continue
|
|
2006
|
+
* ))
|
|
2007
|
+
*
|
|
2008
|
+
* becomes
|
|
2009
|
+
*
|
|
2010
|
+
* (loop $B
|
|
2011
|
+
* (if cond (then …body… (br $B))))
|
|
2012
|
+
*
|
|
2013
|
+
* Saves ~3 B per while-loop (drop the outer block framing + the `i32.eqz`,
|
|
2014
|
+
* trade `br_if`→`if`). Safe only when:
|
|
2015
|
+
* - the block contains nothing but the loop (plus optional `type` slot),
|
|
2016
|
+
* - block / loop are void (no result),
|
|
2017
|
+
* - $A is never targeted from within body (only the head `br_if` uses it).
|
|
2018
|
+
*
|
|
2019
|
+
* @param {Array} ast
|
|
2020
|
+
* @returns {Array}
|
|
2021
|
+
*/
|
|
2022
|
+
const loopify = (ast) => {
|
|
2023
|
+
walk(ast, (node) => {
|
|
2024
|
+
if (!Array.isArray(node) || node[0] !== 'block') return
|
|
2025
|
+
let bi = 1, label = null
|
|
2026
|
+
if (typeof node[1] === 'string' && node[1][0] === '$') { label = node[1]; bi = 2 }
|
|
2027
|
+
if (!label) return
|
|
2028
|
+
while (bi < node.length) {
|
|
2029
|
+
const c = node[bi]
|
|
2030
|
+
if (Array.isArray(c) && c[0] === 'type') { bi++; continue }
|
|
2031
|
+
if (Array.isArray(c) && (c[0] === 'param' || c[0] === 'result')) return // typed → skip
|
|
2032
|
+
break
|
|
2033
|
+
}
|
|
2034
|
+
if (node.length - bi !== 1) return
|
|
2035
|
+
const loop = node[bi]
|
|
2036
|
+
if (!Array.isArray(loop) || loop[0] !== 'loop') return
|
|
2037
|
+
let li = 1, loopLabel = null
|
|
2038
|
+
if (typeof loop[1] === 'string' && loop[1][0] === '$') { loopLabel = loop[1]; li = 2 }
|
|
2039
|
+
const loopHeader = []
|
|
2040
|
+
while (li < loop.length) {
|
|
2041
|
+
const c = loop[li]
|
|
2042
|
+
if (Array.isArray(c) && c[0] === 'type') { loopHeader.push(c); li++; continue }
|
|
2043
|
+
if (Array.isArray(c) && (c[0] === 'param' || c[0] === 'result')) return // typed → skip
|
|
2044
|
+
break
|
|
2045
|
+
}
|
|
2046
|
+
const body = loop.slice(li)
|
|
2047
|
+
if (body.length < 2) return
|
|
2048
|
+
const head = body[0]
|
|
2049
|
+
const tail = body[body.length - 1]
|
|
2050
|
+
if (!Array.isArray(head) || head[0] !== 'br_if' || head[1] !== label || head.length !== 3) return
|
|
2051
|
+
if (!Array.isArray(tail) || tail[0] !== 'br' || tail[1] !== loopLabel || tail.length !== 2) return
|
|
2052
|
+
const inner = body.slice(1, -1)
|
|
2053
|
+
if (targetsLabel(inner, label)) return
|
|
2054
|
+
|
|
2055
|
+
// br_if exits when `cond` is non-zero — `if`'s then-arm runs when its
|
|
2056
|
+
// condition is non-zero. So the if-condition is the negation. Strip a
|
|
2057
|
+
// wrapping `i32.eqz` if present; otherwise wrap.
|
|
2058
|
+
let cond = head[2]
|
|
2059
|
+
if (Array.isArray(cond) && cond[0] === 'i32.eqz' && cond.length === 2) cond = cond[1]
|
|
2060
|
+
else cond = ['i32.eqz', cond]
|
|
2061
|
+
|
|
2062
|
+
const newLoop = ['loop']
|
|
2063
|
+
if (loopLabel) newLoop.push(loopLabel)
|
|
2064
|
+
for (const h of loopHeader) newLoop.push(h)
|
|
2065
|
+
newLoop.push(['if', cond, ['then', ...inner, tail]])
|
|
2066
|
+
|
|
2067
|
+
node.length = 0
|
|
2068
|
+
for (const tok of newLoop) node.push(tok)
|
|
2069
|
+
})
|
|
2070
|
+
return ast
|
|
2071
|
+
}
|
|
2072
|
+
|
|
1931
2073
|
// ==================== STRIP MUT FROM GLOBALS ====================
|
|
1932
2074
|
|
|
1933
2075
|
/**
|
|
@@ -2577,6 +2719,7 @@ export default function optimize(ast, opts = true) {
|
|
|
2577
2719
|
if (opts.inline) ast = inline(ast)
|
|
2578
2720
|
if (opts.offset) ast = offset(ast)
|
|
2579
2721
|
if (opts.unbranch) ast = unbranch(ast)
|
|
2722
|
+
if (opts.loopify) ast = loopify(ast)
|
|
2580
2723
|
if (opts.brif) ast = brif(ast)
|
|
2581
2724
|
if (opts.foldarms) ast = foldarms(ast)
|
|
2582
2725
|
if (opts.deadcode) ast = deadcode(ast)
|
|
@@ -2621,4 +2764,4 @@ export default function optimize(ast, opts = true) {
|
|
|
2621
2764
|
|
|
2622
2765
|
/** Count AST nodes (fast size heuristic). */
|
|
2623
2766
|
export { count as size, count, binarySize }
|
|
2624
|
-
export { optimize, treeshake, fold, deadcode, localReuse, identity, strength, branch, propagate, inline, inlineOnce, normalize, OPTS, vacuum, peephole, globals, offset, unbranch, stripmut, brif, foldarms, dedupe, reorder, dedupTypes, packData, minifyImports, mergeBlocks, coalesceLocals }
|
|
2767
|
+
export { optimize, treeshake, fold, deadcode, localReuse, identity, strength, branch, propagate, inline, inlineOnce, normalize, OPTS, vacuum, peephole, globals, offset, unbranch, loopify, stripmut, brif, foldarms, dedupe, reorder, dedupTypes, packData, minifyImports, mergeBlocks, coalesceLocals }
|
package/types/src/optimize.d.ts
CHANGED
|
@@ -128,6 +128,7 @@ export namespace OPTS {
|
|
|
128
128
|
let globals: boolean;
|
|
129
129
|
let offset: boolean;
|
|
130
130
|
let unbranch: boolean;
|
|
131
|
+
let loopify: boolean;
|
|
131
132
|
let stripmut: boolean;
|
|
132
133
|
let brif: boolean;
|
|
133
134
|
let foldarms: boolean;
|
|
@@ -171,6 +172,31 @@ export function offset(ast: any): any;
|
|
|
171
172
|
* @returns {Array}
|
|
172
173
|
*/
|
|
173
174
|
export function unbranch(ast: any[]): any[];
|
|
175
|
+
/**
|
|
176
|
+
* Collapse the `while`-emit idiom into a single loop.
|
|
177
|
+
*
|
|
178
|
+
* (block $A
|
|
179
|
+
* (loop $B
|
|
180
|
+
* (br_if $A (i32.eqz cond)) ;; exit when cond is false
|
|
181
|
+
* …body…
|
|
182
|
+
* (br $B) ;; continue
|
|
183
|
+
* ))
|
|
184
|
+
*
|
|
185
|
+
* becomes
|
|
186
|
+
*
|
|
187
|
+
* (loop $B
|
|
188
|
+
* (if cond (then …body… (br $B))))
|
|
189
|
+
*
|
|
190
|
+
* Saves ~3 B per while-loop (drop the outer block framing + the `i32.eqz`,
|
|
191
|
+
* trade `br_if`→`if`). Safe only when:
|
|
192
|
+
* - the block contains nothing but the loop (plus optional `type` slot),
|
|
193
|
+
* - block / loop are void (no result),
|
|
194
|
+
* - $A is never targeted from within body (only the head `br_if` uses it).
|
|
195
|
+
*
|
|
196
|
+
* @param {Array} ast
|
|
197
|
+
* @returns {Array}
|
|
198
|
+
*/
|
|
199
|
+
export function loopify(ast: any[]): any[];
|
|
174
200
|
/**
|
|
175
201
|
* Strip mutability from globals that are never written.
|
|
176
202
|
* Enables globals constant-propagation for more globals.
|
|
@@ -222,10 +248,23 @@ export function packData(ast: any[]): any[];
|
|
|
222
248
|
*/
|
|
223
249
|
export function minifyImports(ast: any[]): any[];
|
|
224
250
|
/**
|
|
225
|
-
* Unwrap redundant
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
251
|
+
* Unwrap redundant blocks whose label is never targeted. The block's stack
|
|
252
|
+
* effect is determined entirely by its body, so removing the `block`/`end`
|
|
253
|
+
* framing is sound as long as no `br` reaches into the block from inside.
|
|
254
|
+
*
|
|
255
|
+
* Two complementary patterns:
|
|
256
|
+
*
|
|
257
|
+
* 1. **Block at scope level** (sibling in `func`/`block`/`loop`/`then`/`else`):
|
|
258
|
+
* splice body into the parent scope. Works for untyped, `(result T)`-typed,
|
|
259
|
+
* or even `(param …)`-typed blocks — in all cases the body produces the
|
|
260
|
+
* same net stack effect as the framed block did, at the same position.
|
|
261
|
+
* 2. **Result-typed block in expression position** (`(block (result T) expr)`
|
|
262
|
+
* as the value of some operand): collapse to `expr` if the body is a
|
|
263
|
+
* single value expression. Catches the wrappers jz codegen leaves around
|
|
264
|
+
* arena allocations once `propagate` has folded the intermediate
|
|
265
|
+
* set/get pairs to a single call.
|
|
266
|
+
*
|
|
267
|
+
* Pattern 2 runs first (post-order) so pattern 1 sees the cleaned-up parents.
|
|
229
268
|
* @param {Array} ast
|
|
230
269
|
* @returns {Array}
|
|
231
270
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AAonFA;;;;;;;;;;;GAWG;AACH,sCATW,QAAM,MAAM,SACZ,OAAO,GAAC,MAAM,MAAO,SAkF/B;AA9pFD;;;;GAIG;AACH,4BAHW,GAAG,GACD,MAAM,CAOlB;AAED;;;;GAIG;AACH,wCAFa,MAAM,CAIlB;AAwGD;;;;;GAKG;AACH,6CAgJC;AA2KD;;;;GAIG;AACH,wCAwBC;AAoMD;;;;GAIG;AACH,4CAqBC;AA+CD;;;;;GAKG;AACH,8CAmDC;AA7QD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CA6DC;AAID;;;;GAIG;AACH,0CAuCC;AAgYD,yCAoCC;AAID;;;;GAIG;AACH,0CAiGC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,8CAgKC;AAp0CD;;;;GAIG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAa/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAugDD;;;;;GAKG;AACH,0CAgDC;AAyED;;;;GAIG;AACH,4CAQC;AA4BD;;;;;;;;;;;GAWG;AACH,2CAyDC;AAID,2EAA2E;AAC3E,sCAgEC;AAID;;;;GAIG;AACH,4CAyCC;AAID;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,2CAiDC;AAID;;;;;GAKG;AACH,4CAqBC;AAID;;;;;;GAMG;AACH,wCAmBC;AAID;;;;;GAKG;AACH,4CAiDC;AAoCD;;;;;GAKG;AACH,0CA8DC;AAiWD,uCAyBC;AAtXD;;;;;GAKG;AACH,8CAyEC;AAoID;;;;GAIG;AACH,4CAyDC;AAqBD;;;;;GAKG;AACH,iDAgBC;AAnoCD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,+CA2CC;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,kDAyFC"}
|