watr 4.3.0 → 4.3.3

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 CHANGED
@@ -14,7 +14,8 @@ __export(encode_exports, {
14
14
  i64: () => i64,
15
15
  i8: () => i8,
16
16
  uleb: () => uleb,
17
- uleb5: () => uleb5
17
+ uleb5: () => uleb5,
18
+ v128: () => v128
18
19
  });
19
20
 
20
21
  // src/util.js
@@ -116,7 +117,8 @@ i32.parse = (n) => {
116
117
  };
117
118
  function i64(n, buffer = []) {
118
119
  if (typeof n === "string") n = i64.parse(n);
119
- else if (typeof n === "bigint" && n > 0x7fffffffffffffffn) {
120
+ else if (typeof n === "number") n = BigInt(n);
121
+ if (typeof n === "bigint" && n > 0x7fffffffffffffffn) {
120
122
  n = n - 0x10000000000000000n;
121
123
  }
122
124
  while (true) {
@@ -130,14 +132,19 @@ function i64(n, buffer = []) {
130
132
  }
131
133
  return buffer;
132
134
  }
135
+ var _buf = new ArrayBuffer(8);
136
+ var _u8 = new Uint8Array(_buf);
137
+ var _i32 = new Int32Array(_buf);
138
+ var _f32 = new Float32Array(_buf);
139
+ var _f64 = new Float64Array(_buf);
140
+ var _i64 = new BigInt64Array(_buf);
133
141
  i64.parse = (n) => {
134
142
  n = cleanInt(n);
135
143
  n = n[0] === "-" ? -BigInt(n.slice(1)) : BigInt(n);
136
144
  if (n < -0x8000000000000000n || n > 0xffffffffffffffffn) err(`i64 constant out of range`);
137
- byteView.setBigInt64(0, n);
138
- return byteView.getBigInt64(0);
145
+ _i64[0] = n;
146
+ return _i64[0];
139
147
  };
140
- var byteView = new DataView(new Float64Array(1).buffer);
141
148
  var F32_SIGN = 2147483648;
142
149
  var F32_NAN = 2139095040;
143
150
  function f32(input, value, idx) {
@@ -145,17 +152,12 @@ function f32(input, value, idx) {
145
152
  value = i32.parse(input.slice(idx + 4));
146
153
  value |= F32_NAN;
147
154
  if (input[0] === "-") value |= F32_SIGN;
148
- byteView.setInt32(0, value);
155
+ _i32[0] = value;
149
156
  } else {
150
157
  value = typeof input === "string" ? f32.parse(input) : input;
151
- byteView.setFloat32(0, value);
158
+ _f32[0] = value;
152
159
  }
153
- return [
154
- byteView.getUint8(3),
155
- byteView.getUint8(2),
156
- byteView.getUint8(1),
157
- byteView.getUint8(0)
158
- ];
160
+ return [_u8[0], _u8[1], _u8[2], _u8[3]];
159
161
  }
160
162
  var F64_SIGN = 0x8000000000000000n;
161
163
  var F64_NAN = 0x7ff0000000000000n;
@@ -164,21 +166,12 @@ function f64(input, value, idx) {
164
166
  value = i64.parse(input.slice(idx + 4));
165
167
  value |= F64_NAN;
166
168
  if (input[0] === "-") value |= F64_SIGN;
167
- byteView.setBigInt64(0, value);
169
+ _i64[0] = value;
168
170
  } else {
169
171
  value = typeof input === "string" ? f64.parse(input) : input;
170
- byteView.setFloat64(0, value);
172
+ _f64[0] = value;
171
173
  }
172
- return [
173
- byteView.getUint8(7),
174
- byteView.getUint8(6),
175
- byteView.getUint8(5),
176
- byteView.getUint8(4),
177
- byteView.getUint8(3),
178
- byteView.getUint8(2),
179
- byteView.getUint8(1),
180
- byteView.getUint8(0)
181
- ];
174
+ return [_u8[0], _u8[1], _u8[2], _u8[3], _u8[4], _u8[5], _u8[6], _u8[7]];
182
175
  }
183
176
  f64.parse = (input, max = Number.MAX_VALUE) => {
184
177
  input = input.replaceAll("_", "");
@@ -202,6 +195,12 @@ f64.parse = (input, max = Number.MAX_VALUE) => {
202
195
  return sign * parseFloat(input);
203
196
  };
204
197
  f32.parse = (input) => f64.parse(input, 34028234663852886e22);
198
+ var v128 = (input) => {
199
+ let n = typeof input === "string" ? BigInt(input.replaceAll("_", "")) : BigInt(input);
200
+ let arr = new Uint8Array(16);
201
+ for (let i = 0; i < 16; i++) arr[i] = Number(n & 0xffn), n >>= 8n;
202
+ return [...arr];
203
+ };
205
204
 
206
205
  // src/const.js
207
206
  var INSTR = [
@@ -515,7 +514,157 @@ var INSTR = [
515
514
  "ref.cast_desc_eq reftype",
516
515
  ,
517
516
  "br_on_cast_desc_eq reftype2",
518
- "br_on_cast_desc_eq_fail reftype2"
517
+ "br_on_cast_desc_eq_fail reftype2",
518
+ ,
519
+ ,
520
+ ,
521
+ ,
522
+ ,
523
+ ,
524
+ ,
525
+ ,
526
+ ,
527
+ ,
528
+ ,
529
+ ,
530
+ ,
531
+ ,
532
+ ,
533
+ ,
534
+ ,
535
+ ,
536
+ ,
537
+ ,
538
+ ,
539
+ ,
540
+ ,
541
+ ,
542
+ ,
543
+ ,
544
+ ,
545
+ ,
546
+ ,
547
+ ,
548
+ ,
549
+ ,
550
+ ,
551
+ ,
552
+ ,
553
+ ,
554
+ ,
555
+ ,
556
+ ,
557
+ ,
558
+ ,
559
+ ,
560
+ ,
561
+ ,
562
+ ,
563
+ ,
564
+ ,
565
+ ,
566
+ ,
567
+ ,
568
+ ,
569
+ ,
570
+ ,
571
+ ,
572
+ ,
573
+ ,
574
+ ,
575
+ ,
576
+ ,
577
+ ,
578
+ ,
579
+ ,
580
+ ,
581
+ ,
582
+ ,
583
+ ,
584
+ ,
585
+ ,
586
+ ,
587
+ ,
588
+ ,
589
+ ,
590
+ ,
591
+ ,
592
+ ,
593
+ ,
594
+ ,
595
+ ,
596
+ ,
597
+ ,
598
+ ,
599
+ ,
600
+ ,
601
+ ,
602
+ ,
603
+ ,
604
+ ,
605
+ ,
606
+ ,
607
+ // stringref: 0xFB 0x80-0xB7
608
+ "string.new_utf8 memoryidx?",
609
+ "string.new_wtf16 memoryidx?",
610
+ "string.const stringidx",
611
+ "string.measure_utf8",
612
+ "string.measure_wtf8",
613
+ "string.measure_wtf16",
614
+ "string.encode_utf8 memoryidx?",
615
+ "string.encode_wtf16 memoryidx?",
616
+ "string.concat",
617
+ "string.eq",
618
+ "string.is_usv_sequence",
619
+ "string.new_lossy_utf8 memoryidx?",
620
+ "string.new_wtf8 memoryidx?",
621
+ "string.encode_lossy_utf8 memoryidx?",
622
+ "string.encode_wtf8 memoryidx?",
623
+ ,
624
+ // 0x8F
625
+ "string.as_wtf8",
626
+ "stringview_wtf8.advance",
627
+ "stringview_wtf8.encode_utf8 memoryidx?",
628
+ "stringview_wtf8.slice",
629
+ "stringview_wtf8.encode_lossy_utf8 memoryidx?",
630
+ "stringview_wtf8.encode_wtf8 memoryidx?",
631
+ ,
632
+ ,
633
+ // 0x96-0x97
634
+ "string.as_wtf16",
635
+ "stringview_wtf16.length",
636
+ "stringview_wtf16.get_codeunit",
637
+ "stringview_wtf16.encode memoryidx?",
638
+ "stringview_wtf16.slice",
639
+ ,
640
+ ,
641
+ ,
642
+ // 0x9D-0x9F
643
+ "string.as_iter",
644
+ "stringview_iter.next",
645
+ "stringview_iter.advance",
646
+ "stringview_iter.rewind",
647
+ "stringview_iter.slice",
648
+ ,
649
+ ,
650
+ ,
651
+ ,
652
+ ,
653
+ ,
654
+ ,
655
+ ,
656
+ ,
657
+ ,
658
+ ,
659
+ // 0xA5-0xAF
660
+ "string.new_utf8_array",
661
+ "string.new_wtf16_array",
662
+ "string.encode_utf8_array",
663
+ "string.encode_wtf16_array",
664
+ "string.new_lossy_utf8_array",
665
+ "string.new_wtf8_array",
666
+ "string.encode_lossy_utf8_array",
667
+ "string.encode_wtf8_array"
519
668
  ],
520
669
  // 0xfc: Bulk memory/table operations (nested array)
521
670
  [
@@ -905,7 +1054,7 @@ var INSTR = [
905
1054
  "i64.atomic.rmw32.cmpxchg_u memarg"
906
1055
  ]
907
1056
  ];
908
- var SECTION = { 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 };
1057
+ var SECTION = { custom: 0, type: 1, import: 2, func: 3, table: 4, memory: 5, tag: 13, strings: 14, global: 6, export: 7, start: 8, elem: 9, datacount: 12, code: 10, data: 11 };
909
1058
  var TYPE = {
910
1059
  // Value types
911
1060
  i8: 120,
@@ -932,6 +1081,11 @@ var TYPE = {
932
1081
  cont: 104,
933
1082
  nocont: 117,
934
1083
  // stack switching (Phase 3)
1084
+ string: 103,
1085
+ stringview_wtf8: 102,
1086
+ stringview_wtf16: 96,
1087
+ stringview_iter: 97,
1088
+ // stringref
935
1089
  // Reference type abbreviations (absheaptype abbrs)
936
1090
  nullfuncref: 115,
937
1091
  nullexternref: 114,
@@ -948,6 +1102,8 @@ var TYPE = {
948
1102
  contref: 104,
949
1103
  nocontref: 117,
950
1104
  // stack switching abbreviations
1105
+ stringref: 103,
1106
+ // stringref abbreviation
951
1107
  // ref, refnull
952
1108
  ref: 100,
953
1109
  // -0x1c
@@ -977,10 +1133,10 @@ var parse_default = (str2) => {
977
1133
  buf += str2[i++]
978
1134
  )
979
1135
  );
980
- else if (q < 0) c === 10 || c === 13 ? (buf += str2[i++], commit(), q = 0) : buf += str2[i++];
1136
+ else if (q < 0) c === 10 || c === 13 ? (buf += str2[i++], commit(), q = 0) : q === -2 && c === 41 ? (commit(), q = 0) : buf += str2[i++];
981
1137
  else if (c === 34) buf !== "$" && commit(), q = 34, buf += str2[i++];
982
1138
  else if (c === 40 && str2.charCodeAt(i + 1) === 59) commit(), q = 60, buf = str2[i++] + str2[i++];
983
- else if (c === 59 && str2.charCodeAt(i + 1) === 59) commit(), q = -1, buf = str2[i++] + str2[i++];
1139
+ else if (c === 59 && str2.charCodeAt(i + 1) === 59) commit(), q = str2.indexOf("\n", i) < 0 ? -2 : -1, buf = str2[i++] + str2[i++];
984
1140
  else if (c === 40 && str2.charCodeAt(i + 1) === 64) commit(), p = i, i += 2, buf = "@", depth++, (root = level).push(level = []), parseLevel(p), level = root;
985
1141
  else if (c === 40) commit(), p = i++, depth++, (root = level).push(level = []), parseLevel(p), level = root;
986
1142
  else if (c === 41) return commit(), i++, depth--;
@@ -1135,6 +1291,12 @@ function compile(nodes) {
1135
1291
  }
1136
1292
  return sections;
1137
1293
  };
1294
+ const globalSection = bin(SECTION.global);
1295
+ const elemSection = bin(SECTION.elem);
1296
+ const codeSection = bin(SECTION.code);
1297
+ const metaSection = binMeta();
1298
+ const dataSection = bin(SECTION.data);
1299
+ const stringsSection = ctx.strings.length ? [SECTION.strings, ...vec([0, ...vec(ctx.strings.map((s) => vec(s)))])] : [];
1138
1300
  return Uint8Array.from([
1139
1301
  0,
1140
1302
  97,
@@ -1153,14 +1315,15 @@ function compile(nodes) {
1153
1315
  ...bin(SECTION.table),
1154
1316
  ...bin(SECTION.memory),
1155
1317
  ...bin(SECTION.tag),
1156
- ...bin(SECTION.global),
1318
+ ...stringsSection,
1319
+ ...globalSection,
1157
1320
  ...bin(SECTION.export),
1158
1321
  ...bin(SECTION.start, false),
1159
- ...bin(SECTION.elem),
1322
+ ...elemSection,
1160
1323
  ...bin(SECTION.datacount, false),
1161
- ...bin(SECTION.code),
1162
- ...binMeta(),
1163
- ...bin(SECTION.data)
1324
+ ...codeSection,
1325
+ ...metaSection,
1326
+ ...dataSection
1164
1327
  ]);
1165
1328
  }
1166
1329
  var isIdx = (n) => n?.[0] === "$" || !isNaN(n);
@@ -1229,7 +1392,7 @@ function normalize(nodes, ctx) {
1229
1392
  out.push(...normalize(parts, ctx), "end");
1230
1393
  } else {
1231
1394
  const imm = [];
1232
- while (parts.length && (!Array.isArray(parts[0]) || "type,param,result,ref,exact,on".includes(parts[0][0]))) imm.push(parts.shift());
1395
+ while (parts.length && (!Array.isArray(parts[0]) || parts[0].valueOf !== Array.prototype.valueOf || "type,param,result,ref,exact,on".includes(parts[0][0]))) imm.push(parts.shift());
1233
1396
  out.push(...normalize(parts, ctx), op, ...imm);
1234
1397
  nodes.unshift(...out.splice(out.length - 1 - imm.length));
1235
1398
  }
@@ -1591,12 +1754,17 @@ var IMM = {
1591
1754
  elemidx: (n, c) => uleb(id(n.shift(), c.elem)),
1592
1755
  tagidx: (n, c) => uleb(id(n.shift(), c.tag)),
1593
1756
  "memoryidx?": (n, c) => uleb(id(isIdx(n[0]) ? n.shift() : 0, c.memory)),
1757
+ stringidx: (n, c) => {
1758
+ let s = n.shift(), key = s.valueOf(), idx = c.strings.findIndex((x) => x.valueOf() === key);
1759
+ if (idx < 0) idx = c.strings.push(s) - 1;
1760
+ return uleb(idx);
1761
+ },
1594
1762
  // Value type
1595
1763
  i32: (n) => i32(n.shift()),
1596
1764
  i64: (n) => i64(n.shift()),
1597
1765
  f32: (n) => f32(n.shift()),
1598
1766
  f64: (n) => f64(n.shift()),
1599
- v128: (n) => (void 0)(n.shift()),
1767
+ v128: (n) => v128(n.shift()),
1600
1768
  // Combinations
1601
1769
  typeidx_field: (n, c) => {
1602
1770
  let typeId = id(n.shift(), c.type);
@@ -3320,7 +3488,7 @@ var localReuse = (ast) => {
3320
3488
  const sub = node[i];
3321
3489
  if (!Array.isArray(sub)) continue;
3322
3490
  if (sub[0] === "local") {
3323
- localDecls.push({ idx: i, node: sub });
3491
+ localDecls.push({ node: sub, idx: i });
3324
3492
  if (typeof sub[1] === "string" && sub[1][0] === "$") {
3325
3493
  localTypes.set(sub[1], sub[2]);
3326
3494
  }
package/dist/watr.min.js CHANGED
@@ -1,5 +1,6 @@
1
- var Gt=Object.defineProperty;var Kt=(t,e)=>{for(var r in e)Gt(t,r,{get:e[r],enumerable:!0})};var tt={};Kt(tt,{f32:()=>Q,f64:()=>J,i16:()=>te,i32:()=>W,i64:()=>Z,i8:()=>Qt,uleb:()=>p,uleb5:()=>Zt});var v=(t,e=v.loc)=>{if(e!=null&&v.src){let r=1,i=1;for(let s=0;s<e&&s<v.src.length;s++)v.src[s]===`
2
- `?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)};var Nt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Bt=/^[+-]?(?:0x[\da-f]+|\d+)$/i,Xt=new TextEncoder,Jt=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),kt={n:10,r:13,t:9,'"':34,"'":39,"\\":92},nt=t=>{let e=[],r=1,i,s,l="",a=()=>(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++):kt[t[r]]?i=kt[t[r++]]:isNaN(i=parseInt(t[r]+t[r+1],16))?s+=t[r]:(r++,r++)),i!=null?(a(),e.push(i)):l+=s;return a(),e.valueOf=()=>t,e},Mt=t=>Jt.decode(new Uint8Array(nt(t)));var p=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):W.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),p(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 W(t,e=[]){for(typeof t=="string"&&(t=W.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=>!Nt.test(t)&&Bt.test(t=t.replaceAll("_",""))?t:v(`Bad int ${t}`),Qt=W,te=W;W.parse=t=>(t=parseInt(zt(t)),(t<-2147483648||t>4294967295)&&v("i32 constant out of range"),t);function Z(t,e=[]){for(typeof t=="string"?t=Z.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}Z.parse=t=>(t=zt(t),t=t[0]==="-"?-BigInt(t.slice(1)):BigInt(t),(t<-0x8000000000000000n||t>0xffffffffffffffffn)&&v("i64 constant out of range"),q.setBigInt64(0,t),q.getBigInt64(0));var q=new DataView(new Float64Array(1).buffer),ee=2147483648,re=2139095040;function Q(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=W.parse(t.slice(r+4)),e|=re,t[0]==="-"&&(e|=ee),q.setInt32(0,e)):(e=typeof t=="string"?Q.parse(t):t,q.setFloat32(0,e)),[q.getUint8(3),q.getUint8(2),q.getUint8(1),q.getUint8(0)]}var ie=0x8000000000000000n,se=0x7ff0000000000000n;function J(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=Z.parse(t.slice(r+4)),e|=se,t[0]==="-"&&(e|=ie),q.setBigInt64(0,e)):(e=typeof t=="string"?J.parse(t):t,q.setFloat64(0,e)),[q.getUint8(7),q.getUint8(6),q.getUint8(5),q.getUint8(4),q.getUint8(3),q.getUint8(2),q.getUint8(1),q.getUint8(0)]}J.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,a=""]=i.split("."),n=a.length??0,c=parseInt(l);isNaN(c)&&v();let f=a?parseInt("0x"+a)/16**n: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)};Q.parse=t=>J.parse(t,34028234663852886e22);var st=["unreachable","nop","block block","loop block","if block","else null","then null",,"throw tagidx",,"throw_ref","end end","br labelidx","br_if labelidx","br_table br_table","return","call funcidx","call_indirect call_indirect","return_call funcidx","return_call_indirect call_indirect","call_ref typeidx","return_call_ref typeidx",,,,,"drop","select select","",,,"try_table try_table","local.get localidx","local.set localidx","local.tee localidx","global.get globalidx","global.set globalidx","table.get tableidx","table.set tableidx",,"i32.load memarg","i64.load memarg","f32.load memarg","f64.load memarg","i32.load8_s memarg","i32.load8_u memarg","i32.load16_s memarg","i32.load16_u memarg","i64.load8_s memarg","i64.load8_u memarg","i64.load16_s memarg","i64.load16_u memarg","i64.load32_s memarg","i64.load32_u memarg","i32.store memarg","i64.store memarg","f32.store memarg","f64.store memarg","i32.store8 memarg","i32.store16 memarg","i64.store8 memarg","i64.store16 memarg","i64.store32 memarg","memory.size opt_memory","memory.grow opt_memory","i32.const i32","i64.const i64","f32.const f32","f64.const f64","i32.eqz","i32.eq","i32.ne","i32.lt_s","i32.lt_u","i32.gt_s","i32.gt_u","i32.le_s","i32.le_u","i32.ge_s","i32.ge_u","i64.eqz","i64.eq","i64.ne","i64.lt_s","i64.lt_u","i64.gt_s","i64.gt_u","i64.le_s","i64.le_u","i64.ge_s","i64.ge_u","f32.eq","f32.ne","f32.lt","f32.gt","f32.le","f32.ge","f64.eq","f64.ne","f64.lt","f64.gt","f64.le","f64.ge","i32.clz","i32.ctz","i32.popcnt","i32.add","i32.sub","i32.mul","i32.div_s","i32.div_u","i32.rem_s","i32.rem_u","i32.and","i32.or","i32.xor","i32.shl","i32.shr_s","i32.shr_u","i32.rotl","i32.rotr","i64.clz","i64.ctz","i64.popcnt","i64.add","i64.sub","i64.mul","i64.div_s","i64.div_u","i64.rem_s","i64.rem_u","i64.and","i64.or","i64.xor","i64.shl","i64.shr_s","i64.shr_u","i64.rotl","i64.rotr","f32.abs","f32.neg","f32.ceil","f32.floor","f32.trunc","f32.nearest","f32.sqrt","f32.add","f32.sub","f32.mul","f32.div","f32.min","f32.max","f32.copysign","f64.abs","f64.neg","f64.ceil","f64.floor","f64.trunc","f64.nearest","f64.sqrt","f64.add","f64.sub","f64.mul","f64.div","f64.min","f64.max","f64.copysign","i32.wrap_i64","i32.trunc_f32_s","i32.trunc_f32_u","i32.trunc_f64_s","i32.trunc_f64_u","i64.extend_i32_s","i64.extend_i32_u","i64.trunc_f32_s","i64.trunc_f32_u","i64.trunc_f64_s","i64.trunc_f64_u","f32.convert_i32_s","f32.convert_i32_u","f32.convert_i64_s","f32.convert_i64_u","f32.demote_f64","f64.convert_i32_s","f64.convert_i32_u","f64.convert_i64_s","f64.convert_i64_u","f64.promote_f32","i32.reinterpret_f32","i64.reinterpret_f64","f32.reinterpret_i32","f64.reinterpret_i64","i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s",,,,,,,,,,,,"ref.null ref_null","ref.is_null","ref.func funcidx","ref.eq","ref.as_non_null","br_on_null labelidx","br_on_non_null labelidx",,,,,,,,,,"cont.new typeidx","cont.bind cont_bind","suspend tagidx","resume resume","resume_throw resume_throw","resume_throw_ref resume_throw_ref","switch switch_cont",,,,,,,,,,,,,,,,,,,,,["struct.new typeidx","struct.new_default typeidx","struct.get typeidx_field","struct.get_s typeidx_field","struct.get_u typeidx_field","struct.set typeidx_field","array.new typeidx","array.new_default typeidx","array.new_fixed typeidx_multi","array.new_data typeidx_dataidx","array.new_elem typeidx_elemidx","array.get typeidx","array.get_s typeidx","array.get_u typeidx","array.set typeidx","array.len","array.fill typeidx","array.copy typeidx_typeidx","array.init_data typeidx_dataidx","array.init_elem typeidx_elemidx","ref.test reftype","","ref.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",,"struct.new_desc typeidx","struct.new_default_desc typeidx","ref.get_desc typeidx","ref.cast_desc_eq reftype",,"br_on_cast_desc_eq reftype2","br_on_cast_desc_eq_fail reftype2"],["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"]],U={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},T={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,cont:104,nocont:117,nullfuncref:115,nullexternref:114,nullexnref:116,nullref:113,funcref:112,externref:111,exnref:105,anyref:110,eqref:109,i31ref:108,structref:107,arrayref:106,contref:104,nocontref:117,ref:100,refnull:99,sub:80,subfinal:79,rec:78},V={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},ht={func:0,table:1,memory:2,global:3,tag:4};var D=t=>{let e=0,r=[],i="",s=0,l=0,a=()=>i&&(r.push(i),i=""),n=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&&(a(),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&&(a(),s=0)):i+=t[e++];else if(s<0)f===10||f===13?(i+=t[e++],a(),s=0):i+=t[e++];else if(f===34)i!=="$"&&a(),s=34,i+=t[e++];else if(f===40&&t.charCodeAt(e+1)===59)a(),s=60,i=t[e++]+t[e++];else if(f===59&&t.charCodeAt(e+1)===59)a(),s=-1,i=t[e++]+t[e++];else if(f===40&&t.charCodeAt(e+1)===64)a(),u=e,e+=2,i="@",l++,(o=r).push(r=[]),n(u),r=o;else if(f===40)a(),u=e++,l++,(o=r).push(r=[]),n(u),r=o;else{if(f===41)return a(),e++,l--;f<=32?(a(),e++):i+=t[e++]}s<0&&a(),a()};return n(0),s===34&&v("Unclosed quote",e),s>59&&v("Unclosed block comment",e),l>0&&v("Unclosed parenthesis",e),e<t.length&&v("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var Et=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(Et).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]==='"'?nt(t):t;function rt(t){typeof t=="string"?(v.src=t,t=D(t)||[]):v.src="",v.loc=0,t=Et(t)||[];let e=0;if(t[0]==="module"?(e++,F(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return rt(t.slice(++e).map(l=>l.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((l,a)=>{if(a<e||!Array.isArray(l)||l[0]!=="import")return[l];let[,n,...c]=l;if(!c.some(o=>Array.isArray(o)&&o[0]==="item"))return[l];if(Array.isArray(c.at(-1))&&c.at(-1)[0]!=="item"){let o=c.at(-1);return c.slice(0,-1).filter(u=>u[0]==="item").map(([,u])=>["import",n,u,o])}return c.filter(o=>o[0]==="item").map(([,o,u])=>["import",n,o,u])});let r=[];for(let l in U)(r[U[l]]=r[l]=[]).name=l;r.metadata={},t.slice(e).filter(l=>{if(!Array.isArray(l)){let c=v.loc,f=v.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&&(v.loc=c),v(`Unexpected token ${l}`)}let[a,...n]=l;if(v.loc=l.loc,a==="@custom")r.custom.push(n);else if(a==="rec")for(let c=0;c<n.length;c++){let[,...f]=n[c];dt(f,r.type);let o=[];for(;f[0]?.[0]==="descriptor"||f[0]?.[0]==="describes";)o.push(f.shift());(f=Ut(f,r)).push(c?!0:[r.type.length,n.length]),o.length&&(f.desc=f.desc?[...o,...f.desc]:o),r.type.push(f)}else if(a==="type"){dt(n,r.type);let c=[];for(;n[0]?.[0]==="descriptor"||n[0]?.[0]==="describes";)c.push(n.shift());let f=Ut(n,r);c.length&&(f.desc=f.desc?[...c,...f.desc]:c),r.type.push(f)}else if(a==="start"||a==="export")r[a].push(n);else return!0}).forEach(l=>{let[a,...n]=l;v.loc=l.loc;let c;a==="import"&&([a,...n]=(c=n).pop());let f=r[a];for(f||v(`Unknown section ${a}`),dt(n,f);n[0]?.[0]==="export";)r.export.push([n.shift()[1],[a,f?.length]]);if(n[0]?.[0]==="import"&&([,...c]=n.shift()),a==="table"){let o=n[0]==="i64",u=o?1:0;if(n[u+1]?.[0]==="elem"){let[d,[,...h]]=[n[u],n[u+1]];n=o?["i64",h.length,h.length,d]:[h.length,h.length,d],r.elem.push([["table",f.length],["offset",[o?"i64.const":"i32.const",o?0n:0]],d,...h])}}else if(a==="memory"){let o=n[0]==="i64",u=o?1:0;if(n[u]?.[0]==="data"){let d=n.find(y=>Array.isArray(y)&&y[0]==="pagesize")?.[1]??65536,[,...h]=n.splice(u,1)[0],$=""+Math.ceil(h.reduce((y,k)=>y+k.length,0)/d);r.data.push([["memory",f.length],[o?"i64.const":"i32.const",o?0n:0],...h]),n=o?["i64",$,$]:[$,$]}}else if(a==="func"){let[o,u,d]=_t(n,r);o??=mt(u,d,r),!c&&r.code.push([[o,u,d],...Y(n,r)]),n=[["type",o]]}else if(a==="tag"){let[o,u]=_t(n,r);o??=mt(u,[],r),n=[["type",o]]}c&&(r.import.push([...c,[a,...n]]),n=null),f.push(n)});let i=(l,a=!0)=>{let n=r[l].filter(Boolean).map(c=>qt[l](c,r)).filter(Boolean);return l===U.custom?n.flatMap(c=>[l,...N(c)]):n.length?[l,...N(a?N(n):n)]:[]},s=()=>{let l=[];for(let a in r.metadata){let n=N(nt(`"metadata.code.${a}"`)),c=N(r.metadata[a].map(([f,o])=>[...p(f),...N(o.map(([u,d])=>[...p(u),...N(d)]))]));l.push(0,...N([...n,...c]))}return l};return Uint8Array.from([0,97,115,109,1,0,0,0,...i(U.custom),...i(U.type),...i(U.import),...i(U.func),...i(U.table),...i(U.memory),...i(U.tag),...i(U.global),...i(U.export),...i(U.start,!1),...i(U.elem),...i(U.datacount,!1),...i(U.code),...s(),...i(U.data)])}var L=t=>t?.[0]==="$"||!isNaN(t),F=t=>t?.[0]==="$",bt=t=>t?.[0]==="a"||t?.[0]==="o";function Y(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")F(t[0])&&r.push(t.shift()),r.push(at(t,e));else if(i==="else"||i==="end")F(t[0])&&t.shift();else if(i==="select")r.push(pt(t)[1]);else if(i.endsWith("call_indirect")){let s=L(t[0])?t.shift():0,[l,a,n]=_t(t,e);r.push(s,["type",l??mt(a,n,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&&(v.loc=i.loc),s?.startsWith?.("@metadata.code.")){let a=s.slice(15);r.push(["@metadata",a,i[1]]);continue}if(typeof s!="string"||!Array.isArray(st[s])){r.push(i);continue}let l=i.slice(1);if(s==="block"||s==="loop")r.push(s),F(l[0])&&r.push(l.shift()),r.push(at(l,e),...Y(l,e),"end");else if(s==="if"){let a=[],n=[];l.at(-1)?.[0]==="else"&&(n=Y(l.pop().slice(1),e)),l.at(-1)?.[0]==="then"&&(a=Y(l.pop().slice(1),e));let c=[s];F(l[0])&&c.push(l.shift()),c.push(at(l,e)),r.push(...Y(l,e),...c,...a),n.length&&r.push("else",...n),r.push("end")}else if(s==="try_table"){for(r.push(s),F(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(...Y(l,e),"end")}else{let a=[];for(;l.length&&(!Array.isArray(l[0])||"type,param,result,ref,exact,on".includes(l[0][0]));)a.push(l.shift());r.push(...Y(l,e),s,...a),t.unshift(...r.splice(r.length-1-a.length))}}else r.push(i)}return r}var mt=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),At=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=F(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},pt=t=>{let e=At(t,"param"),r=At(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},_t=(t,e)=>{if(t[0]?.[0]!=="type")return[,...pt(t)];let[,r]=t.shift(),[i,s]=pt(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??mt(i,s,e)]},dt=(t,e)=>{let r=F(t[0])&&t.shift();return r&&(r in e?v(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},Ut=([t],e)=>{let r="subfinal",i=[],s,l=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(i=t).pop(),i=i.filter(n=>Array.isArray(n)&&(n[0]==="descriptor"||n[0]==="describes")?(l.push(n),!1):!0)),[s,...t]=t,s==="func"?(t=pt(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=At(t,"field"):s==="array"&&([t]=t);let a=[s,t,r,i];return l.length&&(a.desc=l),a},qt=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...N(t),...i.flat()]},(t,e)=>{let[r,i,s,l,a]=t;if(a===!0)return;let n=(t.desc??[]).flatMap(([f,o])=>[f==="descriptor"?77:76,...p(x(o,e.type))]),c=(f,o)=>f==="func"?[V.func,...N(o[0].map(u=>C(u,e))),...N(o[1].map(u=>C(u,e)))]:f==="array"?[V.array,...ft(o,e)]:f==="struct"?[V.struct,...N(o.map(u=>ft(u,e)))]:f==="cont"?[V.cont,...p(x(o[0]??o,e.type))]:[V[f]];if(a){let[f,o]=a,u=Array.from({length:o},(d,h)=>{let $=e.type[f+h],y=$.slice(0,4);return $.desc&&(y.desc=$.desc),qt[U.type](y,e)});return[V.rec,...N(u)]}else if(s==="sub"||l?.length)return[V[s],...N(l.map(f=>x(f,e.type))),...n,...c(r,i)];return[...n,...c(r,i)]},([t,e,[r,...i]],s)=>{let l,a=ht[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(a=32);let[[,c]]=i;l=p(x(c,s.type))}else if(r==="tag"){let[[,n]]=i;l=[0,...p(x(n,s.type))]}else r==="memory"?l=ot(i):r==="global"?l=ft(i[0],s):r==="table"?l=[...C(i.pop(),s),...ot(i)]:v(`Unknown kind ${r}`);return[...N(t),...N(e),a,...l]},([[,t]],e)=>p(x(t,e.type)),(t,e)=>{let r=ot(t),i=C(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...et(s,e)]:[...i,...r]},(t,e)=>ot(t),([t,e],r)=>[...ft(t,r),...et(e,r)],([t,[e,r]],i)=>[...N(t),ht[e],...p(x(r,i[e]))],([t],e)=>p(x(t,e.func)),(t,e)=>{let r=0,i=0,s=0,l=0,a,n,c;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,a]=t.shift(),a=x(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=x(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=et(n,e)):i||(r=1),T[t[0]]||t[0]?.[0]==="ref"?c=C(t.shift(),e):t[0]==="func"?c=[T[t.shift()]]:c=[T.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]!==T.funcref&&(l=1,s=1);let f=s<<2|(r||i?i:!!a||l)<<1|(r||i);return[f,...f===0?n:f===1?[0]:f===2?[...p(a||0),...n,0]:f===3?[0]:f===4?n:f===5?c:f===6?[...p(a||0),...n,...c]:c,...N(t.map(s?o=>et(typeof o=="string"?["ref.func",o]:o,e):o=>p(x(o,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[x(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(F(c[0])){let f=c.shift();f in e.local?v(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...c)}e.meta={};let l=Ft(t,e),a=e.import.filter(c=>c[2][0]==="func").length+s;for(let c in e.meta)((e.metadata??={})[c]??=[]).push([a,e.meta[c]]);let n=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,N([...N(n.map(([c,f])=>[...p(c),...C(f,e)])),...l])},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=x(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=x(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??v("Bad offset",r)),[...i?[2,...p(i),...et(r,e)]:r?[0,...et(r,e)]:[1],...N(t.flatMap(s=>ae(s)??[...s]))]},(t,e)=>p(e.data.length),([[,t]],e)=>[0,...p(x(t,e.type))]],C=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[T.refnull,98,...p(x(t[2][1],e.type))]:T[t[2]]?[T[t[2]]]:[T.refnull,...p(x(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[T.ref,98,...p(x(t[1][1],e.type))]:[T.ref,...p(T[t[t.length-1]]||x(t[t.length-1],e.type))]:[T[t]??v(`Unknown type ${t}`)],ft=(t,e,r=t[0]==="mut"?1:0)=>[...C(r?t[1]:t,e),r],St={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...p(x(i,e.elem)),...p(x(r,e.table))]},block:(t,e)=>{e.block.push(1),F(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?C(r[1],e):p(x(r[1],e.type)):[T.void]},try_table:(t,e)=>{F(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?C(r[1],e):p(x(r[1],e.type)):[T.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,...p(x(a[1],e.tag)),...p(H(a[2],e.block))):s.push(n,...p(H(a[1],e.block))),l++}return e.block.push(1),[...i,...p(l),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...p(x(i,e.type)),...p(x(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||F(t[0]));)r.push(...p(H(t.shift(),e.block))),i++;return[...p(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?N(r.map(i=>C(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...p(x(r[1],e.type))]:T[r]?[T[r]]:p(x(r,e.type))},memarg:(t,e,r)=>Tt(t,r,L(t[0])&&!bt(t[0])?x(t.shift(),e.memory):0),opt_memory:(t,e)=>p(x(L(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=C(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=H(t.shift(),e.block),i=C(t.shift(),e),s=C(t.shift(),e),l=a=>a.length>1?a.slice(1):a;return[(s[0]!==T.ref)<<1|i[0]!==T.ref,...p(r),...l(i),...l(s)]},v128const:t=>{let[e,r]=t.shift().split("x"),i=+e.slice(1),s=i>>>3;if(r=+r,e[0]==="i"){let a=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let n=0;n<r;n++)a[n]=tt[e].parse(t.shift());return[...new Uint8Array(a.buffer)]}let l=new Uint8Array(16);for(let a=0;a<r;a++)l.set(tt[e](t.shift()),a*s);return[...l]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(ut(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&v("invalid lane length"),e},memlane:(t,e,r)=>{let i=F(t[0])||L(t[0])&&(bt(t[1])||L(t[1]))?x(t.shift(),e.memory):0;return[...Tt(t,r,i),...p(ut(t.shift()))]},"*":t=>p(t.shift()),labelidx:(t,e)=>p(H(t.shift(),e.block)),laneidx:t=>[ut(t.shift(),255)],funcidx:(t,e)=>p(x(t.shift(),e.func)),typeidx:(t,e)=>p(x(t.shift(),e.type)),tableidx:(t,e)=>p(x(t.shift(),e.table)),memoryidx:(t,e)=>p(x(t.shift(),e.memory)),globalidx:(t,e)=>p(x(t.shift(),e.global)),localidx:(t,e)=>p(x(t.shift(),e.local)),dataidx:(t,e)=>p(x(t.shift(),e.data)),elemidx:(t,e)=>p(x(t.shift(),e.elem)),tagidx:(t,e)=>p(x(t.shift(),e.tag)),"memoryidx?":(t,e)=>p(x(L(t[0])?t.shift():0,e.memory)),i32:t=>W(t.shift()),i64:t=>Z(t.shift()),f32:t=>Q(t.shift()),f64:t=>J(t.shift()),v128:t=>(void 0)(t.shift()),typeidx_field:(t,e)=>{let r=x(t.shift(),e.type);return[...p(r),...p(x(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...p(x(t.shift(),e.type)),...p(t.shift())],typeidx_dataidx:(t,e)=>[...p(x(t.shift(),e.type)),...p(x(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...p(x(t.shift(),e.type)),...p(x(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...p(x(t.shift(),e.type)),...p(x(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...p(x(t.shift(),e.data)),...p(x(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...p(x(t.shift(),e.memory)),...p(x(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...p(x(t.shift(),e.table)),...p(x(t.shift(),e.table))],cont_bind:(t,e)=>[...p(x(t.shift(),e.type)),...p(x(t.shift(),e.type))],switch_cont:(t,e)=>[...p(x(t.shift(),e.type)),...p(x(t.shift(),e.tag))],resume:(t,e)=>{let r=p(x(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,l,a]=t.shift();a==="switch"?i.push(1,...p(x(l,e.tag))):i.push(0,...p(x(l,e.tag)),...p(H(a,e.block))),s++}return[...r,...p(s),...i]},resume_throw:(t,e)=>{let r=p(x(t.shift(),e.type)),i=p(x(t.shift(),e.tag)),s=[],l=0;for(;t[0]?.[0]==="on";){let[,a,n]=t.shift();n==="switch"?s.push(1,...p(x(a,e.tag))):s.push(0,...p(x(a,e.tag)),...p(H(n,e.block))),l++}return[...r,...i,...p(l),...s]},resume_throw_ref:(t,e)=>{let r=p(x(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,l,a]=t.shift();a==="switch"?i.push(1,...p(x(l,e.tag))):i.push(0,...p(x(l,e.tag)),...p(H(a,e.block))),s++}return[...r,...p(s),...i]}},ct={};(function t(e,r){for(let i=0,s,l,a;i<e.length;i++)(s=e[i])&&(Array.isArray(s)?t(s,i):([l,a]=s.split(" "),st[l]=r?[r,...p(i)]:[i],a&&(ct[l]=St[a])))})(st);var Ft=(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&&(v.loc=s.loc),v(`Unknown instruction ${s[0]}`));let[...l]=st[s]||v(`Unknown instruction ${s}`);ct[s]&&(s==="select"&&t[0]?.length?l[0]++:ct[s]===St.reftype&&(t[0][1]==="null"||t[0][0]!=="ref")&&l[l.length-1]++,l.push(...ct[s](t,e,s)));for(let[a,n]of i)(e.meta[a]??=[]).push([r.length,n]);r.push(...l)}return r.push(11),r},et=(t,e)=>Ft(Y([t],e),e),x=(t,e,r)=>(r=F(t)?e[t]:+t,r in e?r:v(`Unknown ${e.name} ${t}`)),H=(t,e,r)=>(r=F(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?v(`Bad label ${t}`):r),le=t=>{let e,r,i,s;for(;bt(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:v(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&v(`Bad offset ${r}`),(e<=0||e>4294967295)&&v(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&v(`Bad align ${e}`),[e,r]},Tt=(t,e,r=0)=>{let[i,s]=le(t),l=(i??ne(e))|(r&&64);return r?[...p(l),...p(r),...p(s??0)]:[...p(l),...p(s??0)]},ne=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)},ae=t=>{if(!Array.isArray(t))return null;let[e,...r]=t;if(e!=="i8"&&e!=="i16"&&e!=="i32"&&e!=="i64"&&e!=="f32"&&e!=="f64")return null;let i=[],s=new DataView(new ArrayBuffer(8));for(let l of r)e==="i8"?i.push(W.parse(l)&511&255):e==="i16"?(s.setInt16(0,W.parse(l),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,W.parse(l),!0),i.push(...new Uint8Array(s.buffer,0,4))):e==="i64"?(s.setBigInt64(0,BigInt(l),!0),i.push(...new Uint8Array(s.buffer,0,8))):e==="f32"?i.push(...Q(l)):e==="f64"&&i.push(...J(l));return i},ot=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(f=>Array.isArray(f)&&f[0]==="pagesize"),s=-1;i>=0&&(s=Math.log2(+t.splice(i,1)[0][1]));let l=!isNaN(parseInt(t[1])),a=(s>=0?8:0)|(e?4:0)|(r?2:0)|(l?1:0),n=e?f=>{if(typeof f=="bigint")return f;let o=typeof f=="string"?f.replaceAll("_",""):String(f);return BigInt(o)}:ut,c=s>=0?p(s):[];return l?[a,...p(n(t.shift())),...p(n(t.shift())),...c]:[a,...p(n(t.shift())),...c]},ut=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?W.parse(t):typeof t=="number"?t:v(`Bad int ${t}`);return r>e?v(`Value out of range ${t}`):r},N=t=>[...p(t.length),...t.flat()];function Ot(t,e={}){typeof t=="string"&&(t=D(t));let{indent:r=" ",newline:i=`
3
- `,comments:s=!0}=e;if(r||="",i||="",typeof t[0]=="string"&&t[0][0]!==";")return a(t);return t.filter(n=>s||!l(n)).map(n=>a(n)).join(i);function l(n){return typeof n=="string"&&n[1]===";"}function a(n,c=0){if(!Array.isArray(n))return n;let f=n[0];if(!f)return"";let o=!1;if(f==="try_table"){let h=1;for(typeof n[h]=="string"&&n[h][0]==="$"&&(f+=" "+n[h++]),Array.isArray(n[h])&&(n[h][0]==="result"||n[h][0]==="type")&&(f+=" "+a(n[h++],c));Array.isArray(n[h])&&/^catch/.test(n[h][0]);)f+=" "+a(n[h++],c).trim();for(;h<n.length;h++)f+=Array.isArray(n[h])?i+r.repeat(c+1)+a(n[h],c+1):" "+n[h];return`(${f+i+r.repeat(c)})`}let u=!!i&&n.length<4&&!n.some(h=>typeof h=="string"&&h[0]===";"&&h[1]===";"),d=r.repeat(c+1);for(let h=1;h<n.length;h++){let $=n[h].valueOf();if(typeof $=="string"&&$[1]===";"){if(!s)continue;if($[0]===";")if(i)f+=i+d+$.trimEnd(),o=!0;else{let y=f[f.length-1];y&&y!==" "&&y!=="("&&(f+=" "),f+=$.trimEnd()+`
4
- `}else{let y=f[f.length-1];y&&y!==" "&&y!=="("&&(f+=" "),f+=$.trimEnd()}}else if(Array.isArray($))u&&(u=$.every(y=>!Array.isArray(y))),f+=i+d+a($,c+1),o=!1;else if(n[0]==="data")u=!1,(i||f[f.length-1]!==")")&&(f+=i||" "),f+=d+$,o=!1;else{let y=f[f.length-1];o&&i?f+=i+d:y===`
5
- `?f+="":(y&&y!==")"&&y!==" "||i||y===")")&&(f+=" "),f+=$,o=!1}}return u?`(${f.replaceAll(i+d+"("," (")})`:`(${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),fe=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)},oe=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},Dt=t=>Array.isArray(t)?t.map(Dt):t,Lt=(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},yt=(t,e,r)=>t.splice(e,0,r),ce=0,R=t=>`$__${t}${ce++}`,ue=(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])),a=Lt(t,"func"),n=a.length?a[0].idx:t[0]==="module"?1:0;yt(t,n,["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=[],d=[];for(let h of f){if(Array.isArray(h)&&h[0]==="param")for(let $=1;$<h.length;$++)h[$][0]!=="$"&&u.push(h[$]);if(Array.isArray(h)&&h[0]==="result")for(let $=1;$<h.length;$++)d.push(h[$])}c[o]={params:u,results:d}}),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 d=f[1],h=f.slice(2);o[u]=["call_indirect",i,["type",d],...h]}if(f[0]==="return_call_ref"){let d=f[1],h=f.slice(2);o[u]=["return_call_indirect",i,["type",d],...h]}}}),t},P={funcref:ue},me={"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]},pe=(t,e)=>(j(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let l=me[r[0]];if(!l)return;let[a,n]=l,c=r.slice(1);i[s]=[`${a}.shr_s`,[`${a}.shl`,...c,[`${a}.const`,n]],[`${a}.const`,n]]}),t);P.sign_ext=pe;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:a,signed:n,min:c,max:f}=Wt[s],o=R(`trunc_${l}_${a}_${n?"s":"u"}`);i[s]=o;let u=`${l}.trunc_${a}_${n?"s":"u"}`,d=l==="i64"?0n:0,h=["func",o,["param","$v",a],["result",l],["if",["result",l],[`${a}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${l}.const`,d]],["else",["if",["result",l],[`${a}.lt`,["local.get","$v"],[`${a}.const`,typeof c=="bigint"?Number(c):c]],["then",[`${l}.const`,c]],["else",["if",["result",l],[`${a}.gt`,["local.get","$v"],[`${a}.const`,typeof f=="bigint"?Number(f):f]],["then",[`${l}.const`,f]],["else",[u,["local.get","$v"]]]]]]]]];t.push(h)}return j(t,(s,l,a)=>{!Array.isArray(s)||!l||i[s[0]]&&(l[a]=["call",i[s[0]],...s.slice(1)])}),t};P.nontrapping=_e;var ye=(t,e)=>{let r=new Set,i=new Set;S(t,a=>{if(Array.isArray(a)){if(a[0]==="memory.copy"){let n=typeof a[1]=="number"?a[1]:0,c=typeof a[2]=="number"?a[2]:0;r.add(`${n}_${c}`)}if(a[0]==="memory.fill"){let n=typeof a[1]=="number"?a[1]:0;i.add(n)}}});let s={},l={};for(let a of r){let[n,c]=a.split("_").map(Number),f=R(`memcpy${a==="0_0"?"":"_"+a}`);s[a]=f;let o=n?["i32.store8",n]:["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 a of i){let n=R(`memset${a===0?"":"_"+a}`);l[a]=n;let c=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"]]],[...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,(a,n,c)=>{if(!(!Array.isArray(a)||!n)){if(a[0]==="memory.copy"){let f=typeof a[1]=="number"?a[1]:0,o=typeof a[2]=="number"?a[2]:0,u=a.filter(d=>Array.isArray(d)||typeof d=="string"&&d[0]==="$");n[c]=["call",s[`${f}_${o}`],...u]}if(a[0]==="memory.fill"){let f=typeof a[1]=="number"?a[1]:0,o=a.filter(u=>Array.isArray(u)||typeof u=="string"&&u[0]==="$");n[c]=["call",l[f],...o]}}}),t};P.bulk_memory=ye;var ge=(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=ge;var xe=(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=xe;var he=(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 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")){r[l]={type:n[0].split(".")[0],value:n[1]};break}}});let i=s=>{if(!Array.isArray(s))return s;let l=s[0];if(l==="global.get"&&r[s[1]]){let a=r[s[1]];return[`${a.type}.const`,a.value]}if(l==="i32.add"||l==="i64.add"){let a=i(s[1]),n=i(s[2]);if(a&&n&&a[0]?.endsWith(".const")&&n[0]?.endsWith(".const")){let c=l.split(".")[0],f=c==="i64"?BigInt(a[1]):Number(a[1]),o=c==="i64"?BigInt(n[1]):Number(n[1]);return[`${c}.const`,f+o]}}if(l==="i32.sub"||l==="i64.sub"){let a=i(s[1]),n=i(s[2]);if(a&&n&&a[0]?.endsWith(".const")&&n[0]?.endsWith(".const")){let c=l.split(".")[0],f=c==="i64"?BigInt(a[1]):Number(a[1]),o=c==="i64"?BigInt(n[1]):Number(n[1]);return[`${c}.const`,f-o]}}if(l==="i32.mul"||l==="i64.mul"){let a=i(s[1]),n=i(s[2]);if(a&&n&&a[0]?.endsWith(".const")&&n[0]?.endsWith(".const")){let c=l.split(".")[0],f=c==="i64"?BigInt(a[1]):Number(a[1]),o=c==="i64"?BigInt(n[1]):Number(n[1]);return[`${c}.const`,f*o]}}return s};return j(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 c=i(s[n]);c!==s[n]&&(s[n]=c)}}}),t};P.extended_const=he;var de=(t,e)=>{let r=new Map,i=[];if(S(t,n=>{if(!Array.isArray(n)||n[0]!=="func")return;let c=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null,f=[];for(let o of n)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(n=>n.length)),l={};for(let[n,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 a=t[0]==="module"?1:0;for(let n of i.reverse())yt(t,a,n);return j(t,(n,c,f)=>{if(!Array.isArray(n)||n[0]!=="func")return;let o=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null;if(!o||!r.has(o))return;let u=r.get(o);for(let d=0;d<n.length;d++)if(Array.isArray(n[d])&&n[d][0]==="result"){n[d]=["result",u[0]];break}}),t};P.multi_value=de;var lt={i32:4,i64:8,f32:4,f64:8},be=(t,e)=>{let r=new Map,i=new Map,s=1;if(S(t,y=>{if(!Array.isArray(y)||y[0]!=="type")return;let k=typeof y[1]=="string"&&y[1][0]==="$"?y[1]:null;if(k){for(let m of y)if(Array.isArray(m)){if(m[0]==="struct"){let g=[];for(let _ of m)if(Array.isArray(_)&&_[0]==="field"){let A=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:null,b=A?_[2]:_[1],I=Array.isArray(b)&&b[0]==="mut"?b[1]:b;g.push({name:A,type:I})}r.set(k,{kind:"struct",fields:g}),i.set(k,s++)}if(m[0]==="array"){let g=m[1],_=Array.isArray(g)&&g[0]==="mut"?g[1]:g;r.set(k,{kind:"array",elemType:_}),i.set(k,s++)}}}}),!r.size)return t;let l=Lt(t,"memory").length>0,a=R("alloc"),n=R("heap_ptr"),c=t[0]==="module"?1:0;l||yt(t,c,["memory",1]),yt(t,c+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 o=y=>{let k=4;for(let m of y.fields)k+=lt[m.type]||4;return k},u=(y,k)=>{let m=4;for(let g=0;g<k;g++)m+=lt[y.fields[g].type]||4;return m},d=(y,k)=>{for(let m=0;m<y.fields.length;m++)if(y.fields[m].name===k)return m;return-1},h=0,$=()=>`$__gc_tmp${h++}`;return S(t,y=>{if(!Array.isArray(y)||y[0]!=="func")return;let k=!1,m=!1,g=!1,_=!1;if(S(y,b=>{Array.isArray(b)&&((b[0]==="struct.new"||b[0]==="struct.new_default")&&(k=!0),(b[0]==="array.new"||b[0]==="array.new_default")&&(m=!0,g=!0,_=!0))}),!k&&!m)return;let A=1;for(let b=1;b<y.length;b++){let I=y[b];if(Array.isArray(I)&&(I[0]==="param"||I[0]==="result"||I[0]==="local"||I[0]==="export"||I[0]==="type"))A=b+1;else if(typeof I=="string"&&I[0]==="$")A=b+1;else if(!Array.isArray(I))A=b+1;else break}k&&y.splice(A++,0,["local","$__gc_ptr","i32"]),m&&y.splice(A++,0,["local","$__gc_aptr","i32"]),g&&y.splice(A++,0,["local","$__gc_alen","i32"]),_&&y.splice(A++,0,["local","$__gc_aidx","i32"])}),j(t,(y,k,m)=>{if(!(!Array.isArray(y)||!k)){if(y[0]==="struct.new"||y[0]==="struct.new_default"){let g=y[1],_=r.get(g);if(!_||_.kind!=="struct")return;let A=o(_),b=i.get(g),I=y.slice(2),B="$__gc_ptr",E=[["local.set",B,["call",a,["i32.const",A]]],["i32.store",["local.get",B],["i32.const",b]]];if(y[0]==="struct.new")for(let M=0;M<_.fields.length;M++){let z=_.fields[M],it=u(_,M),X=z.type==="i64"?"i64.store":z.type==="f32"?"f32.store":z.type==="f64"?"f64.store":"i32.store";E.push([X,["i32.add",["local.get",B],["i32.const",it]],I[M]||[`${z.type}.const`,0]])}else for(let M=0;M<_.fields.length;M++){let z=_.fields[M],it=u(_,M),X=z.type==="i64"?"i64.store":z.type==="f32"?"f32.store":z.type==="f64"?"f64.store":"i32.store",Yt=z.type==="i64"?["i64.const",0n]:z.type==="f32"?["f32.const",0]:z.type==="f64"?["f64.const",0]:["i32.const",0];E.push([X,["i32.add",["local.get",B],["i32.const",it]],Yt])}E.push(["local.get",B]),k[m]=["block",["result","i32"],...E]}if(y[0]==="struct.get"){let g=y[1],_=y[2],A=y[3],b=r.get(g);if(!b||b.kind!=="struct")return;let I=typeof _=="string"&&_[0]==="$"?d(b,_):parseInt(_);if(I<0)return;let B=b.fields[I],E=u(b,I),M=B.type==="i64"?"i64.load":B.type==="f32"?"f32.load":B.type==="f64"?"f64.load":"i32.load";k[m]=[M,["i32.add",A,["i32.const",E]]]}if(y[0]==="struct.set"){let g=y[1],_=y[2],A=y[3],b=y[4],I=r.get(g);if(!I||I.kind!=="struct")return;let B=typeof _=="string"&&_[0]==="$"?d(I,_):parseInt(_);if(B<0)return;let E=I.fields[B],M=u(I,B),z=E.type==="i64"?"i64.store":E.type==="f32"?"f32.store":E.type==="f64"?"f64.store":"i32.store";k[m]=[z,["i32.add",A,["i32.const",M]],b]}if(y[0]==="array.new"||y[0]==="array.new_default"){let g=y[1],_=r.get(g);if(!_||_.kind!=="array")return;let A=i.get(g),b=lt[_.elemType]||4,I=y[0]==="array.new"?y[2]:null,B=y[0]==="array.new"?y[3]:y[2],E="$__gc_aptr",M="$__gc_alen",z="$__gc_aidx",it=_.elemType==="i64"?"i64.store":_.elemType==="f32"?"f32.store":_.elemType==="f64"?"f64.store":"i32.store",X=[["local.set",M,B],["local.set",E,["call",a,["i32.add",["i32.const",8],["i32.mul",["local.get",M],["i32.const",b]]]]],["i32.store",["local.get",E],["i32.const",A]],["i32.store",["i32.add",["local.get",E],["i32.const",4]],["local.get",M]]];I&&X.push(["local.set",z,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",z],["local.get",M]]],[it,["i32.add",["i32.add",["local.get",E],["i32.const",8]],["i32.mul",["local.get",z],["i32.const",b]]],I],["local.set",z,["i32.add",["local.get",z],["i32.const",1]]],["br","$loop"]]]),X.push(["local.get",E]),k[m]=["block",["result","i32"],...X]}if(y[0]==="array.get"){let g=y[1],_=y[2],A=y[3],b=r.get(g);if(!b||b.kind!=="array")return;let I=lt[b.elemType]||4,B=b.elemType==="i64"?"i64.load":b.elemType==="f32"?"f32.load":b.elemType==="f64"?"f64.load":"i32.load";k[m]=[B,["i32.add",["i32.add",_,["i32.const",8]],["i32.mul",A,["i32.const",I]]]]}if(y[0]==="array.set"){let g=y[1],_=y[2],A=y[3],b=y[4],I=r.get(g);if(!I||I.kind!=="array")return;let B=lt[I.elemType]||4,E=I.elemType==="i64"?"i64.store":I.elemType==="f32"?"f32.store":I.elemType==="f64"?"f64.store":"i32.store";k[m]=[E,["i32.add",["i32.add",_,["i32.const",8]],["i32.mul",A,["i32.const",B]]],b]}if(y[0]==="array.len"){let g=y[1];k[m]=["i32.load",["i32.add",g,["i32.const",4]]]}}}),t};P.gc=be;var Ae=(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 a of s)Array.isArray(a)&&(a[0]==="struct"||a[0]==="array")&&r.set(l,i++)}),r.size&&j(t,(s,l,a)=>{if(!(!Array.isArray(s)||!l)){if(s[0]==="ref.test"){let n=s[1],c=null;Array.isArray(n)&&n[0]==="ref"&&(c=n[1]==="null"?n[2]:n[1]);let f=s[2],o=r.get(c);o!==void 0&&(l[a]=["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 n=s[1],c=null,f=!1;Array.isArray(n)&&n[0]==="ref"&&(n[1]==="null"?(f=!0,c=n[2]):c=n[1]);let o=s[2],u=r.get(c);if(u!==void 0){let d=R("cast");f?l[a]=["block",["result","i32"],["local",d,"i32"],["local.set",d,o],["if",["i32.and",["i32.ne",["local.get",d],["i32.const",0]],["i32.ne",["i32.load",["local.get",d]],["i32.const",u]]],["then",["unreachable"]]],["local.get",d]]:l[a]=["block",["result","i32"],["local",d,"i32"],["local.set",d,o],["if",["i32.or",["i32.eqz",["local.get",d]],["i32.ne",["i32.load",["local.get",d]],["i32.const",u]]],["then",["unreachable"]]],["local.get",d]]}}if(s[0]==="br_on_cast"){let n=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 d=r.get(u);if(d!==void 0){let h=R("brcast");l[a]=["block",["result","i32"],["local",h,"i32"],["local.set",h,o],["br_if",n,["i32.and",["i32.ne",["local.get",h],["i32.const",0]],["i32.eq",["i32.load",["local.get",h]],["i32.const",d]]]],["local.get",h]]}}if(s[0]==="br_on_cast_fail"){let n=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 d=r.get(u);if(d!==void 0){let h=R("brfail");l[a]=["block",["result","i32"],["local",h,"i32"],["local.set",h,o],["br_if",n,["i32.or",["i32.eqz",["local.get",h]],["i32.ne",["i32.load",["local.get",h]],["i32.const",d]]]],["local.get",h]]}}}}),t};P.ref_cast=Ae;function gt(t,e=!0){typeof t=="string"&&(t=D(t)),t=Dt(t),e=fe(e);let r=oe(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 $t={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!0},vt=Object.keys($t),we=t=>{if(t===!0)return{...$t};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.size===1&&vt.includes([...e][0])?Object.fromEntries(vt.map(r=>[r,e.has(r)])):Object.fromEntries(vt.map(r=>[r,e.has(r)||e.has("all")]))}return{...$t,...t}},O=t=>Array.isArray(t)?t.map(O):t,G=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)G(t[s],e,t,s)},K=(t,e,r,i)=>{if(Array.isArray(t))for(let l=0;l<t.length;l++){let a=K(t[l],e,t,l);a!==void 0&&(t[l]=a)}let s=e(t,r,i);return s!==void 0?s:t},ve=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,a=[],n=[],c=0,f=0,o=0,u=0,d=0,h=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,A=m.some(b=>Array.isArray(b)&&b[0]==="export");e.set(_,{node:m,idx:c,used:A}),typeof _=="string"&&e.set(c,e.get(_)),c++}else if(g==="global"){let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:f,A=m.some(b=>Array.isArray(b)&&b[0]==="export");r.set(_,{node:m,idx:f,used:A}),typeof _=="string"&&r.set(f,r.get(_)),f++}else if(g==="table"){let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:u,A=m.some(b=>Array.isArray(b)&&b[0]==="export");s.set(_,{node:m,idx:u,used:A}),typeof _=="string"&&s.set(u,s.get(_)),u++}else if(g==="memory"){let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:d,A=m.some(b=>Array.isArray(b)&&b[0]==="export");l.set(_,{node:m,idx:d,used:A}),typeof _=="string"&&l.set(d,l.get(_)),d++}else if(g==="import"){for(let _ of m)if(Array.isArray(_)&&_[0]==="func"){let A=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:h;e.set(A,{node:m,idx:h,used:!0,isImport:!0}),typeof A=="string"&&e.set(h,e.get(A)),h++,c++}}else g==="export"?a.push(m):g==="start"&&n.push(m)}for(let m of a)for(let g of m){if(!Array.isArray(g))continue;let[_,A]=g;_==="func"&&e.has(A)?e.get(A).used=!0:_==="global"&&r.has(A)?r.get(A).used=!0:_==="table"&&s.has(A)?s.get(A).used=!0:_==="memory"&&l.has(A)&&(l.get(A).used=!0)}for(let m of n){let g=m[1];typeof g=="string"&&g[0]!=="$"&&(g=+g),e.has(g)&&(e.get(g).used=!0)}let $=a.length>0||n.length>0;if(!$){for(let[,m]of e)if(m.used){$=!0;break}if(!$){for(let[,m]of r)if(m.used){$=!0;break}}if(!$){for(let[,m]of s)if(m.used){$=!0;break}}if(!$){for(let[,m]of l)if(m.used){$=!0;break}}}if(!$){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"||G(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 y=!0;for(;y;){y=!1;for(let[,m]of e)!m.used||m.isImport||G(m.node,g=>{if(!Array.isArray(g)){typeof g=="string"&&g[0]==="$"&&e.has(g)&&!e.get(g).used&&(e.get(g).used=!0,y=!0);return}let[_,A]=g;if((_==="call"||_==="return_call"||_==="ref.func")&&e.has(A)&&!e.get(A).used&&(e.get(A).used=!0,y=!0),(_==="global.get"||_==="global.set")&&r.has(A)&&!r.get(A).used&&(r.get(A).used=!0,y=!0),_==="call_indirect"||_==="return_call_indirect")for(let b of g)typeof b=="string"&&b[0]==="$"&&s.has(b)&&!s.get(b).used&&(s.get(b).used=!0,y=!0);_==="type"&&i.has(A)&&!i.get(A).used&&(i.get(A).used=!0,y=!0)})}let k=["module"];for(let m of t.slice(1)){if(!Array.isArray(m)){k.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(b=>b.node===m))?.used&&k.push(m)}else if(g==="global"){let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;(_?r.get(_):[...r.values()].find(b=>b.node===m))?.used&&k.push(m)}else k.push(m)}return k},$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,Ie=t=>K(O(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 a=r.startsWith("i64.")&&!r.includes("eqz")?"i64":r.startsWith("f32.")?"f32":r.startsWith("f64.")?"f64":"i32";return Pt(a,l)}if(i.length===2&&e.length===3){let s=w(e[1]),l=w(e[2]);if(!s||!l)return;let a=i(s.value,l.value);if(a===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,a)}}}),ke={"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=>K(O(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let r=ke[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Be=t=>K(O(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 n=Math.log2(l.value);if(Number.isInteger(n))return["i32.shl",i,["i32.const",n]]}let a=w(i);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(r==="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",i,["i64.const",n]]}let a=w(i);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(r==="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",i,["i32.const",a]]}}if(r==="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",i,["i64.const",a]]}}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]]}}),Me=t=>K(O(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 a=null,n=null;for(let c=i+1;c<e.length;c++){let f=e[c];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 c=a.slice(1);return c.length===1?c[0]:["block",...c]}return["nop"]}else{if(n&&n.length>1){let c=n.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"]),ze=t=>{let e=O(t);return G(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)},Ue=t=>{let e=O(t);return G(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=[],s=new Map,l=new Set;for(let a=1;a<r.length;a++){let n=r[a];Array.isArray(n)&&(n[0]==="local"&&(i.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(r,a=>{if(!Array.isArray(a))return;let n=a[0];if(n==="local.get"||n==="local.set"||n==="local.tee"){let c=a[1];typeof c=="string"&&l.add(c)}});for(let a=i.length-1;a>=0;a--){let{idx:n,node:c}=i[a],f=typeof c[1]=="string"&&c[1][0]==="$"?c[1]:null;f&&!l.has(f)&&r.splice(n,1)}}),e},Te=t=>{let e=O(t);return G(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=new Map;((l,a=1)=>{for(let n=a;n<l.length;n++){let c=l[n];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(...O(u))}}else(f==="block"||f==="loop"||f==="if"||f==="call"||f==="call_indirect")&&i.clear();K(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 d=i.get(u);return O(d)}})}})(r)}),e},Ee=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=O(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=[],a=[],n=!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"?n=!0:o[0]==="export"?c=!0:o[0]!=="result"&&o[0]!=="type"&&a.push(o)}if(l&&!n&&!c&&l.length<=2&&a.length===1){let f=new Set(l.map(u=>u.name)),o=!1;G(a[0],u=>{Array.isArray(u)&&(u[0]==="local.set"||u[0]==="local.tee")&&f.has(u[1])&&(o=!0)}),o||r.set(s,{body:a[0],params:l})}}return r.size===0||K(e,i=>{if(!Array.isArray(i)||i[0]!=="call")return;let s=i[1];if(!r.has(s))return;let{body:l,params:a}=r.get(s),n=i.slice(2);if(a.length===0)return O(l);let c=O(l);return K(c,f=>{if(!Array.isArray(f)||f[0]!=="local.get")return;let o=f[1],u=a.findIndex(d=>d.name===o);if(u!==-1&&n[u])return O(n[u])}),c}),e};function xt(t,e=!0){return typeof t=="string"&&(t=D(t)),t=O(t),e=we(e),e.fold&&(t=Ie(t)),e.identity&&(t=Ne(t)),e.strength&&(t=Be(t)),e.branch&&(t=Me(t)),e.propagate&&(t=Te(t)),e.inline&&(t=Ee(t)),e.deadcode&&(t=ze(t)),e.locals&&(t=Ue(t)),e.treeshake&&(t=ve(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},qe=(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 Se(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 n=[];for(let o=2;o<s.length;o++){let u=qe(s[o]);u&&n.push(u)}let c=r.length,f=l.name||`$fn${c}`;i.set(l,{idx:c,name:f.startsWith("$")?f:"$"+f,params:n,fn:l}),r.push(i.get(l))}let a=i.get(l);s[1]=a.name}return s}),r}function Fe(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=D(i),l=[],a=0;s=It(s,f=>{if(f===Vt){let o=e[a++];if(typeof o=="function")return l.push(o),o;if(typeof o=="string"&&(o[0]==="("||/^\s*\(/.test(o))){let u=D(o);return Array.isArray(u)&&Array.isArray(u[0])&&(u._splice=!0),u}return o instanceof Uint8Array?[...o]:o}return f});let n=null;if(l.length){let f=Se(s,l);if(f.length){let o=Fe(f);s[0]==="module"?s.splice(1,0,...o):typeof s[0]=="string"?s=[...o,s]:s.unshift(...o),n={env:{}};for(let u of f)n.env[u.name.slice(1)]=u.fn}}r.polyfill&&(s=gt(s,r.polyfill)),r.optimize&&(s=xt(s,r.optimize));let c=rt(s);return n&&(c._imports=n),c}if(r.polyfill||r.optimize){let i=typeof t=="string"?D(t):t;return r.polyfill&&(i=gt(i,r.polyfill)),r.optimize&&(i=xt(i,r.optimize)),rt(i)}return rt(t)}function We(t,...e){let r=Oe(t,...e),i=new WebAssembly.Module(r);return new WebAssembly.Instance(i,r._imports).exports}var fr=We;export{Oe as compile,fr as default,xt as optimize,D as parse,gt as polyfill,Ot as print,We as watr};
1
+ var Jt=Object.defineProperty;var Zt=(t,e)=>{for(var r in e)Jt(t,r,{get:e[r],enumerable:!0})};var at={};Zt(at,{f32:()=>Q,f64:()=>J,i16:()=>ie,i32:()=>F,i64:()=>Z,i8:()=>re,uleb:()=>g,uleb5:()=>ee,v128:()=>bt});var I=(t,e=I.loc)=>{if(e!=null&&I.src){let r=1,i=1;for(let s=0;s<e&&s<I.src.length;s++)I.src[s]===`
2
+ `?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)};var zt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Tt=/^[+-]?(?:0x[\da-f]+|\d+)$/i,Qt=new TextEncoder,te=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),Mt={n:10,r:13,t:9,'"':34,"'":39,"\\":92},nt=t=>{let e=[],r=1,i,s,l="",n=()=>(l&&e.push(...Qt.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++):Mt[t[r]]?i=Mt[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},Et=t=>te.decode(new Uint8Array(nt(t)));var g=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):F.parse(t)),typeof t=="bigint"){for(;;){let i=Number(t&0x7Fn);if(t>>=7n,t===0n){e.push(i);break}e.push(i|128)}return e}let r=t&127;return t>>>=7,t===0?(e.push(r),e):(e.push(r|128),g(t,e))};function ee(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 F(t,e=[]){for(typeof t=="string"&&(t=F.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 Ut=t=>!zt.test(t)&&Tt.test(t=t.replaceAll("_",""))?t:I(`Bad int ${t}`),re=F,ie=F;F.parse=t=>(t=parseInt(Ut(t)),(t<-2147483648||t>4294967295)&&I("i32 constant out of range"),t);function Z(t,e=[]){for(typeof t=="string"?t=Z.parse(t):typeof t=="number"&&(t=BigInt(t)),typeof t=="bigint"&&t>0x7fffffffffffffffn&&(t=t-0x10000000000000000n);;){let r=Number(t&0x7Fn);if(t>>=7n,t===0n&&!(r&64)||t===-1n&&r&64){e.push(r);break}e.push(r|128)}return e}var it=new ArrayBuffer(8),C=new Uint8Array(it),se=new Int32Array(it),le=new Float32Array(it),ne=new Float64Array(it),dt=new BigInt64Array(it);Z.parse=t=>(t=Ut(t),t=t[0]==="-"?-BigInt(t.slice(1)):BigInt(t),(t<-0x8000000000000000n||t>0xffffffffffffffffn)&&I("i64 constant out of range"),dt[0]=t,dt[0]);var ae=2147483648,fe=2139095040;function Q(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=F.parse(t.slice(r+4)),e|=fe,t[0]==="-"&&(e|=ae),se[0]=e):(e=typeof t=="string"?Q.parse(t):t,le[0]=e),[C[0],C[1],C[2],C[3]]}var oe=0x8000000000000000n,ce=0x7ff0000000000000n;function J(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=Z.parse(t.slice(r+4)),e|=ce,t[0]==="-"&&(e|=oe),dt[0]=e):(e=typeof t=="string"?J.parse(t):t,ne[0]=e),[C[0],C[1],C[2],C[3],C[4],C[5],C[6],C[7]]}J.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,o=parseInt(l);isNaN(o)&&I();let f=n?parseInt("0x"+n)/16**a:0;s=parseInt(s,10);let c=r*(o+f)*2**s;return c=Math.max(-e,Math.min(e,c)),c}return t.includes("nan")?r<0?NaN:NaN:t.includes("inf")?r*(1/0):r*parseFloat(t)};Q.parse=t=>J.parse(t,34028234663852886e22);var bt=t=>{let e=BigInt(typeof t=="string"?t.replaceAll("_",""):t),r=new Uint8Array(16);for(let i=0;i<16;i++)r[i]=Number(e&0xffn),e>>=8n;return[...r]};var st=["unreachable","nop","block block","loop block","if block","else null","then null",,"throw tagidx",,"throw_ref","end end","br labelidx","br_if labelidx","br_table br_table","return","call funcidx","call_indirect call_indirect","return_call funcidx","return_call_indirect call_indirect","call_ref typeidx","return_call_ref typeidx",,,,,"drop","select select","",,,"try_table try_table","local.get localidx","local.set localidx","local.tee localidx","global.get globalidx","global.set globalidx","table.get tableidx","table.set tableidx",,"i32.load memarg","i64.load memarg","f32.load memarg","f64.load memarg","i32.load8_s memarg","i32.load8_u memarg","i32.load16_s memarg","i32.load16_u memarg","i64.load8_s memarg","i64.load8_u memarg","i64.load16_s memarg","i64.load16_u memarg","i64.load32_s memarg","i64.load32_u memarg","i32.store memarg","i64.store memarg","f32.store memarg","f64.store memarg","i32.store8 memarg","i32.store16 memarg","i64.store8 memarg","i64.store16 memarg","i64.store32 memarg","memory.size opt_memory","memory.grow opt_memory","i32.const i32","i64.const i64","f32.const f32","f64.const f64","i32.eqz","i32.eq","i32.ne","i32.lt_s","i32.lt_u","i32.gt_s","i32.gt_u","i32.le_s","i32.le_u","i32.ge_s","i32.ge_u","i64.eqz","i64.eq","i64.ne","i64.lt_s","i64.lt_u","i64.gt_s","i64.gt_u","i64.le_s","i64.le_u","i64.ge_s","i64.ge_u","f32.eq","f32.ne","f32.lt","f32.gt","f32.le","f32.ge","f64.eq","f64.ne","f64.lt","f64.gt","f64.le","f64.ge","i32.clz","i32.ctz","i32.popcnt","i32.add","i32.sub","i32.mul","i32.div_s","i32.div_u","i32.rem_s","i32.rem_u","i32.and","i32.or","i32.xor","i32.shl","i32.shr_s","i32.shr_u","i32.rotl","i32.rotr","i64.clz","i64.ctz","i64.popcnt","i64.add","i64.sub","i64.mul","i64.div_s","i64.div_u","i64.rem_s","i64.rem_u","i64.and","i64.or","i64.xor","i64.shl","i64.shr_s","i64.shr_u","i64.rotl","i64.rotr","f32.abs","f32.neg","f32.ceil","f32.floor","f32.trunc","f32.nearest","f32.sqrt","f32.add","f32.sub","f32.mul","f32.div","f32.min","f32.max","f32.copysign","f64.abs","f64.neg","f64.ceil","f64.floor","f64.trunc","f64.nearest","f64.sqrt","f64.add","f64.sub","f64.mul","f64.div","f64.min","f64.max","f64.copysign","i32.wrap_i64","i32.trunc_f32_s","i32.trunc_f32_u","i32.trunc_f64_s","i32.trunc_f64_u","i64.extend_i32_s","i64.extend_i32_u","i64.trunc_f32_s","i64.trunc_f32_u","i64.trunc_f64_s","i64.trunc_f64_u","f32.convert_i32_s","f32.convert_i32_u","f32.convert_i64_s","f32.convert_i64_u","f32.demote_f64","f64.convert_i32_s","f64.convert_i32_u","f64.convert_i64_s","f64.convert_i64_u","f64.promote_f32","i32.reinterpret_f32","i64.reinterpret_f64","f32.reinterpret_i32","f64.reinterpret_i64","i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s",,,,,,,,,,,,"ref.null ref_null","ref.is_null","ref.func funcidx","ref.eq","ref.as_non_null","br_on_null labelidx","br_on_non_null labelidx",,,,,,,,,,"cont.new typeidx","cont.bind cont_bind","suspend tagidx","resume resume","resume_throw resume_throw","resume_throw_ref resume_throw_ref","switch switch_cont",,,,,,,,,,,,,,,,,,,,,["struct.new typeidx","struct.new_default typeidx","struct.get typeidx_field","struct.get_s typeidx_field","struct.get_u typeidx_field","struct.set typeidx_field","array.new typeidx","array.new_default typeidx","array.new_fixed typeidx_multi","array.new_data typeidx_dataidx","array.new_elem typeidx_elemidx","array.get typeidx","array.get_s typeidx","array.get_u typeidx","array.set typeidx","array.len","array.fill typeidx","array.copy typeidx_typeidx","array.init_data typeidx_dataidx","array.init_elem typeidx_elemidx","ref.test reftype","","ref.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",,"struct.new_desc typeidx","struct.new_default_desc typeidx","ref.get_desc typeidx","ref.cast_desc_eq reftype",,"br_on_cast_desc_eq reftype2","br_on_cast_desc_eq_fail reftype2",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"string.new_utf8 memoryidx?","string.new_wtf16 memoryidx?","string.const stringidx","string.measure_utf8","string.measure_wtf8","string.measure_wtf16","string.encode_utf8 memoryidx?","string.encode_wtf16 memoryidx?","string.concat","string.eq","string.is_usv_sequence","string.new_lossy_utf8 memoryidx?","string.new_wtf8 memoryidx?","string.encode_lossy_utf8 memoryidx?","string.encode_wtf8 memoryidx?",,"string.as_wtf8","stringview_wtf8.advance","stringview_wtf8.encode_utf8 memoryidx?","stringview_wtf8.slice","stringview_wtf8.encode_lossy_utf8 memoryidx?","stringview_wtf8.encode_wtf8 memoryidx?",,,"string.as_wtf16","stringview_wtf16.length","stringview_wtf16.get_codeunit","stringview_wtf16.encode memoryidx?","stringview_wtf16.slice",,,,"string.as_iter","stringview_iter.next","stringview_iter.advance","stringview_iter.rewind","stringview_iter.slice",,,,,,,,,,,,"string.new_utf8_array","string.new_wtf16_array","string.encode_utf8_array","string.encode_wtf16_array","string.new_lossy_utf8_array","string.new_wtf8_array","string.encode_lossy_utf8_array","string.encode_wtf8_array"],["i32.trunc_sat_f32_s","i32.trunc_sat_f32_u","i32.trunc_sat_f64_s","i32.trunc_sat_f64_u","i64.trunc_sat_f32_s","i64.trunc_sat_f32_u","i64.trunc_sat_f64_s","i64.trunc_sat_f64_u","memory.init dataidx_memoryidx","data.drop dataidx","memory.copy memoryidx_memoryidx","memory.fill memoryidx?","table.init reversed","elem.drop elemidx","table.copy tableidx_tableidx","table.grow tableidx","table.size tableidx","table.fill tableidx",,"i64.add128","i64.sub128","i64.mul_wide_s","i64.mul_wide_u"],["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,strings:14,global:6,export:7,start:8,elem:9,datacount:12,code:10,data:11},E={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,cont:104,nocont:117,string:103,stringview_wtf8:102,stringview_wtf16:96,stringview_iter:97,nullfuncref:115,nullexternref:114,nullexnref:116,nullref:113,funcref:112,externref:111,exnref:105,anyref:110,eqref:109,i31ref:108,structref:107,arrayref:106,contref:104,nocontref:117,stringref:103,ref:100,refnull:99,sub:80,subfinal:79,rec:78},V={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},At={func:0,table:1,memory:2,global:3,tag:4};var D=t=>{let e=0,r=[],i="",s=0,l=0,n=()=>i&&(r.push(i),i=""),a=o=>{r.loc=o;for(let f,c,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):s===-2&&f===41?(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=t.indexOf(`
3
+ `,e)<0?-2:-1,i=t[e++]+t[e++];else if(f===40&&t.charCodeAt(e+1)===64)n(),u=e,e+=2,i="@",l++,(c=r).push(r=[]),a(u),r=c;else if(f===40)n(),u=e++,l++,(c=r).push(r=[]),a(u),r=c;else{if(f===41)return n(),e++,l--;f<=32?(n(),e++):i+=t[e++]}s<0&&n(),n()};return a(0),s===34&&I("Unclosed quote",e),s>59&&I("Unclosed block comment",e),l>0&&I("Unclosed parenthesis",e),e<t.length&&I("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var Ot=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(Ot).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("\\")?"$"+Et(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?nt(t):t;function et(t){typeof t=="string"?(I.src=t,t=D(t)||[]):I.src="",I.loc=0,t=Ot(t)||[];let e=0;if(t[0]==="module"?(e++,S(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return et(t.slice(++e).map(u=>u.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((u,h)=>{if(h<e||!Array.isArray(u)||u[0]!=="import")return[u];let[,p,...b]=u;if(!b.some(x=>Array.isArray(x)&&x[0]==="item"))return[u];if(Array.isArray(b.at(-1))&&b.at(-1)[0]!=="item"){let x=b.at(-1);return b.slice(0,-1).filter(m=>m[0]==="item").map(([,m])=>["import",p,m,x])}return b.filter(x=>x[0]==="item").map(([,x,m])=>["import",p,x,m])});let r=[];for(let u in B)(r[B[u]]=r[u]=[]).name=u;r.metadata={},t.slice(e).filter(u=>{if(!Array.isArray(u)){let b=I.loc,_=I.src,x;for(;(b=_.indexOf(u,b))>=0;){if(x=_.charCodeAt(b-1),b>0&&(x>47&&x<58||x>64&&x<91||x>96&&x<123||x===95||x===36)){b++;continue}if(x=_.charCodeAt(b+u.length),x>47&&x<58||x>64&&x<91||x>96&&x<123||x===95){b++;continue}break}b>=0&&(I.loc=b),I(`Unexpected token ${u}`)}let[h,...p]=u;if(I.loc=u.loc,h==="@custom")r.custom.push(p);else if(h==="rec")for(let b=0;b<p.length;b++){let[,..._]=p[b];wt(_,r.type);let x=[];for(;_[0]?.[0]==="descriptor"||_[0]?.[0]==="describes";)x.push(_.shift());(_=qt(_,r)).push(b?!0:[r.type.length,p.length]),x.length&&(_.desc=_.desc?[...x,..._.desc]:x),r.type.push(_)}else if(h==="type"){wt(p,r.type);let b=[];for(;p[0]?.[0]==="descriptor"||p[0]?.[0]==="describes";)b.push(p.shift());let _=qt(p,r);b.length&&(_.desc=_.desc?[...b,..._.desc]:b),r.type.push(_)}else if(h==="start"||h==="export")r[h].push(p);else return!0}).forEach(u=>{let[h,...p]=u;I.loc=u.loc;let b;h==="import"&&([h,...p]=(b=p).pop());let _=r[h];for(_||I(`Unknown section ${h}`),wt(p,_);p[0]?.[0]==="export";)r.export.push([p.shift()[1],[h,_?.length]]);if(p[0]?.[0]==="import"&&([,...b]=p.shift()),h==="table"){let x=p[0]==="i64",m=x?1:0;if(p[m+1]?.[0]==="elem"){let[d,[,...y]]=[p[m],p[m+1]];p=x?["i64",y.length,y.length,d]:[y.length,y.length,d],r.elem.push([["table",_.length],["offset",[x?"i64.const":"i32.const",x?0n:0]],d,...y])}}else if(h==="memory"){let x=p[0]==="i64",m=x?1:0;if(p[m]?.[0]==="data"){let d=p.find(w=>Array.isArray(w)&&w[0]==="pagesize")?.[1]??65536,[,...y]=p.splice(m,1)[0],v=""+Math.ceil(y.reduce((w,k)=>w+k.length,0)/d);r.data.push([["memory",_.length],[x?"i64.const":"i32.const",x?0n:0],...y]),p=x?["i64",v,v]:[v,v]}}else if(h==="func"){let[x,m,d]=yt(p,r);x??=_t(m,d,r),!b&&r.code.push([[x,m,d],...Y(p,r)]),p=[["type",x]]}else if(h==="tag"){let[x,m]=yt(p,r);x??=_t(m,[],r),p=[["type",x]]}b&&(r.import.push([...b,[h,...p]]),p=null),_.push(p)});let i=(u,h=!0)=>{let p=r[u].filter(Boolean).map(b=>Ft[u](b,r)).filter(Boolean);return u===B.custom?p.flatMap(b=>[u,...N(b)]):p.length?[u,...N(h?N(p):p)]:[]},s=()=>{let u=[];for(let h in r.metadata){let p=N(nt(`"metadata.code.${h}"`)),b=N(r.metadata[h].map(([_,x])=>[...g(_),...N(x.map(([m,d])=>[...g(m),...N(d)]))]));u.push(0,...N([...p,...b]))}return u},l=i(B.global),n=i(B.elem),a=i(B.code),o=s(),f=i(B.data),c=r.strings.length?[B.strings,...N([0,...N(r.strings.map(u=>N(u)))])]:[];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),...c,...l,...i(B.export),...i(B.start,!1),...n,...i(B.datacount,!1),...a,...o,...f])}var L=t=>t?.[0]==="$"||!isNaN(t),S=t=>t?.[0]==="$",vt=t=>t?.[0]==="a"||t?.[0]==="o";function Y(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")S(t[0])&&r.push(t.shift()),r.push(ft(t,e));else if(i==="else"||i==="end")S(t[0])&&t.shift();else if(i==="select")r.push(pt(t)[1]);else if(i.endsWith("call_indirect")){let s=L(t[0])?t.shift():0,[l,n,a]=yt(t,e);r.push(s,["type",l??_t(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&&(I.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(st[s])){r.push(i);continue}let l=i.slice(1);if(s==="block"||s==="loop")r.push(s),S(l[0])&&r.push(l.shift()),r.push(ft(l,e),...Y(l,e),"end");else if(s==="if"){let n=[],a=[];l.at(-1)?.[0]==="else"&&(a=Y(l.pop().slice(1),e)),l.at(-1)?.[0]==="then"&&(n=Y(l.pop().slice(1),e));let o=[s];S(l[0])&&o.push(l.shift()),o.push(ft(l,e)),r.push(...Y(l,e),...o,...n),a.length&&r.push("else",...a),r.push("end")}else if(s==="try_table"){for(r.push(s),S(l[0])&&r.push(l.shift()),r.push(ft(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(...Y(l,e),"end")}else{let n=[];for(;l.length&&(!Array.isArray(l[0])||l[0].valueOf!==Array.prototype.valueOf||"type,param,result,ref,exact,on".includes(l[0][0]));)n.push(l.shift());r.push(...Y(l,e),s,...n),t.unshift(...r.splice(r.length-1-n.length))}}else r.push(i)}return r}var _t=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),$t=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=S(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},pt=t=>{let e=$t(t,"param"),r=$t(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},yt=(t,e)=>{if(t[0]?.[0]!=="type")return[,...pt(t)];let[,r]=t.shift(),[i,s]=pt(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]]},ft=(t,e)=>{let[r,i,s]=yt(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??_t(i,s,e)]},wt=(t,e)=>{let r=S(t[0])&&t.shift();return r&&(r in e?I(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},qt=([t],e)=>{let r="subfinal",i=[],s,l=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(i=t).pop(),i=i.filter(a=>Array.isArray(a)&&(a[0]==="descriptor"||a[0]==="describes")?(l.push(a),!1):!0)),[s,...t]=t,s==="func"?(t=pt(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=$t(t,"field"):s==="array"&&([t]=t);let n=[s,t,r,i];return l.length&&(n.desc=l),n},Ft=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...N(t),...i.flat()]},(t,e)=>{let[r,i,s,l,n]=t;if(n===!0)return;let a=(t.desc??[]).flatMap(([f,c])=>[f==="descriptor"?77:76,...g(A(c,e.type))]),o=(f,c)=>f==="func"?[V.func,...N(c[0].map(u=>W(u,e))),...N(c[1].map(u=>W(u,e)))]:f==="array"?[V.array,...ot(c,e)]:f==="struct"?[V.struct,...N(c.map(u=>ot(u,e)))]:f==="cont"?[V.cont,...g(A(c[0]??c,e.type))]:[V[f]];if(n){let[f,c]=n,u=Array.from({length:c},(h,p)=>{let b=e.type[f+p],_=b.slice(0,4);return b.desc&&(_.desc=b.desc),Ft[B.type](_,e)});return[V.rec,...N(u)]}else if(s==="sub"||l?.length)return[V[s],...N(l.map(f=>A(f,e.type))),...a,...o(r,i)];return[...a,...o(r,i)]},([t,e,[r,...i]],s)=>{let l,n=At[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(n=32);let[[,o]]=i;l=g(A(o,s.type))}else if(r==="tag"){let[[,a]]=i;l=[0,...g(A(a,s.type))]}else r==="memory"?l=ct(i):r==="global"?l=ot(i[0],s):r==="table"?l=[...W(i.pop(),s),...ct(i)]:I(`Unknown kind ${r}`);return[...N(t),...N(e),n,...l]},([[,t]],e)=>g(A(t,e.type)),(t,e)=>{let r=ct(t),i=W(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...tt(s,e)]:[...i,...r]},(t,e)=>ct(t),([t,e],r)=>[...ot(t,r),...tt(e,r)],([t,[e,r]],i)=>[...N(t),At[e],...g(A(r,i[e]))],([t],e)=>g(A(t,e.func)),(t,e)=>{let r=0,i=0,s=0,l=0,n,a,o;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=tt(a,e)):i||(r=1),E[t[0]]||t[0]?.[0]==="ref"?o=W(t.shift(),e):t[0]==="func"?o=[E[t.shift()]]:o=[E.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]!==E.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?[...g(n||0),...a,0]:f===3?[0]:f===4?a:f===5?o:f===6?[...g(n||0),...a,...o]:o,...N(t.map(s?c=>tt(typeof c=="string"?["ref.func",c]:c,e):c=>g(A(c,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[,...o]=t.shift();if(S(o[0])){let f=o.shift();f in e.local?I(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...o)}e.meta={};let l=Ct(t,e),n=e.import.filter(o=>o[2][0]==="func").length+s;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([n,e.meta[o]]);let a=e.local.slice(i.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,N([...N(a.map(([o,f])=>[...g(o),...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??I("Bad offset",r)),[...i?[2,...g(i),...tt(r,e)]:r?[0,...tt(r,e)]:[1],...N(t.flatMap(s=>_e(s)??[...s]))]},(t,e)=>g(e.data.length),([[,t]],e)=>[0,...g(A(t,e.type))]],W=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[E.refnull,98,...g(A(t[2][1],e.type))]:E[t[2]]?[E[t[2]]]:[E.refnull,...g(A(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[E.ref,98,...g(A(t[1][1],e.type))]:[E.ref,...g(E[t[t.length-1]]||A(t[t.length-1],e.type))]:[E[t]??I(`Unknown type ${t}`)],ot=(t,e,r=t[0]==="mut"?1:0)=>[...W(r?t[1]:t,e),r],Wt={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...g(A(i,e.elem)),...g(A(r,e.table))]},block:(t,e)=>{e.block.push(1),S(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?W(r[1],e):g(A(r[1],e.type)):[E.void]},try_table:(t,e)=>{S(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?W(r[1],e):g(A(r[1],e.type)):[E.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,...g(A(n[1],e.tag)),...g(H(n[2],e.block))):s.push(a,...g(H(n[1],e.block))),l++}return e.block.push(1),[...i,...g(l),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...g(A(i,e.type)),...g(A(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||S(t[0]));)r.push(...g(H(t.shift(),e.block))),i++;return[...g(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?N(r.map(i=>W(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...g(A(r[1],e.type))]:E[r]?[E[r]]:g(A(r,e.type))},memarg:(t,e,r)=>St(t,r,L(t[0])&&!vt(t[0])?A(t.shift(),e.memory):0),opt_memory:(t,e)=>g(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=H(t.shift(),e.block),i=W(t.shift(),e),s=W(t.shift(),e),l=n=>n.length>1?n.slice(1):n;return[(s[0]!==E.ref)<<1|i[0]!==E.ref,...g(r),...l(i),...l(s)]},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]=at[e].parse(t.shift());return[...new Uint8Array(n.buffer)]}let l=new Uint8Array(16);for(let n=0;n<r;n++)l.set(at[e](t.shift()),n*s);return[...l]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(mt(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&I("invalid lane length"),e},memlane:(t,e,r)=>{let i=S(t[0])||L(t[0])&&(vt(t[1])||L(t[1]))?A(t.shift(),e.memory):0;return[...St(t,r,i),...g(mt(t.shift()))]},"*":t=>g(t.shift()),labelidx:(t,e)=>g(H(t.shift(),e.block)),laneidx:t=>[mt(t.shift(),255)],funcidx:(t,e)=>g(A(t.shift(),e.func)),typeidx:(t,e)=>g(A(t.shift(),e.type)),tableidx:(t,e)=>g(A(t.shift(),e.table)),memoryidx:(t,e)=>g(A(t.shift(),e.memory)),globalidx:(t,e)=>g(A(t.shift(),e.global)),localidx:(t,e)=>g(A(t.shift(),e.local)),dataidx:(t,e)=>g(A(t.shift(),e.data)),elemidx:(t,e)=>g(A(t.shift(),e.elem)),tagidx:(t,e)=>g(A(t.shift(),e.tag)),"memoryidx?":(t,e)=>g(A(L(t[0])?t.shift():0,e.memory)),stringidx:(t,e)=>{let r=t.shift(),i=r.valueOf(),s=e.strings.findIndex(l=>l.valueOf()===i);return s<0&&(s=e.strings.push(r)-1),g(s)},i32:t=>F(t.shift()),i64:t=>Z(t.shift()),f32:t=>Q(t.shift()),f64:t=>J(t.shift()),v128:t=>bt(t.shift()),typeidx_field:(t,e)=>{let r=A(t.shift(),e.type);return[...g(r),...g(A(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...g(A(t.shift(),e.type)),...g(t.shift())],typeidx_dataidx:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...g(A(t.shift(),e.data)),...g(A(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...g(A(t.shift(),e.memory)),...g(A(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...g(A(t.shift(),e.table)),...g(A(t.shift(),e.table))],cont_bind:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.type))],switch_cont:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.tag))],resume:(t,e)=>{let r=g(A(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,l,n]=t.shift();n==="switch"?i.push(1,...g(A(l,e.tag))):i.push(0,...g(A(l,e.tag)),...g(H(n,e.block))),s++}return[...r,...g(s),...i]},resume_throw:(t,e)=>{let r=g(A(t.shift(),e.type)),i=g(A(t.shift(),e.tag)),s=[],l=0;for(;t[0]?.[0]==="on";){let[,n,a]=t.shift();a==="switch"?s.push(1,...g(A(n,e.tag))):s.push(0,...g(A(n,e.tag)),...g(H(a,e.block))),l++}return[...r,...i,...g(l),...s]},resume_throw_ref:(t,e)=>{let r=g(A(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,l,n]=t.shift();n==="switch"?i.push(1,...g(A(l,e.tag))):i.push(0,...g(A(l,e.tag)),...g(H(n,e.block))),s++}return[...r,...g(s),...i]}},ut={};(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(" "),st[l]=r?[r,...g(i)]:[i],n&&(ut[l]=Wt[n])))})(st);var Ct=(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&&(I.loc=s.loc),I(`Unknown instruction ${s[0]}`));let[...l]=st[s]||I(`Unknown instruction ${s}`);ut[s]&&(s==="select"&&t[0]?.length?l[0]++:ut[s]===Wt.reftype&&(t[0][1]==="null"||t[0][0]!=="ref")&&l[l.length-1]++,l.push(...ut[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},tt=(t,e)=>Ct(Y([t],e),e),A=(t,e,r)=>(r=S(t)?e[t]:+t,r in e?r:I(`Unknown ${e.name} ${t}`)),H=(t,e,r)=>(r=S(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?I(`Bad label ${t}`):r),ue=t=>{let e,r,i,s;for(;vt(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:I(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&I(`Bad offset ${r}`),(e<=0||e>4294967295)&&I(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&I(`Bad align ${e}`),[e,r]},St=(t,e,r=0)=>{let[i,s]=ue(t),l=(i??me(e))|(r&&64);return r?[...g(l),...g(r),...g(s??0)]:[...g(l),...g(s??0)]},me=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)},_e=t=>{if(!Array.isArray(t))return null;let[e,...r]=t;if(e!=="i8"&&e!=="i16"&&e!=="i32"&&e!=="i64"&&e!=="f32"&&e!=="f64")return null;let i=[],s=new DataView(new ArrayBuffer(8));for(let l of r)e==="i8"?i.push(F.parse(l)&511&255):e==="i16"?(s.setInt16(0,F.parse(l),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,F.parse(l),!0),i.push(...new Uint8Array(s.buffer,0,4))):e==="i64"?(s.setBigInt64(0,BigInt(l),!0),i.push(...new Uint8Array(s.buffer,0,8))):e==="f32"?i.push(...Q(l)):e==="f64"&&i.push(...J(l));return i},ct=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(f=>Array.isArray(f)&&f[0]==="pagesize"),s=-1;i>=0&&(s=Math.log2(+t.splice(i,1)[0][1]));let l=!isNaN(parseInt(t[1])),n=(s>=0?8:0)|(e?4:0)|(r?2:0)|(l?1:0),a=e?f=>{if(typeof f=="bigint")return f;let c=typeof f=="string"?f.replaceAll("_",""):String(f);return BigInt(c)}:mt,o=s>=0?g(s):[];return l?[n,...g(a(t.shift())),...g(a(t.shift())),...o]:[n,...g(a(t.shift())),...o]},mt=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?F.parse(t):typeof t=="number"?t:I(`Bad int ${t}`);return r>e?I(`Value out of range ${t}`):r},N=t=>[...g(t.length),...t.flat()];function Dt(t,e={}){typeof t=="string"&&(t=D(t));let{indent:r=" ",newline:i=`
4
+ `,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,o=0){if(!Array.isArray(a))return a;let f=a[0];if(!f)return"";let c=!1;if(f==="try_table"){let p=1;for(typeof a[p]=="string"&&a[p][0]==="$"&&(f+=" "+a[p++]),Array.isArray(a[p])&&(a[p][0]==="result"||a[p][0]==="type")&&(f+=" "+n(a[p++],o));Array.isArray(a[p])&&/^catch/.test(a[p][0]);)f+=" "+n(a[p++],o).trim();for(;p<a.length;p++)f+=Array.isArray(a[p])?i+r.repeat(o+1)+n(a[p],o+1):" "+a[p];return`(${f+i+r.repeat(o)})`}let u=!!i&&a.length<4&&!a.some(p=>typeof p=="string"&&p[0]===";"&&p[1]===";"),h=r.repeat(o+1);for(let p=1;p<a.length;p++){let b=a[p].valueOf();if(typeof b=="string"&&b[1]===";"){if(!s)continue;if(b[0]===";")if(i)f+=i+h+b.trimEnd(),c=!0;else{let _=f[f.length-1];_&&_!==" "&&_!=="("&&(f+=" "),f+=b.trimEnd()+`
5
+ `}else{let _=f[f.length-1];_&&_!==" "&&_!=="("&&(f+=" "),f+=b.trimEnd()}}else if(Array.isArray(b))u&&(u=b.every(_=>!Array.isArray(_))),f+=i+h+n(b,o+1),c=!1;else if(a[0]==="data")u=!1,(i||f[f.length-1]!==")")&&(f+=i||" "),f+=h+b,c=!1;else{let _=f[f.length-1];c&&i?f+=i+h:_===`
6
+ `?f+="":(_&&_!==")"&&_!==" "||i||_===")")&&(f+=" "),f+=b,c=!1}}return u?`(${f.replaceAll(i+h+"("," (")})`:`(${f+i+r.repeat(o)})`}}var Pt={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"]},It=Object.keys(Pt),pe=t=>{if(t===!0)return Object.fromEntries(It.map(e=>[e,!0]));if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return Object.fromEntries(It.map(r=>[r,e.has(r)||e.has("all")]))}return{...t}},q=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)q(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)},ye=t=>{let e=new Set;return q(t,r=>{if(typeof r=="string")for(let[i,s]of Object.entries(Pt))s.some(l=>r===l||r.startsWith(l+" "))&&e.add(i)}),q(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")&&q(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),q(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},jt=t=>Array.isArray(t)?t.map(jt):t,Rt=(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},gt=(t,e,r)=>t.splice(e,0,r),ge=0,R=t=>`$__${t}${ge++}`,xe=(t,e)=>{let r=new Set;if(q(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,c)=>[f,c])),n=Rt(t,"func"),a=n.length?n[0].idx:t[0]==="module"?1:0;gt(t,a,["table",i,"funcref",["elem",...s]]);let o={};return q(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 u=[],h=[];for(let p of f){if(Array.isArray(p)&&p[0]==="param")for(let b=1;b<p.length;b++)p[b][0]!=="$"&&u.push(p[b]);if(Array.isArray(p)&&p[0]==="result")for(let b=1;b<p.length;b++)h.push(p[b])}o[c]={params:u,results:h}}),j(t,(f,c,u)=>{if(!(!Array.isArray(f)||!c)){if(f[0]==="ref.func"&&l[f[1]]!==void 0&&(c[u]=["i32.const",l[f[1]]]),f[0]==="call_ref"){let h=f[1],p=f.slice(2);c[u]=["call_indirect",i,["type",h],...p]}if(f[0]==="return_call_ref"){let h=f[1],p=f.slice(2);c[u]=["return_call_indirect",i,["type",h],...p]}}}),t},P={funcref:xe},he={"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]},de=(t,e)=>(j(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let l=he[r[0]];if(!l)return;let[n,a]=l,o=r.slice(1);i[s]=[`${n}.shr_s`,[`${n}.shl`,...o,[`${n}.const`,a]],[`${n}.const`,a]]}),t);P.sign_ext=de;var Lt={"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}},be=(t,e)=>{let r=new Set;if(q(t,s=>{Array.isArray(s)&&Lt[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:o,max:f}=Lt[s],c=R(`trunc_${l}_${n}_${a?"s":"u"}`);i[s]=c;let u=`${l}.trunc_${n}_${a?"s":"u"}`,h=l==="i64"?0n:0,p=["func",c,["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 o=="bigint"?Number(o):o]],["then",[`${l}.const`,o]],["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(p)}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=be;var Ae=(t,e)=>{let r=new Set,i=new Set;q(t,n=>{if(Array.isArray(n)){if(n[0]==="memory.copy"){let a=typeof n[1]=="number"?n[1]:0,o=typeof n[2]=="number"?n[2]:0;r.add(`${a}_${o}`)}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,o]=n.split("_").map(Number),f=R(`memcpy${n==="0_0"?"":"_"+n}`);s[n]=f;let c=a?["i32.store8",a]:["i32.store8"],u=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"]],[...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 o=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"]]],[...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 j(t,(n,a,o)=>{if(!(!Array.isArray(n)||!a)){if(n[0]==="memory.copy"){let f=typeof n[1]=="number"?n[1]:0,c=typeof n[2]=="number"?n[2]:0,u=n.filter(h=>Array.isArray(h)||typeof h=="string"&&h[0]==="$");a[o]=["call",s[`${f}_${c}`],...u]}if(n[0]==="memory.fill"){let f=typeof n[1]=="number"?n[1]:0,c=n.filter(u=>Array.isArray(u)||typeof u=="string"&&u[0]==="$");a[o]=["call",l[f],...c]}}}),t};P.bulk_memory=Ae;var we=(t,e)=>{let r=!1;return q(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=we;var ve=(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=ve;var $e=(t,e)=>{let r={};q(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 o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f+c]}}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 o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f-c]}}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 o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f*c]}}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 o=i(s[a]);o!==s[a]&&(s[a]=o)}}}),t};P.extended_const=$e;var Ie=(t,e)=>{let r=new Map,i=[];if(q(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let o=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null,f=[];for(let c of a)if(Array.isArray(c)&&c[0]==="result")for(let u=1;u<c.length;u++)f.push(c[u]);f.length>1&&o&&r.set(o,f)}),!r.size)return t;let s=Math.max(...[...r.values()].map(a=>a.length)),l={};for(let[a,o]of r)for(let f=1;f<o.length;f++){let c=o[f];if(l[c]||(l[c]=[]),l[c].length<f){let u=R(`ret_${c}_${l[c].length}`);l[c].push(u),i.push(["global",u,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let n=t[0]==="module"?1:0;for(let a of i.reverse())gt(t,n,a);return j(t,(a,o,f)=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!c||!r.has(c))return;let u=r.get(c);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=Ie;var lt={i32:4,i64:8,f32:4,f64:8},ke=(t,e)=>{let r=new Map,i=new Map,s=1;if(q(t,_=>{if(!Array.isArray(_)||_[0]!=="type")return;let x=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:null;if(x){for(let m of _)if(Array.isArray(m)){if(m[0]==="struct"){let d=[];for(let y of m)if(Array.isArray(y)&&y[0]==="field"){let v=typeof y[1]=="string"&&y[1][0]==="$"?y[1]:null,w=v?y[2]:y[1],k=Array.isArray(w)&&w[0]==="mut"?w[1]:w;d.push({name:v,type:k})}r.set(x,{kind:"struct",fields:d}),i.set(x,s++)}if(m[0]==="array"){let d=m[1],y=Array.isArray(d)&&d[0]==="mut"?d[1]:d;r.set(x,{kind:"array",elemType:y}),i.set(x,s++)}}}}),!r.size)return t;let l=Rt(t,"memory").length>0,n=R("alloc"),a=R("heap_ptr"),o=t[0]==="module"?1:0;l||gt(t,o,["memory",1]),gt(t,o+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 c=_=>{let x=4;for(let m of _.fields)x+=lt[m.type]||4;return x},u=(_,x)=>{let m=4;for(let d=0;d<x;d++)m+=lt[_.fields[d].type]||4;return m},h=(_,x)=>{for(let m=0;m<_.fields.length;m++)if(_.fields[m].name===x)return m;return-1},p=0,b=()=>`$__gc_tmp${p++}`;return q(t,_=>{if(!Array.isArray(_)||_[0]!=="func")return;let x=!1,m=!1,d=!1,y=!1;if(q(_,w=>{Array.isArray(w)&&((w[0]==="struct.new"||w[0]==="struct.new_default")&&(x=!0),(w[0]==="array.new"||w[0]==="array.new_default")&&(m=!0,d=!0,y=!0))}),!x&&!m)return;let v=1;for(let w=1;w<_.length;w++){let k=_[w];if(Array.isArray(k)&&(k[0]==="param"||k[0]==="result"||k[0]==="local"||k[0]==="export"||k[0]==="type"))v=w+1;else if(typeof k=="string"&&k[0]==="$")v=w+1;else if(!Array.isArray(k))v=w+1;else break}x&&_.splice(v++,0,["local","$__gc_ptr","i32"]),m&&_.splice(v++,0,["local","$__gc_aptr","i32"]),d&&_.splice(v++,0,["local","$__gc_alen","i32"]),y&&_.splice(v++,0,["local","$__gc_aidx","i32"])}),j(t,(_,x,m)=>{if(!(!Array.isArray(_)||!x)){if(_[0]==="struct.new"||_[0]==="struct.new_default"){let d=_[1],y=r.get(d);if(!y||y.kind!=="struct")return;let v=c(y),w=i.get(d),k=_.slice(2),M="$__gc_ptr",U=[["local.set",M,["call",n,["i32.const",v]]],["i32.store",["local.get",M],["i32.const",w]]];if(_[0]==="struct.new")for(let z=0;z<y.fields.length;z++){let T=y.fields[z],rt=u(y,z),X=T.type==="i64"?"i64.store":T.type==="f32"?"f32.store":T.type==="f64"?"f64.store":"i32.store";U.push([X,["i32.add",["local.get",M],["i32.const",rt]],k[z]||[`${T.type}.const`,0]])}else for(let z=0;z<y.fields.length;z++){let T=y.fields[z],rt=u(y,z),X=T.type==="i64"?"i64.store":T.type==="f32"?"f32.store":T.type==="f64"?"f64.store":"i32.store",Xt=T.type==="i64"?["i64.const",0n]:T.type==="f32"?["f32.const",0]:T.type==="f64"?["f64.const",0]:["i32.const",0];U.push([X,["i32.add",["local.get",M],["i32.const",rt]],Xt])}U.push(["local.get",M]),x[m]=["block",["result","i32"],...U]}if(_[0]==="struct.get"){let d=_[1],y=_[2],v=_[3],w=r.get(d);if(!w||w.kind!=="struct")return;let k=typeof y=="string"&&y[0]==="$"?h(w,y):parseInt(y);if(k<0)return;let M=w.fields[k],U=u(w,k),z=M.type==="i64"?"i64.load":M.type==="f32"?"f32.load":M.type==="f64"?"f64.load":"i32.load";x[m]=[z,["i32.add",v,["i32.const",U]]]}if(_[0]==="struct.set"){let d=_[1],y=_[2],v=_[3],w=_[4],k=r.get(d);if(!k||k.kind!=="struct")return;let M=typeof y=="string"&&y[0]==="$"?h(k,y):parseInt(y);if(M<0)return;let U=k.fields[M],z=u(k,M),T=U.type==="i64"?"i64.store":U.type==="f32"?"f32.store":U.type==="f64"?"f64.store":"i32.store";x[m]=[T,["i32.add",v,["i32.const",z]],w]}if(_[0]==="array.new"||_[0]==="array.new_default"){let d=_[1],y=r.get(d);if(!y||y.kind!=="array")return;let v=i.get(d),w=lt[y.elemType]||4,k=_[0]==="array.new"?_[2]:null,M=_[0]==="array.new"?_[3]:_[2],U="$__gc_aptr",z="$__gc_alen",T="$__gc_aidx",rt=y.elemType==="i64"?"i64.store":y.elemType==="f32"?"f32.store":y.elemType==="f64"?"f64.store":"i32.store",X=[["local.set",z,M],["local.set",U,["call",n,["i32.add",["i32.const",8],["i32.mul",["local.get",z],["i32.const",w]]]]],["i32.store",["local.get",U],["i32.const",v]],["i32.store",["i32.add",["local.get",U],["i32.const",4]],["local.get",z]]];k&&X.push(["local.set",T,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",T],["local.get",z]]],[rt,["i32.add",["i32.add",["local.get",U],["i32.const",8]],["i32.mul",["local.get",T],["i32.const",w]]],k],["local.set",T,["i32.add",["local.get",T],["i32.const",1]]],["br","$loop"]]]),X.push(["local.get",U]),x[m]=["block",["result","i32"],...X]}if(_[0]==="array.get"){let d=_[1],y=_[2],v=_[3],w=r.get(d);if(!w||w.kind!=="array")return;let k=lt[w.elemType]||4,M=w.elemType==="i64"?"i64.load":w.elemType==="f32"?"f32.load":w.elemType==="f64"?"f64.load":"i32.load";x[m]=[M,["i32.add",["i32.add",y,["i32.const",8]],["i32.mul",v,["i32.const",k]]]]}if(_[0]==="array.set"){let d=_[1],y=_[2],v=_[3],w=_[4],k=r.get(d);if(!k||k.kind!=="array")return;let M=lt[k.elemType]||4,U=k.elemType==="i64"?"i64.store":k.elemType==="f32"?"f32.store":k.elemType==="f64"?"f64.store":"i32.store";x[m]=[U,["i32.add",["i32.add",y,["i32.const",8]],["i32.mul",v,["i32.const",M]]],w]}if(_[0]==="array.len"){let d=_[1];x[m]=["i32.load",["i32.add",d,["i32.const",4]]]}}}),t};P.gc=ke;var Ne=(t,e)=>{let r=new Map,i=1;return q(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],o=null;Array.isArray(a)&&a[0]==="ref"&&(o=a[1]==="null"?a[2]:a[1]);let f=s[2],c=r.get(o);c!==void 0&&(l[n]=["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 a=s[1],o=null,f=!1;Array.isArray(a)&&a[0]==="ref"&&(a[1]==="null"?(f=!0,o=a[2]):o=a[1]);let c=s[2],u=r.get(o);if(u!==void 0){let h=R("cast");f?l[n]=["block",["result","i32"],["local",h,"i32"],["local.set",h,c],["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,c],["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],o=s[2],f=s[3],c=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 p=R("brcast");l[n]=["block",["result","i32"],["local",p,"i32"],["local.set",p,c],["br_if",a,["i32.and",["i32.ne",["local.get",p],["i32.const",0]],["i32.eq",["i32.load",["local.get",p]],["i32.const",h]]]],["local.get",p]]}}if(s[0]==="br_on_cast_fail"){let a=s[1],o=s[2],f=s[3],c=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 p=R("brfail");l[n]=["block",["result","i32"],["local",p,"i32"],["local.set",p,c],["br_if",a,["i32.or",["i32.eqz",["local.get",p]],["i32.ne",["i32.load",["local.get",p]],["i32.const",h]]]],["local.get",p]]}}}}),t};P.ref_cast=Ne;function xt(t,e=!0){typeof t=="string"&&(t=D(t)),t=jt(t),e=pe(e);let r=ye(t),i={uid:0};for(let s of It)r.has(s)&&e[s]!==!1&&P[s]&&(t=P[s](t,i));return t}var Nt={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!0},kt=Object.keys(Nt),Be=t=>{if(t===!0)return{...Nt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.size===1&&kt.includes([...e][0])?Object.fromEntries(kt.map(r=>[r,e.has(r)])):Object.fromEntries(kt.map(r=>[r,e.has(r)||e.has("all")]))}return{...Nt,...t}},O=t=>Array.isArray(t)?t.map(O):t,G=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)G(t[s],e,t,s)},K=(t,e,r,i)=>{if(Array.isArray(t))for(let l=0;l<t.length;l++){let n=K(t[l],e,t,l);n!==void 0&&(t[l]=n)}let s=e(t,r,i);return s!==void 0?s:t},Me=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=[],o=0,f=0,c=0,u=0,h=0,p=0;for(let m of t.slice(1)){if(!Array.isArray(m))continue;let d=m[0];if(d==="type"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:c;i.set(y,{node:m,idx:c,used:!1}),typeof y=="string"&&i.set(c,i.get(y)),c++}else if(d==="func"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:o,v=m.some(w=>Array.isArray(w)&&w[0]==="export");e.set(y,{node:m,idx:o,used:v}),typeof y=="string"&&e.set(o,e.get(y)),o++}else if(d==="global"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:f,v=m.some(w=>Array.isArray(w)&&w[0]==="export");r.set(y,{node:m,idx:f,used:v}),typeof y=="string"&&r.set(f,r.get(y)),f++}else if(d==="table"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:u,v=m.some(w=>Array.isArray(w)&&w[0]==="export");s.set(y,{node:m,idx:u,used:v}),typeof y=="string"&&s.set(u,s.get(y)),u++}else if(d==="memory"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:h,v=m.some(w=>Array.isArray(w)&&w[0]==="export");l.set(y,{node:m,idx:h,used:v}),typeof y=="string"&&l.set(h,l.get(y)),h++}else if(d==="import"){for(let y of m)if(Array.isArray(y)&&y[0]==="func"){let v=typeof y[1]=="string"&&y[1][0]==="$"?y[1]:p;e.set(v,{node:m,idx:p,used:!0,isImport:!0}),typeof v=="string"&&e.set(p,e.get(v)),p++,o++}}else d==="export"?n.push(m):d==="start"&&a.push(m)}for(let m of n)for(let d of m){if(!Array.isArray(d))continue;let[y,v]=d;y==="func"&&e.has(v)?e.get(v).used=!0:y==="global"&&r.has(v)?r.get(v).used=!0:y==="table"&&s.has(v)?s.get(v).used=!0:y==="memory"&&l.has(v)&&(l.get(v).used=!0)}for(let m of a){let d=m[1];typeof d=="string"&&d[0]!=="$"&&(d=+d),e.has(d)&&(e.get(d).used=!0)}let b=n.length>0||a.length>0;if(!b){for(let[,m]of e)if(m.used){b=!0;break}if(!b){for(let[,m]of r)if(m.used){b=!0;break}}if(!b){for(let[,m]of s)if(m.used){b=!0;break}}if(!b){for(let[,m]of l)if(m.used){b=!0;break}}}if(!b){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"||G(m,d=>{if(Array.isArray(d)&&d[0]==="ref.func"){let y=d[1];e.has(y)&&(e.get(y).used=!0)}typeof d=="string"&&d[0]==="$"&&e.has(d)&&(e.get(d).used=!0)});let _=!0;for(;_;){_=!1;for(let[,m]of e)!m.used||m.isImport||G(m.node,d=>{if(!Array.isArray(d)){typeof d=="string"&&d[0]==="$"&&e.has(d)&&!e.get(d).used&&(e.get(d).used=!0,_=!0);return}let[y,v]=d;if((y==="call"||y==="return_call"||y==="ref.func")&&e.has(v)&&!e.get(v).used&&(e.get(v).used=!0,_=!0),(y==="global.get"||y==="global.set")&&r.has(v)&&!r.get(v).used&&(r.get(v).used=!0,_=!0),y==="call_indirect"||y==="return_call_indirect")for(let w of d)typeof w=="string"&&w[0]==="$"&&s.has(w)&&!s.get(w).used&&(s.get(w).used=!0,_=!0);y==="type"&&i.has(v)&&!i.get(v).used&&(i.get(v).used=!0,_=!0)})}let x=["module"];for(let m of t.slice(1)){if(!Array.isArray(m)){x.push(m);continue}let d=m[0];if(d==="func"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;(y?e.get(y):[...e.values()].find(w=>w.node===m))?.used&&x.push(m)}else if(d==="global"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;(y?r.get(y):[...r.values()].find(w=>w.node===m))?.used&&x.push(m)}else x.push(m)}return x},ze={"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)},$=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},Vt=(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,Te=t=>K(O(t),e=>{if(!Array.isArray(e))return;let r=e[0],i=ze[r];if(i){if(i.length===1&&e.length===2){let s=$(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 Vt(n,l)}if(i.length===2&&e.length===3){let s=$(e[1]),l=$(e[2]);if(!s||!l)return;let n=i(s.value,l.value);if(n===null)return;let o=/\.(eq|ne|[lg][te])/.test(r)?"i32":r.startsWith("i64.")?"i64":r.startsWith("f32.")?"f32":r.startsWith("f64.")?"f64":"i32";return Vt(o,n)}}}),Ee={"i32.add":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.add":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.sub":(t,e)=>$(e)?.value===0?t:null,"i64.sub":(t,e)=>$(e)?.value===0n?t:null,"i32.mul":(t,e)=>{let r=$(t),i=$(e);return r?.value===1?e:i?.value===1?t:null},"i64.mul":(t,e)=>{let r=$(t),i=$(e);return r?.value===1n?e:i?.value===1n?t:null},"i32.div_s":(t,e)=>$(e)?.value===1?t:null,"i32.div_u":(t,e)=>$(e)?.value===1?t:null,"i64.div_s":(t,e)=>$(e)?.value===1n?t:null,"i64.div_u":(t,e)=>$(e)?.value===1n?t:null,"i32.and":(t,e)=>{let r=$(t),i=$(e);return r?.value===-1?e:i?.value===-1?t:null},"i64.and":(t,e)=>{let r=$(t),i=$(e);return r?.value===-1n?e:i?.value===-1n?t:null},"i32.or":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.or":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.xor":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.xor":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.shl":(t,e)=>$(e)?.value===0?t:null,"i32.shr_s":(t,e)=>$(e)?.value===0?t:null,"i32.shr_u":(t,e)=>$(e)?.value===0?t:null,"i64.shl":(t,e)=>$(e)?.value===0n?t:null,"i64.shr_s":(t,e)=>$(e)?.value===0n?t:null,"i64.shr_u":(t,e)=>$(e)?.value===0n?t:null},Ue=t=>K(O(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let r=Ee[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),qe=t=>K(O(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let l=$(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=$(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=$(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=$(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=$(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=$(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=$(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=$(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n)return["i64.and",i,["i64.const",l.value-1n]]}}),Se=t=>K(O(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let i=1;for(;i<e.length;){let o=e[i];if(Array.isArray(o)&&(o[0]==="then"||o[0]==="else"||o[0]==="result"||o[0]==="param")){i++;continue}break}let s=e[i],l=$(s);if(!l)return;let n=null,a=null;for(let o=i+1;o<e.length;o++){let f=e[o];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 o=n.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}else{if(a&&a.length>1){let o=a.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=$(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=$(i);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),Ht=new Set(["unreachable","return","br","br_table"]),Oe=t=>{let e=O(t);return G(e,r=>{if(!Array.isArray(r))return;let i=r[0];if((i==="func"||i==="block"||i==="loop")&&Yt(r),i==="if")for(let s=1;s<r.length;s++)Array.isArray(r[s])&&(r[s][0]==="then"||r[s][0]==="else")&&Yt(r[s])}),e},Yt=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),Ht.has(l)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),Ht.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},Fe=t=>{let e=O(t);return G(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({node:a,idx:n}),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])))}G(r,n=>{if(!Array.isArray(n))return;let a=n[0];if(a==="local.get"||a==="local.set"||a==="local.tee"){let o=n[1];typeof o=="string"&&l.add(o)}});for(let n=i.length-1;n>=0;n--){let{idx:a,node:o}=i[n],f=typeof o[1]=="string"&&o[1][0]==="$"?o[1]:null;f&&!l.has(f)&&r.splice(a,1)}}),e},We=t=>{let e=O(t);return G(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 o=l[a];if(!Array.isArray(o))continue;let f=o[0];if(f==="local.set"&&o.length===3){let c=o[1],u=o[2];$(u)&&typeof c=="string"?i.set(c,u):typeof c=="string"&&i.delete(c)}else if(f==="local.tee"&&o.length===3){let c=o[1],u=o[2];$(u)&&typeof c=="string"?i.set(c,u):typeof c=="string"&&i.delete(c)}else if(f==="local.get"&&o.length===2){let c=o[1];if(typeof c=="string"&&i.has(c)){let u=i.get(c);o.length=0,o.push(...O(u))}}else(f==="block"||f==="loop"||f==="if"||f==="call"||f==="call_indirect")&&i.clear();K(o,c=>{if(!Array.isArray(c)||c[0]!=="local.get"||c.length!==2)return;let u=c[1];if(typeof u=="string"&&i.has(u)){let h=i.get(u);return O(h)}})}})(r)}),e},Ce=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=O(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,o=!1;for(let f=1;f<i.length;f++){let c=i[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"?a=!0:c[0]==="export"?o=!0:c[0]!=="result"&&c[0]!=="type"&&n.push(c)}if(l&&!a&&!o&&l.length<=2&&n.length===1){let f=new Set(l.map(u=>u.name)),c=!1;G(n[0],u=>{Array.isArray(u)&&(u[0]==="local.set"||u[0]==="local.tee")&&f.has(u[1])&&(c=!0)}),c||r.set(s,{body:n[0],params:l})}}return r.size===0||K(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 O(l);let o=O(l);return K(o,f=>{if(!Array.isArray(f)||f[0]!=="local.get")return;let c=f[1],u=n.findIndex(h=>h.name===c);if(u!==-1&&a[u])return O(a[u])}),o}),e};function ht(t,e=!0){return typeof t=="string"&&(t=D(t)),t=O(t),e=Be(e),e.fold&&(t=Te(t)),e.identity&&(t=Ue(t)),e.strength&&(t=qe(t)),e.branch&&(t=Se(t)),e.propagate&&(t=We(t)),e.inline&&(t=Ce(t)),e.deadcode&&(t=Oe(t)),e.locals&&(t=Fe(t)),e.treeshake&&(t=Me(t)),t}var Gt="\uE000",Kt=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},De=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t;return Kt(r)?Kt(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 Bt(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=Bt(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function Le(t,e){let r=[],i=new Map;return Bt(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 c=2;c<s.length;c++){let u=De(s[c]);u&&a.push(u)}let o=r.length,f=l.name||`$fn${o}`;i.set(l,{idx:o,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 Pe(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function je(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+=Gt+t[f+1];let s=D(i),l=[],n=0;s=Bt(s,f=>{if(f===Gt){let c=e[n++];if(typeof c=="function")return l.push(c),c;if(typeof c=="string"&&(c[0]==="("||/^\s*\(/.test(c))){let u=D(c);return Array.isArray(u)&&Array.isArray(u[0])&&(u._splice=!0),u}return c instanceof Uint8Array?[...c]:c}return f});let a=null;if(l.length){let f=Le(s,l);if(f.length){let c=Pe(f);s[0]==="module"?s.splice(1,0,...c):typeof s[0]=="string"?s=[...c,s]:s.unshift(...c),a={env:{}};for(let u of f)a.env[u.name.slice(1)]=u.fn}}r.polyfill&&(s=xt(s,r.polyfill)),r.optimize&&(s=ht(s,r.optimize));let o=et(s);return a&&(o._imports=a),o}if(r.polyfill||r.optimize){let i=typeof t=="string"?D(t):t;return r.polyfill&&(i=xt(i,r.polyfill)),r.optimize&&(i=ht(i,r.optimize)),et(i)}return et(t)}function Re(t,...e){let r=je(t,...e),i=new WebAssembly.Module(r);return new WebAssembly.Instance(i,r._imports).exports}var pr=Re;export{je as compile,pr as default,ht as optimize,D as parse,xt as polyfill,Dt as print,Re as watr};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watr",
3
- "version": "4.3.0",
3
+ "version": "4.3.3",
4
4
  "description": "Light & fast WAT compiler – WebAssembly Text to binary, parse, print, transform",
5
5
  "main": "watr.js",
6
6
  "bin": {
@@ -46,7 +46,7 @@
46
46
  "test": "node test",
47
47
  "test:repl": "npx playwright test",
48
48
  "types": "npx tsc src/*.js watr.js --allowJs --declaration --emitDeclarationOnly --declarationMap --outDir types",
49
- "prepublishOnly": "npm run build && npm run types",
49
+ "prepublishOnly": "npm test && npm run build && npm run types",
50
50
  "prepare": "git submodule update --init --recursive 2>/dev/null || true"
51
51
  },
52
52
  "repository": {
package/readme.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src="./watr.svg" height="16"> watr [![npm bundle size](https://img.shields.io/bundlephobia/minzip/watr/latest?color=white&label=gzip)](https://bundlephobia.com/package/watr) [![npm](https://img.shields.io/npm/v/watr?color=white)](https://npmjs.org/watr) [![test](https://github.com/dy/watr/actions/workflows/test.js.yml/badge.svg)](https://github.com/dy/watr/actions/workflows/test.js.yml)
1
+ # <img src="./watr.svg" height="16"> watr [![npm](https://img.shields.io/npm/v/watr?color=white)](https://npmjs.org/watr) [![test](https://github.com/dy/watr/actions/workflows/test.js.yml/badge.svg)](https://github.com/dy/watr/actions/workflows/test.js.yml)
2
2
 
3
3
 
4
4
  _Light & fast WAT compiler_
package/src/compile.js CHANGED
@@ -226,6 +226,14 @@ export default function compile(nodes) {
226
226
  }
227
227
 
228
228
 
229
+ // pre-compute sections that may collect string constants (for strings section ordering)
230
+ const globalSection = bin(SECTION.global)
231
+ const elemSection = bin(SECTION.elem)
232
+ const codeSection = bin(SECTION.code)
233
+ const metaSection = binMeta()
234
+ const dataSection = bin(SECTION.data)
235
+ const stringsSection = ctx.strings.length ? [SECTION.strings, ...vec([0x00, ...vec(ctx.strings.map(s => vec(s)))])] : []
236
+
229
237
  // build final binary
230
238
  return Uint8Array.from([
231
239
  0x00, 0x61, 0x73, 0x6d, // magic
@@ -237,14 +245,15 @@ export default function compile(nodes) {
237
245
  ...bin(SECTION.table),
238
246
  ...bin(SECTION.memory),
239
247
  ...bin(SECTION.tag),
240
- ...bin(SECTION.global),
248
+ ...stringsSection,
249
+ ...globalSection,
241
250
  ...bin(SECTION.export),
242
251
  ...bin(SECTION.start, false),
243
- ...bin(SECTION.elem),
252
+ ...elemSection,
244
253
  ...bin(SECTION.datacount, false),
245
- ...bin(SECTION.code),
246
- ...binMeta(),
247
- ...bin(SECTION.data)
254
+ ...codeSection,
255
+ ...metaSection,
256
+ ...dataSection
248
257
  ])
249
258
  }
250
259
 
@@ -342,7 +351,7 @@ function normalize(nodes, ctx) {
342
351
  else {
343
352
  const imm = []
344
353
  // Collect immediate operands (non-arrays or special forms like type/param/result/ref)
345
- while (parts.length && (!Array.isArray(parts[0]) || 'type,param,result,ref,exact,on'.includes(parts[0][0]))) imm.push(parts.shift())
354
+ while (parts.length && (!Array.isArray(parts[0]) || parts[0].valueOf !== Array.prototype.valueOf || 'type,param,result,ref,exact,on'.includes(parts[0][0]))) imm.push(parts.shift())
346
355
  out.push(...normalize(parts, ctx), op, ...imm)
347
356
  nodes.unshift(...out.splice(out.length - 1 - imm.length))
348
357
  }
@@ -857,6 +866,7 @@ const IMM = {
857
866
  elemidx: (n, c) => uleb(id(n.shift(), c.elem)),
858
867
  tagidx: (n, c) => uleb(id(n.shift(), c.tag)),
859
868
  'memoryidx?': (n, c) => uleb(id(isIdx(n[0]) ? n.shift() : 0, c.memory)),
869
+ stringidx: (n, c) => { let s = n.shift(), key = s.valueOf(), idx = c.strings.findIndex(x => x.valueOf() === key); if (idx < 0) idx = c.strings.push(s) - 1; return uleb(idx) },
860
870
 
861
871
  // Value type
862
872
  i32: (n) => encode.i32(n.shift()),
package/src/const.js CHANGED
@@ -62,7 +62,23 @@ export const INSTR = [
62
62
  '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',
63
63
  'any.convert_extern', 'extern.convert_any', 'ref.i31', 'i31.get_s', 'i31.get_u',
64
64
  // custom descriptors (Phase 3): 0xFB 0x20-0x26
65
- , 'struct.new_desc typeidx', 'struct.new_default_desc typeidx', 'ref.get_desc typeidx', 'ref.cast_desc_eq reftype', , 'br_on_cast_desc_eq reftype2', 'br_on_cast_desc_eq_fail reftype2'
65
+ , 'struct.new_desc typeidx', 'struct.new_default_desc typeidx', 'ref.get_desc typeidx', 'ref.cast_desc_eq reftype', , 'br_on_cast_desc_eq reftype2', 'br_on_cast_desc_eq_fail reftype2',
66
+ // 0xFB 0x28-0x7F: padding (88 empty slots)
67
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
68
+ // stringref: 0xFB 0x80-0xB7
69
+ 'string.new_utf8 memoryidx?', 'string.new_wtf16 memoryidx?', 'string.const stringidx', 'string.measure_utf8', 'string.measure_wtf8', 'string.measure_wtf16',
70
+ 'string.encode_utf8 memoryidx?', 'string.encode_wtf16 memoryidx?', 'string.concat', 'string.eq', 'string.is_usv_sequence',
71
+ 'string.new_lossy_utf8 memoryidx?', 'string.new_wtf8 memoryidx?', 'string.encode_lossy_utf8 memoryidx?', 'string.encode_wtf8 memoryidx?',
72
+ , // 0x8F
73
+ 'string.as_wtf8', 'stringview_wtf8.advance', 'stringview_wtf8.encode_utf8 memoryidx?', 'stringview_wtf8.slice',
74
+ 'stringview_wtf8.encode_lossy_utf8 memoryidx?', 'stringview_wtf8.encode_wtf8 memoryidx?',
75
+ ,, // 0x96-0x97
76
+ 'string.as_wtf16', 'stringview_wtf16.length', 'stringview_wtf16.get_codeunit', 'stringview_wtf16.encode memoryidx?', 'stringview_wtf16.slice',
77
+ ,,, // 0x9D-0x9F
78
+ 'string.as_iter', 'stringview_iter.next', 'stringview_iter.advance', 'stringview_iter.rewind', 'stringview_iter.slice',
79
+ ,,,,,,,,,,, // 0xA5-0xAF
80
+ 'string.new_utf8_array', 'string.new_wtf16_array', 'string.encode_utf8_array', 'string.encode_wtf16_array',
81
+ 'string.new_lossy_utf8_array', 'string.new_wtf8_array', 'string.encode_lossy_utf8_array', 'string.encode_wtf8_array'
66
82
  ],
67
83
 
68
84
  // 0xfc: Bulk memory/table operations (nested array)
@@ -144,7 +160,7 @@ export const INSTR = [
144
160
  ]
145
161
 
146
162
  // Binary section type codes
147
- export const SECTION = { 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 }
163
+ export const SECTION = { custom: 0, type: 1, import: 2, func: 3, table: 4, memory: 5, tag: 13, strings: 14, global: 6, export: 7, start: 8, elem: 9, datacount: 12, code: 10, data: 11 }
148
164
 
149
165
  // Type codes
150
166
  export const TYPE = {
@@ -153,10 +169,12 @@ export const TYPE = {
153
169
  // Heap types
154
170
  exn: 0x69, noexn: 0x74, nofunc: 0x73, noextern: 0x72, none: 0x71, func: 0x70, extern: 0x6F, any: 0x6E, eq: 0x6D, i31: 0x6C, struct: 0x6B, array: 0x6A,
155
171
  cont: 0x68, nocont: 0x75, // stack switching (Phase 3)
172
+ string: 0x67, stringview_wtf8: 0x66, stringview_wtf16: 0x60, stringview_iter: 0x61, // stringref
156
173
  // Reference type abbreviations (absheaptype abbrs)
157
174
  nullfuncref: 0x73, nullexternref: 0x72, nullexnref: 0x74, nullref: 0x71,
158
175
  funcref: 0x70, externref: 0x6F, exnref: 0x69, anyref: 0x6E, eqref: 0x6D, i31ref: 0x6C, structref: 0x6B, arrayref: 0x6A,
159
176
  contref: 0x68, nocontref: 0x75, // stack switching abbreviations
177
+ stringref: 0x67, // stringref abbreviation
160
178
  // ref, refnull
161
179
  ref: 0x64, // -0x1c
162
180
  refnull: 0x63, // -0x1d
package/src/encode.js CHANGED
@@ -106,8 +106,9 @@ i32.parse = n => {
106
106
  */
107
107
  export function i64(n, buffer = []) {
108
108
  if (typeof n === 'string') n = i64.parse(n)
109
+ else if (typeof n === 'number') n = BigInt(n)
109
110
  // Normalize unsigned to signed: values > MAX_INT64 become negative
110
- else if (typeof n === 'bigint' && n > 0x7fffffffffffffffn) {
111
+ if (typeof n === 'bigint' && n > 0x7fffffffffffffffn) {
111
112
  n = n - 0x10000000000000000n
112
113
  }
113
114
 
@@ -122,35 +123,31 @@ export function i64(n, buffer = []) {
122
123
  }
123
124
  return buffer
124
125
  }
126
+ const _buf = new ArrayBuffer(8)
127
+ const _u8 = new Uint8Array(_buf), _i32 = new Int32Array(_buf), _f32 = new Float32Array(_buf), _f64 = new Float64Array(_buf), _i64 = new BigInt64Array(_buf)
128
+
125
129
  i64.parse = n => {
126
130
  n = cleanInt(n)
127
131
  n = n[0] === '-' ? -BigInt(n.slice(1)) : BigInt(n) // can be -0x123
128
132
  if (n < -0x8000000000000000n || n > 0xffffffffffffffffn) err(`i64 constant out of range`)
129
- byteView.setBigInt64(0, n)
130
- return byteView.getBigInt64(0)
133
+ _i64[0] = n
134
+ return _i64[0]
131
135
  }
132
136
 
133
- const byteView = new DataView(new Float64Array(1).buffer)
134
-
135
137
  const F32_SIGN = 0x80000000, F32_NAN = 0x7f800000
136
138
  export function f32(input, value, idx) {
137
139
  if (typeof input === 'string' && ~(idx = input.indexOf('nan:'))) {
138
140
  value = i32.parse(input.slice(idx + 4))
139
141
  value |= F32_NAN
140
142
  if (input[0] === '-') value |= F32_SIGN
141
- byteView.setInt32(0, value)
143
+ _i32[0] = value
142
144
  }
143
145
  else {
144
146
  value = typeof input === 'string' ? f32.parse(input) : input
145
- byteView.setFloat32(0, value);
147
+ _f32[0] = value
146
148
  }
147
149
 
148
- return [
149
- byteView.getUint8(3),
150
- byteView.getUint8(2),
151
- byteView.getUint8(1),
152
- byteView.getUint8(0)
153
- ];
150
+ return [_u8[0], _u8[1], _u8[2], _u8[3]]
154
151
  }
155
152
 
156
153
  const F64_SIGN = 0x8000000000000000n, F64_NAN = 0x7ff0000000000000n
@@ -159,23 +156,14 @@ export function f64(input, value, idx) {
159
156
  value = i64.parse(input.slice(idx + 4))
160
157
  value |= F64_NAN
161
158
  if (input[0] === '-') value |= F64_SIGN
162
- byteView.setBigInt64(0, value)
159
+ _i64[0] = value
163
160
  }
164
161
  else {
165
162
  value = typeof input === 'string' ? f64.parse(input) : input
166
- byteView.setFloat64(0, value);
163
+ _f64[0] = value
167
164
  }
168
165
 
169
- return ([
170
- byteView.getUint8(7),
171
- byteView.getUint8(6),
172
- byteView.getUint8(5),
173
- byteView.getUint8(4),
174
- byteView.getUint8(3),
175
- byteView.getUint8(2),
176
- byteView.getUint8(1),
177
- byteView.getUint8(0)
178
- ]);
166
+ return [_u8[0], _u8[1], _u8[2], _u8[3], _u8[4], _u8[5], _u8[6], _u8[7]]
179
167
  }
180
168
 
181
169
  f64.parse = (input, max=Number.MAX_VALUE) => {
@@ -219,3 +207,10 @@ f64.parse = (input, max=Number.MAX_VALUE) => {
219
207
  }
220
208
 
221
209
  f32.parse = input => f64.parse(input, 3.4028234663852886e+38)
210
+
211
+ export const v128 = (input) => {
212
+ let n = typeof input === 'string' ? BigInt(input.replaceAll('_', '')) : BigInt(input)
213
+ let arr = new Uint8Array(16)
214
+ for (let i = 0; i < 16; i++) arr[i] = Number(n & 0xffn), n >>= 8n
215
+ return [...arr]
216
+ }
package/src/optimize.js CHANGED
@@ -804,7 +804,7 @@ const localReuse = (ast) => {
804
804
  if (!Array.isArray(sub)) continue
805
805
 
806
806
  if (sub[0] === 'local') {
807
- localDecls.push({ idx: i, node: sub })
807
+ localDecls.push({ node: sub, idx: i })
808
808
  // (local $name type) or (local type)
809
809
  if (typeof sub[1] === 'string' && sub[1][0] === '$') {
810
810
  localTypes.set(sub[1], sub[2])
package/src/parse.js CHANGED
@@ -25,14 +25,18 @@ export default (str) => {
25
25
  c === 59 && str.charCodeAt(i + 1) === 41 ? (buf += str[i++] + str[i++], --q === 59 && (commit(), q = 0)) : // ;)
26
26
  buf += str[i++]
27
27
  )
28
- // inside ;; ...\n
29
- else if (q < 0) (c === 10 || c === 13 ? (buf += str[i++], commit(), q = 0) : buf += str[i++])
28
+ // inside ;; ..\n: q=-1 normal (has newline), q=-2 inline (no newline — ) ends comment)
29
+ else if (q < 0) (
30
+ c === 10 || c === 13 ? (buf += str[i++], commit(), q = 0) :
31
+ q === -2 && c === 41 ? (commit(), q = 0) :
32
+ buf += str[i++]
33
+ )
30
34
  // start "
31
35
  else if (c === 34) (buf !== '$' && commit(), q = 34, buf += str[i++])
32
36
  // start (;
33
37
  else if (c === 40 && str.charCodeAt(i + 1) === 59) (commit(), q = 60, buf = str[i++] + str[i++])
34
38
  // start ;;
35
- else if (c === 59 && str.charCodeAt(i + 1) === 59) (commit(), q = -1, buf = str[i++] + str[i++])
39
+ else if (c === 59 && str.charCodeAt(i + 1) === 59) (commit(), q = str.indexOf('\n', i) < 0 ? -2 : -1, buf = str[i++] + str[i++])
36
40
  // start (@
37
41
  else if (c === 40 && str.charCodeAt(i + 1) === 64) (commit(), p = i, i += 2, buf = '@', depth++, (root = level).push(level = []), parseLevel(p), level = root)
38
42
  // start (
@@ -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,CAqNtB"}
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.js"],"names":[],"mappings":"AA+BA;;;;;GAKG;AACH,uCAHW,MAAM,QAAM,GACV,UAAU,CA8NtB"}
@@ -8,6 +8,7 @@ export namespace SECTION {
8
8
  export let table: number;
9
9
  export let memory: number;
10
10
  export let tag: number;
11
+ export let strings: number;
11
12
  export let global: number;
12
13
  let _export: number;
13
14
  export { _export as export };
@@ -42,6 +43,10 @@ export namespace TYPE {
42
43
  export let array: number;
43
44
  export let cont: number;
44
45
  export let nocont: number;
46
+ export let string: number;
47
+ export let stringview_wtf8: number;
48
+ export let stringview_wtf16: number;
49
+ export let stringview_iter: number;
45
50
  export let nullfuncref: number;
46
51
  export let nullexternref: number;
47
52
  export let nullexnref: number;
@@ -56,6 +61,7 @@ export namespace TYPE {
56
61
  export let arrayref: number;
57
62
  export let contref: number;
58
63
  export let nocontref: number;
64
+ export let stringref: number;
59
65
  export let ref: number;
60
66
  export let refnull: number;
61
67
  export let sub: number;
@@ -1 +1 @@
1
- {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/const.js"],"names":[],"mappings":"AAIA,0CA2IC"}
1
+ {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/const.js"],"names":[],"mappings":"AAIA,0CA2JC"}
@@ -55,4 +55,5 @@ export namespace i8 { }
55
55
  */
56
56
  export function i16(n: number | string, buffer?: number[]): number[];
57
57
  export namespace i16 { }
58
+ export function v128(input: any): any[];
58
59
  //# sourceMappingURL=encode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/encode.js"],"names":[],"mappings":"AA6CA;;;;;;GAMG;AACH,6BAHW,MAAM,GACJ,MAAM,EAAE,CAapB;AAED;;;;;;GAMG;AACH,uBAJW,MAAM,GAAC,MAAM,WACb,MAAM,EAAE,GACN,MAAM,EAAE,CAepB;;IAQD,4BAIC;;AAED;;;;;;GAMG;AACH,uBAJW,MAAM,GAAC,MAAM,WACb,MAAM,EAAE,GACN,MAAM,EAAE,CAmBpB;;IACD,4BAMC;;AAKD,gEAkBC;;IAmED,mCAA6D;;AAhE7D,gEAsBC;;IAED,iDAsCC;;AA3MM,wBAJI,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,IAAI,WACzB,MAAM,EAAE,GACN,MAAM,EAAE,CA8BpB;AAsBD;;;;;;GAMG;AACH,sBAJW,MAAM,GAAC,MAAM,WACb,MAAM,EAAE,GACN,MAAM,EAAE,CAepB;;AApBD;;;;;;GAMG;AACH,uBAJW,MAAM,GAAC,MAAM,WACb,MAAM,EAAE,GACN,MAAM,EAAE,CAepB"}
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/encode.js"],"names":[],"mappings":"AA6CA;;;;;;GAMG;AACH,6BAHW,MAAM,GACJ,MAAM,EAAE,CAapB;AAED;;;;;;GAMG;AACH,uBAJW,MAAM,GAAC,MAAM,WACb,MAAM,EAAE,GACN,MAAM,EAAE,CAepB;;IAQD,4BAIC;;AAED;;;;;;GAMG;AACH,uBAJW,MAAM,GAAC,MAAM,WACb,MAAM,EAAE,GACN,MAAM,EAAE,CAoBpB;;IAID,4BAMC;;AAGD,gEAaC;;IA0DD,mCAA6D;;AAvD7D,gEAaC;;IAED,iDAsCC;;AA/LM,wBAJI,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,IAAI,WACzB,MAAM,EAAE,GACN,MAAM,EAAE,CA8BpB;AAsBD;;;;;;GAMG;AACH,sBAJW,MAAM,GAAC,MAAM,WACb,MAAM,EAAE,GACN,MAAM,EAAE,CAepB;;AApBD;;;;;;GAMG;AACH,uBAJW,MAAM,GAAC,MAAM,WACb,MAAM,EAAE,GACN,MAAM,EAAE,CAepB;;AA6HM,wCAKN"}
@@ -1 +1 @@
1
- {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/parse.js"],"names":[],"mappings":"AASe,+BAHJ,MAAM,SAqDhB"}
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/parse.js"],"names":[],"mappings":"AASe,+BAHJ,MAAM,SAyDhB"}