watr 4.4.4 → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/watr.js +173 -3
- package/dist/watr.min.js +6 -6
- package/package.json +1 -1
- package/readme.md +3 -3
- package/src/const.js +17 -2
- package/src/optimize.js +12 -2
- package/types/src/const.d.ts.map +1 -1
- package/types/src/optimize.d.ts.map +1 -1
package/dist/watr.js
CHANGED
|
@@ -666,7 +666,7 @@ var INSTR = [
|
|
|
666
666
|
"string.encode_lossy_utf8_array",
|
|
667
667
|
"string.encode_wtf8_array"
|
|
668
668
|
],
|
|
669
|
-
// 0xfc: Bulk memory/table operations (nested array)
|
|
669
|
+
// 0xfc: Bulk memory/table operations + rounding mode control (nested array)
|
|
670
670
|
[
|
|
671
671
|
"i32.trunc_sat_f32_s",
|
|
672
672
|
"i32.trunc_sat_f32_u",
|
|
@@ -690,7 +690,173 @@ var INSTR = [
|
|
|
690
690
|
"i64.add128",
|
|
691
691
|
"i64.sub128",
|
|
692
692
|
"i64.mul_wide_s",
|
|
693
|
-
"i64.mul_wide_u"
|
|
693
|
+
"i64.mul_wide_u",
|
|
694
|
+
,
|
|
695
|
+
,
|
|
696
|
+
,
|
|
697
|
+
,
|
|
698
|
+
,
|
|
699
|
+
,
|
|
700
|
+
,
|
|
701
|
+
,
|
|
702
|
+
,
|
|
703
|
+
,
|
|
704
|
+
,
|
|
705
|
+
,
|
|
706
|
+
,
|
|
707
|
+
,
|
|
708
|
+
,
|
|
709
|
+
,
|
|
710
|
+
,
|
|
711
|
+
,
|
|
712
|
+
,
|
|
713
|
+
,
|
|
714
|
+
,
|
|
715
|
+
,
|
|
716
|
+
,
|
|
717
|
+
,
|
|
718
|
+
,
|
|
719
|
+
,
|
|
720
|
+
,
|
|
721
|
+
,
|
|
722
|
+
,
|
|
723
|
+
,
|
|
724
|
+
,
|
|
725
|
+
,
|
|
726
|
+
,
|
|
727
|
+
,
|
|
728
|
+
,
|
|
729
|
+
,
|
|
730
|
+
,
|
|
731
|
+
,
|
|
732
|
+
,
|
|
733
|
+
,
|
|
734
|
+
,
|
|
735
|
+
,
|
|
736
|
+
,
|
|
737
|
+
,
|
|
738
|
+
,
|
|
739
|
+
,
|
|
740
|
+
,
|
|
741
|
+
,
|
|
742
|
+
,
|
|
743
|
+
,
|
|
744
|
+
,
|
|
745
|
+
,
|
|
746
|
+
,
|
|
747
|
+
,
|
|
748
|
+
,
|
|
749
|
+
,
|
|
750
|
+
,
|
|
751
|
+
,
|
|
752
|
+
,
|
|
753
|
+
,
|
|
754
|
+
,
|
|
755
|
+
,
|
|
756
|
+
,
|
|
757
|
+
,
|
|
758
|
+
,
|
|
759
|
+
,
|
|
760
|
+
,
|
|
761
|
+
,
|
|
762
|
+
,
|
|
763
|
+
,
|
|
764
|
+
,
|
|
765
|
+
,
|
|
766
|
+
,
|
|
767
|
+
,
|
|
768
|
+
,
|
|
769
|
+
,
|
|
770
|
+
,
|
|
771
|
+
,
|
|
772
|
+
,
|
|
773
|
+
,
|
|
774
|
+
,
|
|
775
|
+
,
|
|
776
|
+
,
|
|
777
|
+
,
|
|
778
|
+
,
|
|
779
|
+
,
|
|
780
|
+
,
|
|
781
|
+
,
|
|
782
|
+
,
|
|
783
|
+
,
|
|
784
|
+
,
|
|
785
|
+
,
|
|
786
|
+
,
|
|
787
|
+
,
|
|
788
|
+
,
|
|
789
|
+
,
|
|
790
|
+
,
|
|
791
|
+
,
|
|
792
|
+
,
|
|
793
|
+
,
|
|
794
|
+
,
|
|
795
|
+
,
|
|
796
|
+
,
|
|
797
|
+
,
|
|
798
|
+
,
|
|
799
|
+
// 0x80-0xBB: rounding mode control
|
|
800
|
+
"f32.sqrt_ceil",
|
|
801
|
+
"f32.add_ceil",
|
|
802
|
+
"f32.sub_ceil",
|
|
803
|
+
"f32.mul_ceil",
|
|
804
|
+
"f32.div_ceil",
|
|
805
|
+
"f64.sqrt_ceil",
|
|
806
|
+
"f64.add_ceil",
|
|
807
|
+
"f64.sub_ceil",
|
|
808
|
+
"f64.mul_ceil",
|
|
809
|
+
"f64.div_ceil",
|
|
810
|
+
"f32.convert_ceil_i32_s",
|
|
811
|
+
"f32.convert_ceil_i32_u",
|
|
812
|
+
"f32.convert_ceil_i64_s",
|
|
813
|
+
"f32.convert_ceil_i64_u",
|
|
814
|
+
"f32.demote_ceil_f64",
|
|
815
|
+
"f64.convert_ceil_i32_s",
|
|
816
|
+
"f64.convert_ceil_i32_u",
|
|
817
|
+
"f64.convert_ceil_i64_s",
|
|
818
|
+
"f64.convert_ceil_i64_u",
|
|
819
|
+
"f64.promote_ceil_f32",
|
|
820
|
+
"f32.sqrt_floor",
|
|
821
|
+
"f32.add_floor",
|
|
822
|
+
"f32.sub_floor",
|
|
823
|
+
"f32.mul_floor",
|
|
824
|
+
"f32.div_floor",
|
|
825
|
+
"f64.sqrt_floor",
|
|
826
|
+
"f64.add_floor",
|
|
827
|
+
"f64.sub_floor",
|
|
828
|
+
"f64.mul_floor",
|
|
829
|
+
"f64.div_floor",
|
|
830
|
+
"f32.convert_floor_i32_s",
|
|
831
|
+
"f32.convert_floor_i32_u",
|
|
832
|
+
"f32.convert_floor_i64_s",
|
|
833
|
+
"f32.convert_floor_i64_u",
|
|
834
|
+
"f32.demote_floor_f64",
|
|
835
|
+
"f64.convert_floor_i32_s",
|
|
836
|
+
"f64.convert_floor_i32_u",
|
|
837
|
+
"f64.convert_floor_i64_s",
|
|
838
|
+
"f64.convert_floor_i64_u",
|
|
839
|
+
"f64.promote_floor_f32",
|
|
840
|
+
"f32.sqrt_trunc",
|
|
841
|
+
"f32.add_trunc",
|
|
842
|
+
"f32.sub_trunc",
|
|
843
|
+
"f32.mul_trunc",
|
|
844
|
+
"f32.div_trunc",
|
|
845
|
+
"f64.sqrt_trunc",
|
|
846
|
+
"f64.add_trunc",
|
|
847
|
+
"f64.sub_trunc",
|
|
848
|
+
"f64.mul_trunc",
|
|
849
|
+
"f64.div_trunc",
|
|
850
|
+
"f32.convert_trunc_i32_s",
|
|
851
|
+
"f32.convert_trunc_i32_u",
|
|
852
|
+
"f32.convert_trunc_i64_s",
|
|
853
|
+
"f32.convert_trunc_i64_u",
|
|
854
|
+
"f32.demote_trunc_f64",
|
|
855
|
+
"f64.convert_trunc_i32_s",
|
|
856
|
+
"f64.convert_trunc_i32_u",
|
|
857
|
+
"f64.convert_trunc_i64_s",
|
|
858
|
+
"f64.convert_trunc_i64_u",
|
|
859
|
+
"f64.promote_trunc_f32"
|
|
694
860
|
],
|
|
695
861
|
// 0xfd: SIMD instructions (nested array)
|
|
696
862
|
[
|
|
@@ -3697,13 +3863,17 @@ var inline = (ast) => {
|
|
|
3697
3863
|
if (params && !hasLocals && !hasExport && params.length <= 4 && body.length === 1) {
|
|
3698
3864
|
const paramNames = new Set(params.map((p) => p.name));
|
|
3699
3865
|
let mutatesParam = false;
|
|
3866
|
+
let hasReturn = false;
|
|
3700
3867
|
walk2(body[0], (n) => {
|
|
3701
3868
|
if (!Array.isArray(n)) return;
|
|
3702
3869
|
if ((n[0] === "local.set" || n[0] === "local.tee") && paramNames.has(n[1])) {
|
|
3703
3870
|
mutatesParam = true;
|
|
3704
3871
|
}
|
|
3872
|
+
if (n[0] === "return" || n[0] === "return_call" || n[0] === "return_call_indirect") {
|
|
3873
|
+
hasReturn = true;
|
|
3874
|
+
}
|
|
3705
3875
|
});
|
|
3706
|
-
if (!mutatesParam) {
|
|
3876
|
+
if (!mutatesParam && !hasReturn) {
|
|
3707
3877
|
inlinable.set(name2, { body: body[0], params });
|
|
3708
3878
|
}
|
|
3709
3879
|
}
|
package/dist/watr.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var Ae=Object.defineProperty;var be=(t,e)=>{for(var r in e)Ae(t,r,{get:e[r],enumerable:!0})};var
|
|
2
|
-
`?(r++,s=1):s++;t+=` at ${r}:${s}`}throw Error(t)};var Gt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Vt=/^[+-]?(?:0x[\da-f]+|\d+)$/i,we=new TextEncoder,ve=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),jt={n:10,r:13,t:9,'"':34,"'":39,"\\":92},gt=t=>{let e=[],r=1,s,i,n="",l=()=>(n&&e.push(...we.encode(n)),n="");for(;r<t.length-1;)i=t[r++],s=null,i==="\\"&&(t[r]==="u"?(r++,r++,i=String.fromCodePoint(parseInt(t.slice(r,r=t.indexOf("}",r)),16)),r++):jt[t[r]]?s=jt[t[r++]]:isNaN(s=parseInt(t[r]+t[r+1],16))?i+=t[r]:(r++,r++)),s!=null?(l(),e.push(s)):n+=i;return l(),e.valueOf=()=>t,e},Ht=t=>ve.decode(new Uint8Array(gt(t)));var p=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):R.parse(t)),typeof t=="bigint"){for(;;){let s=Number(t&0x7Fn);if(t>>=7n,t===0n){e.push(s);break}e.push(s|128)}return e}let r=t&127;return t>>>=7,t===0?(e.push(r),e):(e.push(r|128),p(t,e))};function $e(t){let e=[];for(let r=0;r<5;r++){let s=t&127;t>>>=7,r<4&&(s|=128),e.push(s)}return e}function R(t,e=[]){for(typeof t=="string"&&(t=R.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 Yt=t=>!Gt.test(t)&&Vt.test(t=t.replaceAll("_",""))?t:k(`Bad int ${t}`),Ie=R,ke=R;R.parse=t=>(t=parseInt(Yt(t)),(t<-2147483648||t>4294967295)&&k("i32 constant out of range"),t);function st(t,e=[]){for(typeof t=="string"?t=st.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 ut=new ArrayBuffer(8),G=new Uint8Array(ut),Ne=new Int32Array(ut),Me=new Float32Array(ut),Be=new Float64Array(ut),Et=new BigInt64Array(ut);st.parse=t=>(t=Yt(t),t=t[0]==="-"?-BigInt(t.slice(1)):BigInt(t),(t<-0x8000000000000000n||t>0xffffffffffffffffn)&&k("i64 constant out of range"),Et[0]=t,Et[0]);var Se=2147483648,ze=2139095040;function nt(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=R.parse(t.slice(r+4)),e|=ze,t[0]==="-"&&(e|=Se),Ne[0]=e):(e=typeof t=="string"?nt.parse(t):t,Me[0]=e),[G[0],G[1],G[2],G[3]]}var Te=0x8000000000000000n,Ee=0x7ff0000000000000n;function it(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=st.parse(t.slice(r+4)),e|=Ee,t[0]==="-"&&(e|=Te),Et[0]=e):(e=typeof t=="string"?it.parse(t):t,Be[0]=e),[G[0],G[1],G[2],G[3],G[4],G[5],G[6],G[7]]}it.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[s,i="0"]=t.split(/p/i),[n,l=""]=s.split("."),a=l.length??0,o=parseInt(n);isNaN(o)&&k();let f=l?parseInt("0x"+l)/16**a:0;i=parseInt(i,10);let c=r*(o+f)*2**i;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)};nt.parse=t=>it.parse(t,34028234663852886e22);var Ut=t=>{let e=BigInt(typeof t=="string"?t.replaceAll("_",""):t),r=new Uint8Array(16);for(let s=0;s<16;s++)r[s]=Number(e&0xffn),e>>=8n;return[...r]};var mt=["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"]],q={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},F={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},Q={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},qt={func:0,table:1,memory:2,global:3,tag:4};var V=t=>{let e=0,r=[],s="",i=0,n=0,l=()=>s&&(r.push(s),s=""),a=o=>{r.loc=o;for(let f,c,m;e<t.length;)if(f=t.charCodeAt(e),i===34)s+=t[e++],f===92?s+=t[e++]:f===34&&(l(),i=0);else if(i>59)f===40&&t.charCodeAt(e+1)===59?(i++,s+=t[e++]+t[e++]):f===59&&t.charCodeAt(e+1)===41?(s+=t[e++]+t[e++],--i===59&&(l(),i=0)):s+=t[e++];else if(i<0)f===10||f===13?(s+=t[e++],l(),i=0):i===-2&&f===41?(l(),i=0):s+=t[e++];else if(f===34)s!=="$"&&l(),i=34,s+=t[e++];else if(f===40&&t.charCodeAt(e+1)===59)l(),i=60,s=t[e++]+t[e++];else if(f===59&&t.charCodeAt(e+1)===59)l(),i=t.indexOf(`
|
|
3
|
-
`,e)<0?-2:-1,s=t[e++]+t[e++];else if(f===40&&t.charCodeAt(e+1)===64)l(),m=e,e+=2,s="@",n++,(c=r).push(r=[]),a(m),r=c;else if(f===40)l(),m=e++,n++,(c=r).push(r=[]),a(m),r=c;else{if(f===41)return l(),e++,n--;f<=32?(l(),e++):s+=t[e++]}i<0&&l(),l()};return a(0),i===34&&k("Unclosed quote",e),i>59&&k("Unclosed block comment",e),n>0&&k("Unclosed parenthesis",e),e<t.length&&k("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var Zt=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(Zt).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("\\")?"$"+Ht(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?gt(t):t;function at(t){typeof t=="string"?(k.src=t,t=V(t)||[]):k.src="",k.loc=0,t=Zt(t)||[];let e=0;if(t[0]==="module"?(e++,W(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return at(t.slice(++e).map(m=>m.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((m,g)=>{if(g<e||!Array.isArray(m)||m[0]!=="import")return[m];let[,u,...d]=m;if(!d.some(_=>Array.isArray(_)&&_[0]==="item"))return[m];if(Array.isArray(d.at(-1))&&d.at(-1)[0]!=="item"){let _=d.at(-1);return d.slice(0,-1).filter(w=>w[0]==="item").map(([,w])=>["import",u,w,_])}return d.filter(_=>_[0]==="item").map(([,_,w])=>["import",u,_,w])});let r=[];for(let m in q)(r[q[m]]=r[m]=[]).name=m;r.metadata={},t.slice(e).filter(m=>{if(!Array.isArray(m)){let d=k.loc,y=k.src,_;for(;(d=y.indexOf(m,d))>=0;){if(_=y.charCodeAt(d-1),d>0&&(_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95||_===36)){d++;continue}if(_=y.charCodeAt(d+m.length),_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95){d++;continue}break}d>=0&&(k.loc=d),k(`Unexpected token ${m}`)}let[g,...u]=m;if(k.loc=m.loc,g==="@custom")r.custom.push(u);else if(g==="rec")for(let d=0;d<u.length;d++){let[,...y]=u[d];Ot(y,r.type);let _=[];for(;y[0]?.[0]==="descriptor"||y[0]?.[0]==="describes";)_.push(y.shift());(y=Xt(y,r)).push(d?!0:[r.type.length,u.length]),_.length&&(y.desc=y.desc?[..._,...y.desc]:_),r.type.push(y)}else if(g==="type"){Ot(u,r.type);let d=[];for(;u[0]?.[0]==="descriptor"||u[0]?.[0]==="describes";)d.push(u.shift());let y=Xt(u,r);d.length&&(y.desc=y.desc?[...d,...y.desc]:d),r.type.push(y)}else if(g==="start"||g==="export")r[g].push(u);else return!0}).forEach(m=>{let[g,...u]=m;k.loc=m.loc;let d;g==="import"&&([g,...u]=(d=u).pop());let y=r[g];for(y||k(`Unknown section ${g}`),Ot(u,y);u[0]?.[0]==="export";)r.export.push([u.shift()[1],[g,y?.length]]);if(u[0]?.[0]==="import"&&([,...d]=u.shift()),g==="table"){let _=u[0]==="i64",w=_?1:0;if(u[w+1]?.[0]==="elem"){let[v,[,...b]]=[u[w],u[w+1]];u=_?["i64",b.length,b.length,v]:[b.length,b.length,v],r.elem.push([["table",y.length],["offset",[_?"i64.const":"i32.const",_?0n:0]],v,...b])}}else if(g==="memory"){let _=u[0]==="i64",w=_?1:0;if(u[w]?.[0]==="data"){let v=u.find($=>Array.isArray($)&&$[0]==="pagesize")?.[1]??65536,[,...b]=u.splice(w,1)[0],z=""+Math.ceil(b.reduce(($,I)=>$+I.length,0)/v);r.data.push([["memory",y.length],[_?"i64.const":"i32.const",_?0n:0],...b]),u=_?["i64",z,z]:[z,z]}}else if(g==="func"){let[_,w,v]=$t(u,r);_??=wt(w,v,r),!d&&r.code.push([[_,w,v],...et(u,r)]),u=[["type",_]]}else if(g==="tag"){let[_,w]=$t(u,r);_??=wt(w,[],r),u=[["type",_]]}d&&(r.import.push([...d,[g,...u]]),u=null),y.push(u)});let s=(m,g=!0)=>{let u=r[m].filter(Boolean).map(d=>Jt[m](d,r)).filter(Boolean);return m===q.custom?u.flatMap(d=>[m,...E(d)]):u.length?[m,...E(g?E(u):u.flat())]:[]},i=()=>{let m=[];for(let g in r.metadata){let u=E(gt(`"metadata.code.${g}"`)),d=E(r.metadata[g].map(([y,_])=>[...p(y),...E(_.map(([w,v])=>[...p(w),...E(v)]))]));m.push(0,...E([...u,...d]))}return m},n=s(q.global),l=s(q.elem),a=s(q.code),o=i(),f=s(q.data),c=r.strings.length?[q.strings,...E([0,...E(r.strings.map(m=>E(m)))])]:[];return Uint8Array.from([0,97,115,109,1,0,0,0,...s(q.custom),...s(q.type),...s(q.import),...s(q.func),...s(q.table),...s(q.memory),...s(q.tag),...c,...n,...s(q.export),...s(q.start,!1),...l,...s(q.datacount,!1),...a,...o,...f])}var H=t=>t?.[0]==="$"||!isNaN(t),W=t=>t?.[0]==="$",Ft=t=>t?.[0]==="a"||t?.[0]==="o";function et(t,e){let r=[];for(t=[...t];t.length;){let s=t.shift();if(typeof s=="string")if(r.push(s),s==="block"||s==="if"||s==="loop")W(t[0])&&r.push(t.shift()),r.push(ht(t,e));else if(s==="else"||s==="end")W(t[0])&&t.shift();else if(s==="select")r.push(vt(t)[1]);else if(s.endsWith("call_indirect")){let i=H(t[0])?t.shift():0,[n,l,a]=$t(t,e);r.push(i,["type",n??wt(l,a,e)])}else s==="table.init"?r.push(H(t[1])?t.shift():0,t.shift()):s==="table.copy"||s==="memory.copy"?r.push(H(t[0])?t.shift():0,H(t[0])?t.shift():0):s.startsWith("table.")?r.push(H(t[0])?t.shift():0):s==="memory.init"?(r.push(...H(t[1])?[t.shift(),t.shift()].reverse():[t.shift(),0]),e.datacount&&(e.datacount[0]=!0)):s==="data.drop"||s==="array.new_data"||s==="array.init_data"?(s==="data.drop"&&r.push(t.shift()),e.datacount&&(e.datacount[0]=!0)):(s.startsWith("memory.")||s.endsWith("load")||s.endsWith("store"))&&H(t[0])&&r.push(t.shift());else if(Array.isArray(s)){let i=s[0];if(s.loc!=null&&(k.loc=s.loc),i?.startsWith?.("@metadata.code.")){let l=i.slice(15);r.push(["@metadata",l,s[1]]);continue}if(typeof i!="string"||!Array.isArray(mt[i])){r.push(s);continue}let n=s.slice(1);if(i==="block"||i==="loop")r.push(i),W(n[0])&&r.push(n.shift()),r.push(ht(n,e),...et(n,e),"end");else if(i==="if"){let l=[],a=[];n.at(-1)?.[0]==="else"&&(a=et(n.pop().slice(1),e)),n.at(-1)?.[0]==="then"&&(l=et(n.pop().slice(1),e));let o=[i];W(n[0])&&o.push(n.shift()),o.push(ht(n,e)),r.push(...et(n,e),...o,...l),a.length&&r.push("else",...a),r.push("end")}else if(i==="try_table"){for(r.push(i),W(n[0])&&r.push(n.shift()),r.push(ht(n,e));n[0]?.[0]==="catch"||n[0]?.[0]==="catch_ref"||n[0]?.[0]==="catch_all"||n[0]?.[0]==="catch_all_ref";)r.push(n.shift());r.push(...et(n,e),"end")}else{let l=[];for(;n.length&&(!Array.isArray(n[0])||n[0].valueOf!==Array.prototype.valueOf||"type,param,result,ref,exact,on".includes(n[0][0]));)l.push(n.shift());r.push(...et(n,e),i,...l),t.unshift(...r.splice(r.length-1-l.length))}}else r.push(s)}return r}var wt=(t,e,r,s="$"+t+">"+e)=>(r.type[s]??=r.type.push(["func",[t,e]])-1,s),Ct=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...s]=t.shift(),i=W(s[0])&&s.shift();i&&(i in r?(()=>{throw Error(`Duplicate ${e} ${i}`)})():r[i]=r.length),r.push(...s)}return r},vt=t=>{let e=Ct(t,"param"),r=Ct(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},$t=(t,e)=>{if(t[0]?.[0]!=="type")return[,...vt(t)];let[,r]=t.shift(),[s,i]=vt(t),n=e.type[typeof r=="string"&&isNaN(r)?e.type[r]:+r];if(!n)throw Error(`Unknown type ${r}`);if((s.length||i.length)&&n[1].join(">")!==s+">"+i)throw Error(`Type ${r} mismatch`);return[r,...n[1]]},ht=(t,e)=>{let[r,s,i]=$t(t,e);if(!(!s.length&&!i.length))return!s.length&&i.length===1?["result",...i]:["type",r??wt(s,i,e)]},Ot=(t,e)=>{let r=W(t[0])&&t.shift();return r&&(r in e?k(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},Xt=([t],e)=>{let r="subfinal",s=[],i,n=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(s=t).pop(),s=s.filter(a=>Array.isArray(a)&&(a[0]==="descriptor"||a[0]==="describes")?(n.push(a),!1):!0)),[i,...t]=t,i==="func"?(t=vt(t),e.type["$"+t.join(">")]??=e.type.length):i==="struct"?t=Ct(t,"field"):i==="array"&&([t]=t);let l=[i,t,r,s];return n.length&&(l.desc=n),l},Jt=[([t,...e],r)=>{let s=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(s=e.slice(1)),[...E(t),...s.flat()]},(t,e)=>{let[r,s,i,n,l]=t;if(l===!0)return;let a=(t.desc??[]).flatMap(([f,c])=>[f==="descriptor"?77:76,...p(A(c,e.type))]),o=(f,c)=>f==="func"?[Q.func,...E(c[0].map(m=>j(m,e))),...E(c[1].map(m=>j(m,e)))]:f==="array"?[Q.array,...xt(c,e)]:f==="struct"?[Q.struct,...E(c.map(m=>xt(m,e)))]:f==="cont"?[Q.cont,...p(A(c[0]??c,e.type))]:[Q[f]];if(l){let[f,c]=l,m=Array.from({length:c},(g,u)=>{let d=e.type[f+u],y=d.slice(0,4);return d.desc&&(y.desc=d.desc),Jt[q.type](y,e)});return[Q.rec,...E(m)]}else if(i==="sub"||n?.length)return[Q[i],...E(n.map(f=>A(f,e.type))),...a,...o(r,s)];return[...a,...o(r,s)]},([t,e,[r,...s]],i)=>{let n,l=qt[r];if(r==="func"){s[0]==="exact"&&s.shift()&&(l=32);let[[,o]]=s;n=p(A(o,i.type))}else if(r==="tag"){let[[,a]]=s;n=[0,...p(A(a,i.type))]}else r==="memory"?n=dt(s):r==="global"?n=xt(s[0],i):r==="table"?n=[...j(s.pop(),i),...dt(s)]:k(`Unknown kind ${r}`);return[...E(t),...E(e),l,...n]},([[,t]],e)=>p(A(t,e.type)),(t,e)=>{let r=dt(t),s=j(t.shift(),e),[i]=t;return i?[64,0,...s,...r,...lt(i,e)]:[...s,...r]},(t,e)=>dt(t),([t,e],r)=>[...xt(t,r),...lt(e,r)],([t,[e,r]],s)=>[...E(t),qt[e],...p(A(r,s[e]))],([t],e)=>p(A(t,e.func)),(t,e)=>{let r=0,s=0,i=0,n=0,l,a,o;t[0]==="declare"&&(t.shift(),s=1),t[0]?.[0]==="table"?([,l]=t.shift(),l=A(l,e.table)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&t[1][0]!=="item"&&!t[1][0]?.startsWith("ref"))&&(l=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=lt(a,e)):s||(r=1),F[t[0]]||t[0]?.[0]==="ref"?o=j(t.shift(),e):t[0]==="func"?o=[F[t.shift()]]:o=[F.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"&&(i=1),c)),o[0]!==F.funcref&&(n=1,i=1);let f=i<<2|(r||s?s:!!l||n)<<1|(r||s);return[f,...f===0?a:f===1?[0]:f===2?[...p(l||0),...a,0]:f===3?[0]:f===4?a:f===5?o:f===6?[...p(l||0),...a,...o]:o,...E(t.map(i?c=>lt(typeof c=="string"?["ref.func",c]:c,e):c=>p(A(c,e.func))))]},(t,e)=>{let[r,s]=t.shift();s||([,[s]]=e.type[A(r,e.type)]),e.local=Object.create(s),e.block=[],e.local.name="local",e.block.name="block",e._codeIdx===void 0&&(e._codeIdx=0);let i=e._codeIdx++;for(;t[0]?.[0]==="local";){let[,...o]=t.shift();if(W(o[0])){let f=o.shift();f in e.local?k(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...o)}e.meta={};let n=te(t,e),l=e.import.filter(o=>o[2][0]==="func").length+i;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([l,e.meta[o]]);let a=e.local.slice(s.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,E([...E(a.map(([o,f])=>[...p(o),...j(f,e)])),...n])},(t,e)=>{let r,s=0;return t[0]?.[0]==="memory"?([,s]=t.shift(),s=A(s,e.memory)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&typeof t[1][0]=="string")&&(s=A(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??k("Bad offset",r)),[...s?[2,...p(s),...lt(r,e)]:r?[0,...lt(r,e)]:[1],...E(t.flatMap(i=>Oe(i)??[...i]))]},(t,e)=>p(e.data.length),([[,t]],e)=>[0,...p(A(t,e.type))]],j=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[F.refnull,98,...p(A(t[2][1],e.type))]:F[t[2]]?[F[t[2]]]:[F.refnull,...p(A(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[F.ref,98,...p(A(t[1][1],e.type))]:[F.ref,...p(F[t[t.length-1]]||A(t[t.length-1],e.type))]:[F[t]??k(`Unknown type ${t}`)],xt=(t,e,r=t[0]==="mut"?1:0)=>[...j(r?t[1]:t,e),r],Qt={null:()=>[],reversed:(t,e)=>{let r=t.shift(),s=t.shift();return[...p(A(s,e.elem)),...p(A(r,e.table))]},block:(t,e)=>{e.block.push(1),W(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?j(r[1],e):p(A(r[1],e.type)):[F.void]},try_table:(t,e)=>{W(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),s=r?r[0]==="result"?j(r[1],e):p(A(r[1],e.type)):[F.void],i=[],n=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let l=t.shift(),a=l[0]==="catch"?0:l[0]==="catch_ref"?1:l[0]==="catch_all"?2:3;a<=1?i.push(a,...p(A(l[1],e.tag)),...p(tt(l[2],e.block))):i.push(a,...p(tt(l[1],e.block))),n++}return e.block.push(1),[...s,...p(n),...i]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,s]=t.shift();return[...p(A(s,e.type)),...p(A(r,e.table))]},br_table:(t,e)=>{let r=[],s=0;for(;t[0]&&(!isNaN(t[0])||W(t[0]));)r.push(...p(tt(t.shift(),e.block))),s++;return[...p(s-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?E(r.map(s=>j(s,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...p(A(r[1],e.type))]:F[r]?[F[r]]:p(A(r,e.type))},memarg:(t,e,r)=>Kt(t,r,H(t[0])&&!Ft(t[0])?A(t.shift(),e.memory):0),opt_memory:(t,e)=>p(A(H(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=j(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=tt(t.shift(),e.block),s=j(t.shift(),e),i=j(t.shift(),e),n=l=>l.length>1?l.slice(1):l;return[(i[0]!==F.ref)<<1|s[0]!==F.ref,...p(r),...n(s),...n(i)]},v128const:t=>{let[e,r]=t.shift().split("x"),s=+e.slice(1),i=s>>>3;if(r=+r,e[0]==="i"){let l=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let a=0;a<r;a++)l[a]=_t[e].parse(t.shift());return[...new Uint8Array(l.buffer)]}let n=new Uint8Array(16);for(let l=0;l<r;l++)n.set(_t[e](t.shift()),l*i);return[...n]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(bt(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&k("invalid lane length"),e},memlane:(t,e,r)=>{let s=W(t[0])||H(t[0])&&(Ft(t[1])||H(t[1]))?A(t.shift(),e.memory):0;return[...Kt(t,r,s),...p(bt(t.shift()))]},"*":t=>p(t.shift()),labelidx:(t,e)=>p(tt(t.shift(),e.block)),laneidx:t=>[bt(t.shift(),255)],funcidx:(t,e)=>p(A(t.shift(),e.func)),typeidx:(t,e)=>p(A(t.shift(),e.type)),tableidx:(t,e)=>p(A(t.shift(),e.table)),memoryidx:(t,e)=>p(A(t.shift(),e.memory)),globalidx:(t,e)=>p(A(t.shift(),e.global)),localidx:(t,e)=>p(A(t.shift(),e.local)),dataidx:(t,e)=>p(A(t.shift(),e.data)),elemidx:(t,e)=>p(A(t.shift(),e.elem)),tagidx:(t,e)=>p(A(t.shift(),e.tag)),"memoryidx?":(t,e)=>p(A(H(t[0])?t.shift():0,e.memory)),stringidx:(t,e)=>{let r=t.shift(),s=r.valueOf(),i=e.strings.findIndex(n=>n.valueOf()===s);return i<0&&(i=e.strings.push(r)-1),p(i)},i32:t=>R(t.shift()),i64:t=>st(t.shift()),f32:t=>nt(t.shift()),f64:t=>it(t.shift()),v128:t=>Ut(t.shift()),typeidx_field:(t,e)=>{let r=A(t.shift(),e.type);return[...p(r),...p(A(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...p(A(t.shift(),e.type)),...p(t.shift())],typeidx_dataidx:(t,e)=>[...p(A(t.shift(),e.type)),...p(A(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...p(A(t.shift(),e.type)),...p(A(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...p(A(t.shift(),e.type)),...p(A(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...p(A(t.shift(),e.data)),...p(A(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...p(A(t.shift(),e.memory)),...p(A(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...p(A(t.shift(),e.table)),...p(A(t.shift(),e.table))],cont_bind:(t,e)=>[...p(A(t.shift(),e.type)),...p(A(t.shift(),e.type))],switch_cont:(t,e)=>[...p(A(t.shift(),e.type)),...p(A(t.shift(),e.tag))],resume:(t,e)=>{let r=p(A(t.shift(),e.type)),s=[],i=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?s.push(1,...p(A(n,e.tag))):s.push(0,...p(A(n,e.tag)),...p(tt(l,e.block))),i++}return[...r,...p(i),...s]},resume_throw:(t,e)=>{let r=p(A(t.shift(),e.type)),s=p(A(t.shift(),e.tag)),i=[],n=0;for(;t[0]?.[0]==="on";){let[,l,a]=t.shift();a==="switch"?i.push(1,...p(A(l,e.tag))):i.push(0,...p(A(l,e.tag)),...p(tt(a,e.block))),n++}return[...r,...s,...p(n),...i]},resume_throw_ref:(t,e)=>{let r=p(A(t.shift(),e.type)),s=[],i=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?s.push(1,...p(A(n,e.tag))):s.push(0,...p(A(n,e.tag)),...p(tt(l,e.block))),i++}return[...r,...p(i),...s]}},At={};(function t(e,r){for(let s=0,i,n,l;s<e.length;s++)(i=e[s])&&(Array.isArray(i)?t(i,s):([n,l]=i.split(" "),mt[n]=r?[r,...p(s)]:[s],l&&(At[n]=Qt[l])))})(mt);var te=(t,e)=>{let r=[],s=[];for(;t?.length;){let i=t.shift();if(i?.[0]==="@metadata"){s.push(i.slice(1));continue}Array.isArray(i)&&(i.loc!=null&&(k.loc=i.loc),k(`Unknown instruction ${i[0]}`));let[...n]=mt[i]||k(`Unknown instruction ${i}`);At[i]&&(i==="select"&&t[0]?.length?n[0]++:At[i]===Qt.reftype&&(t[0][1]==="null"||t[0][0]!=="ref")&&n[n.length-1]++,n.push(...At[i](t,e,i)));for(let[l,a]of s)(e.meta[l]??=[]).push([r.length,a]);r.push(...n)}return r.push(11),r},lt=(t,e)=>te(et([t],e),e),A=(t,e,r)=>(r=W(t)?e[t]:+t,r in e?r:k(`Unknown ${e.name} ${t}`)),tt=(t,e,r)=>(r=W(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?k(`Bad label ${t}`):r),Ue=t=>{let e,r,s,i;for(;Ft(t[0]);)[s,i]=t.shift().split("="),s==="offset"?r=+i:s==="align"?e=+i:k(`Unknown param ${s}=${i}`);return(r<0||r>4294967295)&&k(`Bad offset ${r}`),(e<=0||e>4294967295)&&k(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&k(`Bad align ${e}`),[e,r]},Kt=(t,e,r=0)=>{let[s,i]=Ue(t),n=(s??qe(e))|(r&&64);return r?[...p(n),...p(r),...p(i??0)]:[...p(n),...p(i??0)]},qe=t=>{let e=t.indexOf(".",3)+1,r=t.slice(1,t[0]==="v"?4:3);if(t[e]==="a"&&(e=t.indexOf(".",e)+1),t[0]==="m")return t.includes("64")?3:2;if(t[e]==="r"){let n=t.slice(e,e+6).match(/\d+/);return Math.log2(n?n[0]/8:+r/8)}let s=t[e]==="l"?e+4:e+5,i=t.slice(s).match(/(\d+)(x|_|$)/);return Math.log2(i?i[2]==="x"?8:i[1]/8:+r/8)},Oe=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 s=[],i=new DataView(new ArrayBuffer(8));for(let n of r)e==="i8"?s.push(R.parse(n)&511&255):e==="i16"?(i.setInt16(0,R.parse(n),!0),s.push(...new Uint8Array(i.buffer,0,2))):e==="i32"?(i.setInt32(0,R.parse(n),!0),s.push(...new Uint8Array(i.buffer,0,4))):e==="i64"?(i.setBigInt64(0,BigInt(n),!0),s.push(...new Uint8Array(i.buffer,0,8))):e==="f32"?s.push(...nt(n)):e==="f64"&&s.push(...it(n));return s},dt=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),s=t.findIndex(f=>Array.isArray(f)&&f[0]==="pagesize"),i=-1;s>=0&&(i=Math.log2(+t.splice(s,1)[0][1]));let n=!isNaN(parseInt(t[1])),l=(i>=0?8:0)|(e?4:0)|(r?2:0)|(n?1:0),a=e?f=>{if(typeof f=="bigint")return f;let c=typeof f=="string"?f.replaceAll("_",""):String(f);return BigInt(c)}:bt,o=i>=0?p(i):[];return n?[l,...p(a(t.shift())),...p(a(t.shift())),...o]:[l,...p(a(t.shift())),...o]},bt=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?R.parse(t):typeof t=="number"?t:k(`Bad int ${t}`);return r>e?k(`Value out of range ${t}`):r},E=t=>[...p(t.length),...t.flat()];function ee(t,e={}){typeof t=="string"&&(t=V(t));let{indent:r=" ",newline:s=`
|
|
4
|
-
`,comments:i=!0}=e;if(r||="",s||="",typeof t[0]=="string"&&t[0][0]!==";")return l(t);return t.filter(a=>i||!n(a)).map(a=>l(a)).join(s);function n(a){return typeof a=="string"&&a[1]===";"}function l(a,o=0){if(!Array.isArray(a))return a;let f=a[0];if(!f)return"";let c=!1;if(f==="try_table"){let u=1;for(typeof a[u]=="string"&&a[u][0]==="$"&&(f+=" "+a[u++]),Array.isArray(a[u])&&(a[u][0]==="result"||a[u][0]==="type")&&(f+=" "+l(a[u++],o));Array.isArray(a[u])&&/^catch/.test(a[u][0]);)f+=" "+l(a[u++],o).trim();for(;u<a.length;u++)f+=Array.isArray(a[u])?s+r.repeat(o+1)+l(a[u],o+1):" "+a[u];return`(${f+s+r.repeat(o)})`}let m=!!s&&a.length<4&&!a.some(u=>typeof u=="string"&&u[0]===";"&&u[1]===";"),
|
|
5
|
-
`}else{let y=f[f.length-1];y&&y!==" "&&y!=="("&&(f+=" "),f+=d.trimEnd()}}else if(Array.isArray(d))m&&(m=d.every(y=>!Array.isArray(y))),f+=s+
|
|
6
|
-
`?f+="":(y&&y!==")"&&y!==" "||s||y===")")&&(f+=" "),f+=d,c=!1}}return m?`(${f.replaceAll(s+g+"("," (")})`:`(${f+s+r.repeat(o)})`}}var ie={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"]},Dt=Object.keys(ie),Fe=t=>{if(t===!0)return Object.fromEntries(Dt.map(e=>[e,!0]));if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return Object.fromEntries(Dt.map(r=>[r,e.has(r)||e.has("all")]))}return{...t}},L=(t,e,r,s)=>{if(e(t,r,s),Array.isArray(t))for(let i=0;i<t.length;i++)L(t[i],e,t,i)},K=(t,e,r,s)=>{if(Array.isArray(t))for(let i=0;i<t.length;i++)K(t[i],e,t,i);e(t,r,s)},Ce=t=>{let e=new Set;return L(t,r=>{if(typeof r=="string")for(let[s,i]of Object.entries(ie))i.some(n=>r===n||r.startsWith(n+" "))&&e.add(s)}),L(t,r=>{if(!(!Array.isArray(r)||r[0]!=="global"))for(let s of r)Array.isArray(s)&&(s[0]==="i32.add"||s[0]==="i32.sub"||s[0]==="i32.mul"||s[0]==="i64.add"||s[0]==="i64.sub"||s[0]==="i64.mul")&&L(s,i=>{Array.isArray(i)&&i[0]==="global.get"&&e.add("extended_const")})}),L(t,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let s=0;for(let i of r)Array.isArray(i)&&i[0]==="result"&&(s+=i.length-1);s>1&&e.add("multi_value")}),e},se=t=>Array.isArray(t)?t.map(se):t,ne=(t,e)=>{let r=[],s=t[0]==="module"?1:0;for(let i=s;i<t.length;i++)Array.isArray(t[i])&&t[i][0]===e&&r.push({node:t[i],idx:i});return r},It=(t,e,r)=>t.splice(e,0,r),De=0,Z=t=>`$__${t}${De++}`,Le=(t,e)=>{let r=new Set;if(L(t,f=>{Array.isArray(f)&&f[0]==="ref.func"&&r.add(f[1])}),!r.size)return t;let s=Z("fntbl"),i=[...r],n=Object.fromEntries(i.map((f,c)=>[f,c])),l=ne(t,"func"),a=l.length?l[0].idx:t[0]==="module"?1:0;It(t,a,["table",s,"funcref",["elem",...i]]);let o={};return L(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c)return;let m=[],g=[];for(let u of f){if(Array.isArray(u)&&u[0]==="param")for(let d=1;d<u.length;d++)u[d][0]!=="$"&&m.push(u[d]);if(Array.isArray(u)&&u[0]==="result")for(let d=1;d<u.length;d++)g.push(u[d])}o[c]={params:m,results:g}}),K(t,(f,c,m)=>{if(!(!Array.isArray(f)||!c)){if(f[0]==="ref.func"&&n[f[1]]!==void 0&&(c[m]=["i32.const",n[f[1]]]),f[0]==="call_ref"){let g=f[1],u=f.slice(2);c[m]=["call_indirect",s,["type",g],...u]}if(f[0]==="return_call_ref"){let g=f[1],u=f.slice(2);c[m]=["return_call_indirect",s,["type",g],...u]}}}),t},X={funcref:Le},We={"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)=>(K(t,(r,s,i)=>{if(!Array.isArray(r)||!s)return;let n=We[r[0]];if(!n)return;let[l,a]=n,o=r.slice(1);s[i]=[`${l}.shr_s`,[`${l}.shl`,...o,[`${l}.const`,a]],[`${l}.const`,a]]}),t);X.sign_ext=Pe;var re={"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}},Re=(t,e)=>{let r=new Set;if(L(t,i=>{Array.isArray(i)&&re[i[0]]&&r.add(i[0])}),!r.size)return t;let s={};for(let i of r){let{itype:n,ftype:l,signed:a,min:o,max:f}=re[i],c=Z(`trunc_${n}_${l}_${a?"s":"u"}`);s[i]=c;let m=`${n}.trunc_${l}_${a?"s":"u"}`,g=n==="i64"?0n:0,u=["func",c,["param","$v",l],["result",n],["if",["result",n],[`${l}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${n}.const`,g]],["else",["if",["result",n],[`${l}.lt`,["local.get","$v"],[`${l}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${n}.const`,o]],["else",["if",["result",n],[`${l}.gt`,["local.get","$v"],[`${l}.const`,typeof f=="bigint"?Number(f):f]],["then",[`${n}.const`,f]],["else",[m,["local.get","$v"]]]]]]]]];t.push(u)}return K(t,(i,n,l)=>{!Array.isArray(i)||!n||s[i[0]]&&(n[l]=["call",s[i[0]],...i.slice(1)])}),t};X.nontrapping=Re;var je=(t,e)=>{let r=new Set,s=new Set;L(t,l=>{if(Array.isArray(l)){if(l[0]==="memory.copy"){let a=typeof l[1]=="number"?l[1]:0,o=typeof l[2]=="number"?l[2]:0;r.add(`${a}_${o}`)}if(l[0]==="memory.fill"){let a=typeof l[1]=="number"?l[1]:0;s.add(a)}}});let i={},n={};for(let l of r){let[a,o]=l.split("_").map(Number),f=Z(`memcpy${l==="0_0"?"":"_"+l}`);i[l]=f;let c=a?["i32.store8",a]:["i32.store8"],m=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",f,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...m,["i32.add",["local.get","$src"],["local.get","$i"]]]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}for(let l of s){let a=Z(`memset${l===0?"":"_"+l}`);n[l]=a;let o=l?["i32.store8",l]:["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 K(t,(l,a,o)=>{if(!(!Array.isArray(l)||!a)){if(l[0]==="memory.copy"){let f=typeof l[1]=="number"?l[1]:0,c=typeof l[2]=="number"?l[2]:0,m=l.filter(g=>Array.isArray(g)||typeof g=="string"&&g[0]==="$");a[o]=["call",i[`${f}_${c}`],...m]}if(l[0]==="memory.fill"){let f=typeof l[1]=="number"?l[1]:0,c=l.filter(m=>Array.isArray(m)||typeof m=="string"&&m[0]==="$");a[o]=["call",n[f],...c]}}}),t};X.bulk_memory=je;var Ge=(t,e)=>{let r=!1;return L(t,s=>{Array.isArray(s)&&(s[0]==="return_call"||s[0]==="return_call_indirect")&&(r=!0)}),r&&K(t,(s,i,n)=>{!Array.isArray(s)||!i||(s[0]==="return_call"&&(i[n]=["return",["call",...s.slice(1)]]),s[0]==="return_call_indirect"&&(i[n]=["return",["call_indirect",...s.slice(1)]]))}),t};X.return_call=Ge;var Ve=(t,e)=>(K(t,(r,s,i)=>{if(!(!Array.isArray(r)||!s)&&(r[0]==="ref.i31"&&(s[i]=["i32.and",...r.slice(1),["i32.const",2147483647]]),r[0]==="i31.get_u"&&(s[i]=r.length>1?r[1]:["drop"]),r[0]==="i31.get_s")){let n=r.slice(1);s[i]=["i32.shr_s",["i32.shl",...n,["i32.const",1]],["i32.const",1]]}}),t);X.i31ref=Ve;var He=(t,e)=>{let r={};L(t,i=>{if(!Array.isArray(i)||i[0]!=="global")return;let n=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(n)for(let l=i.length-1;l>=0;l--){let a=i[l];if(Array.isArray(a)&&(a[0]==="i32.const"||a[0]==="i64.const"||a[0]==="f32.const"||a[0]==="f64.const")){r[n]={type:a[0].split(".")[0],value:a[1]};break}}});let s=i=>{if(!Array.isArray(i))return i;let n=i[0];if(n==="global.get"&&r[i[1]]){let l=r[i[1]];return[`${l.type}.const`,l.value]}if(n==="i32.add"||n==="i64.add"){let l=s(i[1]),a=s(i[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f+c]}}if(n==="i32.sub"||n==="i64.sub"){let l=s(i[1]),a=s(i[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f-c]}}if(n==="i32.mul"||n==="i64.mul"){let l=s(i[1]),a=s(i[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f*c]}}return i};return K(t,(i,n,l)=>{if(!(!Array.isArray(i)||i[0]!=="global"||!n)){for(let a=2;a<i.length;a++)if(Array.isArray(i[a])){let o=s(i[a]);o!==i[a]&&(i[a]=o)}}}),t};X.extended_const=He;var Ye=(t,e)=>{let r=new Map,s=[];if(L(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 m=1;m<c.length;m++)f.push(c[m]);f.length>1&&o&&r.set(o,f)}),!r.size)return t;let i=Math.max(...[...r.values()].map(a=>a.length)),n={};for(let[a,o]of r)for(let f=1;f<o.length;f++){let c=o[f];if(n[c]||(n[c]=[]),n[c].length<f){let m=Z(`ret_${c}_${n[c].length}`);n[c].push(m),s.push(["global",m,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let l=t[0]==="module"?1:0;for(let a of s.reverse())It(t,l,a);return K(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 m=r.get(c);for(let g=0;g<a.length;g++)if(Array.isArray(a[g])&&a[g][0]==="result"){a[g]=["result",m[0]];break}}),t};X.multi_value=Ye;var yt={i32:4,i64:8,f32:4,f64:8},Xe=(t,e)=>{let r=new Map,s=new Map,i=1;if(L(t,y=>{if(!Array.isArray(y)||y[0]!=="type")return;let _=typeof y[1]=="string"&&y[1][0]==="$"?y[1]:null;if(_){for(let w of y)if(Array.isArray(w)){if(w[0]==="struct"){let v=[];for(let b of w)if(Array.isArray(b)&&b[0]==="field"){let z=typeof b[1]=="string"&&b[1][0]==="$"?b[1]:null,$=z?b[2]:b[1],I=Array.isArray($)&&$[0]==="mut"?$[1]:$;v.push({name:z,type:I})}r.set(_,{kind:"struct",fields:v}),s.set(_,i++)}if(w[0]==="array"){let v=w[1],b=Array.isArray(v)&&v[0]==="mut"?v[1]:v;r.set(_,{kind:"array",elemType:b}),s.set(_,i++)}}}}),!r.size)return t;let n=ne(t,"memory").length>0,l=Z("alloc"),a=Z("heap_ptr"),o=t[0]==="module"?1:0;n||It(t,o,["memory",1]),It(t,o+1,["global",a,["mut","i32"],["i32.const",1024]]);let f=["func",l,["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=y=>{let _=4;for(let w of y.fields)_+=yt[w.type]||4;return _},m=(y,_)=>{let w=4;for(let v=0;v<_;v++)w+=yt[y.fields[v].type]||4;return w},g=(y,_)=>{for(let w=0;w<y.fields.length;w++)if(y.fields[w].name===_)return w;return-1},u=0,d=()=>`$__gc_tmp${u++}`;return L(t,y=>{if(!Array.isArray(y)||y[0]!=="func")return;let _=!1,w=!1,v=!1,b=!1;if(L(y,$=>{Array.isArray($)&&(($[0]==="struct.new"||$[0]==="struct.new_default")&&(_=!0),($[0]==="array.new"||$[0]==="array.new_default")&&(w=!0,v=!0,b=!0))}),!_&&!w)return;let z=1;for(let $=1;$<y.length;$++){let I=y[$];if(Array.isArray(I)&&(I[0]==="param"||I[0]==="result"||I[0]==="local"||I[0]==="export"||I[0]==="type"))z=$+1;else if(typeof I=="string"&&I[0]==="$")z=$+1;else if(!Array.isArray(I))z=$+1;else break}_&&y.splice(z++,0,["local","$__gc_ptr","i32"]),w&&y.splice(z++,0,["local","$__gc_aptr","i32"]),v&&y.splice(z++,0,["local","$__gc_alen","i32"]),b&&y.splice(z++,0,["local","$__gc_aidx","i32"])}),K(t,(y,_,w)=>{if(!(!Array.isArray(y)||!_)){if(y[0]==="struct.new"||y[0]==="struct.new_default"){let v=y[1],b=r.get(v);if(!b||b.kind!=="struct")return;let z=c(b),$=s.get(v),I=y.slice(2),U="$__gc_ptr",O=[["local.set",U,["call",l,["i32.const",z]]],["i32.store",["local.get",U],["i32.const",$]]];if(y[0]==="struct.new")for(let T=0;T<b.fields.length;T++){let x=b.fields[T],h=m(b,T),N=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store";O.push([N,["i32.add",["local.get",U],["i32.const",h]],I[T]||[`${x.type}.const`,0]])}else for(let T=0;T<b.fields.length;T++){let x=b.fields[T],h=m(b,T),N=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store",D=x.type==="i64"?["i64.const",0n]:x.type==="f32"?["f32.const",0]:x.type==="f64"?["f64.const",0]:["i32.const",0];O.push([N,["i32.add",["local.get",U],["i32.const",h]],D])}O.push(["local.get",U]),_[w]=["block",["result","i32"],...O]}if(y[0]==="struct.get"){let v=y[1],b=y[2],z=y[3],$=r.get(v);if(!$||$.kind!=="struct")return;let I=typeof b=="string"&&b[0]==="$"?g($,b):parseInt(b);if(I<0)return;let U=$.fields[I],O=m($,I),T=U.type==="i64"?"i64.load":U.type==="f32"?"f32.load":U.type==="f64"?"f64.load":"i32.load";_[w]=[T,["i32.add",z,["i32.const",O]]]}if(y[0]==="struct.set"){let v=y[1],b=y[2],z=y[3],$=y[4],I=r.get(v);if(!I||I.kind!=="struct")return;let U=typeof b=="string"&&b[0]==="$"?g(I,b):parseInt(b);if(U<0)return;let O=I.fields[U],T=m(I,U),x=O.type==="i64"?"i64.store":O.type==="f32"?"f32.store":O.type==="f64"?"f64.store":"i32.store";_[w]=[x,["i32.add",z,["i32.const",T]],$]}if(y[0]==="array.new"||y[0]==="array.new_default"){let v=y[1],b=r.get(v);if(!b||b.kind!=="array")return;let z=s.get(v),$=yt[b.elemType]||4,I=y[0]==="array.new"?y[2]:null,U=y[0]==="array.new"?y[3]:y[2],O="$__gc_aptr",T="$__gc_alen",x="$__gc_aidx",h=b.elemType==="i64"?"i64.store":b.elemType==="f32"?"f32.store":b.elemType==="f64"?"f64.store":"i32.store",N=[["local.set",T,U],["local.set",O,["call",l,["i32.add",["i32.const",8],["i32.mul",["local.get",T],["i32.const",$]]]]],["i32.store",["local.get",O],["i32.const",z]],["i32.store",["i32.add",["local.get",O],["i32.const",4]],["local.get",T]]];I&&N.push(["local.set",x,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",x],["local.get",T]]],[h,["i32.add",["i32.add",["local.get",O],["i32.const",8]],["i32.mul",["local.get",x],["i32.const",$]]],I],["local.set",x,["i32.add",["local.get",x],["i32.const",1]]],["br","$loop"]]]),N.push(["local.get",O]),_[w]=["block",["result","i32"],...N]}if(y[0]==="array.get"){let v=y[1],b=y[2],z=y[3],$=r.get(v);if(!$||$.kind!=="array")return;let I=yt[$.elemType]||4,U=$.elemType==="i64"?"i64.load":$.elemType==="f32"?"f32.load":$.elemType==="f64"?"f64.load":"i32.load";_[w]=[U,["i32.add",["i32.add",b,["i32.const",8]],["i32.mul",z,["i32.const",I]]]]}if(y[0]==="array.set"){let v=y[1],b=y[2],z=y[3],$=y[4],I=r.get(v);if(!I||I.kind!=="array")return;let U=yt[I.elemType]||4,O=I.elemType==="i64"?"i64.store":I.elemType==="f32"?"f32.store":I.elemType==="f64"?"f64.store":"i32.store";_[w]=[O,["i32.add",["i32.add",b,["i32.const",8]],["i32.mul",z,["i32.const",U]]],$]}if(y[0]==="array.len"){let v=y[1];_[w]=["i32.load",["i32.add",v,["i32.const",4]]]}}}),t};X.gc=Xe;var Ke=(t,e)=>{let r=new Map,s=1;return L(t,i=>{if(!Array.isArray(i)||i[0]!=="type")return;let n=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(n)for(let l of i)Array.isArray(l)&&(l[0]==="struct"||l[0]==="array")&&r.set(n,s++)}),r.size&&K(t,(i,n,l)=>{if(!(!Array.isArray(i)||!n)){if(i[0]==="ref.test"){let a=i[1],o=null;Array.isArray(a)&&a[0]==="ref"&&(o=a[1]==="null"?a[2]:a[1]);let f=i[2],c=r.get(o);c!==void 0&&(n[l]=["if",["result","i32"],["i32.eqz",f],["then",["i32.const",0]],["else",["i32.eq",["i32.load",f],["i32.const",c]]]])}if(i[0]==="ref.cast"){let a=i[1],o=null,f=!1;Array.isArray(a)&&a[0]==="ref"&&(a[1]==="null"?(f=!0,o=a[2]):o=a[1]);let c=i[2],m=r.get(o);if(m!==void 0){let g=Z("cast");f?n[l]=["block",["result","i32"],["local",g,"i32"],["local.set",g,c],["if",["i32.and",["i32.ne",["local.get",g],["i32.const",0]],["i32.ne",["i32.load",["local.get",g]],["i32.const",m]]],["then",["unreachable"]]],["local.get",g]]:n[l]=["block",["result","i32"],["local",g,"i32"],["local.set",g,c],["if",["i32.or",["i32.eqz",["local.get",g]],["i32.ne",["i32.load",["local.get",g]],["i32.const",m]]],["then",["unreachable"]]],["local.get",g]]}}if(i[0]==="br_on_cast"){let a=i[1],o=i[2],f=i[3],c=i[4],m=null;Array.isArray(f)&&f[0]==="ref"&&(m=f[1]==="null"?f[2]:f[1]);let g=r.get(m);if(g!==void 0){let u=Z("brcast");n[l]=["block",["result","i32"],["local",u,"i32"],["local.set",u,c],["br_if",a,["i32.and",["i32.ne",["local.get",u],["i32.const",0]],["i32.eq",["i32.load",["local.get",u]],["i32.const",g]]]],["local.get",u]]}}if(i[0]==="br_on_cast_fail"){let a=i[1],o=i[2],f=i[3],c=i[4],m=null;Array.isArray(f)&&f[0]==="ref"&&(m=f[1]==="null"?f[2]:f[1]);let g=r.get(m);if(g!==void 0){let u=Z("brfail");n[l]=["block",["result","i32"],["local",u,"i32"],["local.set",u,c],["br_if",a,["i32.or",["i32.eqz",["local.get",u]],["i32.ne",["i32.load",["local.get",u]],["i32.const",g]]]],["local.get",u]]}}}}),t};X.ref_cast=Ke;function kt(t,e=!0){typeof t=="string"&&(t=V(t)),t=se(t),e=Fe(e);let r=Ce(t),s={uid:0};for(let i of Dt)r.has(i)&&e[i]!==!1&&X[i]&&(t=X[i](t,s));return t}var Wt={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!0,vacuum:!0,peephole:!0,globals:!0,offset:!0,unbranch:!0,stripmut:!0,brif:!0,foldarms:!0,dedupe:!0,reorder:!0,dedupTypes:!0,packData:!0,minifyImports:!1},Lt=Object.keys(Wt),B=(t,e)=>{if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="bigint")return t===e;if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!B(t[r],e[r]))return!1;return!0},Ze=t=>{if(t===!0)return{...Wt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.size===1&&Lt.includes([...e][0])?Object.fromEntries(Lt.map(r=>[r,e.has(r)])):Object.fromEntries(Lt.map(r=>[r,e.has(r)||e.has("all")]))}return{...Wt,...t}},S=t=>Array.isArray(t)?t.map(S):t,P=(t,e,r,s)=>{if(e(t,r,s),Array.isArray(t))for(let i=0;i<t.length;i++)P(t[i],e,t,i)},C=(t,e,r,s)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++){let l=C(t[n],e,t,n);l!==void 0&&(t[n]=l)}let i=e(t,r,s);return i!==void 0?i:t},zt=t=>{let e=1;for(;e<t.length;){let i=t[e];if(Array.isArray(i)&&(i[0]==="then"||i[0]==="else"||i[0]==="result"||i[0]==="param")){e++;continue}break}let r=null,s=null;for(let i=e+1;i<t.length;i++){let n=t[i];Array.isArray(n)&&(n[0]==="then"?r=n:n[0]==="else"&&(s=n))}return{condIdx:e,cond:t[e],thenBranch:r,elseBranch:s}},Je=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,s=new Map,i=new Map,n=new Map,l=new Map,a=(x,h,N,D=!1)=>{let rt=typeof h[1]=="string"&&h[1][0]==="$",xe=rt?h[1]:N,de=!D&&h.some(Rt=>Array.isArray(Rt)&&Rt[0]==="export"),pt={node:h,idx:N,used:de,isImport:D};return x.set(xe,pt),rt&&x.set(N,pt),l.set(h,pt),pt},o=0,f=0,c=0,m=0,g=0,u=[],d=[],y=[],_=[];for(let x of t.slice(1)){if(!Array.isArray(x))continue;let h=x[0];if(h==="type")a(s,x,c++);else if(h==="func")a(e,x,o++);else if(h==="global")a(r,x,f++);else if(h==="table")a(i,x,m++);else if(h==="memory")a(n,x,g++);else if(h==="import")for(let N of x)Array.isArray(N)&&(N[0]==="func"?a(e,N,o++,!0):N[0]==="global"?a(r,N,f++,!0):N[0]==="table"?a(i,N,m++,!0):N[0]==="memory"&&a(n,N,g++,!0));else h==="export"?y.push(x):h==="start"?_.push(x):h==="elem"?u.push(x):h==="data"&&d.push(x)}let w=[],v=x=>{x&&!x.scanned&&w.push(x)},b=x=>{let h=e.get(x);h&&(h.used||(h.used=!0),v(h))},z=x=>{let h=r.get(x);h&&(h.used=!0)},$=x=>{let h=i.get(x);h&&(h.used=!0)},I=x=>{typeof x=="string"&&x[0]!=="$"&&(x=+x);let h=n.get(x);h&&(h.used=!0)},U=x=>{let h=s.get(x);h&&(h.used=!0)};for(let x of y)for(let h of x){if(!Array.isArray(h))continue;let[N,D]=h;N==="func"?b(D):N==="global"?z(D):N==="table"?$(D):N==="memory"&&I(D)}for(let x of _){let h=x[1];typeof h=="string"&&h[0]!=="$"&&(h=+h),b(h)}for(let x of u)P(x,h=>{Array.isArray(h)&&h[0]==="ref.func"?b(h[1]):typeof h=="string"&&h[0]==="$"&&b(h)});for(let x of d){let h=x[1];Array.isArray(h)&&h[0]==="memory"?I(h[1]):typeof h=="string"&&h[0]==="$"?I(h):Array.isArray(h)&&I(0)}for(let x of[e,r,i,n])for(let h of x.values())h.used&&v(h);if(!(y.length>0||_.length>0||u.length>0||w.length>0)){for(let x of[e,r,i,n])for(let h of x.values())h.used=!0;return t}for(;w.length;){let x=w.pop();x.scanned||(x.scanned=!0,!x.isImport&&P(x.node,h=>{if(!Array.isArray(h)){typeof h=="string"&&h[0]==="$"&&b(h);return}let[N,D]=h;if(N==="call"||N==="return_call"||N==="ref.func")b(D);else if(N==="global.get"||N==="global.set")z(D);else if(N==="type")U(D);else if(N==="call_indirect"||N==="return_call_indirect")for(let rt of h)typeof rt=="string"&&rt[0]==="$"&&$(rt);typeof N=="string"&&(N.startsWith("memory.")||N.includes(".load")||N.includes(".store"))&&I(0)}))}let T=["module"];for(let x of t.slice(1)){if(!Array.isArray(x)){T.push(x);continue}let h=x[0];if(h==="func"||h==="global"||h==="type")l.get(x)?.used&&T.push(x);else if(h==="import"){let N=!1;for(let D of x){if(!Array.isArray(D))continue;if(l.get(D)?.used){N=!0;break}}N&&T.push(x)}else T.push(x)}return T},le=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),ft=t=>(e,r)=>t(e,r)?1:0,Nt=t=>(e,r)=>t(e>>>0,r>>>0)?1:0,ot=t=>(e,r)=>t(e,r)?1:0,Mt=t=>(e,r)=>t(BigInt.asUintN(64,e),BigInt.asUintN(64,r))?1:0,Qe={"i32.add":[(t,e)=>t+e|0,"i32"],"i32.sub":[(t,e)=>t-e|0,"i32"],"i32.mul":[(t,e)=>Math.imul(t,e),"i32"],"i32.div_s":[(t,e)=>e!==0?t/e|0:null,"i32"],"i32.div_u":[(t,e)=>e!==0?(t>>>0)/(e>>>0)|0:null,"i32"],"i32.rem_s":[(t,e)=>e!==0?t%e|0:null,"i32"],"i32.rem_u":[(t,e)=>e!==0?(t>>>0)%(e>>>0)|0:null,"i32"],"i32.and":[(t,e)=>t&e,"i32"],"i32.or":[(t,e)=>t|e,"i32"],"i32.xor":[(t,e)=>t^e,"i32"],"i32.shl":[(t,e)=>t<<(e&31),"i32"],"i32.shr_s":[(t,e)=>t>>(e&31),"i32"],"i32.shr_u":[(t,e)=>t>>>(e&31),"i32"],"i32.rotl":[(t,e)=>(e&=31,t<<e|t>>>32-e|0),"i32"],"i32.rotr":[(t,e)=>(e&=31,t>>>e|t<<32-e|0),"i32"],"i32.eq":[ft((t,e)=>t===e),"i32"],"i32.ne":[ft((t,e)=>t!==e),"i32"],"i32.lt_s":[ft((t,e)=>t<e),"i32"],"i32.lt_u":[Nt((t,e)=>t<e),"i32"],"i32.gt_s":[ft((t,e)=>t>e),"i32"],"i32.gt_u":[Nt((t,e)=>t>e),"i32"],"i32.le_s":[ft((t,e)=>t<=e),"i32"],"i32.le_u":[Nt((t,e)=>t<=e),"i32"],"i32.ge_s":[ft((t,e)=>t>=e),"i32"],"i32.ge_u":[Nt((t,e)=>t>=e),"i32"],"i32.eqz":[t=>t===0?1:0,"i32"],"i32.clz":[t=>Math.clz32(t),"i32"],"i32.ctz":[t=>t===0?32:31-Math.clz32(t&-t),"i32"],"i32.popcnt":[t=>{let e=0;for(;t;)e+=t&1,t>>>=1;return e},"i32"],"i32.wrap_i64":[t=>Number(BigInt.asIntN(32,t)),"i32"],"i32.extend8_s":[t=>t<<24>>24,"i32"],"i32.extend16_s":[t=>t<<16>>16,"i32"],"i64.add":[(t,e)=>BigInt.asIntN(64,t+e),"i64"],"i64.sub":[(t,e)=>BigInt.asIntN(64,t-e),"i64"],"i64.mul":[(t,e)=>BigInt.asIntN(64,t*e),"i64"],"i64.div_s":[(t,e)=>e!==0n?BigInt.asIntN(64,t/e):null,"i64"],"i64.div_u":[(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)/BigInt.asUintN(64,e)):null,"i64"],"i64.rem_s":[(t,e)=>e!==0n?BigInt.asIntN(64,t%e):null,"i64"],"i64.rem_u":[(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)%BigInt.asUintN(64,e)):null,"i64"],"i64.and":[(t,e)=>BigInt.asIntN(64,t&e),"i64"],"i64.or":[(t,e)=>BigInt.asIntN(64,t|e),"i64"],"i64.xor":[(t,e)=>BigInt.asIntN(64,t^e),"i64"],"i64.shl":[(t,e)=>BigInt.asIntN(64,t<<(e&63n)),"i64"],"i64.shr_s":[(t,e)=>BigInt.asIntN(64,t>>(e&63n)),"i64"],"i64.shr_u":[(t,e)=>BigInt.asUintN(64,BigInt.asUintN(64,t)>>(e&63n)),"i64"],"i64.eq":[ot((t,e)=>t===e),"i32"],"i64.ne":[ot((t,e)=>t!==e),"i32"],"i64.lt_s":[ot((t,e)=>t<e),"i32"],"i64.lt_u":[Mt((t,e)=>t<e),"i32"],"i64.gt_s":[ot((t,e)=>t>e),"i32"],"i64.gt_u":[Mt((t,e)=>t>e),"i32"],"i64.le_s":[ot((t,e)=>t<=e),"i32"],"i64.le_u":[Mt((t,e)=>t<=e),"i32"],"i64.ge_s":[ot((t,e)=>t>=e),"i32"],"i64.ge_u":[Mt((t,e)=>t>=e),"i32"],"i64.eqz":[t=>t===0n?1:0,"i32"],"i64.extend_i32_s":[t=>BigInt(t),"i64"],"i64.extend_i32_u":[t=>BigInt(t>>>0),"i64"],"i64.extend8_s":[t=>BigInt.asIntN(64,BigInt.asIntN(8,t)),"i64"],"i64.extend16_s":[t=>BigInt.asIntN(64,BigInt.asIntN(16,t)),"i64"],"i64.extend32_s":[t=>BigInt.asIntN(64,BigInt.asIntN(32,t)),"i64"],"f32.add":[(t,e)=>Math.fround(t+e),"f32"],"f32.sub":[(t,e)=>Math.fround(t-e),"f32"],"f32.mul":[(t,e)=>Math.fround(t*e),"f32"],"f32.div":[(t,e)=>Math.fround(t/e),"f32"],"f32.neg":[t=>Math.fround(-t),"f32"],"f32.abs":[t=>Math.fround(Math.abs(t)),"f32"],"f32.sqrt":[t=>Math.fround(Math.sqrt(t)),"f32"],"f32.ceil":[t=>Math.fround(Math.ceil(t)),"f32"],"f32.floor":[t=>Math.fround(Math.floor(t)),"f32"],"f32.trunc":[t=>Math.fround(Math.trunc(t)),"f32"],"f32.nearest":[t=>Math.fround(le(t)),"f32"],"f64.add":[(t,e)=>t+e,"f64"],"f64.sub":[(t,e)=>t-e,"f64"],"f64.mul":[(t,e)=>t*e,"f64"],"f64.div":[(t,e)=>t/e,"f64"],"f64.neg":[t=>-t,"f64"],"f64.abs":[Math.abs,"f64"],"f64.sqrt":[Math.sqrt,"f64"],"f64.ceil":[Math.ceil,"f64"],"f64.floor":[Math.floor,"f64"],"f64.trunc":[Math.trunc,"f64"],"f64.nearest":[le,"f64"]},M=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},ae=(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,tr=t=>C(S(t),e=>{if(!Array.isArray(e))return;let r=Qe[e[0]];if(!r)return;let[s,i]=r;if(s.length===1&&e.length===2){let n=M(e[1]);if(!n)return;let l=s(n.value);return l===null?void 0:ae(i,l)}if(s.length===2&&e.length===3){let n=M(e[1]),l=M(e[2]);if(!n||!l)return;let a=s(n.value,l.value);return a===null?void 0:ae(i,a)}}),J=t=>(e,r)=>{let s=M(e),i=M(r);return s?.value===t?r:i?.value===t?e:null},Y=t=>(e,r)=>M(r)?.value===t?e:null,er={"i32.add":J(0),"i64.add":J(0n),"i32.sub":Y(0),"i64.sub":Y(0n),"i32.mul":J(1),"i64.mul":J(1n),"i32.div_s":Y(1),"i32.div_u":Y(1),"i64.div_s":Y(1n),"i64.div_u":Y(1n),"i32.and":J(-1),"i64.and":J(-1n),"i32.or":J(0),"i64.or":J(0n),"i32.xor":J(0),"i64.xor":J(0n),"i32.shl":Y(0),"i32.shr_s":Y(0),"i32.shr_u":Y(0),"i64.shl":Y(0n),"i64.shr_s":Y(0n),"i64.shr_u":Y(0n)},rr=t=>C(S(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let r=er[e[0]];if(!r)return;let s=r(e[1],e[2]);if(s!==null)return s}),ir=t=>C(S(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,s,i]=e;if(r==="i32.mul"){let n=M(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]]}let l=M(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]]}}if(r==="i64.mul"){let n=M(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]]}let l=M(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]]}}if(r==="i32.div_u"){let n=M(i);if(n&&n.value>0&&!(n.value&n.value-1)){let l=Math.log2(n.value);if(Number.isInteger(l))return["i32.shr_u",s,["i32.const",l]]}}if(r==="i64.div_u"){let n=M(i);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let l=BigInt(n.value.toString(2).length-1);return["i64.shr_u",s,["i64.const",l]]}}if(r==="i32.rem_u"){let n=M(i);if(n&&n.value>0&&!(n.value&n.value-1))return["i32.and",s,["i32.const",n.value-1]]}if(r==="i64.rem_u"){let n=M(i);if(n&&n.value>0n&&(n.value&n.value-1n)===0n)return["i64.and",s,["i64.const",n.value-1n]]}}),sr=t=>C(S(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let{cond:s,thenBranch:i,elseBranch:n}=zt(e),l=M(s);if(!l)return;let a=l.value!==0&&l.value!==0n?i:n;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 s=e[e.length-1],i=M(s);return i?i.value===0||i.value===0n?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let s=e[e.length-1],i=M(s);return i?i.value===0||i.value===0n?e[2]:e[1]:void 0}}),fe=new Set(["unreachable","return","br","br_table"]),nr=t=>{let e=S(t);return P(e,r=>{if(!Array.isArray(r))return;let s=r[0];if((s==="func"||s==="block"||s==="loop")&&oe(r),s==="if")for(let i=1;i<r.length;i++)Array.isArray(r[i])&&(r[i][0]==="then"||r[i][0]==="else")&&oe(r[i])}),e},oe=t=>{let e=!1,r=-1;for(let s=1;s<t.length;s++){let i=t[s];if(Array.isArray(i)){let n=i[0];if(n==="param"||n==="result"||n==="local"||n==="type"||n==="export")continue;e&&r===-1&&(r=s),fe.has(n)&&(e=!0,r=s+1)}else typeof i=="string"&&(e&&r===-1&&(r=s),fe.has(i)&&(e=!0,r=s+1))}r>0&&r<t.length&&t.splice(r)},lr=t=>{let e=S(t);return P(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let s=[],i=new Map,n=new Set;for(let l=1;l<r.length;l++){let a=r[l];Array.isArray(a)&&(a[0]==="local"&&(s.push({node:a,idx:l}),typeof a[1]=="string"&&a[1][0]==="$"&&i.set(a[1],a[2])),a[0]==="param"&&typeof a[1]=="string"&&a[1][0]==="$"&&(i.set(a[1],a[2]),n.add(a[1])))}P(r,l=>{if(!Array.isArray(l))return;let a=l[0];if(a==="local.get"||a==="local.set"||a==="local.tee"){let o=l[1];typeof o=="string"&&n.add(o)}});for(let l=s.length-1;l>=0;l--){let{idx:a,node:o}=s[l],f=typeof o[1]=="string"&&o[1][0]==="$"?o[1]:null;f&&!n.has(f)&&r.splice(a,1)}}),e},ar=new Set(["call","call_indirect","return_call","return_call_indirect","table.set","table.grow","table.fill","table.copy","table.init","struct.set","struct.new","array.set","array.new","array.new_fixed","array.new_data","array.new_elem","array.init_data","array.init_elem","ref.i31","global.set","local.set","local.tee","unreachable","return","br","br_if","br_table","br_on_null","br_on_non_null","br_on_cast","br_on_cast_fail","throw","rethrow","throw_ref","try_table","data.drop","elem.drop"]),fr=[".store","memory.",".atomic."],ct=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||ar.has(e))return!1;for(let r of fr)if(e.includes(r))return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!ct(t[r]))return!1;return!0},Bt=t=>{let e=new Map,r=s=>(e.has(s)||e.set(s,{gets:0,sets:0,tees:0}),e.get(s));return P(t,s=>{!Array.isArray(s)||s.length<2||typeof s[1]!="string"||(s[0]==="local.get"?r(s[1]).gets++:s[0]==="local.set"?r(s[1]).sets++:s[0]==="local.tee"&&r(s[1]).tees++)}),e},ye=t=>M(t.val)||t.pure&&t.singleUse,ce=(t,e)=>C(t,r=>{if(!Array.isArray(r)||r[0]!=="local.get"||r.length!==2)return;let s=typeof r[1]=="string"&&e.get(r[1]);if(s&&ye(s))return S(s.val)}),or=(t,e,r)=>{let s=!1,i=l=>r.get(l)||{gets:0,sets:0,tees:0},n=new Map;for(let l=1;l<t.length;l++){let a=t[l];if(!Array.isArray(a))continue;let o=a[0];if(!(o==="param"||o==="result"||o==="local"||o==="type"||o==="export")){if(o==="local.set"&&a.length===3&&typeof a[1]=="string"){ce(a[2],n);let f=i(a[1]);n.set(a[1],{val:a[2],pure:ct(a[2]),singleUse:f.gets<=1&&f.sets<=1&&f.tees===0});continue}if((o==="block"||o==="loop"||o==="if")&&n.clear(),o==="call"||o==="call_indirect"||o==="return_call"||o==="return_call_indirect")for(let[f,c]of n)M(c.val)||n.delete(f);if(o==="local.get"&&a.length===2&&typeof a[1]=="string"){let f=n.get(a[1]);if(f&&ye(f)){let c=S(f.val);a.length=0,a.push(...Array.isArray(c)?c:[c]),s=!0;continue}}if(o!=="block"&&o!=="loop"&&o!=="if"){let f=S(a);ce(a,n),B(f,a)||(s=!0)}}}return s},cr=(t,e,r)=>{let s=!1;for(let i=1;i<t.length-1;i++){let n=t[i],l=t[i+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let a=n[1];if(l[1]!==a||e.has(a))continue;let o=r.get(a)||{gets:0,sets:0,tees:0};if(o.sets!==1||o.gets!==1||o.tees!==0)continue;let f=S(n[2]);t.splice(i,2,...Array.isArray(f)?[f]:[f]),s=!0,i--}return s},ur=(t,e,r)=>{let s=!1;for(let i=1;i<t.length-1;i++){let n=t[i],l=t[i+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let a=n[1];if(l[1]!==a||e.has(a))continue;let o=r.get(a)||{gets:0,sets:0,tees:0};o.sets+o.gets+o.tees<=2||(t.splice(i,2,["local.tee",a,S(n[2])]),s=!0)}return s},mr=(t,e,r)=>{let s=!1,i=n=>r.get(n)||{gets:0,sets:0,tees:0};for(let n=t.length-1;n>=1;n--){let l=t[n];if(!Array.isArray(l))continue;let a=typeof l[1]=="string"?l[1]:null;if(!a||e.has(a))continue;let o=i(a);(l[0]==="local.set"&&o.gets===0&&o.tees===0&&ct(l[2])||l[0]==="local"&&a[0]==="$"&&o.gets===0&&o.sets===0&&o.tees===0)&&(t.splice(n,1),s=!0)}return s},yr=t=>{let e=S(t);return P(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let s=new Set;for(let i of r)Array.isArray(i)&&i[0]==="param"&&typeof i[1]=="string"&&s.add(i[1]);for(let i=0;i<4;i++){let n=!1;if(or(r,s,Bt(r))&&(n=!0),cr(r,s,Bt(r))&&(n=!0),ur(r,s,Bt(r))&&(n=!0),mr(r,s,Bt(r))&&(n=!0),!n)break}}),e},pr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=new Map;for(let s of e.slice(1)){if(!Array.isArray(s)||s[0]!=="func")continue;let i=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(!i)continue;let n=[],l=[],a=!1,o=!1;for(let f=1;f<s.length;f++){let c=s[f];if(Array.isArray(c))if(c[0]==="param")if(typeof c[1]=="string"&&c[1][0]==="$")n.push({name:c[1],type:c[2]});else{n=null;break}else c[0]==="local"?a=!0:c[0]==="export"?o=!0:c[0]!=="result"&&c[0]!=="type"&&l.push(c)}if(n&&!a&&!o&&n.length<=4&&l.length===1){let f=new Set(n.map(m=>m.name)),c=!1;P(l[0],m=>{Array.isArray(m)&&(m[0]==="local.set"||m[0]==="local.tee")&&f.has(m[1])&&(c=!0)}),c||r.set(i,{body:l[0],params:n})}}return r.size===0||C(e,s=>{if(!Array.isArray(s)||s[0]!=="call")return;let i=s[1];if(!r.has(i))return;let{body:n,params:l}=r.get(i),a=s.slice(2);if(l.length===0)return S(n);let o=S(n);return C(o,f=>{if(!Array.isArray(f)||f[0]!=="local.get")return;let c=f[1],m=l.findIndex(g=>g.name===c);if(m!==-1&&a[m])return S(a[m])}),o}),e},gr=t=>C(S(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="nop")return["nop"];if(r==="drop"&&e.length===2&&ct(e[1]))return["nop"];if(r==="select"&&e.length>=4&&B(e[1],e[2]))return e[1];if(r==="if"){let{cond:s,thenBranch:i,elseBranch:n}=zt(e),l=!i||i.length<=1,a=!n||n.length<=1;if(l&&a)return ct(s)?["nop"]:["drop",s];if(n&&a&&!l)return e.filter(o=>o!==n)}if(r==="func"||r==="block"||r==="loop"||r==="then"||r==="else"){let s=[r];for(let i=1;i<e.length;i++){let n=e[i];if(n==="nop"||Array.isArray(n)&&n[0]==="nop")continue;let l=e[i+1],a=l==="drop"||Array.isArray(l)&&l[0]==="drop"&&l.length===1;if(Array.isArray(n)&&ct(n)&&a){i++;continue}s.push(n)}if(s.length!==e.length)return s}}),_r={"i32.sub":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.sub":(t,e)=>B(t,e)?["i64.const",0n]:null,"i32.xor":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.xor":(t,e)=>B(t,e)?["i64.const",0n]:null,"i32.and":(t,e)=>B(t,e)?t:null,"i64.and":(t,e)=>B(t,e)?t:null,"i32.or":(t,e)=>B(t,e)?t:null,"i64.or":(t,e)=>B(t,e)?t:null,"i32.eq":(t,e)=>B(t,e)?["i32.const",1]:null,"i64.eq":(t,e)=>B(t,e)?["i32.const",1]:null,"i32.ne":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.ne":(t,e)=>B(t,e)?["i32.const",0]:null,"i32.lt_s":(t,e)=>B(t,e)?["i32.const",0]:null,"i32.lt_u":(t,e)=>B(t,e)?["i32.const",0]:null,"i32.gt_s":(t,e)=>B(t,e)?["i32.const",0]:null,"i32.gt_u":(t,e)=>B(t,e)?["i32.const",0]:null,"i32.le_s":(t,e)=>B(t,e)?["i32.const",1]:null,"i32.le_u":(t,e)=>B(t,e)?["i32.const",1]:null,"i32.ge_s":(t,e)=>B(t,e)?["i32.const",1]:null,"i32.ge_u":(t,e)=>B(t,e)?["i32.const",1]:null,"i64.lt_s":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.lt_u":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.gt_s":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.gt_u":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.le_s":(t,e)=>B(t,e)?["i32.const",1]:null,"i64.le_u":(t,e)=>B(t,e)?["i32.const",1]:null,"i64.ge_s":(t,e)=>B(t,e)?["i32.const",1]:null,"i64.ge_u":(t,e)=>B(t,e)?["i32.const",1]:null,"i32.mul":(t,e)=>{let r=M(t),s=M(e);return r?.value===0||s?.value===0?["i32.const",0]:null},"i64.mul":(t,e)=>{let r=M(t),s=M(e);return r?.value===0n||s?.value===0n?["i64.const",0n]:null},"i32.and":(t,e)=>{let r=M(t),s=M(e);return r?.value===0||s?.value===0?["i32.const",0]:null},"i64.and":(t,e)=>{let r=M(t),s=M(e);return r?.value===0n||s?.value===0n?["i64.const",0n]:null},"i32.or":(t,e)=>{let r=M(t),s=M(e);return r?.value===-1||s?.value===-1?["i32.const",-1]:null},"i64.or":(t,e)=>{let r=M(t),s=M(e);return r?.value===-1n||s?.value===-1n?["i64.const",-1n]:null},"local.set":(t,e)=>Array.isArray(e)&&e[0]==="local.get"&&e[1]===t?["nop"]:null},hr=t=>C(S(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let r=_r[e[0]];if(!r)return;let s=r(e[1],e[2]);if(s!==null)return s}),xr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=new Map,s=new Set;for(let i of e.slice(1)){if(!Array.isArray(i)||i[0]!=="global")continue;let n=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!n)continue;let l=typeof i[1]=="string"&&i[1][0]==="$",a=l?3:2,o=l?i[2]:i[1];if(Array.isArray(o)&&o[0]==="mut")continue;let f=i[a];M(f)&&r.set(n,f)}P(e,i=>{if(!Array.isArray(i)||i[0]!=="global.set")return;let n=i[1];typeof n=="string"&&n[0]==="$"&&s.add(n)});for(let i of s)r.delete(i);return r.size===0?e:C(e,i=>{if(!Array.isArray(i)||i[0]!=="global.get"||i.length!==2)return;let n=i[1];if(r.has(n))return S(r.get(n))})},dr=t=>C(S(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(typeof r!="string"||!r.endsWith("load")&&!r.endsWith("store"))return;let s=r.endsWith("store"),i=0,n=null,l=1;for(typeof e[1]=="string"&&(e[1][0]==="$"||!isNaN(e[1]))&&(n=e[1],l=2);l<e.length&&typeof e[l]=="string"&&(e[l].startsWith("offset=")||e[l].startsWith("align="));)e[l].startsWith("offset=")&&(i=+e[l].slice(7)),l++;let a=s?e.length-2:e.length-1,o=s?e.length-1:-1;if(a<l)return;let f=e[a];if(!Array.isArray(f)||f[0]!=="i32.add"||f.length!==3)return;let c=f[1],m=f[2],g=M(c),u=M(m),d=null,y=null;if(g&&g.type==="i32"?(y=g.value,d=m):u&&u.type==="i32"&&(y=u.value,d=c),d===null||y===null)return;let _=i+y,w=[r];n!==null&&w.push(n),w.push(`offset=${_}`);let v=null;for(let b=l;b<a;b++)typeof e[b]=="string"&&e[b].startsWith("align=")&&(v=e[b]);return v&&w.push(v),w.push(d),s&&w.push(e[o]),w}),Ar=t=>{let e=S(t);return P(e,r=>{if(!Array.isArray(r)||r[0]!=="block")return;let i=1,n=null;if(typeof r[1]=="string"&&r[1][0]==="$"&&(n=r[1],i=2),!n)return;let l=-1;for(let o=r.length-1;o>=i;o--){let f=r[o];if(!Array.isArray(f)){f!=="nop"&&f!=="end"&&(l=o);continue}let c=f[0];if(!(c==="param"||c==="result"||c==="local"||c==="type"||c==="export")){l=o;break}}if(l<0)return;let a=r[l];Array.isArray(a)&&a[0]==="br"&&a[1]===n&&r.splice(l,1)}),e},br=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=new Set;return P(e,s=>{Array.isArray(s)&&s[0]==="global.set"&&typeof s[1]=="string"&&r.add(s[1])}),C(e,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let i=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(!i||r.has(i))return;let n=typeof s[1]=="string"&&s[1][0]==="$",l=n?s[2]:s[1];if(Array.isArray(l)&&l[0]==="mut"){let a=[...s];return a[n?2:1]=l[1],a}})},wr=t=>C(S(t),e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{cond:r,thenBranch:s,elseBranch:i}=zt(e),n=!s||s.length<=1,l=!i||i.length<=1;if(!n&&l&&s.length===2){let a=s[1];if(Array.isArray(a)&&a[0]==="br"&&a.length===2)return["br_if",a[1],r]}if(n&&!l&&i.length===2){let a=i[1];if(Array.isArray(a)&&a[0]==="br"&&a.length===2)return["br_if",a[1],["i32.eqz",r]]}}),vr=t=>C(S(t),e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{thenBranch:r,elseBranch:s}=zt(e);if(!r||!s||r.length<=1||s.length<=1||!e.some(g=>Array.isArray(g)&&g[0]==="result"))return;let n=0,l=Math.min(r.length,s.length);for(let g=1;g<l&&B(r[r.length-g],s[s.length-g]);g++)n++;if(n===0)return;let a=r.slice(r.length-n),o=r.slice(0,r.length-n),f=s.slice(0,s.length-n),c=["block"];for(let g=1;g<e.length;g++){let u=e[g];if(Array.isArray(u)&&(u[0]==="then"||u[0]==="else"))break;Array.isArray(u)&&(u[0]==="result"||u[0]==="type")&&c.push(u)}let m=["if"];for(let g=1;g<e.length;g++){let u=e[g];if(Array.isArray(u)&&(u[0]==="then"||u[0]==="else"))break;Array.isArray(u)&&(u[0]==="result"||u[0]==="type")||m.push(u)}return m.push(o.length>1?o:["then"]),m.push(f.length>1?f:["else"]),c.push(m,...a),c}),pe=(t,e)=>{let r=[],s=[t];for(;s.length;){let i=s.pop();if(Array.isArray(i)){s.push("|");for(let n=i.length-1;n>=0;n--)s.push(i[n]);s.push("[")}else typeof i=="string"?r.push(e.has(i)?"$__L":i):typeof i=="bigint"?r.push(i.toString()+"n"):typeof i=="number"?r.push(i.toString()):i===null?r.push("null"):i===!0?r.push("t"):i===!1?r.push("f"):r.push(String(i))}return r.join(",")},$r=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=new Map,s=new Map;for(let i of e.slice(1)){if(!Array.isArray(i)||i[0]!=="func")continue;let n=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!n)continue;let l=new Set;typeof i[1]=="string"&&i[1][0]==="$"&&l.add(i[1]),P(i,o=>{if(!Array.isArray(o)||typeof o[1]!="string"||o[1][0]!=="$")return;let f=o[0];(f==="param"||f==="local"||f==="block"||f==="loop"||f==="if")&&l.add(o[1])});let a=pe(i,l);r.has(a)?s.set(n,r.get(a)):r.set(a,n)}return s.size===0||C(e,i=>{if(!Array.isArray(i))return;let n=i[0];if((n==="call"||n==="return_call")&&s.has(i[1]))return[n,s.get(i[1]),...i.slice(2)];if(n==="ref.func"&&s.has(i[1]))return["ref.func",s.get(i[1])];if(n==="elem"){let l=i[i.length-1];if(Array.isArray(l))return[...i.slice(0,-1),l.map(a=>s.get(a)||a)]}if(n==="call_indirect"&&i.length>=3){let l=i[1];if(typeof l=="string"&&s.has(l))return["call_indirect",s.get(l),...i.slice(2)]}}),e},Ir=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=new Map,s=new Map;for(let i of e.slice(1)){if(!Array.isArray(i)||i[0]!=="type")continue;let n=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!n)continue;let l=pe(i,new Set([n]));r.has(l)?s.set(n,r.get(l)):r.set(l,n)}if(s.size===0)return e;for(let i=e.length-1;i>=0;i--){let n=e[i];if(Array.isArray(n)&&n[0]==="type"){let l=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null;l&&s.has(l)&&e.splice(i,1)}}return C(e,i=>{if(!Array.isArray(i))return;let n=i[0];if(n==="func")for(let l=1;l<i.length;l++){let a=i[l];Array.isArray(a)&&a[0]==="type"&&typeof a[1]=="string"&&s.has(a[1])&&(i[l]=["type",s.get(a[1])])}if(n==="import")for(let l=1;l<i.length;l++){let a=i[l];if(Array.isArray(a))for(let o=1;o<a.length;o++){let f=a[o];Array.isArray(f)&&f[0]==="type"&&typeof f[1]=="string"&&s.has(f[1])&&(a[o]=["type",s.get(f[1])])}}if(n==="call_indirect"||n==="return_call_indirect"){if(typeof i[1]=="string"&&s.has(i[1]))return[n,s.get(i[1]),...i.slice(2)];if(Array.isArray(i[1])&&i[1][0]==="type"&&typeof i[1][1]=="string"&&s.has(i[1][1]))return[n,["type",s.get(i[1][1])],...i.slice(2)]}}),e},St=t=>{if(typeof t!="string"||t.length<2||t[0]!=='"')return new Uint8Array;let e=t.slice(1,-1),r=[];for(let s=0;s<e.length;s++)if(e[s]==="\\"){let i=e[++s];i==="x"||i==="X"?(r.push(parseInt(e.slice(s+1,s+3),16)),s+=2):/[0-9a-fA-F]/.test(i)&&/[0-9a-fA-F]/.test(e[s+1])?(r.push(parseInt(e.slice(s,s+2),16)),s++):i==="n"?r.push(10):i==="t"?r.push(9):i==="r"?r.push(13):i==="\\"?r.push(92):i==='"'?r.push(34):r.push(i.charCodeAt(0))}else r.push(e.charCodeAt(s));return new Uint8Array(r)},ge=t=>{let e='"';for(let r=0;r<t.length;r++){let s=t[r];s>=32&&s<127&&s!==34&&s!==92?e+=String.fromCharCode(s):e+="\\"+s.toString(16).padStart(2,"0")}return e+'"'},kr=t=>{let e=[];for(let s of t)if(typeof s=="string")e.push(...St(s));else if(Array.isArray(s)&&s[0]==="i8")for(let i=1;i<s.length;i++)e.push(Number(s[i])&255);else return t;let r=e.length;for(;r>0&&e[r-1]===0;)r--;return r===e.length?t:r===0?[]:[ge(new Uint8Array(e.slice(0,r)))]},Nr=t=>{let e=1;if(typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"){let s=t[e][1];e++;let i=t[e];return Array.isArray(i)&&(i[0]==="i32.const"||i[0]==="i64.const")?{memidx:s,offset:Number(i[1])}:null}let r=t[e];return Array.isArray(r)&&(r[0]==="i32.const"||r[0]==="i64.const")?{memidx:0,offset:Number(r[1])}:null},ue=t=>{let e=1;typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"&&e++,Array.isArray(t[e])&&typeof t[e][0]=="string"&&!t[e][0].startsWith('"')&&e++;let r=0;for(let s=e;s<t.length;s++){let i=t[s];if(typeof i=="string")r+=St(i).length;else if(Array.isArray(i)&&i[0]==="i8")r+=i.length-1;else return null}return r},Mr=(t,e)=>{let r=1;typeof t[r]=="string"&&t[r][0]==="$"&&r++,Array.isArray(t[r])&&t[r][0]==="memory"&&r++,Array.isArray(t[r])&&typeof t[r][0]=="string"&&!t[r][0].startsWith('"')&&r++;let s=1;typeof e[s]=="string"&&e[s][0]==="$"&&s++,Array.isArray(e[s])&&e[s][0]==="memory"&&s++,Array.isArray(e[s])&&typeof e[s][0]=="string"&&!e[s][0].startsWith('"')&&s++;let i=t.slice(r),n=e.slice(s);if(i.length===1&&n.length===1&&typeof i[0]=="string"&&typeof n[0]=="string"){let l=St(i[0]),a=St(n[0]),o=new Uint8Array(l.length+a.length);return o.set(l),o.set(a,l.length),t.length=r,t.push(ge(o)),!0}return t.length=r,t.push(...i,...n),!0},Br=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t);for(let i of e){if(!Array.isArray(i)||i[0]!=="data")continue;let n=1;typeof i[1]=="string"&&i[1][0]==="$"&&(n=2),n<i.length&&Array.isArray(i[n])&&typeof i[n][0]=="string"&&!i[n][0].startsWith('"')&&n++;let l=i.slice(n);if(l.length===0)continue;let a=kr(l);(a.length!==l.length||a.length>0&&a[0]!==l[0])&&(i.length=n,i.push(...a))}let r=[];for(let i=0;i<e.length;i++){let n=e[i];if(Array.isArray(n)&&n[0]==="data"){let l=Nr(n);if(l){let a=ue(n);a!==null&&r.push({...l,node:n,index:i,len:a})}}}r.sort((i,n)=>{let l=String(i.memidx),a=String(n.memidx);return l!==a?l.localeCompare(a):i.offset-n.offset});let s=new Set;for(let i=0;i<r.length-1;i++){let n=r[i],l=r[i+1];s.has(n.index)||String(n.memidx)!==String(l.memidx)||n.offset+n.len===l.offset&&Mr(n.node,l.node)&&(s.add(l.index),n.len=ue(n.node))}return s.size>0&&(e=e.filter((i,n)=>!s.has(n))),e},me=()=>{let t=new Map,e=0;return r=>{if(!t.has(r)){let s="",i=e++;do s=String.fromCharCode(97+i%26)+s,i=Math.floor(i/26)-1;while(i>=0);t.set(r,s||"a")}return t.get(r)}},Sr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=me(),s=me();for(let i of e)!Array.isArray(i)||i[0]!=="import"||(typeof i[1]=="string"&&i[1][0]==='"'&&(i[1]='"'+r(i[1].slice(1,-1))+'"'),typeof i[2]=="string"&&i[2][0]==='"'&&(i[2]='"'+s(i[2].slice(1,-1))+'"'));return e},zr=t=>{let e=!0;return P(t,r=>{if(!e||!Array.isArray(r))return;let s=r[0];if(s==="func"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if((s==="call"||s==="return_call"||s==="ref.func")&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(s==="start"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(s==="elem")for(let i of r){if(typeof i=="string"&&i[0]!=="$"&&/^\d/.test(i)){e=!1;break}if(Array.isArray(i)&&i[0]==="ref.func"&&(typeof i[1]!="string"||i[1][0]!=="$")){e=!1;break}}}),e},Tr=t=>{if(!Array.isArray(t)||t[0]!=="module"||!zr(t))return t;let e=S(t),r=new Map;P(e,l=>{Array.isArray(l)&&(l[0]==="call"||l[0]==="return_call")&&r.set(l[1],(r.get(l[1])||0)+1)});let s=[],i=[],n=[];for(let l of e.slice(1)){if(!Array.isArray(l)){n.push(l);continue}l[0]==="import"?s.push(l):l[0]==="func"?i.push(l):n.push(l)}return i.sort((l,a)=>(r.get(a[1])||0)-(r.get(l[1])||0)),["module",...s,...i,...n]};function Tt(t,e=!0){typeof t=="string"&&(t=V(t)),t=S(t),e=Ze(e);for(let r=0;r<6;r++){let s=t;if(e.stripmut&&(t=br(t)),e.globals&&(t=xr(t)),e.fold&&(t=tr(t)),e.identity&&(t=rr(t)),e.peephole&&(t=hr(t)),e.strength&&(t=ir(t)),e.branch&&(t=sr(t)),e.propagate&&(t=yr(t)),e.inline&&(t=pr(t)),e.offset&&(t=dr(t)),e.unbranch&&(t=Ar(t)),e.brif&&(t=wr(t)),e.foldarms&&(t=vr(t)),e.deadcode&&(t=nr(t)),e.vacuum&&(t=gr(t)),e.locals&&(t=lr(t)),e.dedupe&&(t=$r(t)),e.dedupTypes&&(t=Ir(t)),e.packData&&(t=Br(t)),e.reorder&&(t=Tr(t)),e.treeshake&&(t=Je(t)),e.minifyImports&&(t=Sr(t)),B(s,t))break}return t}var _e="\uE000",he=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},Er=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...s]=t;return he(r)?he(r):r==="local.get"&&e.locals?.[s[0]]?e.locals[s[0]]:r==="call"&&e.funcs?.[s[0]]?e.funcs[s[0]].result?.[0]:null};function Pt(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let s=Pt(t[r],e);s?._splice?(t.splice(r,1,...s),r+=s.length-1):t[r]=s}return t}function Ur(t,e){let r=[],s=new Map;return Pt(t,i=>{if(!Array.isArray(i))return i;if(i[0]==="call"&&typeof i[1]=="function"){let n=i[1];if(!s.has(n)){let a=[];for(let c=2;c<i.length;c++){let m=Er(i[c]);m&&a.push(m)}let o=r.length,f=n.name||`$fn${o}`;s.set(n,{idx:o,name:f.startsWith("$")?f:"$"+f,params:a,fn:n}),r.push(s.get(n))}let l=s.get(n);i[1]=l.name}return i}),r}function qr(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(s=>["param",s])]])}function Or(t,...e){let r={};if(!Array.isArray(t)&&e.length&&typeof e[e.length-1]=="object"&&e[e.length-1]!==null&&!e[e.length-1].byteLength&&(r=e.pop()),Array.isArray(t)&&t.raw){let s=t[0];for(let f=0;f<e.length;f++)s+=_e+t[f+1];let i=V(s),n=[],l=0;i=Pt(i,f=>{if(f===_e){let c=e[l++];if(typeof c=="function")return n.push(c),c;if(typeof c=="string"&&(c[0]==="("||/^\s*\(/.test(c))){let m=V(c);return Array.isArray(m)&&Array.isArray(m[0])&&(m._splice=!0),m}return c.byteLength!==void 0?[...c]:c}return f});let a=null;if(n.length){let f=Ur(i,n);if(f.length){let c=qr(f);i[0]==="module"?i.splice(1,0,...c):typeof i[0]=="string"?i=[...c,i]:i.unshift(...c),a={env:{}};for(let m of f)a.env[m.name.slice(1)]=m.fn}}r.polyfill&&(i=kt(i,r.polyfill)),r.optimize&&(i=Tt(i,r.optimize));let o=at(i);return a&&(o._imports=a),o}if(r.polyfill||r.optimize){let s=typeof t=="string"?V(t):t;return r.polyfill&&(s=kt(s,r.polyfill)),r.optimize&&(s=Tt(s,r.optimize)),at(s)}return at(t)}function Fr(t,...e){let r=Or(t,...e),s=new WebAssembly.Module(r);return new WebAssembly.Instance(s,r._imports).exports}var ai=Fr;export{Or as compile,ai as default,Tt as optimize,V as parse,kt as polyfill,ee as print,Fr as watr};
|
|
1
|
+
var Ae=Object.defineProperty;var be=(t,e)=>{for(var r in e)Ae(t,r,{get:e[r],enumerable:!0})};var gt={};be(gt,{f32:()=>nt,f64:()=>it,i16:()=>ke,i32:()=>R,i64:()=>st,i8:()=>Ie,uleb:()=>p,uleb5:()=>$e,v128:()=>qt});var k=(t,e=k.loc)=>{if(e!=null&&k.src){let r=1,s=1;for(let i=0;i<e&&i<k.src.length;i++)k.src[i]===`
|
|
2
|
+
`?(r++,s=1):s++;t+=` at ${r}:${s}`}throw Error(t)};var Gt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Vt=/^[+-]?(?:0x[\da-f]+|\d+)$/i,we=new TextEncoder,ve=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),jt={n:10,r:13,t:9,'"':34,"'":39,"\\":92},pt=t=>{let e=[],r=1,s,i,n="",l=()=>(n&&e.push(...we.encode(n)),n="");for(;r<t.length-1;)i=t[r++],s=null,i==="\\"&&(t[r]==="u"?(r++,r++,i=String.fromCodePoint(parseInt(t.slice(r,r=t.indexOf("}",r)),16)),r++):jt[t[r]]?s=jt[t[r++]]:isNaN(s=parseInt(t[r]+t[r+1],16))?i+=t[r]:(r++,r++)),s!=null?(l(),e.push(s)):n+=i;return l(),e.valueOf=()=>t,e},Ht=t=>ve.decode(new Uint8Array(pt(t)));var p=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):R.parse(t)),typeof t=="bigint"){for(;;){let s=Number(t&0x7Fn);if(t>>=7n,t===0n){e.push(s);break}e.push(s|128)}return e}let r=t&127;return t>>>=7,t===0?(e.push(r),e):(e.push(r|128),p(t,e))};function $e(t){let e=[];for(let r=0;r<5;r++){let s=t&127;t>>>=7,r<4&&(s|=128),e.push(s)}return e}function R(t,e=[]){for(typeof t=="string"&&(t=R.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 Yt=t=>!Gt.test(t)&&Vt.test(t=t.replaceAll("_",""))?t:k(`Bad int ${t}`),Ie=R,ke=R;R.parse=t=>(t=parseInt(Yt(t)),(t<-2147483648||t>4294967295)&&k("i32 constant out of range"),t);function st(t,e=[]){for(typeof t=="string"?t=st.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 ut=new ArrayBuffer(8),G=new Uint8Array(ut),Ne=new Int32Array(ut),Me=new Float32Array(ut),Be=new Float64Array(ut),Et=new BigInt64Array(ut);st.parse=t=>(t=Yt(t),t=t[0]==="-"?-BigInt(t.slice(1)):BigInt(t),(t<-0x8000000000000000n||t>0xffffffffffffffffn)&&k("i64 constant out of range"),Et[0]=t,Et[0]);var Se=2147483648,ze=2139095040;function nt(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=R.parse(t.slice(r+4)),e|=ze,t[0]==="-"&&(e|=Se),Ne[0]=e):(e=typeof t=="string"?nt.parse(t):t,Me[0]=e),[G[0],G[1],G[2],G[3]]}var Te=0x8000000000000000n,Ee=0x7ff0000000000000n;function it(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=st.parse(t.slice(r+4)),e|=Ee,t[0]==="-"&&(e|=Te),Et[0]=e):(e=typeof t=="string"?it.parse(t):t,Be[0]=e),[G[0],G[1],G[2],G[3],G[4],G[5],G[6],G[7]]}it.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[s,i="0"]=t.split(/p/i),[n,l=""]=s.split("."),a=l.length??0,o=parseInt(n);isNaN(o)&&k();let f=l?parseInt("0x"+l)/16**a:0;i=parseInt(i,10);let c=r*(o+f)*2**i;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)};nt.parse=t=>it.parse(t,34028234663852886e22);var qt=t=>{let e=BigInt(typeof t=="string"?t.replaceAll("_",""):t),r=new Uint8Array(16);for(let s=0;s<16;s++)r[s]=Number(e&0xffn),e>>=8n;return[...r]};var mt=["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",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"f32.sqrt_ceil","f32.add_ceil","f32.sub_ceil","f32.mul_ceil","f32.div_ceil","f64.sqrt_ceil","f64.add_ceil","f64.sub_ceil","f64.mul_ceil","f64.div_ceil","f32.convert_ceil_i32_s","f32.convert_ceil_i32_u","f32.convert_ceil_i64_s","f32.convert_ceil_i64_u","f32.demote_ceil_f64","f64.convert_ceil_i32_s","f64.convert_ceil_i32_u","f64.convert_ceil_i64_s","f64.convert_ceil_i64_u","f64.promote_ceil_f32","f32.sqrt_floor","f32.add_floor","f32.sub_floor","f32.mul_floor","f32.div_floor","f64.sqrt_floor","f64.add_floor","f64.sub_floor","f64.mul_floor","f64.div_floor","f32.convert_floor_i32_s","f32.convert_floor_i32_u","f32.convert_floor_i64_s","f32.convert_floor_i64_u","f32.demote_floor_f64","f64.convert_floor_i32_s","f64.convert_floor_i32_u","f64.convert_floor_i64_s","f64.convert_floor_i64_u","f64.promote_floor_f32","f32.sqrt_trunc","f32.add_trunc","f32.sub_trunc","f32.mul_trunc","f32.div_trunc","f64.sqrt_trunc","f64.add_trunc","f64.sub_trunc","f64.mul_trunc","f64.div_trunc","f32.convert_trunc_i32_s","f32.convert_trunc_i32_u","f32.convert_trunc_i64_s","f32.convert_trunc_i64_u","f32.demote_trunc_f64","f64.convert_trunc_i32_s","f64.convert_trunc_i32_u","f64.convert_trunc_i64_s","f64.convert_trunc_i64_u","f64.promote_trunc_f32"],["v128.load memarg","v128.load8x8_s memarg","v128.load8x8_u memarg","v128.load16x4_s memarg","v128.load16x4_u memarg","v128.load32x2_s memarg","v128.load32x2_u memarg","v128.load8_splat memarg","v128.load16_splat memarg","v128.load32_splat memarg","v128.load64_splat memarg","v128.store memarg","v128.const v128const","i8x16.shuffle shuffle","i8x16.swizzle","i8x16.splat","i16x8.splat","i32x4.splat","i64x2.splat","f32x4.splat","f64x2.splat","i8x16.extract_lane_s laneidx","i8x16.extract_lane_u laneidx","i8x16.replace_lane laneidx","i16x8.extract_lane_s laneidx","i16x8.extract_lane_u laneidx","i16x8.replace_lane laneidx","i32x4.extract_lane laneidx","i32x4.replace_lane laneidx","i64x2.extract_lane laneidx","i64x2.replace_lane laneidx","f32x4.extract_lane laneidx","f32x4.replace_lane laneidx","f64x2.extract_lane laneidx","f64x2.replace_lane laneidx","i8x16.eq","i8x16.ne","i8x16.lt_s","i8x16.lt_u","i8x16.gt_s","i8x16.gt_u","i8x16.le_s","i8x16.le_u","i8x16.ge_s","i8x16.ge_u","i16x8.eq","i16x8.ne","i16x8.lt_s","i16x8.lt_u","i16x8.gt_s","i16x8.gt_u","i16x8.le_s","i16x8.le_u","i16x8.ge_s","i16x8.ge_u","i32x4.eq","i32x4.ne","i32x4.lt_s","i32x4.lt_u","i32x4.gt_s","i32x4.gt_u","i32x4.le_s","i32x4.le_u","i32x4.ge_s","i32x4.ge_u","f32x4.eq","f32x4.ne","f32x4.lt","f32x4.gt","f32x4.le","f32x4.ge","f64x2.eq","f64x2.ne","f64x2.lt","f64x2.gt","f64x2.le","f64x2.ge","v128.not","v128.and","v128.andnot","v128.or","v128.xor","v128.bitselect","v128.any_true","v128.load8_lane memlane","v128.load16_lane memlane","v128.load32_lane memlane","v128.load64_lane memlane","v128.store8_lane memlane","v128.store16_lane memlane","v128.store32_lane memlane","v128.store64_lane memlane","v128.load32_zero memarg","v128.load64_zero memarg","f32x4.demote_f64x2_zero","f64x2.promote_low_f32x4","i8x16.abs","i8x16.neg","i8x16.popcnt","i8x16.all_true","i8x16.bitmask","i8x16.narrow_i16x8_s","i8x16.narrow_i16x8_u","f32x4.ceil","f32x4.floor","f32x4.trunc","f32x4.nearest","i8x16.shl","i8x16.shr_s","i8x16.shr_u","i8x16.add","i8x16.add_sat_s","i8x16.add_sat_u","i8x16.sub","i8x16.sub_sat_s","i8x16.sub_sat_u","f64x2.ceil","f64x2.floor","i8x16.min_s","i8x16.min_u","i8x16.max_s","i8x16.max_u","f64x2.trunc","i8x16.avgr_u","i16x8.extadd_pairwise_i8x16_s","i16x8.extadd_pairwise_i8x16_u","i32x4.extadd_pairwise_i16x8_s","i32x4.extadd_pairwise_i16x8_u","i16x8.abs","i16x8.neg","i16x8.q15mulr_sat_s","i16x8.all_true","i16x8.bitmask","i16x8.narrow_i32x4_s","i16x8.narrow_i32x4_u","i16x8.extend_low_i8x16_s","i16x8.extend_high_i8x16_s","i16x8.extend_low_i8x16_u","i16x8.extend_high_i8x16_u","i16x8.shl","i16x8.shr_s","i16x8.shr_u","i16x8.add","i16x8.add_sat_s","i16x8.add_sat_u","i16x8.sub","i16x8.sub_sat_s","i16x8.sub_sat_u","f64x2.nearest","i16x8.mul","i16x8.min_s","i16x8.min_u","i16x8.max_s","i16x8.max_u",,"i16x8.avgr_u","i16x8.extmul_low_i8x16_s","i16x8.extmul_high_i8x16_s","i16x8.extmul_low_i8x16_u","i16x8.extmul_high_i8x16_u","i32x4.abs","i32x4.neg",,"i32x4.all_true","i32x4.bitmask",,,"i32x4.extend_low_i16x8_s","i32x4.extend_high_i16x8_s","i32x4.extend_low_i16x8_u","i32x4.extend_high_i16x8_u","i32x4.shl","i32x4.shr_s","i32x4.shr_u","i32x4.add",,,"i32x4.sub",,,,"i32x4.mul","i32x4.min_s","i32x4.min_u","i32x4.max_s","i32x4.max_u","i32x4.dot_i16x8_s",,"i32x4.extmul_low_i16x8_s","i32x4.extmul_high_i16x8_s","i32x4.extmul_low_i16x8_u","i32x4.extmul_high_i16x8_u","i64x2.abs","i64x2.neg",,"i64x2.all_true","i64x2.bitmask",,,"i64x2.extend_low_i32x4_s","i64x2.extend_high_i32x4_s","i64x2.extend_low_i32x4_u","i64x2.extend_high_i32x4_u","i64x2.shl","i64x2.shr_s","i64x2.shr_u","i64x2.add",,,"i64x2.sub",,,,"i64x2.mul","i64x2.eq","i64x2.ne","i64x2.lt_s","i64x2.gt_s","i64x2.le_s","i64x2.ge_s","i64x2.extmul_low_i32x4_s","i64x2.extmul_high_i32x4_s","i64x2.extmul_low_i32x4_u","i64x2.extmul_high_i32x4_u","f32x4.abs","f32x4.neg",,"f32x4.sqrt","f32x4.add","f32x4.sub","f32x4.mul","f32x4.div","f32x4.min","f32x4.max","f32x4.pmin","f32x4.pmax","f64x2.abs","f64x2.neg",,"f64x2.sqrt","f64x2.add","f64x2.sub","f64x2.mul","f64x2.div","f64x2.min","f64x2.max","f64x2.pmin","f64x2.pmax","i32x4.trunc_sat_f32x4_s","i32x4.trunc_sat_f32x4_u","f32x4.convert_i32x4_s","f32x4.convert_i32x4_u","i32x4.trunc_sat_f64x2_s_zero","i32x4.trunc_sat_f64x2_u_zero","f64x2.convert_low_i32x4_s","f64x2.convert_low_i32x4_u","i8x16.relaxed_swizzle","i32x4.relaxed_trunc_f32x4_s","i32x4.relaxed_trunc_f32x4_u","i32x4.relaxed_trunc_f64x2_s_zero","i32x4.relaxed_trunc_f64x2_u_zero","f32x4.relaxed_madd","f32x4.relaxed_nmadd","f64x2.relaxed_madd","f64x2.relaxed_nmadd","i8x16.relaxed_laneselect","i16x8.relaxed_laneselect","i32x4.relaxed_laneselect","i64x2.relaxed_laneselect","f32x4.relaxed_min","f32x4.relaxed_max","f64x2.relaxed_min","f64x2.relaxed_max","i16x8.relaxed_q15mulr_s","i16x8.relaxed_dot_i8x16_i7x16_s","i32x4.relaxed_dot_i8x16_i7x16_add_s"],["memory.atomic.notify memarg","memory.atomic.wait32 memarg","memory.atomic.wait64 memarg","atomic.fence opt_memory",,,,,,,,,,,,,"i32.atomic.load memarg","i64.atomic.load memarg","i32.atomic.load8_u memarg","i32.atomic.load16_u memarg","i64.atomic.load8_u memarg","i64.atomic.load16_u memarg","i64.atomic.load32_u memarg","i32.atomic.store memarg","i64.atomic.store memarg","i32.atomic.store8 memarg","i32.atomic.store16 memarg","i64.atomic.store8 memarg","i64.atomic.store16 memarg","i64.atomic.store32 memarg","i32.atomic.rmw.add memarg","i64.atomic.rmw.add memarg","i32.atomic.rmw8.add_u memarg","i32.atomic.rmw16.add_u memarg","i64.atomic.rmw8.add_u memarg","i64.atomic.rmw16.add_u memarg","i64.atomic.rmw32.add_u memarg","i32.atomic.rmw.sub memarg","i64.atomic.rmw.sub memarg","i32.atomic.rmw8.sub_u memarg","i32.atomic.rmw16.sub_u memarg","i64.atomic.rmw8.sub_u memarg","i64.atomic.rmw16.sub_u memarg","i64.atomic.rmw32.sub_u memarg","i32.atomic.rmw.and memarg","i64.atomic.rmw.and memarg","i32.atomic.rmw8.and_u memarg","i32.atomic.rmw16.and_u memarg","i64.atomic.rmw8.and_u memarg","i64.atomic.rmw16.and_u memarg","i64.atomic.rmw32.and_u memarg","i32.atomic.rmw.or memarg","i64.atomic.rmw.or memarg","i32.atomic.rmw8.or_u memarg","i32.atomic.rmw16.or_u memarg","i64.atomic.rmw8.or_u memarg","i64.atomic.rmw16.or_u memarg","i64.atomic.rmw32.or_u memarg","i32.atomic.rmw.xor memarg","i64.atomic.rmw.xor memarg","i32.atomic.rmw8.xor_u memarg","i32.atomic.rmw16.xor_u memarg","i64.atomic.rmw8.xor_u memarg","i64.atomic.rmw16.xor_u memarg","i64.atomic.rmw32.xor_u memarg","i32.atomic.rmw.xchg memarg","i64.atomic.rmw.xchg memarg","i32.atomic.rmw8.xchg_u memarg","i32.atomic.rmw16.xchg_u memarg","i64.atomic.rmw8.xchg_u memarg","i64.atomic.rmw16.xchg_u memarg","i64.atomic.rmw32.xchg_u memarg","i32.atomic.rmw.cmpxchg memarg","i64.atomic.rmw.cmpxchg memarg","i32.atomic.rmw8.cmpxchg_u memarg","i32.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw8.cmpxchg_u memarg","i64.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw32.cmpxchg_u memarg"]],U={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},F={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},Q={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},Ut={func:0,table:1,memory:2,global:3,tag:4};var V=t=>{let e=0,r=[],s="",i=0,n=0,l=()=>s&&(r.push(s),s=""),a=o=>{r.loc=o;for(let f,c,m;e<t.length;)if(f=t.charCodeAt(e),i===34)s+=t[e++],f===92?s+=t[e++]:f===34&&(l(),i=0);else if(i>59)f===40&&t.charCodeAt(e+1)===59?(i++,s+=t[e++]+t[e++]):f===59&&t.charCodeAt(e+1)===41?(s+=t[e++]+t[e++],--i===59&&(l(),i=0)):s+=t[e++];else if(i<0)f===10||f===13?(s+=t[e++],l(),i=0):i===-2&&f===41?(l(),i=0):s+=t[e++];else if(f===34)s!=="$"&&l(),i=34,s+=t[e++];else if(f===40&&t.charCodeAt(e+1)===59)l(),i=60,s=t[e++]+t[e++];else if(f===59&&t.charCodeAt(e+1)===59)l(),i=t.indexOf(`
|
|
3
|
+
`,e)<0?-2:-1,s=t[e++]+t[e++];else if(f===40&&t.charCodeAt(e+1)===64)l(),m=e,e+=2,s="@",n++,(c=r).push(r=[]),a(m),r=c;else if(f===40)l(),m=e++,n++,(c=r).push(r=[]),a(m),r=c;else{if(f===41)return l(),e++,n--;f<=32?(l(),e++):s+=t[e++]}i<0&&l(),l()};return a(0),i===34&&k("Unclosed quote",e),i>59&&k("Unclosed block comment",e),n>0&&k("Unclosed parenthesis",e),e<t.length&&k("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var Zt=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(Zt).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("\\")?"$"+Ht(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?pt(t):t;function at(t){typeof t=="string"?(k.src=t,t=V(t)||[]):k.src="",k.loc=0,t=Zt(t)||[];let e=0;if(t[0]==="module"?(e++,W(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return at(t.slice(++e).map(m=>m.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((m,_)=>{if(_<e||!Array.isArray(m)||m[0]!=="import")return[m];let[,u,...d]=m;if(!d.some(g=>Array.isArray(g)&&g[0]==="item"))return[m];if(Array.isArray(d.at(-1))&&d.at(-1)[0]!=="item"){let g=d.at(-1);return d.slice(0,-1).filter(w=>w[0]==="item").map(([,w])=>["import",u,w,g])}return d.filter(g=>g[0]==="item").map(([,g,w])=>["import",u,g,w])});let r=[];for(let m in U)(r[U[m]]=r[m]=[]).name=m;r.metadata={},t.slice(e).filter(m=>{if(!Array.isArray(m)){let d=k.loc,y=k.src,g;for(;(d=y.indexOf(m,d))>=0;){if(g=y.charCodeAt(d-1),d>0&&(g>47&&g<58||g>64&&g<91||g>96&&g<123||g===95||g===36)){d++;continue}if(g=y.charCodeAt(d+m.length),g>47&&g<58||g>64&&g<91||g>96&&g<123||g===95){d++;continue}break}d>=0&&(k.loc=d),k(`Unexpected token ${m}`)}let[_,...u]=m;if(k.loc=m.loc,_==="@custom")r.custom.push(u);else if(_==="rec")for(let d=0;d<u.length;d++){let[,...y]=u[d];Ot(y,r.type);let g=[];for(;y[0]?.[0]==="descriptor"||y[0]?.[0]==="describes";)g.push(y.shift());(y=Xt(y,r)).push(d?!0:[r.type.length,u.length]),g.length&&(y.desc=y.desc?[...g,...y.desc]:g),r.type.push(y)}else if(_==="type"){Ot(u,r.type);let d=[];for(;u[0]?.[0]==="descriptor"||u[0]?.[0]==="describes";)d.push(u.shift());let y=Xt(u,r);d.length&&(y.desc=y.desc?[...d,...y.desc]:d),r.type.push(y)}else if(_==="start"||_==="export")r[_].push(u);else return!0}).forEach(m=>{let[_,...u]=m;k.loc=m.loc;let d;_==="import"&&([_,...u]=(d=u).pop());let y=r[_];for(y||k(`Unknown section ${_}`),Ot(u,y);u[0]?.[0]==="export";)r.export.push([u.shift()[1],[_,y?.length]]);if(u[0]?.[0]==="import"&&([,...d]=u.shift()),_==="table"){let g=u[0]==="i64",w=g?1:0;if(u[w+1]?.[0]==="elem"){let[v,[,...b]]=[u[w],u[w+1]];u=g?["i64",b.length,b.length,v]:[b.length,b.length,v],r.elem.push([["table",y.length],["offset",[g?"i64.const":"i32.const",g?0n:0]],v,...b])}}else if(_==="memory"){let g=u[0]==="i64",w=g?1:0;if(u[w]?.[0]==="data"){let v=u.find($=>Array.isArray($)&&$[0]==="pagesize")?.[1]??65536,[,...b]=u.splice(w,1)[0],z=""+Math.ceil(b.reduce(($,I)=>$+I.length,0)/v);r.data.push([["memory",y.length],[g?"i64.const":"i32.const",g?0n:0],...b]),u=g?["i64",z,z]:[z,z]}}else if(_==="func"){let[g,w,v]=$t(u,r);g??=wt(w,v,r),!d&&r.code.push([[g,w,v],...et(u,r)]),u=[["type",g]]}else if(_==="tag"){let[g,w]=$t(u,r);g??=wt(w,[],r),u=[["type",g]]}d&&(r.import.push([...d,[_,...u]]),u=null),y.push(u)});let s=(m,_=!0)=>{let u=r[m].filter(Boolean).map(d=>Jt[m](d,r)).filter(Boolean);return m===U.custom?u.flatMap(d=>[m,...E(d)]):u.length?[m,...E(_?E(u):u.flat())]:[]},i=()=>{let m=[];for(let _ in r.metadata){let u=E(pt(`"metadata.code.${_}"`)),d=E(r.metadata[_].map(([y,g])=>[...p(y),...E(g.map(([w,v])=>[...p(w),...E(v)]))]));m.push(0,...E([...u,...d]))}return m},n=s(U.global),l=s(U.elem),a=s(U.code),o=i(),f=s(U.data),c=r.strings.length?[U.strings,...E([0,...E(r.strings.map(m=>E(m)))])]:[];return Uint8Array.from([0,97,115,109,1,0,0,0,...s(U.custom),...s(U.type),...s(U.import),...s(U.func),...s(U.table),...s(U.memory),...s(U.tag),...c,...n,...s(U.export),...s(U.start,!1),...l,...s(U.datacount,!1),...a,...o,...f])}var H=t=>t?.[0]==="$"||!isNaN(t),W=t=>t?.[0]==="$",Ft=t=>t?.[0]==="a"||t?.[0]==="o";function et(t,e){let r=[];for(t=[...t];t.length;){let s=t.shift();if(typeof s=="string")if(r.push(s),s==="block"||s==="if"||s==="loop")W(t[0])&&r.push(t.shift()),r.push(ht(t,e));else if(s==="else"||s==="end")W(t[0])&&t.shift();else if(s==="select")r.push(vt(t)[1]);else if(s.endsWith("call_indirect")){let i=H(t[0])?t.shift():0,[n,l,a]=$t(t,e);r.push(i,["type",n??wt(l,a,e)])}else s==="table.init"?r.push(H(t[1])?t.shift():0,t.shift()):s==="table.copy"||s==="memory.copy"?r.push(H(t[0])?t.shift():0,H(t[0])?t.shift():0):s.startsWith("table.")?r.push(H(t[0])?t.shift():0):s==="memory.init"?(r.push(...H(t[1])?[t.shift(),t.shift()].reverse():[t.shift(),0]),e.datacount&&(e.datacount[0]=!0)):s==="data.drop"||s==="array.new_data"||s==="array.init_data"?(s==="data.drop"&&r.push(t.shift()),e.datacount&&(e.datacount[0]=!0)):(s.startsWith("memory.")||s.endsWith("load")||s.endsWith("store"))&&H(t[0])&&r.push(t.shift());else if(Array.isArray(s)){let i=s[0];if(s.loc!=null&&(k.loc=s.loc),i?.startsWith?.("@metadata.code.")){let l=i.slice(15);r.push(["@metadata",l,s[1]]);continue}if(typeof i!="string"||!Array.isArray(mt[i])){r.push(s);continue}let n=s.slice(1);if(i==="block"||i==="loop")r.push(i),W(n[0])&&r.push(n.shift()),r.push(ht(n,e),...et(n,e),"end");else if(i==="if"){let l=[],a=[];n.at(-1)?.[0]==="else"&&(a=et(n.pop().slice(1),e)),n.at(-1)?.[0]==="then"&&(l=et(n.pop().slice(1),e));let o=[i];W(n[0])&&o.push(n.shift()),o.push(ht(n,e)),r.push(...et(n,e),...o,...l),a.length&&r.push("else",...a),r.push("end")}else if(i==="try_table"){for(r.push(i),W(n[0])&&r.push(n.shift()),r.push(ht(n,e));n[0]?.[0]==="catch"||n[0]?.[0]==="catch_ref"||n[0]?.[0]==="catch_all"||n[0]?.[0]==="catch_all_ref";)r.push(n.shift());r.push(...et(n,e),"end")}else{let l=[];for(;n.length&&(!Array.isArray(n[0])||n[0].valueOf!==Array.prototype.valueOf||"type,param,result,ref,exact,on".includes(n[0][0]));)l.push(n.shift());r.push(...et(n,e),i,...l),t.unshift(...r.splice(r.length-1-l.length))}}else r.push(s)}return r}var wt=(t,e,r,s="$"+t+">"+e)=>(r.type[s]??=r.type.push(["func",[t,e]])-1,s),Ct=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...s]=t.shift(),i=W(s[0])&&s.shift();i&&(i in r?(()=>{throw Error(`Duplicate ${e} ${i}`)})():r[i]=r.length),r.push(...s)}return r},vt=t=>{let e=Ct(t,"param"),r=Ct(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},$t=(t,e)=>{if(t[0]?.[0]!=="type")return[,...vt(t)];let[,r]=t.shift(),[s,i]=vt(t),n=e.type[typeof r=="string"&&isNaN(r)?e.type[r]:+r];if(!n)throw Error(`Unknown type ${r}`);if((s.length||i.length)&&n[1].join(">")!==s+">"+i)throw Error(`Type ${r} mismatch`);return[r,...n[1]]},ht=(t,e)=>{let[r,s,i]=$t(t,e);if(!(!s.length&&!i.length))return!s.length&&i.length===1?["result",...i]:["type",r??wt(s,i,e)]},Ot=(t,e)=>{let r=W(t[0])&&t.shift();return r&&(r in e?k(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},Xt=([t],e)=>{let r="subfinal",s=[],i,n=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(s=t).pop(),s=s.filter(a=>Array.isArray(a)&&(a[0]==="descriptor"||a[0]==="describes")?(n.push(a),!1):!0)),[i,...t]=t,i==="func"?(t=vt(t),e.type["$"+t.join(">")]??=e.type.length):i==="struct"?t=Ct(t,"field"):i==="array"&&([t]=t);let l=[i,t,r,s];return n.length&&(l.desc=n),l},Jt=[([t,...e],r)=>{let s=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(s=e.slice(1)),[...E(t),...s.flat()]},(t,e)=>{let[r,s,i,n,l]=t;if(l===!0)return;let a=(t.desc??[]).flatMap(([f,c])=>[f==="descriptor"?77:76,...p(A(c,e.type))]),o=(f,c)=>f==="func"?[Q.func,...E(c[0].map(m=>j(m,e))),...E(c[1].map(m=>j(m,e)))]:f==="array"?[Q.array,...xt(c,e)]:f==="struct"?[Q.struct,...E(c.map(m=>xt(m,e)))]:f==="cont"?[Q.cont,...p(A(c[0]??c,e.type))]:[Q[f]];if(l){let[f,c]=l,m=Array.from({length:c},(_,u)=>{let d=e.type[f+u],y=d.slice(0,4);return d.desc&&(y.desc=d.desc),Jt[U.type](y,e)});return[Q.rec,...E(m)]}else if(i==="sub"||n?.length)return[Q[i],...E(n.map(f=>A(f,e.type))),...a,...o(r,s)];return[...a,...o(r,s)]},([t,e,[r,...s]],i)=>{let n,l=Ut[r];if(r==="func"){s[0]==="exact"&&s.shift()&&(l=32);let[[,o]]=s;n=p(A(o,i.type))}else if(r==="tag"){let[[,a]]=s;n=[0,...p(A(a,i.type))]}else r==="memory"?n=dt(s):r==="global"?n=xt(s[0],i):r==="table"?n=[...j(s.pop(),i),...dt(s)]:k(`Unknown kind ${r}`);return[...E(t),...E(e),l,...n]},([[,t]],e)=>p(A(t,e.type)),(t,e)=>{let r=dt(t),s=j(t.shift(),e),[i]=t;return i?[64,0,...s,...r,...lt(i,e)]:[...s,...r]},(t,e)=>dt(t),([t,e],r)=>[...xt(t,r),...lt(e,r)],([t,[e,r]],s)=>[...E(t),Ut[e],...p(A(r,s[e]))],([t],e)=>p(A(t,e.func)),(t,e)=>{let r=0,s=0,i=0,n=0,l,a,o;t[0]==="declare"&&(t.shift(),s=1),t[0]?.[0]==="table"?([,l]=t.shift(),l=A(l,e.table)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&t[1][0]!=="item"&&!t[1][0]?.startsWith("ref"))&&(l=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=lt(a,e)):s||(r=1),F[t[0]]||t[0]?.[0]==="ref"?o=j(t.shift(),e):t[0]==="func"?o=[F[t.shift()]]:o=[F.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"&&(i=1),c)),o[0]!==F.funcref&&(n=1,i=1);let f=i<<2|(r||s?s:!!l||n)<<1|(r||s);return[f,...f===0?a:f===1?[0]:f===2?[...p(l||0),...a,0]:f===3?[0]:f===4?a:f===5?o:f===6?[...p(l||0),...a,...o]:o,...E(t.map(i?c=>lt(typeof c=="string"?["ref.func",c]:c,e):c=>p(A(c,e.func))))]},(t,e)=>{let[r,s]=t.shift();s||([,[s]]=e.type[A(r,e.type)]),e.local=Object.create(s),e.block=[],e.local.name="local",e.block.name="block",e._codeIdx===void 0&&(e._codeIdx=0);let i=e._codeIdx++;for(;t[0]?.[0]==="local";){let[,...o]=t.shift();if(W(o[0])){let f=o.shift();f in e.local?k(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...o)}e.meta={};let n=te(t,e),l=e.import.filter(o=>o[2][0]==="func").length+i;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([l,e.meta[o]]);let a=e.local.slice(s.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,E([...E(a.map(([o,f])=>[...p(o),...j(f,e)])),...n])},(t,e)=>{let r,s=0;return t[0]?.[0]==="memory"?([,s]=t.shift(),s=A(s,e.memory)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&typeof t[1][0]=="string")&&(s=A(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??k("Bad offset",r)),[...s?[2,...p(s),...lt(r,e)]:r?[0,...lt(r,e)]:[1],...E(t.flatMap(i=>Oe(i)??[...i]))]},(t,e)=>p(e.data.length),([[,t]],e)=>[0,...p(A(t,e.type))]],j=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[F.refnull,98,...p(A(t[2][1],e.type))]:F[t[2]]?[F[t[2]]]:[F.refnull,...p(A(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[F.ref,98,...p(A(t[1][1],e.type))]:[F.ref,...p(F[t[t.length-1]]||A(t[t.length-1],e.type))]:[F[t]??k(`Unknown type ${t}`)],xt=(t,e,r=t[0]==="mut"?1:0)=>[...j(r?t[1]:t,e),r],Qt={null:()=>[],reversed:(t,e)=>{let r=t.shift(),s=t.shift();return[...p(A(s,e.elem)),...p(A(r,e.table))]},block:(t,e)=>{e.block.push(1),W(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?j(r[1],e):p(A(r[1],e.type)):[F.void]},try_table:(t,e)=>{W(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),s=r?r[0]==="result"?j(r[1],e):p(A(r[1],e.type)):[F.void],i=[],n=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let l=t.shift(),a=l[0]==="catch"?0:l[0]==="catch_ref"?1:l[0]==="catch_all"?2:3;a<=1?i.push(a,...p(A(l[1],e.tag)),...p(tt(l[2],e.block))):i.push(a,...p(tt(l[1],e.block))),n++}return e.block.push(1),[...s,...p(n),...i]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,s]=t.shift();return[...p(A(s,e.type)),...p(A(r,e.table))]},br_table:(t,e)=>{let r=[],s=0;for(;t[0]&&(!isNaN(t[0])||W(t[0]));)r.push(...p(tt(t.shift(),e.block))),s++;return[...p(s-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?E(r.map(s=>j(s,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...p(A(r[1],e.type))]:F[r]?[F[r]]:p(A(r,e.type))},memarg:(t,e,r)=>Kt(t,r,H(t[0])&&!Ft(t[0])?A(t.shift(),e.memory):0),opt_memory:(t,e)=>p(A(H(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=j(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=tt(t.shift(),e.block),s=j(t.shift(),e),i=j(t.shift(),e),n=l=>l.length>1?l.slice(1):l;return[(i[0]!==F.ref)<<1|s[0]!==F.ref,...p(r),...n(s),...n(i)]},v128const:t=>{let[e,r]=t.shift().split("x"),s=+e.slice(1),i=s>>>3;if(r=+r,e[0]==="i"){let l=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let a=0;a<r;a++)l[a]=gt[e].parse(t.shift());return[...new Uint8Array(l.buffer)]}let n=new Uint8Array(16);for(let l=0;l<r;l++)n.set(gt[e](t.shift()),l*i);return[...n]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(bt(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&k("invalid lane length"),e},memlane:(t,e,r)=>{let s=W(t[0])||H(t[0])&&(Ft(t[1])||H(t[1]))?A(t.shift(),e.memory):0;return[...Kt(t,r,s),...p(bt(t.shift()))]},"*":t=>p(t.shift()),labelidx:(t,e)=>p(tt(t.shift(),e.block)),laneidx:t=>[bt(t.shift(),255)],funcidx:(t,e)=>p(A(t.shift(),e.func)),typeidx:(t,e)=>p(A(t.shift(),e.type)),tableidx:(t,e)=>p(A(t.shift(),e.table)),memoryidx:(t,e)=>p(A(t.shift(),e.memory)),globalidx:(t,e)=>p(A(t.shift(),e.global)),localidx:(t,e)=>p(A(t.shift(),e.local)),dataidx:(t,e)=>p(A(t.shift(),e.data)),elemidx:(t,e)=>p(A(t.shift(),e.elem)),tagidx:(t,e)=>p(A(t.shift(),e.tag)),"memoryidx?":(t,e)=>p(A(H(t[0])?t.shift():0,e.memory)),stringidx:(t,e)=>{let r=t.shift(),s=r.valueOf(),i=e.strings.findIndex(n=>n.valueOf()===s);return i<0&&(i=e.strings.push(r)-1),p(i)},i32:t=>R(t.shift()),i64:t=>st(t.shift()),f32:t=>nt(t.shift()),f64:t=>it(t.shift()),v128:t=>qt(t.shift()),typeidx_field:(t,e)=>{let r=A(t.shift(),e.type);return[...p(r),...p(A(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...p(A(t.shift(),e.type)),...p(t.shift())],typeidx_dataidx:(t,e)=>[...p(A(t.shift(),e.type)),...p(A(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...p(A(t.shift(),e.type)),...p(A(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...p(A(t.shift(),e.type)),...p(A(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...p(A(t.shift(),e.data)),...p(A(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...p(A(t.shift(),e.memory)),...p(A(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...p(A(t.shift(),e.table)),...p(A(t.shift(),e.table))],cont_bind:(t,e)=>[...p(A(t.shift(),e.type)),...p(A(t.shift(),e.type))],switch_cont:(t,e)=>[...p(A(t.shift(),e.type)),...p(A(t.shift(),e.tag))],resume:(t,e)=>{let r=p(A(t.shift(),e.type)),s=[],i=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?s.push(1,...p(A(n,e.tag))):s.push(0,...p(A(n,e.tag)),...p(tt(l,e.block))),i++}return[...r,...p(i),...s]},resume_throw:(t,e)=>{let r=p(A(t.shift(),e.type)),s=p(A(t.shift(),e.tag)),i=[],n=0;for(;t[0]?.[0]==="on";){let[,l,a]=t.shift();a==="switch"?i.push(1,...p(A(l,e.tag))):i.push(0,...p(A(l,e.tag)),...p(tt(a,e.block))),n++}return[...r,...s,...p(n),...i]},resume_throw_ref:(t,e)=>{let r=p(A(t.shift(),e.type)),s=[],i=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?s.push(1,...p(A(n,e.tag))):s.push(0,...p(A(n,e.tag)),...p(tt(l,e.block))),i++}return[...r,...p(i),...s]}},At={};(function t(e,r){for(let s=0,i,n,l;s<e.length;s++)(i=e[s])&&(Array.isArray(i)?t(i,s):([n,l]=i.split(" "),mt[n]=r?[r,...p(s)]:[s],l&&(At[n]=Qt[l])))})(mt);var te=(t,e)=>{let r=[],s=[];for(;t?.length;){let i=t.shift();if(i?.[0]==="@metadata"){s.push(i.slice(1));continue}Array.isArray(i)&&(i.loc!=null&&(k.loc=i.loc),k(`Unknown instruction ${i[0]}`));let[...n]=mt[i]||k(`Unknown instruction ${i}`);At[i]&&(i==="select"&&t[0]?.length?n[0]++:At[i]===Qt.reftype&&(t[0][1]==="null"||t[0][0]!=="ref")&&n[n.length-1]++,n.push(...At[i](t,e,i)));for(let[l,a]of s)(e.meta[l]??=[]).push([r.length,a]);r.push(...n)}return r.push(11),r},lt=(t,e)=>te(et([t],e),e),A=(t,e,r)=>(r=W(t)?e[t]:+t,r in e?r:k(`Unknown ${e.name} ${t}`)),tt=(t,e,r)=>(r=W(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?k(`Bad label ${t}`):r),qe=t=>{let e,r,s,i;for(;Ft(t[0]);)[s,i]=t.shift().split("="),s==="offset"?r=+i:s==="align"?e=+i:k(`Unknown param ${s}=${i}`);return(r<0||r>4294967295)&&k(`Bad offset ${r}`),(e<=0||e>4294967295)&&k(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&k(`Bad align ${e}`),[e,r]},Kt=(t,e,r=0)=>{let[s,i]=qe(t),n=(s??Ue(e))|(r&&64);return r?[...p(n),...p(r),...p(i??0)]:[...p(n),...p(i??0)]},Ue=t=>{let e=t.indexOf(".",3)+1,r=t.slice(1,t[0]==="v"?4:3);if(t[e]==="a"&&(e=t.indexOf(".",e)+1),t[0]==="m")return t.includes("64")?3:2;if(t[e]==="r"){let n=t.slice(e,e+6).match(/\d+/);return Math.log2(n?n[0]/8:+r/8)}let s=t[e]==="l"?e+4:e+5,i=t.slice(s).match(/(\d+)(x|_|$)/);return Math.log2(i?i[2]==="x"?8:i[1]/8:+r/8)},Oe=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 s=[],i=new DataView(new ArrayBuffer(8));for(let n of r)e==="i8"?s.push(R.parse(n)&511&255):e==="i16"?(i.setInt16(0,R.parse(n),!0),s.push(...new Uint8Array(i.buffer,0,2))):e==="i32"?(i.setInt32(0,R.parse(n),!0),s.push(...new Uint8Array(i.buffer,0,4))):e==="i64"?(i.setBigInt64(0,BigInt(n),!0),s.push(...new Uint8Array(i.buffer,0,8))):e==="f32"?s.push(...nt(n)):e==="f64"&&s.push(...it(n));return s},dt=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),s=t.findIndex(f=>Array.isArray(f)&&f[0]==="pagesize"),i=-1;s>=0&&(i=Math.log2(+t.splice(s,1)[0][1]));let n=!isNaN(parseInt(t[1])),l=(i>=0?8:0)|(e?4:0)|(r?2:0)|(n?1:0),a=e?f=>{if(typeof f=="bigint")return f;let c=typeof f=="string"?f.replaceAll("_",""):String(f);return BigInt(c)}:bt,o=i>=0?p(i):[];return n?[l,...p(a(t.shift())),...p(a(t.shift())),...o]:[l,...p(a(t.shift())),...o]},bt=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?R.parse(t):typeof t=="number"?t:k(`Bad int ${t}`);return r>e?k(`Value out of range ${t}`):r},E=t=>[...p(t.length),...t.flat()];function ee(t,e={}){typeof t=="string"&&(t=V(t));let{indent:r=" ",newline:s=`
|
|
4
|
+
`,comments:i=!0}=e;if(r||="",s||="",typeof t[0]=="string"&&t[0][0]!==";")return l(t);return t.filter(a=>i||!n(a)).map(a=>l(a)).join(s);function n(a){return typeof a=="string"&&a[1]===";"}function l(a,o=0){if(!Array.isArray(a))return a;let f=a[0];if(!f)return"";let c=!1;if(f==="try_table"){let u=1;for(typeof a[u]=="string"&&a[u][0]==="$"&&(f+=" "+a[u++]),Array.isArray(a[u])&&(a[u][0]==="result"||a[u][0]==="type")&&(f+=" "+l(a[u++],o));Array.isArray(a[u])&&/^catch/.test(a[u][0]);)f+=" "+l(a[u++],o).trim();for(;u<a.length;u++)f+=Array.isArray(a[u])?s+r.repeat(o+1)+l(a[u],o+1):" "+a[u];return`(${f+s+r.repeat(o)})`}let m=!!s&&a.length<4&&!a.some(u=>typeof u=="string"&&u[0]===";"&&u[1]===";"),_=r.repeat(o+1);for(let u=1;u<a.length;u++){let d=a[u].valueOf();if(typeof d=="string"&&d[1]===";"){if(!i)continue;if(d[0]===";")if(s)f+=s+_+d.trimEnd(),c=!0;else{let y=f[f.length-1];y&&y!==" "&&y!=="("&&(f+=" "),f+=d.trimEnd()+`
|
|
5
|
+
`}else{let y=f[f.length-1];y&&y!==" "&&y!=="("&&(f+=" "),f+=d.trimEnd()}}else if(Array.isArray(d))m&&(m=d.every(y=>!Array.isArray(y))),f+=s+_+l(d,o+1),c=!1;else if(a[0]==="data")m=!1,(s||f[f.length-1]!==")")&&(f+=s||" "),f+=_+d,c=!1;else{let y=f[f.length-1];c&&s?f+=s+_:y===`
|
|
6
|
+
`?f+="":(y&&y!==")"&&y!==" "||s||y===")")&&(f+=" "),f+=d,c=!1}}return m?`(${f.replaceAll(s+_+"("," (")})`:`(${f+s+r.repeat(o)})`}}var ie={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"]},Dt=Object.keys(ie),Fe=t=>{if(t===!0)return Object.fromEntries(Dt.map(e=>[e,!0]));if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return Object.fromEntries(Dt.map(r=>[r,e.has(r)||e.has("all")]))}return{...t}},L=(t,e,r,s)=>{if(e(t,r,s),Array.isArray(t))for(let i=0;i<t.length;i++)L(t[i],e,t,i)},K=(t,e,r,s)=>{if(Array.isArray(t))for(let i=0;i<t.length;i++)K(t[i],e,t,i);e(t,r,s)},Ce=t=>{let e=new Set;return L(t,r=>{if(typeof r=="string")for(let[s,i]of Object.entries(ie))i.some(n=>r===n||r.startsWith(n+" "))&&e.add(s)}),L(t,r=>{if(!(!Array.isArray(r)||r[0]!=="global"))for(let s of r)Array.isArray(s)&&(s[0]==="i32.add"||s[0]==="i32.sub"||s[0]==="i32.mul"||s[0]==="i64.add"||s[0]==="i64.sub"||s[0]==="i64.mul")&&L(s,i=>{Array.isArray(i)&&i[0]==="global.get"&&e.add("extended_const")})}),L(t,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let s=0;for(let i of r)Array.isArray(i)&&i[0]==="result"&&(s+=i.length-1);s>1&&e.add("multi_value")}),e},se=t=>Array.isArray(t)?t.map(se):t,ne=(t,e)=>{let r=[],s=t[0]==="module"?1:0;for(let i=s;i<t.length;i++)Array.isArray(t[i])&&t[i][0]===e&&r.push({node:t[i],idx:i});return r},It=(t,e,r)=>t.splice(e,0,r),De=0,Z=t=>`$__${t}${De++}`,Le=(t,e)=>{let r=new Set;if(L(t,f=>{Array.isArray(f)&&f[0]==="ref.func"&&r.add(f[1])}),!r.size)return t;let s=Z("fntbl"),i=[...r],n=Object.fromEntries(i.map((f,c)=>[f,c])),l=ne(t,"func"),a=l.length?l[0].idx:t[0]==="module"?1:0;It(t,a,["table",s,"funcref",["elem",...i]]);let o={};return L(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c)return;let m=[],_=[];for(let u of f){if(Array.isArray(u)&&u[0]==="param")for(let d=1;d<u.length;d++)u[d][0]!=="$"&&m.push(u[d]);if(Array.isArray(u)&&u[0]==="result")for(let d=1;d<u.length;d++)_.push(u[d])}o[c]={params:m,results:_}}),K(t,(f,c,m)=>{if(!(!Array.isArray(f)||!c)){if(f[0]==="ref.func"&&n[f[1]]!==void 0&&(c[m]=["i32.const",n[f[1]]]),f[0]==="call_ref"){let _=f[1],u=f.slice(2);c[m]=["call_indirect",s,["type",_],...u]}if(f[0]==="return_call_ref"){let _=f[1],u=f.slice(2);c[m]=["return_call_indirect",s,["type",_],...u]}}}),t},X={funcref:Le},We={"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)=>(K(t,(r,s,i)=>{if(!Array.isArray(r)||!s)return;let n=We[r[0]];if(!n)return;let[l,a]=n,o=r.slice(1);s[i]=[`${l}.shr_s`,[`${l}.shl`,...o,[`${l}.const`,a]],[`${l}.const`,a]]}),t);X.sign_ext=Pe;var re={"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}},Re=(t,e)=>{let r=new Set;if(L(t,i=>{Array.isArray(i)&&re[i[0]]&&r.add(i[0])}),!r.size)return t;let s={};for(let i of r){let{itype:n,ftype:l,signed:a,min:o,max:f}=re[i],c=Z(`trunc_${n}_${l}_${a?"s":"u"}`);s[i]=c;let m=`${n}.trunc_${l}_${a?"s":"u"}`,_=n==="i64"?0n:0,u=["func",c,["param","$v",l],["result",n],["if",["result",n],[`${l}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${n}.const`,_]],["else",["if",["result",n],[`${l}.lt`,["local.get","$v"],[`${l}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${n}.const`,o]],["else",["if",["result",n],[`${l}.gt`,["local.get","$v"],[`${l}.const`,typeof f=="bigint"?Number(f):f]],["then",[`${n}.const`,f]],["else",[m,["local.get","$v"]]]]]]]]];t.push(u)}return K(t,(i,n,l)=>{!Array.isArray(i)||!n||s[i[0]]&&(n[l]=["call",s[i[0]],...i.slice(1)])}),t};X.nontrapping=Re;var je=(t,e)=>{let r=new Set,s=new Set;L(t,l=>{if(Array.isArray(l)){if(l[0]==="memory.copy"){let a=typeof l[1]=="number"?l[1]:0,o=typeof l[2]=="number"?l[2]:0;r.add(`${a}_${o}`)}if(l[0]==="memory.fill"){let a=typeof l[1]=="number"?l[1]:0;s.add(a)}}});let i={},n={};for(let l of r){let[a,o]=l.split("_").map(Number),f=Z(`memcpy${l==="0_0"?"":"_"+l}`);i[l]=f;let c=a?["i32.store8",a]:["i32.store8"],m=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",f,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...m,["i32.add",["local.get","$src"],["local.get","$i"]]]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}for(let l of s){let a=Z(`memset${l===0?"":"_"+l}`);n[l]=a;let o=l?["i32.store8",l]:["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 K(t,(l,a,o)=>{if(!(!Array.isArray(l)||!a)){if(l[0]==="memory.copy"){let f=typeof l[1]=="number"?l[1]:0,c=typeof l[2]=="number"?l[2]:0,m=l.filter(_=>Array.isArray(_)||typeof _=="string"&&_[0]==="$");a[o]=["call",i[`${f}_${c}`],...m]}if(l[0]==="memory.fill"){let f=typeof l[1]=="number"?l[1]:0,c=l.filter(m=>Array.isArray(m)||typeof m=="string"&&m[0]==="$");a[o]=["call",n[f],...c]}}}),t};X.bulk_memory=je;var Ge=(t,e)=>{let r=!1;return L(t,s=>{Array.isArray(s)&&(s[0]==="return_call"||s[0]==="return_call_indirect")&&(r=!0)}),r&&K(t,(s,i,n)=>{!Array.isArray(s)||!i||(s[0]==="return_call"&&(i[n]=["return",["call",...s.slice(1)]]),s[0]==="return_call_indirect"&&(i[n]=["return",["call_indirect",...s.slice(1)]]))}),t};X.return_call=Ge;var Ve=(t,e)=>(K(t,(r,s,i)=>{if(!(!Array.isArray(r)||!s)&&(r[0]==="ref.i31"&&(s[i]=["i32.and",...r.slice(1),["i32.const",2147483647]]),r[0]==="i31.get_u"&&(s[i]=r.length>1?r[1]:["drop"]),r[0]==="i31.get_s")){let n=r.slice(1);s[i]=["i32.shr_s",["i32.shl",...n,["i32.const",1]],["i32.const",1]]}}),t);X.i31ref=Ve;var He=(t,e)=>{let r={};L(t,i=>{if(!Array.isArray(i)||i[0]!=="global")return;let n=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(n)for(let l=i.length-1;l>=0;l--){let a=i[l];if(Array.isArray(a)&&(a[0]==="i32.const"||a[0]==="i64.const"||a[0]==="f32.const"||a[0]==="f64.const")){r[n]={type:a[0].split(".")[0],value:a[1]};break}}});let s=i=>{if(!Array.isArray(i))return i;let n=i[0];if(n==="global.get"&&r[i[1]]){let l=r[i[1]];return[`${l.type}.const`,l.value]}if(n==="i32.add"||n==="i64.add"){let l=s(i[1]),a=s(i[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f+c]}}if(n==="i32.sub"||n==="i64.sub"){let l=s(i[1]),a=s(i[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f-c]}}if(n==="i32.mul"||n==="i64.mul"){let l=s(i[1]),a=s(i[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f*c]}}return i};return K(t,(i,n,l)=>{if(!(!Array.isArray(i)||i[0]!=="global"||!n)){for(let a=2;a<i.length;a++)if(Array.isArray(i[a])){let o=s(i[a]);o!==i[a]&&(i[a]=o)}}}),t};X.extended_const=He;var Ye=(t,e)=>{let r=new Map,s=[];if(L(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 m=1;m<c.length;m++)f.push(c[m]);f.length>1&&o&&r.set(o,f)}),!r.size)return t;let i=Math.max(...[...r.values()].map(a=>a.length)),n={};for(let[a,o]of r)for(let f=1;f<o.length;f++){let c=o[f];if(n[c]||(n[c]=[]),n[c].length<f){let m=Z(`ret_${c}_${n[c].length}`);n[c].push(m),s.push(["global",m,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let l=t[0]==="module"?1:0;for(let a of s.reverse())It(t,l,a);return K(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 m=r.get(c);for(let _=0;_<a.length;_++)if(Array.isArray(a[_])&&a[_][0]==="result"){a[_]=["result",m[0]];break}}),t};X.multi_value=Ye;var yt={i32:4,i64:8,f32:4,f64:8},Xe=(t,e)=>{let r=new Map,s=new Map,i=1;if(L(t,y=>{if(!Array.isArray(y)||y[0]!=="type")return;let g=typeof y[1]=="string"&&y[1][0]==="$"?y[1]:null;if(g){for(let w of y)if(Array.isArray(w)){if(w[0]==="struct"){let v=[];for(let b of w)if(Array.isArray(b)&&b[0]==="field"){let z=typeof b[1]=="string"&&b[1][0]==="$"?b[1]:null,$=z?b[2]:b[1],I=Array.isArray($)&&$[0]==="mut"?$[1]:$;v.push({name:z,type:I})}r.set(g,{kind:"struct",fields:v}),s.set(g,i++)}if(w[0]==="array"){let v=w[1],b=Array.isArray(v)&&v[0]==="mut"?v[1]:v;r.set(g,{kind:"array",elemType:b}),s.set(g,i++)}}}}),!r.size)return t;let n=ne(t,"memory").length>0,l=Z("alloc"),a=Z("heap_ptr"),o=t[0]==="module"?1:0;n||It(t,o,["memory",1]),It(t,o+1,["global",a,["mut","i32"],["i32.const",1024]]);let f=["func",l,["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=y=>{let g=4;for(let w of y.fields)g+=yt[w.type]||4;return g},m=(y,g)=>{let w=4;for(let v=0;v<g;v++)w+=yt[y.fields[v].type]||4;return w},_=(y,g)=>{for(let w=0;w<y.fields.length;w++)if(y.fields[w].name===g)return w;return-1},u=0,d=()=>`$__gc_tmp${u++}`;return L(t,y=>{if(!Array.isArray(y)||y[0]!=="func")return;let g=!1,w=!1,v=!1,b=!1;if(L(y,$=>{Array.isArray($)&&(($[0]==="struct.new"||$[0]==="struct.new_default")&&(g=!0),($[0]==="array.new"||$[0]==="array.new_default")&&(w=!0,v=!0,b=!0))}),!g&&!w)return;let z=1;for(let $=1;$<y.length;$++){let I=y[$];if(Array.isArray(I)&&(I[0]==="param"||I[0]==="result"||I[0]==="local"||I[0]==="export"||I[0]==="type"))z=$+1;else if(typeof I=="string"&&I[0]==="$")z=$+1;else if(!Array.isArray(I))z=$+1;else break}g&&y.splice(z++,0,["local","$__gc_ptr","i32"]),w&&y.splice(z++,0,["local","$__gc_aptr","i32"]),v&&y.splice(z++,0,["local","$__gc_alen","i32"]),b&&y.splice(z++,0,["local","$__gc_aidx","i32"])}),K(t,(y,g,w)=>{if(!(!Array.isArray(y)||!g)){if(y[0]==="struct.new"||y[0]==="struct.new_default"){let v=y[1],b=r.get(v);if(!b||b.kind!=="struct")return;let z=c(b),$=s.get(v),I=y.slice(2),q="$__gc_ptr",O=[["local.set",q,["call",l,["i32.const",z]]],["i32.store",["local.get",q],["i32.const",$]]];if(y[0]==="struct.new")for(let T=0;T<b.fields.length;T++){let x=b.fields[T],h=m(b,T),N=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store";O.push([N,["i32.add",["local.get",q],["i32.const",h]],I[T]||[`${x.type}.const`,0]])}else for(let T=0;T<b.fields.length;T++){let x=b.fields[T],h=m(b,T),N=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store",D=x.type==="i64"?["i64.const",0n]:x.type==="f32"?["f32.const",0]:x.type==="f64"?["f64.const",0]:["i32.const",0];O.push([N,["i32.add",["local.get",q],["i32.const",h]],D])}O.push(["local.get",q]),g[w]=["block",["result","i32"],...O]}if(y[0]==="struct.get"){let v=y[1],b=y[2],z=y[3],$=r.get(v);if(!$||$.kind!=="struct")return;let I=typeof b=="string"&&b[0]==="$"?_($,b):parseInt(b);if(I<0)return;let q=$.fields[I],O=m($,I),T=q.type==="i64"?"i64.load":q.type==="f32"?"f32.load":q.type==="f64"?"f64.load":"i32.load";g[w]=[T,["i32.add",z,["i32.const",O]]]}if(y[0]==="struct.set"){let v=y[1],b=y[2],z=y[3],$=y[4],I=r.get(v);if(!I||I.kind!=="struct")return;let q=typeof b=="string"&&b[0]==="$"?_(I,b):parseInt(b);if(q<0)return;let O=I.fields[q],T=m(I,q),x=O.type==="i64"?"i64.store":O.type==="f32"?"f32.store":O.type==="f64"?"f64.store":"i32.store";g[w]=[x,["i32.add",z,["i32.const",T]],$]}if(y[0]==="array.new"||y[0]==="array.new_default"){let v=y[1],b=r.get(v);if(!b||b.kind!=="array")return;let z=s.get(v),$=yt[b.elemType]||4,I=y[0]==="array.new"?y[2]:null,q=y[0]==="array.new"?y[3]:y[2],O="$__gc_aptr",T="$__gc_alen",x="$__gc_aidx",h=b.elemType==="i64"?"i64.store":b.elemType==="f32"?"f32.store":b.elemType==="f64"?"f64.store":"i32.store",N=[["local.set",T,q],["local.set",O,["call",l,["i32.add",["i32.const",8],["i32.mul",["local.get",T],["i32.const",$]]]]],["i32.store",["local.get",O],["i32.const",z]],["i32.store",["i32.add",["local.get",O],["i32.const",4]],["local.get",T]]];I&&N.push(["local.set",x,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",x],["local.get",T]]],[h,["i32.add",["i32.add",["local.get",O],["i32.const",8]],["i32.mul",["local.get",x],["i32.const",$]]],I],["local.set",x,["i32.add",["local.get",x],["i32.const",1]]],["br","$loop"]]]),N.push(["local.get",O]),g[w]=["block",["result","i32"],...N]}if(y[0]==="array.get"){let v=y[1],b=y[2],z=y[3],$=r.get(v);if(!$||$.kind!=="array")return;let I=yt[$.elemType]||4,q=$.elemType==="i64"?"i64.load":$.elemType==="f32"?"f32.load":$.elemType==="f64"?"f64.load":"i32.load";g[w]=[q,["i32.add",["i32.add",b,["i32.const",8]],["i32.mul",z,["i32.const",I]]]]}if(y[0]==="array.set"){let v=y[1],b=y[2],z=y[3],$=y[4],I=r.get(v);if(!I||I.kind!=="array")return;let q=yt[I.elemType]||4,O=I.elemType==="i64"?"i64.store":I.elemType==="f32"?"f32.store":I.elemType==="f64"?"f64.store":"i32.store";g[w]=[O,["i32.add",["i32.add",b,["i32.const",8]],["i32.mul",z,["i32.const",q]]],$]}if(y[0]==="array.len"){let v=y[1];g[w]=["i32.load",["i32.add",v,["i32.const",4]]]}}}),t};X.gc=Xe;var Ke=(t,e)=>{let r=new Map,s=1;return L(t,i=>{if(!Array.isArray(i)||i[0]!=="type")return;let n=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(n)for(let l of i)Array.isArray(l)&&(l[0]==="struct"||l[0]==="array")&&r.set(n,s++)}),r.size&&K(t,(i,n,l)=>{if(!(!Array.isArray(i)||!n)){if(i[0]==="ref.test"){let a=i[1],o=null;Array.isArray(a)&&a[0]==="ref"&&(o=a[1]==="null"?a[2]:a[1]);let f=i[2],c=r.get(o);c!==void 0&&(n[l]=["if",["result","i32"],["i32.eqz",f],["then",["i32.const",0]],["else",["i32.eq",["i32.load",f],["i32.const",c]]]])}if(i[0]==="ref.cast"){let a=i[1],o=null,f=!1;Array.isArray(a)&&a[0]==="ref"&&(a[1]==="null"?(f=!0,o=a[2]):o=a[1]);let c=i[2],m=r.get(o);if(m!==void 0){let _=Z("cast");f?n[l]=["block",["result","i32"],["local",_,"i32"],["local.set",_,c],["if",["i32.and",["i32.ne",["local.get",_],["i32.const",0]],["i32.ne",["i32.load",["local.get",_]],["i32.const",m]]],["then",["unreachable"]]],["local.get",_]]:n[l]=["block",["result","i32"],["local",_,"i32"],["local.set",_,c],["if",["i32.or",["i32.eqz",["local.get",_]],["i32.ne",["i32.load",["local.get",_]],["i32.const",m]]],["then",["unreachable"]]],["local.get",_]]}}if(i[0]==="br_on_cast"){let a=i[1],o=i[2],f=i[3],c=i[4],m=null;Array.isArray(f)&&f[0]==="ref"&&(m=f[1]==="null"?f[2]:f[1]);let _=r.get(m);if(_!==void 0){let u=Z("brcast");n[l]=["block",["result","i32"],["local",u,"i32"],["local.set",u,c],["br_if",a,["i32.and",["i32.ne",["local.get",u],["i32.const",0]],["i32.eq",["i32.load",["local.get",u]],["i32.const",_]]]],["local.get",u]]}}if(i[0]==="br_on_cast_fail"){let a=i[1],o=i[2],f=i[3],c=i[4],m=null;Array.isArray(f)&&f[0]==="ref"&&(m=f[1]==="null"?f[2]:f[1]);let _=r.get(m);if(_!==void 0){let u=Z("brfail");n[l]=["block",["result","i32"],["local",u,"i32"],["local.set",u,c],["br_if",a,["i32.or",["i32.eqz",["local.get",u]],["i32.ne",["i32.load",["local.get",u]],["i32.const",_]]]],["local.get",u]]}}}}),t};X.ref_cast=Ke;function kt(t,e=!0){typeof t=="string"&&(t=V(t)),t=se(t),e=Fe(e);let r=Ce(t),s={uid:0};for(let i of Dt)r.has(i)&&e[i]!==!1&&X[i]&&(t=X[i](t,s));return t}var Wt={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!0,vacuum:!0,peephole:!0,globals:!0,offset:!0,unbranch:!0,stripmut:!0,brif:!0,foldarms:!0,dedupe:!0,reorder:!0,dedupTypes:!0,packData:!0,minifyImports:!1},Lt=Object.keys(Wt),B=(t,e)=>{if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="bigint")return t===e;if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!B(t[r],e[r]))return!1;return!0},Ze=t=>{if(t===!0)return{...Wt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.size===1&&Lt.includes([...e][0])?Object.fromEntries(Lt.map(r=>[r,e.has(r)])):Object.fromEntries(Lt.map(r=>[r,e.has(r)||e.has("all")]))}return{...Wt,...t}},S=t=>Array.isArray(t)?t.map(S):t,P=(t,e,r,s)=>{if(e(t,r,s),Array.isArray(t))for(let i=0;i<t.length;i++)P(t[i],e,t,i)},C=(t,e,r,s)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++){let l=C(t[n],e,t,n);l!==void 0&&(t[n]=l)}let i=e(t,r,s);return i!==void 0?i:t},zt=t=>{let e=1;for(;e<t.length;){let i=t[e];if(Array.isArray(i)&&(i[0]==="then"||i[0]==="else"||i[0]==="result"||i[0]==="param")){e++;continue}break}let r=null,s=null;for(let i=e+1;i<t.length;i++){let n=t[i];Array.isArray(n)&&(n[0]==="then"?r=n:n[0]==="else"&&(s=n))}return{condIdx:e,cond:t[e],thenBranch:r,elseBranch:s}},Je=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,s=new Map,i=new Map,n=new Map,l=new Map,a=(x,h,N,D=!1)=>{let rt=typeof h[1]=="string"&&h[1][0]==="$",xe=rt?h[1]:N,de=!D&&h.some(Rt=>Array.isArray(Rt)&&Rt[0]==="export"),_t={node:h,idx:N,used:de,isImport:D};return x.set(xe,_t),rt&&x.set(N,_t),l.set(h,_t),_t},o=0,f=0,c=0,m=0,_=0,u=[],d=[],y=[],g=[];for(let x of t.slice(1)){if(!Array.isArray(x))continue;let h=x[0];if(h==="type")a(s,x,c++);else if(h==="func")a(e,x,o++);else if(h==="global")a(r,x,f++);else if(h==="table")a(i,x,m++);else if(h==="memory")a(n,x,_++);else if(h==="import")for(let N of x)Array.isArray(N)&&(N[0]==="func"?a(e,N,o++,!0):N[0]==="global"?a(r,N,f++,!0):N[0]==="table"?a(i,N,m++,!0):N[0]==="memory"&&a(n,N,_++,!0));else h==="export"?y.push(x):h==="start"?g.push(x):h==="elem"?u.push(x):h==="data"&&d.push(x)}let w=[],v=x=>{x&&!x.scanned&&w.push(x)},b=x=>{let h=e.get(x);h&&(h.used||(h.used=!0),v(h))},z=x=>{let h=r.get(x);h&&(h.used=!0)},$=x=>{let h=i.get(x);h&&(h.used=!0)},I=x=>{typeof x=="string"&&x[0]!=="$"&&(x=+x);let h=n.get(x);h&&(h.used=!0)},q=x=>{let h=s.get(x);h&&(h.used=!0)};for(let x of y)for(let h of x){if(!Array.isArray(h))continue;let[N,D]=h;N==="func"?b(D):N==="global"?z(D):N==="table"?$(D):N==="memory"&&I(D)}for(let x of g){let h=x[1];typeof h=="string"&&h[0]!=="$"&&(h=+h),b(h)}for(let x of u)P(x,h=>{Array.isArray(h)&&h[0]==="ref.func"?b(h[1]):typeof h=="string"&&h[0]==="$"&&b(h)});for(let x of d){let h=x[1];Array.isArray(h)&&h[0]==="memory"?I(h[1]):typeof h=="string"&&h[0]==="$"?I(h):Array.isArray(h)&&I(0)}for(let x of[e,r,i,n])for(let h of x.values())h.used&&v(h);if(!(y.length>0||g.length>0||u.length>0||w.length>0)){for(let x of[e,r,i,n])for(let h of x.values())h.used=!0;return t}for(;w.length;){let x=w.pop();x.scanned||(x.scanned=!0,!x.isImport&&P(x.node,h=>{if(!Array.isArray(h)){typeof h=="string"&&h[0]==="$"&&b(h);return}let[N,D]=h;if(N==="call"||N==="return_call"||N==="ref.func")b(D);else if(N==="global.get"||N==="global.set")z(D);else if(N==="type")q(D);else if(N==="call_indirect"||N==="return_call_indirect")for(let rt of h)typeof rt=="string"&&rt[0]==="$"&&$(rt);typeof N=="string"&&(N.startsWith("memory.")||N.includes(".load")||N.includes(".store"))&&I(0)}))}let T=["module"];for(let x of t.slice(1)){if(!Array.isArray(x)){T.push(x);continue}let h=x[0];if(h==="func"||h==="global"||h==="type")l.get(x)?.used&&T.push(x);else if(h==="import"){let N=!1;for(let D of x){if(!Array.isArray(D))continue;if(l.get(D)?.used){N=!0;break}}N&&T.push(x)}else T.push(x)}return T},le=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),ft=t=>(e,r)=>t(e,r)?1:0,Nt=t=>(e,r)=>t(e>>>0,r>>>0)?1:0,ot=t=>(e,r)=>t(e,r)?1:0,Mt=t=>(e,r)=>t(BigInt.asUintN(64,e),BigInt.asUintN(64,r))?1:0,Qe={"i32.add":[(t,e)=>t+e|0,"i32"],"i32.sub":[(t,e)=>t-e|0,"i32"],"i32.mul":[(t,e)=>Math.imul(t,e),"i32"],"i32.div_s":[(t,e)=>e!==0?t/e|0:null,"i32"],"i32.div_u":[(t,e)=>e!==0?(t>>>0)/(e>>>0)|0:null,"i32"],"i32.rem_s":[(t,e)=>e!==0?t%e|0:null,"i32"],"i32.rem_u":[(t,e)=>e!==0?(t>>>0)%(e>>>0)|0:null,"i32"],"i32.and":[(t,e)=>t&e,"i32"],"i32.or":[(t,e)=>t|e,"i32"],"i32.xor":[(t,e)=>t^e,"i32"],"i32.shl":[(t,e)=>t<<(e&31),"i32"],"i32.shr_s":[(t,e)=>t>>(e&31),"i32"],"i32.shr_u":[(t,e)=>t>>>(e&31),"i32"],"i32.rotl":[(t,e)=>(e&=31,t<<e|t>>>32-e|0),"i32"],"i32.rotr":[(t,e)=>(e&=31,t>>>e|t<<32-e|0),"i32"],"i32.eq":[ft((t,e)=>t===e),"i32"],"i32.ne":[ft((t,e)=>t!==e),"i32"],"i32.lt_s":[ft((t,e)=>t<e),"i32"],"i32.lt_u":[Nt((t,e)=>t<e),"i32"],"i32.gt_s":[ft((t,e)=>t>e),"i32"],"i32.gt_u":[Nt((t,e)=>t>e),"i32"],"i32.le_s":[ft((t,e)=>t<=e),"i32"],"i32.le_u":[Nt((t,e)=>t<=e),"i32"],"i32.ge_s":[ft((t,e)=>t>=e),"i32"],"i32.ge_u":[Nt((t,e)=>t>=e),"i32"],"i32.eqz":[t=>t===0?1:0,"i32"],"i32.clz":[t=>Math.clz32(t),"i32"],"i32.ctz":[t=>t===0?32:31-Math.clz32(t&-t),"i32"],"i32.popcnt":[t=>{let e=0;for(;t;)e+=t&1,t>>>=1;return e},"i32"],"i32.wrap_i64":[t=>Number(BigInt.asIntN(32,t)),"i32"],"i32.extend8_s":[t=>t<<24>>24,"i32"],"i32.extend16_s":[t=>t<<16>>16,"i32"],"i64.add":[(t,e)=>BigInt.asIntN(64,t+e),"i64"],"i64.sub":[(t,e)=>BigInt.asIntN(64,t-e),"i64"],"i64.mul":[(t,e)=>BigInt.asIntN(64,t*e),"i64"],"i64.div_s":[(t,e)=>e!==0n?BigInt.asIntN(64,t/e):null,"i64"],"i64.div_u":[(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)/BigInt.asUintN(64,e)):null,"i64"],"i64.rem_s":[(t,e)=>e!==0n?BigInt.asIntN(64,t%e):null,"i64"],"i64.rem_u":[(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)%BigInt.asUintN(64,e)):null,"i64"],"i64.and":[(t,e)=>BigInt.asIntN(64,t&e),"i64"],"i64.or":[(t,e)=>BigInt.asIntN(64,t|e),"i64"],"i64.xor":[(t,e)=>BigInt.asIntN(64,t^e),"i64"],"i64.shl":[(t,e)=>BigInt.asIntN(64,t<<(e&63n)),"i64"],"i64.shr_s":[(t,e)=>BigInt.asIntN(64,t>>(e&63n)),"i64"],"i64.shr_u":[(t,e)=>BigInt.asUintN(64,BigInt.asUintN(64,t)>>(e&63n)),"i64"],"i64.eq":[ot((t,e)=>t===e),"i32"],"i64.ne":[ot((t,e)=>t!==e),"i32"],"i64.lt_s":[ot((t,e)=>t<e),"i32"],"i64.lt_u":[Mt((t,e)=>t<e),"i32"],"i64.gt_s":[ot((t,e)=>t>e),"i32"],"i64.gt_u":[Mt((t,e)=>t>e),"i32"],"i64.le_s":[ot((t,e)=>t<=e),"i32"],"i64.le_u":[Mt((t,e)=>t<=e),"i32"],"i64.ge_s":[ot((t,e)=>t>=e),"i32"],"i64.ge_u":[Mt((t,e)=>t>=e),"i32"],"i64.eqz":[t=>t===0n?1:0,"i32"],"i64.extend_i32_s":[t=>BigInt(t),"i64"],"i64.extend_i32_u":[t=>BigInt(t>>>0),"i64"],"i64.extend8_s":[t=>BigInt.asIntN(64,BigInt.asIntN(8,t)),"i64"],"i64.extend16_s":[t=>BigInt.asIntN(64,BigInt.asIntN(16,t)),"i64"],"i64.extend32_s":[t=>BigInt.asIntN(64,BigInt.asIntN(32,t)),"i64"],"f32.add":[(t,e)=>Math.fround(t+e),"f32"],"f32.sub":[(t,e)=>Math.fround(t-e),"f32"],"f32.mul":[(t,e)=>Math.fround(t*e),"f32"],"f32.div":[(t,e)=>Math.fround(t/e),"f32"],"f32.neg":[t=>Math.fround(-t),"f32"],"f32.abs":[t=>Math.fround(Math.abs(t)),"f32"],"f32.sqrt":[t=>Math.fround(Math.sqrt(t)),"f32"],"f32.ceil":[t=>Math.fround(Math.ceil(t)),"f32"],"f32.floor":[t=>Math.fround(Math.floor(t)),"f32"],"f32.trunc":[t=>Math.fround(Math.trunc(t)),"f32"],"f32.nearest":[t=>Math.fround(le(t)),"f32"],"f64.add":[(t,e)=>t+e,"f64"],"f64.sub":[(t,e)=>t-e,"f64"],"f64.mul":[(t,e)=>t*e,"f64"],"f64.div":[(t,e)=>t/e,"f64"],"f64.neg":[t=>-t,"f64"],"f64.abs":[Math.abs,"f64"],"f64.sqrt":[Math.sqrt,"f64"],"f64.ceil":[Math.ceil,"f64"],"f64.floor":[Math.floor,"f64"],"f64.trunc":[Math.trunc,"f64"],"f64.nearest":[le,"f64"]},M=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},ae=(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,tr=t=>C(S(t),e=>{if(!Array.isArray(e))return;let r=Qe[e[0]];if(!r)return;let[s,i]=r;if(s.length===1&&e.length===2){let n=M(e[1]);if(!n)return;let l=s(n.value);return l===null?void 0:ae(i,l)}if(s.length===2&&e.length===3){let n=M(e[1]),l=M(e[2]);if(!n||!l)return;let a=s(n.value,l.value);return a===null?void 0:ae(i,a)}}),J=t=>(e,r)=>{let s=M(e),i=M(r);return s?.value===t?r:i?.value===t?e:null},Y=t=>(e,r)=>M(r)?.value===t?e:null,er={"i32.add":J(0),"i64.add":J(0n),"i32.sub":Y(0),"i64.sub":Y(0n),"i32.mul":J(1),"i64.mul":J(1n),"i32.div_s":Y(1),"i32.div_u":Y(1),"i64.div_s":Y(1n),"i64.div_u":Y(1n),"i32.and":J(-1),"i64.and":J(-1n),"i32.or":J(0),"i64.or":J(0n),"i32.xor":J(0),"i64.xor":J(0n),"i32.shl":Y(0),"i32.shr_s":Y(0),"i32.shr_u":Y(0),"i64.shl":Y(0n),"i64.shr_s":Y(0n),"i64.shr_u":Y(0n)},rr=t=>C(S(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let r=er[e[0]];if(!r)return;let s=r(e[1],e[2]);if(s!==null)return s}),ir=t=>C(S(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,s,i]=e;if(r==="i32.mul"){let n=M(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]]}let l=M(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]]}}if(r==="i64.mul"){let n=M(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]]}let l=M(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]]}}if(r==="i32.div_u"){let n=M(i);if(n&&n.value>0&&!(n.value&n.value-1)){let l=Math.log2(n.value);if(Number.isInteger(l))return["i32.shr_u",s,["i32.const",l]]}}if(r==="i64.div_u"){let n=M(i);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let l=BigInt(n.value.toString(2).length-1);return["i64.shr_u",s,["i64.const",l]]}}if(r==="i32.rem_u"){let n=M(i);if(n&&n.value>0&&!(n.value&n.value-1))return["i32.and",s,["i32.const",n.value-1]]}if(r==="i64.rem_u"){let n=M(i);if(n&&n.value>0n&&(n.value&n.value-1n)===0n)return["i64.and",s,["i64.const",n.value-1n]]}}),sr=t=>C(S(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let{cond:s,thenBranch:i,elseBranch:n}=zt(e),l=M(s);if(!l)return;let a=l.value!==0&&l.value!==0n?i:n;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 s=e[e.length-1],i=M(s);return i?i.value===0||i.value===0n?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let s=e[e.length-1],i=M(s);return i?i.value===0||i.value===0n?e[2]:e[1]:void 0}}),fe=new Set(["unreachable","return","br","br_table"]),nr=t=>{let e=S(t);return P(e,r=>{if(!Array.isArray(r))return;let s=r[0];if((s==="func"||s==="block"||s==="loop")&&oe(r),s==="if")for(let i=1;i<r.length;i++)Array.isArray(r[i])&&(r[i][0]==="then"||r[i][0]==="else")&&oe(r[i])}),e},oe=t=>{let e=!1,r=-1;for(let s=1;s<t.length;s++){let i=t[s];if(Array.isArray(i)){let n=i[0];if(n==="param"||n==="result"||n==="local"||n==="type"||n==="export")continue;e&&r===-1&&(r=s),fe.has(n)&&(e=!0,r=s+1)}else typeof i=="string"&&(e&&r===-1&&(r=s),fe.has(i)&&(e=!0,r=s+1))}r>0&&r<t.length&&t.splice(r)},lr=t=>{let e=S(t);return P(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let s=[],i=new Map,n=new Set;for(let l=1;l<r.length;l++){let a=r[l];Array.isArray(a)&&(a[0]==="local"&&(s.push({node:a,idx:l}),typeof a[1]=="string"&&a[1][0]==="$"&&i.set(a[1],a[2])),a[0]==="param"&&typeof a[1]=="string"&&a[1][0]==="$"&&(i.set(a[1],a[2]),n.add(a[1])))}P(r,l=>{if(!Array.isArray(l))return;let a=l[0];if(a==="local.get"||a==="local.set"||a==="local.tee"){let o=l[1];typeof o=="string"&&n.add(o)}});for(let l=s.length-1;l>=0;l--){let{idx:a,node:o}=s[l],f=typeof o[1]=="string"&&o[1][0]==="$"?o[1]:null;f&&!n.has(f)&&r.splice(a,1)}}),e},ar=new Set(["call","call_indirect","return_call","return_call_indirect","table.set","table.grow","table.fill","table.copy","table.init","struct.set","struct.new","array.set","array.new","array.new_fixed","array.new_data","array.new_elem","array.init_data","array.init_elem","ref.i31","global.set","local.set","local.tee","unreachable","return","br","br_if","br_table","br_on_null","br_on_non_null","br_on_cast","br_on_cast_fail","throw","rethrow","throw_ref","try_table","data.drop","elem.drop"]),fr=[".store","memory.",".atomic."],ct=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||ar.has(e))return!1;for(let r of fr)if(e.includes(r))return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!ct(t[r]))return!1;return!0},Bt=t=>{let e=new Map,r=s=>(e.has(s)||e.set(s,{gets:0,sets:0,tees:0}),e.get(s));return P(t,s=>{!Array.isArray(s)||s.length<2||typeof s[1]!="string"||(s[0]==="local.get"?r(s[1]).gets++:s[0]==="local.set"?r(s[1]).sets++:s[0]==="local.tee"&&r(s[1]).tees++)}),e},ye=t=>M(t.val)||t.pure&&t.singleUse,ce=(t,e)=>C(t,r=>{if(!Array.isArray(r)||r[0]!=="local.get"||r.length!==2)return;let s=typeof r[1]=="string"&&e.get(r[1]);if(s&&ye(s))return S(s.val)}),or=(t,e,r)=>{let s=!1,i=l=>r.get(l)||{gets:0,sets:0,tees:0},n=new Map;for(let l=1;l<t.length;l++){let a=t[l];if(!Array.isArray(a))continue;let o=a[0];if(!(o==="param"||o==="result"||o==="local"||o==="type"||o==="export")){if(o==="local.set"&&a.length===3&&typeof a[1]=="string"){ce(a[2],n);let f=i(a[1]);n.set(a[1],{val:a[2],pure:ct(a[2]),singleUse:f.gets<=1&&f.sets<=1&&f.tees===0});continue}if((o==="block"||o==="loop"||o==="if")&&n.clear(),o==="call"||o==="call_indirect"||o==="return_call"||o==="return_call_indirect")for(let[f,c]of n)M(c.val)||n.delete(f);if(o==="local.get"&&a.length===2&&typeof a[1]=="string"){let f=n.get(a[1]);if(f&&ye(f)){let c=S(f.val);a.length=0,a.push(...Array.isArray(c)?c:[c]),s=!0;continue}}if(o!=="block"&&o!=="loop"&&o!=="if"){let f=S(a);ce(a,n),B(f,a)||(s=!0)}}}return s},cr=(t,e,r)=>{let s=!1;for(let i=1;i<t.length-1;i++){let n=t[i],l=t[i+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let a=n[1];if(l[1]!==a||e.has(a))continue;let o=r.get(a)||{gets:0,sets:0,tees:0};if(o.sets!==1||o.gets!==1||o.tees!==0)continue;let f=S(n[2]);t.splice(i,2,...Array.isArray(f)?[f]:[f]),s=!0,i--}return s},ur=(t,e,r)=>{let s=!1;for(let i=1;i<t.length-1;i++){let n=t[i],l=t[i+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let a=n[1];if(l[1]!==a||e.has(a))continue;let o=r.get(a)||{gets:0,sets:0,tees:0};o.sets+o.gets+o.tees<=2||(t.splice(i,2,["local.tee",a,S(n[2])]),s=!0)}return s},mr=(t,e,r)=>{let s=!1,i=n=>r.get(n)||{gets:0,sets:0,tees:0};for(let n=t.length-1;n>=1;n--){let l=t[n];if(!Array.isArray(l))continue;let a=typeof l[1]=="string"?l[1]:null;if(!a||e.has(a))continue;let o=i(a);(l[0]==="local.set"&&o.gets===0&&o.tees===0&&ct(l[2])||l[0]==="local"&&a[0]==="$"&&o.gets===0&&o.sets===0&&o.tees===0)&&(t.splice(n,1),s=!0)}return s},yr=t=>{let e=S(t);return P(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let s=new Set;for(let i of r)Array.isArray(i)&&i[0]==="param"&&typeof i[1]=="string"&&s.add(i[1]);for(let i=0;i<4;i++){let n=!1;if(or(r,s,Bt(r))&&(n=!0),cr(r,s,Bt(r))&&(n=!0),ur(r,s,Bt(r))&&(n=!0),mr(r,s,Bt(r))&&(n=!0),!n)break}}),e},_r=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=new Map;for(let s of e.slice(1)){if(!Array.isArray(s)||s[0]!=="func")continue;let i=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(!i)continue;let n=[],l=[],a=!1,o=!1;for(let f=1;f<s.length;f++){let c=s[f];if(Array.isArray(c))if(c[0]==="param")if(typeof c[1]=="string"&&c[1][0]==="$")n.push({name:c[1],type:c[2]});else{n=null;break}else c[0]==="local"?a=!0:c[0]==="export"?o=!0:c[0]!=="result"&&c[0]!=="type"&&l.push(c)}if(n&&!a&&!o&&n.length<=4&&l.length===1){let f=new Set(n.map(_=>_.name)),c=!1,m=!1;P(l[0],_=>{Array.isArray(_)&&((_[0]==="local.set"||_[0]==="local.tee")&&f.has(_[1])&&(c=!0),(_[0]==="return"||_[0]==="return_call"||_[0]==="return_call_indirect")&&(m=!0))}),!c&&!m&&r.set(i,{body:l[0],params:n})}}return r.size===0||C(e,s=>{if(!Array.isArray(s)||s[0]!=="call")return;let i=s[1];if(!r.has(i))return;let{body:n,params:l}=r.get(i),a=s.slice(2);if(l.length===0)return S(n);let o=S(n);return C(o,f=>{if(!Array.isArray(f)||f[0]!=="local.get")return;let c=f[1],m=l.findIndex(_=>_.name===c);if(m!==-1&&a[m])return S(a[m])}),o}),e},pr=t=>C(S(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="nop")return["nop"];if(r==="drop"&&e.length===2&&ct(e[1]))return["nop"];if(r==="select"&&e.length>=4&&B(e[1],e[2]))return e[1];if(r==="if"){let{cond:s,thenBranch:i,elseBranch:n}=zt(e),l=!i||i.length<=1,a=!n||n.length<=1;if(l&&a)return ct(s)?["nop"]:["drop",s];if(n&&a&&!l)return e.filter(o=>o!==n)}if(r==="func"||r==="block"||r==="loop"||r==="then"||r==="else"){let s=[r];for(let i=1;i<e.length;i++){let n=e[i];if(n==="nop"||Array.isArray(n)&&n[0]==="nop")continue;let l=e[i+1],a=l==="drop"||Array.isArray(l)&&l[0]==="drop"&&l.length===1;if(Array.isArray(n)&&ct(n)&&a){i++;continue}s.push(n)}if(s.length!==e.length)return s}}),gr={"i32.sub":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.sub":(t,e)=>B(t,e)?["i64.const",0n]:null,"i32.xor":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.xor":(t,e)=>B(t,e)?["i64.const",0n]:null,"i32.and":(t,e)=>B(t,e)?t:null,"i64.and":(t,e)=>B(t,e)?t:null,"i32.or":(t,e)=>B(t,e)?t:null,"i64.or":(t,e)=>B(t,e)?t:null,"i32.eq":(t,e)=>B(t,e)?["i32.const",1]:null,"i64.eq":(t,e)=>B(t,e)?["i32.const",1]:null,"i32.ne":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.ne":(t,e)=>B(t,e)?["i32.const",0]:null,"i32.lt_s":(t,e)=>B(t,e)?["i32.const",0]:null,"i32.lt_u":(t,e)=>B(t,e)?["i32.const",0]:null,"i32.gt_s":(t,e)=>B(t,e)?["i32.const",0]:null,"i32.gt_u":(t,e)=>B(t,e)?["i32.const",0]:null,"i32.le_s":(t,e)=>B(t,e)?["i32.const",1]:null,"i32.le_u":(t,e)=>B(t,e)?["i32.const",1]:null,"i32.ge_s":(t,e)=>B(t,e)?["i32.const",1]:null,"i32.ge_u":(t,e)=>B(t,e)?["i32.const",1]:null,"i64.lt_s":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.lt_u":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.gt_s":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.gt_u":(t,e)=>B(t,e)?["i32.const",0]:null,"i64.le_s":(t,e)=>B(t,e)?["i32.const",1]:null,"i64.le_u":(t,e)=>B(t,e)?["i32.const",1]:null,"i64.ge_s":(t,e)=>B(t,e)?["i32.const",1]:null,"i64.ge_u":(t,e)=>B(t,e)?["i32.const",1]:null,"i32.mul":(t,e)=>{let r=M(t),s=M(e);return r?.value===0||s?.value===0?["i32.const",0]:null},"i64.mul":(t,e)=>{let r=M(t),s=M(e);return r?.value===0n||s?.value===0n?["i64.const",0n]:null},"i32.and":(t,e)=>{let r=M(t),s=M(e);return r?.value===0||s?.value===0?["i32.const",0]:null},"i64.and":(t,e)=>{let r=M(t),s=M(e);return r?.value===0n||s?.value===0n?["i64.const",0n]:null},"i32.or":(t,e)=>{let r=M(t),s=M(e);return r?.value===-1||s?.value===-1?["i32.const",-1]:null},"i64.or":(t,e)=>{let r=M(t),s=M(e);return r?.value===-1n||s?.value===-1n?["i64.const",-1n]:null},"local.set":(t,e)=>Array.isArray(e)&&e[0]==="local.get"&&e[1]===t?["nop"]:null},hr=t=>C(S(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let r=gr[e[0]];if(!r)return;let s=r(e[1],e[2]);if(s!==null)return s}),xr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=new Map,s=new Set;for(let i of e.slice(1)){if(!Array.isArray(i)||i[0]!=="global")continue;let n=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!n)continue;let l=typeof i[1]=="string"&&i[1][0]==="$",a=l?3:2,o=l?i[2]:i[1];if(Array.isArray(o)&&o[0]==="mut")continue;let f=i[a];M(f)&&r.set(n,f)}P(e,i=>{if(!Array.isArray(i)||i[0]!=="global.set")return;let n=i[1];typeof n=="string"&&n[0]==="$"&&s.add(n)});for(let i of s)r.delete(i);return r.size===0?e:C(e,i=>{if(!Array.isArray(i)||i[0]!=="global.get"||i.length!==2)return;let n=i[1];if(r.has(n))return S(r.get(n))})},dr=t=>C(S(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(typeof r!="string"||!r.endsWith("load")&&!r.endsWith("store"))return;let s=r.endsWith("store"),i=0,n=null,l=1;for(typeof e[1]=="string"&&(e[1][0]==="$"||!isNaN(e[1]))&&(n=e[1],l=2);l<e.length&&typeof e[l]=="string"&&(e[l].startsWith("offset=")||e[l].startsWith("align="));)e[l].startsWith("offset=")&&(i=+e[l].slice(7)),l++;let a=s?e.length-2:e.length-1,o=s?e.length-1:-1;if(a<l)return;let f=e[a];if(!Array.isArray(f)||f[0]!=="i32.add"||f.length!==3)return;let c=f[1],m=f[2],_=M(c),u=M(m),d=null,y=null;if(_&&_.type==="i32"?(y=_.value,d=m):u&&u.type==="i32"&&(y=u.value,d=c),d===null||y===null)return;let g=i+y,w=[r];n!==null&&w.push(n),w.push(`offset=${g}`);let v=null;for(let b=l;b<a;b++)typeof e[b]=="string"&&e[b].startsWith("align=")&&(v=e[b]);return v&&w.push(v),w.push(d),s&&w.push(e[o]),w}),Ar=t=>{let e=S(t);return P(e,r=>{if(!Array.isArray(r)||r[0]!=="block")return;let i=1,n=null;if(typeof r[1]=="string"&&r[1][0]==="$"&&(n=r[1],i=2),!n)return;let l=-1;for(let o=r.length-1;o>=i;o--){let f=r[o];if(!Array.isArray(f)){f!=="nop"&&f!=="end"&&(l=o);continue}let c=f[0];if(!(c==="param"||c==="result"||c==="local"||c==="type"||c==="export")){l=o;break}}if(l<0)return;let a=r[l];Array.isArray(a)&&a[0]==="br"&&a[1]===n&&r.splice(l,1)}),e},br=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=new Set;return P(e,s=>{Array.isArray(s)&&s[0]==="global.set"&&typeof s[1]=="string"&&r.add(s[1])}),C(e,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let i=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(!i||r.has(i))return;let n=typeof s[1]=="string"&&s[1][0]==="$",l=n?s[2]:s[1];if(Array.isArray(l)&&l[0]==="mut"){let a=[...s];return a[n?2:1]=l[1],a}})},wr=t=>C(S(t),e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{cond:r,thenBranch:s,elseBranch:i}=zt(e),n=!s||s.length<=1,l=!i||i.length<=1;if(!n&&l&&s.length===2){let a=s[1];if(Array.isArray(a)&&a[0]==="br"&&a.length===2)return["br_if",a[1],r]}if(n&&!l&&i.length===2){let a=i[1];if(Array.isArray(a)&&a[0]==="br"&&a.length===2)return["br_if",a[1],["i32.eqz",r]]}}),vr=t=>C(S(t),e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{thenBranch:r,elseBranch:s}=zt(e);if(!r||!s||r.length<=1||s.length<=1||!e.some(_=>Array.isArray(_)&&_[0]==="result"))return;let n=0,l=Math.min(r.length,s.length);for(let _=1;_<l&&B(r[r.length-_],s[s.length-_]);_++)n++;if(n===0)return;let a=r.slice(r.length-n),o=r.slice(0,r.length-n),f=s.slice(0,s.length-n),c=["block"];for(let _=1;_<e.length;_++){let u=e[_];if(Array.isArray(u)&&(u[0]==="then"||u[0]==="else"))break;Array.isArray(u)&&(u[0]==="result"||u[0]==="type")&&c.push(u)}let m=["if"];for(let _=1;_<e.length;_++){let u=e[_];if(Array.isArray(u)&&(u[0]==="then"||u[0]==="else"))break;Array.isArray(u)&&(u[0]==="result"||u[0]==="type")||m.push(u)}return m.push(o.length>1?o:["then"]),m.push(f.length>1?f:["else"]),c.push(m,...a),c}),_e=(t,e)=>{let r=[],s=[t];for(;s.length;){let i=s.pop();if(Array.isArray(i)){s.push("|");for(let n=i.length-1;n>=0;n--)s.push(i[n]);s.push("[")}else typeof i=="string"?r.push(e.has(i)?"$__L":i):typeof i=="bigint"?r.push(i.toString()+"n"):typeof i=="number"?r.push(i.toString()):i===null?r.push("null"):i===!0?r.push("t"):i===!1?r.push("f"):r.push(String(i))}return r.join(",")},$r=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=new Map,s=new Map;for(let i of e.slice(1)){if(!Array.isArray(i)||i[0]!=="func")continue;let n=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!n)continue;let l=new Set;typeof i[1]=="string"&&i[1][0]==="$"&&l.add(i[1]),P(i,o=>{if(!Array.isArray(o)||typeof o[1]!="string"||o[1][0]!=="$")return;let f=o[0];(f==="param"||f==="local"||f==="block"||f==="loop"||f==="if")&&l.add(o[1])});let a=_e(i,l);r.has(a)?s.set(n,r.get(a)):r.set(a,n)}return s.size===0||C(e,i=>{if(!Array.isArray(i))return;let n=i[0];if((n==="call"||n==="return_call")&&s.has(i[1]))return[n,s.get(i[1]),...i.slice(2)];if(n==="ref.func"&&s.has(i[1]))return["ref.func",s.get(i[1])];if(n==="elem"){let l=i[i.length-1];if(Array.isArray(l))return[...i.slice(0,-1),l.map(a=>s.get(a)||a)]}if(n==="call_indirect"&&i.length>=3){let l=i[1];if(typeof l=="string"&&s.has(l))return["call_indirect",s.get(l),...i.slice(2)]}}),e},Ir=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=new Map,s=new Map;for(let i of e.slice(1)){if(!Array.isArray(i)||i[0]!=="type")continue;let n=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!n)continue;let l=_e(i,new Set([n]));r.has(l)?s.set(n,r.get(l)):r.set(l,n)}if(s.size===0)return e;for(let i=e.length-1;i>=0;i--){let n=e[i];if(Array.isArray(n)&&n[0]==="type"){let l=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null;l&&s.has(l)&&e.splice(i,1)}}return C(e,i=>{if(!Array.isArray(i))return;let n=i[0];if(n==="func")for(let l=1;l<i.length;l++){let a=i[l];Array.isArray(a)&&a[0]==="type"&&typeof a[1]=="string"&&s.has(a[1])&&(i[l]=["type",s.get(a[1])])}if(n==="import")for(let l=1;l<i.length;l++){let a=i[l];if(Array.isArray(a))for(let o=1;o<a.length;o++){let f=a[o];Array.isArray(f)&&f[0]==="type"&&typeof f[1]=="string"&&s.has(f[1])&&(a[o]=["type",s.get(f[1])])}}if(n==="call_indirect"||n==="return_call_indirect"){if(typeof i[1]=="string"&&s.has(i[1]))return[n,s.get(i[1]),...i.slice(2)];if(Array.isArray(i[1])&&i[1][0]==="type"&&typeof i[1][1]=="string"&&s.has(i[1][1]))return[n,["type",s.get(i[1][1])],...i.slice(2)]}}),e},St=t=>{if(typeof t!="string"||t.length<2||t[0]!=='"')return new Uint8Array;let e=t.slice(1,-1),r=[];for(let s=0;s<e.length;s++)if(e[s]==="\\"){let i=e[++s];i==="x"||i==="X"?(r.push(parseInt(e.slice(s+1,s+3),16)),s+=2):/[0-9a-fA-F]/.test(i)&&/[0-9a-fA-F]/.test(e[s+1])?(r.push(parseInt(e.slice(s,s+2),16)),s++):i==="n"?r.push(10):i==="t"?r.push(9):i==="r"?r.push(13):i==="\\"?r.push(92):i==='"'?r.push(34):r.push(i.charCodeAt(0))}else r.push(e.charCodeAt(s));return new Uint8Array(r)},pe=t=>{let e='"';for(let r=0;r<t.length;r++){let s=t[r];s>=32&&s<127&&s!==34&&s!==92?e+=String.fromCharCode(s):e+="\\"+s.toString(16).padStart(2,"0")}return e+'"'},kr=t=>{let e=[];for(let s of t)if(typeof s=="string")e.push(...St(s));else if(Array.isArray(s)&&s[0]==="i8")for(let i=1;i<s.length;i++)e.push(Number(s[i])&255);else return t;let r=e.length;for(;r>0&&e[r-1]===0;)r--;return r===e.length?t:r===0?[]:[pe(new Uint8Array(e.slice(0,r)))]},Nr=t=>{let e=1;if(typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"){let s=t[e][1];e++;let i=t[e];return Array.isArray(i)&&(i[0]==="i32.const"||i[0]==="i64.const")?{memidx:s,offset:Number(i[1])}:null}let r=t[e];return Array.isArray(r)&&(r[0]==="i32.const"||r[0]==="i64.const")?{memidx:0,offset:Number(r[1])}:null},ue=t=>{let e=1;typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"&&e++,Array.isArray(t[e])&&typeof t[e][0]=="string"&&!t[e][0].startsWith('"')&&e++;let r=0;for(let s=e;s<t.length;s++){let i=t[s];if(typeof i=="string")r+=St(i).length;else if(Array.isArray(i)&&i[0]==="i8")r+=i.length-1;else return null}return r},Mr=(t,e)=>{let r=1;typeof t[r]=="string"&&t[r][0]==="$"&&r++,Array.isArray(t[r])&&t[r][0]==="memory"&&r++,Array.isArray(t[r])&&typeof t[r][0]=="string"&&!t[r][0].startsWith('"')&&r++;let s=1;typeof e[s]=="string"&&e[s][0]==="$"&&s++,Array.isArray(e[s])&&e[s][0]==="memory"&&s++,Array.isArray(e[s])&&typeof e[s][0]=="string"&&!e[s][0].startsWith('"')&&s++;let i=t.slice(r),n=e.slice(s);if(i.length===1&&n.length===1&&typeof i[0]=="string"&&typeof n[0]=="string"){let l=St(i[0]),a=St(n[0]),o=new Uint8Array(l.length+a.length);return o.set(l),o.set(a,l.length),t.length=r,t.push(pe(o)),!0}return t.length=r,t.push(...i,...n),!0},Br=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t);for(let i of e){if(!Array.isArray(i)||i[0]!=="data")continue;let n=1;typeof i[1]=="string"&&i[1][0]==="$"&&(n=2),n<i.length&&Array.isArray(i[n])&&typeof i[n][0]=="string"&&!i[n][0].startsWith('"')&&n++;let l=i.slice(n);if(l.length===0)continue;let a=kr(l);(a.length!==l.length||a.length>0&&a[0]!==l[0])&&(i.length=n,i.push(...a))}let r=[];for(let i=0;i<e.length;i++){let n=e[i];if(Array.isArray(n)&&n[0]==="data"){let l=Nr(n);if(l){let a=ue(n);a!==null&&r.push({...l,node:n,index:i,len:a})}}}r.sort((i,n)=>{let l=String(i.memidx),a=String(n.memidx);return l!==a?l.localeCompare(a):i.offset-n.offset});let s=new Set;for(let i=0;i<r.length-1;i++){let n=r[i],l=r[i+1];s.has(n.index)||String(n.memidx)!==String(l.memidx)||n.offset+n.len===l.offset&&Mr(n.node,l.node)&&(s.add(l.index),n.len=ue(n.node))}return s.size>0&&(e=e.filter((i,n)=>!s.has(n))),e},me=()=>{let t=new Map,e=0;return r=>{if(!t.has(r)){let s="",i=e++;do s=String.fromCharCode(97+i%26)+s,i=Math.floor(i/26)-1;while(i>=0);t.set(r,s||"a")}return t.get(r)}},Sr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=me(),s=me();for(let i of e)!Array.isArray(i)||i[0]!=="import"||(typeof i[1]=="string"&&i[1][0]==='"'&&(i[1]='"'+r(i[1].slice(1,-1))+'"'),typeof i[2]=="string"&&i[2][0]==='"'&&(i[2]='"'+s(i[2].slice(1,-1))+'"'));return e},zr=t=>{let e=!0;return P(t,r=>{if(!e||!Array.isArray(r))return;let s=r[0];if(s==="func"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if((s==="call"||s==="return_call"||s==="ref.func")&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(s==="start"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(s==="elem")for(let i of r){if(typeof i=="string"&&i[0]!=="$"&&/^\d/.test(i)){e=!1;break}if(Array.isArray(i)&&i[0]==="ref.func"&&(typeof i[1]!="string"||i[1][0]!=="$")){e=!1;break}}}),e},Tr=t=>{if(!Array.isArray(t)||t[0]!=="module"||!zr(t))return t;let e=S(t),r=new Map;P(e,l=>{Array.isArray(l)&&(l[0]==="call"||l[0]==="return_call")&&r.set(l[1],(r.get(l[1])||0)+1)});let s=[],i=[],n=[];for(let l of e.slice(1)){if(!Array.isArray(l)){n.push(l);continue}l[0]==="import"?s.push(l):l[0]==="func"?i.push(l):n.push(l)}return i.sort((l,a)=>(r.get(a[1])||0)-(r.get(l[1])||0)),["module",...s,...i,...n]};function Tt(t,e=!0){typeof t=="string"&&(t=V(t)),t=S(t),e=Ze(e);for(let r=0;r<6;r++){let s=t;if(e.stripmut&&(t=br(t)),e.globals&&(t=xr(t)),e.fold&&(t=tr(t)),e.identity&&(t=rr(t)),e.peephole&&(t=hr(t)),e.strength&&(t=ir(t)),e.branch&&(t=sr(t)),e.propagate&&(t=yr(t)),e.inline&&(t=_r(t)),e.offset&&(t=dr(t)),e.unbranch&&(t=Ar(t)),e.brif&&(t=wr(t)),e.foldarms&&(t=vr(t)),e.deadcode&&(t=nr(t)),e.vacuum&&(t=pr(t)),e.locals&&(t=lr(t)),e.dedupe&&(t=$r(t)),e.dedupTypes&&(t=Ir(t)),e.packData&&(t=Br(t)),e.reorder&&(t=Tr(t)),e.treeshake&&(t=Je(t)),e.minifyImports&&(t=Sr(t)),B(s,t))break}return t}var ge="\uE000",he=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},Er=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...s]=t;return he(r)?he(r):r==="local.get"&&e.locals?.[s[0]]?e.locals[s[0]]:r==="call"&&e.funcs?.[s[0]]?e.funcs[s[0]].result?.[0]:null};function Pt(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let s=Pt(t[r],e);s?._splice?(t.splice(r,1,...s),r+=s.length-1):t[r]=s}return t}function qr(t,e){let r=[],s=new Map;return Pt(t,i=>{if(!Array.isArray(i))return i;if(i[0]==="call"&&typeof i[1]=="function"){let n=i[1];if(!s.has(n)){let a=[];for(let c=2;c<i.length;c++){let m=Er(i[c]);m&&a.push(m)}let o=r.length,f=n.name||`$fn${o}`;s.set(n,{idx:o,name:f.startsWith("$")?f:"$"+f,params:a,fn:n}),r.push(s.get(n))}let l=s.get(n);i[1]=l.name}return i}),r}function Ur(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(s=>["param",s])]])}function Or(t,...e){let r={};if(!Array.isArray(t)&&e.length&&typeof e[e.length-1]=="object"&&e[e.length-1]!==null&&!e[e.length-1].byteLength&&(r=e.pop()),Array.isArray(t)&&t.raw){let s=t[0];for(let f=0;f<e.length;f++)s+=ge+t[f+1];let i=V(s),n=[],l=0;i=Pt(i,f=>{if(f===ge){let c=e[l++];if(typeof c=="function")return n.push(c),c;if(typeof c=="string"&&(c[0]==="("||/^\s*\(/.test(c))){let m=V(c);return Array.isArray(m)&&Array.isArray(m[0])&&(m._splice=!0),m}return c.byteLength!==void 0?[...c]:c}return f});let a=null;if(n.length){let f=qr(i,n);if(f.length){let c=Ur(f);i[0]==="module"?i.splice(1,0,...c):typeof i[0]=="string"?i=[...c,i]:i.unshift(...c),a={env:{}};for(let m of f)a.env[m.name.slice(1)]=m.fn}}r.polyfill&&(i=kt(i,r.polyfill)),r.optimize&&(i=Tt(i,r.optimize));let o=at(i);return a&&(o._imports=a),o}if(r.polyfill||r.optimize){let s=typeof t=="string"?V(t):t;return r.polyfill&&(s=kt(s,r.polyfill)),r.optimize&&(s=Tt(s,r.optimize)),at(s)}return at(t)}function Fr(t,...e){let r=Or(t,...e),s=new WebAssembly.Module(r);return new WebAssembly.Instance(s,r._imports).exports}var ai=Fr;export{Or as compile,ai as default,Tt as optimize,V as parse,kt as polyfill,ee as print,Fr as watr};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
_Light & fast WAT compiler_
|
|
5
5
|
|
|
6
|
-
* [feature](https://webassembly.org/features
|
|
6
|
+
* [feature](https://webassembly.org/features/?categories=browsers%2Cstandalones%2Ctools) & [spec](https://webassembly.github.io/spec/core/text/index.html)-complete, zero deps
|
|
7
7
|
* [compile](./docs.md#compilesource-options) · [polyfill](./docs.md#polyfillast-options) · [optimize](./docs.md#optimizeast-options) · [parse](./docs.md#parsesource-options) · [prettify](./docs.md#printtree-options) · [minify](./docs.md#printtree-options)
|
|
8
8
|
* instant wasm, JS interop, CLI, clear errors
|
|
9
9
|
|
|
@@ -56,11 +56,11 @@ npx watr input.wat --polyfill # newer features → MVP
|
|
|
56
56
|
|
|
57
57
|
## Metrics
|
|
58
58
|
|
|
59
|
-
* **watr** —
|
|
59
|
+
* **watr** — ~84 KB minified (~24 KB gzipped), 4,460 op/s
|
|
60
60
|
* [spec/wast.js](https://github.com/WebAssembly/spec) — 216 KB, 2,185 op/s
|
|
61
61
|
* [wabt](https://github.com/WebAssembly/wabt) — 282 KB, 1,273 op/s
|
|
62
62
|
* [binaryen](https://github.com/WebAssembly/binaryen) — 1,100 KB, 718 op/s
|
|
63
|
-
* [wat-compiler](https://github.com/stagas/wat-compiler) —
|
|
63
|
+
* [wat-compiler](https://github.com/stagas/wat-compiler) — ~152 KB (+ wabt dep), 539 op/s
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
## Used by
|
package/src/const.js
CHANGED
|
@@ -81,13 +81,28 @@ export const INSTR = [
|
|
|
81
81
|
'string.new_lossy_utf8_array', 'string.new_wtf8_array', 'string.encode_lossy_utf8_array', 'string.encode_wtf8_array'
|
|
82
82
|
],
|
|
83
83
|
|
|
84
|
-
// 0xfc: Bulk memory/table operations (nested array)
|
|
84
|
+
// 0xfc: Bulk memory/table operations + rounding mode control (nested array)
|
|
85
85
|
[
|
|
86
86
|
'i32.trunc_sat_f32_s', 'i32.trunc_sat_f32_u', 'i32.trunc_sat_f64_s', 'i32.trunc_sat_f64_u',
|
|
87
87
|
'i64.trunc_sat_f32_s', 'i64.trunc_sat_f32_u', 'i64.trunc_sat_f64_s', 'i64.trunc_sat_f64_u',
|
|
88
88
|
'memory.init dataidx_memoryidx', 'data.drop dataidx', 'memory.copy memoryidx_memoryidx', 'memory.fill memoryidx?',
|
|
89
89
|
'table.init reversed', 'elem.drop elemidx', 'table.copy tableidx_tableidx', 'table.grow tableidx', 'table.size tableidx', 'table.fill tableidx', ,
|
|
90
|
-
'i64.add128', 'i64.sub128', 'i64.mul_wide_s', 'i64.mul_wide_u'
|
|
90
|
+
'i64.add128', 'i64.sub128', 'i64.mul_wide_s', 'i64.mul_wide_u',
|
|
91
|
+
// 0x17-0x7F: padding (105 empty slots)
|
|
92
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
|
93
|
+
// 0x80-0xBB: rounding mode control
|
|
94
|
+
'f32.sqrt_ceil', 'f32.add_ceil', 'f32.sub_ceil', 'f32.mul_ceil', 'f32.div_ceil',
|
|
95
|
+
'f64.sqrt_ceil', 'f64.add_ceil', 'f64.sub_ceil', 'f64.mul_ceil', 'f64.div_ceil',
|
|
96
|
+
'f32.convert_ceil_i32_s', 'f32.convert_ceil_i32_u', 'f32.convert_ceil_i64_s', 'f32.convert_ceil_i64_u', 'f32.demote_ceil_f64',
|
|
97
|
+
'f64.convert_ceil_i32_s', 'f64.convert_ceil_i32_u', 'f64.convert_ceil_i64_s', 'f64.convert_ceil_i64_u', 'f64.promote_ceil_f32',
|
|
98
|
+
'f32.sqrt_floor', 'f32.add_floor', 'f32.sub_floor', 'f32.mul_floor', 'f32.div_floor',
|
|
99
|
+
'f64.sqrt_floor', 'f64.add_floor', 'f64.sub_floor', 'f64.mul_floor', 'f64.div_floor',
|
|
100
|
+
'f32.convert_floor_i32_s', 'f32.convert_floor_i32_u', 'f32.convert_floor_i64_s', 'f32.convert_floor_i64_u', 'f32.demote_floor_f64',
|
|
101
|
+
'f64.convert_floor_i32_s', 'f64.convert_floor_i32_u', 'f64.convert_floor_i64_s', 'f64.convert_floor_i64_u', 'f64.promote_floor_f32',
|
|
102
|
+
'f32.sqrt_trunc', 'f32.add_trunc', 'f32.sub_trunc', 'f32.mul_trunc', 'f32.div_trunc',
|
|
103
|
+
'f64.sqrt_trunc', 'f64.add_trunc', 'f64.sub_trunc', 'f64.mul_trunc', 'f64.div_trunc',
|
|
104
|
+
'f32.convert_trunc_i32_s', 'f32.convert_trunc_i32_u', 'f32.convert_trunc_i64_s', 'f32.convert_trunc_i64_u', 'f32.demote_trunc_f64',
|
|
105
|
+
'f64.convert_trunc_i32_s', 'f64.convert_trunc_i32_u', 'f64.convert_trunc_i64_s', 'f64.convert_trunc_i64_u', 'f64.promote_trunc_f32'
|
|
91
106
|
],
|
|
92
107
|
|
|
93
108
|
// 0xfd: SIMD instructions (nested array)
|
package/src/optimize.js
CHANGED
|
@@ -1076,16 +1076,26 @@ const inline = (ast) => {
|
|
|
1076
1076
|
|
|
1077
1077
|
// Inline: no locals, <= 4 params, single expression body, not exported
|
|
1078
1078
|
if (params && !hasLocals && !hasExport && params.length <= 4 && body.length === 1) {
|
|
1079
|
-
// Check if function mutates any of its params (local.set/tee on param)
|
|
1079
|
+
// Check if function mutates any of its params (local.set/tee on param),
|
|
1080
|
+
// or contains a control-transfer op (`return`, `return_call`,
|
|
1081
|
+
// `return_call_indirect`). Inlining such bodies into a different-typed
|
|
1082
|
+
// caller would propagate the transfer to the caller, returning from the
|
|
1083
|
+
// wrong function with the wrong type. Lifting the body into a
|
|
1084
|
+
// `(block $exit ...)` and rewriting returns to `(br $exit X)` would
|
|
1085
|
+
// unlock these — left for a future pass.
|
|
1080
1086
|
const paramNames = new Set(params.map(p => p.name))
|
|
1081
1087
|
let mutatesParam = false
|
|
1088
|
+
let hasReturn = false
|
|
1082
1089
|
walk(body[0], (n) => {
|
|
1083
1090
|
if (!Array.isArray(n)) return
|
|
1084
1091
|
if ((n[0] === 'local.set' || n[0] === 'local.tee') && paramNames.has(n[1])) {
|
|
1085
1092
|
mutatesParam = true
|
|
1086
1093
|
}
|
|
1094
|
+
if (n[0] === 'return' || n[0] === 'return_call' || n[0] === 'return_call_indirect') {
|
|
1095
|
+
hasReturn = true
|
|
1096
|
+
}
|
|
1087
1097
|
})
|
|
1088
|
-
if (!mutatesParam) {
|
|
1098
|
+
if (!mutatesParam && !hasReturn) {
|
|
1089
1099
|
inlinable.set(name, { body: body[0], params })
|
|
1090
1100
|
}
|
|
1091
1101
|
}
|
package/types/src/const.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/const.js"],"names":[],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/const.js"],"names":[],"mappings":"AAIA,0CA0KC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AA4gEA;;;;;;;;;;;GAWG;AACH,sCATW,QAAM,MAAM,SACZ,OAAO,GAAC,MAAM,MAAO,SA6C/B;AA56DD;;;;;GAKG;AACH,6CAgJC;AA6ID;;;;GAIG;AACH,wCAwBC;AAoMD;;;;GAIG;AACH,4CAuBC;AA+CD;;;;;GAKG;AACH,8CAqDC;AAjRD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CA6DC;AAID;;;;GAIG;AACH,0CAuCC;AAwVD;;;;GAIG;AACH,yCAwBC;AAID;;;;GAIG;AACH,0CAkGC;AAxjCD;;;;GAIG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAgB/B;;;;;;;;;;;;;;;;;;;;;;;;;AA0iCD;;;;;GAKG;AACH,0CAgDC;AAyED;;;;GAIG;AACH,4CAQC;AAID;;;;GAIG;AACH,2CA0CC;AAID,2EAA2E;AAC3E,sCAgEC;AAID;;;;GAIG;AACH,4CAyCC;AAID;;;;;GAKG;AACH,4CAsBC;AAID;;;;;;GAMG;AACH,wCAmBC;AAID;;;;;GAKG;AACH,4CAiDC;AAoCD;;;;;GAKG;AACH,0CA+DC;AAoWD,uCA0BC;AA1XD;;;;;GAKG;AACH,8CA0EC;AAoID;;;;GAIG;AACH,4CA0DC;AAqBD;;;;;GAKG;AACH,iDAiBC"}
|