watr 4.2.0 → 4.2.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 +37 -13
- package/dist/watr.min.js +5 -5
- package/package.json +1 -1
- package/src/compile.js +20 -10
- package/src/optimize.js +15 -2
- package/src/parse.js +2 -2
- package/src/util.js +4 -4
- package/types/src/compile.d.ts.map +1 -1
- package/types/src/optimize.d.ts.map +1 -1
- package/types/src/util.d.ts +3 -3
- package/types/src/util.d.ts.map +1 -1
package/dist/watr.js
CHANGED
|
@@ -18,7 +18,7 @@ __export(encode_exports, {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
// src/util.js
|
|
21
|
-
var err = (text, pos = err.
|
|
21
|
+
var err = (text, pos = err.loc) => {
|
|
22
22
|
if (pos != null && err.src) {
|
|
23
23
|
let line = 1, col = 1;
|
|
24
24
|
for (let i = 0; i < pos && i < err.src.length; i++) {
|
|
@@ -951,7 +951,7 @@ var parse_default = (str2) => {
|
|
|
951
951
|
let i = 0, level = [], buf = "", q = 0, depth = 0;
|
|
952
952
|
const commit = () => buf && (level.push(buf), buf = "");
|
|
953
953
|
const parseLevel = (pos) => {
|
|
954
|
-
level.
|
|
954
|
+
level.loc = pos;
|
|
955
955
|
for (let c, root, p; i < str2.length; ) {
|
|
956
956
|
c = str2.charCodeAt(i);
|
|
957
957
|
if (q === 34) buf += str2[i++], c === 92 ? buf += str2[i++] : c === 34 && (commit(), q = 0);
|
|
@@ -996,14 +996,14 @@ var cleanup = (node, result) => !Array.isArray(node) ? typeof node !== "string"
|
|
|
996
996
|
) : (
|
|
997
997
|
// remove annotations like (@name ...) except @custom and @metadata.code.*
|
|
998
998
|
node[0]?.[0] === "@" && node[0] !== "@custom" && !node[0]?.startsWith?.("@metadata.code.") ? null : (
|
|
999
|
-
// unwrap single-element array containing module (after removing comments), preserve .
|
|
1000
|
-
(result = node.map(cleanup).filter((n) => n != null), result.
|
|
999
|
+
// unwrap single-element array containing module (after removing comments), preserve .loc
|
|
1000
|
+
(result = node.map(cleanup).filter((n) => n != null), result.loc = node.loc, result.length === 1 && result[0]?.[0] === "module" ? result[0] : result)
|
|
1001
1001
|
)
|
|
1002
1002
|
);
|
|
1003
1003
|
function compile(nodes) {
|
|
1004
1004
|
if (typeof nodes === "string") err.src = nodes, nodes = parse_default(nodes) || [];
|
|
1005
1005
|
else err.src = "";
|
|
1006
|
-
err.
|
|
1006
|
+
err.loc = 0;
|
|
1007
1007
|
nodes = cleanup(nodes) || [];
|
|
1008
1008
|
let idx = 0;
|
|
1009
1009
|
if (nodes[0] === "module") idx++, isId(nodes[idx]) && idx++;
|
|
@@ -1015,12 +1015,25 @@ function compile(nodes) {
|
|
|
1015
1015
|
ctx.metadata = {};
|
|
1016
1016
|
nodes.slice(idx).filter((n) => {
|
|
1017
1017
|
if (!Array.isArray(n)) {
|
|
1018
|
-
let pos = err.
|
|
1019
|
-
|
|
1018
|
+
let pos = err.loc, src = err.src, c;
|
|
1019
|
+
while ((pos = src.indexOf(n, pos)) >= 0) {
|
|
1020
|
+
c = src.charCodeAt(pos - 1);
|
|
1021
|
+
if (pos > 0 && (c > 47 && c < 58 || c > 64 && c < 91 || c > 96 && c < 123 || c === 95 || c === 36)) {
|
|
1022
|
+
pos++;
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
c = src.charCodeAt(pos + n.length);
|
|
1026
|
+
if (c > 47 && c < 58 || c > 64 && c < 91 || c > 96 && c < 123 || c === 95) {
|
|
1027
|
+
pos++;
|
|
1028
|
+
continue;
|
|
1029
|
+
}
|
|
1030
|
+
break;
|
|
1031
|
+
}
|
|
1032
|
+
if (pos >= 0) err.loc = pos;
|
|
1020
1033
|
err(`Unexpected token ${n}`);
|
|
1021
1034
|
}
|
|
1022
1035
|
let [kind, ...node] = n;
|
|
1023
|
-
err.
|
|
1036
|
+
err.loc = n.loc;
|
|
1024
1037
|
if (kind === "@custom") {
|
|
1025
1038
|
ctx.custom.push(node);
|
|
1026
1039
|
} else if (kind === "rec") {
|
|
@@ -1037,7 +1050,7 @@ function compile(nodes) {
|
|
|
1037
1050
|
else return true;
|
|
1038
1051
|
}).forEach((n) => {
|
|
1039
1052
|
let [kind, ...node] = n;
|
|
1040
|
-
err.
|
|
1053
|
+
err.loc = n.loc;
|
|
1041
1054
|
let imported;
|
|
1042
1055
|
if (kind === "import") [kind, ...node] = (imported = node).pop();
|
|
1043
1056
|
let items = ctx[kind];
|
|
@@ -1147,7 +1160,7 @@ function normalize(nodes, ctx) {
|
|
|
1147
1160
|
} else if ((node.startsWith("memory.") || node.endsWith("load") || node.endsWith("store")) && isIdx(nodes[0])) out.push(nodes.shift());
|
|
1148
1161
|
} else if (Array.isArray(node)) {
|
|
1149
1162
|
const op = node[0];
|
|
1150
|
-
node.
|
|
1163
|
+
node.loc != null && (err.loc = node.loc);
|
|
1151
1164
|
if (op?.startsWith?.("@metadata.code.")) {
|
|
1152
1165
|
let type = op.slice(15);
|
|
1153
1166
|
out.push(["@metadata", type, node[1]]);
|
|
@@ -1561,7 +1574,7 @@ var instr = (nodes, ctx) => {
|
|
|
1561
1574
|
continue;
|
|
1562
1575
|
}
|
|
1563
1576
|
if (Array.isArray(op)) {
|
|
1564
|
-
op.
|
|
1577
|
+
op.loc != null && (err.loc = op.loc);
|
|
1565
1578
|
err(`Unknown instruction ${op[0]}`);
|
|
1566
1579
|
}
|
|
1567
1580
|
let [...bytes] = INSTR[op] || err(`Unknown instruction ${op}`);
|
|
@@ -2687,7 +2700,8 @@ var treeshake = (ast) => {
|
|
|
2687
2700
|
}
|
|
2688
2701
|
}
|
|
2689
2702
|
for (const start of starts) {
|
|
2690
|
-
|
|
2703
|
+
let ref = start[1];
|
|
2704
|
+
if (typeof ref === "string" && ref[0] !== "$") ref = +ref;
|
|
2691
2705
|
if (funcs.has(ref)) funcs.get(ref).used = true;
|
|
2692
2706
|
}
|
|
2693
2707
|
let hasExports = exports.length > 0 || starts.length > 0;
|
|
@@ -3308,7 +3322,17 @@ var inline = (ast) => {
|
|
|
3308
3322
|
}
|
|
3309
3323
|
}
|
|
3310
3324
|
if (params && !hasLocals && !hasExport && params.length <= 2 && body.length === 1) {
|
|
3311
|
-
|
|
3325
|
+
const paramNames = new Set(params.map((p) => p.name));
|
|
3326
|
+
let mutatesParam = false;
|
|
3327
|
+
walk2(body[0], (n) => {
|
|
3328
|
+
if (!Array.isArray(n)) return;
|
|
3329
|
+
if ((n[0] === "local.set" || n[0] === "local.tee") && paramNames.has(n[1])) {
|
|
3330
|
+
mutatesParam = true;
|
|
3331
|
+
}
|
|
3332
|
+
});
|
|
3333
|
+
if (!mutatesParam) {
|
|
3334
|
+
inlinable.set(name2, { body: body[0], params });
|
|
3335
|
+
}
|
|
3312
3336
|
}
|
|
3313
3337
|
}
|
|
3314
3338
|
if (inlinable.size === 0) return result;
|
package/dist/watr.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var Gt=Object.defineProperty;var Kt=(t,e)=>{for(var
|
|
2
|
-
`?(i++,r=1):r++;t+=` at ${i}:${r}`}throw Error(t)};var kt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Bt=/^[+-]?(?:0x[\da-f]+|\d+)$/i,Xt=new TextEncoder,Jt=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),Nt={n:10,r:13,t:9,'"':34,"'":39,"\\":92},lt=t=>{let e=[],i=1,r,s,l="",a=()=>(l&&e.push(...Xt.encode(l)),l="");for(;i<t.length-1;)s=t[i++],r=null,s==="\\"&&(t[i]==="u"?(i++,i++,s=String.fromCodePoint(parseInt(t.slice(i,i=t.indexOf("}",i)),16)),i++):Nt[t[i]]?r=Nt[t[i++]]:isNaN(r=parseInt(t[i]+t[i+1],16))?s+=t[i]:(i++,i++)),r!=null?(a(),e.push(r)):l+=s;return a(),e.valueOf=()=>t,e},Mt=t=>Jt.decode(new Uint8Array(lt(t)));var y=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):D.parse(t)),typeof t=="bigint"){for(;;){let r=Number(t&0x7Fn);if(t>>=7n,t===0n){e.push(r);break}e.push(r|128)}return e}let i=t&127;return t>>>=7,t===0?(e.push(i),e):(e.push(i|128),y(t,e))};function Zt(t){let e=[];for(let i=0;i<5;i++){let r=t&127;t>>>=7,i<4&&(r|=128),e.push(r)}return e}function D(t,e=[]){for(typeof t=="string"&&(t=D.parse(t));;){let i=Number(t&127);if(t>>=7,t===0&&!(i&64)||t===-1&&i&64){e.push(i);break}e.push(i|128)}return e}var zt=t=>!kt.test(t)&&Bt.test(t=t.replaceAll("_",""))?t:$(`Bad int ${t}`),Qt=D,te=D;D.parse=t=>(t=parseInt(zt(t)),(t<-2147483648||t>4294967295)&&$("i32 constant out of range"),t);function K(t,e=[]){for(typeof t=="string"?t=K.parse(t):typeof t=="bigint"&&t>0x7fffffffffffffffn&&(t=t-0x10000000000000000n);;){let i=Number(t&0x7Fn);if(t>>=7n,t===0n&&!(i&64)||t===-1n&&i&64){e.push(i);break}e.push(i|128)}return e}K.parse=t=>(t=zt(t),t=t[0]==="-"?-BigInt(t.slice(1)):BigInt(t),(t<-0x8000000000000000n||t>0xffffffffffffffffn)&&$("i64 constant out of range"),E.setBigInt64(0,t),E.getBigInt64(0));var E=new DataView(new Float64Array(1).buffer),ee=2147483648,ie=2139095040;function et(t,e,i){return typeof t=="string"&&~(i=t.indexOf("nan:"))?(e=D.parse(t.slice(i+4)),e|=ie,t[0]==="-"&&(e|=ee),E.setInt32(0,e)):(e=typeof t=="string"?et.parse(t):t,E.setFloat32(0,e)),[E.getUint8(3),E.getUint8(2),E.getUint8(1),E.getUint8(0)]}var re=0x8000000000000000n,se=0x7ff0000000000000n;function X(t,e,i){return typeof t=="string"&&~(i=t.indexOf("nan:"))?(e=K.parse(t.slice(i+4)),e|=se,t[0]==="-"&&(e|=re),E.setBigInt64(0,e)):(e=typeof t=="string"?X.parse(t):t,E.setFloat64(0,e)),[E.getUint8(7),E.getUint8(6),E.getUint8(5),E.getUint8(4),E.getUint8(3),E.getUint8(2),E.getUint8(1),E.getUint8(0)]}X.parse=(t,e=Number.MAX_VALUE)=>{t=t.replaceAll("_","");let i=1;if(t[0]==="-"?(i=-1,t=t.slice(1)):t[0]==="+"&&(t=t.slice(1)),t[1]==="x"){let[r,s="0"]=t.split(/p/i),[l,a=""]=r.split("."),n=a.length??0,o=parseInt(l);isNaN(o)&&$();let f=a?parseInt("0x"+a)/16**n:0;s=parseInt(s,10);let c=i*(o+f)*2**s;return c=Math.max(-e,Math.min(e,c)),c}return t.includes("nan")?i<0?NaN:NaN:t.includes("inf")?i*(1/0):i*parseFloat(t)};et.parse=t=>X.parse(t,34028234663852886e22);var it=["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",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,["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.cast reftype","","br_on_cast reftype2","br_on_cast_fail reftype2","any.convert_extern","extern.convert_any","ref.i31","i31.get_s","i31.get_u"],["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"],["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"]],B={custom:0,type:1,import:2,func:3,table:4,memory:5,tag:13,global:6,export:7,start:8,elem:9,datacount:12,code:10,data:11},q={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,nullfuncref:115,nullexternref:114,nullexnref:116,nullref:113,funcref:112,externref:111,exnref:105,anyref:110,eqref:109,i31ref:108,structref:107,arrayref:106,ref:100,refnull:99,sub:80,subfinal:79,rec:78},Ut={func:96,struct:95,array:94,sub:80,subfinal:79,rec:78},xt={func:0,table:1,memory:2,global:3,tag:4};var L=t=>{let e=0,i=[],r="",s=0,l=0,a=()=>r&&(i.push(r),r=""),n=o=>{i.i=o;for(let f,c,m;e<t.length;)if(f=t.charCodeAt(e),s===34)r+=t[e++],f===92?r+=t[e++]:f===34&&(a(),s=0);else if(s>59)f===40&&t.charCodeAt(e+1)===59?(s++,r+=t[e++]+t[e++]):f===59&&t.charCodeAt(e+1)===41?(r+=t[e++]+t[e++],--s===59&&(a(),s=0)):r+=t[e++];else if(s<0)f===10||f===13?(r+=t[e++],a(),s=0):r+=t[e++];else if(f===34)r!=="$"&&a(),s=34,r+=t[e++];else if(f===40&&t.charCodeAt(e+1)===59)a(),s=60,r=t[e++]+t[e++];else if(f===59&&t.charCodeAt(e+1)===59)a(),s=-1,r=t[e++]+t[e++];else if(f===40&&t.charCodeAt(e+1)===64)a(),m=e,e+=2,r="@",l++,(c=i).push(i=[]),n(m),i=c;else if(f===40)a(),m=e++,l++,(c=i).push(i=[]),n(m),i=c;else{if(f===41)return a(),e++,l--;f<=32?(a(),e++):r+=t[e++]}s<0&&a(),a()};return n(0),s===34&&$("Unclosed quote",e),s>59&&$("Unclosed block comment",e),l>0&&$("Unclosed parenthesis",e),e<t.length&&$("Unexpected closing parenthesis",e),i.length>1?i:i[0]||[]};var qt=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(qt).filter(i=>i!=null),e.i=t.i,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("\\")?"$"+Mt(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?lt(t):t;function Q(t){typeof t=="string"?($.src=t,t=L(t)||[]):$.src="",$.i=0,t=qt(t)||[];let e=0;if(t[0]==="module"?(e++,O(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return Q(t.slice(++e).map(l=>l.valueOf().slice(1,-1)).flat().join(""));let i=[];for(let l in B)(i[B[l]]=i[l]=[]).name=l;i.metadata={},t.slice(e).filter(l=>{if(!Array.isArray(l)){let o=$.src?.indexOf(l,$.i);o>=0&&($.i=o),$(`Unexpected token ${l}`)}let[a,...n]=l;if($.i=l.i,a==="@custom")i.custom.push(n);else if(a==="rec")for(let o=0;o<n.length;o++){let[,...f]=n[o];ht(f,i.type),(f=Tt(f,i)).push(o?!0:[i.type.length,n.length]),i.type.push(f)}else if(a==="type")ht(n,i.type),i.type.push(Tt(n,i));else if(a==="start"||a==="export")i[a].push(n);else return!0}).forEach(l=>{let[a,...n]=l;$.i=l.i;let o;a==="import"&&([a,...n]=(o=n).pop());let f=i[a];for(f||$(`Unknown section ${a}`),ht(n,f);n[0]?.[0]==="export";)i.export.push([n.shift()[1],[a,f?.length]]);if(n[0]?.[0]==="import"&&([,...o]=n.shift()),a==="table"){let c=n[0]==="i64",m=c?1:0;if(n[m+1]?.[0]==="elem"){let[x,[,...g]]=[n[m],n[m+1]];n=c?["i64",g.length,g.length,x]:[g.length,g.length,x],i.elem.push([["table",f.length],["offset",[c?"i64.const":"i32.const",c?0n:0]],x,...g])}}else if(a==="memory"){let c=n[0]==="i64",m=c?1:0;if(n[m]?.[0]==="data"){let[,...x]=n.splice(m,1)[0],g=""+Math.ceil(x.reduce((I,p)=>I+p.length,0)/65536);i.data.push([["memory",f.length],[c?"i64.const":"i32.const",c?0n:0],...x]),n=c?["i64",g,g]:[g,g]}}else if(a==="func"){let[c,m,x]=_t(n,i);c??=ut(m,x,i),!o&&i.code.push([[c,m,x],...V(n,i)]),n=[["type",c]]}else if(a==="tag"){let[c,m]=_t(n,i);c??=ut(m,[],i),n=[["type",c]]}o&&(i.import.push([...o,[a,...n]]),n=null),f.push(n)});let r=(l,a=!0)=>{let n=i[l].filter(Boolean).map(o=>At[l](o,i)).filter(Boolean);return l===B.custom?n.flatMap(o=>[l,...k(o)]):n.length?[l,...k(a?k(n):n)]:[]},s=()=>{let l=[];for(let a in i.metadata){let n=k(lt(`"metadata.code.${a}"`)),o=k(i.metadata[a].map(([f,c])=>[...y(f),...k(c.map(([m,x])=>[...y(m),...k(x)]))]));l.push(0,...k([...n,...o]))}return l};return Uint8Array.from([0,97,115,109,1,0,0,0,...r(B.custom),...r(B.type),...r(B.import),...r(B.func),...r(B.table),...r(B.memory),...r(B.tag),...r(B.global),...r(B.export),...r(B.start,!1),...r(B.elem),...r(B.datacount,!1),...r(B.code),...s(),...r(B.data)])}var C=t=>t?.[0]==="$"||!isNaN(t),O=t=>t?.[0]==="$",dt=t=>t?.[0]==="a"||t?.[0]==="o";function V(t,e){let i=[];for(t=[...t];t.length;){let r=t.shift();if(typeof r=="string")if(i.push(r),r==="block"||r==="if"||r==="loop")O(t[0])&&i.push(t.shift()),i.push(nt(t,e));else if(r==="else"||r==="end")O(t[0])&&t.shift();else if(r==="select")i.push(mt(t)[1]);else if(r.endsWith("call_indirect")){let s=C(t[0])?t.shift():0,[l,a,n]=_t(t,e);i.push(s,["type",l??ut(a,n,e)])}else r==="table.init"?i.push(C(t[1])?t.shift():0,t.shift()):r==="table.copy"||r==="memory.copy"?i.push(C(t[0])?t.shift():0,C(t[0])?t.shift():0):r.startsWith("table.")?i.push(C(t[0])?t.shift():0):r==="memory.init"?(i.push(...C(t[1])?[t.shift(),t.shift()].reverse():[t.shift(),0]),e.datacount&&(e.datacount[0]=!0)):r==="data.drop"||r==="array.new_data"||r==="array.init_data"?(r==="data.drop"&&i.push(t.shift()),e.datacount&&(e.datacount[0]=!0)):(r.startsWith("memory.")||r.endsWith("load")||r.endsWith("store"))&&C(t[0])&&i.push(t.shift());else if(Array.isArray(r)){let s=r[0];if(r.i!=null&&($.i=r.i),s?.startsWith?.("@metadata.code.")){let a=s.slice(15);i.push(["@metadata",a,r[1]]);continue}if(typeof s!="string"||!Array.isArray(it[s])){i.push(r);continue}let l=r.slice(1);if(s==="block"||s==="loop")i.push(s),O(l[0])&&i.push(l.shift()),i.push(nt(l,e),...V(l,e),"end");else if(s==="if"){let a=[],n=[];l.at(-1)?.[0]==="else"&&(n=V(l.pop().slice(1),e)),l.at(-1)?.[0]==="then"&&(a=V(l.pop().slice(1),e));let o=[s];O(l[0])&&o.push(l.shift()),o.push(nt(l,e)),i.push(...V(l,e),...o,...a),n.length&&i.push("else",...n),i.push("end")}else if(s==="try_table"){for(i.push(s),O(l[0])&&i.push(l.shift()),i.push(nt(l,e));l[0]?.[0]==="catch"||l[0]?.[0]==="catch_ref"||l[0]?.[0]==="catch_all"||l[0]?.[0]==="catch_all_ref";)i.push(l.shift());i.push(...V(l,e),"end")}else{let a=[];for(;l.length&&(!Array.isArray(l[0])||"type,param,result,ref".includes(l[0][0]));)a.push(l.shift());i.push(...V(l,e),s,...a),t.unshift(...i.splice(i.length-1-a.length))}}else i.push(r)}return i}var ut=(t,e,i,r="$"+t+">"+e)=>(i.type[r]??=i.type.push(["func",[t,e]])-1,r),bt=(t,e)=>{let i=[];for(;t[0]?.[0]===e;){let[,...r]=t.shift(),s=O(r[0])&&r.shift();s&&(s in i?(()=>{throw Error(`Duplicate ${e} ${s}`)})():i[s]=i.length),i.push(...r)}return i},mt=t=>{let e=bt(t,"param"),i=bt(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,i]},_t=(t,e)=>{if(t[0]?.[0]!=="type")return[,...mt(t)];let[,i]=t.shift(),[r,s]=mt(t),l=e.type[typeof i=="string"&&isNaN(i)?e.type[i]:+i];if(!l)throw Error(`Unknown type ${i}`);if((r.length||s.length)&&l[1].join(">")!==r+">"+s)throw Error(`Type ${i} mismatch`);return[i,...l[1]]},nt=(t,e)=>{let[i,r,s]=_t(t,e);if(!(!r.length&&!s.length))return!r.length&&s.length===1?["result",...s]:["type",i??ut(r,s,e)]},ht=(t,e)=>{let i=O(t[0])&&t.shift();return i&&(i in e?$(`Duplicate ${e.name} ${i}`):e[i]=e.length),i},Tt=([t],e)=>{let i="subfinal",r=[],s;return t[0]==="sub"&&(i=t.shift(),t[0]==="final"&&(i+=t.shift()),t=(r=t).pop()),[s,...t]=t,s==="func"?(t=mt(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=bt(t,"field"):s==="array"&&([t]=t),[s,t,i,r]},At=[([t,...e],i)=>{let r=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(r=e.slice(1)),[...k(t),...r.flat()]},([t,e,i,r,s],l)=>{if(s===!0)return;let a;if(s){t="rec";let[n,o]=s,f=Array.from({length:o},(c,m)=>At[B.type](l.type[n+m].slice(0,4),l));a=k(f)}else i==="sub"||r?.length?(a=[...k(r.map(n=>A(n,l.type))),...At[B.type]([t,e],l)],t=i):t==="func"?a=[...k(e[0].map(n=>W(n,l))),...k(e[1].map(n=>W(n,l)))]:t==="array"?a=at(e,l):t==="struct"&&(a=k(e.map(n=>at(n,l))));return[Ut[t],...a]},([t,e,[i,...r]],s)=>{let l;if(i==="func"){let[[,a]]=r;l=y(A(a,s.type))}else if(i==="tag"){let[[,a]]=r;l=[0,...y(A(a,s.type))]}else i==="memory"?l=ft(r):i==="global"?l=at(r[0],s):i==="table"?l=[...W(r.pop(),s),...ft(r)]:$(`Unknown kind ${i}`);return[...k(t),...k(e),xt[i],...l]},([[,t]],e)=>y(A(t,e.type)),(t,e)=>{let i=ft(t),r=W(t.shift(),e),[s]=t;return s?[64,0,...r,...i,...Z(s,e)]:[...r,...i]},(t,e)=>ft(t),([t,e],i)=>[...at(t,i),...Z(e,i)],([t,[e,i]],r)=>[...k(t),xt[e],...y(A(i,r[e]))],([t],e)=>y(A(t,e.func)),(t,e)=>{let i=0,r=0,s=0,l=0,a,n,o;t[0]==="declare"&&(t.shift(),r=1),t[0]?.[0]==="table"?([,a]=t.shift(),a=A(a,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"))&&(a=A(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(n=t.shift(),n[0]==="offset"&&([,n]=n),n=Z(n,e)):r||(i=1),q[t[0]]||t[0]?.[0]==="ref"?o=W(t.shift(),e):t[0]==="func"?o=[q[t.shift()]]:o=[q.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]!==q.funcref&&(l=1,s=1);let f=s<<2|(i||r?r:!!a||l)<<1|(i||r);return[f,...f===0?n:f===1?[0]:f===2?[...y(a||0),...n,0]:f===3?[0]:f===4?n:f===5?o:f===6?[...y(a||0),...n,...o]:o,...k(t.map(s?c=>Z(typeof c=="string"?["ref.func",c]:c,e):c=>y(A(c,e.func))))]},(t,e)=>{let[i,r]=t.shift();r||([,[r]]=e.type[A(i,e.type)]),e.local=Object.create(r),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(O(o[0])){let f=o.shift();f in e.local?$(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...o)}e.meta={};let l=Ot(t,e),a=e.import.filter(o=>o[2][0]==="func").length+s;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([a,e.meta[o]]);let n=e.local.slice(r.length).reduce((o,f)=>(f==o[o.length-1]?.[1]?o[o.length-1][0]++:o.push([1,f]),o),[]);return e.local=e.block=e.meta=null,k([...k(n.map(([o,f])=>[...y(o),...W(f,e)])),...l])},(t,e)=>{let i,r=0;return t[0]?.[0]==="memory"?([,r]=t.shift(),r=A(r,e.memory)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&typeof t[1][0]=="string")&&(r=A(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(i=t.shift(),i[0]==="offset"&&([,i]=i),i??$("Bad offset",i)),[...r?[2,...y(r),...Z(i,e)]:i?[0,...Z(i,e)]:[1],...k(t.flat())]},(t,e)=>y(e.data.length),([[,t]],e)=>[0,...y(A(t,e.type))]],W=(t,e)=>t[0]==="ref"?t[1]=="null"?q[t[2]]?[q[t[2]]]:[q.refnull,...y(A(t[t.length-1],e.type))]:[q.ref,...y(q[t[t.length-1]]||A(t[t.length-1],e.type))]:[q[t]??$(`Unknown type ${t}`)],at=(t,e,i=t[0]==="mut"?1:0)=>[...W(i?t[1]:t,e),i],St={null:()=>[],reversed:(t,e)=>{let i=t.shift(),r=t.shift();return[...y(A(r,e.elem)),...y(A(i,e.table))]},block:(t,e)=>{e.block.push(1),O(t[0])&&(e.block[t.shift()]=e.block.length);let i=t.shift();return i?i[0]==="result"?W(i[1],e):y(A(i[1],e.type)):[q.void]},try_table:(t,e)=>{O(t[0])&&(e.block[t.shift()]=e.block.length+1);let i=t.shift(),r=i?i[0]==="result"?W(i[1],e):y(A(i[1],e.type)):[q.void],s=[],l=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let a=t.shift(),n=a[0]==="catch"?0:a[0]==="catch_ref"?1:a[0]==="catch_all"?2:3;n<=1?s.push(n,...y(A(a[1],e.tag)),...y(rt(a[2],e.block))):s.push(n,...y(rt(a[1],e.block))),l++}return e.block.push(1),[...r,...y(l),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let i=t.shift(),[,r]=t.shift();return[...y(A(r,e.type)),...y(A(i,e.table))]},br_table:(t,e)=>{let i=[],r=0;for(;t[0]&&(!isNaN(t[0])||O(t[0]));)i.push(...y(rt(t.shift(),e.block))),r++;return[...y(r-1),...i]},select:(t,e)=>{let i=t.shift()||[];return i.length?k(i.map(r=>W(r,e))):[]},ref_null:(t,e)=>{let i=t.shift();return q[i]?[q[i]]:y(A(i,e.type))},memarg:(t,e,i)=>Et(t,i,C(t[0])&&!dt(t[0])?A(t.shift(),e.memory):0),opt_memory:(t,e)=>y(A(C(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let i=W(t.shift(),e);return i.length>1?i.slice(1):i},reftype2:(t,e)=>{let i=rt(t.shift(),e.block),r=W(t.shift(),e),s=W(t.shift(),e);return[(s[0]!==q.ref)<<1|r[0]!==q.ref,...y(i),r.pop(),s.pop()]},v128const:t=>{let[e,i]=t.shift().split("x"),r=+e.slice(1),s=r>>>3;if(i=+i,e[0]==="i"){let a=i===16?new Uint8Array(16):i===8?new Uint16Array(8):i===4?new Uint32Array(4):new BigUint64Array(2);for(let n=0;n<i;n++)a[n]=J[e].parse(t.shift());return[...new Uint8Array(a.buffer)]}let l=new Uint8Array(16);for(let a=0;a<i;a++)l.set(J[e](t.shift()),a*s);return[...l]},shuffle:t=>{let e=[];for(let i=0;i<16;i++)e.push(ct(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&$("invalid lane length"),e},memlane:(t,e,i)=>{let r=O(t[0])||C(t[0])&&(dt(t[1])||C(t[1]))?A(t.shift(),e.memory):0;return[...Et(t,i,r),...y(ct(t.shift()))]},"*":t=>y(t.shift()),labelidx:(t,e)=>y(rt(t.shift(),e.block)),laneidx:t=>[ct(t.shift(),255)],funcidx:(t,e)=>y(A(t.shift(),e.func)),typeidx:(t,e)=>y(A(t.shift(),e.type)),tableidx:(t,e)=>y(A(t.shift(),e.table)),memoryidx:(t,e)=>y(A(t.shift(),e.memory)),globalidx:(t,e)=>y(A(t.shift(),e.global)),localidx:(t,e)=>y(A(t.shift(),e.local)),dataidx:(t,e)=>y(A(t.shift(),e.data)),elemidx:(t,e)=>y(A(t.shift(),e.elem)),tagidx:(t,e)=>y(A(t.shift(),e.tag)),"memoryidx?":(t,e)=>y(A(C(t[0])?t.shift():0,e.memory)),i32:t=>D(t.shift()),i64:t=>K(t.shift()),f32:t=>et(t.shift()),f64:t=>X(t.shift()),v128:t=>(void 0)(t.shift()),typeidx_field:(t,e)=>{let i=A(t.shift(),e.type);return[...y(i),...y(A(t.shift(),e.type[i][1]))]},typeidx_multi:(t,e)=>[...y(A(t.shift(),e.type)),...y(t.shift())],typeidx_dataidx:(t,e)=>[...y(A(t.shift(),e.type)),...y(A(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...y(A(t.shift(),e.type)),...y(A(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...y(A(t.shift(),e.type)),...y(A(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...y(A(t.shift(),e.data)),...y(A(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...y(A(t.shift(),e.memory)),...y(A(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...y(A(t.shift(),e.table)),...y(A(t.shift(),e.table))]},ot={};(function t(e,i){for(let r=0,s,l,a;r<e.length;r++)(s=e[r])&&(Array.isArray(s)?t(s,r):([l,a]=s.split(" "),it[l]=i?[i,...y(r)]:[r],a&&(ot[l]=St[a])))})(it);var Ot=(t,e)=>{let i=[],r=[];for(;t?.length;){let s=t.shift();if(s?.[0]==="@metadata"){r.push(s.slice(1));continue}Array.isArray(s)&&(s.i!=null&&($.i=s.i),$(`Unknown instruction ${s[0]}`));let[...l]=it[s]||$(`Unknown instruction ${s}`);ot[s]&&(s==="select"&&t[0]?.length?l[0]++:ot[s]===St.reftype&&(t[0][1]==="null"||t[0][0]!=="ref")&&l[l.length-1]++,l.push(...ot[s](t,e,s)));for(let[a,n]of r)(e.meta[a]??=[]).push([i.length,n]);i.push(...l)}return i.push(11),i},Z=(t,e)=>Ot(V([t],e),e),A=(t,e,i)=>(i=O(t)?e[t]:+t,i in e?i:$(`Unknown ${e.name} ${t}`)),rt=(t,e,i)=>(i=O(t)?e.length-e[t]:+t,isNaN(i)||i>e.length?$(`Bad label ${t}`):i),le=t=>{let e,i,r,s;for(;dt(t[0]);)[r,s]=t.shift().split("="),r==="offset"?i=+s:r==="align"?e=+s:$(`Unknown param ${r}=${s}`);return(i<0||i>4294967295)&&$(`Bad offset ${i}`),(e<=0||e>4294967295)&&$(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&$(`Bad align ${e}`),[e,i]},Et=(t,e,i=0)=>{let[r,s]=le(t),l=(r??ne(e))|(i&&64);return i?[...y(l),...y(i),...y(s??0)]:[...y(l),...y(s??0)]},ne=t=>{let e=t.indexOf(".",3)+1,i=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 l=t.slice(e,e+6).match(/\d+/);return Math.log2(l?l[0]/8:+i/8)}let r=t[e]==="l"?e+4:e+5,s=t.slice(r).match(/(\d+)(x|_|$)/);return Math.log2(s?s[2]==="x"?8:s[1]/8:+i/8)},ft=t=>{let e=t[0]==="i64"&&t.shift(),i=t[t.length-1]==="shared"&&t.pop(),r=!isNaN(parseInt(t[1])),s=(e?4:0)|(i?2:0)|(r?1:0),l=e?a=>{if(typeof a=="bigint")return a;let n=typeof a=="string"?a.replaceAll("_",""):String(a);return BigInt(n)}:ct;return r?[s,...y(l(t.shift())),...y(l(t.shift()))]:[s,...y(l(t.shift()))]},ct=(t,e=4294967295)=>{let i=typeof t=="string"&&t[0]!=="+"?D.parse(t):typeof t=="number"?t:$(`Bad int ${t}`);return i>e?$(`Value out of range ${t}`):i},k=t=>[...y(t.length),...t.flat()];function Ft(t,e={}){typeof t=="string"&&(t=L(t));let{indent:i=" ",newline:r=`
|
|
3
|
-
`,comments:s=!0}=e;if(
|
|
4
|
-
`}else{let p=f[f.length-1];p&&p!==" "&&p!=="("&&(f+=" "),f+=I.trimEnd()}}else if(Array.isArray(I))
|
|
5
|
-
`?f+="":(p&&p!==")"&&p!==" "||r||p===")")&&(f+=" "),f+=I,c=!1}}return m?`(${f.replaceAll(r+x+"("," (")})`:`(${f+r+i.repeat(o)})`}}var Lt={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(Lt),ae=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(i=>[i,e.has(i)||e.has("all")]))}return{...t}},S=(t,e,i,r)=>{if(e(t,i,r),Array.isArray(t))for(let s=0;s<t.length;s++)S(t[s],e,t,s)},P=(t,e,i,r)=>{if(Array.isArray(t))for(let s=0;s<t.length;s++)P(t[s],e,t,s);e(t,i,r)},fe=t=>{let e=new Set;return S(t,i=>{if(typeof i=="string")for(let[r,s]of Object.entries(Lt))s.some(l=>i===l||i.startsWith(l+" "))&&e.add(r)}),S(t,i=>{if(!(!Array.isArray(i)||i[0]!=="global"))for(let r of i)Array.isArray(r)&&(r[0]==="i32.add"||r[0]==="i32.sub"||r[0]==="i32.mul"||r[0]==="i64.add"||r[0]==="i64.sub"||r[0]==="i64.mul")&&S(r,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),S(t,i=>{if(!Array.isArray(i)||i[0]!=="func")return;let r=0;for(let s of i)Array.isArray(s)&&s[0]==="result"&&(r+=s.length-1);r>1&&e.add("multi_value")}),e},Ct=t=>Array.isArray(t)?t.map(Ct):t,Dt=(t,e)=>{let i=[],r=t[0]==="module"?1:0;for(let s=r;s<t.length;s++)Array.isArray(t[s])&&t[s][0]===e&&i.push({node:t[s],idx:s});return i},pt=(t,e,i)=>t.splice(e,0,i),oe=0,R=t=>`$__${t}${oe++}`,ce=(t,e)=>{let i=new Set;if(S(t,f=>{Array.isArray(f)&&f[0]==="ref.func"&&i.add(f[1])}),!i.size)return t;let r=R("fntbl"),s=[...i],l=Object.fromEntries(s.map((f,c)=>[f,c])),a=Dt(t,"func"),n=a.length?a[0].idx:t[0]==="module"?1:0;pt(t,n,["table",r,"funcref",["elem",...s]]);let o={};return S(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c)return;let m=[],x=[];for(let g of f){if(Array.isArray(g)&&g[0]==="param")for(let I=1;I<g.length;I++)g[I][0]!=="$"&&m.push(g[I]);if(Array.isArray(g)&&g[0]==="result")for(let I=1;I<g.length;I++)x.push(g[I])}o[c]={params:m,results:x}}),P(t,(f,c,m)=>{if(!(!Array.isArray(f)||!c)){if(f[0]==="ref.func"&&l[f[1]]!==void 0&&(c[m]=["i32.const",l[f[1]]]),f[0]==="call_ref"){let x=f[1],g=f.slice(2);c[m]=["call_indirect",r,["type",x],...g]}if(f[0]==="return_call_ref"){let x=f[1],g=f.slice(2);c[m]=["return_call_indirect",r,["type",x],...g]}}}),t},j={funcref:ce},ue={"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]},me=(t,e)=>(P(t,(i,r,s)=>{if(!Array.isArray(i)||!r)return;let l=ue[i[0]];if(!l)return;let[a,n]=l,o=i.slice(1);r[s]=[`${a}.shr_s`,[`${a}.shl`,...o,[`${a}.const`,n]],[`${a}.const`,n]]}),t);j.sign_ext=me;var Wt={"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}},_e=(t,e)=>{let i=new Set;if(S(t,s=>{Array.isArray(s)&&Wt[s[0]]&&i.add(s[0])}),!i.size)return t;let r={};for(let s of i){let{itype:l,ftype:a,signed:n,min:o,max:f}=Wt[s],c=R(`trunc_${l}_${a}_${n?"s":"u"}`);r[s]=c;let m=`${l}.trunc_${a}_${n?"s":"u"}`,x=l==="i64"?0n:0,g=["func",c,["param","$v",a],["result",l],["if",["result",l],[`${a}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${l}.const`,x]],["else",["if",["result",l],[`${a}.lt`,["local.get","$v"],[`${a}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${l}.const`,o]],["else",["if",["result",l],[`${a}.gt`,["local.get","$v"],[`${a}.const`,typeof f=="bigint"?Number(f):f]],["then",[`${l}.const`,f]],["else",[m,["local.get","$v"]]]]]]]]];t.push(g)}return P(t,(s,l,a)=>{!Array.isArray(s)||!l||r[s[0]]&&(l[a]=["call",r[s[0]],...s.slice(1)])}),t};j.nontrapping=_e;var pe=(t,e)=>{let i=new Set,r=new Set;S(t,a=>{if(Array.isArray(a)){if(a[0]==="memory.copy"){let n=typeof a[1]=="number"?a[1]:0,o=typeof a[2]=="number"?a[2]:0;i.add(`${n}_${o}`)}if(a[0]==="memory.fill"){let n=typeof a[1]=="number"?a[1]:0;r.add(n)}}});let s={},l={};for(let a of i){let[n,o]=a.split("_").map(Number),f=R(`memcpy${a==="0_0"?"":"_"+a}`);s[a]=f;let c=n?["i32.store8",n]:["i32.store8"],m=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",f,["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 a of r){let n=R(`memset${a===0?"":"_"+a}`);l[a]=n;let o=a?["i32.store8",a]:["i32.store8"];t.push(["func",n,["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 P(t,(a,n,o)=>{if(!(!Array.isArray(a)||!n)){if(a[0]==="memory.copy"){let f=typeof a[1]=="number"?a[1]:0,c=typeof a[2]=="number"?a[2]:0,m=a.filter(x=>Array.isArray(x)||typeof x=="string"&&x[0]==="$");n[o]=["call",s[`${f}_${c}`],...m]}if(a[0]==="memory.fill"){let f=typeof a[1]=="number"?a[1]:0,c=a.filter(m=>Array.isArray(m)||typeof m=="string"&&m[0]==="$");n[o]=["call",l[f],...c]}}}),t};j.bulk_memory=pe;var ye=(t,e)=>{let i=!1;return S(t,r=>{Array.isArray(r)&&(r[0]==="return_call"||r[0]==="return_call_indirect")&&(i=!0)}),i&&P(t,(r,s,l)=>{!Array.isArray(r)||!s||(r[0]==="return_call"&&(s[l]=["return",["call",...r.slice(1)]]),r[0]==="return_call_indirect"&&(s[l]=["return",["call_indirect",...r.slice(1)]]))}),t};j.return_call=ye;var ge=(t,e)=>(P(t,(i,r,s)=>{if(!(!Array.isArray(i)||!r)&&(i[0]==="ref.i31"&&(r[s]=["i32.and",...i.slice(1),["i32.const",2147483647]]),i[0]==="i31.get_u"&&(r[s]=i.length>1?i[1]:["drop"]),i[0]==="i31.get_s")){let l=i.slice(1);r[s]=["i32.shr_s",["i32.shl",...l,["i32.const",1]],["i32.const",1]]}}),t);j.i31ref=ge;var xe=(t,e)=>{let i={};S(t,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let l=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(l)for(let a=s.length-1;a>=0;a--){let n=s[a];if(Array.isArray(n)&&(n[0]==="i32.const"||n[0]==="i64.const"||n[0]==="f32.const"||n[0]==="f64.const")){i[l]={type:n[0].split(".")[0],value:n[1]};break}}});let r=s=>{if(!Array.isArray(s))return s;let l=s[0];if(l==="global.get"&&i[s[1]]){let a=i[s[1]];return[`${a.type}.const`,a.value]}if(l==="i32.add"||l==="i64.add"){let a=r(s[1]),n=r(s[2]);if(a&&n&&a[0]?.endsWith(".const")&&n[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(a[1]):Number(a[1]),c=o==="i64"?BigInt(n[1]):Number(n[1]);return[`${o}.const`,f+c]}}if(l==="i32.sub"||l==="i64.sub"){let a=r(s[1]),n=r(s[2]);if(a&&n&&a[0]?.endsWith(".const")&&n[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(a[1]):Number(a[1]),c=o==="i64"?BigInt(n[1]):Number(n[1]);return[`${o}.const`,f-c]}}if(l==="i32.mul"||l==="i64.mul"){let a=r(s[1]),n=r(s[2]);if(a&&n&&a[0]?.endsWith(".const")&&n[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(a[1]):Number(a[1]),c=o==="i64"?BigInt(n[1]):Number(n[1]);return[`${o}.const`,f*c]}}return s};return P(t,(s,l,a)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!l)){for(let n=2;n<s.length;n++)if(Array.isArray(s[n])){let o=r(s[n]);o!==s[n]&&(s[n]=o)}}}),t};j.extended_const=xe;var he=(t,e)=>{let i=new Map,r=[];if(S(t,n=>{if(!Array.isArray(n)||n[0]!=="func")return;let o=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null,f=[];for(let c of n)if(Array.isArray(c)&&c[0]==="result")for(let m=1;m<c.length;m++)f.push(c[m]);f.length>1&&o&&i.set(o,f)}),!i.size)return t;let s=Math.max(...[...i.values()].map(n=>n.length)),l={};for(let[n,o]of i)for(let f=1;f<o.length;f++){let c=o[f];if(l[c]||(l[c]=[]),l[c].length<f){let m=R(`ret_${c}_${l[c].length}`);l[c].push(m),r.push(["global",m,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let a=t[0]==="module"?1:0;for(let n of r.reverse())pt(t,a,n);return P(t,(n,o,f)=>{if(!Array.isArray(n)||n[0]!=="func")return;let c=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null;if(!c||!i.has(c))return;let m=i.get(c);for(let x=0;x<n.length;x++)if(Array.isArray(n[x])&&n[x][0]==="result"){n[x]=["result",m[0]];break}}),t};j.multi_value=he;var st={i32:4,i64:8,f32:4,f64:8},de=(t,e)=>{let i=new Map,r=new Map,s=1;if(S(t,p=>{if(!Array.isArray(p)||p[0]!=="type")return;let N=typeof p[1]=="string"&&p[1][0]==="$"?p[1]:null;if(N){for(let u of p)if(Array.isArray(u)){if(u[0]==="struct"){let h=[];for(let _ of u)if(Array.isArray(_)&&_[0]==="field"){let b=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:null,d=b?_[2]:_[1],v=Array.isArray(d)&&d[0]==="mut"?d[1]:d;h.push({name:b,type:v})}i.set(N,{kind:"struct",fields:h}),r.set(N,s++)}if(u[0]==="array"){let h=u[1],_=Array.isArray(h)&&h[0]==="mut"?h[1]:h;i.set(N,{kind:"array",elemType:_}),r.set(N,s++)}}}}),!i.size)return t;let l=Dt(t,"memory").length>0,a=R("alloc"),n=R("heap_ptr"),o=t[0]==="module"?1:0;l||pt(t,o,["memory",1]),pt(t,o+1,["global",n,["mut","i32"],["i32.const",1024]]);let f=["func",a,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",n]],["global.set",n,["i32.add",["global.get",n],["local.get","$size"]]],["local.get","$ptr"]];t.push(f);let c=p=>{let N=4;for(let u of p.fields)N+=st[u.type]||4;return N},m=(p,N)=>{let u=4;for(let h=0;h<N;h++)u+=st[p.fields[h].type]||4;return u},x=(p,N)=>{for(let u=0;u<p.fields.length;u++)if(p.fields[u].name===N)return u;return-1},g=0,I=()=>`$__gc_tmp${g++}`;return S(t,p=>{if(!Array.isArray(p)||p[0]!=="func")return;let N=!1,u=!1,h=!1,_=!1;if(S(p,d=>{Array.isArray(d)&&((d[0]==="struct.new"||d[0]==="struct.new_default")&&(N=!0),(d[0]==="array.new"||d[0]==="array.new_default")&&(u=!0,h=!0,_=!0))}),!N&&!u)return;let b=1;for(let d=1;d<p.length;d++){let v=p[d];if(Array.isArray(v)&&(v[0]==="param"||v[0]==="result"||v[0]==="local"||v[0]==="export"||v[0]==="type"))b=d+1;else if(typeof v=="string"&&v[0]==="$")b=d+1;else if(!Array.isArray(v))b=d+1;else break}N&&p.splice(b++,0,["local","$__gc_ptr","i32"]),u&&p.splice(b++,0,["local","$__gc_aptr","i32"]),h&&p.splice(b++,0,["local","$__gc_alen","i32"]),_&&p.splice(b++,0,["local","$__gc_aidx","i32"])}),P(t,(p,N,u)=>{if(!(!Array.isArray(p)||!N)){if(p[0]==="struct.new"||p[0]==="struct.new_default"){let h=p[1],_=i.get(h);if(!_||_.kind!=="struct")return;let b=c(_),d=r.get(h),v=p.slice(2),M="$__gc_ptr",T=[["local.set",M,["call",a,["i32.const",b]]],["i32.store",["local.get",M],["i32.const",d]]];if(p[0]==="struct.new")for(let z=0;z<_.fields.length;z++){let U=_.fields[z],tt=m(_,z),Y=U.type==="i64"?"i64.store":U.type==="f32"?"f32.store":U.type==="f64"?"f64.store":"i32.store";T.push([Y,["i32.add",["local.get",M],["i32.const",tt]],v[z]||[`${U.type}.const`,0]])}else for(let z=0;z<_.fields.length;z++){let U=_.fields[z],tt=m(_,z),Y=U.type==="i64"?"i64.store":U.type==="f32"?"f32.store":U.type==="f64"?"f64.store":"i32.store",Yt=U.type==="i64"?["i64.const",0n]:U.type==="f32"?["f32.const",0]:U.type==="f64"?["f64.const",0]:["i32.const",0];T.push([Y,["i32.add",["local.get",M],["i32.const",tt]],Yt])}T.push(["local.get",M]),N[u]=["block",["result","i32"],...T]}if(p[0]==="struct.get"){let h=p[1],_=p[2],b=p[3],d=i.get(h);if(!d||d.kind!=="struct")return;let v=typeof _=="string"&&_[0]==="$"?x(d,_):parseInt(_);if(v<0)return;let M=d.fields[v],T=m(d,v),z=M.type==="i64"?"i64.load":M.type==="f32"?"f32.load":M.type==="f64"?"f64.load":"i32.load";N[u]=[z,["i32.add",b,["i32.const",T]]]}if(p[0]==="struct.set"){let h=p[1],_=p[2],b=p[3],d=p[4],v=i.get(h);if(!v||v.kind!=="struct")return;let M=typeof _=="string"&&_[0]==="$"?x(v,_):parseInt(_);if(M<0)return;let T=v.fields[M],z=m(v,M),U=T.type==="i64"?"i64.store":T.type==="f32"?"f32.store":T.type==="f64"?"f64.store":"i32.store";N[u]=[U,["i32.add",b,["i32.const",z]],d]}if(p[0]==="array.new"||p[0]==="array.new_default"){let h=p[1],_=i.get(h);if(!_||_.kind!=="array")return;let b=r.get(h),d=st[_.elemType]||4,v=p[0]==="array.new"?p[2]:null,M=p[0]==="array.new"?p[3]:p[2],T="$__gc_aptr",z="$__gc_alen",U="$__gc_aidx",tt=_.elemType==="i64"?"i64.store":_.elemType==="f32"?"f32.store":_.elemType==="f64"?"f64.store":"i32.store",Y=[["local.set",z,M],["local.set",T,["call",a,["i32.add",["i32.const",8],["i32.mul",["local.get",z],["i32.const",d]]]]],["i32.store",["local.get",T],["i32.const",b]],["i32.store",["i32.add",["local.get",T],["i32.const",4]],["local.get",z]]];v&&Y.push(["local.set",U,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",U],["local.get",z]]],[tt,["i32.add",["i32.add",["local.get",T],["i32.const",8]],["i32.mul",["local.get",U],["i32.const",d]]],v],["local.set",U,["i32.add",["local.get",U],["i32.const",1]]],["br","$loop"]]]),Y.push(["local.get",T]),N[u]=["block",["result","i32"],...Y]}if(p[0]==="array.get"){let h=p[1],_=p[2],b=p[3],d=i.get(h);if(!d||d.kind!=="array")return;let v=st[d.elemType]||4,M=d.elemType==="i64"?"i64.load":d.elemType==="f32"?"f32.load":d.elemType==="f64"?"f64.load":"i32.load";N[u]=[M,["i32.add",["i32.add",_,["i32.const",8]],["i32.mul",b,["i32.const",v]]]]}if(p[0]==="array.set"){let h=p[1],_=p[2],b=p[3],d=p[4],v=i.get(h);if(!v||v.kind!=="array")return;let M=st[v.elemType]||4,T=v.elemType==="i64"?"i64.store":v.elemType==="f32"?"f32.store":v.elemType==="f64"?"f64.store":"i32.store";N[u]=[T,["i32.add",["i32.add",_,["i32.const",8]],["i32.mul",b,["i32.const",M]]],d]}if(p[0]==="array.len"){let h=p[1];N[u]=["i32.load",["i32.add",h,["i32.const",4]]]}}}),t};j.gc=de;var be=(t,e)=>{let i=new Map,r=1;return S(t,s=>{if(!Array.isArray(s)||s[0]!=="type")return;let l=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(l)for(let a of s)Array.isArray(a)&&(a[0]==="struct"||a[0]==="array")&&i.set(l,r++)}),i.size&&P(t,(s,l,a)=>{if(!(!Array.isArray(s)||!l)){if(s[0]==="ref.test"){let n=s[1],o=null;Array.isArray(n)&&n[0]==="ref"&&(o=n[1]==="null"?n[2]:n[1]);let f=s[2],c=i.get(o);c!==void 0&&(l[a]=["if",["result","i32"],["i32.eqz",f],["then",["i32.const",0]],["else",["i32.eq",["i32.load",f],["i32.const",c]]]])}if(s[0]==="ref.cast"){let n=s[1],o=null,f=!1;Array.isArray(n)&&n[0]==="ref"&&(n[1]==="null"?(f=!0,o=n[2]):o=n[1]);let c=s[2],m=i.get(o);if(m!==void 0){let x=R("cast");f?l[a]=["block",["result","i32"],["local",x,"i32"],["local.set",x,c],["if",["i32.and",["i32.ne",["local.get",x],["i32.const",0]],["i32.ne",["i32.load",["local.get",x]],["i32.const",m]]],["then",["unreachable"]]],["local.get",x]]:l[a]=["block",["result","i32"],["local",x,"i32"],["local.set",x,c],["if",["i32.or",["i32.eqz",["local.get",x]],["i32.ne",["i32.load",["local.get",x]],["i32.const",m]]],["then",["unreachable"]]],["local.get",x]]}}if(s[0]==="br_on_cast"){let n=s[1],o=s[2],f=s[3],c=s[4],m=null;Array.isArray(f)&&f[0]==="ref"&&(m=f[1]==="null"?f[2]:f[1]);let x=i.get(m);if(x!==void 0){let g=R("brcast");l[a]=["block",["result","i32"],["local",g,"i32"],["local.set",g,c],["br_if",n,["i32.and",["i32.ne",["local.get",g],["i32.const",0]],["i32.eq",["i32.load",["local.get",g]],["i32.const",x]]]],["local.get",g]]}}if(s[0]==="br_on_cast_fail"){let n=s[1],o=s[2],f=s[3],c=s[4],m=null;Array.isArray(f)&&f[0]==="ref"&&(m=f[1]==="null"?f[2]:f[1]);let x=i.get(m);if(x!==void 0){let g=R("brfail");l[a]=["block",["result","i32"],["local",g,"i32"],["local.set",g,c],["br_if",n,["i32.or",["i32.eqz",["local.get",g]],["i32.ne",["i32.load",["local.get",g]],["i32.const",x]]]],["local.get",g]]}}}}),t};j.ref_cast=be;function yt(t,e=!0){typeof t=="string"&&(t=L(t)),t=Ct(t),e=ae(e);let i=fe(t),r={uid:0};for(let s of wt)i.has(s)&&e[s]!==!1&&j[s]&&(t=j[s](t,r));return t}var vt={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!0},$t=Object.keys(vt),Ae=t=>{if(t===!0)return{...vt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.size===1&&$t.includes([...e][0])?Object.fromEntries($t.map(i=>[i,e.has(i)])):Object.fromEntries($t.map(i=>[i,e.has(i)||e.has("all")]))}return{...vt,...t}},F=t=>Array.isArray(t)?t.map(F):t,G=(t,e,i,r)=>{if(e(t,i,r),Array.isArray(t))for(let s=0;s<t.length;s++)G(t[s],e,t,s)},H=(t,e,i,r)=>{if(Array.isArray(t))for(let l=0;l<t.length;l++){let a=H(t[l],e,t,l);a!==void 0&&(t[l]=a)}let s=e(t,i,r);return s!==void 0?s:t},we=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,i=new Map,r=new Map,s=new Map,l=new Map,a=[],n=[],o=0,f=0,c=0,m=0,x=0,g=0;for(let u of t.slice(1)){if(!Array.isArray(u))continue;let h=u[0];if(h==="type"){let _=typeof u[1]=="string"&&u[1][0]==="$"?u[1]:c;r.set(_,{node:u,idx:c,used:!1}),typeof _=="string"&&r.set(c,r.get(_)),c++}else if(h==="func"){let _=typeof u[1]=="string"&&u[1][0]==="$"?u[1]:o,b=u.some(d=>Array.isArray(d)&&d[0]==="export");e.set(_,{node:u,idx:o,used:b}),typeof _=="string"&&e.set(o,e.get(_)),o++}else if(h==="global"){let _=typeof u[1]=="string"&&u[1][0]==="$"?u[1]:f,b=u.some(d=>Array.isArray(d)&&d[0]==="export");i.set(_,{node:u,idx:f,used:b}),typeof _=="string"&&i.set(f,i.get(_)),f++}else if(h==="table"){let _=typeof u[1]=="string"&&u[1][0]==="$"?u[1]:m,b=u.some(d=>Array.isArray(d)&&d[0]==="export");s.set(_,{node:u,idx:m,used:b}),typeof _=="string"&&s.set(m,s.get(_)),m++}else if(h==="memory"){let _=typeof u[1]=="string"&&u[1][0]==="$"?u[1]:x,b=u.some(d=>Array.isArray(d)&&d[0]==="export");l.set(_,{node:u,idx:x,used:b}),typeof _=="string"&&l.set(x,l.get(_)),x++}else if(h==="import"){for(let _ of u)if(Array.isArray(_)&&_[0]==="func"){let b=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:g;e.set(b,{node:u,idx:g,used:!0,isImport:!0}),typeof b=="string"&&e.set(g,e.get(b)),g++,o++}}else h==="export"?a.push(u):h==="start"&&n.push(u)}for(let u of a)for(let h of u){if(!Array.isArray(h))continue;let[_,b]=h;_==="func"&&e.has(b)?e.get(b).used=!0:_==="global"&&i.has(b)?i.get(b).used=!0:_==="table"&&s.has(b)?s.get(b).used=!0:_==="memory"&&l.has(b)&&(l.get(b).used=!0)}for(let u of n){let h=u[1];e.has(h)&&(e.get(h).used=!0)}let I=a.length>0||n.length>0;if(!I){for(let[,u]of e)if(u.used){I=!0;break}if(!I){for(let[,u]of i)if(u.used){I=!0;break}}if(!I){for(let[,u]of s)if(u.used){I=!0;break}}if(!I){for(let[,u]of l)if(u.used){I=!0;break}}}if(!I){for(let[,u]of e)u.used=!0;for(let[,u]of i)u.used=!0;for(let[,u]of s)u.used=!0;for(let[,u]of l)u.used=!0}for(let u of t.slice(1))!Array.isArray(u)||u[0]!=="elem"||G(u,h=>{if(Array.isArray(h)&&h[0]==="ref.func"){let _=h[1];e.has(_)&&(e.get(_).used=!0)}typeof h=="string"&&h[0]==="$"&&e.has(h)&&(e.get(h).used=!0)});let p=!0;for(;p;){p=!1;for(let[,u]of e)!u.used||u.isImport||G(u.node,h=>{if(!Array.isArray(h)){typeof h=="string"&&h[0]==="$"&&e.has(h)&&!e.get(h).used&&(e.get(h).used=!0,p=!0);return}let[_,b]=h;if((_==="call"||_==="return_call"||_==="ref.func")&&e.has(b)&&!e.get(b).used&&(e.get(b).used=!0,p=!0),(_==="global.get"||_==="global.set")&&i.has(b)&&!i.get(b).used&&(i.get(b).used=!0,p=!0),_==="call_indirect"||_==="return_call_indirect")for(let d of h)typeof d=="string"&&d[0]==="$"&&s.has(d)&&!s.get(d).used&&(s.get(d).used=!0,p=!0);_==="type"&&r.has(b)&&!r.get(b).used&&(r.get(b).used=!0,p=!0)})}let N=["module"];for(let u of t.slice(1)){if(!Array.isArray(u)){N.push(u);continue}let h=u[0];if(h==="func"){let _=typeof u[1]=="string"&&u[1][0]==="$"?u[1]:null;(_?e.get(_):[...e.values()].find(d=>d.node===u))?.used&&N.push(u)}else if(h==="global"){let _=typeof u[1]=="string"&&u[1][0]==="$"?u[1]:null;(_?i.get(_):[...i.values()].find(d=>d.node===u))?.used&&N.push(u)}else N.push(u)}return N},$e={"i32.add":(t,e)=>t+e|0,"i32.sub":(t,e)=>t-e|0,"i32.mul":(t,e)=>Math.imul(t,e),"i32.div_s":(t,e)=>e!==0?t/e|0:null,"i32.div_u":(t,e)=>e!==0?(t>>>0)/(e>>>0)|0:null,"i32.rem_s":(t,e)=>e!==0?t%e|0:null,"i32.rem_u":(t,e)=>e!==0?(t>>>0)%(e>>>0)|0:null,"i32.and":(t,e)=>t&e,"i32.or":(t,e)=>t|e,"i32.xor":(t,e)=>t^e,"i32.shl":(t,e)=>t<<(e&31),"i32.shr_s":(t,e)=>t>>(e&31),"i32.shr_u":(t,e)=>t>>>(e&31),"i32.rotl":(t,e)=>(e&=31,t<<e|t>>>32-e|0),"i32.rotr":(t,e)=>(e&=31,t>>>e|t<<32-e|0),"i32.eq":(t,e)=>t===e?1:0,"i32.ne":(t,e)=>t!==e?1:0,"i32.lt_s":(t,e)=>t<e?1:0,"i32.lt_u":(t,e)=>t>>>0<e>>>0?1:0,"i32.gt_s":(t,e)=>t>e?1:0,"i32.gt_u":(t,e)=>t>>>0>e>>>0?1:0,"i32.le_s":(t,e)=>t<=e?1:0,"i32.le_u":(t,e)=>t>>>0<=e>>>0?1:0,"i32.ge_s":(t,e)=>t>=e?1:0,"i32.ge_u":(t,e)=>t>>>0>=e>>>0?1:0,"i32.eqz":t=>t===0?1:0,"i32.clz":t=>Math.clz32(t),"i32.ctz":t=>t===0?32:31-Math.clz32(t&-t),"i32.popcnt":t=>{let e=0;for(;t;)e+=t&1,t>>>=1;return e},"i32.wrap_i64":t=>Number(BigInt.asIntN(32,t)),"i64.add":(t,e)=>BigInt.asIntN(64,t+e),"i64.sub":(t,e)=>BigInt.asIntN(64,t-e),"i64.mul":(t,e)=>BigInt.asIntN(64,t*e),"i64.div_s":(t,e)=>e!==0n?BigInt.asIntN(64,t/e):null,"i64.div_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)/BigInt.asUintN(64,e)):null,"i64.rem_s":(t,e)=>e!==0n?BigInt.asIntN(64,t%e):null,"i64.rem_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)%BigInt.asUintN(64,e)):null,"i64.and":(t,e)=>BigInt.asIntN(64,t&e),"i64.or":(t,e)=>BigInt.asIntN(64,t|e),"i64.xor":(t,e)=>BigInt.asIntN(64,t^e),"i64.shl":(t,e)=>BigInt.asIntN(64,t<<(e&63n)),"i64.shr_s":(t,e)=>BigInt.asIntN(64,t>>(e&63n)),"i64.shr_u":(t,e)=>BigInt.asUintN(64,BigInt.asUintN(64,t)>>(e&63n)),"i64.eq":(t,e)=>t===e?1:0,"i64.ne":(t,e)=>t!==e?1:0,"i64.lt_s":(t,e)=>t<e?1:0,"i64.lt_u":(t,e)=>BigInt.asUintN(64,t)<BigInt.asUintN(64,e)?1:0,"i64.gt_s":(t,e)=>t>e?1:0,"i64.gt_u":(t,e)=>BigInt.asUintN(64,t)>BigInt.asUintN(64,e)?1:0,"i64.le_s":(t,e)=>t<=e?1:0,"i64.le_u":(t,e)=>BigInt.asUintN(64,t)<=BigInt.asUintN(64,e)?1:0,"i64.ge_s":(t,e)=>t>=e?1:0,"i64.ge_u":(t,e)=>BigInt.asUintN(64,t)>=BigInt.asUintN(64,e)?1:0,"i64.eqz":t=>t===0n?1:0,"i64.extend_i32_s":t=>BigInt(t),"i64.extend_i32_u":t=>BigInt(t>>>0),"f32.add":(t,e)=>Math.fround(t+e),"f32.sub":(t,e)=>Math.fround(t-e),"f32.mul":(t,e)=>Math.fround(t*e),"f32.div":(t,e)=>Math.fround(t/e),"f32.neg":t=>Math.fround(-t),"f32.abs":t=>Math.fround(Math.abs(t)),"f32.sqrt":t=>Math.fround(Math.sqrt(t)),"f32.ceil":t=>Math.fround(Math.ceil(t)),"f32.floor":t=>Math.fround(Math.floor(t)),"f32.trunc":t=>Math.fround(Math.trunc(t)),"f32.nearest":t=>Math.fround(Math.round(t)),"f64.add":(t,e)=>t+e,"f64.sub":(t,e)=>t-e,"f64.mul":(t,e)=>t*e,"f64.div":(t,e)=>t/e,"f64.neg":t=>-t,"f64.abs":t=>Math.abs(t),"f64.sqrt":t=>Math.sqrt(t),"f64.ceil":t=>Math.ceil(t),"f64.floor":t=>Math.floor(t),"f64.trunc":t=>Math.trunc(t),"f64.nearest":t=>Math.round(t)},w=t=>{if(!Array.isArray(t)||t.length!==2)return null;let[e,i]=t;return e==="i32.const"?{type:"i32",value:Number(i)|0}:e==="i64.const"?{type:"i64",value:BigInt(i)}:e==="f32.const"?{type:"f32",value:Math.fround(Number(i))}:e==="f64.const"?{type:"f64",value:Number(i)}:null},jt=(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,ve=t=>H(F(t),e=>{if(!Array.isArray(e))return;let i=e[0],r=$e[i];if(r){if(r.length===1&&e.length===2){let s=w(e[1]);if(!s)return;let l=r(s.value);if(l===null)return;let a=i.startsWith("i64.")&&!i.includes("eqz")?"i64":i.startsWith("f32.")?"f32":i.startsWith("f64.")?"f64":"i32";return jt(a,l)}if(r.length===2&&e.length===3){let s=w(e[1]),l=w(e[2]);if(!s||!l)return;let a=r(s.value,l.value);if(a===null)return;let o=/\.(eq|ne|[lg][te])/.test(i)?"i32":i.startsWith("i64.")?"i64":i.startsWith("f32.")?"f32":i.startsWith("f64.")?"f64":"i32";return jt(o,a)}}}),Ie={"i32.add":(t,e)=>{let i=w(t),r=w(e);return i?.value===0?e:r?.value===0?t:null},"i64.add":(t,e)=>{let i=w(t),r=w(e);return i?.value===0n?e:r?.value===0n?t:null},"i32.sub":(t,e)=>w(e)?.value===0?t:null,"i64.sub":(t,e)=>w(e)?.value===0n?t:null,"i32.mul":(t,e)=>{let i=w(t),r=w(e);return i?.value===1?e:r?.value===1?t:null},"i64.mul":(t,e)=>{let i=w(t),r=w(e);return i?.value===1n?e:r?.value===1n?t:null},"i32.div_s":(t,e)=>w(e)?.value===1?t:null,"i32.div_u":(t,e)=>w(e)?.value===1?t:null,"i64.div_s":(t,e)=>w(e)?.value===1n?t:null,"i64.div_u":(t,e)=>w(e)?.value===1n?t:null,"i32.and":(t,e)=>{let i=w(t),r=w(e);return i?.value===-1?e:r?.value===-1?t:null},"i64.and":(t,e)=>{let i=w(t),r=w(e);return i?.value===-1n?e:r?.value===-1n?t:null},"i32.or":(t,e)=>{let i=w(t),r=w(e);return i?.value===0?e:r?.value===0?t:null},"i64.or":(t,e)=>{let i=w(t),r=w(e);return i?.value===0n?e:r?.value===0n?t:null},"i32.xor":(t,e)=>{let i=w(t),r=w(e);return i?.value===0?e:r?.value===0?t:null},"i64.xor":(t,e)=>{let i=w(t),r=w(e);return i?.value===0n?e:r?.value===0n?t:null},"i32.shl":(t,e)=>w(e)?.value===0?t:null,"i32.shr_s":(t,e)=>w(e)?.value===0?t:null,"i32.shr_u":(t,e)=>w(e)?.value===0?t:null,"i64.shl":(t,e)=>w(e)?.value===0n?t:null,"i64.shr_s":(t,e)=>w(e)?.value===0n?t:null,"i64.shr_u":(t,e)=>w(e)?.value===0n?t:null},Ne=t=>H(F(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let i=Ie[e[0]];if(!i)return;let r=i(e[1],e[2]);if(r!==null)return r}),ke=t=>H(F(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let[i,r,s]=e;if(i==="i32.mul"){let l=w(s);if(l&&l.value>0&&!(l.value&l.value-1)){let n=Math.log2(l.value);if(Number.isInteger(n))return["i32.shl",r,["i32.const",n]]}let a=w(r);if(a&&a.value>0&&!(a.value&a.value-1)){let n=Math.log2(a.value);if(Number.isInteger(n))return["i32.shl",s,["i32.const",n]]}}if(i==="i64.mul"){let l=w(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let n=BigInt(l.value.toString(2).length-1);return["i64.shl",r,["i64.const",n]]}let a=w(r);if(a&&a.value>0n&&(a.value&a.value-1n)===0n){let n=BigInt(a.value.toString(2).length-1);return["i64.shl",s,["i64.const",n]]}}if(i==="i32.div_u"){let l=w(s);if(l&&l.value>0&&!(l.value&l.value-1)){let a=Math.log2(l.value);if(Number.isInteger(a))return["i32.shr_u",r,["i32.const",a]]}}if(i==="i64.div_u"){let l=w(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let a=BigInt(l.value.toString(2).length-1);return["i64.shr_u",r,["i64.const",a]]}}if(i==="i32.rem_u"){let l=w(s);if(l&&l.value>0&&!(l.value&l.value-1))return["i32.and",r,["i32.const",l.value-1]]}if(i==="i64.rem_u"){let l=w(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n)return["i64.and",r,["i64.const",l.value-1n]]}}),Be=t=>H(F(t),e=>{if(!Array.isArray(e))return;let i=e[0];if(i==="if"){let r=1;for(;r<e.length;){let o=e[r];if(Array.isArray(o)&&(o[0]==="then"||o[0]==="else"||o[0]==="result"||o[0]==="param")){r++;continue}break}let s=e[r],l=w(s);if(!l)return;let a=null,n=null;for(let o=r+1;o<e.length;o++){let f=e[o];Array.isArray(f)&&(f[0]==="then"?a=f:f[0]==="else"&&(n=f))}if(l.value!==0&&l.value!==0n){if(a&&a.length>1){let o=a.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}else{if(n&&n.length>1){let o=n.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}}if(i==="br_if"&&e.length>=3){let r=e[e.length-1],s=w(r);return s?s.value===0||s.value===0n?["nop"]:["br",e[1]]:void 0}if(i==="select"&&e.length>=4){let r=e[e.length-1],s=w(r);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),Pt=new Set(["unreachable","return","br","br_table"]),Me=t=>{let e=F(t);return G(e,i=>{if(!Array.isArray(i))return;let r=i[0];if((r==="func"||r==="block"||r==="loop")&&Rt(i),r==="if")for(let s=1;s<i.length;s++)Array.isArray(i[s])&&(i[s][0]==="then"||i[s][0]==="else")&&Rt(i[s])}),e},Rt=t=>{let e=!1,i=-1;for(let r=1;r<t.length;r++){let s=t[r];if(Array.isArray(s)){let l=s[0];if(l==="param"||l==="result"||l==="local"||l==="type"||l==="export")continue;e&&i===-1&&(i=r),Pt.has(l)&&(e=!0,i=r+1)}else typeof s=="string"&&(e&&i===-1&&(i=r),Pt.has(s)&&(e=!0,i=r+1))}i>0&&i<t.length&&t.splice(i)},ze=t=>{let e=F(t);return G(e,i=>{if(!Array.isArray(i)||i[0]!=="func")return;let r=[],s=new Map,l=new Set;for(let a=1;a<i.length;a++){let n=i[a];Array.isArray(n)&&(n[0]==="local"&&(r.push({idx:a,node:n}),typeof n[1]=="string"&&n[1][0]==="$"&&s.set(n[1],n[2])),n[0]==="param"&&typeof n[1]=="string"&&n[1][0]==="$"&&(s.set(n[1],n[2]),l.add(n[1])))}G(i,a=>{if(!Array.isArray(a))return;let n=a[0];if(n==="local.get"||n==="local.set"||n==="local.tee"){let o=a[1];typeof o=="string"&&l.add(o)}});for(let a=r.length-1;a>=0;a--){let{idx:n,node:o}=r[a],f=typeof o[1]=="string"&&o[1][0]==="$"?o[1]:null;f&&!l.has(f)&&i.splice(n,1)}}),e},Ue=t=>{let e=F(t);return G(e,i=>{if(!Array.isArray(i)||i[0]!=="func")return;let r=new Map;((l,a=1)=>{for(let n=a;n<l.length;n++){let o=l[n];if(!Array.isArray(o))continue;let f=o[0];if(f==="local.set"&&o.length===3){let c=o[1],m=o[2];w(m)&&typeof c=="string"?r.set(c,m):typeof c=="string"&&r.delete(c)}else if(f==="local.tee"&&o.length===3){let c=o[1],m=o[2];w(m)&&typeof c=="string"?r.set(c,m):typeof c=="string"&&r.delete(c)}else if(f==="local.get"&&o.length===2){let c=o[1];if(typeof c=="string"&&r.has(c)){let m=r.get(c);o.length=0,o.push(...F(m))}}else(f==="block"||f==="loop"||f==="if"||f==="call"||f==="call_indirect")&&r.clear();H(o,c=>{if(!Array.isArray(c)||c[0]!=="local.get"||c.length!==2)return;let m=c[1];if(typeof m=="string"&&r.has(m)){let x=r.get(m);return F(x)}})}})(i)}),e},Te=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=F(t),i=new Map;for(let r of e.slice(1)){if(!Array.isArray(r)||r[0]!=="func")continue;let s=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!s)continue;let l=[],a=[],n=!1,o=!1;for(let f=1;f<r.length;f++){let c=r[f];if(Array.isArray(c))if(c[0]==="param")if(typeof c[1]=="string"&&c[1][0]==="$")l.push({name:c[1],type:c[2]});else{l=null;break}else c[0]==="local"?n=!0:c[0]==="export"?o=!0:c[0]!=="result"&&c[0]!=="type"&&a.push(c)}l&&!n&&!o&&l.length<=2&&a.length===1&&i.set(s,{body:a[0],params:l})}return i.size===0||H(e,r=>{if(!Array.isArray(r)||r[0]!=="call")return;let s=r[1];if(!i.has(s))return;let{body:l,params:a}=i.get(s),n=r.slice(2);if(a.length===0)return F(l);let o=F(l);return H(o,f=>{if(!Array.isArray(f)||f[0]!=="local.get")return;let c=f[1],m=a.findIndex(x=>x.name===c);if(m!==-1&&n[m])return F(n[m])}),o}),e};function gt(t,e=!0){return typeof t=="string"&&(t=L(t)),t=F(t),e=Ae(e),e.fold&&(t=ve(t)),e.identity&&(t=Ne(t)),e.strength&&(t=ke(t)),e.branch&&(t=Be(t)),e.propagate&&(t=Ue(t)),e.inline&&(t=Te(t)),e.deadcode&&(t=Me(t)),e.locals&&(t=ze(t)),e.treeshake&&(t=we(t)),t}var Vt="\uE000",Ht=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},Ee=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[i,...r]=t;return Ht(i)?Ht(i):i==="local.get"&&e.locals?.[r[0]]?e.locals[r[0]]:i==="call"&&e.funcs?.[r[0]]?e.funcs[r[0]].result?.[0]:null};function It(t,e){if(t=e(t),Array.isArray(t))for(let i=0;i<t.length;i++){let r=It(t[i],e);r?._splice?(t.splice(i,1,...r),i+=r.length-1):t[i]=r}return t}function qe(t,e){let i=[],r=new Map;return It(t,s=>{if(!Array.isArray(s))return s;if(s[0]==="call"&&typeof s[1]=="function"){let l=s[1];if(!r.has(l)){let n=[];for(let c=2;c<s.length;c++){let m=Ee(s[c]);m&&n.push(m)}let o=i.length,f=l.name||`$fn${o}`;r.set(l,{idx:o,name:f.startsWith("$")?f:"$"+f,params:n,fn:l}),i.push(r.get(l))}let a=r.get(l);s[1]=a.name}return s}),i}function Se(t){return t.map(({name:e,params:i})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...i.map(r=>["param",r])]])}function Oe(t,...e){let i={};if(!Array.isArray(t)&&e.length&&typeof e[e.length-1]=="object"&&e[e.length-1]!==null&&!(e[e.length-1]instanceof Uint8Array)&&(i=e.pop()),Array.isArray(t)&&t.raw){let r=t[0];for(let f=0;f<e.length;f++)r+=Vt+t[f+1];let s=L(r),l=[],a=0;s=It(s,f=>{if(f===Vt){let c=e[a++];if(typeof c=="function")return l.push(c),c;if(typeof c=="string"&&(c[0]==="("||/^\s*\(/.test(c))){let m=L(c);return Array.isArray(m)&&Array.isArray(m[0])&&(m._splice=!0),m}return c instanceof Uint8Array?[...c]:c}return f});let n=null;if(l.length){let f=qe(s,l);if(f.length){let c=Se(f);s[0]==="module"?s.splice(1,0,...c):typeof s[0]=="string"?s=[...c,s]:s.unshift(...c),n={env:{}};for(let m of f)n.env[m.name.slice(1)]=m.fn}}i.polyfill&&(s=yt(s,i.polyfill)),i.optimize&&(s=gt(s,i.optimize));let o=Q(s);return n&&(o._imports=n),o}if(i.polyfill||i.optimize){let r=typeof t=="string"?L(t):t;return i.polyfill&&(r=yt(r,i.polyfill)),i.optimize&&(r=gt(r,i.optimize)),Q(r)}return Q(t)}function Fe(t,...e){let i=Oe(t,...e),r=new WebAssembly.Module(i);return new WebAssembly.Instance(r,i._imports).exports}var ai=Fe;export{Oe as compile,ai as default,gt as optimize,L as parse,yt as polyfill,Ft as print,Fe as watr};
|
|
1
|
+
var Gt=Object.defineProperty;var Kt=(t,e)=>{for(var r in e)Gt(t,r,{get:e[r],enumerable:!0})};var J={};Kt(J,{f32:()=>et,f64:()=>X,i16:()=>te,i32:()=>D,i64:()=>K,i8:()=>Qt,uleb:()=>y,uleb5:()=>Zt});var $=(t,e=$.loc)=>{if(e!=null&&$.src){let r=1,i=1;for(let s=0;s<e&&s<$.src.length;s++)$.src[s]===`
|
|
2
|
+
`?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)};var kt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Bt=/^[+-]?(?:0x[\da-f]+|\d+)$/i,Xt=new TextEncoder,Jt=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),Nt={n:10,r:13,t:9,'"':34,"'":39,"\\":92},lt=t=>{let e=[],r=1,i,s,l="",n=()=>(l&&e.push(...Xt.encode(l)),l="");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++):Nt[t[r]]?i=Nt[t[r++]]:isNaN(i=parseInt(t[r]+t[r+1],16))?s+=t[r]:(r++,r++)),i!=null?(n(),e.push(i)):l+=s;return n(),e.valueOf=()=>t,e},Mt=t=>Jt.decode(new Uint8Array(lt(t)));var y=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):D.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),y(t,e))};function Zt(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 D(t,e=[]){for(typeof t=="string"&&(t=D.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=>!kt.test(t)&&Bt.test(t=t.replaceAll("_",""))?t:$(`Bad int ${t}`),Qt=D,te=D;D.parse=t=>(t=parseInt(zt(t)),(t<-2147483648||t>4294967295)&&$("i32 constant out of range"),t);function K(t,e=[]){for(typeof t=="string"?t=K.parse(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}K.parse=t=>(t=zt(t),t=t[0]==="-"?-BigInt(t.slice(1)):BigInt(t),(t<-0x8000000000000000n||t>0xffffffffffffffffn)&&$("i64 constant out of range"),E.setBigInt64(0,t),E.getBigInt64(0));var E=new DataView(new Float64Array(1).buffer),ee=2147483648,re=2139095040;function et(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=D.parse(t.slice(r+4)),e|=re,t[0]==="-"&&(e|=ee),E.setInt32(0,e)):(e=typeof t=="string"?et.parse(t):t,E.setFloat32(0,e)),[E.getUint8(3),E.getUint8(2),E.getUint8(1),E.getUint8(0)]}var ie=0x8000000000000000n,se=0x7ff0000000000000n;function X(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=K.parse(t.slice(r+4)),e|=se,t[0]==="-"&&(e|=ie),E.setBigInt64(0,e)):(e=typeof t=="string"?X.parse(t):t,E.setFloat64(0,e)),[E.getUint8(7),E.getUint8(6),E.getUint8(5),E.getUint8(4),E.getUint8(3),E.getUint8(2),E.getUint8(1),E.getUint8(0)]}X.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),[l,n=""]=i.split("."),a=n.length??0,c=parseInt(l);isNaN(c)&&$();let f=n?parseInt("0x"+n)/16**a:0;s=parseInt(s,10);let o=r*(c+f)*2**s;return o=Math.max(-e,Math.min(e,o)),o}return t.includes("nan")?r<0?NaN:NaN:t.includes("inf")?r*(1/0):r*parseFloat(t)};et.parse=t=>X.parse(t,34028234663852886e22);var rt=["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",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,["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.cast reftype","","br_on_cast reftype2","br_on_cast_fail reftype2","any.convert_extern","extern.convert_any","ref.i31","i31.get_s","i31.get_u"],["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"],["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"]],B={custom:0,type:1,import:2,func:3,table:4,memory:5,tag:13,global:6,export:7,start:8,elem:9,datacount:12,code:10,data:11},q={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,nullfuncref:115,nullexternref:114,nullexnref:116,nullref:113,funcref:112,externref:111,exnref:105,anyref:110,eqref:109,i31ref:108,structref:107,arrayref:106,ref:100,refnull:99,sub:80,subfinal:79,rec:78},Ut={func:96,struct:95,array:94,sub:80,subfinal:79,rec:78},xt={func:0,table:1,memory:2,global:3,tag:4};var C=t=>{let e=0,r=[],i="",s=0,l=0,n=()=>i&&(r.push(i),i=""),a=c=>{r.loc=c;for(let f,o,u;e<t.length;)if(f=t.charCodeAt(e),s===34)i+=t[e++],f===92?i+=t[e++]:f===34&&(n(),s=0);else if(s>59)f===40&&t.charCodeAt(e+1)===59?(s++,i+=t[e++]+t[e++]):f===59&&t.charCodeAt(e+1)===41?(i+=t[e++]+t[e++],--s===59&&(n(),s=0)):i+=t[e++];else if(s<0)f===10||f===13?(i+=t[e++],n(),s=0):i+=t[e++];else if(f===34)i!=="$"&&n(),s=34,i+=t[e++];else if(f===40&&t.charCodeAt(e+1)===59)n(),s=60,i=t[e++]+t[e++];else if(f===59&&t.charCodeAt(e+1)===59)n(),s=-1,i=t[e++]+t[e++];else if(f===40&&t.charCodeAt(e+1)===64)n(),u=e,e+=2,i="@",l++,(o=r).push(r=[]),a(u),r=o;else if(f===40)n(),u=e++,l++,(o=r).push(r=[]),a(u),r=o;else{if(f===41)return n(),e++,l--;f<=32?(n(),e++):i+=t[e++]}s<0&&n(),n()};return a(0),s===34&&$("Unclosed quote",e),s>59&&$("Unclosed block comment",e),l>0&&$("Unclosed parenthesis",e),e<t.length&&$("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var qt=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(qt).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("\\")?"$"+Mt(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?lt(t):t;function Q(t){typeof t=="string"?($.src=t,t=C(t)||[]):$.src="",$.loc=0,t=qt(t)||[];let e=0;if(t[0]==="module"?(e++,O(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return Q(t.slice(++e).map(l=>l.valueOf().slice(1,-1)).flat().join(""));let r=[];for(let l in B)(r[B[l]]=r[l]=[]).name=l;r.metadata={},t.slice(e).filter(l=>{if(!Array.isArray(l)){let c=$.loc,f=$.src,o;for(;(c=f.indexOf(l,c))>=0;){if(o=f.charCodeAt(c-1),c>0&&(o>47&&o<58||o>64&&o<91||o>96&&o<123||o===95||o===36)){c++;continue}if(o=f.charCodeAt(c+l.length),o>47&&o<58||o>64&&o<91||o>96&&o<123||o===95){c++;continue}break}c>=0&&($.loc=c),$(`Unexpected token ${l}`)}let[n,...a]=l;if($.loc=l.loc,n==="@custom")r.custom.push(a);else if(n==="rec")for(let c=0;c<a.length;c++){let[,...f]=a[c];ht(f,r.type),(f=Tt(f,r)).push(c?!0:[r.type.length,a.length]),r.type.push(f)}else if(n==="type")ht(a,r.type),r.type.push(Tt(a,r));else if(n==="start"||n==="export")r[n].push(a);else return!0}).forEach(l=>{let[n,...a]=l;$.loc=l.loc;let c;n==="import"&&([n,...a]=(c=a).pop());let f=r[n];for(f||$(`Unknown section ${n}`),ht(a,f);a[0]?.[0]==="export";)r.export.push([a.shift()[1],[n,f?.length]]);if(a[0]?.[0]==="import"&&([,...c]=a.shift()),n==="table"){let o=a[0]==="i64",u=o?1:0;if(a[u+1]?.[0]==="elem"){let[h,[,...x]]=[a[u],a[u+1]];a=o?["i64",x.length,x.length,h]:[x.length,x.length,h],r.elem.push([["table",f.length],["offset",[o?"i64.const":"i32.const",o?0n:0]],h,...x])}}else if(n==="memory"){let o=a[0]==="i64",u=o?1:0;if(a[u]?.[0]==="data"){let[,...h]=a.splice(u,1)[0],x=""+Math.ceil(h.reduce((I,p)=>I+p.length,0)/65536);r.data.push([["memory",f.length],[o?"i64.const":"i32.const",o?0n:0],...h]),a=o?["i64",x,x]:[x,x]}}else if(n==="func"){let[o,u,h]=_t(a,r);o??=ut(u,h,r),!c&&r.code.push([[o,u,h],...V(a,r)]),a=[["type",o]]}else if(n==="tag"){let[o,u]=_t(a,r);o??=ut(u,[],r),a=[["type",o]]}c&&(r.import.push([...c,[n,...a]]),a=null),f.push(a)});let i=(l,n=!0)=>{let a=r[l].filter(Boolean).map(c=>At[l](c,r)).filter(Boolean);return l===B.custom?a.flatMap(c=>[l,...k(c)]):a.length?[l,...k(n?k(a):a)]:[]},s=()=>{let l=[];for(let n in r.metadata){let a=k(lt(`"metadata.code.${n}"`)),c=k(r.metadata[n].map(([f,o])=>[...y(f),...k(o.map(([u,h])=>[...y(u),...k(h)]))]));l.push(0,...k([...a,...c]))}return l};return Uint8Array.from([0,97,115,109,1,0,0,0,...i(B.custom),...i(B.type),...i(B.import),...i(B.func),...i(B.table),...i(B.memory),...i(B.tag),...i(B.global),...i(B.export),...i(B.start,!1),...i(B.elem),...i(B.datacount,!1),...i(B.code),...s(),...i(B.data)])}var L=t=>t?.[0]==="$"||!isNaN(t),O=t=>t?.[0]==="$",dt=t=>t?.[0]==="a"||t?.[0]==="o";function V(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")O(t[0])&&r.push(t.shift()),r.push(at(t,e));else if(i==="else"||i==="end")O(t[0])&&t.shift();else if(i==="select")r.push(mt(t)[1]);else if(i.endsWith("call_indirect")){let s=L(t[0])?t.shift():0,[l,n,a]=_t(t,e);r.push(s,["type",l??ut(n,a,e)])}else i==="table.init"?r.push(L(t[1])?t.shift():0,t.shift()):i==="table.copy"||i==="memory.copy"?r.push(L(t[0])?t.shift():0,L(t[0])?t.shift():0):i.startsWith("table.")?r.push(L(t[0])?t.shift():0):i==="memory.init"?(r.push(...L(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"))&&L(t[0])&&r.push(t.shift());else if(Array.isArray(i)){let s=i[0];if(i.loc!=null&&($.loc=i.loc),s?.startsWith?.("@metadata.code.")){let n=s.slice(15);r.push(["@metadata",n,i[1]]);continue}if(typeof s!="string"||!Array.isArray(rt[s])){r.push(i);continue}let l=i.slice(1);if(s==="block"||s==="loop")r.push(s),O(l[0])&&r.push(l.shift()),r.push(at(l,e),...V(l,e),"end");else if(s==="if"){let n=[],a=[];l.at(-1)?.[0]==="else"&&(a=V(l.pop().slice(1),e)),l.at(-1)?.[0]==="then"&&(n=V(l.pop().slice(1),e));let c=[s];O(l[0])&&c.push(l.shift()),c.push(at(l,e)),r.push(...V(l,e),...c,...n),a.length&&r.push("else",...a),r.push("end")}else if(s==="try_table"){for(r.push(s),O(l[0])&&r.push(l.shift()),r.push(at(l,e));l[0]?.[0]==="catch"||l[0]?.[0]==="catch_ref"||l[0]?.[0]==="catch_all"||l[0]?.[0]==="catch_all_ref";)r.push(l.shift());r.push(...V(l,e),"end")}else{let n=[];for(;l.length&&(!Array.isArray(l[0])||"type,param,result,ref".includes(l[0][0]));)n.push(l.shift());r.push(...V(l,e),s,...n),t.unshift(...r.splice(r.length-1-n.length))}}else r.push(i)}return r}var ut=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),bt=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=O(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},mt=t=>{let e=bt(t,"param"),r=bt(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},_t=(t,e)=>{if(t[0]?.[0]!=="type")return[,...mt(t)];let[,r]=t.shift(),[i,s]=mt(t),l=e.type[typeof r=="string"&&isNaN(r)?e.type[r]:+r];if(!l)throw Error(`Unknown type ${r}`);if((i.length||s.length)&&l[1].join(">")!==i+">"+s)throw Error(`Type ${r} mismatch`);return[r,...l[1]]},at=(t,e)=>{let[r,i,s]=_t(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??ut(i,s,e)]},ht=(t,e)=>{let r=O(t[0])&&t.shift();return r&&(r in e?$(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},Tt=([t],e)=>{let r="subfinal",i=[],s;return t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(i=t).pop()),[s,...t]=t,s==="func"?(t=mt(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=bt(t,"field"):s==="array"&&([t]=t),[s,t,r,i]},At=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...k(t),...i.flat()]},([t,e,r,i,s],l)=>{if(s===!0)return;let n;if(s){t="rec";let[a,c]=s,f=Array.from({length:c},(o,u)=>At[B.type](l.type[a+u].slice(0,4),l));n=k(f)}else r==="sub"||i?.length?(n=[...k(i.map(a=>A(a,l.type))),...At[B.type]([t,e],l)],t=r):t==="func"?n=[...k(e[0].map(a=>W(a,l))),...k(e[1].map(a=>W(a,l)))]:t==="array"?n=nt(e,l):t==="struct"&&(n=k(e.map(a=>nt(a,l))));return[Ut[t],...n]},([t,e,[r,...i]],s)=>{let l;if(r==="func"){let[[,n]]=i;l=y(A(n,s.type))}else if(r==="tag"){let[[,n]]=i;l=[0,...y(A(n,s.type))]}else r==="memory"?l=ft(i):r==="global"?l=nt(i[0],s):r==="table"?l=[...W(i.pop(),s),...ft(i)]:$(`Unknown kind ${r}`);return[...k(t),...k(e),xt[r],...l]},([[,t]],e)=>y(A(t,e.type)),(t,e)=>{let r=ft(t),i=W(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...Z(s,e)]:[...i,...r]},(t,e)=>ft(t),([t,e],r)=>[...nt(t,r),...Z(e,r)],([t,[e,r]],i)=>[...k(t),xt[e],...y(A(r,i[e]))],([t],e)=>y(A(t,e.func)),(t,e)=>{let r=0,i=0,s=0,l=0,n,a,c;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,n]=t.shift(),n=A(n,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"))&&(n=A(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(a=t.shift(),a[0]==="offset"&&([,a]=a),a=Z(a,e)):i||(r=1),q[t[0]]||t[0]?.[0]==="ref"?c=W(t.shift(),e):t[0]==="func"?c=[q[t.shift()]]:c=[q.func],t=t.map(o=>(o[0]==="item"&&(o=o.length===3&&o[1]==="ref.func"?o[2]:o[1]),o[0]==="ref.func"&&([,o]=o),typeof o!="string"&&(s=1),o)),c[0]!==q.funcref&&(l=1,s=1);let f=s<<2|(r||i?i:!!n||l)<<1|(r||i);return[f,...f===0?a:f===1?[0]:f===2?[...y(n||0),...a,0]:f===3?[0]:f===4?a:f===5?c:f===6?[...y(n||0),...a,...c]:c,...k(t.map(s?o=>Z(typeof o=="string"?["ref.func",o]:o,e):o=>y(A(o,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[A(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[,...c]=t.shift();if(O(c[0])){let f=c.shift();f in e.local?$(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...c)}e.meta={};let l=Ot(t,e),n=e.import.filter(c=>c[2][0]==="func").length+s;for(let c in e.meta)((e.metadata??={})[c]??=[]).push([n,e.meta[c]]);let a=e.local.slice(i.length).reduce((c,f)=>(f==c[c.length-1]?.[1]?c[c.length-1][0]++:c.push([1,f]),c),[]);return e.local=e.block=e.meta=null,k([...k(a.map(([c,f])=>[...y(c),...W(f,e)])),...l])},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=A(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=A(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??$("Bad offset",r)),[...i?[2,...y(i),...Z(r,e)]:r?[0,...Z(r,e)]:[1],...k(t.flat())]},(t,e)=>y(e.data.length),([[,t]],e)=>[0,...y(A(t,e.type))]],W=(t,e)=>t[0]==="ref"?t[1]=="null"?q[t[2]]?[q[t[2]]]:[q.refnull,...y(A(t[t.length-1],e.type))]:[q.ref,...y(q[t[t.length-1]]||A(t[t.length-1],e.type))]:[q[t]??$(`Unknown type ${t}`)],nt=(t,e,r=t[0]==="mut"?1:0)=>[...W(r?t[1]:t,e),r],St={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...y(A(i,e.elem)),...y(A(r,e.table))]},block:(t,e)=>{e.block.push(1),O(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?W(r[1],e):y(A(r[1],e.type)):[q.void]},try_table:(t,e)=>{O(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?W(r[1],e):y(A(r[1],e.type)):[q.void],s=[],l=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let n=t.shift(),a=n[0]==="catch"?0:n[0]==="catch_ref"?1:n[0]==="catch_all"?2:3;a<=1?s.push(a,...y(A(n[1],e.tag)),...y(it(n[2],e.block))):s.push(a,...y(it(n[1],e.block))),l++}return e.block.push(1),[...i,...y(l),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...y(A(i,e.type)),...y(A(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||O(t[0]));)r.push(...y(it(t.shift(),e.block))),i++;return[...y(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?k(r.map(i=>W(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return q[r]?[q[r]]:y(A(r,e.type))},memarg:(t,e,r)=>Et(t,r,L(t[0])&&!dt(t[0])?A(t.shift(),e.memory):0),opt_memory:(t,e)=>y(A(L(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=W(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=it(t.shift(),e.block),i=W(t.shift(),e),s=W(t.shift(),e);return[(s[0]!==q.ref)<<1|i[0]!==q.ref,...y(r),i.pop(),s.pop()]},v128const:t=>{let[e,r]=t.shift().split("x"),i=+e.slice(1),s=i>>>3;if(r=+r,e[0]==="i"){let n=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let a=0;a<r;a++)n[a]=J[e].parse(t.shift());return[...new Uint8Array(n.buffer)]}let l=new Uint8Array(16);for(let n=0;n<r;n++)l.set(J[e](t.shift()),n*s);return[...l]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(ct(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&$("invalid lane length"),e},memlane:(t,e,r)=>{let i=O(t[0])||L(t[0])&&(dt(t[1])||L(t[1]))?A(t.shift(),e.memory):0;return[...Et(t,r,i),...y(ct(t.shift()))]},"*":t=>y(t.shift()),labelidx:(t,e)=>y(it(t.shift(),e.block)),laneidx:t=>[ct(t.shift(),255)],funcidx:(t,e)=>y(A(t.shift(),e.func)),typeidx:(t,e)=>y(A(t.shift(),e.type)),tableidx:(t,e)=>y(A(t.shift(),e.table)),memoryidx:(t,e)=>y(A(t.shift(),e.memory)),globalidx:(t,e)=>y(A(t.shift(),e.global)),localidx:(t,e)=>y(A(t.shift(),e.local)),dataidx:(t,e)=>y(A(t.shift(),e.data)),elemidx:(t,e)=>y(A(t.shift(),e.elem)),tagidx:(t,e)=>y(A(t.shift(),e.tag)),"memoryidx?":(t,e)=>y(A(L(t[0])?t.shift():0,e.memory)),i32:t=>D(t.shift()),i64:t=>K(t.shift()),f32:t=>et(t.shift()),f64:t=>X(t.shift()),v128:t=>(void 0)(t.shift()),typeidx_field:(t,e)=>{let r=A(t.shift(),e.type);return[...y(r),...y(A(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...y(A(t.shift(),e.type)),...y(t.shift())],typeidx_dataidx:(t,e)=>[...y(A(t.shift(),e.type)),...y(A(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...y(A(t.shift(),e.type)),...y(A(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...y(A(t.shift(),e.type)),...y(A(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...y(A(t.shift(),e.data)),...y(A(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...y(A(t.shift(),e.memory)),...y(A(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...y(A(t.shift(),e.table)),...y(A(t.shift(),e.table))]},ot={};(function t(e,r){for(let i=0,s,l,n;i<e.length;i++)(s=e[i])&&(Array.isArray(s)?t(s,i):([l,n]=s.split(" "),rt[l]=r?[r,...y(i)]:[i],n&&(ot[l]=St[n])))})(rt);var Ot=(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&&($.loc=s.loc),$(`Unknown instruction ${s[0]}`));let[...l]=rt[s]||$(`Unknown instruction ${s}`);ot[s]&&(s==="select"&&t[0]?.length?l[0]++:ot[s]===St.reftype&&(t[0][1]==="null"||t[0][0]!=="ref")&&l[l.length-1]++,l.push(...ot[s](t,e,s)));for(let[n,a]of i)(e.meta[n]??=[]).push([r.length,a]);r.push(...l)}return r.push(11),r},Z=(t,e)=>Ot(V([t],e),e),A=(t,e,r)=>(r=O(t)?e[t]:+t,r in e?r:$(`Unknown ${e.name} ${t}`)),it=(t,e,r)=>(r=O(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?$(`Bad label ${t}`):r),le=t=>{let e,r,i,s;for(;dt(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:$(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&$(`Bad offset ${r}`),(e<=0||e>4294967295)&&$(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&$(`Bad align ${e}`),[e,r]},Et=(t,e,r=0)=>{let[i,s]=le(t),l=(i??ae(e))|(r&&64);return r?[...y(l),...y(r),...y(s??0)]:[...y(l),...y(s??0)]},ae=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 l=t.slice(e,e+6).match(/\d+/);return Math.log2(l?l[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)},ft=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=!isNaN(parseInt(t[1])),s=(e?4:0)|(r?2:0)|(i?1:0),l=e?n=>{if(typeof n=="bigint")return n;let a=typeof n=="string"?n.replaceAll("_",""):String(n);return BigInt(a)}:ct;return i?[s,...y(l(t.shift())),...y(l(t.shift()))]:[s,...y(l(t.shift()))]},ct=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?D.parse(t):typeof t=="number"?t:$(`Bad int ${t}`);return r>e?$(`Value out of range ${t}`):r},k=t=>[...y(t.length),...t.flat()];function Ft(t,e={}){typeof t=="string"&&(t=C(t));let{indent:r=" ",newline:i=`
|
|
3
|
+
`,comments:s=!0}=e;if(r||="",i||="",typeof t[0]=="string"&&t[0][0]!==";")return n(t);return t.filter(a=>s||!l(a)).map(a=>n(a)).join(i);function l(a){return typeof a=="string"&&a[1]===";"}function n(a,c=0){if(!Array.isArray(a))return a;let f=a[0];if(!f)return"";let o=!1;if(f==="try_table"){let x=1;for(typeof a[x]=="string"&&a[x][0]==="$"&&(f+=" "+a[x++]),Array.isArray(a[x])&&(a[x][0]==="result"||a[x][0]==="type")&&(f+=" "+n(a[x++],c));Array.isArray(a[x])&&/^catch/.test(a[x][0]);)f+=" "+n(a[x++],c).trim();for(;x<a.length;x++)f+=Array.isArray(a[x])?i+r.repeat(c+1)+n(a[x],c+1):" "+a[x];return`(${f+i+r.repeat(c)})`}let u=!!i&&a.length<4&&!a.some(x=>typeof x=="string"&&x[0]===";"&&x[1]===";"),h=r.repeat(c+1);for(let x=1;x<a.length;x++){let I=a[x].valueOf();if(typeof I=="string"&&I[1]===";"){if(!s)continue;if(I[0]===";")if(i)f+=i+h+I.trimEnd(),o=!0;else{let p=f[f.length-1];p&&p!==" "&&p!=="("&&(f+=" "),f+=I.trimEnd()+`
|
|
4
|
+
`}else{let p=f[f.length-1];p&&p!==" "&&p!=="("&&(f+=" "),f+=I.trimEnd()}}else if(Array.isArray(I))u&&(u=I.every(p=>!Array.isArray(p))),f+=i+h+n(I,c+1),o=!1;else if(a[0]==="data")u=!1,(i||f[f.length-1]!==")")&&(f+=i||" "),f+=h+I,o=!1;else{let p=f[f.length-1];o&&i?f+=i+h:p===`
|
|
5
|
+
`?f+="":(p&&p!==")"&&p!==" "||i||p===")")&&(f+=" "),f+=I,o=!1}}return u?`(${f.replaceAll(i+h+"("," (")})`:`(${f+i+r.repeat(c)})`}}var Ct={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(Ct),ne=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}},S=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)S(t[s],e,t,s)},j=(t,e,r,i)=>{if(Array.isArray(t))for(let s=0;s<t.length;s++)j(t[s],e,t,s);e(t,r,i)},fe=t=>{let e=new Set;return S(t,r=>{if(typeof r=="string")for(let[i,s]of Object.entries(Ct))s.some(l=>r===l||r.startsWith(l+" "))&&e.add(i)}),S(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")&&S(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),S(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},Lt=t=>Array.isArray(t)?t.map(Lt):t,Dt=(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},pt=(t,e,r)=>t.splice(e,0,r),oe=0,R=t=>`$__${t}${oe++}`,ce=(t,e)=>{let r=new Set;if(S(t,f=>{Array.isArray(f)&&f[0]==="ref.func"&&r.add(f[1])}),!r.size)return t;let i=R("fntbl"),s=[...r],l=Object.fromEntries(s.map((f,o)=>[f,o])),n=Dt(t,"func"),a=n.length?n[0].idx:t[0]==="module"?1:0;pt(t,a,["table",i,"funcref",["elem",...s]]);let c={};return S(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let o=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!o)return;let u=[],h=[];for(let x of f){if(Array.isArray(x)&&x[0]==="param")for(let I=1;I<x.length;I++)x[I][0]!=="$"&&u.push(x[I]);if(Array.isArray(x)&&x[0]==="result")for(let I=1;I<x.length;I++)h.push(x[I])}c[o]={params:u,results:h}}),j(t,(f,o,u)=>{if(!(!Array.isArray(f)||!o)){if(f[0]==="ref.func"&&l[f[1]]!==void 0&&(o[u]=["i32.const",l[f[1]]]),f[0]==="call_ref"){let h=f[1],x=f.slice(2);o[u]=["call_indirect",i,["type",h],...x]}if(f[0]==="return_call_ref"){let h=f[1],x=f.slice(2);o[u]=["return_call_indirect",i,["type",h],...x]}}}),t},P={funcref:ce},ue={"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]},me=(t,e)=>(j(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let l=ue[r[0]];if(!l)return;let[n,a]=l,c=r.slice(1);i[s]=[`${n}.shr_s`,[`${n}.shl`,...c,[`${n}.const`,a]],[`${n}.const`,a]]}),t);P.sign_ext=me;var Wt={"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}},_e=(t,e)=>{let r=new Set;if(S(t,s=>{Array.isArray(s)&&Wt[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:l,ftype:n,signed:a,min:c,max:f}=Wt[s],o=R(`trunc_${l}_${n}_${a?"s":"u"}`);i[s]=o;let u=`${l}.trunc_${n}_${a?"s":"u"}`,h=l==="i64"?0n:0,x=["func",o,["param","$v",n],["result",l],["if",["result",l],[`${n}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${l}.const`,h]],["else",["if",["result",l],[`${n}.lt`,["local.get","$v"],[`${n}.const`,typeof c=="bigint"?Number(c):c]],["then",[`${l}.const`,c]],["else",["if",["result",l],[`${n}.gt`,["local.get","$v"],[`${n}.const`,typeof f=="bigint"?Number(f):f]],["then",[`${l}.const`,f]],["else",[u,["local.get","$v"]]]]]]]]];t.push(x)}return j(t,(s,l,n)=>{!Array.isArray(s)||!l||i[s[0]]&&(l[n]=["call",i[s[0]],...s.slice(1)])}),t};P.nontrapping=_e;var pe=(t,e)=>{let r=new Set,i=new Set;S(t,n=>{if(Array.isArray(n)){if(n[0]==="memory.copy"){let a=typeof n[1]=="number"?n[1]:0,c=typeof n[2]=="number"?n[2]:0;r.add(`${a}_${c}`)}if(n[0]==="memory.fill"){let a=typeof n[1]=="number"?n[1]:0;i.add(a)}}});let s={},l={};for(let n of r){let[a,c]=n.split("_").map(Number),f=R(`memcpy${n==="0_0"?"":"_"+n}`);s[n]=f;let o=a?["i32.store8",a]:["i32.store8"],u=c?["i32.load8_u",c]:["i32.load8_u"];t.push(["func",f,["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"]]],[...o,["i32.add",["local.get","$dst"],["local.get","$i"]],[...u,["i32.add",["local.get","$src"],["local.get","$i"]]]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}for(let n of i){let a=R(`memset${n===0?"":"_"+n}`);l[n]=a;let c=n?["i32.store8",n]:["i32.store8"];t.push(["func",a,["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"]]],[...c,["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 j(t,(n,a,c)=>{if(!(!Array.isArray(n)||!a)){if(n[0]==="memory.copy"){let f=typeof n[1]=="number"?n[1]:0,o=typeof n[2]=="number"?n[2]:0,u=n.filter(h=>Array.isArray(h)||typeof h=="string"&&h[0]==="$");a[c]=["call",s[`${f}_${o}`],...u]}if(n[0]==="memory.fill"){let f=typeof n[1]=="number"?n[1]:0,o=n.filter(u=>Array.isArray(u)||typeof u=="string"&&u[0]==="$");a[c]=["call",l[f],...o]}}}),t};P.bulk_memory=pe;var ye=(t,e)=>{let r=!1;return S(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&j(t,(i,s,l)=>{!Array.isArray(i)||!s||(i[0]==="return_call"&&(s[l]=["return",["call",...i.slice(1)]]),i[0]==="return_call_indirect"&&(s[l]=["return",["call_indirect",...i.slice(1)]]))}),t};P.return_call=ye;var ge=(t,e)=>(j(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 l=r.slice(1);i[s]=["i32.shr_s",["i32.shl",...l,["i32.const",1]],["i32.const",1]]}}),t);P.i31ref=ge;var xe=(t,e)=>{let r={};S(t,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let l=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(l)for(let n=s.length-1;n>=0;n--){let a=s[n];if(Array.isArray(a)&&(a[0]==="i32.const"||a[0]==="i64.const"||a[0]==="f32.const"||a[0]==="f64.const")){r[l]={type:a[0].split(".")[0],value:a[1]};break}}});let i=s=>{if(!Array.isArray(s))return s;let l=s[0];if(l==="global.get"&&r[s[1]]){let n=r[s[1]];return[`${n.type}.const`,n.value]}if(l==="i32.add"||l==="i64.add"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let c=l.split(".")[0],f=c==="i64"?BigInt(n[1]):Number(n[1]),o=c==="i64"?BigInt(a[1]):Number(a[1]);return[`${c}.const`,f+o]}}if(l==="i32.sub"||l==="i64.sub"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let c=l.split(".")[0],f=c==="i64"?BigInt(n[1]):Number(n[1]),o=c==="i64"?BigInt(a[1]):Number(a[1]);return[`${c}.const`,f-o]}}if(l==="i32.mul"||l==="i64.mul"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let c=l.split(".")[0],f=c==="i64"?BigInt(n[1]):Number(n[1]),o=c==="i64"?BigInt(a[1]):Number(a[1]);return[`${c}.const`,f*o]}}return s};return j(t,(s,l,n)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!l)){for(let a=2;a<s.length;a++)if(Array.isArray(s[a])){let c=i(s[a]);c!==s[a]&&(s[a]=c)}}}),t};P.extended_const=xe;var he=(t,e)=>{let r=new Map,i=[];if(S(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null,f=[];for(let o of a)if(Array.isArray(o)&&o[0]==="result")for(let u=1;u<o.length;u++)f.push(o[u]);f.length>1&&c&&r.set(c,f)}),!r.size)return t;let s=Math.max(...[...r.values()].map(a=>a.length)),l={};for(let[a,c]of r)for(let f=1;f<c.length;f++){let o=c[f];if(l[o]||(l[o]=[]),l[o].length<f){let u=R(`ret_${o}_${l[o].length}`);l[o].push(u),i.push(["global",u,["mut",o],[`${o}.const`,o==="i64"?0n:0]])}}let n=t[0]==="module"?1:0;for(let a of i.reverse())pt(t,n,a);return j(t,(a,c,f)=>{if(!Array.isArray(a)||a[0]!=="func")return;let o=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!o||!r.has(o))return;let u=r.get(o);for(let h=0;h<a.length;h++)if(Array.isArray(a[h])&&a[h][0]==="result"){a[h]=["result",u[0]];break}}),t};P.multi_value=he;var st={i32:4,i64:8,f32:4,f64:8},de=(t,e)=>{let r=new Map,i=new Map,s=1;if(S(t,p=>{if(!Array.isArray(p)||p[0]!=="type")return;let N=typeof p[1]=="string"&&p[1][0]==="$"?p[1]:null;if(N){for(let m of p)if(Array.isArray(m)){if(m[0]==="struct"){let g=[];for(let _ of m)if(Array.isArray(_)&&_[0]==="field"){let b=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:null,d=b?_[2]:_[1],v=Array.isArray(d)&&d[0]==="mut"?d[1]:d;g.push({name:b,type:v})}r.set(N,{kind:"struct",fields:g}),i.set(N,s++)}if(m[0]==="array"){let g=m[1],_=Array.isArray(g)&&g[0]==="mut"?g[1]:g;r.set(N,{kind:"array",elemType:_}),i.set(N,s++)}}}}),!r.size)return t;let l=Dt(t,"memory").length>0,n=R("alloc"),a=R("heap_ptr"),c=t[0]==="module"?1:0;l||pt(t,c,["memory",1]),pt(t,c+1,["global",a,["mut","i32"],["i32.const",1024]]);let f=["func",n,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",a]],["global.set",a,["i32.add",["global.get",a],["local.get","$size"]]],["local.get","$ptr"]];t.push(f);let o=p=>{let N=4;for(let m of p.fields)N+=st[m.type]||4;return N},u=(p,N)=>{let m=4;for(let g=0;g<N;g++)m+=st[p.fields[g].type]||4;return m},h=(p,N)=>{for(let m=0;m<p.fields.length;m++)if(p.fields[m].name===N)return m;return-1},x=0,I=()=>`$__gc_tmp${x++}`;return S(t,p=>{if(!Array.isArray(p)||p[0]!=="func")return;let N=!1,m=!1,g=!1,_=!1;if(S(p,d=>{Array.isArray(d)&&((d[0]==="struct.new"||d[0]==="struct.new_default")&&(N=!0),(d[0]==="array.new"||d[0]==="array.new_default")&&(m=!0,g=!0,_=!0))}),!N&&!m)return;let b=1;for(let d=1;d<p.length;d++){let v=p[d];if(Array.isArray(v)&&(v[0]==="param"||v[0]==="result"||v[0]==="local"||v[0]==="export"||v[0]==="type"))b=d+1;else if(typeof v=="string"&&v[0]==="$")b=d+1;else if(!Array.isArray(v))b=d+1;else break}N&&p.splice(b++,0,["local","$__gc_ptr","i32"]),m&&p.splice(b++,0,["local","$__gc_aptr","i32"]),g&&p.splice(b++,0,["local","$__gc_alen","i32"]),_&&p.splice(b++,0,["local","$__gc_aidx","i32"])}),j(t,(p,N,m)=>{if(!(!Array.isArray(p)||!N)){if(p[0]==="struct.new"||p[0]==="struct.new_default"){let g=p[1],_=r.get(g);if(!_||_.kind!=="struct")return;let b=o(_),d=i.get(g),v=p.slice(2),M="$__gc_ptr",T=[["local.set",M,["call",n,["i32.const",b]]],["i32.store",["local.get",M],["i32.const",d]]];if(p[0]==="struct.new")for(let z=0;z<_.fields.length;z++){let U=_.fields[z],tt=u(_,z),G=U.type==="i64"?"i64.store":U.type==="f32"?"f32.store":U.type==="f64"?"f64.store":"i32.store";T.push([G,["i32.add",["local.get",M],["i32.const",tt]],v[z]||[`${U.type}.const`,0]])}else for(let z=0;z<_.fields.length;z++){let U=_.fields[z],tt=u(_,z),G=U.type==="i64"?"i64.store":U.type==="f32"?"f32.store":U.type==="f64"?"f64.store":"i32.store",Yt=U.type==="i64"?["i64.const",0n]:U.type==="f32"?["f32.const",0]:U.type==="f64"?["f64.const",0]:["i32.const",0];T.push([G,["i32.add",["local.get",M],["i32.const",tt]],Yt])}T.push(["local.get",M]),N[m]=["block",["result","i32"],...T]}if(p[0]==="struct.get"){let g=p[1],_=p[2],b=p[3],d=r.get(g);if(!d||d.kind!=="struct")return;let v=typeof _=="string"&&_[0]==="$"?h(d,_):parseInt(_);if(v<0)return;let M=d.fields[v],T=u(d,v),z=M.type==="i64"?"i64.load":M.type==="f32"?"f32.load":M.type==="f64"?"f64.load":"i32.load";N[m]=[z,["i32.add",b,["i32.const",T]]]}if(p[0]==="struct.set"){let g=p[1],_=p[2],b=p[3],d=p[4],v=r.get(g);if(!v||v.kind!=="struct")return;let M=typeof _=="string"&&_[0]==="$"?h(v,_):parseInt(_);if(M<0)return;let T=v.fields[M],z=u(v,M),U=T.type==="i64"?"i64.store":T.type==="f32"?"f32.store":T.type==="f64"?"f64.store":"i32.store";N[m]=[U,["i32.add",b,["i32.const",z]],d]}if(p[0]==="array.new"||p[0]==="array.new_default"){let g=p[1],_=r.get(g);if(!_||_.kind!=="array")return;let b=i.get(g),d=st[_.elemType]||4,v=p[0]==="array.new"?p[2]:null,M=p[0]==="array.new"?p[3]:p[2],T="$__gc_aptr",z="$__gc_alen",U="$__gc_aidx",tt=_.elemType==="i64"?"i64.store":_.elemType==="f32"?"f32.store":_.elemType==="f64"?"f64.store":"i32.store",G=[["local.set",z,M],["local.set",T,["call",n,["i32.add",["i32.const",8],["i32.mul",["local.get",z],["i32.const",d]]]]],["i32.store",["local.get",T],["i32.const",b]],["i32.store",["i32.add",["local.get",T],["i32.const",4]],["local.get",z]]];v&&G.push(["local.set",U,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",U],["local.get",z]]],[tt,["i32.add",["i32.add",["local.get",T],["i32.const",8]],["i32.mul",["local.get",U],["i32.const",d]]],v],["local.set",U,["i32.add",["local.get",U],["i32.const",1]]],["br","$loop"]]]),G.push(["local.get",T]),N[m]=["block",["result","i32"],...G]}if(p[0]==="array.get"){let g=p[1],_=p[2],b=p[3],d=r.get(g);if(!d||d.kind!=="array")return;let v=st[d.elemType]||4,M=d.elemType==="i64"?"i64.load":d.elemType==="f32"?"f32.load":d.elemType==="f64"?"f64.load":"i32.load";N[m]=[M,["i32.add",["i32.add",_,["i32.const",8]],["i32.mul",b,["i32.const",v]]]]}if(p[0]==="array.set"){let g=p[1],_=p[2],b=p[3],d=p[4],v=r.get(g);if(!v||v.kind!=="array")return;let M=st[v.elemType]||4,T=v.elemType==="i64"?"i64.store":v.elemType==="f32"?"f32.store":v.elemType==="f64"?"f64.store":"i32.store";N[m]=[T,["i32.add",["i32.add",_,["i32.const",8]],["i32.mul",b,["i32.const",M]]],d]}if(p[0]==="array.len"){let g=p[1];N[m]=["i32.load",["i32.add",g,["i32.const",4]]]}}}),t};P.gc=de;var be=(t,e)=>{let r=new Map,i=1;return S(t,s=>{if(!Array.isArray(s)||s[0]!=="type")return;let l=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(l)for(let n of s)Array.isArray(n)&&(n[0]==="struct"||n[0]==="array")&&r.set(l,i++)}),r.size&&j(t,(s,l,n)=>{if(!(!Array.isArray(s)||!l)){if(s[0]==="ref.test"){let a=s[1],c=null;Array.isArray(a)&&a[0]==="ref"&&(c=a[1]==="null"?a[2]:a[1]);let f=s[2],o=r.get(c);o!==void 0&&(l[n]=["if",["result","i32"],["i32.eqz",f],["then",["i32.const",0]],["else",["i32.eq",["i32.load",f],["i32.const",o]]]])}if(s[0]==="ref.cast"){let a=s[1],c=null,f=!1;Array.isArray(a)&&a[0]==="ref"&&(a[1]==="null"?(f=!0,c=a[2]):c=a[1]);let o=s[2],u=r.get(c);if(u!==void 0){let h=R("cast");f?l[n]=["block",["result","i32"],["local",h,"i32"],["local.set",h,o],["if",["i32.and",["i32.ne",["local.get",h],["i32.const",0]],["i32.ne",["i32.load",["local.get",h]],["i32.const",u]]],["then",["unreachable"]]],["local.get",h]]:l[n]=["block",["result","i32"],["local",h,"i32"],["local.set",h,o],["if",["i32.or",["i32.eqz",["local.get",h]],["i32.ne",["i32.load",["local.get",h]],["i32.const",u]]],["then",["unreachable"]]],["local.get",h]]}}if(s[0]==="br_on_cast"){let a=s[1],c=s[2],f=s[3],o=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let h=r.get(u);if(h!==void 0){let x=R("brcast");l[n]=["block",["result","i32"],["local",x,"i32"],["local.set",x,o],["br_if",a,["i32.and",["i32.ne",["local.get",x],["i32.const",0]],["i32.eq",["i32.load",["local.get",x]],["i32.const",h]]]],["local.get",x]]}}if(s[0]==="br_on_cast_fail"){let a=s[1],c=s[2],f=s[3],o=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let h=r.get(u);if(h!==void 0){let x=R("brfail");l[n]=["block",["result","i32"],["local",x,"i32"],["local.set",x,o],["br_if",a,["i32.or",["i32.eqz",["local.get",x]],["i32.ne",["i32.load",["local.get",x]],["i32.const",h]]]],["local.get",x]]}}}}),t};P.ref_cast=be;function yt(t,e=!0){typeof t=="string"&&(t=C(t)),t=Lt(t),e=ne(e);let r=fe(t),i={uid:0};for(let s of wt)r.has(s)&&e[s]!==!1&&P[s]&&(t=P[s](t,i));return t}var vt={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!0},$t=Object.keys(vt),Ae=t=>{if(t===!0)return{...vt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.size===1&&$t.includes([...e][0])?Object.fromEntries($t.map(r=>[r,e.has(r)])):Object.fromEntries($t.map(r=>[r,e.has(r)||e.has("all")]))}return{...vt,...t}},F=t=>Array.isArray(t)?t.map(F):t,H=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)H(t[s],e,t,s)},Y=(t,e,r,i)=>{if(Array.isArray(t))for(let l=0;l<t.length;l++){let n=Y(t[l],e,t,l);n!==void 0&&(t[l]=n)}let s=e(t,r,i);return s!==void 0?s:t},we=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=new Map,l=new Map,n=[],a=[],c=0,f=0,o=0,u=0,h=0,x=0;for(let m of t.slice(1)){if(!Array.isArray(m))continue;let g=m[0];if(g==="type"){let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:o;i.set(_,{node:m,idx:o,used:!1}),typeof _=="string"&&i.set(o,i.get(_)),o++}else if(g==="func"){let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:c,b=m.some(d=>Array.isArray(d)&&d[0]==="export");e.set(_,{node:m,idx:c,used:b}),typeof _=="string"&&e.set(c,e.get(_)),c++}else if(g==="global"){let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:f,b=m.some(d=>Array.isArray(d)&&d[0]==="export");r.set(_,{node:m,idx:f,used:b}),typeof _=="string"&&r.set(f,r.get(_)),f++}else if(g==="table"){let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:u,b=m.some(d=>Array.isArray(d)&&d[0]==="export");s.set(_,{node:m,idx:u,used:b}),typeof _=="string"&&s.set(u,s.get(_)),u++}else if(g==="memory"){let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:h,b=m.some(d=>Array.isArray(d)&&d[0]==="export");l.set(_,{node:m,idx:h,used:b}),typeof _=="string"&&l.set(h,l.get(_)),h++}else if(g==="import"){for(let _ of m)if(Array.isArray(_)&&_[0]==="func"){let b=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:x;e.set(b,{node:m,idx:x,used:!0,isImport:!0}),typeof b=="string"&&e.set(x,e.get(b)),x++,c++}}else g==="export"?n.push(m):g==="start"&&a.push(m)}for(let m of n)for(let g of m){if(!Array.isArray(g))continue;let[_,b]=g;_==="func"&&e.has(b)?e.get(b).used=!0:_==="global"&&r.has(b)?r.get(b).used=!0:_==="table"&&s.has(b)?s.get(b).used=!0:_==="memory"&&l.has(b)&&(l.get(b).used=!0)}for(let m of a){let g=m[1];typeof g=="string"&&g[0]!=="$"&&(g=+g),e.has(g)&&(e.get(g).used=!0)}let I=n.length>0||a.length>0;if(!I){for(let[,m]of e)if(m.used){I=!0;break}if(!I){for(let[,m]of r)if(m.used){I=!0;break}}if(!I){for(let[,m]of s)if(m.used){I=!0;break}}if(!I){for(let[,m]of l)if(m.used){I=!0;break}}}if(!I){for(let[,m]of e)m.used=!0;for(let[,m]of r)m.used=!0;for(let[,m]of s)m.used=!0;for(let[,m]of l)m.used=!0}for(let m of t.slice(1))!Array.isArray(m)||m[0]!=="elem"||H(m,g=>{if(Array.isArray(g)&&g[0]==="ref.func"){let _=g[1];e.has(_)&&(e.get(_).used=!0)}typeof g=="string"&&g[0]==="$"&&e.has(g)&&(e.get(g).used=!0)});let p=!0;for(;p;){p=!1;for(let[,m]of e)!m.used||m.isImport||H(m.node,g=>{if(!Array.isArray(g)){typeof g=="string"&&g[0]==="$"&&e.has(g)&&!e.get(g).used&&(e.get(g).used=!0,p=!0);return}let[_,b]=g;if((_==="call"||_==="return_call"||_==="ref.func")&&e.has(b)&&!e.get(b).used&&(e.get(b).used=!0,p=!0),(_==="global.get"||_==="global.set")&&r.has(b)&&!r.get(b).used&&(r.get(b).used=!0,p=!0),_==="call_indirect"||_==="return_call_indirect")for(let d of g)typeof d=="string"&&d[0]==="$"&&s.has(d)&&!s.get(d).used&&(s.get(d).used=!0,p=!0);_==="type"&&i.has(b)&&!i.get(b).used&&(i.get(b).used=!0,p=!0)})}let N=["module"];for(let m of t.slice(1)){if(!Array.isArray(m)){N.push(m);continue}let g=m[0];if(g==="func"){let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;(_?e.get(_):[...e.values()].find(d=>d.node===m))?.used&&N.push(m)}else if(g==="global"){let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;(_?r.get(_):[...r.values()].find(d=>d.node===m))?.used&&N.push(m)}else N.push(m)}return N},$e={"i32.add":(t,e)=>t+e|0,"i32.sub":(t,e)=>t-e|0,"i32.mul":(t,e)=>Math.imul(t,e),"i32.div_s":(t,e)=>e!==0?t/e|0:null,"i32.div_u":(t,e)=>e!==0?(t>>>0)/(e>>>0)|0:null,"i32.rem_s":(t,e)=>e!==0?t%e|0:null,"i32.rem_u":(t,e)=>e!==0?(t>>>0)%(e>>>0)|0:null,"i32.and":(t,e)=>t&e,"i32.or":(t,e)=>t|e,"i32.xor":(t,e)=>t^e,"i32.shl":(t,e)=>t<<(e&31),"i32.shr_s":(t,e)=>t>>(e&31),"i32.shr_u":(t,e)=>t>>>(e&31),"i32.rotl":(t,e)=>(e&=31,t<<e|t>>>32-e|0),"i32.rotr":(t,e)=>(e&=31,t>>>e|t<<32-e|0),"i32.eq":(t,e)=>t===e?1:0,"i32.ne":(t,e)=>t!==e?1:0,"i32.lt_s":(t,e)=>t<e?1:0,"i32.lt_u":(t,e)=>t>>>0<e>>>0?1:0,"i32.gt_s":(t,e)=>t>e?1:0,"i32.gt_u":(t,e)=>t>>>0>e>>>0?1:0,"i32.le_s":(t,e)=>t<=e?1:0,"i32.le_u":(t,e)=>t>>>0<=e>>>0?1:0,"i32.ge_s":(t,e)=>t>=e?1:0,"i32.ge_u":(t,e)=>t>>>0>=e>>>0?1:0,"i32.eqz":t=>t===0?1:0,"i32.clz":t=>Math.clz32(t),"i32.ctz":t=>t===0?32:31-Math.clz32(t&-t),"i32.popcnt":t=>{let e=0;for(;t;)e+=t&1,t>>>=1;return e},"i32.wrap_i64":t=>Number(BigInt.asIntN(32,t)),"i64.add":(t,e)=>BigInt.asIntN(64,t+e),"i64.sub":(t,e)=>BigInt.asIntN(64,t-e),"i64.mul":(t,e)=>BigInt.asIntN(64,t*e),"i64.div_s":(t,e)=>e!==0n?BigInt.asIntN(64,t/e):null,"i64.div_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)/BigInt.asUintN(64,e)):null,"i64.rem_s":(t,e)=>e!==0n?BigInt.asIntN(64,t%e):null,"i64.rem_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)%BigInt.asUintN(64,e)):null,"i64.and":(t,e)=>BigInt.asIntN(64,t&e),"i64.or":(t,e)=>BigInt.asIntN(64,t|e),"i64.xor":(t,e)=>BigInt.asIntN(64,t^e),"i64.shl":(t,e)=>BigInt.asIntN(64,t<<(e&63n)),"i64.shr_s":(t,e)=>BigInt.asIntN(64,t>>(e&63n)),"i64.shr_u":(t,e)=>BigInt.asUintN(64,BigInt.asUintN(64,t)>>(e&63n)),"i64.eq":(t,e)=>t===e?1:0,"i64.ne":(t,e)=>t!==e?1:0,"i64.lt_s":(t,e)=>t<e?1:0,"i64.lt_u":(t,e)=>BigInt.asUintN(64,t)<BigInt.asUintN(64,e)?1:0,"i64.gt_s":(t,e)=>t>e?1:0,"i64.gt_u":(t,e)=>BigInt.asUintN(64,t)>BigInt.asUintN(64,e)?1:0,"i64.le_s":(t,e)=>t<=e?1:0,"i64.le_u":(t,e)=>BigInt.asUintN(64,t)<=BigInt.asUintN(64,e)?1:0,"i64.ge_s":(t,e)=>t>=e?1:0,"i64.ge_u":(t,e)=>BigInt.asUintN(64,t)>=BigInt.asUintN(64,e)?1:0,"i64.eqz":t=>t===0n?1:0,"i64.extend_i32_s":t=>BigInt(t),"i64.extend_i32_u":t=>BigInt(t>>>0),"f32.add":(t,e)=>Math.fround(t+e),"f32.sub":(t,e)=>Math.fround(t-e),"f32.mul":(t,e)=>Math.fround(t*e),"f32.div":(t,e)=>Math.fround(t/e),"f32.neg":t=>Math.fround(-t),"f32.abs":t=>Math.fround(Math.abs(t)),"f32.sqrt":t=>Math.fround(Math.sqrt(t)),"f32.ceil":t=>Math.fround(Math.ceil(t)),"f32.floor":t=>Math.fround(Math.floor(t)),"f32.trunc":t=>Math.fround(Math.trunc(t)),"f32.nearest":t=>Math.fround(Math.round(t)),"f64.add":(t,e)=>t+e,"f64.sub":(t,e)=>t-e,"f64.mul":(t,e)=>t*e,"f64.div":(t,e)=>t/e,"f64.neg":t=>-t,"f64.abs":t=>Math.abs(t),"f64.sqrt":t=>Math.sqrt(t),"f64.ceil":t=>Math.ceil(t),"f64.floor":t=>Math.floor(t),"f64.trunc":t=>Math.trunc(t),"f64.nearest":t=>Math.round(t)},w=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},Pt=(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,ve=t=>Y(F(t),e=>{if(!Array.isArray(e))return;let r=e[0],i=$e[r];if(i){if(i.length===1&&e.length===2){let s=w(e[1]);if(!s)return;let l=i(s.value);if(l===null)return;let n=r.startsWith("i64.")&&!r.includes("eqz")?"i64":r.startsWith("f32.")?"f32":r.startsWith("f64.")?"f64":"i32";return Pt(n,l)}if(i.length===2&&e.length===3){let s=w(e[1]),l=w(e[2]);if(!s||!l)return;let n=i(s.value,l.value);if(n===null)return;let c=/\.(eq|ne|[lg][te])/.test(r)?"i32":r.startsWith("i64.")?"i64":r.startsWith("f32.")?"f32":r.startsWith("f64.")?"f64":"i32";return Pt(c,n)}}}),Ie={"i32.add":(t,e)=>{let r=w(t),i=w(e);return r?.value===0?e:i?.value===0?t:null},"i64.add":(t,e)=>{let r=w(t),i=w(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.sub":(t,e)=>w(e)?.value===0?t:null,"i64.sub":(t,e)=>w(e)?.value===0n?t:null,"i32.mul":(t,e)=>{let r=w(t),i=w(e);return r?.value===1?e:i?.value===1?t:null},"i64.mul":(t,e)=>{let r=w(t),i=w(e);return r?.value===1n?e:i?.value===1n?t:null},"i32.div_s":(t,e)=>w(e)?.value===1?t:null,"i32.div_u":(t,e)=>w(e)?.value===1?t:null,"i64.div_s":(t,e)=>w(e)?.value===1n?t:null,"i64.div_u":(t,e)=>w(e)?.value===1n?t:null,"i32.and":(t,e)=>{let r=w(t),i=w(e);return r?.value===-1?e:i?.value===-1?t:null},"i64.and":(t,e)=>{let r=w(t),i=w(e);return r?.value===-1n?e:i?.value===-1n?t:null},"i32.or":(t,e)=>{let r=w(t),i=w(e);return r?.value===0?e:i?.value===0?t:null},"i64.or":(t,e)=>{let r=w(t),i=w(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.xor":(t,e)=>{let r=w(t),i=w(e);return r?.value===0?e:i?.value===0?t:null},"i64.xor":(t,e)=>{let r=w(t),i=w(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.shl":(t,e)=>w(e)?.value===0?t:null,"i32.shr_s":(t,e)=>w(e)?.value===0?t:null,"i32.shr_u":(t,e)=>w(e)?.value===0?t:null,"i64.shl":(t,e)=>w(e)?.value===0n?t:null,"i64.shr_s":(t,e)=>w(e)?.value===0n?t:null,"i64.shr_u":(t,e)=>w(e)?.value===0n?t:null},Ne=t=>Y(F(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let r=Ie[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),ke=t=>Y(F(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let l=w(s);if(l&&l.value>0&&!(l.value&l.value-1)){let a=Math.log2(l.value);if(Number.isInteger(a))return["i32.shl",i,["i32.const",a]]}let n=w(i);if(n&&n.value>0&&!(n.value&n.value-1)){let a=Math.log2(n.value);if(Number.isInteger(a))return["i32.shl",s,["i32.const",a]]}}if(r==="i64.mul"){let l=w(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let a=BigInt(l.value.toString(2).length-1);return["i64.shl",i,["i64.const",a]]}let n=w(i);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let a=BigInt(n.value.toString(2).length-1);return["i64.shl",s,["i64.const",a]]}}if(r==="i32.div_u"){let l=w(s);if(l&&l.value>0&&!(l.value&l.value-1)){let n=Math.log2(l.value);if(Number.isInteger(n))return["i32.shr_u",i,["i32.const",n]]}}if(r==="i64.div_u"){let l=w(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let n=BigInt(l.value.toString(2).length-1);return["i64.shr_u",i,["i64.const",n]]}}if(r==="i32.rem_u"){let l=w(s);if(l&&l.value>0&&!(l.value&l.value-1))return["i32.and",i,["i32.const",l.value-1]]}if(r==="i64.rem_u"){let l=w(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n)return["i64.and",i,["i64.const",l.value-1n]]}}),Be=t=>Y(F(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let i=1;for(;i<e.length;){let c=e[i];if(Array.isArray(c)&&(c[0]==="then"||c[0]==="else"||c[0]==="result"||c[0]==="param")){i++;continue}break}let s=e[i],l=w(s);if(!l)return;let n=null,a=null;for(let c=i+1;c<e.length;c++){let f=e[c];Array.isArray(f)&&(f[0]==="then"?n=f:f[0]==="else"&&(a=f))}if(l.value!==0&&l.value!==0n){if(n&&n.length>1){let c=n.slice(1);return c.length===1?c[0]:["block",...c]}return["nop"]}else{if(a&&a.length>1){let c=a.slice(1);return c.length===1?c[0]:["block",...c]}return["nop"]}}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=w(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=w(i);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),jt=new Set(["unreachable","return","br","br_table"]),Me=t=>{let e=F(t);return H(e,r=>{if(!Array.isArray(r))return;let i=r[0];if((i==="func"||i==="block"||i==="loop")&&Rt(r),i==="if")for(let s=1;s<r.length;s++)Array.isArray(r[s])&&(r[s][0]==="then"||r[s][0]==="else")&&Rt(r[s])}),e},Rt=t=>{let e=!1,r=-1;for(let i=1;i<t.length;i++){let s=t[i];if(Array.isArray(s)){let l=s[0];if(l==="param"||l==="result"||l==="local"||l==="type"||l==="export")continue;e&&r===-1&&(r=i),jt.has(l)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),jt.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},ze=t=>{let e=F(t);return H(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=[],s=new Map,l=new Set;for(let n=1;n<r.length;n++){let a=r[n];Array.isArray(a)&&(a[0]==="local"&&(i.push({idx:n,node:a}),typeof a[1]=="string"&&a[1][0]==="$"&&s.set(a[1],a[2])),a[0]==="param"&&typeof a[1]=="string"&&a[1][0]==="$"&&(s.set(a[1],a[2]),l.add(a[1])))}H(r,n=>{if(!Array.isArray(n))return;let a=n[0];if(a==="local.get"||a==="local.set"||a==="local.tee"){let c=n[1];typeof c=="string"&&l.add(c)}});for(let n=i.length-1;n>=0;n--){let{idx:a,node:c}=i[n],f=typeof c[1]=="string"&&c[1][0]==="$"?c[1]:null;f&&!l.has(f)&&r.splice(a,1)}}),e},Ue=t=>{let e=F(t);return H(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=new Map;((l,n=1)=>{for(let a=n;a<l.length;a++){let c=l[a];if(!Array.isArray(c))continue;let f=c[0];if(f==="local.set"&&c.length===3){let o=c[1],u=c[2];w(u)&&typeof o=="string"?i.set(o,u):typeof o=="string"&&i.delete(o)}else if(f==="local.tee"&&c.length===3){let o=c[1],u=c[2];w(u)&&typeof o=="string"?i.set(o,u):typeof o=="string"&&i.delete(o)}else if(f==="local.get"&&c.length===2){let o=c[1];if(typeof o=="string"&&i.has(o)){let u=i.get(o);c.length=0,c.push(...F(u))}}else(f==="block"||f==="loop"||f==="if"||f==="call"||f==="call_indirect")&&i.clear();Y(c,o=>{if(!Array.isArray(o)||o[0]!=="local.get"||o.length!==2)return;let u=o[1];if(typeof u=="string"&&i.has(u)){let h=i.get(u);return F(h)}})}})(r)}),e},Te=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=F(t),r=new Map;for(let i of e.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 l=[],n=[],a=!1,c=!1;for(let f=1;f<i.length;f++){let o=i[f];if(Array.isArray(o))if(o[0]==="param")if(typeof o[1]=="string"&&o[1][0]==="$")l.push({name:o[1],type:o[2]});else{l=null;break}else o[0]==="local"?a=!0:o[0]==="export"?c=!0:o[0]!=="result"&&o[0]!=="type"&&n.push(o)}if(l&&!a&&!c&&l.length<=2&&n.length===1){let f=new Set(l.map(u=>u.name)),o=!1;H(n[0],u=>{Array.isArray(u)&&(u[0]==="local.set"||u[0]==="local.tee")&&f.has(u[1])&&(o=!0)}),o||r.set(s,{body:n[0],params:l})}}return r.size===0||Y(e,i=>{if(!Array.isArray(i)||i[0]!=="call")return;let s=i[1];if(!r.has(s))return;let{body:l,params:n}=r.get(s),a=i.slice(2);if(n.length===0)return F(l);let c=F(l);return Y(c,f=>{if(!Array.isArray(f)||f[0]!=="local.get")return;let o=f[1],u=n.findIndex(h=>h.name===o);if(u!==-1&&a[u])return F(a[u])}),c}),e};function gt(t,e=!0){return typeof t=="string"&&(t=C(t)),t=F(t),e=Ae(e),e.fold&&(t=ve(t)),e.identity&&(t=Ne(t)),e.strength&&(t=ke(t)),e.branch&&(t=Be(t)),e.propagate&&(t=Ue(t)),e.inline&&(t=Te(t)),e.deadcode&&(t=Me(t)),e.locals&&(t=ze(t)),e.treeshake&&(t=we(t)),t}var Vt="\uE000",Ht=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},Ee=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t;return Ht(r)?Ht(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 It(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=It(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function qe(t,e){let r=[],i=new Map;return It(t,s=>{if(!Array.isArray(s))return s;if(s[0]==="call"&&typeof s[1]=="function"){let l=s[1];if(!i.has(l)){let a=[];for(let o=2;o<s.length;o++){let u=Ee(s[o]);u&&a.push(u)}let c=r.length,f=l.name||`$fn${c}`;i.set(l,{idx:c,name:f.startsWith("$")?f:"$"+f,params:a,fn:l}),r.push(i.get(l))}let n=i.get(l);s[1]=n.name}return s}),r}function Se(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function Oe(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]instanceof Uint8Array)&&(r=e.pop()),Array.isArray(t)&&t.raw){let i=t[0];for(let f=0;f<e.length;f++)i+=Vt+t[f+1];let s=C(i),l=[],n=0;s=It(s,f=>{if(f===Vt){let o=e[n++];if(typeof o=="function")return l.push(o),o;if(typeof o=="string"&&(o[0]==="("||/^\s*\(/.test(o))){let u=C(o);return Array.isArray(u)&&Array.isArray(u[0])&&(u._splice=!0),u}return o instanceof Uint8Array?[...o]:o}return f});let a=null;if(l.length){let f=qe(s,l);if(f.length){let o=Se(f);s[0]==="module"?s.splice(1,0,...o):typeof s[0]=="string"?s=[...o,s]:s.unshift(...o),a={env:{}};for(let u of f)a.env[u.name.slice(1)]=u.fn}}r.polyfill&&(s=yt(s,r.polyfill)),r.optimize&&(s=gt(s,r.optimize));let c=Q(s);return a&&(c._imports=a),c}if(r.polyfill||r.optimize){let i=typeof t=="string"?C(t):t;return r.polyfill&&(i=yt(i,r.polyfill)),r.optimize&&(i=gt(i,r.optimize)),Q(i)}return Q(t)}function Fe(t,...e){let r=Oe(t,...e),i=new WebAssembly.Module(r);return new WebAssembly.Instance(i,r._imports).exports}var nr=Fe;export{Oe as compile,nr as default,gt as optimize,C as parse,yt as polyfill,Ft as print,Fe as watr};
|
package/package.json
CHANGED
package/src/compile.js
CHANGED
|
@@ -7,7 +7,7 @@ import { err, unescape, str } from './util.js'
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Clean up AST: remove comments, normalize quoted ids, convert strings to bytes.
|
|
10
|
-
* Preserves @custom and @metadata.code.* annotations. Preserves .
|
|
10
|
+
* Preserves @custom and @metadata.code.* annotations. Preserves .loc for error reporting.
|
|
11
11
|
*
|
|
12
12
|
* @param {any} node - AST node
|
|
13
13
|
* @param {Array} [result] - Internal accumulator
|
|
@@ -25,8 +25,8 @@ const cleanup = (node, result) => !Array.isArray(node) ? (
|
|
|
25
25
|
) :
|
|
26
26
|
// remove annotations like (@name ...) except @custom and @metadata.code.*
|
|
27
27
|
node[0]?.[0] === '@' && node[0] !== '@custom' && !node[0]?.startsWith?.('@metadata.code.') ? null :
|
|
28
|
-
// unwrap single-element array containing module (after removing comments), preserve .
|
|
29
|
-
(result = node.map(cleanup).filter(n => n != null), result.
|
|
28
|
+
// unwrap single-element array containing module (after removing comments), preserve .loc
|
|
29
|
+
(result = node.map(cleanup).filter(n => n != null), result.loc = node.loc, result.length === 1 && result[0]?.[0] === 'module' ? result[0] : result)
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -39,7 +39,7 @@ export default function compile(nodes) {
|
|
|
39
39
|
// normalize to (module ...) form
|
|
40
40
|
if (typeof nodes === 'string') err.src = nodes, nodes = parse(nodes) || []
|
|
41
41
|
else err.src = '' // clear source if AST passed directly
|
|
42
|
-
err.
|
|
42
|
+
err.loc = 0
|
|
43
43
|
|
|
44
44
|
nodes = cleanup(nodes) || []
|
|
45
45
|
|
|
@@ -64,12 +64,22 @@ export default function compile(nodes) {
|
|
|
64
64
|
// initialize types
|
|
65
65
|
nodes.slice(idx).filter((n) => {
|
|
66
66
|
if (!Array.isArray(n)) {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
// find token as standalone word (not substring of another token)
|
|
68
|
+
let pos = err.loc, src = err.src, c
|
|
69
|
+
while ((pos = src.indexOf(n, pos)) >= 0) {
|
|
70
|
+
c = src.charCodeAt(pos - 1)
|
|
71
|
+
// check not preceded by word char or $
|
|
72
|
+
if (pos > 0 && (c > 47 && c < 58 || c > 64 && c < 91 || c > 96 && c < 123 || c === 95 || c === 36)) { pos++; continue }
|
|
73
|
+
c = src.charCodeAt(pos + n.length)
|
|
74
|
+
// check not followed by word char
|
|
75
|
+
if (c > 47 && c < 58 || c > 64 && c < 91 || c > 96 && c < 123 || c === 95) { pos++; continue }
|
|
76
|
+
break
|
|
77
|
+
}
|
|
78
|
+
if (pos >= 0) err.loc = pos
|
|
69
79
|
err(`Unexpected token ${n}`)
|
|
70
80
|
}
|
|
71
81
|
let [kind, ...node] = n
|
|
72
|
-
err.
|
|
82
|
+
err.loc = n.loc // track position for errors
|
|
73
83
|
// (@custom "name" placement? data) - custom section support
|
|
74
84
|
if (kind === '@custom') {
|
|
75
85
|
ctx.custom.push(node)
|
|
@@ -103,7 +113,7 @@ export default function compile(nodes) {
|
|
|
103
113
|
// prepare/normalize nodes
|
|
104
114
|
.forEach((n) => {
|
|
105
115
|
let [kind, ...node] = n
|
|
106
|
-
err.
|
|
116
|
+
err.loc = n.loc // track position for errors
|
|
107
117
|
let imported // if node needs to be imported
|
|
108
118
|
|
|
109
119
|
// import abbr
|
|
@@ -266,7 +276,7 @@ function normalize(nodes, ctx) {
|
|
|
266
276
|
}
|
|
267
277
|
else if (Array.isArray(node)) {
|
|
268
278
|
const op = node[0]
|
|
269
|
-
node.
|
|
279
|
+
node.loc != null && (err.loc = node.loc) // track position for errors
|
|
270
280
|
|
|
271
281
|
// code metadata annotations - pass through as marker with metadata type and data
|
|
272
282
|
// (@metadata.code.<type> data:str)
|
|
@@ -851,7 +861,7 @@ const instr = (nodes, ctx) => {
|
|
|
851
861
|
|
|
852
862
|
// Array = unknown instruction passed through from normalize
|
|
853
863
|
if (Array.isArray(op)) {
|
|
854
|
-
op.
|
|
864
|
+
op.loc != null && (err.loc = op.loc)
|
|
855
865
|
err(`Unknown instruction ${op[0]}`)
|
|
856
866
|
}
|
|
857
867
|
|
package/src/optimize.js
CHANGED
|
@@ -178,7 +178,9 @@ const treeshake = (ast) => {
|
|
|
178
178
|
|
|
179
179
|
// Mark start function as used
|
|
180
180
|
for (const start of starts) {
|
|
181
|
-
|
|
181
|
+
let ref = start[1]
|
|
182
|
+
// Convert numeric string refs to numbers
|
|
183
|
+
if (typeof ref === 'string' && ref[0] !== '$') ref = +ref
|
|
182
184
|
if (funcs.has(ref)) funcs.get(ref).used = true
|
|
183
185
|
}
|
|
184
186
|
|
|
@@ -970,7 +972,18 @@ const inline = (ast) => {
|
|
|
970
972
|
|
|
971
973
|
// Only inline: no locals, <= 2 params, single expression body, not exported
|
|
972
974
|
if (params && !hasLocals && !hasExport && params.length <= 2 && body.length === 1) {
|
|
973
|
-
|
|
975
|
+
// Check if function mutates any of its params (local.set/tee on param)
|
|
976
|
+
const paramNames = new Set(params.map(p => p.name))
|
|
977
|
+
let mutatesParam = false
|
|
978
|
+
walk(body[0], (n) => {
|
|
979
|
+
if (!Array.isArray(n)) return
|
|
980
|
+
if ((n[0] === 'local.set' || n[0] === 'local.tee') && paramNames.has(n[1])) {
|
|
981
|
+
mutatesParam = true
|
|
982
|
+
}
|
|
983
|
+
})
|
|
984
|
+
if (!mutatesParam) {
|
|
985
|
+
inlinable.set(name, { body: body[0], params })
|
|
986
|
+
}
|
|
974
987
|
}
|
|
975
988
|
}
|
|
976
989
|
|
package/src/parse.js
CHANGED
|
@@ -2,7 +2,7 @@ import { err } from "./util.js"
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Parses a wasm text string and constructs a nested array structure (AST).
|
|
5
|
-
* Each array node has `.
|
|
5
|
+
* Each array node has `.loc` property with source offset for error reporting.
|
|
6
6
|
*
|
|
7
7
|
* @param {string} str - The input string with WAT code to parse.
|
|
8
8
|
* @returns {Array} An array representing the nested syntax tree (AST).
|
|
@@ -13,7 +13,7 @@ export default (str) => {
|
|
|
13
13
|
const commit = () => buf && (level.push(buf), buf = '')
|
|
14
14
|
|
|
15
15
|
const parseLevel = (pos) => {
|
|
16
|
-
level.
|
|
16
|
+
level.loc = pos // store start position for error reporting
|
|
17
17
|
for (let c, root, p; i < str.length;) {
|
|
18
18
|
c = str.charCodeAt(i)
|
|
19
19
|
|
package/src/util.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Throws an error with optional source position.
|
|
3
|
-
* Uses err.src for source and err.
|
|
4
|
-
* If pos provided or err.
|
|
3
|
+
* Uses err.src for source and err.loc for default position.
|
|
4
|
+
* If pos provided or err.loc set, appends "at line:col".
|
|
5
5
|
*
|
|
6
6
|
* @param {string} text - Error message
|
|
7
|
-
* @param {number} [pos] - Byte offset in source (defaults to err.
|
|
7
|
+
* @param {number} [pos] - Byte offset in source (defaults to err.loc)
|
|
8
8
|
* @throws {Error}
|
|
9
9
|
*/
|
|
10
|
-
export const err = (text, pos=err.
|
|
10
|
+
export const err = (text, pos=err.loc) => {
|
|
11
11
|
if (pos != null && err.src) {
|
|
12
12
|
let line = 1, col = 1
|
|
13
13
|
for (let i = 0; i < pos && i < err.src.length; i++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.js"],"names":[],"mappings":"AA+BA;;;;;GAKG;AACH,uCAHW,MAAM,QAAM,GACV,UAAU,
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.js"],"names":[],"mappings":"AA+BA;;;;;GAKG;AACH,uCAHW,MAAM,QAAM,GACV,UAAU,CA6LtB"}
|
|
@@ -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":"AAioCA;;;;;;;;;;;GAWG;AACH,sCATW,QAAM,MAAM,SACZ,OAAO,GAAC,MAAM,MAAO,SAwB/B;AAtkCD;;;;;GAKG;AACH,6CA8LC;AAyHD;;;;GAIG;AACH,wCAmCC;AAwQD;;;;GAIG;AACH,4CAuBC;AA+CD;;;;;GAKG;AACH,8CAqDC;AApTD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CA6DC;AAID;;;;GAIG;AACH,0CA0EC;AAiJD;;;;;GAKG;AACH,6CAuEC;AAID;;;;GAIG;AACH,0CAwFC;AAn+BD;;;;GAIG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAe/B"}
|
package/types/src/util.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Throws an error with optional source position.
|
|
3
|
-
* Uses err.src for source and err.
|
|
4
|
-
* If pos provided or err.
|
|
3
|
+
* Uses err.src for source and err.loc for default position.
|
|
4
|
+
* If pos provided or err.loc set, appends "at line:col".
|
|
5
5
|
*
|
|
6
6
|
* @param {string} text - Error message
|
|
7
|
-
* @param {number} [pos] - Byte offset in source (defaults to err.
|
|
7
|
+
* @param {number} [pos] - Byte offset in source (defaults to err.loc)
|
|
8
8
|
* @throws {Error}
|
|
9
9
|
*/
|
|
10
10
|
export const err: (text: string, pos?: number) => never;
|
package/types/src/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,mBAAoB,MAJT,MAIa,EAAE,MAHf,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,mBAAoB,MAJT,MAIa,EAAE,MAHf,MAG0B,WAUpC;AAOM,2CAAkF;AAEzF,8DAA8D;AAC9D,2BAAiD;AAEjD,6DAA6D;AAC7D,2BAAiD;AAe1C,uBAHI,MAAM,GACJ,MAAM,EAAE,CA8BpB;AAUM,4BAHI,MAAM,GACJ,MAAM,CAE6C"}
|