watr 4.3.3 → 4.4.0

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.min.js CHANGED
@@ -1,6 +1,6 @@
1
- var Jt=Object.defineProperty;var Zt=(t,e)=>{for(var r in e)Jt(t,r,{get:e[r],enumerable:!0})};var at={};Zt(at,{f32:()=>Q,f64:()=>J,i16:()=>ie,i32:()=>F,i64:()=>Z,i8:()=>re,uleb:()=>g,uleb5:()=>ee,v128:()=>bt});var I=(t,e=I.loc)=>{if(e!=null&&I.src){let r=1,i=1;for(let s=0;s<e&&s<I.src.length;s++)I.src[s]===`
2
- `?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)};var zt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Tt=/^[+-]?(?:0x[\da-f]+|\d+)$/i,Qt=new TextEncoder,te=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),Mt={n:10,r:13,t:9,'"':34,"'":39,"\\":92},nt=t=>{let e=[],r=1,i,s,l="",n=()=>(l&&e.push(...Qt.encode(l)),l="");for(;r<t.length-1;)s=t[r++],i=null,s==="\\"&&(t[r]==="u"?(r++,r++,s=String.fromCodePoint(parseInt(t.slice(r,r=t.indexOf("}",r)),16)),r++):Mt[t[r]]?i=Mt[t[r++]]:isNaN(i=parseInt(t[r]+t[r+1],16))?s+=t[r]:(r++,r++)),i!=null?(n(),e.push(i)):l+=s;return n(),e.valueOf=()=>t,e},Et=t=>te.decode(new Uint8Array(nt(t)));var g=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):F.parse(t)),typeof t=="bigint"){for(;;){let i=Number(t&0x7Fn);if(t>>=7n,t===0n){e.push(i);break}e.push(i|128)}return e}let r=t&127;return t>>>=7,t===0?(e.push(r),e):(e.push(r|128),g(t,e))};function ee(t){let e=[];for(let r=0;r<5;r++){let i=t&127;t>>>=7,r<4&&(i|=128),e.push(i)}return e}function F(t,e=[]){for(typeof t=="string"&&(t=F.parse(t));;){let r=Number(t&127);if(t>>=7,t===0&&!(r&64)||t===-1&&r&64){e.push(r);break}e.push(r|128)}return e}var Ut=t=>!zt.test(t)&&Tt.test(t=t.replaceAll("_",""))?t:I(`Bad int ${t}`),re=F,ie=F;F.parse=t=>(t=parseInt(Ut(t)),(t<-2147483648||t>4294967295)&&I("i32 constant out of range"),t);function Z(t,e=[]){for(typeof t=="string"?t=Z.parse(t):typeof t=="number"&&(t=BigInt(t)),typeof t=="bigint"&&t>0x7fffffffffffffffn&&(t=t-0x10000000000000000n);;){let r=Number(t&0x7Fn);if(t>>=7n,t===0n&&!(r&64)||t===-1n&&r&64){e.push(r);break}e.push(r|128)}return e}var it=new ArrayBuffer(8),C=new Uint8Array(it),se=new Int32Array(it),le=new Float32Array(it),ne=new Float64Array(it),dt=new BigInt64Array(it);Z.parse=t=>(t=Ut(t),t=t[0]==="-"?-BigInt(t.slice(1)):BigInt(t),(t<-0x8000000000000000n||t>0xffffffffffffffffn)&&I("i64 constant out of range"),dt[0]=t,dt[0]);var ae=2147483648,fe=2139095040;function Q(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=F.parse(t.slice(r+4)),e|=fe,t[0]==="-"&&(e|=ae),se[0]=e):(e=typeof t=="string"?Q.parse(t):t,le[0]=e),[C[0],C[1],C[2],C[3]]}var oe=0x8000000000000000n,ce=0x7ff0000000000000n;function J(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=Z.parse(t.slice(r+4)),e|=ce,t[0]==="-"&&(e|=oe),dt[0]=e):(e=typeof t=="string"?J.parse(t):t,ne[0]=e),[C[0],C[1],C[2],C[3],C[4],C[5],C[6],C[7]]}J.parse=(t,e=Number.MAX_VALUE)=>{t=t.replaceAll("_","");let r=1;if(t[0]==="-"?(r=-1,t=t.slice(1)):t[0]==="+"&&(t=t.slice(1)),t[1]==="x"){let[i,s="0"]=t.split(/p/i),[l,n=""]=i.split("."),a=n.length??0,o=parseInt(l);isNaN(o)&&I();let f=n?parseInt("0x"+n)/16**a:0;s=parseInt(s,10);let c=r*(o+f)*2**s;return c=Math.max(-e,Math.min(e,c)),c}return t.includes("nan")?r<0?NaN:NaN:t.includes("inf")?r*(1/0):r*parseFloat(t)};Q.parse=t=>J.parse(t,34028234663852886e22);var bt=t=>{let e=BigInt(typeof t=="string"?t.replaceAll("_",""):t),r=new Uint8Array(16);for(let i=0;i<16;i++)r[i]=Number(e&0xffn),e>>=8n;return[...r]};var st=["unreachable","nop","block block","loop block","if block","else null","then null",,"throw tagidx",,"throw_ref","end end","br labelidx","br_if labelidx","br_table br_table","return","call funcidx","call_indirect call_indirect","return_call funcidx","return_call_indirect call_indirect","call_ref typeidx","return_call_ref typeidx",,,,,"drop","select select","",,,"try_table try_table","local.get localidx","local.set localidx","local.tee localidx","global.get globalidx","global.set globalidx","table.get tableidx","table.set tableidx",,"i32.load memarg","i64.load memarg","f32.load memarg","f64.load memarg","i32.load8_s memarg","i32.load8_u memarg","i32.load16_s memarg","i32.load16_u memarg","i64.load8_s memarg","i64.load8_u memarg","i64.load16_s memarg","i64.load16_u memarg","i64.load32_s memarg","i64.load32_u memarg","i32.store memarg","i64.store memarg","f32.store memarg","f64.store memarg","i32.store8 memarg","i32.store16 memarg","i64.store8 memarg","i64.store16 memarg","i64.store32 memarg","memory.size opt_memory","memory.grow opt_memory","i32.const i32","i64.const i64","f32.const f32","f64.const f64","i32.eqz","i32.eq","i32.ne","i32.lt_s","i32.lt_u","i32.gt_s","i32.gt_u","i32.le_s","i32.le_u","i32.ge_s","i32.ge_u","i64.eqz","i64.eq","i64.ne","i64.lt_s","i64.lt_u","i64.gt_s","i64.gt_u","i64.le_s","i64.le_u","i64.ge_s","i64.ge_u","f32.eq","f32.ne","f32.lt","f32.gt","f32.le","f32.ge","f64.eq","f64.ne","f64.lt","f64.gt","f64.le","f64.ge","i32.clz","i32.ctz","i32.popcnt","i32.add","i32.sub","i32.mul","i32.div_s","i32.div_u","i32.rem_s","i32.rem_u","i32.and","i32.or","i32.xor","i32.shl","i32.shr_s","i32.shr_u","i32.rotl","i32.rotr","i64.clz","i64.ctz","i64.popcnt","i64.add","i64.sub","i64.mul","i64.div_s","i64.div_u","i64.rem_s","i64.rem_u","i64.and","i64.or","i64.xor","i64.shl","i64.shr_s","i64.shr_u","i64.rotl","i64.rotr","f32.abs","f32.neg","f32.ceil","f32.floor","f32.trunc","f32.nearest","f32.sqrt","f32.add","f32.sub","f32.mul","f32.div","f32.min","f32.max","f32.copysign","f64.abs","f64.neg","f64.ceil","f64.floor","f64.trunc","f64.nearest","f64.sqrt","f64.add","f64.sub","f64.mul","f64.div","f64.min","f64.max","f64.copysign","i32.wrap_i64","i32.trunc_f32_s","i32.trunc_f32_u","i32.trunc_f64_s","i32.trunc_f64_u","i64.extend_i32_s","i64.extend_i32_u","i64.trunc_f32_s","i64.trunc_f32_u","i64.trunc_f64_s","i64.trunc_f64_u","f32.convert_i32_s","f32.convert_i32_u","f32.convert_i64_s","f32.convert_i64_u","f32.demote_f64","f64.convert_i32_s","f64.convert_i32_u","f64.convert_i64_s","f64.convert_i64_u","f64.promote_f32","i32.reinterpret_f32","i64.reinterpret_f64","f32.reinterpret_i32","f64.reinterpret_i64","i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s",,,,,,,,,,,,"ref.null ref_null","ref.is_null","ref.func funcidx","ref.eq","ref.as_non_null","br_on_null labelidx","br_on_non_null labelidx",,,,,,,,,,"cont.new typeidx","cont.bind cont_bind","suspend tagidx","resume resume","resume_throw resume_throw","resume_throw_ref resume_throw_ref","switch switch_cont",,,,,,,,,,,,,,,,,,,,,["struct.new typeidx","struct.new_default typeidx","struct.get typeidx_field","struct.get_s typeidx_field","struct.get_u typeidx_field","struct.set typeidx_field","array.new typeidx","array.new_default typeidx","array.new_fixed typeidx_multi","array.new_data typeidx_dataidx","array.new_elem typeidx_elemidx","array.get typeidx","array.get_s typeidx","array.get_u typeidx","array.set typeidx","array.len","array.fill typeidx","array.copy typeidx_typeidx","array.init_data typeidx_dataidx","array.init_elem typeidx_elemidx","ref.test reftype","","ref.cast reftype","","br_on_cast reftype2","br_on_cast_fail reftype2","any.convert_extern","extern.convert_any","ref.i31","i31.get_s","i31.get_u",,"struct.new_desc typeidx","struct.new_default_desc typeidx","ref.get_desc typeidx","ref.cast_desc_eq reftype",,"br_on_cast_desc_eq reftype2","br_on_cast_desc_eq_fail reftype2",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"string.new_utf8 memoryidx?","string.new_wtf16 memoryidx?","string.const stringidx","string.measure_utf8","string.measure_wtf8","string.measure_wtf16","string.encode_utf8 memoryidx?","string.encode_wtf16 memoryidx?","string.concat","string.eq","string.is_usv_sequence","string.new_lossy_utf8 memoryidx?","string.new_wtf8 memoryidx?","string.encode_lossy_utf8 memoryidx?","string.encode_wtf8 memoryidx?",,"string.as_wtf8","stringview_wtf8.advance","stringview_wtf8.encode_utf8 memoryidx?","stringview_wtf8.slice","stringview_wtf8.encode_lossy_utf8 memoryidx?","stringview_wtf8.encode_wtf8 memoryidx?",,,"string.as_wtf16","stringview_wtf16.length","stringview_wtf16.get_codeunit","stringview_wtf16.encode memoryidx?","stringview_wtf16.slice",,,,"string.as_iter","stringview_iter.next","stringview_iter.advance","stringview_iter.rewind","stringview_iter.slice",,,,,,,,,,,,"string.new_utf8_array","string.new_wtf16_array","string.encode_utf8_array","string.encode_wtf16_array","string.new_lossy_utf8_array","string.new_wtf8_array","string.encode_lossy_utf8_array","string.encode_wtf8_array"],["i32.trunc_sat_f32_s","i32.trunc_sat_f32_u","i32.trunc_sat_f64_s","i32.trunc_sat_f64_u","i64.trunc_sat_f32_s","i64.trunc_sat_f32_u","i64.trunc_sat_f64_s","i64.trunc_sat_f64_u","memory.init dataidx_memoryidx","data.drop dataidx","memory.copy memoryidx_memoryidx","memory.fill memoryidx?","table.init reversed","elem.drop elemidx","table.copy tableidx_tableidx","table.grow tableidx","table.size tableidx","table.fill tableidx",,"i64.add128","i64.sub128","i64.mul_wide_s","i64.mul_wide_u"],["v128.load memarg","v128.load8x8_s memarg","v128.load8x8_u memarg","v128.load16x4_s memarg","v128.load16x4_u memarg","v128.load32x2_s memarg","v128.load32x2_u memarg","v128.load8_splat memarg","v128.load16_splat memarg","v128.load32_splat memarg","v128.load64_splat memarg","v128.store memarg","v128.const v128const","i8x16.shuffle shuffle","i8x16.swizzle","i8x16.splat","i16x8.splat","i32x4.splat","i64x2.splat","f32x4.splat","f64x2.splat","i8x16.extract_lane_s laneidx","i8x16.extract_lane_u laneidx","i8x16.replace_lane laneidx","i16x8.extract_lane_s laneidx","i16x8.extract_lane_u laneidx","i16x8.replace_lane laneidx","i32x4.extract_lane laneidx","i32x4.replace_lane laneidx","i64x2.extract_lane laneidx","i64x2.replace_lane laneidx","f32x4.extract_lane laneidx","f32x4.replace_lane laneidx","f64x2.extract_lane laneidx","f64x2.replace_lane laneidx","i8x16.eq","i8x16.ne","i8x16.lt_s","i8x16.lt_u","i8x16.gt_s","i8x16.gt_u","i8x16.le_s","i8x16.le_u","i8x16.ge_s","i8x16.ge_u","i16x8.eq","i16x8.ne","i16x8.lt_s","i16x8.lt_u","i16x8.gt_s","i16x8.gt_u","i16x8.le_s","i16x8.le_u","i16x8.ge_s","i16x8.ge_u","i32x4.eq","i32x4.ne","i32x4.lt_s","i32x4.lt_u","i32x4.gt_s","i32x4.gt_u","i32x4.le_s","i32x4.le_u","i32x4.ge_s","i32x4.ge_u","f32x4.eq","f32x4.ne","f32x4.lt","f32x4.gt","f32x4.le","f32x4.ge","f64x2.eq","f64x2.ne","f64x2.lt","f64x2.gt","f64x2.le","f64x2.ge","v128.not","v128.and","v128.andnot","v128.or","v128.xor","v128.bitselect","v128.any_true","v128.load8_lane memlane","v128.load16_lane memlane","v128.load32_lane memlane","v128.load64_lane memlane","v128.store8_lane memlane","v128.store16_lane memlane","v128.store32_lane memlane","v128.store64_lane memlane","v128.load32_zero memarg","v128.load64_zero memarg","f32x4.demote_f64x2_zero","f64x2.promote_low_f32x4","i8x16.abs","i8x16.neg","i8x16.popcnt","i8x16.all_true","i8x16.bitmask","i8x16.narrow_i16x8_s","i8x16.narrow_i16x8_u","f32x4.ceil","f32x4.floor","f32x4.trunc","f32x4.nearest","i8x16.shl","i8x16.shr_s","i8x16.shr_u","i8x16.add","i8x16.add_sat_s","i8x16.add_sat_u","i8x16.sub","i8x16.sub_sat_s","i8x16.sub_sat_u","f64x2.ceil","f64x2.floor","i8x16.min_s","i8x16.min_u","i8x16.max_s","i8x16.max_u","f64x2.trunc","i8x16.avgr_u","i16x8.extadd_pairwise_i8x16_s","i16x8.extadd_pairwise_i8x16_u","i32x4.extadd_pairwise_i16x8_s","i32x4.extadd_pairwise_i16x8_u","i16x8.abs","i16x8.neg","i16x8.q15mulr_sat_s","i16x8.all_true","i16x8.bitmask","i16x8.narrow_i32x4_s","i16x8.narrow_i32x4_u","i16x8.extend_low_i8x16_s","i16x8.extend_high_i8x16_s","i16x8.extend_low_i8x16_u","i16x8.extend_high_i8x16_u","i16x8.shl","i16x8.shr_s","i16x8.shr_u","i16x8.add","i16x8.add_sat_s","i16x8.add_sat_u","i16x8.sub","i16x8.sub_sat_s","i16x8.sub_sat_u","f64x2.nearest","i16x8.mul","i16x8.min_s","i16x8.min_u","i16x8.max_s","i16x8.max_u",,"i16x8.avgr_u","i16x8.extmul_low_i8x16_s","i16x8.extmul_high_i8x16_s","i16x8.extmul_low_i8x16_u","i16x8.extmul_high_i8x16_u","i32x4.abs","i32x4.neg",,"i32x4.all_true","i32x4.bitmask",,,"i32x4.extend_low_i16x8_s","i32x4.extend_high_i16x8_s","i32x4.extend_low_i16x8_u","i32x4.extend_high_i16x8_u","i32x4.shl","i32x4.shr_s","i32x4.shr_u","i32x4.add",,,"i32x4.sub",,,,"i32x4.mul","i32x4.min_s","i32x4.min_u","i32x4.max_s","i32x4.max_u","i32x4.dot_i16x8_s",,"i32x4.extmul_low_i16x8_s","i32x4.extmul_high_i16x8_s","i32x4.extmul_low_i16x8_u","i32x4.extmul_high_i16x8_u","i64x2.abs","i64x2.neg",,"i64x2.all_true","i64x2.bitmask",,,"i64x2.extend_low_i32x4_s","i64x2.extend_high_i32x4_s","i64x2.extend_low_i32x4_u","i64x2.extend_high_i32x4_u","i64x2.shl","i64x2.shr_s","i64x2.shr_u","i64x2.add",,,"i64x2.sub",,,,"i64x2.mul","i64x2.eq","i64x2.ne","i64x2.lt_s","i64x2.gt_s","i64x2.le_s","i64x2.ge_s","i64x2.extmul_low_i32x4_s","i64x2.extmul_high_i32x4_s","i64x2.extmul_low_i32x4_u","i64x2.extmul_high_i32x4_u","f32x4.abs","f32x4.neg",,"f32x4.sqrt","f32x4.add","f32x4.sub","f32x4.mul","f32x4.div","f32x4.min","f32x4.max","f32x4.pmin","f32x4.pmax","f64x2.abs","f64x2.neg",,"f64x2.sqrt","f64x2.add","f64x2.sub","f64x2.mul","f64x2.div","f64x2.min","f64x2.max","f64x2.pmin","f64x2.pmax","i32x4.trunc_sat_f32x4_s","i32x4.trunc_sat_f32x4_u","f32x4.convert_i32x4_s","f32x4.convert_i32x4_u","i32x4.trunc_sat_f64x2_s_zero","i32x4.trunc_sat_f64x2_u_zero","f64x2.convert_low_i32x4_s","f64x2.convert_low_i32x4_u","i8x16.relaxed_swizzle","i32x4.relaxed_trunc_f32x4_s","i32x4.relaxed_trunc_f32x4_u","i32x4.relaxed_trunc_f64x2_s_zero","i32x4.relaxed_trunc_f64x2_u_zero","f32x4.relaxed_madd","f32x4.relaxed_nmadd","f64x2.relaxed_madd","f64x2.relaxed_nmadd","i8x16.relaxed_laneselect","i16x8.relaxed_laneselect","i32x4.relaxed_laneselect","i64x2.relaxed_laneselect","f32x4.relaxed_min","f32x4.relaxed_max","f64x2.relaxed_min","f64x2.relaxed_max","i16x8.relaxed_q15mulr_s","i16x8.relaxed_dot_i8x16_i7x16_s","i32x4.relaxed_dot_i8x16_i7x16_add_s"],["memory.atomic.notify memarg","memory.atomic.wait32 memarg","memory.atomic.wait64 memarg","atomic.fence opt_memory",,,,,,,,,,,,,"i32.atomic.load memarg","i64.atomic.load memarg","i32.atomic.load8_u memarg","i32.atomic.load16_u memarg","i64.atomic.load8_u memarg","i64.atomic.load16_u memarg","i64.atomic.load32_u memarg","i32.atomic.store memarg","i64.atomic.store memarg","i32.atomic.store8 memarg","i32.atomic.store16 memarg","i64.atomic.store8 memarg","i64.atomic.store16 memarg","i64.atomic.store32 memarg","i32.atomic.rmw.add memarg","i64.atomic.rmw.add memarg","i32.atomic.rmw8.add_u memarg","i32.atomic.rmw16.add_u memarg","i64.atomic.rmw8.add_u memarg","i64.atomic.rmw16.add_u memarg","i64.atomic.rmw32.add_u memarg","i32.atomic.rmw.sub memarg","i64.atomic.rmw.sub memarg","i32.atomic.rmw8.sub_u memarg","i32.atomic.rmw16.sub_u memarg","i64.atomic.rmw8.sub_u memarg","i64.atomic.rmw16.sub_u memarg","i64.atomic.rmw32.sub_u memarg","i32.atomic.rmw.and memarg","i64.atomic.rmw.and memarg","i32.atomic.rmw8.and_u memarg","i32.atomic.rmw16.and_u memarg","i64.atomic.rmw8.and_u memarg","i64.atomic.rmw16.and_u memarg","i64.atomic.rmw32.and_u memarg","i32.atomic.rmw.or memarg","i64.atomic.rmw.or memarg","i32.atomic.rmw8.or_u memarg","i32.atomic.rmw16.or_u memarg","i64.atomic.rmw8.or_u memarg","i64.atomic.rmw16.or_u memarg","i64.atomic.rmw32.or_u memarg","i32.atomic.rmw.xor memarg","i64.atomic.rmw.xor memarg","i32.atomic.rmw8.xor_u memarg","i32.atomic.rmw16.xor_u memarg","i64.atomic.rmw8.xor_u memarg","i64.atomic.rmw16.xor_u memarg","i64.atomic.rmw32.xor_u memarg","i32.atomic.rmw.xchg memarg","i64.atomic.rmw.xchg memarg","i32.atomic.rmw8.xchg_u memarg","i32.atomic.rmw16.xchg_u memarg","i64.atomic.rmw8.xchg_u memarg","i64.atomic.rmw16.xchg_u memarg","i64.atomic.rmw32.xchg_u memarg","i32.atomic.rmw.cmpxchg memarg","i64.atomic.rmw.cmpxchg memarg","i32.atomic.rmw8.cmpxchg_u memarg","i32.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw8.cmpxchg_u memarg","i64.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw32.cmpxchg_u memarg"]],B={custom:0,type:1,import:2,func:3,table:4,memory:5,tag:13,strings:14,global:6,export:7,start:8,elem:9,datacount:12,code:10,data:11},E={i8:120,i16:119,i32:127,i64:126,f32:125,f64:124,void:64,v128:123,exn:105,noexn:116,nofunc:115,noextern:114,none:113,func:112,extern:111,any:110,eq:109,i31:108,struct:107,array:106,cont:104,nocont:117,string:103,stringview_wtf8:102,stringview_wtf16:96,stringview_iter:97,nullfuncref:115,nullexternref:114,nullexnref:116,nullref:113,funcref:112,externref:111,exnref:105,anyref:110,eqref:109,i31ref:108,structref:107,arrayref:106,contref:104,nocontref:117,stringref:103,ref:100,refnull:99,sub:80,subfinal:79,rec:78},V={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},At={func:0,table:1,memory:2,global:3,tag:4};var D=t=>{let e=0,r=[],i="",s=0,l=0,n=()=>i&&(r.push(i),i=""),a=o=>{r.loc=o;for(let f,c,u;e<t.length;)if(f=t.charCodeAt(e),s===34)i+=t[e++],f===92?i+=t[e++]:f===34&&(n(),s=0);else if(s>59)f===40&&t.charCodeAt(e+1)===59?(s++,i+=t[e++]+t[e++]):f===59&&t.charCodeAt(e+1)===41?(i+=t[e++]+t[e++],--s===59&&(n(),s=0)):i+=t[e++];else if(s<0)f===10||f===13?(i+=t[e++],n(),s=0):s===-2&&f===41?(n(),s=0):i+=t[e++];else if(f===34)i!=="$"&&n(),s=34,i+=t[e++];else if(f===40&&t.charCodeAt(e+1)===59)n(),s=60,i=t[e++]+t[e++];else if(f===59&&t.charCodeAt(e+1)===59)n(),s=t.indexOf(`
3
- `,e)<0?-2:-1,i=t[e++]+t[e++];else if(f===40&&t.charCodeAt(e+1)===64)n(),u=e,e+=2,i="@",l++,(c=r).push(r=[]),a(u),r=c;else if(f===40)n(),u=e++,l++,(c=r).push(r=[]),a(u),r=c;else{if(f===41)return n(),e++,l--;f<=32?(n(),e++):i+=t[e++]}s<0&&n(),n()};return a(0),s===34&&I("Unclosed quote",e),s>59&&I("Unclosed block comment",e),l>0&&I("Unclosed parenthesis",e),e<t.length&&I("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var Ot=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(Ot).filter(r=>r!=null),e.loc=t.loc,e.length===1&&e[0]?.[0]==="module"?e[0]:e):typeof t!="string"?t:t[0]===";"||t[1]===";"?null:t[0]==="$"&&t[1]==='"'?t.includes("\\")?"$"+Et(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?nt(t):t;function et(t){typeof t=="string"?(I.src=t,t=D(t)||[]):I.src="",I.loc=0,t=Ot(t)||[];let e=0;if(t[0]==="module"?(e++,S(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return et(t.slice(++e).map(u=>u.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((u,h)=>{if(h<e||!Array.isArray(u)||u[0]!=="import")return[u];let[,p,...b]=u;if(!b.some(x=>Array.isArray(x)&&x[0]==="item"))return[u];if(Array.isArray(b.at(-1))&&b.at(-1)[0]!=="item"){let x=b.at(-1);return b.slice(0,-1).filter(m=>m[0]==="item").map(([,m])=>["import",p,m,x])}return b.filter(x=>x[0]==="item").map(([,x,m])=>["import",p,x,m])});let r=[];for(let u in B)(r[B[u]]=r[u]=[]).name=u;r.metadata={},t.slice(e).filter(u=>{if(!Array.isArray(u)){let b=I.loc,_=I.src,x;for(;(b=_.indexOf(u,b))>=0;){if(x=_.charCodeAt(b-1),b>0&&(x>47&&x<58||x>64&&x<91||x>96&&x<123||x===95||x===36)){b++;continue}if(x=_.charCodeAt(b+u.length),x>47&&x<58||x>64&&x<91||x>96&&x<123||x===95){b++;continue}break}b>=0&&(I.loc=b),I(`Unexpected token ${u}`)}let[h,...p]=u;if(I.loc=u.loc,h==="@custom")r.custom.push(p);else if(h==="rec")for(let b=0;b<p.length;b++){let[,..._]=p[b];wt(_,r.type);let x=[];for(;_[0]?.[0]==="descriptor"||_[0]?.[0]==="describes";)x.push(_.shift());(_=qt(_,r)).push(b?!0:[r.type.length,p.length]),x.length&&(_.desc=_.desc?[...x,..._.desc]:x),r.type.push(_)}else if(h==="type"){wt(p,r.type);let b=[];for(;p[0]?.[0]==="descriptor"||p[0]?.[0]==="describes";)b.push(p.shift());let _=qt(p,r);b.length&&(_.desc=_.desc?[...b,..._.desc]:b),r.type.push(_)}else if(h==="start"||h==="export")r[h].push(p);else return!0}).forEach(u=>{let[h,...p]=u;I.loc=u.loc;let b;h==="import"&&([h,...p]=(b=p).pop());let _=r[h];for(_||I(`Unknown section ${h}`),wt(p,_);p[0]?.[0]==="export";)r.export.push([p.shift()[1],[h,_?.length]]);if(p[0]?.[0]==="import"&&([,...b]=p.shift()),h==="table"){let x=p[0]==="i64",m=x?1:0;if(p[m+1]?.[0]==="elem"){let[d,[,...y]]=[p[m],p[m+1]];p=x?["i64",y.length,y.length,d]:[y.length,y.length,d],r.elem.push([["table",_.length],["offset",[x?"i64.const":"i32.const",x?0n:0]],d,...y])}}else if(h==="memory"){let x=p[0]==="i64",m=x?1:0;if(p[m]?.[0]==="data"){let d=p.find(w=>Array.isArray(w)&&w[0]==="pagesize")?.[1]??65536,[,...y]=p.splice(m,1)[0],v=""+Math.ceil(y.reduce((w,k)=>w+k.length,0)/d);r.data.push([["memory",_.length],[x?"i64.const":"i32.const",x?0n:0],...y]),p=x?["i64",v,v]:[v,v]}}else if(h==="func"){let[x,m,d]=yt(p,r);x??=_t(m,d,r),!b&&r.code.push([[x,m,d],...Y(p,r)]),p=[["type",x]]}else if(h==="tag"){let[x,m]=yt(p,r);x??=_t(m,[],r),p=[["type",x]]}b&&(r.import.push([...b,[h,...p]]),p=null),_.push(p)});let i=(u,h=!0)=>{let p=r[u].filter(Boolean).map(b=>Ft[u](b,r)).filter(Boolean);return u===B.custom?p.flatMap(b=>[u,...N(b)]):p.length?[u,...N(h?N(p):p)]:[]},s=()=>{let u=[];for(let h in r.metadata){let p=N(nt(`"metadata.code.${h}"`)),b=N(r.metadata[h].map(([_,x])=>[...g(_),...N(x.map(([m,d])=>[...g(m),...N(d)]))]));u.push(0,...N([...p,...b]))}return u},l=i(B.global),n=i(B.elem),a=i(B.code),o=s(),f=i(B.data),c=r.strings.length?[B.strings,...N([0,...N(r.strings.map(u=>N(u)))])]:[];return Uint8Array.from([0,97,115,109,1,0,0,0,...i(B.custom),...i(B.type),...i(B.import),...i(B.func),...i(B.table),...i(B.memory),...i(B.tag),...c,...l,...i(B.export),...i(B.start,!1),...n,...i(B.datacount,!1),...a,...o,...f])}var L=t=>t?.[0]==="$"||!isNaN(t),S=t=>t?.[0]==="$",vt=t=>t?.[0]==="a"||t?.[0]==="o";function Y(t,e){let r=[];for(t=[...t];t.length;){let i=t.shift();if(typeof i=="string")if(r.push(i),i==="block"||i==="if"||i==="loop")S(t[0])&&r.push(t.shift()),r.push(ft(t,e));else if(i==="else"||i==="end")S(t[0])&&t.shift();else if(i==="select")r.push(pt(t)[1]);else if(i.endsWith("call_indirect")){let s=L(t[0])?t.shift():0,[l,n,a]=yt(t,e);r.push(s,["type",l??_t(n,a,e)])}else i==="table.init"?r.push(L(t[1])?t.shift():0,t.shift()):i==="table.copy"||i==="memory.copy"?r.push(L(t[0])?t.shift():0,L(t[0])?t.shift():0):i.startsWith("table.")?r.push(L(t[0])?t.shift():0):i==="memory.init"?(r.push(...L(t[1])?[t.shift(),t.shift()].reverse():[t.shift(),0]),e.datacount&&(e.datacount[0]=!0)):i==="data.drop"||i==="array.new_data"||i==="array.init_data"?(i==="data.drop"&&r.push(t.shift()),e.datacount&&(e.datacount[0]=!0)):(i.startsWith("memory.")||i.endsWith("load")||i.endsWith("store"))&&L(t[0])&&r.push(t.shift());else if(Array.isArray(i)){let s=i[0];if(i.loc!=null&&(I.loc=i.loc),s?.startsWith?.("@metadata.code.")){let n=s.slice(15);r.push(["@metadata",n,i[1]]);continue}if(typeof s!="string"||!Array.isArray(st[s])){r.push(i);continue}let l=i.slice(1);if(s==="block"||s==="loop")r.push(s),S(l[0])&&r.push(l.shift()),r.push(ft(l,e),...Y(l,e),"end");else if(s==="if"){let n=[],a=[];l.at(-1)?.[0]==="else"&&(a=Y(l.pop().slice(1),e)),l.at(-1)?.[0]==="then"&&(n=Y(l.pop().slice(1),e));let o=[s];S(l[0])&&o.push(l.shift()),o.push(ft(l,e)),r.push(...Y(l,e),...o,...n),a.length&&r.push("else",...a),r.push("end")}else if(s==="try_table"){for(r.push(s),S(l[0])&&r.push(l.shift()),r.push(ft(l,e));l[0]?.[0]==="catch"||l[0]?.[0]==="catch_ref"||l[0]?.[0]==="catch_all"||l[0]?.[0]==="catch_all_ref";)r.push(l.shift());r.push(...Y(l,e),"end")}else{let n=[];for(;l.length&&(!Array.isArray(l[0])||l[0].valueOf!==Array.prototype.valueOf||"type,param,result,ref,exact,on".includes(l[0][0]));)n.push(l.shift());r.push(...Y(l,e),s,...n),t.unshift(...r.splice(r.length-1-n.length))}}else r.push(i)}return r}var _t=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),$t=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=S(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},pt=t=>{let e=$t(t,"param"),r=$t(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},yt=(t,e)=>{if(t[0]?.[0]!=="type")return[,...pt(t)];let[,r]=t.shift(),[i,s]=pt(t),l=e.type[typeof r=="string"&&isNaN(r)?e.type[r]:+r];if(!l)throw Error(`Unknown type ${r}`);if((i.length||s.length)&&l[1].join(">")!==i+">"+s)throw Error(`Type ${r} mismatch`);return[r,...l[1]]},ft=(t,e)=>{let[r,i,s]=yt(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??_t(i,s,e)]},wt=(t,e)=>{let r=S(t[0])&&t.shift();return r&&(r in e?I(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},qt=([t],e)=>{let r="subfinal",i=[],s,l=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(i=t).pop(),i=i.filter(a=>Array.isArray(a)&&(a[0]==="descriptor"||a[0]==="describes")?(l.push(a),!1):!0)),[s,...t]=t,s==="func"?(t=pt(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=$t(t,"field"):s==="array"&&([t]=t);let n=[s,t,r,i];return l.length&&(n.desc=l),n},Ft=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...N(t),...i.flat()]},(t,e)=>{let[r,i,s,l,n]=t;if(n===!0)return;let a=(t.desc??[]).flatMap(([f,c])=>[f==="descriptor"?77:76,...g(A(c,e.type))]),o=(f,c)=>f==="func"?[V.func,...N(c[0].map(u=>W(u,e))),...N(c[1].map(u=>W(u,e)))]:f==="array"?[V.array,...ot(c,e)]:f==="struct"?[V.struct,...N(c.map(u=>ot(u,e)))]:f==="cont"?[V.cont,...g(A(c[0]??c,e.type))]:[V[f]];if(n){let[f,c]=n,u=Array.from({length:c},(h,p)=>{let b=e.type[f+p],_=b.slice(0,4);return b.desc&&(_.desc=b.desc),Ft[B.type](_,e)});return[V.rec,...N(u)]}else if(s==="sub"||l?.length)return[V[s],...N(l.map(f=>A(f,e.type))),...a,...o(r,i)];return[...a,...o(r,i)]},([t,e,[r,...i]],s)=>{let l,n=At[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(n=32);let[[,o]]=i;l=g(A(o,s.type))}else if(r==="tag"){let[[,a]]=i;l=[0,...g(A(a,s.type))]}else r==="memory"?l=ct(i):r==="global"?l=ot(i[0],s):r==="table"?l=[...W(i.pop(),s),...ct(i)]:I(`Unknown kind ${r}`);return[...N(t),...N(e),n,...l]},([[,t]],e)=>g(A(t,e.type)),(t,e)=>{let r=ct(t),i=W(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...tt(s,e)]:[...i,...r]},(t,e)=>ct(t),([t,e],r)=>[...ot(t,r),...tt(e,r)],([t,[e,r]],i)=>[...N(t),At[e],...g(A(r,i[e]))],([t],e)=>g(A(t,e.func)),(t,e)=>{let r=0,i=0,s=0,l=0,n,a,o;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,n]=t.shift(),n=A(n,e.table)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&t[1][0]!=="item"&&!t[1][0]?.startsWith("ref"))&&(n=A(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(a=t.shift(),a[0]==="offset"&&([,a]=a),a=tt(a,e)):i||(r=1),E[t[0]]||t[0]?.[0]==="ref"?o=W(t.shift(),e):t[0]==="func"?o=[E[t.shift()]]:o=[E.func],t=t.map(c=>(c[0]==="item"&&(c=c.length===3&&c[1]==="ref.func"?c[2]:c[1]),c[0]==="ref.func"&&([,c]=c),typeof c!="string"&&(s=1),c)),o[0]!==E.funcref&&(l=1,s=1);let f=s<<2|(r||i?i:!!n||l)<<1|(r||i);return[f,...f===0?a:f===1?[0]:f===2?[...g(n||0),...a,0]:f===3?[0]:f===4?a:f===5?o:f===6?[...g(n||0),...a,...o]:o,...N(t.map(s?c=>tt(typeof c=="string"?["ref.func",c]:c,e):c=>g(A(c,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[A(r,e.type)]),e.local=Object.create(i),e.block=[],e.local.name="local",e.block.name="block",e._codeIdx===void 0&&(e._codeIdx=0);let s=e._codeIdx++;for(;t[0]?.[0]==="local";){let[,...o]=t.shift();if(S(o[0])){let f=o.shift();f in e.local?I(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...o)}e.meta={};let l=Ct(t,e),n=e.import.filter(o=>o[2][0]==="func").length+s;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([n,e.meta[o]]);let a=e.local.slice(i.length).reduce((o,f)=>(f==o[o.length-1]?.[1]?o[o.length-1][0]++:o.push([1,f]),o),[]);return e.local=e.block=e.meta=null,N([...N(a.map(([o,f])=>[...g(o),...W(f,e)])),...l])},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=A(i,e.memory)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&typeof t[1][0]=="string")&&(i=A(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??I("Bad offset",r)),[...i?[2,...g(i),...tt(r,e)]:r?[0,...tt(r,e)]:[1],...N(t.flatMap(s=>_e(s)??[...s]))]},(t,e)=>g(e.data.length),([[,t]],e)=>[0,...g(A(t,e.type))]],W=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[E.refnull,98,...g(A(t[2][1],e.type))]:E[t[2]]?[E[t[2]]]:[E.refnull,...g(A(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[E.ref,98,...g(A(t[1][1],e.type))]:[E.ref,...g(E[t[t.length-1]]||A(t[t.length-1],e.type))]:[E[t]??I(`Unknown type ${t}`)],ot=(t,e,r=t[0]==="mut"?1:0)=>[...W(r?t[1]:t,e),r],Wt={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...g(A(i,e.elem)),...g(A(r,e.table))]},block:(t,e)=>{e.block.push(1),S(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?W(r[1],e):g(A(r[1],e.type)):[E.void]},try_table:(t,e)=>{S(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?W(r[1],e):g(A(r[1],e.type)):[E.void],s=[],l=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let n=t.shift(),a=n[0]==="catch"?0:n[0]==="catch_ref"?1:n[0]==="catch_all"?2:3;a<=1?s.push(a,...g(A(n[1],e.tag)),...g(H(n[2],e.block))):s.push(a,...g(H(n[1],e.block))),l++}return e.block.push(1),[...i,...g(l),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...g(A(i,e.type)),...g(A(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||S(t[0]));)r.push(...g(H(t.shift(),e.block))),i++;return[...g(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?N(r.map(i=>W(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...g(A(r[1],e.type))]:E[r]?[E[r]]:g(A(r,e.type))},memarg:(t,e,r)=>St(t,r,L(t[0])&&!vt(t[0])?A(t.shift(),e.memory):0),opt_memory:(t,e)=>g(A(L(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=W(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=H(t.shift(),e.block),i=W(t.shift(),e),s=W(t.shift(),e),l=n=>n.length>1?n.slice(1):n;return[(s[0]!==E.ref)<<1|i[0]!==E.ref,...g(r),...l(i),...l(s)]},v128const:t=>{let[e,r]=t.shift().split("x"),i=+e.slice(1),s=i>>>3;if(r=+r,e[0]==="i"){let n=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let a=0;a<r;a++)n[a]=at[e].parse(t.shift());return[...new Uint8Array(n.buffer)]}let l=new Uint8Array(16);for(let n=0;n<r;n++)l.set(at[e](t.shift()),n*s);return[...l]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(mt(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&I("invalid lane length"),e},memlane:(t,e,r)=>{let i=S(t[0])||L(t[0])&&(vt(t[1])||L(t[1]))?A(t.shift(),e.memory):0;return[...St(t,r,i),...g(mt(t.shift()))]},"*":t=>g(t.shift()),labelidx:(t,e)=>g(H(t.shift(),e.block)),laneidx:t=>[mt(t.shift(),255)],funcidx:(t,e)=>g(A(t.shift(),e.func)),typeidx:(t,e)=>g(A(t.shift(),e.type)),tableidx:(t,e)=>g(A(t.shift(),e.table)),memoryidx:(t,e)=>g(A(t.shift(),e.memory)),globalidx:(t,e)=>g(A(t.shift(),e.global)),localidx:(t,e)=>g(A(t.shift(),e.local)),dataidx:(t,e)=>g(A(t.shift(),e.data)),elemidx:(t,e)=>g(A(t.shift(),e.elem)),tagidx:(t,e)=>g(A(t.shift(),e.tag)),"memoryidx?":(t,e)=>g(A(L(t[0])?t.shift():0,e.memory)),stringidx:(t,e)=>{let r=t.shift(),i=r.valueOf(),s=e.strings.findIndex(l=>l.valueOf()===i);return s<0&&(s=e.strings.push(r)-1),g(s)},i32:t=>F(t.shift()),i64:t=>Z(t.shift()),f32:t=>Q(t.shift()),f64:t=>J(t.shift()),v128:t=>bt(t.shift()),typeidx_field:(t,e)=>{let r=A(t.shift(),e.type);return[...g(r),...g(A(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...g(A(t.shift(),e.type)),...g(t.shift())],typeidx_dataidx:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...g(A(t.shift(),e.data)),...g(A(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...g(A(t.shift(),e.memory)),...g(A(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...g(A(t.shift(),e.table)),...g(A(t.shift(),e.table))],cont_bind:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.type))],switch_cont:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.tag))],resume:(t,e)=>{let r=g(A(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,l,n]=t.shift();n==="switch"?i.push(1,...g(A(l,e.tag))):i.push(0,...g(A(l,e.tag)),...g(H(n,e.block))),s++}return[...r,...g(s),...i]},resume_throw:(t,e)=>{let r=g(A(t.shift(),e.type)),i=g(A(t.shift(),e.tag)),s=[],l=0;for(;t[0]?.[0]==="on";){let[,n,a]=t.shift();a==="switch"?s.push(1,...g(A(n,e.tag))):s.push(0,...g(A(n,e.tag)),...g(H(a,e.block))),l++}return[...r,...i,...g(l),...s]},resume_throw_ref:(t,e)=>{let r=g(A(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,l,n]=t.shift();n==="switch"?i.push(1,...g(A(l,e.tag))):i.push(0,...g(A(l,e.tag)),...g(H(n,e.block))),s++}return[...r,...g(s),...i]}},ut={};(function t(e,r){for(let i=0,s,l,n;i<e.length;i++)(s=e[i])&&(Array.isArray(s)?t(s,i):([l,n]=s.split(" "),st[l]=r?[r,...g(i)]:[i],n&&(ut[l]=Wt[n])))})(st);var Ct=(t,e)=>{let r=[],i=[];for(;t?.length;){let s=t.shift();if(s?.[0]==="@metadata"){i.push(s.slice(1));continue}Array.isArray(s)&&(s.loc!=null&&(I.loc=s.loc),I(`Unknown instruction ${s[0]}`));let[...l]=st[s]||I(`Unknown instruction ${s}`);ut[s]&&(s==="select"&&t[0]?.length?l[0]++:ut[s]===Wt.reftype&&(t[0][1]==="null"||t[0][0]!=="ref")&&l[l.length-1]++,l.push(...ut[s](t,e,s)));for(let[n,a]of i)(e.meta[n]??=[]).push([r.length,a]);r.push(...l)}return r.push(11),r},tt=(t,e)=>Ct(Y([t],e),e),A=(t,e,r)=>(r=S(t)?e[t]:+t,r in e?r:I(`Unknown ${e.name} ${t}`)),H=(t,e,r)=>(r=S(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?I(`Bad label ${t}`):r),ue=t=>{let e,r,i,s;for(;vt(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:I(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&I(`Bad offset ${r}`),(e<=0||e>4294967295)&&I(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&I(`Bad align ${e}`),[e,r]},St=(t,e,r=0)=>{let[i,s]=ue(t),l=(i??me(e))|(r&&64);return r?[...g(l),...g(r),...g(s??0)]:[...g(l),...g(s??0)]},me=t=>{let e=t.indexOf(".",3)+1,r=t.slice(1,t[0]==="v"?4:3);if(t[e]==="a"&&(e=t.indexOf(".",e)+1),t[0]==="m")return t.includes("64")?3:2;if(t[e]==="r"){let l=t.slice(e,e+6).match(/\d+/);return Math.log2(l?l[0]/8:+r/8)}let i=t[e]==="l"?e+4:e+5,s=t.slice(i).match(/(\d+)(x|_|$)/);return Math.log2(s?s[2]==="x"?8:s[1]/8:+r/8)},_e=t=>{if(!Array.isArray(t))return null;let[e,...r]=t;if(e!=="i8"&&e!=="i16"&&e!=="i32"&&e!=="i64"&&e!=="f32"&&e!=="f64")return null;let i=[],s=new DataView(new ArrayBuffer(8));for(let l of r)e==="i8"?i.push(F.parse(l)&511&255):e==="i16"?(s.setInt16(0,F.parse(l),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,F.parse(l),!0),i.push(...new Uint8Array(s.buffer,0,4))):e==="i64"?(s.setBigInt64(0,BigInt(l),!0),i.push(...new Uint8Array(s.buffer,0,8))):e==="f32"?i.push(...Q(l)):e==="f64"&&i.push(...J(l));return i},ct=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(f=>Array.isArray(f)&&f[0]==="pagesize"),s=-1;i>=0&&(s=Math.log2(+t.splice(i,1)[0][1]));let l=!isNaN(parseInt(t[1])),n=(s>=0?8:0)|(e?4:0)|(r?2:0)|(l?1:0),a=e?f=>{if(typeof f=="bigint")return f;let c=typeof f=="string"?f.replaceAll("_",""):String(f);return BigInt(c)}:mt,o=s>=0?g(s):[];return l?[n,...g(a(t.shift())),...g(a(t.shift())),...o]:[n,...g(a(t.shift())),...o]},mt=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?F.parse(t):typeof t=="number"?t:I(`Bad int ${t}`);return r>e?I(`Value out of range ${t}`):r},N=t=>[...g(t.length),...t.flat()];function Dt(t,e={}){typeof t=="string"&&(t=D(t));let{indent:r=" ",newline:i=`
4
- `,comments:s=!0}=e;if(r||="",i||="",typeof t[0]=="string"&&t[0][0]!==";")return n(t);return t.filter(a=>s||!l(a)).map(a=>n(a)).join(i);function l(a){return typeof a=="string"&&a[1]===";"}function n(a,o=0){if(!Array.isArray(a))return a;let f=a[0];if(!f)return"";let c=!1;if(f==="try_table"){let p=1;for(typeof a[p]=="string"&&a[p][0]==="$"&&(f+=" "+a[p++]),Array.isArray(a[p])&&(a[p][0]==="result"||a[p][0]==="type")&&(f+=" "+n(a[p++],o));Array.isArray(a[p])&&/^catch/.test(a[p][0]);)f+=" "+n(a[p++],o).trim();for(;p<a.length;p++)f+=Array.isArray(a[p])?i+r.repeat(o+1)+n(a[p],o+1):" "+a[p];return`(${f+i+r.repeat(o)})`}let u=!!i&&a.length<4&&!a.some(p=>typeof p=="string"&&p[0]===";"&&p[1]===";"),h=r.repeat(o+1);for(let p=1;p<a.length;p++){let b=a[p].valueOf();if(typeof b=="string"&&b[1]===";"){if(!s)continue;if(b[0]===";")if(i)f+=i+h+b.trimEnd(),c=!0;else{let _=f[f.length-1];_&&_!==" "&&_!=="("&&(f+=" "),f+=b.trimEnd()+`
5
- `}else{let _=f[f.length-1];_&&_!==" "&&_!=="("&&(f+=" "),f+=b.trimEnd()}}else if(Array.isArray(b))u&&(u=b.every(_=>!Array.isArray(_))),f+=i+h+n(b,o+1),c=!1;else if(a[0]==="data")u=!1,(i||f[f.length-1]!==")")&&(f+=i||" "),f+=h+b,c=!1;else{let _=f[f.length-1];c&&i?f+=i+h:_===`
6
- `?f+="":(_&&_!==")"&&_!==" "||i||_===")")&&(f+=" "),f+=b,c=!1}}return u?`(${f.replaceAll(i+h+"("," (")})`:`(${f+i+r.repeat(o)})`}}var Pt={funcref:["ref.func","call_ref","return_call_ref"],sign_ext:["i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s"],nontrapping:["i32.trunc_sat_f32_s","i32.trunc_sat_f32_u","i32.trunc_sat_f64_s","i32.trunc_sat_f64_u","i64.trunc_sat_f32_s","i64.trunc_sat_f32_u","i64.trunc_sat_f64_s","i64.trunc_sat_f64_u"],bulk_memory:["memory.copy","memory.fill"],return_call:["return_call","return_call_indirect"],i31ref:["ref.i31","i31.get_s","i31.get_u"],extended_const:["global.get"],multi_value:[],gc:["struct.new","struct.get","struct.set","array.new","array.get","array.set","array.len","struct.new_default","array.new_default","array.new_fixed","array.copy"],ref_cast:["ref.test","ref.cast","br_on_cast","br_on_cast_fail"]},It=Object.keys(Pt),pe=t=>{if(t===!0)return Object.fromEntries(It.map(e=>[e,!0]));if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return Object.fromEntries(It.map(r=>[r,e.has(r)||e.has("all")]))}return{...t}},q=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)q(t[s],e,t,s)},j=(t,e,r,i)=>{if(Array.isArray(t))for(let s=0;s<t.length;s++)j(t[s],e,t,s);e(t,r,i)},ye=t=>{let e=new Set;return q(t,r=>{if(typeof r=="string")for(let[i,s]of Object.entries(Pt))s.some(l=>r===l||r.startsWith(l+" "))&&e.add(i)}),q(t,r=>{if(!(!Array.isArray(r)||r[0]!=="global"))for(let i of r)Array.isArray(i)&&(i[0]==="i32.add"||i[0]==="i32.sub"||i[0]==="i32.mul"||i[0]==="i64.add"||i[0]==="i64.sub"||i[0]==="i64.mul")&&q(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),q(t,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=0;for(let s of r)Array.isArray(s)&&s[0]==="result"&&(i+=s.length-1);i>1&&e.add("multi_value")}),e},jt=t=>Array.isArray(t)?t.map(jt):t,Rt=(t,e)=>{let r=[],i=t[0]==="module"?1:0;for(let s=i;s<t.length;s++)Array.isArray(t[s])&&t[s][0]===e&&r.push({node:t[s],idx:s});return r},gt=(t,e,r)=>t.splice(e,0,r),ge=0,R=t=>`$__${t}${ge++}`,xe=(t,e)=>{let r=new Set;if(q(t,f=>{Array.isArray(f)&&f[0]==="ref.func"&&r.add(f[1])}),!r.size)return t;let i=R("fntbl"),s=[...r],l=Object.fromEntries(s.map((f,c)=>[f,c])),n=Rt(t,"func"),a=n.length?n[0].idx:t[0]==="module"?1:0;gt(t,a,["table",i,"funcref",["elem",...s]]);let o={};return q(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c)return;let u=[],h=[];for(let p of f){if(Array.isArray(p)&&p[0]==="param")for(let b=1;b<p.length;b++)p[b][0]!=="$"&&u.push(p[b]);if(Array.isArray(p)&&p[0]==="result")for(let b=1;b<p.length;b++)h.push(p[b])}o[c]={params:u,results:h}}),j(t,(f,c,u)=>{if(!(!Array.isArray(f)||!c)){if(f[0]==="ref.func"&&l[f[1]]!==void 0&&(c[u]=["i32.const",l[f[1]]]),f[0]==="call_ref"){let h=f[1],p=f.slice(2);c[u]=["call_indirect",i,["type",h],...p]}if(f[0]==="return_call_ref"){let h=f[1],p=f.slice(2);c[u]=["return_call_indirect",i,["type",h],...p]}}}),t},P={funcref:xe},he={"i32.extend8_s":["i32",24],"i32.extend16_s":["i32",16],"i64.extend8_s":["i64",56n],"i64.extend16_s":["i64",48n],"i64.extend32_s":["i64",32n]},de=(t,e)=>(j(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let l=he[r[0]];if(!l)return;let[n,a]=l,o=r.slice(1);i[s]=[`${n}.shr_s`,[`${n}.shl`,...o,[`${n}.const`,a]],[`${n}.const`,a]]}),t);P.sign_ext=de;var Lt={"i32.trunc_sat_f32_s":{itype:"i32",ftype:"f32",signed:!0,min:-2147483648,max:2147483647},"i32.trunc_sat_f32_u":{itype:"i32",ftype:"f32",signed:!1,min:0,max:4294967295},"i32.trunc_sat_f64_s":{itype:"i32",ftype:"f64",signed:!0,min:-2147483648,max:2147483647},"i32.trunc_sat_f64_u":{itype:"i32",ftype:"f64",signed:!1,min:0,max:4294967295},"i64.trunc_sat_f32_s":{itype:"i64",ftype:"f32",signed:!0,min:-9223372036854775808n,max:9223372036854775807n},"i64.trunc_sat_f32_u":{itype:"i64",ftype:"f32",signed:!1,min:0n,max:18446744073709551615n},"i64.trunc_sat_f64_s":{itype:"i64",ftype:"f64",signed:!0,min:-9223372036854775808n,max:9223372036854775807n},"i64.trunc_sat_f64_u":{itype:"i64",ftype:"f64",signed:!1,min:0n,max:18446744073709551615n}},be=(t,e)=>{let r=new Set;if(q(t,s=>{Array.isArray(s)&&Lt[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:l,ftype:n,signed:a,min:o,max:f}=Lt[s],c=R(`trunc_${l}_${n}_${a?"s":"u"}`);i[s]=c;let u=`${l}.trunc_${n}_${a?"s":"u"}`,h=l==="i64"?0n:0,p=["func",c,["param","$v",n],["result",l],["if",["result",l],[`${n}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${l}.const`,h]],["else",["if",["result",l],[`${n}.lt`,["local.get","$v"],[`${n}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${l}.const`,o]],["else",["if",["result",l],[`${n}.gt`,["local.get","$v"],[`${n}.const`,typeof f=="bigint"?Number(f):f]],["then",[`${l}.const`,f]],["else",[u,["local.get","$v"]]]]]]]]];t.push(p)}return j(t,(s,l,n)=>{!Array.isArray(s)||!l||i[s[0]]&&(l[n]=["call",i[s[0]],...s.slice(1)])}),t};P.nontrapping=be;var Ae=(t,e)=>{let r=new Set,i=new Set;q(t,n=>{if(Array.isArray(n)){if(n[0]==="memory.copy"){let a=typeof n[1]=="number"?n[1]:0,o=typeof n[2]=="number"?n[2]:0;r.add(`${a}_${o}`)}if(n[0]==="memory.fill"){let a=typeof n[1]=="number"?n[1]:0;i.add(a)}}});let s={},l={};for(let n of r){let[a,o]=n.split("_").map(Number),f=R(`memcpy${n==="0_0"?"":"_"+n}`);s[n]=f;let c=a?["i32.store8",a]:["i32.store8"],u=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",f,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...u,["i32.add",["local.get","$src"],["local.get","$i"]]]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}for(let n of i){let a=R(`memset${n===0?"":"_"+n}`);l[n]=a;let o=n?["i32.store8",n]:["i32.store8"];t.push(["func",a,["param","$dst","i32"],["param","$val","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...o,["i32.add",["local.get","$dst"],["local.get","$i"]],["local.get","$val"]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}return j(t,(n,a,o)=>{if(!(!Array.isArray(n)||!a)){if(n[0]==="memory.copy"){let f=typeof n[1]=="number"?n[1]:0,c=typeof n[2]=="number"?n[2]:0,u=n.filter(h=>Array.isArray(h)||typeof h=="string"&&h[0]==="$");a[o]=["call",s[`${f}_${c}`],...u]}if(n[0]==="memory.fill"){let f=typeof n[1]=="number"?n[1]:0,c=n.filter(u=>Array.isArray(u)||typeof u=="string"&&u[0]==="$");a[o]=["call",l[f],...c]}}}),t};P.bulk_memory=Ae;var we=(t,e)=>{let r=!1;return q(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&j(t,(i,s,l)=>{!Array.isArray(i)||!s||(i[0]==="return_call"&&(s[l]=["return",["call",...i.slice(1)]]),i[0]==="return_call_indirect"&&(s[l]=["return",["call_indirect",...i.slice(1)]]))}),t};P.return_call=we;var ve=(t,e)=>(j(t,(r,i,s)=>{if(!(!Array.isArray(r)||!i)&&(r[0]==="ref.i31"&&(i[s]=["i32.and",...r.slice(1),["i32.const",2147483647]]),r[0]==="i31.get_u"&&(i[s]=r.length>1?r[1]:["drop"]),r[0]==="i31.get_s")){let l=r.slice(1);i[s]=["i32.shr_s",["i32.shl",...l,["i32.const",1]],["i32.const",1]]}}),t);P.i31ref=ve;var $e=(t,e)=>{let r={};q(t,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let l=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(l)for(let n=s.length-1;n>=0;n--){let a=s[n];if(Array.isArray(a)&&(a[0]==="i32.const"||a[0]==="i64.const"||a[0]==="f32.const"||a[0]==="f64.const")){r[l]={type:a[0].split(".")[0],value:a[1]};break}}});let i=s=>{if(!Array.isArray(s))return s;let l=s[0];if(l==="global.get"&&r[s[1]]){let n=r[s[1]];return[`${n.type}.const`,n.value]}if(l==="i32.add"||l==="i64.add"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f+c]}}if(l==="i32.sub"||l==="i64.sub"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f-c]}}if(l==="i32.mul"||l==="i64.mul"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f*c]}}return s};return j(t,(s,l,n)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!l)){for(let a=2;a<s.length;a++)if(Array.isArray(s[a])){let o=i(s[a]);o!==s[a]&&(s[a]=o)}}}),t};P.extended_const=$e;var Ie=(t,e)=>{let r=new Map,i=[];if(q(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let o=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null,f=[];for(let c of a)if(Array.isArray(c)&&c[0]==="result")for(let u=1;u<c.length;u++)f.push(c[u]);f.length>1&&o&&r.set(o,f)}),!r.size)return t;let s=Math.max(...[...r.values()].map(a=>a.length)),l={};for(let[a,o]of r)for(let f=1;f<o.length;f++){let c=o[f];if(l[c]||(l[c]=[]),l[c].length<f){let u=R(`ret_${c}_${l[c].length}`);l[c].push(u),i.push(["global",u,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let n=t[0]==="module"?1:0;for(let a of i.reverse())gt(t,n,a);return j(t,(a,o,f)=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!c||!r.has(c))return;let u=r.get(c);for(let h=0;h<a.length;h++)if(Array.isArray(a[h])&&a[h][0]==="result"){a[h]=["result",u[0]];break}}),t};P.multi_value=Ie;var lt={i32:4,i64:8,f32:4,f64:8},ke=(t,e)=>{let r=new Map,i=new Map,s=1;if(q(t,_=>{if(!Array.isArray(_)||_[0]!=="type")return;let x=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:null;if(x){for(let m of _)if(Array.isArray(m)){if(m[0]==="struct"){let d=[];for(let y of m)if(Array.isArray(y)&&y[0]==="field"){let v=typeof y[1]=="string"&&y[1][0]==="$"?y[1]:null,w=v?y[2]:y[1],k=Array.isArray(w)&&w[0]==="mut"?w[1]:w;d.push({name:v,type:k})}r.set(x,{kind:"struct",fields:d}),i.set(x,s++)}if(m[0]==="array"){let d=m[1],y=Array.isArray(d)&&d[0]==="mut"?d[1]:d;r.set(x,{kind:"array",elemType:y}),i.set(x,s++)}}}}),!r.size)return t;let l=Rt(t,"memory").length>0,n=R("alloc"),a=R("heap_ptr"),o=t[0]==="module"?1:0;l||gt(t,o,["memory",1]),gt(t,o+1,["global",a,["mut","i32"],["i32.const",1024]]);let f=["func",n,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",a]],["global.set",a,["i32.add",["global.get",a],["local.get","$size"]]],["local.get","$ptr"]];t.push(f);let c=_=>{let x=4;for(let m of _.fields)x+=lt[m.type]||4;return x},u=(_,x)=>{let m=4;for(let d=0;d<x;d++)m+=lt[_.fields[d].type]||4;return m},h=(_,x)=>{for(let m=0;m<_.fields.length;m++)if(_.fields[m].name===x)return m;return-1},p=0,b=()=>`$__gc_tmp${p++}`;return q(t,_=>{if(!Array.isArray(_)||_[0]!=="func")return;let x=!1,m=!1,d=!1,y=!1;if(q(_,w=>{Array.isArray(w)&&((w[0]==="struct.new"||w[0]==="struct.new_default")&&(x=!0),(w[0]==="array.new"||w[0]==="array.new_default")&&(m=!0,d=!0,y=!0))}),!x&&!m)return;let v=1;for(let w=1;w<_.length;w++){let k=_[w];if(Array.isArray(k)&&(k[0]==="param"||k[0]==="result"||k[0]==="local"||k[0]==="export"||k[0]==="type"))v=w+1;else if(typeof k=="string"&&k[0]==="$")v=w+1;else if(!Array.isArray(k))v=w+1;else break}x&&_.splice(v++,0,["local","$__gc_ptr","i32"]),m&&_.splice(v++,0,["local","$__gc_aptr","i32"]),d&&_.splice(v++,0,["local","$__gc_alen","i32"]),y&&_.splice(v++,0,["local","$__gc_aidx","i32"])}),j(t,(_,x,m)=>{if(!(!Array.isArray(_)||!x)){if(_[0]==="struct.new"||_[0]==="struct.new_default"){let d=_[1],y=r.get(d);if(!y||y.kind!=="struct")return;let v=c(y),w=i.get(d),k=_.slice(2),M="$__gc_ptr",U=[["local.set",M,["call",n,["i32.const",v]]],["i32.store",["local.get",M],["i32.const",w]]];if(_[0]==="struct.new")for(let z=0;z<y.fields.length;z++){let T=y.fields[z],rt=u(y,z),X=T.type==="i64"?"i64.store":T.type==="f32"?"f32.store":T.type==="f64"?"f64.store":"i32.store";U.push([X,["i32.add",["local.get",M],["i32.const",rt]],k[z]||[`${T.type}.const`,0]])}else for(let z=0;z<y.fields.length;z++){let T=y.fields[z],rt=u(y,z),X=T.type==="i64"?"i64.store":T.type==="f32"?"f32.store":T.type==="f64"?"f64.store":"i32.store",Xt=T.type==="i64"?["i64.const",0n]:T.type==="f32"?["f32.const",0]:T.type==="f64"?["f64.const",0]:["i32.const",0];U.push([X,["i32.add",["local.get",M],["i32.const",rt]],Xt])}U.push(["local.get",M]),x[m]=["block",["result","i32"],...U]}if(_[0]==="struct.get"){let d=_[1],y=_[2],v=_[3],w=r.get(d);if(!w||w.kind!=="struct")return;let k=typeof y=="string"&&y[0]==="$"?h(w,y):parseInt(y);if(k<0)return;let M=w.fields[k],U=u(w,k),z=M.type==="i64"?"i64.load":M.type==="f32"?"f32.load":M.type==="f64"?"f64.load":"i32.load";x[m]=[z,["i32.add",v,["i32.const",U]]]}if(_[0]==="struct.set"){let d=_[1],y=_[2],v=_[3],w=_[4],k=r.get(d);if(!k||k.kind!=="struct")return;let M=typeof y=="string"&&y[0]==="$"?h(k,y):parseInt(y);if(M<0)return;let U=k.fields[M],z=u(k,M),T=U.type==="i64"?"i64.store":U.type==="f32"?"f32.store":U.type==="f64"?"f64.store":"i32.store";x[m]=[T,["i32.add",v,["i32.const",z]],w]}if(_[0]==="array.new"||_[0]==="array.new_default"){let d=_[1],y=r.get(d);if(!y||y.kind!=="array")return;let v=i.get(d),w=lt[y.elemType]||4,k=_[0]==="array.new"?_[2]:null,M=_[0]==="array.new"?_[3]:_[2],U="$__gc_aptr",z="$__gc_alen",T="$__gc_aidx",rt=y.elemType==="i64"?"i64.store":y.elemType==="f32"?"f32.store":y.elemType==="f64"?"f64.store":"i32.store",X=[["local.set",z,M],["local.set",U,["call",n,["i32.add",["i32.const",8],["i32.mul",["local.get",z],["i32.const",w]]]]],["i32.store",["local.get",U],["i32.const",v]],["i32.store",["i32.add",["local.get",U],["i32.const",4]],["local.get",z]]];k&&X.push(["local.set",T,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",T],["local.get",z]]],[rt,["i32.add",["i32.add",["local.get",U],["i32.const",8]],["i32.mul",["local.get",T],["i32.const",w]]],k],["local.set",T,["i32.add",["local.get",T],["i32.const",1]]],["br","$loop"]]]),X.push(["local.get",U]),x[m]=["block",["result","i32"],...X]}if(_[0]==="array.get"){let d=_[1],y=_[2],v=_[3],w=r.get(d);if(!w||w.kind!=="array")return;let k=lt[w.elemType]||4,M=w.elemType==="i64"?"i64.load":w.elemType==="f32"?"f32.load":w.elemType==="f64"?"f64.load":"i32.load";x[m]=[M,["i32.add",["i32.add",y,["i32.const",8]],["i32.mul",v,["i32.const",k]]]]}if(_[0]==="array.set"){let d=_[1],y=_[2],v=_[3],w=_[4],k=r.get(d);if(!k||k.kind!=="array")return;let M=lt[k.elemType]||4,U=k.elemType==="i64"?"i64.store":k.elemType==="f32"?"f32.store":k.elemType==="f64"?"f64.store":"i32.store";x[m]=[U,["i32.add",["i32.add",y,["i32.const",8]],["i32.mul",v,["i32.const",M]]],w]}if(_[0]==="array.len"){let d=_[1];x[m]=["i32.load",["i32.add",d,["i32.const",4]]]}}}),t};P.gc=ke;var Ne=(t,e)=>{let r=new Map,i=1;return q(t,s=>{if(!Array.isArray(s)||s[0]!=="type")return;let l=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(l)for(let n of s)Array.isArray(n)&&(n[0]==="struct"||n[0]==="array")&&r.set(l,i++)}),r.size&&j(t,(s,l,n)=>{if(!(!Array.isArray(s)||!l)){if(s[0]==="ref.test"){let a=s[1],o=null;Array.isArray(a)&&a[0]==="ref"&&(o=a[1]==="null"?a[2]:a[1]);let f=s[2],c=r.get(o);c!==void 0&&(l[n]=["if",["result","i32"],["i32.eqz",f],["then",["i32.const",0]],["else",["i32.eq",["i32.load",f],["i32.const",c]]]])}if(s[0]==="ref.cast"){let a=s[1],o=null,f=!1;Array.isArray(a)&&a[0]==="ref"&&(a[1]==="null"?(f=!0,o=a[2]):o=a[1]);let c=s[2],u=r.get(o);if(u!==void 0){let h=R("cast");f?l[n]=["block",["result","i32"],["local",h,"i32"],["local.set",h,c],["if",["i32.and",["i32.ne",["local.get",h],["i32.const",0]],["i32.ne",["i32.load",["local.get",h]],["i32.const",u]]],["then",["unreachable"]]],["local.get",h]]:l[n]=["block",["result","i32"],["local",h,"i32"],["local.set",h,c],["if",["i32.or",["i32.eqz",["local.get",h]],["i32.ne",["i32.load",["local.get",h]],["i32.const",u]]],["then",["unreachable"]]],["local.get",h]]}}if(s[0]==="br_on_cast"){let a=s[1],o=s[2],f=s[3],c=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let h=r.get(u);if(h!==void 0){let p=R("brcast");l[n]=["block",["result","i32"],["local",p,"i32"],["local.set",p,c],["br_if",a,["i32.and",["i32.ne",["local.get",p],["i32.const",0]],["i32.eq",["i32.load",["local.get",p]],["i32.const",h]]]],["local.get",p]]}}if(s[0]==="br_on_cast_fail"){let a=s[1],o=s[2],f=s[3],c=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let h=r.get(u);if(h!==void 0){let p=R("brfail");l[n]=["block",["result","i32"],["local",p,"i32"],["local.set",p,c],["br_if",a,["i32.or",["i32.eqz",["local.get",p]],["i32.ne",["i32.load",["local.get",p]],["i32.const",h]]]],["local.get",p]]}}}}),t};P.ref_cast=Ne;function xt(t,e=!0){typeof t=="string"&&(t=D(t)),t=jt(t),e=pe(e);let r=ye(t),i={uid:0};for(let s of It)r.has(s)&&e[s]!==!1&&P[s]&&(t=P[s](t,i));return t}var Nt={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!0},kt=Object.keys(Nt),Be=t=>{if(t===!0)return{...Nt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.size===1&&kt.includes([...e][0])?Object.fromEntries(kt.map(r=>[r,e.has(r)])):Object.fromEntries(kt.map(r=>[r,e.has(r)||e.has("all")]))}return{...Nt,...t}},O=t=>Array.isArray(t)?t.map(O):t,G=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)G(t[s],e,t,s)},K=(t,e,r,i)=>{if(Array.isArray(t))for(let l=0;l<t.length;l++){let n=K(t[l],e,t,l);n!==void 0&&(t[l]=n)}let s=e(t,r,i);return s!==void 0?s:t},Me=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=new Map,l=new Map,n=[],a=[],o=0,f=0,c=0,u=0,h=0,p=0;for(let m of t.slice(1)){if(!Array.isArray(m))continue;let d=m[0];if(d==="type"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:c;i.set(y,{node:m,idx:c,used:!1}),typeof y=="string"&&i.set(c,i.get(y)),c++}else if(d==="func"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:o,v=m.some(w=>Array.isArray(w)&&w[0]==="export");e.set(y,{node:m,idx:o,used:v}),typeof y=="string"&&e.set(o,e.get(y)),o++}else if(d==="global"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:f,v=m.some(w=>Array.isArray(w)&&w[0]==="export");r.set(y,{node:m,idx:f,used:v}),typeof y=="string"&&r.set(f,r.get(y)),f++}else if(d==="table"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:u,v=m.some(w=>Array.isArray(w)&&w[0]==="export");s.set(y,{node:m,idx:u,used:v}),typeof y=="string"&&s.set(u,s.get(y)),u++}else if(d==="memory"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:h,v=m.some(w=>Array.isArray(w)&&w[0]==="export");l.set(y,{node:m,idx:h,used:v}),typeof y=="string"&&l.set(h,l.get(y)),h++}else if(d==="import"){for(let y of m)if(Array.isArray(y)&&y[0]==="func"){let v=typeof y[1]=="string"&&y[1][0]==="$"?y[1]:p;e.set(v,{node:m,idx:p,used:!0,isImport:!0}),typeof v=="string"&&e.set(p,e.get(v)),p++,o++}}else d==="export"?n.push(m):d==="start"&&a.push(m)}for(let m of n)for(let d of m){if(!Array.isArray(d))continue;let[y,v]=d;y==="func"&&e.has(v)?e.get(v).used=!0:y==="global"&&r.has(v)?r.get(v).used=!0:y==="table"&&s.has(v)?s.get(v).used=!0:y==="memory"&&l.has(v)&&(l.get(v).used=!0)}for(let m of a){let d=m[1];typeof d=="string"&&d[0]!=="$"&&(d=+d),e.has(d)&&(e.get(d).used=!0)}let b=n.length>0||a.length>0;if(!b){for(let[,m]of e)if(m.used){b=!0;break}if(!b){for(let[,m]of r)if(m.used){b=!0;break}}if(!b){for(let[,m]of s)if(m.used){b=!0;break}}if(!b){for(let[,m]of l)if(m.used){b=!0;break}}}if(!b){for(let[,m]of e)m.used=!0;for(let[,m]of r)m.used=!0;for(let[,m]of s)m.used=!0;for(let[,m]of l)m.used=!0}for(let m of t.slice(1))!Array.isArray(m)||m[0]!=="elem"||G(m,d=>{if(Array.isArray(d)&&d[0]==="ref.func"){let y=d[1];e.has(y)&&(e.get(y).used=!0)}typeof d=="string"&&d[0]==="$"&&e.has(d)&&(e.get(d).used=!0)});let _=!0;for(;_;){_=!1;for(let[,m]of e)!m.used||m.isImport||G(m.node,d=>{if(!Array.isArray(d)){typeof d=="string"&&d[0]==="$"&&e.has(d)&&!e.get(d).used&&(e.get(d).used=!0,_=!0);return}let[y,v]=d;if((y==="call"||y==="return_call"||y==="ref.func")&&e.has(v)&&!e.get(v).used&&(e.get(v).used=!0,_=!0),(y==="global.get"||y==="global.set")&&r.has(v)&&!r.get(v).used&&(r.get(v).used=!0,_=!0),y==="call_indirect"||y==="return_call_indirect")for(let w of d)typeof w=="string"&&w[0]==="$"&&s.has(w)&&!s.get(w).used&&(s.get(w).used=!0,_=!0);y==="type"&&i.has(v)&&!i.get(v).used&&(i.get(v).used=!0,_=!0)})}let x=["module"];for(let m of t.slice(1)){if(!Array.isArray(m)){x.push(m);continue}let d=m[0];if(d==="func"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;(y?e.get(y):[...e.values()].find(w=>w.node===m))?.used&&x.push(m)}else if(d==="global"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;(y?r.get(y):[...r.values()].find(w=>w.node===m))?.used&&x.push(m)}else x.push(m)}return x},ze={"i32.add":(t,e)=>t+e|0,"i32.sub":(t,e)=>t-e|0,"i32.mul":(t,e)=>Math.imul(t,e),"i32.div_s":(t,e)=>e!==0?t/e|0:null,"i32.div_u":(t,e)=>e!==0?(t>>>0)/(e>>>0)|0:null,"i32.rem_s":(t,e)=>e!==0?t%e|0:null,"i32.rem_u":(t,e)=>e!==0?(t>>>0)%(e>>>0)|0:null,"i32.and":(t,e)=>t&e,"i32.or":(t,e)=>t|e,"i32.xor":(t,e)=>t^e,"i32.shl":(t,e)=>t<<(e&31),"i32.shr_s":(t,e)=>t>>(e&31),"i32.shr_u":(t,e)=>t>>>(e&31),"i32.rotl":(t,e)=>(e&=31,t<<e|t>>>32-e|0),"i32.rotr":(t,e)=>(e&=31,t>>>e|t<<32-e|0),"i32.eq":(t,e)=>t===e?1:0,"i32.ne":(t,e)=>t!==e?1:0,"i32.lt_s":(t,e)=>t<e?1:0,"i32.lt_u":(t,e)=>t>>>0<e>>>0?1:0,"i32.gt_s":(t,e)=>t>e?1:0,"i32.gt_u":(t,e)=>t>>>0>e>>>0?1:0,"i32.le_s":(t,e)=>t<=e?1:0,"i32.le_u":(t,e)=>t>>>0<=e>>>0?1:0,"i32.ge_s":(t,e)=>t>=e?1:0,"i32.ge_u":(t,e)=>t>>>0>=e>>>0?1:0,"i32.eqz":t=>t===0?1:0,"i32.clz":t=>Math.clz32(t),"i32.ctz":t=>t===0?32:31-Math.clz32(t&-t),"i32.popcnt":t=>{let e=0;for(;t;)e+=t&1,t>>>=1;return e},"i32.wrap_i64":t=>Number(BigInt.asIntN(32,t)),"i64.add":(t,e)=>BigInt.asIntN(64,t+e),"i64.sub":(t,e)=>BigInt.asIntN(64,t-e),"i64.mul":(t,e)=>BigInt.asIntN(64,t*e),"i64.div_s":(t,e)=>e!==0n?BigInt.asIntN(64,t/e):null,"i64.div_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)/BigInt.asUintN(64,e)):null,"i64.rem_s":(t,e)=>e!==0n?BigInt.asIntN(64,t%e):null,"i64.rem_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)%BigInt.asUintN(64,e)):null,"i64.and":(t,e)=>BigInt.asIntN(64,t&e),"i64.or":(t,e)=>BigInt.asIntN(64,t|e),"i64.xor":(t,e)=>BigInt.asIntN(64,t^e),"i64.shl":(t,e)=>BigInt.asIntN(64,t<<(e&63n)),"i64.shr_s":(t,e)=>BigInt.asIntN(64,t>>(e&63n)),"i64.shr_u":(t,e)=>BigInt.asUintN(64,BigInt.asUintN(64,t)>>(e&63n)),"i64.eq":(t,e)=>t===e?1:0,"i64.ne":(t,e)=>t!==e?1:0,"i64.lt_s":(t,e)=>t<e?1:0,"i64.lt_u":(t,e)=>BigInt.asUintN(64,t)<BigInt.asUintN(64,e)?1:0,"i64.gt_s":(t,e)=>t>e?1:0,"i64.gt_u":(t,e)=>BigInt.asUintN(64,t)>BigInt.asUintN(64,e)?1:0,"i64.le_s":(t,e)=>t<=e?1:0,"i64.le_u":(t,e)=>BigInt.asUintN(64,t)<=BigInt.asUintN(64,e)?1:0,"i64.ge_s":(t,e)=>t>=e?1:0,"i64.ge_u":(t,e)=>BigInt.asUintN(64,t)>=BigInt.asUintN(64,e)?1:0,"i64.eqz":t=>t===0n?1:0,"i64.extend_i32_s":t=>BigInt(t),"i64.extend_i32_u":t=>BigInt(t>>>0),"f32.add":(t,e)=>Math.fround(t+e),"f32.sub":(t,e)=>Math.fround(t-e),"f32.mul":(t,e)=>Math.fround(t*e),"f32.div":(t,e)=>Math.fround(t/e),"f32.neg":t=>Math.fround(-t),"f32.abs":t=>Math.fround(Math.abs(t)),"f32.sqrt":t=>Math.fround(Math.sqrt(t)),"f32.ceil":t=>Math.fround(Math.ceil(t)),"f32.floor":t=>Math.fround(Math.floor(t)),"f32.trunc":t=>Math.fround(Math.trunc(t)),"f32.nearest":t=>Math.fround(Math.round(t)),"f64.add":(t,e)=>t+e,"f64.sub":(t,e)=>t-e,"f64.mul":(t,e)=>t*e,"f64.div":(t,e)=>t/e,"f64.neg":t=>-t,"f64.abs":t=>Math.abs(t),"f64.sqrt":t=>Math.sqrt(t),"f64.ceil":t=>Math.ceil(t),"f64.floor":t=>Math.floor(t),"f64.trunc":t=>Math.trunc(t),"f64.nearest":t=>Math.round(t)},$=t=>{if(!Array.isArray(t)||t.length!==2)return null;let[e,r]=t;return e==="i32.const"?{type:"i32",value:Number(r)|0}:e==="i64.const"?{type:"i64",value:BigInt(r)}:e==="f32.const"?{type:"f32",value:Math.fround(Number(r))}:e==="f64.const"?{type:"f64",value:Number(r)}:null},Vt=(t,e)=>t==="i32"?["i32.const",e|0]:t==="i64"?["i64.const",e]:t==="f32"?["f32.const",Math.fround(e)]:t==="f64"?["f64.const",e]:null,Te=t=>K(O(t),e=>{if(!Array.isArray(e))return;let r=e[0],i=ze[r];if(i){if(i.length===1&&e.length===2){let s=$(e[1]);if(!s)return;let l=i(s.value);if(l===null)return;let n=r.startsWith("i64.")&&!r.includes("eqz")?"i64":r.startsWith("f32.")?"f32":r.startsWith("f64.")?"f64":"i32";return Vt(n,l)}if(i.length===2&&e.length===3){let s=$(e[1]),l=$(e[2]);if(!s||!l)return;let n=i(s.value,l.value);if(n===null)return;let o=/\.(eq|ne|[lg][te])/.test(r)?"i32":r.startsWith("i64.")?"i64":r.startsWith("f32.")?"f32":r.startsWith("f64.")?"f64":"i32";return Vt(o,n)}}}),Ee={"i32.add":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.add":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.sub":(t,e)=>$(e)?.value===0?t:null,"i64.sub":(t,e)=>$(e)?.value===0n?t:null,"i32.mul":(t,e)=>{let r=$(t),i=$(e);return r?.value===1?e:i?.value===1?t:null},"i64.mul":(t,e)=>{let r=$(t),i=$(e);return r?.value===1n?e:i?.value===1n?t:null},"i32.div_s":(t,e)=>$(e)?.value===1?t:null,"i32.div_u":(t,e)=>$(e)?.value===1?t:null,"i64.div_s":(t,e)=>$(e)?.value===1n?t:null,"i64.div_u":(t,e)=>$(e)?.value===1n?t:null,"i32.and":(t,e)=>{let r=$(t),i=$(e);return r?.value===-1?e:i?.value===-1?t:null},"i64.and":(t,e)=>{let r=$(t),i=$(e);return r?.value===-1n?e:i?.value===-1n?t:null},"i32.or":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.or":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.xor":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.xor":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.shl":(t,e)=>$(e)?.value===0?t:null,"i32.shr_s":(t,e)=>$(e)?.value===0?t:null,"i32.shr_u":(t,e)=>$(e)?.value===0?t:null,"i64.shl":(t,e)=>$(e)?.value===0n?t:null,"i64.shr_s":(t,e)=>$(e)?.value===0n?t:null,"i64.shr_u":(t,e)=>$(e)?.value===0n?t:null},Ue=t=>K(O(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let r=Ee[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),qe=t=>K(O(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let l=$(s);if(l&&l.value>0&&!(l.value&l.value-1)){let a=Math.log2(l.value);if(Number.isInteger(a))return["i32.shl",i,["i32.const",a]]}let n=$(i);if(n&&n.value>0&&!(n.value&n.value-1)){let a=Math.log2(n.value);if(Number.isInteger(a))return["i32.shl",s,["i32.const",a]]}}if(r==="i64.mul"){let l=$(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let a=BigInt(l.value.toString(2).length-1);return["i64.shl",i,["i64.const",a]]}let n=$(i);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let a=BigInt(n.value.toString(2).length-1);return["i64.shl",s,["i64.const",a]]}}if(r==="i32.div_u"){let l=$(s);if(l&&l.value>0&&!(l.value&l.value-1)){let n=Math.log2(l.value);if(Number.isInteger(n))return["i32.shr_u",i,["i32.const",n]]}}if(r==="i64.div_u"){let l=$(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let n=BigInt(l.value.toString(2).length-1);return["i64.shr_u",i,["i64.const",n]]}}if(r==="i32.rem_u"){let l=$(s);if(l&&l.value>0&&!(l.value&l.value-1))return["i32.and",i,["i32.const",l.value-1]]}if(r==="i64.rem_u"){let l=$(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n)return["i64.and",i,["i64.const",l.value-1n]]}}),Se=t=>K(O(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let i=1;for(;i<e.length;){let o=e[i];if(Array.isArray(o)&&(o[0]==="then"||o[0]==="else"||o[0]==="result"||o[0]==="param")){i++;continue}break}let s=e[i],l=$(s);if(!l)return;let n=null,a=null;for(let o=i+1;o<e.length;o++){let f=e[o];Array.isArray(f)&&(f[0]==="then"?n=f:f[0]==="else"&&(a=f))}if(l.value!==0&&l.value!==0n){if(n&&n.length>1){let o=n.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}else{if(a&&a.length>1){let o=a.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=$(i);return s?s.value===0||s.value===0n?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let i=e[e.length-1],s=$(i);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),Ht=new Set(["unreachable","return","br","br_table"]),Oe=t=>{let e=O(t);return G(e,r=>{if(!Array.isArray(r))return;let i=r[0];if((i==="func"||i==="block"||i==="loop")&&Yt(r),i==="if")for(let s=1;s<r.length;s++)Array.isArray(r[s])&&(r[s][0]==="then"||r[s][0]==="else")&&Yt(r[s])}),e},Yt=t=>{let e=!1,r=-1;for(let i=1;i<t.length;i++){let s=t[i];if(Array.isArray(s)){let l=s[0];if(l==="param"||l==="result"||l==="local"||l==="type"||l==="export")continue;e&&r===-1&&(r=i),Ht.has(l)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),Ht.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},Fe=t=>{let e=O(t);return G(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=[],s=new Map,l=new Set;for(let n=1;n<r.length;n++){let a=r[n];Array.isArray(a)&&(a[0]==="local"&&(i.push({node:a,idx:n}),typeof a[1]=="string"&&a[1][0]==="$"&&s.set(a[1],a[2])),a[0]==="param"&&typeof a[1]=="string"&&a[1][0]==="$"&&(s.set(a[1],a[2]),l.add(a[1])))}G(r,n=>{if(!Array.isArray(n))return;let a=n[0];if(a==="local.get"||a==="local.set"||a==="local.tee"){let o=n[1];typeof o=="string"&&l.add(o)}});for(let n=i.length-1;n>=0;n--){let{idx:a,node:o}=i[n],f=typeof o[1]=="string"&&o[1][0]==="$"?o[1]:null;f&&!l.has(f)&&r.splice(a,1)}}),e},We=t=>{let e=O(t);return G(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=new Map;((l,n=1)=>{for(let a=n;a<l.length;a++){let o=l[a];if(!Array.isArray(o))continue;let f=o[0];if(f==="local.set"&&o.length===3){let c=o[1],u=o[2];$(u)&&typeof c=="string"?i.set(c,u):typeof c=="string"&&i.delete(c)}else if(f==="local.tee"&&o.length===3){let c=o[1],u=o[2];$(u)&&typeof c=="string"?i.set(c,u):typeof c=="string"&&i.delete(c)}else if(f==="local.get"&&o.length===2){let c=o[1];if(typeof c=="string"&&i.has(c)){let u=i.get(c);o.length=0,o.push(...O(u))}}else(f==="block"||f==="loop"||f==="if"||f==="call"||f==="call_indirect")&&i.clear();K(o,c=>{if(!Array.isArray(c)||c[0]!=="local.get"||c.length!==2)return;let u=c[1];if(typeof u=="string"&&i.has(u)){let h=i.get(u);return O(h)}})}})(r)}),e},Ce=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=O(t),r=new Map;for(let i of e.slice(1)){if(!Array.isArray(i)||i[0]!=="func")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let l=[],n=[],a=!1,o=!1;for(let f=1;f<i.length;f++){let c=i[f];if(Array.isArray(c))if(c[0]==="param")if(typeof c[1]=="string"&&c[1][0]==="$")l.push({name:c[1],type:c[2]});else{l=null;break}else c[0]==="local"?a=!0:c[0]==="export"?o=!0:c[0]!=="result"&&c[0]!=="type"&&n.push(c)}if(l&&!a&&!o&&l.length<=2&&n.length===1){let f=new Set(l.map(u=>u.name)),c=!1;G(n[0],u=>{Array.isArray(u)&&(u[0]==="local.set"||u[0]==="local.tee")&&f.has(u[1])&&(c=!0)}),c||r.set(s,{body:n[0],params:l})}}return r.size===0||K(e,i=>{if(!Array.isArray(i)||i[0]!=="call")return;let s=i[1];if(!r.has(s))return;let{body:l,params:n}=r.get(s),a=i.slice(2);if(n.length===0)return O(l);let o=O(l);return K(o,f=>{if(!Array.isArray(f)||f[0]!=="local.get")return;let c=f[1],u=n.findIndex(h=>h.name===c);if(u!==-1&&a[u])return O(a[u])}),o}),e};function ht(t,e=!0){return typeof t=="string"&&(t=D(t)),t=O(t),e=Be(e),e.fold&&(t=Te(t)),e.identity&&(t=Ue(t)),e.strength&&(t=qe(t)),e.branch&&(t=Se(t)),e.propagate&&(t=We(t)),e.inline&&(t=Ce(t)),e.deadcode&&(t=Oe(t)),e.locals&&(t=Fe(t)),e.treeshake&&(t=Me(t)),t}var Gt="\uE000",Kt=t=>{if(!t||typeof t!="string")return null;let e=t.split(".")[0];return/^[if](32|64)|v128/.test(e)?e:/\.(eq|ne|[lg][te]|eqz)/.test(t)||t==="memory.size"||t==="memory.grow"?"i32":null},De=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t;return Kt(r)?Kt(r):r==="local.get"&&e.locals?.[i[0]]?e.locals[i[0]]:r==="call"&&e.funcs?.[i[0]]?e.funcs[i[0]].result?.[0]:null};function Bt(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=Bt(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function Le(t,e){let r=[],i=new Map;return Bt(t,s=>{if(!Array.isArray(s))return s;if(s[0]==="call"&&typeof s[1]=="function"){let l=s[1];if(!i.has(l)){let a=[];for(let c=2;c<s.length;c++){let u=De(s[c]);u&&a.push(u)}let o=r.length,f=l.name||`$fn${o}`;i.set(l,{idx:o,name:f.startsWith("$")?f:"$"+f,params:a,fn:l}),r.push(i.get(l))}let n=i.get(l);s[1]=n.name}return s}),r}function Pe(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function je(t,...e){let r={};if(!Array.isArray(t)&&e.length&&typeof e[e.length-1]=="object"&&e[e.length-1]!==null&&!(e[e.length-1]instanceof Uint8Array)&&(r=e.pop()),Array.isArray(t)&&t.raw){let i=t[0];for(let f=0;f<e.length;f++)i+=Gt+t[f+1];let s=D(i),l=[],n=0;s=Bt(s,f=>{if(f===Gt){let c=e[n++];if(typeof c=="function")return l.push(c),c;if(typeof c=="string"&&(c[0]==="("||/^\s*\(/.test(c))){let u=D(c);return Array.isArray(u)&&Array.isArray(u[0])&&(u._splice=!0),u}return c instanceof Uint8Array?[...c]:c}return f});let a=null;if(l.length){let f=Le(s,l);if(f.length){let c=Pe(f);s[0]==="module"?s.splice(1,0,...c):typeof s[0]=="string"?s=[...c,s]:s.unshift(...c),a={env:{}};for(let u of f)a.env[u.name.slice(1)]=u.fn}}r.polyfill&&(s=xt(s,r.polyfill)),r.optimize&&(s=ht(s,r.optimize));let o=et(s);return a&&(o._imports=a),o}if(r.polyfill||r.optimize){let i=typeof t=="string"?D(t):t;return r.polyfill&&(i=xt(i,r.polyfill)),r.optimize&&(i=ht(i,r.optimize)),et(i)}return et(t)}function Re(t,...e){let r=je(t,...e),i=new WebAssembly.Module(r);return new WebAssembly.Instance(i,r._imports).exports}var pr=Re;export{je as compile,pr as default,ht as optimize,D as parse,xt as polyfill,Dt as print,Re as watr};
1
+ var de=Object.defineProperty;var Ae=(t,e)=>{for(var r in e)de(t,r,{get:e[r],enumerable:!0})};var gt={};Ae(gt,{f32:()=>st,f64:()=>rt,i16:()=>Ie,i32:()=>P,i64:()=>it,i8:()=>$e,uleb:()=>p,uleb5:()=>ve,v128:()=>Et});var I=(t,e=I.loc)=>{if(e!=null&&I.src){let r=1,s=1;for(let i=0;i<e&&i<I.src.length;i++)I.src[i]===`
2
+ `?(r++,s=1):s++;t+=` at ${r}:${s}`}throw Error(t)};var jt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Gt=/^[+-]?(?:0x[\da-f]+|\d+)$/i,be=new TextEncoder,we=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),Rt={n:10,r:13,t:9,'"':34,"'":39,"\\":92},pt=t=>{let e=[],r=1,s,i,n="",l=()=>(n&&e.push(...be.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++):Rt[t[r]]?s=Rt[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},Vt=t=>we.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("_","")):P.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 ve(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 P(t,e=[]){for(typeof t=="string"&&(t=P.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 Ht=t=>!jt.test(t)&&Gt.test(t=t.replaceAll("_",""))?t:I(`Bad int ${t}`),$e=P,Ie=P;P.parse=t=>(t=parseInt(Ht(t)),(t<-2147483648||t>4294967295)&&I("i32 constant out of range"),t);function it(t,e=[]){for(typeof t=="string"?t=it.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 ct=new ArrayBuffer(8),j=new Uint8Array(ct),ke=new Int32Array(ct),Ne=new Float32Array(ct),Me=new Float64Array(ct),Tt=new BigInt64Array(ct);it.parse=t=>(t=Ht(t),t=t[0]==="-"?-BigInt(t.slice(1)):BigInt(t),(t<-0x8000000000000000n||t>0xffffffffffffffffn)&&I("i64 constant out of range"),Tt[0]=t,Tt[0]);var Be=2147483648,Se=2139095040;function st(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=P.parse(t.slice(r+4)),e|=Se,t[0]==="-"&&(e|=Be),ke[0]=e):(e=typeof t=="string"?st.parse(t):t,Ne[0]=e),[j[0],j[1],j[2],j[3]]}var ze=0x8000000000000000n,Te=0x7ff0000000000000n;function rt(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=it.parse(t.slice(r+4)),e|=Te,t[0]==="-"&&(e|=ze),Tt[0]=e):(e=typeof t=="string"?rt.parse(t):t,Me[0]=e),[j[0],j[1],j[2],j[3],j[4],j[5],j[6],j[7]]}rt.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)&&I();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)};st.parse=t=>rt.parse(t,34028234663852886e22);var Et=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 ut=["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"]],O={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 G=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,u;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(),u=e,e+=2,s="@",n++,(c=r).push(r=[]),a(u),r=c;else if(f===40)l(),u=e++,n++,(c=r).push(r=[]),a(u),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&&I("Unclosed quote",e),i>59&&I("Unclosed block comment",e),n>0&&I("Unclosed parenthesis",e),e<t.length&&I("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var Kt=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(Kt).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("\\")?"$"+Vt(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?pt(t):t;function lt(t){typeof t=="string"?(I.src=t,t=G(t)||[]):I.src="",I.loc=0,t=Kt(t)||[];let e=0;if(t[0]==="module"?(e++,L(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return lt(t.slice(++e).map(u=>u.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((u,g)=>{if(g<e||!Array.isArray(u)||u[0]!=="import")return[u];let[,y,...x]=u;if(!x.some(h=>Array.isArray(h)&&h[0]==="item"))return[u];if(Array.isArray(x.at(-1))&&x.at(-1)[0]!=="item"){let h=x.at(-1);return x.slice(0,-1).filter(w=>w[0]==="item").map(([,w])=>["import",y,w,h])}return x.filter(h=>h[0]==="item").map(([,h,w])=>["import",y,h,w])});let r=[];for(let u in O)(r[O[u]]=r[u]=[]).name=u;r.metadata={},t.slice(e).filter(u=>{if(!Array.isArray(u)){let x=I.loc,m=I.src,h;for(;(x=m.indexOf(u,x))>=0;){if(h=m.charCodeAt(x-1),x>0&&(h>47&&h<58||h>64&&h<91||h>96&&h<123||h===95||h===36)){x++;continue}if(h=m.charCodeAt(x+u.length),h>47&&h<58||h>64&&h<91||h>96&&h<123||h===95){x++;continue}break}x>=0&&(I.loc=x),I(`Unexpected token ${u}`)}let[g,...y]=u;if(I.loc=u.loc,g==="@custom")r.custom.push(y);else if(g==="rec")for(let x=0;x<y.length;x++){let[,...m]=y[x];qt(m,r.type);let h=[];for(;m[0]?.[0]==="descriptor"||m[0]?.[0]==="describes";)h.push(m.shift());(m=Yt(m,r)).push(x?!0:[r.type.length,y.length]),h.length&&(m.desc=m.desc?[...h,...m.desc]:h),r.type.push(m)}else if(g==="type"){qt(y,r.type);let x=[];for(;y[0]?.[0]==="descriptor"||y[0]?.[0]==="describes";)x.push(y.shift());let m=Yt(y,r);x.length&&(m.desc=m.desc?[...x,...m.desc]:x),r.type.push(m)}else if(g==="start"||g==="export")r[g].push(y);else return!0}).forEach(u=>{let[g,...y]=u;I.loc=u.loc;let x;g==="import"&&([g,...y]=(x=y).pop());let m=r[g];for(m||I(`Unknown section ${g}`),qt(y,m);y[0]?.[0]==="export";)r.export.push([y.shift()[1],[g,m?.length]]);if(y[0]?.[0]==="import"&&([,...x]=y.shift()),g==="table"){let h=y[0]==="i64",w=h?1:0;if(y[w+1]?.[0]==="elem"){let[v,[,...b]]=[y[w],y[w+1]];y=h?["i64",b.length,b.length,v]:[b.length,b.length,v],r.elem.push([["table",m.length],["offset",[h?"i64.const":"i32.const",h?0n:0]],v,...b])}}else if(g==="memory"){let h=y[0]==="i64",w=h?1:0;if(y[w]?.[0]==="data"){let v=y.find($=>Array.isArray($)&&$[0]==="pagesize")?.[1]??65536,[,...b]=y.splice(w,1)[0],z=""+Math.ceil(b.reduce(($,k)=>$+k.length,0)/v);r.data.push([["memory",m.length],[h?"i64.const":"i32.const",h?0n:0],...b]),y=h?["i64",z,z]:[z,z]}}else if(g==="func"){let[h,w,v]=vt(y,r);h??=bt(w,v,r),!x&&r.code.push([[h,w,v],...et(y,r)]),y=[["type",h]]}else if(g==="tag"){let[h,w]=vt(y,r);h??=bt(w,[],r),y=[["type",h]]}x&&(r.import.push([...x,[g,...y]]),y=null),m.push(y)});let s=(u,g=!0)=>{let y=r[u].filter(Boolean).map(x=>Zt[u](x,r)).filter(Boolean);return u===O.custom?y.flatMap(x=>[u,...T(x)]):y.length?[u,...T(g?T(y):y)]:[]},i=()=>{let u=[];for(let g in r.metadata){let y=T(pt(`"metadata.code.${g}"`)),x=T(r.metadata[g].map(([m,h])=>[...p(m),...T(h.map(([w,v])=>[...p(w),...T(v)]))]));u.push(0,...T([...y,...x]))}return u},n=s(O.global),l=s(O.elem),a=s(O.code),o=i(),f=s(O.data),c=r.strings.length?[O.strings,...T([0,...T(r.strings.map(u=>T(u)))])]:[];return Uint8Array.from([0,97,115,109,1,0,0,0,...s(O.custom),...s(O.type),...s(O.import),...s(O.func),...s(O.table),...s(O.memory),...s(O.tag),...c,...n,...s(O.export),...s(O.start,!1),...l,...s(O.datacount,!1),...a,...o,...f])}var V=t=>t?.[0]==="$"||!isNaN(t),L=t=>t?.[0]==="$",Ot=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")L(t[0])&&r.push(t.shift()),r.push(_t(t,e));else if(s==="else"||s==="end")L(t[0])&&t.shift();else if(s==="select")r.push(wt(t)[1]);else if(s.endsWith("call_indirect")){let i=V(t[0])?t.shift():0,[n,l,a]=vt(t,e);r.push(i,["type",n??bt(l,a,e)])}else s==="table.init"?r.push(V(t[1])?t.shift():0,t.shift()):s==="table.copy"||s==="memory.copy"?r.push(V(t[0])?t.shift():0,V(t[0])?t.shift():0):s.startsWith("table.")?r.push(V(t[0])?t.shift():0):s==="memory.init"?(r.push(...V(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"))&&V(t[0])&&r.push(t.shift());else if(Array.isArray(s)){let i=s[0];if(s.loc!=null&&(I.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(ut[i])){r.push(s);continue}let n=s.slice(1);if(i==="block"||i==="loop")r.push(i),L(n[0])&&r.push(n.shift()),r.push(_t(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];L(n[0])&&o.push(n.shift()),o.push(_t(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),L(n[0])&&r.push(n.shift()),r.push(_t(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 bt=(t,e,r,s="$"+t+">"+e)=>(r.type[s]??=r.type.push(["func",[t,e]])-1,s),Ft=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...s]=t.shift(),i=L(s[0])&&s.shift();i&&(i in r?(()=>{throw Error(`Duplicate ${e} ${i}`)})():r[i]=r.length),r.push(...s)}return r},wt=t=>{let e=Ft(t,"param"),r=Ft(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},vt=(t,e)=>{if(t[0]?.[0]!=="type")return[,...wt(t)];let[,r]=t.shift(),[s,i]=wt(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]]},_t=(t,e)=>{let[r,s,i]=vt(t,e);if(!(!s.length&&!i.length))return!s.length&&i.length===1?["result",...i]:["type",r??bt(s,i,e)]},qt=(t,e)=>{let r=L(t[0])&&t.shift();return r&&(r in e?I(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},Yt=([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=wt(t),e.type["$"+t.join(">")]??=e.type.length):i==="struct"?t=Ft(t,"field"):i==="array"&&([t]=t);let l=[i,t,r,s];return n.length&&(l.desc=n),l},Zt=[([t,...e],r)=>{let s=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(s=e.slice(1)),[...T(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,...T(c[0].map(u=>R(u,e))),...T(c[1].map(u=>R(u,e)))]:f==="array"?[Q.array,...ht(c,e)]:f==="struct"?[Q.struct,...T(c.map(u=>ht(u,e)))]:f==="cont"?[Q.cont,...p(A(c[0]??c,e.type))]:[Q[f]];if(l){let[f,c]=l,u=Array.from({length:c},(g,y)=>{let x=e.type[f+y],m=x.slice(0,4);return x.desc&&(m.desc=x.desc),Zt[O.type](m,e)});return[Q.rec,...T(u)]}else if(i==="sub"||n?.length)return[Q[i],...T(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=xt(s):r==="global"?n=ht(s[0],i):r==="table"?n=[...R(s.pop(),i),...xt(s)]:I(`Unknown kind ${r}`);return[...T(t),...T(e),l,...n]},([[,t]],e)=>p(A(t,e.type)),(t,e)=>{let r=xt(t),s=R(t.shift(),e),[i]=t;return i?[64,0,...s,...r,...nt(i,e)]:[...s,...r]},(t,e)=>xt(t),([t,e],r)=>[...ht(t,r),...nt(e,r)],([t,[e,r]],s)=>[...T(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=nt(a,e)):s||(r=1),F[t[0]]||t[0]?.[0]==="ref"?o=R(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,...T(t.map(i?c=>nt(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(L(o[0])){let f=o.shift();f in e.local?I(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...o)}e.meta={};let n=Qt(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,T([...T(a.map(([o,f])=>[...p(o),...R(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??I("Bad offset",r)),[...s?[2,...p(s),...nt(r,e)]:r?[0,...nt(r,e)]:[1],...T(t.flatMap(i=>qe(i)??[...i]))]},(t,e)=>p(e.data.length),([[,t]],e)=>[0,...p(A(t,e.type))]],R=(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]??I(`Unknown type ${t}`)],ht=(t,e,r=t[0]==="mut"?1:0)=>[...R(r?t[1]:t,e),r],Jt={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),L(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?R(r[1],e):p(A(r[1],e.type)):[F.void]},try_table:(t,e)=>{L(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),s=r?r[0]==="result"?R(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])||L(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?T(r.map(s=>R(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)=>Xt(t,r,V(t[0])&&!Ot(t[0])?A(t.shift(),e.memory):0),opt_memory:(t,e)=>p(A(V(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=R(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=tt(t.shift(),e.block),s=R(t.shift(),e),i=R(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(At(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&I("invalid lane length"),e},memlane:(t,e,r)=>{let s=L(t[0])||V(t[0])&&(Ot(t[1])||V(t[1]))?A(t.shift(),e.memory):0;return[...Xt(t,r,s),...p(At(t.shift()))]},"*":t=>p(t.shift()),labelidx:(t,e)=>p(tt(t.shift(),e.block)),laneidx:t=>[At(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(V(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=>P(t.shift()),i64:t=>it(t.shift()),f32:t=>st(t.shift()),f64:t=>rt(t.shift()),v128:t=>Et(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]}},dt={};(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(" "),ut[n]=r?[r,...p(s)]:[s],l&&(dt[n]=Jt[l])))})(ut);var Qt=(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&&(I.loc=i.loc),I(`Unknown instruction ${i[0]}`));let[...n]=ut[i]||I(`Unknown instruction ${i}`);dt[i]&&(i==="select"&&t[0]?.length?n[0]++:dt[i]===Jt.reftype&&(t[0][1]==="null"||t[0][0]!=="ref")&&n[n.length-1]++,n.push(...dt[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},nt=(t,e)=>Qt(et([t],e),e),A=(t,e,r)=>(r=L(t)?e[t]:+t,r in e?r:I(`Unknown ${e.name} ${t}`)),tt=(t,e,r)=>(r=L(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?I(`Bad label ${t}`):r),Ee=t=>{let e,r,s,i;for(;Ot(t[0]);)[s,i]=t.shift().split("="),s==="offset"?r=+i:s==="align"?e=+i:I(`Unknown param ${s}=${i}`);return(r<0||r>4294967295)&&I(`Bad offset ${r}`),(e<=0||e>4294967295)&&I(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&I(`Bad align ${e}`),[e,r]},Xt=(t,e,r=0)=>{let[s,i]=Ee(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)},qe=t=>{if(!Array.isArray(t))return null;let[e,...r]=t;if(e!=="i8"&&e!=="i16"&&e!=="i32"&&e!=="i64"&&e!=="f32"&&e!=="f64")return null;let s=[],i=new DataView(new ArrayBuffer(8));for(let n of r)e==="i8"?s.push(P.parse(n)&511&255):e==="i16"?(i.setInt16(0,P.parse(n),!0),s.push(...new Uint8Array(i.buffer,0,2))):e==="i32"?(i.setInt32(0,P.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(...st(n)):e==="f64"&&s.push(...rt(n));return s},xt=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)}:At,o=i>=0?p(i):[];return n?[l,...p(a(t.shift())),...p(a(t.shift())),...o]:[l,...p(a(t.shift())),...o]},At=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?P.parse(t):typeof t=="number"?t:I(`Bad int ${t}`);return r>e?I(`Value out of range ${t}`):r},T=t=>[...p(t.length),...t.flat()];function te(t,e={}){typeof t=="string"&&(t=G(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 y=1;for(typeof a[y]=="string"&&a[y][0]==="$"&&(f+=" "+a[y++]),Array.isArray(a[y])&&(a[y][0]==="result"||a[y][0]==="type")&&(f+=" "+l(a[y++],o));Array.isArray(a[y])&&/^catch/.test(a[y][0]);)f+=" "+l(a[y++],o).trim();for(;y<a.length;y++)f+=Array.isArray(a[y])?s+r.repeat(o+1)+l(a[y],o+1):" "+a[y];return`(${f+s+r.repeat(o)})`}let u=!!s&&a.length<4&&!a.some(y=>typeof y=="string"&&y[0]===";"&&y[1]===";"),g=r.repeat(o+1);for(let y=1;y<a.length;y++){let x=a[y].valueOf();if(typeof x=="string"&&x[1]===";"){if(!i)continue;if(x[0]===";")if(s)f+=s+g+x.trimEnd(),c=!0;else{let m=f[f.length-1];m&&m!==" "&&m!=="("&&(f+=" "),f+=x.trimEnd()+`
5
+ `}else{let m=f[f.length-1];m&&m!==" "&&m!=="("&&(f+=" "),f+=x.trimEnd()}}else if(Array.isArray(x))u&&(u=x.every(m=>!Array.isArray(m))),f+=s+g+l(x,o+1),c=!1;else if(a[0]==="data")u=!1,(s||f[f.length-1]!==")")&&(f+=s||" "),f+=g+x,c=!1;else{let m=f[f.length-1];c&&s?f+=s+g:m===`
6
+ `?f+="":(m&&m!==")"&&m!==" "||s||m===")")&&(f+=" "),f+=x,c=!1}}return u?`(${f.replaceAll(s+g+"("," (")})`:`(${f+s+r.repeat(o)})`}}var re={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"]},Ct=Object.keys(re),Oe=t=>{if(t===!0)return Object.fromEntries(Ct.map(e=>[e,!0]));if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return Object.fromEntries(Ct.map(r=>[r,e.has(r)||e.has("all")]))}return{...t}},D=(t,e,r,s)=>{if(e(t,r,s),Array.isArray(t))for(let i=0;i<t.length;i++)D(t[i],e,t,i)},X=(t,e,r,s)=>{if(Array.isArray(t))for(let i=0;i<t.length;i++)X(t[i],e,t,i);e(t,r,s)},Fe=t=>{let e=new Set;return D(t,r=>{if(typeof r=="string")for(let[s,i]of Object.entries(re))i.some(n=>r===n||r.startsWith(n+" "))&&e.add(s)}),D(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")&&D(s,i=>{Array.isArray(i)&&i[0]==="global.get"&&e.add("extended_const")})}),D(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},ie=t=>Array.isArray(t)?t.map(ie):t,se=(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},$t=(t,e,r)=>t.splice(e,0,r),Ce=0,K=t=>`$__${t}${Ce++}`,De=(t,e)=>{let r=new Set;if(D(t,f=>{Array.isArray(f)&&f[0]==="ref.func"&&r.add(f[1])}),!r.size)return t;let s=K("fntbl"),i=[...r],n=Object.fromEntries(i.map((f,c)=>[f,c])),l=se(t,"func"),a=l.length?l[0].idx:t[0]==="module"?1:0;$t(t,a,["table",s,"funcref",["elem",...i]]);let o={};return D(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c)return;let u=[],g=[];for(let y of f){if(Array.isArray(y)&&y[0]==="param")for(let x=1;x<y.length;x++)y[x][0]!=="$"&&u.push(y[x]);if(Array.isArray(y)&&y[0]==="result")for(let x=1;x<y.length;x++)g.push(y[x])}o[c]={params:u,results:g}}),X(t,(f,c,u)=>{if(!(!Array.isArray(f)||!c)){if(f[0]==="ref.func"&&n[f[1]]!==void 0&&(c[u]=["i32.const",n[f[1]]]),f[0]==="call_ref"){let g=f[1],y=f.slice(2);c[u]=["call_indirect",s,["type",g],...y]}if(f[0]==="return_call_ref"){let g=f[1],y=f.slice(2);c[u]=["return_call_indirect",s,["type",g],...y]}}}),t},Y={funcref:De},Le={"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]},We=(t,e)=>(X(t,(r,s,i)=>{if(!Array.isArray(r)||!s)return;let n=Le[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);Y.sign_ext=We;var ee={"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}},Pe=(t,e)=>{let r=new Set;if(D(t,i=>{Array.isArray(i)&&ee[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}=ee[i],c=K(`trunc_${n}_${l}_${a?"s":"u"}`);s[i]=c;let u=`${n}.trunc_${l}_${a?"s":"u"}`,g=n==="i64"?0n:0,y=["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",[u,["local.get","$v"]]]]]]]]];t.push(y)}return X(t,(i,n,l)=>{!Array.isArray(i)||!n||s[i[0]]&&(n[l]=["call",s[i[0]],...i.slice(1)])}),t};Y.nontrapping=Pe;var Re=(t,e)=>{let r=new Set,s=new Set;D(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=K(`memcpy${l==="0_0"?"":"_"+l}`);i[l]=f;let c=a?["i32.store8",a]:["i32.store8"],u=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",f,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...u,["i32.add",["local.get","$src"],["local.get","$i"]]]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}for(let l of s){let a=K(`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 X(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,u=l.filter(g=>Array.isArray(g)||typeof g=="string"&&g[0]==="$");a[o]=["call",i[`${f}_${c}`],...u]}if(l[0]==="memory.fill"){let f=typeof l[1]=="number"?l[1]:0,c=l.filter(u=>Array.isArray(u)||typeof u=="string"&&u[0]==="$");a[o]=["call",n[f],...c]}}}),t};Y.bulk_memory=Re;var je=(t,e)=>{let r=!1;return D(t,s=>{Array.isArray(s)&&(s[0]==="return_call"||s[0]==="return_call_indirect")&&(r=!0)}),r&&X(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};Y.return_call=je;var Ge=(t,e)=>(X(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);Y.i31ref=Ge;var Ve=(t,e)=>{let r={};D(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 X(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};Y.extended_const=Ve;var He=(t,e)=>{let r=new Map,s=[];if(D(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let o=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null,f=[];for(let c of a)if(Array.isArray(c)&&c[0]==="result")for(let u=1;u<c.length;u++)f.push(c[u]);f.length>1&&o&&r.set(o,f)}),!r.size)return t;let 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 u=K(`ret_${c}_${n[c].length}`);n[c].push(u),s.push(["global",u,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let l=t[0]==="module"?1:0;for(let a of s.reverse())$t(t,l,a);return X(t,(a,o,f)=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!c||!r.has(c))return;let u=r.get(c);for(let g=0;g<a.length;g++)if(Array.isArray(a[g])&&a[g][0]==="result"){a[g]=["result",u[0]];break}}),t};Y.multi_value=He;var mt={i32:4,i64:8,f32:4,f64:8},Ye=(t,e)=>{let r=new Map,s=new Map,i=1;if(D(t,m=>{if(!Array.isArray(m)||m[0]!=="type")return;let h=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;if(h){for(let w of m)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],k=Array.isArray($)&&$[0]==="mut"?$[1]:$;v.push({name:z,type:k})}r.set(h,{kind:"struct",fields:v}),s.set(h,i++)}if(w[0]==="array"){let v=w[1],b=Array.isArray(v)&&v[0]==="mut"?v[1]:v;r.set(h,{kind:"array",elemType:b}),s.set(h,i++)}}}}),!r.size)return t;let n=se(t,"memory").length>0,l=K("alloc"),a=K("heap_ptr"),o=t[0]==="module"?1:0;n||$t(t,o,["memory",1]),$t(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=m=>{let h=4;for(let w of m.fields)h+=mt[w.type]||4;return h},u=(m,h)=>{let w=4;for(let v=0;v<h;v++)w+=mt[m.fields[v].type]||4;return w},g=(m,h)=>{for(let w=0;w<m.fields.length;w++)if(m.fields[w].name===h)return w;return-1},y=0,x=()=>`$__gc_tmp${y++}`;return D(t,m=>{if(!Array.isArray(m)||m[0]!=="func")return;let h=!1,w=!1,v=!1,b=!1;if(D(m,$=>{Array.isArray($)&&(($[0]==="struct.new"||$[0]==="struct.new_default")&&(h=!0),($[0]==="array.new"||$[0]==="array.new_default")&&(w=!0,v=!0,b=!0))}),!h&&!w)return;let z=1;for(let $=1;$<m.length;$++){let k=m[$];if(Array.isArray(k)&&(k[0]==="param"||k[0]==="result"||k[0]==="local"||k[0]==="export"||k[0]==="type"))z=$+1;else if(typeof k=="string"&&k[0]==="$")z=$+1;else if(!Array.isArray(k))z=$+1;else break}h&&m.splice(z++,0,["local","$__gc_ptr","i32"]),w&&m.splice(z++,0,["local","$__gc_aptr","i32"]),v&&m.splice(z++,0,["local","$__gc_alen","i32"]),b&&m.splice(z++,0,["local","$__gc_aidx","i32"])}),X(t,(m,h,w)=>{if(!(!Array.isArray(m)||!h)){if(m[0]==="struct.new"||m[0]==="struct.new_default"){let v=m[1],b=r.get(v);if(!b||b.kind!=="struct")return;let z=c(b),$=s.get(v),k=m.slice(2),q="$__gc_ptr",E=[["local.set",q,["call",l,["i32.const",z]]],["i32.store",["local.get",q],["i32.const",$]]];if(m[0]==="struct.new")for(let d=0;d<b.fields.length;d++){let _=b.fields[d],N=u(b,d),U=_.type==="i64"?"i64.store":_.type==="f32"?"f32.store":_.type==="f64"?"f64.store":"i32.store";E.push([U,["i32.add",["local.get",q],["i32.const",N]],k[d]||[`${_.type}.const`,0]])}else for(let d=0;d<b.fields.length;d++){let _=b.fields[d],N=u(b,d),U=_.type==="i64"?"i64.store":_.type==="f32"?"f32.store":_.type==="f64"?"f64.store":"i32.store",J=_.type==="i64"?["i64.const",0n]:_.type==="f32"?["f32.const",0]:_.type==="f64"?["f64.const",0]:["i32.const",0];E.push([U,["i32.add",["local.get",q],["i32.const",N]],J])}E.push(["local.get",q]),h[w]=["block",["result","i32"],...E]}if(m[0]==="struct.get"){let v=m[1],b=m[2],z=m[3],$=r.get(v);if(!$||$.kind!=="struct")return;let k=typeof b=="string"&&b[0]==="$"?g($,b):parseInt(b);if(k<0)return;let q=$.fields[k],E=u($,k),d=q.type==="i64"?"i64.load":q.type==="f32"?"f32.load":q.type==="f64"?"f64.load":"i32.load";h[w]=[d,["i32.add",z,["i32.const",E]]]}if(m[0]==="struct.set"){let v=m[1],b=m[2],z=m[3],$=m[4],k=r.get(v);if(!k||k.kind!=="struct")return;let q=typeof b=="string"&&b[0]==="$"?g(k,b):parseInt(b);if(q<0)return;let E=k.fields[q],d=u(k,q),_=E.type==="i64"?"i64.store":E.type==="f32"?"f32.store":E.type==="f64"?"f64.store":"i32.store";h[w]=[_,["i32.add",z,["i32.const",d]],$]}if(m[0]==="array.new"||m[0]==="array.new_default"){let v=m[1],b=r.get(v);if(!b||b.kind!=="array")return;let z=s.get(v),$=mt[b.elemType]||4,k=m[0]==="array.new"?m[2]:null,q=m[0]==="array.new"?m[3]:m[2],E="$__gc_aptr",d="$__gc_alen",_="$__gc_aidx",N=b.elemType==="i64"?"i64.store":b.elemType==="f32"?"f32.store":b.elemType==="f64"?"f64.store":"i32.store",U=[["local.set",d,q],["local.set",E,["call",l,["i32.add",["i32.const",8],["i32.mul",["local.get",d],["i32.const",$]]]]],["i32.store",["local.get",E],["i32.const",z]],["i32.store",["i32.add",["local.get",E],["i32.const",4]],["local.get",d]]];k&&U.push(["local.set",_,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",_],["local.get",d]]],[N,["i32.add",["i32.add",["local.get",E],["i32.const",8]],["i32.mul",["local.get",_],["i32.const",$]]],k],["local.set",_,["i32.add",["local.get",_],["i32.const",1]]],["br","$loop"]]]),U.push(["local.get",E]),h[w]=["block",["result","i32"],...U]}if(m[0]==="array.get"){let v=m[1],b=m[2],z=m[3],$=r.get(v);if(!$||$.kind!=="array")return;let k=mt[$.elemType]||4,q=$.elemType==="i64"?"i64.load":$.elemType==="f32"?"f32.load":$.elemType==="f64"?"f64.load":"i32.load";h[w]=[q,["i32.add",["i32.add",b,["i32.const",8]],["i32.mul",z,["i32.const",k]]]]}if(m[0]==="array.set"){let v=m[1],b=m[2],z=m[3],$=m[4],k=r.get(v);if(!k||k.kind!=="array")return;let q=mt[k.elemType]||4,E=k.elemType==="i64"?"i64.store":k.elemType==="f32"?"f32.store":k.elemType==="f64"?"f64.store":"i32.store";h[w]=[E,["i32.add",["i32.add",b,["i32.const",8]],["i32.mul",z,["i32.const",q]]],$]}if(m[0]==="array.len"){let v=m[1];h[w]=["i32.load",["i32.add",v,["i32.const",4]]]}}}),t};Y.gc=Ye;var Xe=(t,e)=>{let r=new Map,s=1;return D(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&&X(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],u=r.get(o);if(u!==void 0){let g=K("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",u]]],["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",u]]],["then",["unreachable"]]],["local.get",g]]}}if(i[0]==="br_on_cast"){let a=i[1],o=i[2],f=i[3],c=i[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let g=r.get(u);if(g!==void 0){let y=K("brcast");n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["br_if",a,["i32.and",["i32.ne",["local.get",y],["i32.const",0]],["i32.eq",["i32.load",["local.get",y]],["i32.const",g]]]],["local.get",y]]}}if(i[0]==="br_on_cast_fail"){let a=i[1],o=i[2],f=i[3],c=i[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let g=r.get(u);if(g!==void 0){let y=K("brfail");n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["br_if",a,["i32.or",["i32.eqz",["local.get",y]],["i32.ne",["i32.load",["local.get",y]],["i32.const",g]]]],["local.get",y]]}}}}),t};Y.ref_cast=Xe;function It(t,e=!0){typeof t=="string"&&(t=G(t)),t=ie(t),e=Oe(e);let r=Fe(t),s={uid:0};for(let i of Ct)r.has(i)&&e[i]!==!1&&Y[i]&&(t=Y[i](t,s));return t}var Lt={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},Dt=Object.keys(Lt),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},Ke=t=>{if(t===!0)return{...Lt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.size===1&&Dt.includes([...e][0])?Object.fromEntries(Dt.map(r=>[r,e.has(r)])):Object.fromEntries(Dt.map(r=>[r,e.has(r)||e.has("all")]))}return{...Lt,...t}},S=t=>Array.isArray(t)?t.map(S):t,W=(t,e,r,s)=>{if(e(t,r,s),Array.isArray(t))for(let i=0;i<t.length;i++)W(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},St=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}},Ze=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=(d,_,N,U=!1)=>{let J=typeof _[1]=="string"&&_[1][0]==="$",he=J?_[1]:N,xe=!U&&_.some(Pt=>Array.isArray(Pt)&&Pt[0]==="export"),yt={node:_,idx:N,used:xe,isImport:U};return d.set(he,yt),J&&d.set(N,yt),l.set(_,yt),yt},o=0,f=0,c=0,u=0,g=0,y=[],x=[],m=[];for(let d of t.slice(1)){if(!Array.isArray(d))continue;let _=d[0];if(_==="type")a(s,d,c++);else if(_==="func")a(e,d,o++);else if(_==="global")a(r,d,f++);else if(_==="table")a(i,d,u++);else if(_==="memory")a(n,d,g++);else if(_==="import")for(let N of d)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,u++,!0):N[0]==="memory"&&a(n,N,g++,!0));else _==="export"?x.push(d):_==="start"?m.push(d):_==="elem"&&y.push(d)}let h=[],w=d=>{d&&!d.scanned&&h.push(d)},v=d=>{let _=e.get(d);_&&(_.used||(_.used=!0),w(_))},b=d=>{let _=r.get(d);_&&(_.used=!0)},z=d=>{let _=i.get(d);_&&(_.used=!0)},$=d=>{let _=n.get(d);_&&(_.used=!0)},k=d=>{let _=s.get(d);_&&(_.used=!0)};for(let d of x)for(let _ of d){if(!Array.isArray(_))continue;let[N,U]=_;N==="func"?v(U):N==="global"?b(U):N==="table"?z(U):N==="memory"&&$(U)}for(let d of m){let _=d[1];typeof _=="string"&&_[0]!=="$"&&(_=+_),v(_)}for(let d of y)W(d,_=>{Array.isArray(_)&&_[0]==="ref.func"?v(_[1]):typeof _=="string"&&_[0]==="$"&&v(_)});for(let d of[e,r,i,n])for(let _ of d.values())_.used&&w(_);if(!(x.length>0||m.length>0||y.length>0||h.length>0)){for(let d of[e,r,i,n])for(let _ of d.values())_.used=!0;return t}for(;h.length;){let d=h.pop();d.scanned||(d.scanned=!0,!d.isImport&&W(d.node,_=>{if(!Array.isArray(_)){typeof _=="string"&&_[0]==="$"&&v(_);return}let[N,U]=_;if(N==="call"||N==="return_call"||N==="ref.func")v(U);else if(N==="global.get"||N==="global.set")b(U);else if(N==="type")k(U);else if(N==="call_indirect"||N==="return_call_indirect")for(let J of _)typeof J=="string"&&J[0]==="$"&&z(J)}))}let E=["module"];for(let d of t.slice(1)){if(!Array.isArray(d)){E.push(d);continue}let _=d[0];if(_==="func"||_==="global"||_==="type")l.get(d)?.used&&E.push(d);else if(_==="import"){let N=!1;for(let U of d){if(!Array.isArray(U))continue;if(l.get(U)?.used){N=!0;break}}N&&E.push(d)}else E.push(d)}return E},ne=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),at=t=>(e,r)=>t(e,r)?1:0,kt=t=>(e,r)=>t(e>>>0,r>>>0)?1:0,ft=t=>(e,r)=>t(e,r)?1:0,Nt=t=>(e,r)=>t(BigInt.asUintN(64,e),BigInt.asUintN(64,r))?1:0,Je={"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":[at((t,e)=>t===e),"i32"],"i32.ne":[at((t,e)=>t!==e),"i32"],"i32.lt_s":[at((t,e)=>t<e),"i32"],"i32.lt_u":[kt((t,e)=>t<e),"i32"],"i32.gt_s":[at((t,e)=>t>e),"i32"],"i32.gt_u":[kt((t,e)=>t>e),"i32"],"i32.le_s":[at((t,e)=>t<=e),"i32"],"i32.le_u":[kt((t,e)=>t<=e),"i32"],"i32.ge_s":[at((t,e)=>t>=e),"i32"],"i32.ge_u":[kt((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":[ft((t,e)=>t===e),"i32"],"i64.ne":[ft((t,e)=>t!==e),"i32"],"i64.lt_s":[ft((t,e)=>t<e),"i32"],"i64.lt_u":[Nt((t,e)=>t<e),"i32"],"i64.gt_s":[ft((t,e)=>t>e),"i32"],"i64.gt_u":[Nt((t,e)=>t>e),"i32"],"i64.le_s":[ft((t,e)=>t<=e),"i32"],"i64.le_u":[Nt((t,e)=>t<=e),"i32"],"i64.ge_s":[ft((t,e)=>t>=e),"i32"],"i64.ge_u":[Nt((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(ne(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":[ne,"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},le=(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,Qe=t=>C(S(t),e=>{if(!Array.isArray(e))return;let r=Je[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:le(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:le(i,a)}}),Z=t=>(e,r)=>{let s=M(e),i=M(r);return s?.value===t?r:i?.value===t?e:null},H=t=>(e,r)=>M(r)?.value===t?e:null,tr={"i32.add":Z(0),"i64.add":Z(0n),"i32.sub":H(0),"i64.sub":H(0n),"i32.mul":Z(1),"i64.mul":Z(1n),"i32.div_s":H(1),"i32.div_u":H(1),"i64.div_s":H(1n),"i64.div_u":H(1n),"i32.and":Z(-1),"i64.and":Z(-1n),"i32.or":Z(0),"i64.or":Z(0n),"i32.xor":Z(0),"i64.xor":Z(0n),"i32.shl":H(0),"i32.shr_s":H(0),"i32.shr_u":H(0),"i64.shl":H(0n),"i64.shr_s":H(0n),"i64.shr_u":H(0n)},er=t=>C(S(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let r=tr[e[0]];if(!r)return;let s=r(e[1],e[2]);if(s!==null)return s}),rr=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]]}}),ir=t=>C(S(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let{cond:s,thenBranch:i,elseBranch:n}=St(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}}),ae=new Set(["unreachable","return","br","br_table"]),sr=t=>{let e=S(t);return W(e,r=>{if(!Array.isArray(r))return;let s=r[0];if((s==="func"||s==="block"||s==="loop")&&fe(r),s==="if")for(let i=1;i<r.length;i++)Array.isArray(r[i])&&(r[i][0]==="then"||r[i][0]==="else")&&fe(r[i])}),e},fe=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),ae.has(n)&&(e=!0,r=s+1)}else typeof i=="string"&&(e&&r===-1&&(r=s),ae.has(i)&&(e=!0,r=s+1))}r>0&&r<t.length&&t.splice(r)},nr=t=>{let e=S(t);return W(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])))}W(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},lr=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"]),ar=[".store","memory.",".atomic."],ot=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||lr.has(e))return!1;for(let r of ar)if(e.includes(r))return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!ot(t[r]))return!1;return!0},Mt=t=>{let e=new Map,r=s=>(e.has(s)||e.set(s,{gets:0,sets:0,tees:0}),e.get(s));return W(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},me=t=>M(t.val)||t.pure&&t.singleUse,oe=(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&&me(s))return S(s.val)}),fr=(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"){oe(a[2],n);let f=i(a[1]);n.set(a[1],{val:a[2],pure:ot(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&&me(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);oe(a,n),B(f,a)||(s=!0)}}}return s},or=(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},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};o.sets+o.gets+o.tees<=2||(t.splice(i,2,["local.tee",a,S(n[2])]),s=!0)}return s},ur=(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&&ot(l[2])||l[0]==="local"&&a[0]==="$"&&o.gets===0&&o.sets===0&&o.tees===0)&&(t.splice(n,1),s=!0)}return s},mr=t=>{let e=S(t);return W(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(fr(r,s,Mt(r))&&(n=!0),or(r,s,Mt(r))&&(n=!0),cr(r,s,Mt(r))&&(n=!0),ur(r,s,Mt(r))&&(n=!0),!n)break}}),e},yr=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(u=>u.name)),c=!1;W(l[0],u=>{Array.isArray(u)&&(u[0]==="local.set"||u[0]==="local.tee")&&f.has(u[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],u=l.findIndex(g=>g.name===c);if(u!==-1&&a[u])return S(a[u])}),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&&ot(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}=St(e),l=!i||i.length<=1,a=!n||n.length<=1;if(l&&a)return ot(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)&&ot(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},_r=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}),hr=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)}W(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))})},xr=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],u=f[2],g=M(c),y=M(u),x=null,m=null;if(g&&g.type==="i32"?(m=g.value,x=u):y&&y.type==="i32"&&(m=y.value,x=c),x===null||m===null)return;let h=i+m,w=[r];n!==null&&w.push(n),w.push(`offset=${h}`);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(x),s&&w.push(e[o]),w}),dr=t=>{let e=S(t);return W(e,r=>{if(!Array.isArray(r))return;let s=r[0];if(s!=="block"&&s!=="loop")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},Ar=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=new Set;return W(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}})},br=t=>C(S(t),e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{cond:r,thenBranch:s,elseBranch:i}=St(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]]}}),wr=t=>C(S(t),e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{thenBranch:r,elseBranch:s}=St(e);if(!r||!s||r.length<=1||s.length<=1)return;let i=0,n=Math.min(r.length,s.length);for(let u=1;u<n&&B(r[r.length-u],s[s.length-u]);u++)i++;if(i===0)return;let l=r.slice(r.length-i),a=r.slice(0,r.length-i),o=s.slice(0,s.length-i),f=["block"];for(let u=1;u<e.length;u++){let g=e[u];if(Array.isArray(g)&&(g[0]==="then"||g[0]==="else"))break;Array.isArray(g)&&(g[0]==="result"||g[0]==="type")&&f.push(g)}let c=["if"];for(let u=1;u<e.length;u++){let g=e[u];if(Array.isArray(g)&&(g[0]==="then"||g[0]==="else"))break;c.push(g)}return c.push(a.length>1?a:["then"]),c.push(o.length>1?o:["else"]),f.push(c,...l),f}),ye=(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(",")},vr=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]),W(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=ye(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},$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]!=="type")continue;let n=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!n)continue;let l=ye(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},Bt=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+'"'},Ir=t=>{let e=[];for(let s of t)if(typeof s=="string")e.push(...Bt(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)))]},kr=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},ce=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+=Bt(i).length;else if(Array.isArray(i)&&i[0]==="i8")r+=i.length-1;else return null}return r},Nr=(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=Bt(i[0]),a=Bt(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},Mr=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=Ir(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=kr(n);if(l){let a=ce(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&&Nr(n.node,l.node)&&(s.add(l.index),n.len=ce(n.node))}return s.size>0&&(e=e.filter((i,n)=>!s.has(n))),e},ue=()=>{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)}},Br=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=S(t),r=ue(),s=ue();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},Sr=t=>{let e=!0;return W(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},zr=t=>{if(!Array.isArray(t)||t[0]!=="module"||!Sr(t))return t;let e=S(t),r=new Map;W(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 zt(t,e=!0){typeof t=="string"&&(t=G(t)),t=S(t),e=Ke(e);for(let r=0;r<6;r++){let s=t;if(e.stripmut&&(t=Ar(t)),e.globals&&(t=hr(t)),e.fold&&(t=Qe(t)),e.identity&&(t=er(t)),e.peephole&&(t=_r(t)),e.strength&&(t=rr(t)),e.branch&&(t=ir(t)),e.propagate&&(t=mr(t)),e.inline&&(t=yr(t)),e.offset&&(t=xr(t)),e.unbranch&&(t=dr(t)),e.brif&&(t=br(t)),e.foldarms&&(t=wr(t)),e.deadcode&&(t=sr(t)),e.vacuum&&(t=pr(t)),e.locals&&(t=nr(t)),e.dedupe&&(t=vr(t)),e.dedupTypes&&(t=$r(t)),e.packData&&(t=Mr(t)),e.reorder&&(t=zr(t)),e.treeshake&&(t=Ze(t)),e.minifyImports&&(t=Br(t)),B(s,t))break}return t}var ge="\uE000",_e=t=>{if(!t||typeof t!="string")return null;let e=t.split(".")[0];return/^[if](32|64)|v128/.test(e)?e:/\.(eq|ne|[lg][te]|eqz)/.test(t)||t==="memory.size"||t==="memory.grow"?"i32":null},Tr=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...s]=t;return _e(r)?_e(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 Wt(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let s=Wt(t[r],e);s?._splice?(t.splice(r,1,...s),r+=s.length-1):t[r]=s}return t}function Er(t,e){let r=[],s=new Map;return Wt(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 u=Tr(i[c]);u&&a.push(u)}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 qr(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=G(s),n=[],l=0;i=Wt(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 u=G(c);return Array.isArray(u)&&Array.isArray(u[0])&&(u._splice=!0),u}return c.byteLength!==void 0?[...c]:c}return f});let a=null;if(n.length){let f=Er(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 u of f)a.env[u.name.slice(1)]=u.fn}}r.polyfill&&(i=It(i,r.polyfill)),r.optimize&&(i=zt(i,r.optimize));let o=lt(i);return a&&(o._imports=a),o}if(r.polyfill||r.optimize){let s=typeof t=="string"?G(t):t;return r.polyfill&&(s=It(s,r.polyfill)),r.optimize&&(s=zt(s,r.optimize)),lt(s)}return lt(t)}function Or(t,...e){let r=qr(t,...e),s=new WebAssembly.Module(r);return new WebAssembly.Instance(s,r._imports).exports}var li=Or;export{qr as compile,li as default,zt as optimize,G as parse,It as polyfill,te as print,Or as watr};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watr",
3
- "version": "4.3.3",
3
+ "version": "4.4.0",
4
4
  "description": "Light & fast WAT compiler – WebAssembly Text to binary, parse, print, transform",
5
5
  "main": "watr.js",
6
6
  "bin": {