watr 4.6.5 → 4.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/watr.js +20 -3
- package/dist/watr.min.js +1 -1
- package/dist/watr.wasm +0 -0
- package/package.json +1 -1
- package/src/optimize.js +20 -3
- package/types/src/optimize.d.ts.map +1 -1
package/dist/watr.js
CHANGED
|
@@ -3987,9 +3987,16 @@ var eliminateDeadStores = (funcNode, params, useCounts) => {
|
|
|
3987
3987
|
const name2 = typeof sub[1] === "string" ? sub[1] : null;
|
|
3988
3988
|
if (!name2 || params.has(name2)) continue;
|
|
3989
3989
|
const uses = getPostUseCount(name2);
|
|
3990
|
-
if (sub[0] === "local.set" && uses.gets === 0 && uses.tees === 0
|
|
3991
|
-
|
|
3992
|
-
|
|
3990
|
+
if (sub[0] === "local.set" && uses.gets === 0 && uses.tees === 0) {
|
|
3991
|
+
if (sub.length === 3) {
|
|
3992
|
+
if (isPure(sub[2])) {
|
|
3993
|
+
funcNode.splice(i, 1);
|
|
3994
|
+
changed = true;
|
|
3995
|
+
}
|
|
3996
|
+
} else if (sub.length === 2) {
|
|
3997
|
+
funcNode[i] = ["drop"];
|
|
3998
|
+
changed = true;
|
|
3999
|
+
}
|
|
3993
4000
|
} else if (sub[0] === "local" && name2[0] === "$" && uses.gets === 0 && uses.sets === 0 && uses.tees === 0) {
|
|
3994
4001
|
funcNode.splice(i, 1);
|
|
3995
4002
|
changed = true;
|
|
@@ -4313,6 +4320,16 @@ var targetsLabel = (body, label) => {
|
|
|
4313
4320
|
}
|
|
4314
4321
|
} else break;
|
|
4315
4322
|
}
|
|
4323
|
+
} else if (op === "catch" || op === "catch_ref") {
|
|
4324
|
+
if (n[2] === label) {
|
|
4325
|
+
found = true;
|
|
4326
|
+
return;
|
|
4327
|
+
}
|
|
4328
|
+
} else if (op === "catch_all" || op === "catch_all_ref") {
|
|
4329
|
+
if (n[1] === label) {
|
|
4330
|
+
found = true;
|
|
4331
|
+
return;
|
|
4332
|
+
}
|
|
4316
4333
|
}
|
|
4317
4334
|
}
|
|
4318
4335
|
for (let i = 1; i < n.length; i++) search(n[i], inner);
|
package/dist/watr.min.js
CHANGED
|
@@ -3,4 +3,4 @@ var Re=Object.defineProperty;var We=(t,e)=>{for(var r in e)Re(t,r,{get:e[r],enum
|
|
|
3
3
|
`,e)<0?-2:-1,i=t[e++]+t[e++];else if(a===40&&t.charCodeAt(e+1)===64)l(),u=e,e+=2,i="@",n++,(c=r).push(r=[]),f(u),r=c;else if(a===40)l(),u=e++,n++,(c=r).push(r=[]),f(u),r=c;else{if(a===41)return l(),e++,n--;a<=32?(l(),e++):i+=t[e++]}s<0&&l(),l()};return f(0),s===34&&B("Unclosed quote",e),s>59&&B("Unclosed block comment",e),n>0&&B("Unclosed parenthesis",e),e<t.length&&B("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var me=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(me).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("\\")?"$"+fe(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?wt(t):t;function ct(t){typeof t=="string"?(B.src=t,t=Z(t)||[]):B.src="",B.loc=0,t=me(t)||[];let e=0;if(t[0]==="module"?(e++,G(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return ct(t.slice(++e).map(u=>u.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((u,m)=>{if(m<e||!Array.isArray(u)||u[0]!=="import")return[u];let[,y,...g]=u;if(!g.some(_=>Array.isArray(_)&&_[0]==="item"))return[u];if(Array.isArray(g.at(-1))&&g.at(-1)[0]!=="item"){let _=g.at(-1);return g.slice(0,-1).filter(b=>b[0]==="item").map(([,b])=>["import",y,b,_])}return g.filter(_=>_[0]==="item").map(([,_,b])=>["import",y,_,b])});let r=[];for(let u in D)(r[D[u]]=r[u]=[]).name=u;r.metadata={},t.slice(e).filter(u=>{if(!Array.isArray(u)){let g=B.loc,p=B.src,_;for(;(g=p.indexOf(u,g))>=0;){if(_=p.charCodeAt(g-1),g>0&&(_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95||_===36)){g++;continue}if(_=p.charCodeAt(g+u.length),_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95){g++;continue}break}g>=0&&(B.loc=g),B(`Unexpected token ${u}`)}let[m,...y]=u;if(B.loc=u.loc,m==="@custom")r.custom.push(y);else if(m==="rec")for(let g=0;g<y.length;g++){let[,...p]=y[g];Pt(p,r.type);let _=[];for(;p[0]?.[0]==="descriptor"||p[0]?.[0]==="describes";)_.push(p.shift());(p=ue(p,r)).push(g?!0:[r.type.length,y.length]),_.length&&(p.desc=p.desc?[..._,...p.desc]:_),r.type.push(p)}else if(m==="type"){Pt(y,r.type);let g=[];for(;y[0]?.[0]==="descriptor"||y[0]?.[0]==="describes";)g.push(y.shift());let p=ue(y,r);g.length&&(p.desc=p.desc?[...g,...p.desc]:g),r.type.push(p)}else if(m==="start"||m==="export")r[m].push(y);else return!0}).forEach(u=>{let[m,...y]=u;B.loc=u.loc;let g;m==="import"&&([m,...y]=(g=y).pop());let p=r[m];for(p||B(`Unknown section ${m}`),Pt(y,p);y[0]?.[0]==="export";)r.export.push([y.shift()[1],[m,p?.length]]);if(y[0]?.[0]==="import"&&([,...g]=y.shift()),m==="table"){let _=y[0]==="i64",b=_?1:0;if(y[b+1]?.[0]==="elem"){let[v,[,...A]]=[y[b],y[b+1]];y=_?["i64",A.length,A.length,v]:[A.length,A.length,v],r.elem.push([["table",p.length],["offset",[_?"i64.const":"i32.const",_?0n:0]],v,...A])}}else if(m==="memory"){let _=y[0]==="i64",b=_?1:0;if(y[b]?.[0]==="data"){let v=y.find(I=>Array.isArray(I)&&I[0]==="pagesize")?.[1]??65536,[,...A]=y.splice(b,1)[0],S=""+Math.ceil(A.reduce((I,M)=>I+M.length,0)/v);r.data.push([["memory",p.length],[_?"i64.const":"i32.const",_?0n:0],...A]),y=_?["i64",S,S]:[S,S]}}else if(m==="func"){let[_,b,v]=zt(y,r);_??=Nt(b,v,r),!g&&r.code.push([[_,b,v],...ft(y,r)]),y=[["type",_]]}else if(m==="tag"){let[_,b]=zt(y,r);_??=Nt(b,[],r),y=[["type",_]]}g&&(r.import.push([...g,[m,...y]]),y=null),p.push(y)});let i=(u,m=!0)=>{let y=r[u].filter(Boolean).map(g=>pe[u](g,r)).filter(Boolean);return u===D.custom?y.flatMap(g=>[u,...O(g)]):y.length?[u,...O(m?O(y):y.flat())]:[]},s=()=>{let u=[];for(let m in r.metadata){let y=O(wt(`"metadata.code.${m}"`)),g=O(r.metadata[m].map(([p,_])=>[...h(p),...O(_.map(([b,v])=>[...h(b),...O(v)]))]));u.push(0,...O([...y,...g]))}return u},n=i(D.global),l=i(D.elem),f=i(D.code),o=s(),a=i(D.data),c=r.strings.length?[D.strings,...O([0,...O(r.strings.map(u=>O(u)))])]:[];return Uint8Array.from([0,97,115,109,1,0,0,0,...i(D.custom),...i(D.type),...i(D.import),...i(D.func),...i(D.table),...i(D.memory),...i(D.tag),...c,...n,...i(D.export),...i(D.start,!1),...l,...i(D.datacount,!1),...f,...o,...a])}var K=t=>t?.[0]==="$"||!isNaN(t),G=t=>t?.[0]==="$",jt=t=>t?.[0]==="a"||t?.[0]==="o";function ft(t,e){let r=[];for(t=[...t];t.length;){let i=t.shift();if(typeof i=="string")if(r.push(i),i==="block"||i==="if"||i==="loop")G(t[0])&&r.push(t.shift()),r.push($t(t,e));else if(i==="else"||i==="end")G(t[0])&&t.shift();else if(i==="select")r.push(St(t)[1]);else if(i.endsWith("call_indirect")){let s=K(t[0])?t.shift():0,[n,l,f]=zt(t,e);r.push(s,["type",n??Nt(l,f,e)])}else i==="table.init"?r.push(K(t[1])?t.shift():0,t.shift()):i==="table.copy"||i==="memory.copy"?r.push(K(t[0])?t.shift():0,K(t[0])?t.shift():0):i.startsWith("table.")?r.push(K(t[0])?t.shift():0):i==="memory.init"?(r.push(...K(t[1])?[t.shift(),t.shift()].reverse():[t.shift(),0]),e.datacount&&(e.datacount[0]=!0)):i==="data.drop"||i==="array.new_data"||i==="array.init_data"?(i==="data.drop"&&r.push(t.shift()),e.datacount&&(e.datacount[0]=!0)):(i.startsWith("memory.")||i.endsWith("load")||i.endsWith("store"))&&K(t[0])&&r.push(t.shift());else if(Array.isArray(i)){let s=i[0];if(i.loc!=null&&(B.loc=i.loc),s?.startsWith?.("@metadata.code.")){let l=s.slice(15);r.push(["@metadata",l,i[1]]);continue}if(typeof s!="string"||!Array.isArray(At[s])){r.push(i);continue}let n=i.slice(1);if(s==="block"||s==="loop")r.push(s),G(n[0])&&r.push(n.shift()),r.push($t(n,e),...ft(n,e),"end");else if(s==="if"){let l=[],f=[];n.at(-1)?.[0]==="else"&&(f=ft(n.pop().slice(1),e)),n.at(-1)?.[0]==="then"&&(l=ft(n.pop().slice(1),e));let o=[s];G(n[0])&&o.push(n.shift()),o.push($t(n,e)),r.push(...ft(n,e),...o,...l),f.length&&r.push("else",...f),r.push("end")}else if(s==="try_table"){for(r.push(s),G(n[0])&&r.push(n.shift()),r.push($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(...ft(n,e),"end")}else if(s==="ref.test"||s==="ref.cast"){let l=n[0];(!Array.isArray(l)||l[1]==="null"||l[0]!=="ref")&&(s+="_null"),r.push(...ft(n.slice(1),e),s,l),t.unshift(...r.splice(r.length-2))}else{let l=[];for(;n.length&&(!Array.isArray(n[0])||n[0].valueOf!==Array.prototype.valueOf||"type,param,result,ref,exact,on".includes(n[0][0]));)l.push(n.shift());r.push(...ft(n,e),s,...l),t.unshift(...r.splice(r.length-1-l.length))}}else r.push(i)}return r}var Nt=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),Gt=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=G(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},St=t=>{let e=Gt(t,"param"),r=Gt(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},zt=(t,e)=>{if(t[0]?.[0]!=="type")return[,...St(t)];let[,r]=t.shift(),[i,s]=St(t),n=e.type[typeof r=="string"&&isNaN(r)?e.type[r]:+r];if(!n)throw Error(`Unknown type ${r}`);if((i.length||s.length)&&n[1].join(">")!==i+">"+s)throw Error(`Type ${r} mismatch`);return[r,...n[1]]},$t=(t,e)=>{let[r,i,s]=zt(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??Nt(i,s,e)]},Pt=(t,e)=>{let r=G(t[0])&&t.shift();return r&&(r in e?B(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},ue=([t],e)=>{let r="subfinal",i=[],s,n=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(i=t).pop(),i=i.filter(f=>Array.isArray(f)&&(f[0]==="descriptor"||f[0]==="describes")?(n.push(f),!1):!0)),[s,...t]=t,s==="func"?(t=St(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=Gt(t,"field"):s==="array"&&([t]=t);let l=[s,t,r,i];return n.length&&(l.desc=n),l},pe=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...O(t),...i.flat()]},(t,e)=>{let[r,i,s,n,l]=t;if(l===!0)return;let f=(t.desc??[]).flatMap(([a,c])=>[a==="descriptor"?77:76,...h($(c,e.type))]),o=(a,c)=>a==="func"?[at.func,...O(c[0].map(u=>Y(u,e))),...O(c[1].map(u=>Y(u,e)))]:a==="array"?[at.array,...It(c,e)]:a==="struct"?[at.struct,...O(c.map(u=>It(u,e)))]:a==="cont"?[at.cont,...h($(c[0]??c,e.type))]:[at[a]];if(l){let[a,c]=l,u=Array.from({length:c},(m,y)=>{let g=e.type[a+y],p=g.slice(0,4);return g.desc&&(p.desc=g.desc),pe[D.type](p,e)});return[at.rec,...O(u)]}else if(s==="sub"||n?.length)return[at[s],...O(n.map(a=>$(a,e.type))),...f,...o(r,i)];return[...f,...o(r,i)]},([t,e,[r,...i]],s)=>{let n,l=Wt[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(l=32);let[[,o]]=i;n=h($(o,s.type))}else if(r==="tag"){let[[,f]]=i;n=[0,...h($(f,s.type))]}else r==="memory"?n=kt(i):r==="global"?n=It(i[0],s):r==="table"?n=[...Y(i.pop(),s),...kt(i)]:B(`Unknown kind ${r}`);return[...O(t),...O(e),l,...n]},([[,t]],e)=>h($(t,e.type)),(t,e)=>{let r=kt(t),i=Y(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...gt(s,e)]:[...i,...r]},(t,e)=>kt(t),([t,e],r)=>[...It(t,r),...gt(e,r)],([t,[e,r]],i)=>[...O(t),Wt[e],...h($(r,i[e]))],([t],e)=>h($(t,e.func)),(t,e)=>{let r=0,i=0,s=0,n=0,l,f,o;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,l]=t.shift(),l=$(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=$(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(f=t.shift(),f[0]==="offset"&&([,f]=f),f=gt(f,e)):i||(r=1),R[t[0]]||t[0]?.[0]==="ref"?o=Y(t.shift(),e):t[0]==="func"?o=[R[t.shift()]]:o=[R.func],t=t.map(c=>(c[0]==="item"&&(c=c.length===3&&c[1]==="ref.func"?c[2]:c[1]),c[0]==="ref.func"&&([,c]=c),typeof c!="string"&&(s=1),c)),o[0]!==R.funcref&&(n=1,s=1);let a=s<<2|(r||i?i:!!l||n)<<1|(r||i);return[a,...a===0?f:a===1?[0]:a===2?[...h(l||0),...f,0]:a===3?[0]:a===4?f:a===5?o:a===6?[...h(l||0),...f,...o]:o,...O(t.map(s?c=>gt(typeof c=="string"?["ref.func",c]:c,e):c=>h($(c,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[$(r,e.type)]),e.local=Object.create(i),e.block=[],e.local.name="local",e.block.name="block",e._codeIdx===void 0&&(e._codeIdx=0);let s=e._codeIdx++;for(;t[0]?.[0]==="local";){let[,...o]=t.shift();if(G(o[0])){let a=o.shift();a in e.local?B(`Duplicate local ${a}`):e.local[a]=e.local.length}e.local.push(...o)}e.meta={};let n=_e(t,e),l=e.import.filter(o=>o[2][0]==="func").length+s;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([l,e.meta[o]]);let f=e.local.slice(i.length).reduce((o,a)=>(a==o[o.length-1]?.[1]?o[o.length-1][0]++:o.push([1,a]),o),[]);return e.local=e.block=e.meta=null,O([...O(f.map(([o,a])=>[...h(o),...Y(a,e)])),...n])},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=$(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=$(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??B("Bad offset",r)),[...i?[2,...h(i),...gt(r,e)]:r?[0,...gt(r,e)]:[1],...O(t.flatMap(s=>ir(s)??[...s]))]},(t,e)=>h(e.data.length),([[,t]],e)=>[0,...h($(t,e.type))]],Y=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[R.refnull,98,...h($(t[2][1],e.type))]:R[t[2]]?[R[t[2]]]:[R.refnull,...h($(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[R.ref,98,...h($(t[1][1],e.type))]:[R.ref,...h(R[t[t.length-1]]||$(t[t.length-1],e.type))]:[R[t]??B(`Unknown type ${t}`)],It=(t,e,r=t[0]==="mut"?1:0)=>[...Y(r?t[1]:t,e),r],ge={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...h($(i,e.elem)),...h($(r,e.table))]},block:(t,e)=>{e.block.push(1),G(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?Y(r[1],e):h($(r[1],e.type)):[R.void]},try_table:(t,e)=>{G(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?Y(r[1],e):h($(r[1],e.type)):[R.void],s=[],n=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let l=t.shift(),f=l[0]==="catch"?0:l[0]==="catch_ref"?1:l[0]==="catch_all"?2:3;f<=1?s.push(f,...h($(l[1],e.tag)),...h(ot(l[2],e.block))):s.push(f,...h(ot(l[1],e.block))),n++}return e.block.push(1),[...i,...h(n),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...h($(i,e.type)),...h($(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||G(t[0]));)r.push(...h(ot(t.shift(),e.block))),i++;return[...h(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?O(r.map(i=>Y(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...h($(r[1],e.type))]:R[r]?[R[r]]:h($(r,e.type))},memarg:(t,e,r)=>ye(t,r,K(t[0])&&!jt(t[0])?$(t.shift(),e.memory):0),opt_memory:(t,e)=>h($(K(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=Y(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=ot(t.shift(),e.block),i=Y(t.shift(),e),s=Y(t.shift(),e),n=l=>l.length>1?l.slice(1):l;return[(s[0]!==R.ref)<<1|i[0]!==R.ref,...h(r),...n(i),...n(s)]},v128const:t=>{let[e,r]=t.shift().split("x"),i=+e.slice(1),s=i>>>3;if(r=+r,e[0]==="i"){let l=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let f=0;f<r;f++)l[f]=vt[e].parse(t.shift());return[...new Uint8Array(l.buffer)]}let n=new Uint8Array(16);for(let l=0;l<r;l++)n.set(vt[e](t.shift()),l*s);return[...n]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(Bt(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&B("invalid lane length"),e},memlane:(t,e,r)=>{let i=G(t[0])||K(t[0])&&(jt(t[1])||K(t[1]))?$(t.shift(),e.memory):0;return[...ye(t,r,i),...h(Bt(t.shift()))]},"*":t=>h(t.shift()),labelidx:(t,e)=>h(ot(t.shift(),e.block)),laneidx:t=>[Bt(t.shift(),255)],funcidx:(t,e)=>h($(t.shift(),e.func)),typeidx:(t,e)=>h($(t.shift(),e.type)),tableidx:(t,e)=>h($(t.shift(),e.table)),memoryidx:(t,e)=>h($(t.shift(),e.memory)),globalidx:(t,e)=>h($(t.shift(),e.global)),localidx:(t,e)=>h($(t.shift(),e.local)),dataidx:(t,e)=>h($(t.shift(),e.data)),elemidx:(t,e)=>h($(t.shift(),e.elem)),tagidx:(t,e)=>h($(t.shift(),e.tag)),"memoryidx?":(t,e)=>h($(K(t[0])?t.shift():0,e.memory)),stringidx:(t,e)=>{let r=t.shift(),i=r.valueOf(),s=e.strings.findIndex(n=>n.valueOf()===i);return s<0&&(s=e.strings.push(r)-1),h(s)},i32:t=>H(t.shift()),i64:t=>mt(t.shift()),f32:t=>pt(t.shift()),f64:t=>ut(t.shift()),v128:t=>Rt(t.shift()),typeidx_field:(t,e)=>{let r=$(t.shift(),e.type);return[...h(r),...h($(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...h($(t.shift(),e.type)),...h(t.shift())],typeidx_dataidx:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...h($(t.shift(),e.data)),...h($(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...h($(t.shift(),e.memory)),...h($(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...h($(t.shift(),e.table)),...h($(t.shift(),e.table))],cont_bind:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.type))],switch_cont:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.tag))],resume:(t,e)=>{let r=h($(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...h($(n,e.tag))):i.push(0,...h($(n,e.tag)),...h(ot(l,e.block))),s++}return[...r,...h(s),...i]},resume_throw:(t,e)=>{let r=h($(t.shift(),e.type)),i=h($(t.shift(),e.tag)),s=[],n=0;for(;t[0]?.[0]==="on";){let[,l,f]=t.shift();f==="switch"?s.push(1,...h($(l,e.tag))):s.push(0,...h($(l,e.tag)),...h(ot(f,e.block))),n++}return[...r,...i,...h(n),...s]},resume_throw_ref:(t,e)=>{let r=h($(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...h($(n,e.tag))):i.push(0,...h($(n,e.tag)),...h(ot(l,e.block))),s++}return[...r,...h(s),...i]}},Mt={};(function t(e,r){for(let i=0,s,n,l;i<e.length;i++)(s=e[i])&&(Array.isArray(s)?t(s,i):([n,l]=s.split(" "),At[n]=r?[r,...h(i)]:[i],l&&(Mt[n]=ge[l])))})(At);var _e=(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&&(B.loc=s.loc),B(`Unknown instruction ${s[0]}`));let[...n]=At[s]||B(`Unknown instruction ${s}`);Mt[s]&&(s==="select"&&t[0]?.length?n[0]++:Mt[s]===ge.reftype&&!s.endsWith("_null")&&(t[0][1]==="null"||t[0][0]!=="ref")&&n[n.length-1]++,n.push(...Mt[s](t,e,s)));for(let[l,f]of i)(e.meta[l]??=[]).push([r.length,f]);r.push(...n)}return r.push(11),r},gt=(t,e)=>_e(ft([t],e),e),$=(t,e,r)=>(r=G(t)?e[t]:+t,r in e?r:B(`Unknown ${e.name} ${t}`)),ot=(t,e,r)=>(r=G(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?B(`Bad label ${t}`):r),er=t=>{let e,r,i,s;for(;jt(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:B(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&B(`Bad offset ${r}`),(e<=0||e>4294967295)&&B(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&B(`Bad align ${e}`),[e,r]},ye=(t,e,r=0)=>{let[i,s]=er(t),n=(i??rr(e))|(r&&64);return r?[...h(n),...h(r),...h(s??0)]:[...h(n),...h(s??0)]},rr=t=>{let e=t.indexOf(".",3)+1,r=t.slice(1,t[0]==="v"?4:3);if(t[e]==="a"&&(e=t.indexOf(".",e)+1),t[0]==="m")return t.includes("64")?3:2;if(t[e]==="r"){let n=t.slice(e,e+6).match(/\d+/);return Math.log2(n?n[0]/8:+r/8)}let i=t[e]==="l"?e+4:e+5,s=t.slice(i).match(/(\d+)(x|_|$)/);return Math.log2(s?s[2]==="x"?8:s[1]/8:+r/8)},ir=t=>{if(!Array.isArray(t))return null;let[e,...r]=t;if(e!=="i8"&&e!=="i16"&&e!=="i32"&&e!=="i64"&&e!=="f32"&&e!=="f64")return null;let i=[],s=new DataView(new ArrayBuffer(8));for(let n of r)e==="i8"?i.push(H.parse(n)&511&255):e==="i16"?(s.setInt16(0,H.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,H.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,4))):e==="i64"?(s.setBigInt64(0,BigInt(n),!0),i.push(...new Uint8Array(s.buffer,0,8))):e==="f32"?i.push(...pt(n)):e==="f64"&&i.push(...ut(n));return i},kt=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(a=>Array.isArray(a)&&a[0]==="pagesize"),s=-1;i>=0&&(s=Math.log2(+t.splice(i,1)[0][1]));let n=!isNaN(parseInt(t[1])),l=(s>=0?8:0)|(e?4:0)|(r?2:0)|(n?1:0),f=e?a=>{if(typeof a=="bigint")return a;let c=typeof a=="string"?a.replaceAll("_",""):String(a);return BigInt(c)}:Bt,o=s>=0?h(s):[];return n?[l,...h(f(t.shift())),...h(f(t.shift())),...o]:[l,...h(f(t.shift())),...o]},Bt=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?H.parse(t):typeof t=="number"?t:B(`Bad int ${t}`);return r>e?B(`Value out of range ${t}`):r},O=t=>[...h(t.length),...t.flat()];function he(t,e={}){typeof t=="string"&&(t=Z(t));let{indent:r=" ",newline:i=`
|
|
4
4
|
`,comments:s=!0}=e;if(r||="",i||="",typeof t[0]=="string"&&t[0][0]!==";")return l(t);return t.filter(f=>s||!n(f)).map(f=>l(f)).join(i);function n(f){return typeof f=="string"&&f[1]===";"}function l(f,o=0){if(!Array.isArray(f))return f;let a=f[0];if(!a)return"";let c=!1;if(a==="try_table"){let y=1;for(typeof f[y]=="string"&&f[y][0]==="$"&&(a+=" "+f[y++]),Array.isArray(f[y])&&(f[y][0]==="result"||f[y][0]==="type")&&(a+=" "+l(f[y++],o));Array.isArray(f[y])&&/^catch/.test(f[y][0]);)a+=" "+l(f[y++],o).trim();for(;y<f.length;y++)a+=Array.isArray(f[y])?i+r.repeat(o+1)+l(f[y],o+1):" "+f[y];return`(${a+i+r.repeat(o)})`}let u=!!i&&f.length<4&&!f.some(y=>typeof y=="string"&&y[0]===";"&&y[1]===";"),m=r.repeat(o+1);for(let y=1;y<f.length;y++){let g=f[y].valueOf();if(typeof g=="string"&&g[1]===";"){if(!s)continue;if(g[0]===";")if(i)a+=i+m+g.trimEnd(),c=!0;else{let p=a[a.length-1];p&&p!==" "&&p!=="("&&(a+=" "),a+=g.trimEnd()+`
|
|
5
5
|
`}else{let p=a[a.length-1];p&&p!==" "&&p!=="("&&(a+=" "),a+=g.trimEnd()}}else if(Array.isArray(g))u&&(u=g.every(p=>!Array.isArray(p))),a+=i+m+l(g,o+1),c=!1;else if(f[0]==="data")u=!1,(i||a[a.length-1]!==")")&&(a+=i||" "),a+=m+g,c=!1;else{let p=a[a.length-1];c&&i?a+=i+m:p===`
|
|
6
|
-
`?a+="":(p&&p!==")"&&p!==" "||i||p===")")&&(a+=" "),a+=g,c=!1}}return u?`(${a.replaceAll(i+m+"("," (")})`:`(${a+i+r.repeat(o)})`}}var de={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"]},Ht=Object.keys(de),sr=t=>{if(t===!0)return Object.fromEntries(Ht.map(e=>[e,!0]));if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return Object.fromEntries(Ht.map(r=>[r,e.has(r)||e.has("all")]))}return{...t}},P=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)P(t[s],e,t,s)},et=(t,e,r,i)=>{if(Array.isArray(t))for(let s=0;s<t.length;s++)et(t[s],e,t,s);e(t,r,i)},nr=t=>{let e=new Set;return P(t,r=>{if(typeof r=="string")for(let[i,s]of Object.entries(de))s.some(n=>r===n||r.startsWith(n+" "))&&e.add(i)}),P(t,r=>{if(!(!Array.isArray(r)||r[0]!=="global"))for(let i of r)Array.isArray(i)&&(i[0]==="i32.add"||i[0]==="i32.sub"||i[0]==="i32.mul"||i[0]==="i64.add"||i[0]==="i64.sub"||i[0]==="i64.mul")&&P(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),P(t,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=0;for(let s of r)Array.isArray(s)&&s[0]==="result"&&(i+=s.length-1);i>1&&e.add("multi_value")}),e},Ae=t=>Array.isArray(t)?t.map(Ae):t,be=(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},Tt=(t,e,r)=>t.splice(e,0,r),lr=0,nt=t=>`$__${t}${lr++}`,fr=(t,e)=>{let r=new Set;if(P(t,a=>{Array.isArray(a)&&a[0]==="ref.func"&&r.add(a[1])}),!r.size)return t;let i=nt("fntbl"),s=[...r],n=Object.fromEntries(s.map((a,c)=>[a,c])),l=be(t,"func"),f=l.length?l[0].idx:t[0]==="module"?1:0;Tt(t,f,["table",i,"funcref",["elem",...s]]);let o={};return P(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!c)return;let u=[],m=[];for(let y of a){if(Array.isArray(y)&&y[0]==="param")for(let g=1;g<y.length;g++)y[g][0]!=="$"&&u.push(y[g]);if(Array.isArray(y)&&y[0]==="result")for(let g=1;g<y.length;g++)m.push(y[g])}o[c]={params:u,results:m}}),et(t,(a,c,u)=>{if(!(!Array.isArray(a)||!c)){if(a[0]==="ref.func"&&n[a[1]]!==void 0&&(c[u]=["i32.const",n[a[1]]]),a[0]==="call_ref"){let m=a[1],y=a.slice(2);c[u]=["call_indirect",i,["type",m],...y]}if(a[0]==="return_call_ref"){let m=a[1],y=a.slice(2);c[u]=["return_call_indirect",i,["type",m],...y]}}}),t},tt={funcref:fr},ar={"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]},or=(t,e)=>(et(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let n=ar[r[0]];if(!n)return;let[l,f]=n,o=r.slice(1);i[s]=[`${l}.shr_s`,[`${l}.shl`,...o,[`${l}.const`,f]],[`${l}.const`,f]]}),t);tt.sign_ext=or;var xe={"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}},cr=(t,e)=>{let r=new Set;if(P(t,s=>{Array.isArray(s)&&xe[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:n,ftype:l,signed:f,min:o,max:a}=xe[s],c=nt(`trunc_${n}_${l}_${f?"s":"u"}`);i[s]=c;let u=`${n}.trunc_${l}_${f?"s":"u"}`,m=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`,m]],["else",["if",["result",n],[`${l}.lt`,["local.get","$v"],[`${l}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${n}.const`,o]],["else",["if",["result",n],[`${l}.gt`,["local.get","$v"],[`${l}.const`,typeof a=="bigint"?Number(a):a]],["then",[`${n}.const`,a]],["else",[u,["local.get","$v"]]]]]]]]];t.push(y)}return et(t,(s,n,l)=>{!Array.isArray(s)||!n||i[s[0]]&&(n[l]=["call",i[s[0]],...s.slice(1)])}),t};tt.nontrapping=cr;var ur=(t,e)=>{let r=new Set,i=new Set;P(t,l=>{if(Array.isArray(l)){if(l[0]==="memory.copy"){let f=typeof l[1]=="number"?l[1]:0,o=typeof l[2]=="number"?l[2]:0;r.add(`${f}_${o}`)}if(l[0]==="memory.fill"){let f=typeof l[1]=="number"?l[1]:0;i.add(f)}}});let s={},n={};for(let l of r){let[f,o]=l.split("_").map(Number),a=nt(`memcpy${l==="0_0"?"":"_"+l}`);s[l]=a;let c=f?["i32.store8",f]:["i32.store8"],u=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",a,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...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 i){let f=nt(`memset${l===0?"":"_"+l}`);n[l]=f;let o=l?["i32.store8",l]:["i32.store8"];t.push(["func",f,["param","$dst","i32"],["param","$val","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...o,["i32.add",["local.get","$dst"],["local.get","$i"]],["local.get","$val"]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}return et(t,(l,f,o)=>{if(!(!Array.isArray(l)||!f)){if(l[0]==="memory.copy"){let a=typeof l[1]=="number"?l[1]:0,c=typeof l[2]=="number"?l[2]:0,u=l.filter(m=>Array.isArray(m)||typeof m=="string"&&m[0]==="$");f[o]=["call",s[`${a}_${c}`],...u]}if(l[0]==="memory.fill"){let a=typeof l[1]=="number"?l[1]:0,c=l.filter(u=>Array.isArray(u)||typeof u=="string"&&u[0]==="$");f[o]=["call",n[a],...c]}}}),t};tt.bulk_memory=ur;var yr=(t,e)=>{let r=!1;return P(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&et(t,(i,s,n)=>{!Array.isArray(i)||!s||(i[0]==="return_call"&&(s[n]=["return",["call",...i.slice(1)]]),i[0]==="return_call_indirect"&&(s[n]=["return",["call_indirect",...i.slice(1)]]))}),t};tt.return_call=yr;var mr=(t,e)=>(et(t,(r,i,s)=>{if(!(!Array.isArray(r)||!i)&&(r[0]==="ref.i31"&&(i[s]=["i32.and",...r.slice(1),["i32.const",2147483647]]),r[0]==="i31.get_u"&&(i[s]=r.length>1?r[1]:["drop"]),r[0]==="i31.get_s")){let n=r.slice(1);i[s]=["i32.shr_s",["i32.shl",...n,["i32.const",1]],["i32.const",1]]}}),t);tt.i31ref=mr;var pr=(t,e)=>{let r={};P(t,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l=s.length-1;l>=0;l--){let f=s[l];if(Array.isArray(f)&&(f[0]==="i32.const"||f[0]==="i64.const"||f[0]==="f32.const"||f[0]==="f64.const")){r[n]={type:f[0].split(".")[0],value:f[1]};break}}});let i=s=>{if(!Array.isArray(s))return s;let n=s[0];if(n==="global.get"&&r[s[1]]){let l=r[s[1]];return[`${l.type}.const`,l.value]}if(n==="i32.add"||n==="i64.add"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a+c]}}if(n==="i32.sub"||n==="i64.sub"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a-c]}}if(n==="i32.mul"||n==="i64.mul"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a*c]}}return s};return et(t,(s,n,l)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!n)){for(let f=2;f<s.length;f++)if(Array.isArray(s[f])){let o=i(s[f]);o!==s[f]&&(s[f]=o)}}}),t};tt.extended_const=pr;var gr=(t,e)=>{let r=new Map,i=[];if(P(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let o=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null,a=[];for(let c of f)if(Array.isArray(c)&&c[0]==="result")for(let u=1;u<c.length;u++)a.push(c[u]);a.length>1&&o&&r.set(o,a)}),!r.size)return t;let s=Math.max(...[...r.values()].map(f=>f.length)),n={};for(let[f,o]of r)for(let a=1;a<o.length;a++){let c=o[a];if(n[c]||(n[c]=[]),n[c].length<a){let u=nt(`ret_${c}_${n[c].length}`);n[c].push(u),i.push(["global",u,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let l=t[0]==="module"?1:0;for(let f of i.reverse())Tt(t,l,f);return et(t,(f,o,a)=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c||!r.has(c))return;let u=r.get(c);for(let m=0;m<f.length;m++)if(Array.isArray(f[m])&&f[m][0]==="result"){f[m]=["result",u[0]];break}}),t};tt.multi_value=gr;var bt={i32:4,i64:8,f32:4,f64:8},_r=(t,e)=>{let r=new Map,i=new Map,s=1;if(P(t,p=>{if(!Array.isArray(p)||p[0]!=="type")return;let _=typeof p[1]=="string"&&p[1][0]==="$"?p[1]:null;if(_){for(let b of p)if(Array.isArray(b)){if(b[0]==="struct"){let v=[];for(let A of b)if(Array.isArray(A)&&A[0]==="field"){let S=typeof A[1]=="string"&&A[1][0]==="$"?A[1]:null,I=S?A[2]:A[1],M=Array.isArray(I)&&I[0]==="mut"?I[1]:I;v.push({name:S,type:M})}r.set(_,{kind:"struct",fields:v}),i.set(_,s++)}if(b[0]==="array"){let v=b[1],A=Array.isArray(v)&&v[0]==="mut"?v[1]:v;r.set(_,{kind:"array",elemType:A}),i.set(_,s++)}}}}),!r.size)return t;let n=be(t,"memory").length>0,l=nt("alloc"),f=nt("heap_ptr"),o=t[0]==="module"?1:0;n||Tt(t,o,["memory",1]),Tt(t,o+1,["global",f,["mut","i32"],["i32.const",1024]]);let a=["func",l,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",f]],["global.set",f,["i32.add",["global.get",f],["local.get","$size"]]],["local.get","$ptr"]];t.push(a);let c=p=>{let _=4;for(let b of p.fields)_+=bt[b.type]||4;return _},u=(p,_)=>{let b=4;for(let v=0;v<_;v++)b+=bt[p.fields[v].type]||4;return b},m=(p,_)=>{for(let b=0;b<p.fields.length;b++)if(p.fields[b].name===_)return b;return-1},y=0,g=()=>`$__gc_tmp${y++}`;return P(t,p=>{if(!Array.isArray(p)||p[0]!=="func")return;let _=!1,b=!1,v=!1,A=!1;if(P(p,I=>{Array.isArray(I)&&((I[0]==="struct.new"||I[0]==="struct.new_default")&&(_=!0),(I[0]==="array.new"||I[0]==="array.new_default")&&(b=!0,v=!0,A=!0))}),!_&&!b)return;let S=1;for(let I=1;I<p.length;I++){let M=p[I];if(Array.isArray(M)&&(M[0]==="param"||M[0]==="result"||M[0]==="local"||M[0]==="export"||M[0]==="type"))S=I+1;else if(typeof M=="string"&&M[0]==="$")S=I+1;else if(!Array.isArray(M))S=I+1;else break}_&&p.splice(S++,0,["local","$__gc_ptr","i32"]),b&&p.splice(S++,0,["local","$__gc_aptr","i32"]),v&&p.splice(S++,0,["local","$__gc_alen","i32"]),A&&p.splice(S++,0,["local","$__gc_aidx","i32"])}),et(t,(p,_,b)=>{if(!(!Array.isArray(p)||!_)){if(p[0]==="struct.new"||p[0]==="struct.new_default"){let v=p[1],A=r.get(v);if(!A||A.kind!=="struct")return;let S=c(A),I=i.get(v),M=p.slice(2),F="$__gc_ptr",q=[["local.set",F,["call",l,["i32.const",S]]],["i32.store",["local.get",F],["i32.const",I]]];if(p[0]==="struct.new")for(let E=0;E<A.fields.length;E++){let x=A.fields[E],d=u(A,E),k=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store";q.push([k,["i32.add",["local.get",F],["i32.const",d]],M[E]||[`${x.type}.const`,0]])}else for(let E=0;E<A.fields.length;E++){let x=A.fields[E],d=u(A,E),k=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store",L=x.type==="i64"?["i64.const",0n]:x.type==="f32"?["f32.const",0]:x.type==="f64"?["f64.const",0]:["i32.const",0];q.push([k,["i32.add",["local.get",F],["i32.const",d]],L])}q.push(["local.get",F]),_[b]=["block",["result","i32"],...q]}if(p[0]==="struct.get"){let v=p[1],A=p[2],S=p[3],I=r.get(v);if(!I||I.kind!=="struct")return;let M=typeof A=="string"&&A[0]==="$"?m(I,A):parseInt(A);if(M<0)return;let F=I.fields[M],q=u(I,M),E=F.type==="i64"?"i64.load":F.type==="f32"?"f32.load":F.type==="f64"?"f64.load":"i32.load";_[b]=[E,["i32.add",S,["i32.const",q]]]}if(p[0]==="struct.set"){let v=p[1],A=p[2],S=p[3],I=p[4],M=r.get(v);if(!M||M.kind!=="struct")return;let F=typeof A=="string"&&A[0]==="$"?m(M,A):parseInt(A);if(F<0)return;let q=M.fields[F],E=u(M,F),x=q.type==="i64"?"i64.store":q.type==="f32"?"f32.store":q.type==="f64"?"f64.store":"i32.store";_[b]=[x,["i32.add",S,["i32.const",E]],I]}if(p[0]==="array.new"||p[0]==="array.new_default"){let v=p[1],A=r.get(v);if(!A||A.kind!=="array")return;let S=i.get(v),I=bt[A.elemType]||4,M=p[0]==="array.new"?p[2]:null,F=p[0]==="array.new"?p[3]:p[2],q="$__gc_aptr",E="$__gc_alen",x="$__gc_aidx",d=A.elemType==="i64"?"i64.store":A.elemType==="f32"?"f32.store":A.elemType==="f64"?"f64.store":"i32.store",k=[["local.set",E,F],["local.set",q,["call",l,["i32.add",["i32.const",8],["i32.mul",["local.get",E],["i32.const",I]]]]],["i32.store",["local.get",q],["i32.const",S]],["i32.store",["i32.add",["local.get",q],["i32.const",4]],["local.get",E]]];M&&k.push(["local.set",x,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",x],["local.get",E]]],[d,["i32.add",["i32.add",["local.get",q],["i32.const",8]],["i32.mul",["local.get",x],["i32.const",I]]],M],["local.set",x,["i32.add",["local.get",x],["i32.const",1]]],["br","$loop"]]]),k.push(["local.get",q]),_[b]=["block",["result","i32"],...k]}if(p[0]==="array.get"){let v=p[1],A=p[2],S=p[3],I=r.get(v);if(!I||I.kind!=="array")return;let M=bt[I.elemType]||4,F=I.elemType==="i64"?"i64.load":I.elemType==="f32"?"f32.load":I.elemType==="f64"?"f64.load":"i32.load";_[b]=[F,["i32.add",["i32.add",A,["i32.const",8]],["i32.mul",S,["i32.const",M]]]]}if(p[0]==="array.set"){let v=p[1],A=p[2],S=p[3],I=p[4],M=r.get(v);if(!M||M.kind!=="array")return;let F=bt[M.elemType]||4,q=M.elemType==="i64"?"i64.store":M.elemType==="f32"?"f32.store":M.elemType==="f64"?"f64.store":"i32.store";_[b]=[q,["i32.add",["i32.add",A,["i32.const",8]],["i32.mul",S,["i32.const",F]]],I]}if(p[0]==="array.len"){let v=p[1];_[b]=["i32.load",["i32.add",v,["i32.const",4]]]}}}),t};tt.gc=_r;var hr=(t,e)=>{let r=new Map,i=1;return P(t,s=>{if(!Array.isArray(s)||s[0]!=="type")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l of s)Array.isArray(l)&&(l[0]==="struct"||l[0]==="array")&&r.set(n,i++)}),r.size&&et(t,(s,n,l)=>{if(!(!Array.isArray(s)||!n)){if(s[0]==="ref.test"){let f=s[1],o=null;Array.isArray(f)&&f[0]==="ref"&&(o=f[1]==="null"?f[2]:f[1]);let a=s[2],c=r.get(o);c!==void 0&&(n[l]=["if",["result","i32"],["i32.eqz",a],["then",["i32.const",0]],["else",["i32.eq",["i32.load",a],["i32.const",c]]]])}if(s[0]==="ref.cast"){let f=s[1],o=null,a=!1;Array.isArray(f)&&f[0]==="ref"&&(f[1]==="null"?(a=!0,o=f[2]):o=f[1]);let c=s[2],u=r.get(o);if(u!==void 0){let m=nt("cast");a?n[l]=["block",["result","i32"],["local",m,"i32"],["local.set",m,c],["if",["i32.and",["i32.ne",["local.get",m],["i32.const",0]],["i32.ne",["i32.load",["local.get",m]],["i32.const",u]]],["then",["unreachable"]]],["local.get",m]]:n[l]=["block",["result","i32"],["local",m,"i32"],["local.set",m,c],["if",["i32.or",["i32.eqz",["local.get",m]],["i32.ne",["i32.load",["local.get",m]],["i32.const",u]]],["then",["unreachable"]]],["local.get",m]]}}if(s[0]==="br_on_cast"){let f=s[1],o=s[2],a=s[3],c=s[4],u=null;Array.isArray(a)&&a[0]==="ref"&&(u=a[1]==="null"?a[2]:a[1]);let m=r.get(u);if(m!==void 0){let y=nt("brcast");n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["br_if",f,["i32.and",["i32.ne",["local.get",y],["i32.const",0]],["i32.eq",["i32.load",["local.get",y]],["i32.const",m]]]],["local.get",y]]}}if(s[0]==="br_on_cast_fail"){let f=s[1],o=s[2],a=s[3],c=s[4],u=null;Array.isArray(a)&&a[0]==="ref"&&(u=a[1]==="null"?a[2]:a[1]);let m=r.get(u);if(m!==void 0){let y=nt("brfail");n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["br_if",f,["i32.or",["i32.eqz",["local.get",y]],["i32.ne",["i32.load",["local.get",y]],["i32.const",m]]]],["local.get",y]]}}}}),t};tt.ref_cast=hr;function Et(t,e=!0){typeof t=="string"&&(t=Z(t)),t=Ae(t),e=sr(e);let r=nr(t),i={uid:0};for(let s of Ht)r.has(s)&&e[s]!==!1&&tt[s]&&(t=tt[s](t,i));return t}var Vt={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!1,inlineOnce:!0,vacuum:!0,mergeBlocks:!0,coalesce:!0,peephole:!0,globals:!0,offset:!0,unbranch:!0,loopify:!0,stripmut:!0,brif:!0,foldarms:!1,dedupe:!0,reorder:!1,dedupTypes:!0,packData:!0,minifyImports:!1},we=Object.keys(Vt);var ve=t=>{try{return ct(t).length}catch{return 1/0}},T=(t,e)=>{if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="bigint")return t===e;if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!T(t[r],e[r]))return!1;return!0},xr=t=>{if(t===!0)return{...Vt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.has("all")?Object.fromEntries(we.map(r=>[r,!0])):Object.fromEntries(we.map(r=>[r,e.has(r)]))}return{...Vt,...t}},J=t=>Array.isArray(t)?t.map(J):t,C=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)C(t[s],e,t,s)},W=(t,e,r,i)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++){let l=W(t[n],e,t,n);l!==void 0&&(t[n]=l)}let s=e(t,r,i);return s!==void 0?s:t},Lt=t=>{let e=1;for(;e<t.length;){let s=t[e];if(Array.isArray(s)&&(s[0]==="then"||s[0]==="else"||s[0]==="result"||s[0]==="param")){e++;continue}break}let r=null,i=null;for(let s=e+1;s<t.length;s++){let n=t[s];Array.isArray(n)&&(n[0]==="then"?r=n:n[0]==="else"&&(i=n))}return{condIdx:e,cond:t[e],thenBranch:r,elseBranch:i}},dr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=new Map,n=new Map,l=new Map,f=(x,d,k,L=!1)=>{let rt=typeof d[1]=="string"&&d[1][0]==="$",w=rt?d[1]:k,N=!L&&d.some(it=>Array.isArray(it)&&it[0]==="export"),U={node:d,idx:k,used:N,isImport:L};return x.set(w,U),rt&&x.set(k,U),l.set(d,U),U},o=0,a=0,c=0,u=0,m=0,y=[],g=[],p=[],_=[];for(let x of t.slice(1)){if(!Array.isArray(x))continue;let d=x[0];if(d==="type")f(i,x,c++);else if(d==="func")f(e,x,o++);else if(d==="global")f(r,x,a++);else if(d==="table")f(s,x,u++);else if(d==="memory")f(n,x,m++);else if(d==="import")for(let k of x)Array.isArray(k)&&(k[0]==="func"?f(e,k,o++,!0):k[0]==="global"?f(r,k,a++,!0):k[0]==="table"?f(s,k,u++,!0):k[0]==="memory"&&f(n,k,m++,!0));else d==="export"?p.push(x):d==="start"?_.push(x):d==="elem"?y.push(x):d==="data"&&g.push(x)}let b=[],v=x=>{x&&!x.scanned&&b.push(x)},A=x=>{let d=e.get(x);d&&(d.used||(d.used=!0),v(d))},S=x=>{let d=r.get(x);d&&(d.used=!0)},I=x=>{let d=s.get(x);d&&(d.used=!0)},M=x=>{typeof x=="string"&&x[0]!=="$"&&(x=+x);let d=n.get(x);d&&(d.used=!0)},F=x=>{let d=i.get(x);d&&(d.used=!0)};for(let x of p)for(let d of x){if(!Array.isArray(d))continue;let[k,L]=d;k==="func"?A(L):k==="global"?S(L):k==="table"?I(L):k==="memory"&&M(L)}for(let x of _){let d=x[1];typeof d=="string"&&d[0]!=="$"&&(d=+d),A(d)}for(let x of y)C(x,d=>{Array.isArray(d)&&d[0]==="ref.func"?A(d[1]):typeof d=="string"&&d[0]==="$"&&A(d)});for(let x of g){let d=x[1];Array.isArray(d)&&d[0]==="memory"?M(d[1]):typeof d=="string"&&d[0]==="$"?M(d):Array.isArray(d)&&M(0)}for(let x of[e,r,s,n])for(let d of x.values())d.used&&v(d);if(!(p.length>0||_.length>0||y.length>0||b.length>0)){for(let x of[e,r,s,n])for(let d of x.values())d.used=!0;return t}for(;b.length;){let x=b.pop();x.scanned||(x.scanned=!0,!x.isImport&&C(x.node,d=>{if(!Array.isArray(d)){typeof d=="string"&&d[0]==="$"&&A(d);return}let[k,L]=d;if(k==="call"||k==="return_call"||k==="ref.func")A(L);else if(k==="global.get"||k==="global.set")S(L);else if(k==="type")F(L);else if(k==="call_indirect"||k==="return_call_indirect")for(let rt of d)typeof rt=="string"&&rt[0]==="$"&&I(rt);typeof k=="string"&&(k.startsWith("memory.")||k.includes(".load")||k.includes(".store"))&&M(0)}))}let E=["module"];for(let x of t.slice(1)){if(!Array.isArray(x)){E.push(x);continue}let d=x[0];if(d==="func"||d==="global"||d==="type")l.get(x)?.used&&E.push(x);else if(d==="import"){let k=!1;for(let L of x){if(!Array.isArray(L))continue;if(l.get(L)?.used){k=!0;break}}k&&E.push(x)}else E.push(x)}return E},$e=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),ze=new ArrayBuffer(8),Kt=new Float64Array(ze),Qt=new BigInt64Array(ze),Te=new ArrayBuffer(4),Jt=new Float32Array(Te),te=new Int32Array(Te),Ar=t=>(Kt[0]=t,Qt[0]),br=t=>(Qt[0]=BigInt.asIntN(64,t),Kt[0]),wr=t=>(Jt[0]=t,te[0]),vr=t=>(te[0]=t|0,Jt[0]),_t=t=>(e,r)=>t(e,r)?1:0,Ut=t=>(e,r)=>t(e>>>0,r>>>0)?1:0,ht=t=>(e,r)=>t(e,r)?1:0,qt=t=>(e,r)=>t(BigInt.asUintN(64,e),BigInt.asUintN(64,r))?1:0,$r={"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":[_t((t,e)=>t===e),"i32"],"i32.ne":[_t((t,e)=>t!==e),"i32"],"i32.lt_s":[_t((t,e)=>t<e),"i32"],"i32.lt_u":[Ut((t,e)=>t<e),"i32"],"i32.gt_s":[_t((t,e)=>t>e),"i32"],"i32.gt_u":[Ut((t,e)=>t>e),"i32"],"i32.le_s":[_t((t,e)=>t<=e),"i32"],"i32.le_u":[Ut((t,e)=>t<=e),"i32"],"i32.ge_s":[_t((t,e)=>t>=e),"i32"],"i32.ge_u":[Ut((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":[ht((t,e)=>t===e),"i32"],"i64.ne":[ht((t,e)=>t!==e),"i32"],"i64.lt_s":[ht((t,e)=>t<e),"i32"],"i64.lt_u":[qt((t,e)=>t<e),"i32"],"i64.gt_s":[ht((t,e)=>t>e),"i32"],"i64.gt_u":[qt((t,e)=>t>e),"i32"],"i64.le_s":[ht((t,e)=>t<=e),"i32"],"i64.le_u":[qt((t,e)=>t<=e),"i32"],"i64.ge_s":[ht((t,e)=>t>=e),"i32"],"i64.ge_u":[qt((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($e(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":[$e,"f64"],"i32.reinterpret_f32":[wr,"i32"],"f32.reinterpret_i32":[vr,"f32"],"i64.reinterpret_f64":[Ar,"i64"],"f64.reinterpret_i64":[br,"f64"],"f32.convert_i32_s":[t=>Math.fround(t|0),"f32"],"f32.convert_i32_u":[t=>Math.fround(t>>>0),"f32"],"f32.convert_i64_s":[t=>Math.fround(Number(BigInt.asIntN(64,t))),"f32"],"f32.convert_i64_u":[t=>Math.fround(Number(BigInt.asUintN(64,t))),"f32"],"f64.convert_i32_s":[t=>t|0,"f64"],"f64.convert_i32_u":[t=>t>>>0,"f64"],"f64.convert_i64_s":[t=>Number(BigInt.asIntN(64,t)),"f64"],"f64.convert_i64_u":[t=>Number(BigInt.asUintN(64,t)),"f64"],"f32.demote_f64":[t=>Math.fround(t),"f32"],"f64.promote_f32":[t=>Math.fround(t),"f64"]},Ir=(t,e=t?.indexOf?.("nan"))=>{if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),i=t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?BigInt(r):0x8000000000000n;return Qt[0]=BigInt.asIntN(64,i|0x7ff0000000000000n|(t[0]==="-"?1n<<63n:0n)),Kt[0]},kr=(t,e=t?.indexOf?.("nan"))=>{if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),i=t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?parseInt(r):4194304;return te[0]=i|2139095040|(t[0]==="-"?2147483648:0)|0,Jt[0]},z=t=>{if(!Array.isArray(t)||t.length!==2)return null;let[e,r]=t;if(e==="i32.const")return{type:"i32",value:Number(r)|0};if(e==="i64.const")return{type:"i64",value:BigInt(r)};if(e==="f32.const"){let i=kr(r);return{type:"f32",value:i!==null?i:Math.fround(Number(r))}}if(e==="f64.const"){let i=Ir(r);return{type:"f64",value:i!==null?i:Number(r)}}return null},Ie=(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,Mr=t=>W(t,e=>{if(!Array.isArray(e))return;let r=$r[e[0]];if(!r)return;let[i,s]=r;if(i.length===1&&e.length===2){let n=z(e[1]);if(!n)return;let l=i(n.value);return l===null?void 0:Ie(s,l)}if(i.length===2&&e.length===3){let n=z(e[1]),l=z(e[2]);if(!n||!l)return;let f=i(n.value,l.value);return f===null?void 0:Ie(s,f)}}),lt=t=>(e,r)=>{let i=z(e),s=z(r);return i?.value===t?r:s?.value===t?e:null},Q=t=>(e,r)=>z(r)?.value===t?e:null,Br={"i32.add":lt(0),"i64.add":lt(0n),"i32.sub":Q(0),"i64.sub":Q(0n),"i32.mul":lt(1),"i64.mul":lt(1n),"i32.div_s":Q(1),"i32.div_u":Q(1),"i64.div_s":Q(1n),"i64.div_u":Q(1n),"i32.and":lt(-1),"i64.and":lt(-1n),"i32.or":lt(0),"i64.or":lt(0n),"i32.xor":lt(0),"i64.xor":lt(0n),"i32.shl":Q(0),"i32.shr_s":Q(0),"i32.shr_u":Q(0),"i64.shl":Q(0n),"i64.shr_s":Q(0n),"i64.shr_u":Q(0n)},Nr=t=>W(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=Br[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Sr=t=>W(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1)){let f=Math.log2(n.value);if(Number.isInteger(f))return["i32.shl",i,["i32.const",f]]}let l=z(i);if(l&&l.value>0&&!(l.value&l.value-1)){let f=Math.log2(l.value);if(Number.isInteger(f))return["i32.shl",s,["i32.const",f]]}}if(r==="i64.mul"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let f=BigInt(n.value.toString(2).length-1);return["i64.shl",i,["i64.const",f]]}let l=z(i);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let f=BigInt(l.value.toString(2).length-1);return["i64.shl",s,["i64.const",f]]}}if(r==="i32.div_u"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1)){let l=Math.log2(n.value);if(Number.isInteger(l))return["i32.shr_u",i,["i32.const",l]]}}if(r==="i64.div_u"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let l=BigInt(n.value.toString(2).length-1);return["i64.shr_u",i,["i64.const",l]]}}if(r==="i32.rem_u"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1))return["i32.and",i,["i32.const",n.value-1]]}if(r==="i64.rem_u"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n)return["i64.and",i,["i64.const",n.value-1n]]}}),zr=t=>W(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Lt(e),l=z(i);if(!l)return;let f=l.value!==0&&l.value!==0n?s:n;if(f&&f.length>1){let o=f.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=z(i);return s?s.value===0||s.value===0n?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let i=e[e.length-1],s=z(i);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),ke=new Set(["unreachable","return","br","br_table"]),Tr=t=>(C(t,e=>{if(!Array.isArray(e))return;let r=e[0];if((r==="func"||r==="block"||r==="loop")&&Me(e),r==="if")for(let i=1;i<e.length;i++)Array.isArray(e[i])&&(e[i][0]==="then"||e[i][0]==="else")&&Me(e[i])}),t),Me=t=>{let e=!1,r=-1;for(let i=1;i<t.length;i++){let s=t[i];if(Array.isArray(s)){let n=s[0];if(n==="param"||n==="result"||n==="local"||n==="type"||n==="export")continue;e&&r===-1&&(r=i),ke.has(n)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),ke.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},Er=t=>(C(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=[],i=new Map,s=new Set;for(let n=1;n<e.length;n++){let l=e[n];Array.isArray(l)&&(l[0]==="local"&&(r.push({node:l,idx:n}),typeof l[1]=="string"&&l[1][0]==="$"&&i.set(l[1],l[2])),l[0]==="param"&&typeof l[1]=="string"&&l[1][0]==="$"&&(i.set(l[1],l[2]),s.add(l[1])))}C(e,n=>{if(!Array.isArray(n))return;let l=n[0];if(l==="local.get"||l==="local.set"||l==="local.tee"){let f=n[1];typeof f=="string"&&s.add(f)}});for(let n=r.length-1;n>=0;n--){let{idx:l,node:f}=r[n],o=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;o&&!s.has(o)&&e.splice(l,1)}}),t),Ur=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"]),qr=[".store","memory.",".atomic."],xt=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||Ur.has(e))return!1;for(let r of qr)if(e.includes(r))return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!xt(t[r]))return!1;return!0},Fr=t=>{let e=new Map,r=i=>(e.has(i)||e.set(i,{gets:0,sets:0,tees:0}),e.get(i));return C(t,i=>{!Array.isArray(i)||i.length<2||typeof i[1]!="string"||(i[0]==="local.get"?r(i[1]).gets++:i[0]==="local.set"?r(i[1]).sets++:i[0]==="local.tee"&&r(i[1]).tees++)}),e},Or=t=>{let e=z(t);if(!e)return!1;if(e.type==="i32"){let r=e.value|0;return r>=-64&&r<=63}if(e.type==="i64"){let r=typeof e.value=="bigint"?e.value:BigInt(e.value);return r>=-64n&&r<=63n}return!1},Ee=t=>t.pure&&t.singleUse||Or(t.val),Yt=(t,e)=>{for(let[r,i]of t){let s=!1;C(i.val,n=>{Array.isArray(n)&&(n[0]==="local.get"||n[0]==="local.tee")&&n[1]===e&&(s=!0)}),s&&t.delete(r)}},Ue=t=>{if(!Array.isArray(t))return!1;let e=t[0];if(typeof e=="string"&&(e.includes(".load")||e==="memory.copy"||e==="memory.size"))return!0;for(let r=1;r<t.length;r++)if(Ue(t[r]))return!0;return!1},Xt=t=>{if(!Array.isArray(t))return!1;let e=t[0];if(typeof e=="string"&&(e.endsWith(".store")||e==="memory.copy"||e==="memory.fill"||e==="memory.init"||e.includes(".atomic.")&&!e.endsWith(".load")))return!0;for(let r=1;r<t.length;r++)if(Xt(t[r]))return!0;return!1},Zt=(t,e)=>{if(!Array.isArray(t))return t;let r=t[0];if(r==="local.get"&&t.length===2){let s=typeof t[1]=="string"&&e.get(t[1]);return s&&Ee(s)?J(s.val):t}let i=e;if(r==="block"||r==="loop"||r==="if"){let s=null;C(t,n=>{Array.isArray(n)&&(n[0]==="local.set"||n[0]==="local.tee")&&typeof n[1]=="string"&&e.has(n[1])&&(s||(s=new Map(e)),s.delete(n[1]))}),s&&(i=s)}for(let s=1;s<t.length;s++){let n=Zt(t[s],i);n!==t[s]&&(t[s]=n),s+1<t.length&&Array.isArray(t[s])&&C(t[s],l=>{Array.isArray(l)&&(l[0]==="local.set"||l[0]==="local.tee")&&typeof l[1]=="string"&&(i===e&&(i=new Map(e)),i.delete(l[1]),Yt(i,l[1]))})}return t},Lr=(t,e,r)=>{let i=!1,s=l=>r.get(l)||{gets:0,sets:0,tees:0},n=new Map;for(let l=1;l<t.length;l++){let f=t[l];if(!Array.isArray(f))continue;let o=f[0];if(!(o==="param"||o==="result"||o==="local"||o==="type"||o==="export")){if((o==="local.set"||o==="local.tee")&&f.length===3&&typeof f[1]=="string"){let a=Zt(f[2],n);a!==f[2]&&(f[2]=a,i=!0);let c=s(f[1]);if(Yt(n,f[1]),Xt(f[2]))for(let[u,m]of n)m.readsMem&&n.delete(u);n.set(f[1],{val:f[2],pure:xt(f[2]),readsMem:Ue(f[2]),singleUse:c.gets<=1&&c.sets<=1&&c.tees===0});continue}if((o==="block"||o==="loop"||o==="if")&&n.clear(),o==="call"||o==="call_indirect"||o==="return_call"||o==="return_call_indirect")for(let[a,c]of n)z(c.val)||n.delete(a);if(o==="local.get"&&f.length===2&&typeof f[1]=="string"){let a=n.get(f[1]);if(a&&Ee(a)){let c=J(a.val);f.length=0,f.push(...Array.isArray(c)?c:[c]),i=!0;continue}}if(o!=="block"&&o!=="loop"&&o!=="if"){let a=J(f);if(Zt(f,n),T(a,f)||(i=!0),C(f,c=>{Array.isArray(c)&&(c[0]==="local.set"||c[0]==="local.tee")&&typeof c[1]=="string"&&(n.delete(c[1]),Yt(n,c[1]))}),Xt(f))for(let[c,u]of n)u.readsMem&&n.delete(c)}}}return i},Cr=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let f=n[1];if(l[1]!==f||e.has(f))continue;let o=r.get(f)||{gets:0,sets:0,tees:0};if(o.sets!==1||o.gets!==1||o.tees!==0)continue;let a=J(n[2]);t.splice(s,2,...Array.isArray(a)?[a]:[a]),i=!0,s--}return i},Dr=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let f=n[1];if(l[1]!==f||e.has(f))continue;let o=r.get(f)||{gets:0,sets:0,tees:0};o.sets+o.gets+o.tees<=2||(t.splice(s,2,["local.tee",f,J(n[2])]),i=!0)}return i},Rr=(t,e,r)=>{let i=!1,s=n=>r.get(n)||{gets:0,sets:0,tees:0};for(let n=t.length-1;n>=1;n--){let l=t[n];if(!Array.isArray(l))continue;let f=typeof l[1]=="string"?l[1]:null;if(!f||e.has(f))continue;let o=s(f);(l[0]==="local.set"&&o.gets===0&&o.tees===0&&xt(l[2])||l[0]==="local"&&f[0]==="$"&&o.gets===0&&o.sets===0&&o.tees===0)&&(t.splice(n,1),i=!0)}return i},qe=t=>Array.isArray(t)&&(t[0]==="func"||t[0]==="block"||t[0]==="loop"||t[0]==="then"||t[0]==="else"),Be=t=>(C(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Set;for(let s of e)Array.isArray(s)&&s[0]==="param"&&typeof s[1]=="string"&&r.add(s[1]);let i=[];W(e,s=>{qe(s)&&i.push(s)});for(let s=0;s<6;s++){let n=Fr(e),l=!1;for(let f of i)Lr(f,r,n)&&(l=!0),Cr(f,r,n)&&(l=!0),Dr(f,r,n)&&(l=!0),Rr(f,r,n)&&(l=!0);if(!l)break}}),t),Wr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map;for(let r of t.slice(1)){if(!Array.isArray(r)||r[0]!=="func")continue;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i)continue;let s=[],n=[],l=!1,f=!1;for(let o=1;o<r.length;o++){let a=r[o];if(Array.isArray(a))if(a[0]==="param")if(typeof a[1]=="string"&&a[1][0]==="$")s.push({name:a[1],type:a[2]});else{s=null;break}else a[0]==="local"?l=!0:a[0]==="export"?f=!0:a[0]!=="result"&&a[0]!=="type"&&n.push(a)}if(s&&!l&&!f&&s.length<=4&&n.length===1){let o=new Set(s.map(u=>u.name)),a=!1,c=!1;C(n[0],u=>{Array.isArray(u)&&((u[0]==="local.set"||u[0]==="local.tee")&&o.has(u[1])&&(a=!0),(u[0]==="return"||u[0]==="return_call"||u[0]==="return_call_indirect")&&(c=!0))}),!a&&!c&&e.set(i,{body:n[0],params:s})}}return e.size===0||W(t,r=>{if(!Array.isArray(r)||r[0]!=="call")return;let i=r[1];if(!e.has(i))return;let{body:s,params:n}=e.get(i),l=r.slice(2);if(n.length===0)return J(s);let f=J(s);return W(f,o=>{if(!Array.isArray(o)||o[0]!=="local.get")return;let a=o[1],c=n.findIndex(u=>u.name===a);if(c!==-1&&l[c])return J(l[c])}),f}),t},Pr=0,jr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set(["export","type","param","result","local"]),r=a=>{let c=2;for(;c<a.length&&(typeof a[c]=="string"||Array.isArray(a[c])&&e.has(a[c][0]));)c++;return c},i=a=>a==="br"||a==="br_if"||a==="br_table",s=a=>{if(!Array.isArray(a))return!1;let c=a[0];if(c==="return_call"||c==="return_call_indirect"||c==="return_call_ref"||c==="try"||c==="try_table"||c==="delegate"||c==="rethrow")return!0;if(i(c)){for(let u=1;u<a.length;u++)if(typeof a[u]=="number"||typeof a[u]=="string"&&/^\d+$/.test(a[u]))return!0}for(let u=1;u<a.length;u++)if(s(a[u]))return!0;return!1},n=(a,c)=>{if(!Array.isArray(a))return!1;if((a[0]==="call"||a[0]==="return_call")&&a[1]===c)return!0;for(let u=1;u<a.length;u++)if(n(a[u],c))return!0;return!1},l=a=>a==="i32"?["i32.const",0]:a==="i64"?["i64.const",0n]:a==="f32"?["f32.const",0]:a==="f64"?["f64.const",0]:a==="v128"?["v128.const","i64x2",0n,0n]:null,f=(a,c)=>{let u=!1,m=!1,y=0,g=p=>{if(u||!Array.isArray(p))return;let _=p[0],b=_==="local.set"||_==="local.tee";if((b||_==="local.get")&&p[1]===c){if(b)for(let A=2;A<p.length&&!u;A++)g(p[A]);if(u)return;u=!0,(_==="local.get"||y>0)&&(m=!0);return}let v=_==="if";for(let A=1;A<p.length&&!u;A++){let S=p[A],I=v&&Array.isArray(S)&&(S[0]==="then"||S[0]==="else");I&&y++,g(S),I&&y--}};for(let p of a){if(u)break;g(p)}return u?m:!1},o=(a,c)=>{if(!Array.isArray(a))return;let u=a[0];if(u==="export"&&Array.isArray(a[2])&&a[2][0]==="func"&&typeof a[2][1]=="string")c.add(a[2][1]);else if(u==="start"&&typeof a[1]=="string")c.add(a[1]);else if(u==="ref.func"&&typeof a[1]=="string")c.add(a[1]);else if(u==="elem")for(let m of a)typeof m=="string"&&m[0]==="$"&&c.add(m);for(let m of a)o(m,c)};for(let a=0;a<16;a++){let c=t.filter(w=>Array.isArray(w)&&w[0]==="func"),u=new Map;for(let w of c)typeof w[1]=="string"&&u.set(w[1],w);let m=new Map,y=new Set,g=w=>{if(!Array.isArray(w))return;let N=w[0];N==="call"&&typeof w[1]=="string"?m.set(w[1],(m.get(w[1])||0)+1):N==="return_call"&&typeof w[1]=="string"&&y.add(w[1]);for(let U=1;U<w.length;U++)g(w[U])};g(t);let p=new Set;for(let w of t)(!Array.isArray(w)||w[0]!=="func")&&o(w,p);let _=null;for(let[w,N]of u){if(p.has(w)||y.has(w)||m.get(w)!==1||n(N,w))continue;let U=!0,it=0;for(let V=2;V<N.length;V++){let j=N[V];if(typeof j!="string"){if(!Array.isArray(j)){U=!1;break}if(j[0]==="param"||j[0]==="local"){if(typeof j[1]!="string"||j[1][0]!=="$"){U=!1;break}if(j[0]==="local"&&!l(j[2])){U=!1;break}}else if(j[0]==="result")it+=j.length-1;else if(j[0]==="export"){U=!1;break}else{if(j[0]==="type")continue;break}}}if(!U||it>1)continue;let st=!1;for(let V=r(N);V<N.length;V++)if(s(N[V])){st=!0;break}if(!st){_=w;break}}if(!_)break;let b=u.get(_),v=[],A=[],S=null;for(let w=2;w<b.length;w++){let N=b[w];if(!(typeof N=="string"||!Array.isArray(N)))if(N[0]==="param")v.push({name:N[1],type:N[2]});else if(N[0]==="result")N.length>1&&(S=N[1]);else if(N[0]==="local")A.push({name:N[1],type:N[2]});else{if(N[0]==="export"||N[0]==="type")continue;break}}let I=b.slice(r(b)),M=++Pr,F=`$__inl${M}`,q=new Map;for(let w of v)q.set(w.name,`$__inl${M}_${w.name.slice(1)}`);for(let w of A)q.set(w.name,`$__inl${M}_${w.name.slice(1)}`);let E=w=>w==="block"||w==="loop"||w==="if",x=new Map,d=w=>{if(Array.isArray(w)){E(w[0])&&typeof w[1]=="string"&&w[1][0]==="$"&&!x.has(w[1])&&x.set(w[1],`$__inl${M}L_${w[1].slice(1)}`);for(let N=1;N<w.length;N++)d(w[N])}};for(let w of I)d(w);let k=w=>{if(!Array.isArray(w))return w;let N=w[0];return(N==="local.get"||N==="local.set"||N==="local.tee")&&typeof w[1]=="string"&&q.has(w[1])?[N,q.get(w[1]),...w.slice(2).map(k)]:N==="return"?["br",F,...w.slice(1).map(k)]:E(N)&&typeof w[1]=="string"&&x.has(w[1])?[N,x.get(w[1]),...w.slice(2).map(k)]:i(N)?[N,...w.slice(1).map(U=>typeof U=="string"&&x.has(U)?x.get(U):k(U))]:w.map((U,it)=>it===0?U:k(U))},L=!1;for(let w of c){if(w===b||L)continue;let N=r(w);for(let U=N;U<w.length;U++){let it=W(w[U],st=>{if(L||!Array.isArray(st)||st[0]!=="call"||st[1]!==_)return;let V=st.slice(2);if(V.length!==v.length)return;let j=v.map((yt,De)=>["local.set",q.get(yt.name),V[De]]),re=A.filter(yt=>f(I,yt.name)).map(yt=>["local.set",q.get(yt.name),l(yt.type)]),ie=I.map(k);return L=!0,S?["block",F,["result",S],...j,...re,...ie]:["block",F,...j,...re,...ie]});if(it!==w[U]&&(w[U]=it),L){let st=[...v,...A].map(V=>["local",q.get(V.name),V.type]);st.length&&w.splice(r(w),0,...st);break}}if(L)break}if(!L)break;let rt=t.indexOf(b);rt>=0&&t.splice(rt,1)}return t},Ft=(t,e)=>{let r=!1,i=(s,n)=>{if(r||!Array.isArray(s))return;let l=s[0],f=n;if((l==="block"||l==="loop")&&typeof s[1]=="string"&&s[1]===e&&(f=!0),!n){if(l==="br"||l==="br_if"||l==="br_on_null"||l==="br_on_non_null"||l==="br_on_cast"||l==="br_on_cast_fail"){if(s[1]===e){r=!0;return}}else if(l==="br_table"){for(let o=1;o<s.length&&typeof s[o]=="string";o++)if(s[o]===e){r=!0;return}}}for(let o=1;o<s.length;o++)i(s[o],f)};for(let s of t)i(s,!1);return r},Gr=t=>(W(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let r=1,i=null;typeof e[1]=="string"&&e[1][0]==="$"&&(i=e[1],r=2);let s=!1;for(;r<e.length;){let f=e[r];if(Array.isArray(f)&&(f[0]==="param"||f[0]==="type")){r++;continue}if(Array.isArray(f)&&f[0]==="result"){s=!0,r++;continue}break}let n=e.slice(r);if(!s||n.length!==1)return;let l=n[0];if(Array.isArray(l)&&!(i&&Ft(n,i))){e.length=0;for(let f of l)e.push(f)}}),C(t,e=>{if(!qe(e))return;let r=1;for(;r<e.length;){let i=e[r];if(!Array.isArray(i)){r++;continue}{let f=i[0],o=f==="local.set"||f==="global.set"?2:f==="drop"?1:-1;if(o>=0&&i.length===o+1){let a=i[o];if(Array.isArray(a)&&a[0]==="block"){let c=1,u=null;typeof a[1]=="string"&&a[1][0]==="$"&&(u=a[1],c=2);let m=!1;for(;c<a.length;){let g=a[c];if(Array.isArray(g)&&(g[0]==="param"||g[0]==="type")){c++;continue}if(Array.isArray(g)&&g[0]==="result"){m=!0,c++;continue}break}let y=m?a.slice(c):null;if(y&&y.length>=2&&!(u&&Ft(y,u))){let g=y[y.length-1],p=y.slice(0,-1);i[o]=g,e.splice(r,1,...p,i);continue}}}}if(i[0]!=="block"){r++;continue}let s=1,n=null;for(typeof i[1]=="string"&&i[1][0]==="$"&&(n=i[1],s=2);s<i.length;){let f=i[s];if(Array.isArray(f)&&(f[0]==="param"||f[0]==="result"||f[0]==="type")){s++;continue}break}let l=i.slice(s);if(n&&Ft(l,n)){r++;continue}e.splice(r,1,...l),r+=l.length}}),t),Hr=t=>(C(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Map;for(let m of e)Array.isArray(m)&&m[0]==="local"&&typeof m[1]=="string"&&m[1][0]==="$"&&typeof m[2]=="string"&&r.set(m[1],m[2]);if(r.size<2)return;let i=new Map,s=[],n=0,l=!1,f=0,o=m=>{if(l||!Array.isArray(m))return;let y=m[0],g=y==="loop";g&&s.push({start:n,end:n});let p=y==="local.set"||y==="local.tee";if(p||y==="local.get"){let _=m[1];if(typeof _!="string"||_[0]!=="$"){l=!0;return}if(p)for(let v=2;v<m.length;v++)o(m[v]);let b=n++;if(r.has(_)){let v=i.get(_);v||(v={start:b,end:b,firstOp:y,firstCond:f>0,loops:new Set},i.set(_,v)),b>v.end&&(v.end=b);for(let A of s)v.loops.add(A)}}else{n++;let _=y==="if";for(let b=1;b<m.length;b++){let v=m[b],A=_&&Array.isArray(v)&&(v[0]==="then"||v[0]==="else");A&&f++,o(v),A&&f--}}if(g){let _=s.pop();_.end=n}};if(o(e),l)return;for(let m of i.values())for(let y of m.loops)y.start<m.start&&(m.start=y.start),y.end>m.end&&(m.end=y.end);let a=[...i.entries()].sort((m,y)=>m[1].start-y[1].start),c=new Map,u=[];for(let[m,y]of a){let g=y.firstOp==="local.get"||y.firstCond,p=r.get(m),_=g?null:u.find(b=>b.type===p&&b.end<y.start);_?(c.set(m,_.primary),y.end>_.end&&(_.end=y.end)):u.push({primary:m,type:p,end:y.end})}c.size!==0&&C(e,m=>{Array.isArray(m)&&(m[0]==="local.get"||m[0]==="local.set"||m[0]==="local.tee")&&c.has(m[1])&&(m[1]=c.get(m[1]))})}),t),Vr=t=>W(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="nop")return["nop"];if(r==="drop"&&e.length===2&&xt(e[1]))return["nop"];if(r==="select"&&e.length>=4&&T(e[1],e[2]))return e[1];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Lt(e),l=!s||s.length<=1,f=!n||n.length<=1;if(l&&f)return xt(i)?["nop"]:["drop",i];if(n&&f&&!l)return e.filter(o=>o!==n)}if(r==="func"||r==="block"||r==="loop"||r==="then"||r==="else"){let i=[r];for(let s=1;s<e.length;s++){let n=e[s];if(n==="nop"||Array.isArray(n)&&n[0]==="nop")continue;let l=e[s+1],f=l==="drop"||Array.isArray(l)&&l[0]==="drop"&&l.length===1;if(Array.isArray(n)&&xt(n)&&f){s++;continue}i.push(n)}if(i.length!==e.length)return i}}),Yr={"i32.sub":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.sub":(t,e)=>T(t,e)?["i64.const",0n]:null,"i32.xor":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.xor":(t,e)=>T(t,e)?["i64.const",0n]:null,"i32.and":(t,e)=>T(t,e)?t:null,"i64.and":(t,e)=>T(t,e)?t:null,"i32.or":(t,e)=>T(t,e)?t:null,"i64.or":(t,e)=>T(t,e)?t:null,"i32.eq":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.eq":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ne":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.ne":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.lt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.lt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.gt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.gt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.le_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.le_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ge_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ge_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.lt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.lt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.gt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.gt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.le_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.le_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.ge_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.ge_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.mul":(t,e)=>{let r=z(t),i=z(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.mul":(t,e)=>{let r=z(t),i=z(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.and":(t,e)=>{let r=z(t),i=z(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.and":(t,e)=>{let r=z(t),i=z(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.or":(t,e)=>{let r=z(t),i=z(e);return r?.value===-1||i?.value===-1?["i32.const",-1]:null},"i64.or":(t,e)=>{let r=z(t),i=z(e);return r?.value===-1n||i?.value===-1n?["i64.const",-1n]:null},"local.set":(t,e)=>Array.isArray(e)&&e[0]==="local.get"&&e[1]===t?["nop"]:null},Xr=t=>W(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=Yr[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Zr=t=>{let e=typeof t=="bigint"?t:BigInt(Math.trunc(Number(t)||0)),r=1;for(;;){let i=e&0x7fn;if(e>>=7n,e===0n&&(i&0x40n)===0n||e===-1n&&(i&0x40n)!==0n)return r;r++}},Kr=t=>{if(!Array.isArray(t))return 4;switch(t[0]){case"i32.const":case"i64.const":return 1+Zr(t[1]);case"f32.const":return 5;case"f64.const":return 9;case"v128.const":return 18;default:return 4}},Qr=2,Jr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Set;for(let n of t.slice(1)){if(!Array.isArray(n))continue;if(n[0]==="export"&&Array.isArray(n[2])&&n[2][0]==="global"&&typeof n[2][1]=="string"){r.add(n[2][1]);continue}if(n[0]!=="global")continue;let l=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null;if(!l)continue;n.some(a=>Array.isArray(a)&&a[0]==="export")&&r.add(l);let f=n[2];if(Array.isArray(f)&&f[0]==="mut"||Array.isArray(f)&&f[0]==="import")continue;let o=n[3];z(o)&&e.set(l,o)}if(e.size===0)return t;let i=new Map;C(t,n=>{if(!Array.isArray(n))return;let l=n[1];typeof l!="string"||l[0]!=="$"||(n[0]==="global.set"?e.delete(l):n[0]==="global.get"&&i.set(l,(i.get(l)||0)+1))});let s=new Set;for(let[n,l]of e){let f=i.get(n)||0;if(f===0)continue;let o=Kr(l),a=o+2,c=f*Qr+a;f*o+(r.has(n)?a:0)<=c&&s.add(n)}if(s.size===0)return t;W(t,n=>{if(!(!Array.isArray(n)||n[0]!=="global.get"||n.length!==2)&&s.has(n[1]))return J(e.get(n[1]))});for(let n=t.length-1;n>=1;n--){let l=t[n];Array.isArray(l)&&l[0]==="global"&&typeof l[1]=="string"&&s.has(l[1])&&!r.has(l[1])&&t.splice(n,1)}return t},ti=t=>W(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(typeof r!="string"||!r.endsWith("load")&&!r.endsWith("store"))return;let i=r.endsWith("store"),s=0,n=null,l=1;for(typeof e[1]=="string"&&(e[1][0]==="$"||!isNaN(e[1]))&&(n=e[1],l=2);l<e.length&&typeof e[l]=="string"&&(e[l].startsWith("offset=")||e[l].startsWith("align="));)e[l].startsWith("offset=")&&(s=+e[l].slice(7)),l++;let f=i?e.length-2:e.length-1,o=i?e.length-1:-1;if(f<l)return;let a=e[f];if(!Array.isArray(a)||a[0]!=="i32.add"||a.length!==3)return;let c=a[1],u=a[2],m=z(c),y=z(u),g=null,p=null;if(m&&m.type==="i32"?(p=m.value,g=u):y&&y.type==="i32"&&(p=y.value,g=c),g===null||p===null)return;let _=s+p,b=[r];n!==null&&b.push(n),b.push(`offset=${_}`);let v=null;for(let A=l;A<f;A++)typeof e[A]=="string"&&e[A].startsWith("align=")&&(v=e[A]);return v&&b.push(v),b.push(g),i&&b.push(e[o]),b}),ei=t=>(C(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let i=1,s=null;if(typeof e[1]=="string"&&e[1][0]==="$"&&(s=e[1],i=2),!s)return;let n=-1;for(let f=e.length-1;f>=i;f--){let o=e[f];if(!Array.isArray(o)){o!=="nop"&&o!=="end"&&(n=f);continue}let a=o[0];if(!(a==="param"||a==="result"||a==="local"||a==="type"||a==="export")){n=f;break}}if(n<0)return;let l=e[n];Array.isArray(l)&&l[0]==="br"&&l[1]===s&&e.splice(n,1,...l.slice(2))}),t),ri=t=>(C(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let r=1,i=null;if(typeof e[1]=="string"&&e[1][0]==="$"&&(i=e[1],r=2),!i)return;for(;r<e.length;){let g=e[r];if(Array.isArray(g)&&g[0]==="type"){r++;continue}if(Array.isArray(g)&&(g[0]==="param"||g[0]==="result"))return;break}if(e.length-r!==1)return;let s=e[r];if(!Array.isArray(s)||s[0]!=="loop")return;let n=1,l=null;typeof s[1]=="string"&&s[1][0]==="$"&&(l=s[1],n=2);let f=[];for(;n<s.length;){let g=s[n];if(Array.isArray(g)&&g[0]==="type"){f.push(g),n++;continue}if(Array.isArray(g)&&(g[0]==="param"||g[0]==="result"))return;break}let o=s.slice(n);if(o.length<2)return;let a=o[0],c=o[o.length-1];if(!Array.isArray(a)||a[0]!=="br_if"||a[1]!==i||a.length!==3||!Array.isArray(c)||c[0]!=="br"||c[1]!==l||c.length!==2)return;let u=o.slice(1,-1);if(Ft(u,i))return;let m=a[2];Array.isArray(m)&&m[0]==="i32.eqz"&&m.length===2?m=m[1]:m=["i32.eqz",m];let y=["loop"];l&&y.push(l);for(let g of f)y.push(g);y.push(["if",m,["then",...u,c]]),e.length=0;for(let g of y)e.push(g)}),t),ii=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set;return C(t,r=>{Array.isArray(r)&&r[0]==="global.set"&&typeof r[1]=="string"&&e.add(r[1])}),W(t,r=>{if(!Array.isArray(r)||r[0]!=="global")return;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i||e.has(i))return;let s=typeof r[1]=="string"&&r[1][0]==="$",n=s?r[2]:r[1];if(Array.isArray(n)&&n[0]==="mut"){let l=[...r];return l[s?2:1]=n[1],l}})},si=t=>W(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{cond:r,thenBranch:i,elseBranch:s}=Lt(e),n=!i||i.length<=1,l=!s||s.length<=1;if(!n&&l&&i.length===2){let f=i[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],r]}if(n&&!l&&s.length===2){let f=s[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],["i32.eqz",r]]}}),ni=t=>W(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{thenBranch:r,elseBranch:i}=Lt(e);if(!r||!i||r.length<=1||i.length<=1||!e.some(m=>Array.isArray(m)&&m[0]==="result"))return;let n=0,l=Math.min(r.length,i.length);for(let m=1;m<l&&T(r[r.length-m],i[i.length-m]);m++)n++;if(n===0)return;let f=r.slice(r.length-n),o=r.slice(0,r.length-n),a=i.slice(0,i.length-n),c=["block"];for(let m=1;m<e.length;m++){let y=e[m];if(Array.isArray(y)&&(y[0]==="then"||y[0]==="else"))break;Array.isArray(y)&&(y[0]==="result"||y[0]==="type")&&c.push(y)}let u=["if"];for(let m=1;m<e.length;m++){let y=e[m];if(Array.isArray(y)&&(y[0]==="then"||y[0]==="else"))break;Array.isArray(y)&&(y[0]==="result"||y[0]==="type")||u.push(y)}return u.push(o.length>1?o:["then"]),u.push(a.length>1?a:["else"]),c.push(u,...f),c}),Fe=(t,e)=>{let r=[],i=[t];for(;i.length;){let s=i.pop();if(Array.isArray(s)){i.push("|");for(let n=s.length-1;n>=0;n--)i.push(s[n]);i.push("[")}else typeof s=="string"?r.push(e.has(s)?"$__L":s):typeof s=="bigint"?r.push(s.toString()+"n"):typeof s=="number"?r.push(s.toString()):s===null?r.push("null"):s===!0?r.push("t"):s===!1?r.push("f"):r.push(String(s))}return r.join(",")},li=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="func")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=new Set;typeof i[1]=="string"&&i[1][0]==="$"&&n.add(i[1]),C(i,f=>{if(!Array.isArray(f)||typeof f[1]!="string"||f[1][0]!=="$")return;let o=f[0];(o==="param"||o==="local"||o==="block"||o==="loop"||o==="if")&&n.add(f[1])});let l=Fe(i,n);e.has(l)?r.set(s,e.get(l)):e.set(l,s)}return r.size===0||W(t,i=>{if(!Array.isArray(i))return;let s=i[0];if((s==="call"||s==="return_call")&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(s==="ref.func"&&r.has(i[1]))return["ref.func",r.get(i[1])];if(s==="elem"){let n=i[i.length-1];if(Array.isArray(n))return[...i.slice(0,-1),n.map(l=>r.get(l)||l)]}if(s==="call_indirect"&&i.length>=3){let n=i[1];if(typeof n=="string"&&r.has(n))return["call_indirect",r.get(n),...i.slice(2)]}}),t},fi=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="type")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=Fe(i,new Set([s]));e.has(n)?r.set(s,e.get(n)):e.set(n,s)}if(r.size===0)return t;for(let i=t.length-1;i>=0;i--){let s=t[i];if(Array.isArray(s)&&s[0]==="type"){let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;n&&r.has(n)&&t.splice(i,1)}}return W(t,i=>{if(!Array.isArray(i))return;let s=i[0];if(s==="func")for(let n=1;n<i.length;n++){let l=i[n];Array.isArray(l)&&l[0]==="type"&&typeof l[1]=="string"&&r.has(l[1])&&(i[n]=["type",r.get(l[1])])}if(s==="import")for(let n=1;n<i.length;n++){let l=i[n];if(Array.isArray(l))for(let f=1;f<l.length;f++){let o=l[f];Array.isArray(o)&&o[0]==="type"&&typeof o[1]=="string"&&r.has(o[1])&&(l[f]=["type",r.get(o[1])])}}if(s==="call_indirect"||s==="return_call_indirect"){if(typeof i[1]=="string"&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(Array.isArray(i[1])&&i[1][0]==="type"&&typeof i[1][1]=="string"&&r.has(i[1][1]))return[s,["type",r.get(i[1][1])],...i.slice(2)]}}),t},Ot=t=>{if(typeof t!="string"||t.length<2||t[0]!=='"')return new Uint8Array;let e=t.slice(1,-1),r=[];for(let i=0;i<e.length;i++)if(e[i]==="\\"){let s=e[++i];s==="x"||s==="X"?(r.push(parseInt(e.slice(i+1,i+3),16)),i+=2):/[0-9a-fA-F]/.test(s)&&/[0-9a-fA-F]/.test(e[i+1])?(r.push(parseInt(e.slice(i,i+2),16)),i++):s==="n"?r.push(10):s==="t"?r.push(9):s==="r"?r.push(13):s==="\\"?r.push(92):s==='"'?r.push(34):r.push(s.charCodeAt(0))}else r.push(e.charCodeAt(i));return new Uint8Array(r)},Oe=t=>{let e='"';for(let r=0;r<t.length;r++){let i=t[r];i>=32&&i<127&&i!==34&&i!==92?e+=String.fromCharCode(i):e+="\\"+i.toString(16).padStart(2,"0")}return e+'"'},ai=t=>{let e=[];for(let i of t)if(typeof i=="string")e.push(...Ot(i));else if(Array.isArray(i)&&i[0]==="i8")for(let s=1;s<i.length;s++)e.push(Number(i[s])&255);else return t;let r=e.length;for(;r>0&&e[r-1]===0;)r--;return r===e.length?t:r===0?[]:[Oe(new Uint8Array(e.slice(0,r)))]},oi=t=>{let e=1;if(typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"){let i=t[e][1];e++;let s=t[e];return Array.isArray(s)&&(s[0]==="i32.const"||s[0]==="i64.const")?{memidx:i,offset:Number(s[1])}:null}let r=t[e];return Array.isArray(r)&&(r[0]==="i32.const"||r[0]==="i64.const")?{memidx:0,offset:Number(r[1])}:null},Ne=t=>{let e=1;typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"&&e++,Array.isArray(t[e])&&typeof t[e][0]=="string"&&!t[e][0].startsWith('"')&&e++;let r=0;for(let i=e;i<t.length;i++){let s=t[i];if(typeof s=="string")r+=Ot(s).length;else if(Array.isArray(s)&&s[0]==="i8")r+=s.length-1;else return null}return r},ci=(t,e)=>{let r=1;typeof t[r]=="string"&&t[r][0]==="$"&&r++,Array.isArray(t[r])&&t[r][0]==="memory"&&r++,Array.isArray(t[r])&&typeof t[r][0]=="string"&&!t[r][0].startsWith('"')&&r++;let i=1;typeof e[i]=="string"&&e[i][0]==="$"&&i++,Array.isArray(e[i])&&e[i][0]==="memory"&&i++,Array.isArray(e[i])&&typeof e[i][0]=="string"&&!e[i][0].startsWith('"')&&i++;let s=t.slice(r),n=e.slice(i);if(s.length===1&&n.length===1&&typeof s[0]=="string"&&typeof n[0]=="string"){let l=Ot(s[0]),f=Ot(n[0]),o=new Uint8Array(l.length+f.length);return o.set(l),o.set(f,l.length),t.length=r,t.push(Oe(o)),!0}return t.length=r,t.push(...s,...n),!0},ui=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;for(let i of t){if(!Array.isArray(i)||i[0]!=="data")continue;let s=1;typeof i[1]=="string"&&i[1][0]==="$"&&(s=2),s<i.length&&Array.isArray(i[s])&&typeof i[s][0]=="string"&&!i[s][0].startsWith('"')&&s++;let n=i.slice(s);if(n.length===0)continue;let l=ai(n);(l.length!==n.length||l.length>0&&l[0]!==n[0])&&(i.length=s,i.push(...l))}let e=[];for(let i=0;i<t.length;i++){let s=t[i];if(Array.isArray(s)&&s[0]==="data"){let n=oi(s);if(n){let l=Ne(s);l!==null&&e.push({...n,node:s,index:i,len:l})}}}e.sort((i,s)=>{let n=String(i.memidx),l=String(s.memidx);return n!==l?n.localeCompare(l):i.offset-s.offset});let r=new Set;for(let i=0;i<e.length-1;i++){let s=e[i],n=e[i+1];r.has(s.index)||String(s.memidx)!==String(n.memidx)||s.offset+s.len===n.offset&&ci(s.node,n.node)&&(r.add(n.index),s.len=Ne(s.node))}return r.size>0&&(t=t.filter((i,s)=>!r.has(s))),t},Se=()=>{let t=new Map,e=0;return r=>{if(!t.has(r)){let i="",s=e++;do i=String.fromCharCode(97+s%26)+i,s=Math.floor(s/26)-1;while(s>=0);t.set(r,i||"a")}return t.get(r)}},yi=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=Se(),r=Se();for(let i of t)!Array.isArray(i)||i[0]!=="import"||(typeof i[1]=="string"&&i[1][0]==='"'&&(i[1]='"'+e(i[1].slice(1,-1))+'"'),typeof i[2]=="string"&&i[2][0]==='"'&&(i[2]='"'+r(i[2].slice(1,-1))+'"'));return t},mi=t=>{let e=!0;return C(t,r=>{if(!e||!Array.isArray(r))return;let i=r[0];if(i==="func"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if((i==="call"||i==="return_call"||i==="ref.func")&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="start"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="elem")for(let s of r){if(typeof s=="string"&&s[0]!=="$"&&/^\d/.test(s)){e=!1;break}if(Array.isArray(s)&&s[0]==="ref.func"&&(typeof s[1]!="string"||s[1][0]!=="$")){e=!1;break}}}),e},pi=t=>{if(!Array.isArray(t)||t[0]!=="module"||!mi(t))return t;let e=new Map;C(t,n=>{Array.isArray(n)&&(n[0]==="call"||n[0]==="return_call")&&e.set(n[1],(e.get(n[1])||0)+1)});let r=[],i=[],s=[];for(let n of t.slice(1)){if(!Array.isArray(n)){s.push(n);continue}n[0]==="import"?r.push(n):n[0]==="func"?i.push(n):s.push(n)}return i.sort((n,l)=>(e.get(l[1])||0)-(e.get(n[1])||0)),["module",...r,...i,...s]};function Ct(t,e=!0){typeof t=="string"&&(t=Z(t));let r=e===!0;e=xr(e);let i=e.log?(l,f)=>e.log(l,f):()=>{},s=e.verbose||e.log;t=J(t);let n=null;for(let l=0;l<3;l++){n=J(t);let f=ve(t);e.stripmut&&(t=ii(t)),e.globals&&(t=Jr(t)),e.fold&&(t=Mr(t)),e.identity&&(t=Nr(t)),e.peephole&&(t=Xr(t)),e.strength&&(t=Sr(t)),e.branch&&(t=zr(t)),e.propagate&&(t=Be(t)),e.inlineOnce&&(t=jr(t)),e.inline&&(t=Wr(t)),e.offset&&(t=ti(t)),e.unbranch&&(t=ei(t)),e.loopify&&(t=ri(t)),e.brif&&(t=si(t)),e.foldarms&&(t=ni(t)),e.deadcode&&(t=Tr(t)),e.vacuum&&(t=Vr(t)),e.mergeBlocks&&(t=Gr(t)),e.coalesce&&(t=Hr(t)),e.locals&&(t=Er(t)),e.dedupe&&(t=li(t)),e.dedupTypes&&(t=fi(t)),e.packData&&(t=ui(t)),e.reorder&&(t=pi(t)),e.treeshake&&(t=dr(t)),e.minifyImports&&(t=yi(t)),e.propagate&&(e.inlineOnce||e.inline)&&(t=Be(t));let a=ve(t)-f;if((s||a!==0)&&i(` round ${l+1}: ${a>0?"+":""}${a} bytes`,a),a>(r?0:16)){s&&i(` \u26A0 round ${l+1} inflated by ${a} bytes, reverting`,a),t=n;break}if(T(n,t))break}return t}var Le="\uE000",Ce=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},gi=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t;return Ce(r)?Ce(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 ee(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=ee(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function _i(t,e){let r=[],i=new Map;return ee(t,s=>{if(!Array.isArray(s))return s;if(s[0]==="call"&&typeof s[1]=="function"){let n=s[1];if(!i.has(n)){let f=[];for(let c=2;c<s.length;c++){let u=gi(s[c]);u&&f.push(u)}let o=r.length,a=n.name||`$fn${o}`;i.set(n,{idx:o,name:a.startsWith("$")?a:"$"+a,params:f,fn:n}),r.push(i.get(n))}let l=i.get(n);s[1]=l.name}return s}),r}function hi(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function xi(t,...e){let r={};if(!Array.isArray(t)&&e.length&&typeof e[e.length-1]=="object"&&e[e.length-1]!==null&&!e[e.length-1].byteLength&&(r=e.pop()),Array.isArray(t)&&t.raw){let i=t[0];for(let a=0;a<e.length;a++)i+=Le+t[a+1];let s=Z(i),n=[],l=0;s=ee(s,a=>{if(a===Le){let c=e[l++];if(typeof c=="function")return n.push(c),c;if(typeof c=="string"&&(c[0]==="("||/^\s*\(/.test(c))){let u=Z(c);return Array.isArray(u)&&Array.isArray(u[0])&&(u._splice=!0),u}return c.byteLength!==void 0?[...c]:c}return a});let f=null;if(n.length){let a=_i(s,n);if(a.length){let c=hi(a);s[0]==="module"?s.splice(1,0,...c):typeof s[0]=="string"?s=[...c,s]:s.unshift(...c),f={env:{}};for(let u of a)f.env[u.name.slice(1)]=u.fn}}r.polyfill&&(s=Et(s,r.polyfill)),r.optimize&&(s=Ct(s,r.optimize));let o=ct(s);return f&&(o._imports=f),o}if(r.polyfill||r.optimize){let i=typeof t=="string"?Z(t):t;return r.polyfill&&(i=Et(i,r.polyfill)),r.optimize&&(i=Ct(i,r.optimize)),ct(i)}return ct(t)}function di(t,...e){let r=xi(t,...e),i=new WebAssembly.Module(r);return new WebAssembly.Instance(i,r._imports).exports}var ji=di;export{xi as compile,ji as default,Ct as optimize,Z as parse,Et as polyfill,he as print,di as watr};
|
|
6
|
+
`?a+="":(p&&p!==")"&&p!==" "||i||p===")")&&(a+=" "),a+=g,c=!1}}return u?`(${a.replaceAll(i+m+"("," (")})`:`(${a+i+r.repeat(o)})`}}var de={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"]},Ht=Object.keys(de),sr=t=>{if(t===!0)return Object.fromEntries(Ht.map(e=>[e,!0]));if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return Object.fromEntries(Ht.map(r=>[r,e.has(r)||e.has("all")]))}return{...t}},P=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)P(t[s],e,t,s)},et=(t,e,r,i)=>{if(Array.isArray(t))for(let s=0;s<t.length;s++)et(t[s],e,t,s);e(t,r,i)},nr=t=>{let e=new Set;return P(t,r=>{if(typeof r=="string")for(let[i,s]of Object.entries(de))s.some(n=>r===n||r.startsWith(n+" "))&&e.add(i)}),P(t,r=>{if(!(!Array.isArray(r)||r[0]!=="global"))for(let i of r)Array.isArray(i)&&(i[0]==="i32.add"||i[0]==="i32.sub"||i[0]==="i32.mul"||i[0]==="i64.add"||i[0]==="i64.sub"||i[0]==="i64.mul")&&P(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),P(t,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=0;for(let s of r)Array.isArray(s)&&s[0]==="result"&&(i+=s.length-1);i>1&&e.add("multi_value")}),e},Ae=t=>Array.isArray(t)?t.map(Ae):t,be=(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},Tt=(t,e,r)=>t.splice(e,0,r),lr=0,nt=t=>`$__${t}${lr++}`,fr=(t,e)=>{let r=new Set;if(P(t,a=>{Array.isArray(a)&&a[0]==="ref.func"&&r.add(a[1])}),!r.size)return t;let i=nt("fntbl"),s=[...r],n=Object.fromEntries(s.map((a,c)=>[a,c])),l=be(t,"func"),f=l.length?l[0].idx:t[0]==="module"?1:0;Tt(t,f,["table",i,"funcref",["elem",...s]]);let o={};return P(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!c)return;let u=[],m=[];for(let y of a){if(Array.isArray(y)&&y[0]==="param")for(let g=1;g<y.length;g++)y[g][0]!=="$"&&u.push(y[g]);if(Array.isArray(y)&&y[0]==="result")for(let g=1;g<y.length;g++)m.push(y[g])}o[c]={params:u,results:m}}),et(t,(a,c,u)=>{if(!(!Array.isArray(a)||!c)){if(a[0]==="ref.func"&&n[a[1]]!==void 0&&(c[u]=["i32.const",n[a[1]]]),a[0]==="call_ref"){let m=a[1],y=a.slice(2);c[u]=["call_indirect",i,["type",m],...y]}if(a[0]==="return_call_ref"){let m=a[1],y=a.slice(2);c[u]=["return_call_indirect",i,["type",m],...y]}}}),t},tt={funcref:fr},ar={"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]},or=(t,e)=>(et(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let n=ar[r[0]];if(!n)return;let[l,f]=n,o=r.slice(1);i[s]=[`${l}.shr_s`,[`${l}.shl`,...o,[`${l}.const`,f]],[`${l}.const`,f]]}),t);tt.sign_ext=or;var xe={"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}},cr=(t,e)=>{let r=new Set;if(P(t,s=>{Array.isArray(s)&&xe[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:n,ftype:l,signed:f,min:o,max:a}=xe[s],c=nt(`trunc_${n}_${l}_${f?"s":"u"}`);i[s]=c;let u=`${n}.trunc_${l}_${f?"s":"u"}`,m=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`,m]],["else",["if",["result",n],[`${l}.lt`,["local.get","$v"],[`${l}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${n}.const`,o]],["else",["if",["result",n],[`${l}.gt`,["local.get","$v"],[`${l}.const`,typeof a=="bigint"?Number(a):a]],["then",[`${n}.const`,a]],["else",[u,["local.get","$v"]]]]]]]]];t.push(y)}return et(t,(s,n,l)=>{!Array.isArray(s)||!n||i[s[0]]&&(n[l]=["call",i[s[0]],...s.slice(1)])}),t};tt.nontrapping=cr;var ur=(t,e)=>{let r=new Set,i=new Set;P(t,l=>{if(Array.isArray(l)){if(l[0]==="memory.copy"){let f=typeof l[1]=="number"?l[1]:0,o=typeof l[2]=="number"?l[2]:0;r.add(`${f}_${o}`)}if(l[0]==="memory.fill"){let f=typeof l[1]=="number"?l[1]:0;i.add(f)}}});let s={},n={};for(let l of r){let[f,o]=l.split("_").map(Number),a=nt(`memcpy${l==="0_0"?"":"_"+l}`);s[l]=a;let c=f?["i32.store8",f]:["i32.store8"],u=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",a,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...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 i){let f=nt(`memset${l===0?"":"_"+l}`);n[l]=f;let o=l?["i32.store8",l]:["i32.store8"];t.push(["func",f,["param","$dst","i32"],["param","$val","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...o,["i32.add",["local.get","$dst"],["local.get","$i"]],["local.get","$val"]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}return et(t,(l,f,o)=>{if(!(!Array.isArray(l)||!f)){if(l[0]==="memory.copy"){let a=typeof l[1]=="number"?l[1]:0,c=typeof l[2]=="number"?l[2]:0,u=l.filter(m=>Array.isArray(m)||typeof m=="string"&&m[0]==="$");f[o]=["call",s[`${a}_${c}`],...u]}if(l[0]==="memory.fill"){let a=typeof l[1]=="number"?l[1]:0,c=l.filter(u=>Array.isArray(u)||typeof u=="string"&&u[0]==="$");f[o]=["call",n[a],...c]}}}),t};tt.bulk_memory=ur;var yr=(t,e)=>{let r=!1;return P(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&et(t,(i,s,n)=>{!Array.isArray(i)||!s||(i[0]==="return_call"&&(s[n]=["return",["call",...i.slice(1)]]),i[0]==="return_call_indirect"&&(s[n]=["return",["call_indirect",...i.slice(1)]]))}),t};tt.return_call=yr;var mr=(t,e)=>(et(t,(r,i,s)=>{if(!(!Array.isArray(r)||!i)&&(r[0]==="ref.i31"&&(i[s]=["i32.and",...r.slice(1),["i32.const",2147483647]]),r[0]==="i31.get_u"&&(i[s]=r.length>1?r[1]:["drop"]),r[0]==="i31.get_s")){let n=r.slice(1);i[s]=["i32.shr_s",["i32.shl",...n,["i32.const",1]],["i32.const",1]]}}),t);tt.i31ref=mr;var pr=(t,e)=>{let r={};P(t,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l=s.length-1;l>=0;l--){let f=s[l];if(Array.isArray(f)&&(f[0]==="i32.const"||f[0]==="i64.const"||f[0]==="f32.const"||f[0]==="f64.const")){r[n]={type:f[0].split(".")[0],value:f[1]};break}}});let i=s=>{if(!Array.isArray(s))return s;let n=s[0];if(n==="global.get"&&r[s[1]]){let l=r[s[1]];return[`${l.type}.const`,l.value]}if(n==="i32.add"||n==="i64.add"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a+c]}}if(n==="i32.sub"||n==="i64.sub"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a-c]}}if(n==="i32.mul"||n==="i64.mul"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let o=n.split(".")[0],a=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(f[1]):Number(f[1]);return[`${o}.const`,a*c]}}return s};return et(t,(s,n,l)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!n)){for(let f=2;f<s.length;f++)if(Array.isArray(s[f])){let o=i(s[f]);o!==s[f]&&(s[f]=o)}}}),t};tt.extended_const=pr;var gr=(t,e)=>{let r=new Map,i=[];if(P(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let o=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null,a=[];for(let c of f)if(Array.isArray(c)&&c[0]==="result")for(let u=1;u<c.length;u++)a.push(c[u]);a.length>1&&o&&r.set(o,a)}),!r.size)return t;let s=Math.max(...[...r.values()].map(f=>f.length)),n={};for(let[f,o]of r)for(let a=1;a<o.length;a++){let c=o[a];if(n[c]||(n[c]=[]),n[c].length<a){let u=nt(`ret_${c}_${n[c].length}`);n[c].push(u),i.push(["global",u,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let l=t[0]==="module"?1:0;for(let f of i.reverse())Tt(t,l,f);return et(t,(f,o,a)=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c||!r.has(c))return;let u=r.get(c);for(let m=0;m<f.length;m++)if(Array.isArray(f[m])&&f[m][0]==="result"){f[m]=["result",u[0]];break}}),t};tt.multi_value=gr;var bt={i32:4,i64:8,f32:4,f64:8},_r=(t,e)=>{let r=new Map,i=new Map,s=1;if(P(t,p=>{if(!Array.isArray(p)||p[0]!=="type")return;let _=typeof p[1]=="string"&&p[1][0]==="$"?p[1]:null;if(_){for(let b of p)if(Array.isArray(b)){if(b[0]==="struct"){let v=[];for(let A of b)if(Array.isArray(A)&&A[0]==="field"){let S=typeof A[1]=="string"&&A[1][0]==="$"?A[1]:null,I=S?A[2]:A[1],M=Array.isArray(I)&&I[0]==="mut"?I[1]:I;v.push({name:S,type:M})}r.set(_,{kind:"struct",fields:v}),i.set(_,s++)}if(b[0]==="array"){let v=b[1],A=Array.isArray(v)&&v[0]==="mut"?v[1]:v;r.set(_,{kind:"array",elemType:A}),i.set(_,s++)}}}}),!r.size)return t;let n=be(t,"memory").length>0,l=nt("alloc"),f=nt("heap_ptr"),o=t[0]==="module"?1:0;n||Tt(t,o,["memory",1]),Tt(t,o+1,["global",f,["mut","i32"],["i32.const",1024]]);let a=["func",l,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",f]],["global.set",f,["i32.add",["global.get",f],["local.get","$size"]]],["local.get","$ptr"]];t.push(a);let c=p=>{let _=4;for(let b of p.fields)_+=bt[b.type]||4;return _},u=(p,_)=>{let b=4;for(let v=0;v<_;v++)b+=bt[p.fields[v].type]||4;return b},m=(p,_)=>{for(let b=0;b<p.fields.length;b++)if(p.fields[b].name===_)return b;return-1},y=0,g=()=>`$__gc_tmp${y++}`;return P(t,p=>{if(!Array.isArray(p)||p[0]!=="func")return;let _=!1,b=!1,v=!1,A=!1;if(P(p,I=>{Array.isArray(I)&&((I[0]==="struct.new"||I[0]==="struct.new_default")&&(_=!0),(I[0]==="array.new"||I[0]==="array.new_default")&&(b=!0,v=!0,A=!0))}),!_&&!b)return;let S=1;for(let I=1;I<p.length;I++){let M=p[I];if(Array.isArray(M)&&(M[0]==="param"||M[0]==="result"||M[0]==="local"||M[0]==="export"||M[0]==="type"))S=I+1;else if(typeof M=="string"&&M[0]==="$")S=I+1;else if(!Array.isArray(M))S=I+1;else break}_&&p.splice(S++,0,["local","$__gc_ptr","i32"]),b&&p.splice(S++,0,["local","$__gc_aptr","i32"]),v&&p.splice(S++,0,["local","$__gc_alen","i32"]),A&&p.splice(S++,0,["local","$__gc_aidx","i32"])}),et(t,(p,_,b)=>{if(!(!Array.isArray(p)||!_)){if(p[0]==="struct.new"||p[0]==="struct.new_default"){let v=p[1],A=r.get(v);if(!A||A.kind!=="struct")return;let S=c(A),I=i.get(v),M=p.slice(2),F="$__gc_ptr",q=[["local.set",F,["call",l,["i32.const",S]]],["i32.store",["local.get",F],["i32.const",I]]];if(p[0]==="struct.new")for(let E=0;E<A.fields.length;E++){let x=A.fields[E],d=u(A,E),k=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store";q.push([k,["i32.add",["local.get",F],["i32.const",d]],M[E]||[`${x.type}.const`,0]])}else for(let E=0;E<A.fields.length;E++){let x=A.fields[E],d=u(A,E),k=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store",L=x.type==="i64"?["i64.const",0n]:x.type==="f32"?["f32.const",0]:x.type==="f64"?["f64.const",0]:["i32.const",0];q.push([k,["i32.add",["local.get",F],["i32.const",d]],L])}q.push(["local.get",F]),_[b]=["block",["result","i32"],...q]}if(p[0]==="struct.get"){let v=p[1],A=p[2],S=p[3],I=r.get(v);if(!I||I.kind!=="struct")return;let M=typeof A=="string"&&A[0]==="$"?m(I,A):parseInt(A);if(M<0)return;let F=I.fields[M],q=u(I,M),E=F.type==="i64"?"i64.load":F.type==="f32"?"f32.load":F.type==="f64"?"f64.load":"i32.load";_[b]=[E,["i32.add",S,["i32.const",q]]]}if(p[0]==="struct.set"){let v=p[1],A=p[2],S=p[3],I=p[4],M=r.get(v);if(!M||M.kind!=="struct")return;let F=typeof A=="string"&&A[0]==="$"?m(M,A):parseInt(A);if(F<0)return;let q=M.fields[F],E=u(M,F),x=q.type==="i64"?"i64.store":q.type==="f32"?"f32.store":q.type==="f64"?"f64.store":"i32.store";_[b]=[x,["i32.add",S,["i32.const",E]],I]}if(p[0]==="array.new"||p[0]==="array.new_default"){let v=p[1],A=r.get(v);if(!A||A.kind!=="array")return;let S=i.get(v),I=bt[A.elemType]||4,M=p[0]==="array.new"?p[2]:null,F=p[0]==="array.new"?p[3]:p[2],q="$__gc_aptr",E="$__gc_alen",x="$__gc_aidx",d=A.elemType==="i64"?"i64.store":A.elemType==="f32"?"f32.store":A.elemType==="f64"?"f64.store":"i32.store",k=[["local.set",E,F],["local.set",q,["call",l,["i32.add",["i32.const",8],["i32.mul",["local.get",E],["i32.const",I]]]]],["i32.store",["local.get",q],["i32.const",S]],["i32.store",["i32.add",["local.get",q],["i32.const",4]],["local.get",E]]];M&&k.push(["local.set",x,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",x],["local.get",E]]],[d,["i32.add",["i32.add",["local.get",q],["i32.const",8]],["i32.mul",["local.get",x],["i32.const",I]]],M],["local.set",x,["i32.add",["local.get",x],["i32.const",1]]],["br","$loop"]]]),k.push(["local.get",q]),_[b]=["block",["result","i32"],...k]}if(p[0]==="array.get"){let v=p[1],A=p[2],S=p[3],I=r.get(v);if(!I||I.kind!=="array")return;let M=bt[I.elemType]||4,F=I.elemType==="i64"?"i64.load":I.elemType==="f32"?"f32.load":I.elemType==="f64"?"f64.load":"i32.load";_[b]=[F,["i32.add",["i32.add",A,["i32.const",8]],["i32.mul",S,["i32.const",M]]]]}if(p[0]==="array.set"){let v=p[1],A=p[2],S=p[3],I=p[4],M=r.get(v);if(!M||M.kind!=="array")return;let F=bt[M.elemType]||4,q=M.elemType==="i64"?"i64.store":M.elemType==="f32"?"f32.store":M.elemType==="f64"?"f64.store":"i32.store";_[b]=[q,["i32.add",["i32.add",A,["i32.const",8]],["i32.mul",S,["i32.const",F]]],I]}if(p[0]==="array.len"){let v=p[1];_[b]=["i32.load",["i32.add",v,["i32.const",4]]]}}}),t};tt.gc=_r;var hr=(t,e)=>{let r=new Map,i=1;return P(t,s=>{if(!Array.isArray(s)||s[0]!=="type")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l of s)Array.isArray(l)&&(l[0]==="struct"||l[0]==="array")&&r.set(n,i++)}),r.size&&et(t,(s,n,l)=>{if(!(!Array.isArray(s)||!n)){if(s[0]==="ref.test"){let f=s[1],o=null;Array.isArray(f)&&f[0]==="ref"&&(o=f[1]==="null"?f[2]:f[1]);let a=s[2],c=r.get(o);c!==void 0&&(n[l]=["if",["result","i32"],["i32.eqz",a],["then",["i32.const",0]],["else",["i32.eq",["i32.load",a],["i32.const",c]]]])}if(s[0]==="ref.cast"){let f=s[1],o=null,a=!1;Array.isArray(f)&&f[0]==="ref"&&(f[1]==="null"?(a=!0,o=f[2]):o=f[1]);let c=s[2],u=r.get(o);if(u!==void 0){let m=nt("cast");a?n[l]=["block",["result","i32"],["local",m,"i32"],["local.set",m,c],["if",["i32.and",["i32.ne",["local.get",m],["i32.const",0]],["i32.ne",["i32.load",["local.get",m]],["i32.const",u]]],["then",["unreachable"]]],["local.get",m]]:n[l]=["block",["result","i32"],["local",m,"i32"],["local.set",m,c],["if",["i32.or",["i32.eqz",["local.get",m]],["i32.ne",["i32.load",["local.get",m]],["i32.const",u]]],["then",["unreachable"]]],["local.get",m]]}}if(s[0]==="br_on_cast"){let f=s[1],o=s[2],a=s[3],c=s[4],u=null;Array.isArray(a)&&a[0]==="ref"&&(u=a[1]==="null"?a[2]:a[1]);let m=r.get(u);if(m!==void 0){let y=nt("brcast");n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["br_if",f,["i32.and",["i32.ne",["local.get",y],["i32.const",0]],["i32.eq",["i32.load",["local.get",y]],["i32.const",m]]]],["local.get",y]]}}if(s[0]==="br_on_cast_fail"){let f=s[1],o=s[2],a=s[3],c=s[4],u=null;Array.isArray(a)&&a[0]==="ref"&&(u=a[1]==="null"?a[2]:a[1]);let m=r.get(u);if(m!==void 0){let y=nt("brfail");n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["br_if",f,["i32.or",["i32.eqz",["local.get",y]],["i32.ne",["i32.load",["local.get",y]],["i32.const",m]]]],["local.get",y]]}}}}),t};tt.ref_cast=hr;function Et(t,e=!0){typeof t=="string"&&(t=Z(t)),t=Ae(t),e=sr(e);let r=nr(t),i={uid:0};for(let s of Ht)r.has(s)&&e[s]!==!1&&tt[s]&&(t=tt[s](t,i));return t}var Vt={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!1,inlineOnce:!0,vacuum:!0,mergeBlocks:!0,coalesce:!0,peephole:!0,globals:!0,offset:!0,unbranch:!0,loopify:!0,stripmut:!0,brif:!0,foldarms:!1,dedupe:!0,reorder:!1,dedupTypes:!0,packData:!0,minifyImports:!1},we=Object.keys(Vt);var ve=t=>{try{return ct(t).length}catch{return 1/0}},T=(t,e)=>{if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="bigint")return t===e;if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!T(t[r],e[r]))return!1;return!0},xr=t=>{if(t===!0)return{...Vt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.has("all")?Object.fromEntries(we.map(r=>[r,!0])):Object.fromEntries(we.map(r=>[r,e.has(r)]))}return{...Vt,...t}},J=t=>Array.isArray(t)?t.map(J):t,C=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)C(t[s],e,t,s)},W=(t,e,r,i)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++){let l=W(t[n],e,t,n);l!==void 0&&(t[n]=l)}let s=e(t,r,i);return s!==void 0?s:t},Lt=t=>{let e=1;for(;e<t.length;){let s=t[e];if(Array.isArray(s)&&(s[0]==="then"||s[0]==="else"||s[0]==="result"||s[0]==="param")){e++;continue}break}let r=null,i=null;for(let s=e+1;s<t.length;s++){let n=t[s];Array.isArray(n)&&(n[0]==="then"?r=n:n[0]==="else"&&(i=n))}return{condIdx:e,cond:t[e],thenBranch:r,elseBranch:i}},dr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=new Map,n=new Map,l=new Map,f=(x,d,k,L=!1)=>{let rt=typeof d[1]=="string"&&d[1][0]==="$",w=rt?d[1]:k,N=!L&&d.some(it=>Array.isArray(it)&&it[0]==="export"),U={node:d,idx:k,used:N,isImport:L};return x.set(w,U),rt&&x.set(k,U),l.set(d,U),U},o=0,a=0,c=0,u=0,m=0,y=[],g=[],p=[],_=[];for(let x of t.slice(1)){if(!Array.isArray(x))continue;let d=x[0];if(d==="type")f(i,x,c++);else if(d==="func")f(e,x,o++);else if(d==="global")f(r,x,a++);else if(d==="table")f(s,x,u++);else if(d==="memory")f(n,x,m++);else if(d==="import")for(let k of x)Array.isArray(k)&&(k[0]==="func"?f(e,k,o++,!0):k[0]==="global"?f(r,k,a++,!0):k[0]==="table"?f(s,k,u++,!0):k[0]==="memory"&&f(n,k,m++,!0));else d==="export"?p.push(x):d==="start"?_.push(x):d==="elem"?y.push(x):d==="data"&&g.push(x)}let b=[],v=x=>{x&&!x.scanned&&b.push(x)},A=x=>{let d=e.get(x);d&&(d.used||(d.used=!0),v(d))},S=x=>{let d=r.get(x);d&&(d.used=!0)},I=x=>{let d=s.get(x);d&&(d.used=!0)},M=x=>{typeof x=="string"&&x[0]!=="$"&&(x=+x);let d=n.get(x);d&&(d.used=!0)},F=x=>{let d=i.get(x);d&&(d.used=!0)};for(let x of p)for(let d of x){if(!Array.isArray(d))continue;let[k,L]=d;k==="func"?A(L):k==="global"?S(L):k==="table"?I(L):k==="memory"&&M(L)}for(let x of _){let d=x[1];typeof d=="string"&&d[0]!=="$"&&(d=+d),A(d)}for(let x of y)C(x,d=>{Array.isArray(d)&&d[0]==="ref.func"?A(d[1]):typeof d=="string"&&d[0]==="$"&&A(d)});for(let x of g){let d=x[1];Array.isArray(d)&&d[0]==="memory"?M(d[1]):typeof d=="string"&&d[0]==="$"?M(d):Array.isArray(d)&&M(0)}for(let x of[e,r,s,n])for(let d of x.values())d.used&&v(d);if(!(p.length>0||_.length>0||y.length>0||b.length>0)){for(let x of[e,r,s,n])for(let d of x.values())d.used=!0;return t}for(;b.length;){let x=b.pop();x.scanned||(x.scanned=!0,!x.isImport&&C(x.node,d=>{if(!Array.isArray(d)){typeof d=="string"&&d[0]==="$"&&A(d);return}let[k,L]=d;if(k==="call"||k==="return_call"||k==="ref.func")A(L);else if(k==="global.get"||k==="global.set")S(L);else if(k==="type")F(L);else if(k==="call_indirect"||k==="return_call_indirect")for(let rt of d)typeof rt=="string"&&rt[0]==="$"&&I(rt);typeof k=="string"&&(k.startsWith("memory.")||k.includes(".load")||k.includes(".store"))&&M(0)}))}let E=["module"];for(let x of t.slice(1)){if(!Array.isArray(x)){E.push(x);continue}let d=x[0];if(d==="func"||d==="global"||d==="type")l.get(x)?.used&&E.push(x);else if(d==="import"){let k=!1;for(let L of x){if(!Array.isArray(L))continue;if(l.get(L)?.used){k=!0;break}}k&&E.push(x)}else E.push(x)}return E},$e=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),ze=new ArrayBuffer(8),Kt=new Float64Array(ze),Qt=new BigInt64Array(ze),Te=new ArrayBuffer(4),Jt=new Float32Array(Te),te=new Int32Array(Te),Ar=t=>(Kt[0]=t,Qt[0]),br=t=>(Qt[0]=BigInt.asIntN(64,t),Kt[0]),wr=t=>(Jt[0]=t,te[0]),vr=t=>(te[0]=t|0,Jt[0]),_t=t=>(e,r)=>t(e,r)?1:0,Ut=t=>(e,r)=>t(e>>>0,r>>>0)?1:0,ht=t=>(e,r)=>t(e,r)?1:0,qt=t=>(e,r)=>t(BigInt.asUintN(64,e),BigInt.asUintN(64,r))?1:0,$r={"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":[_t((t,e)=>t===e),"i32"],"i32.ne":[_t((t,e)=>t!==e),"i32"],"i32.lt_s":[_t((t,e)=>t<e),"i32"],"i32.lt_u":[Ut((t,e)=>t<e),"i32"],"i32.gt_s":[_t((t,e)=>t>e),"i32"],"i32.gt_u":[Ut((t,e)=>t>e),"i32"],"i32.le_s":[_t((t,e)=>t<=e),"i32"],"i32.le_u":[Ut((t,e)=>t<=e),"i32"],"i32.ge_s":[_t((t,e)=>t>=e),"i32"],"i32.ge_u":[Ut((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":[ht((t,e)=>t===e),"i32"],"i64.ne":[ht((t,e)=>t!==e),"i32"],"i64.lt_s":[ht((t,e)=>t<e),"i32"],"i64.lt_u":[qt((t,e)=>t<e),"i32"],"i64.gt_s":[ht((t,e)=>t>e),"i32"],"i64.gt_u":[qt((t,e)=>t>e),"i32"],"i64.le_s":[ht((t,e)=>t<=e),"i32"],"i64.le_u":[qt((t,e)=>t<=e),"i32"],"i64.ge_s":[ht((t,e)=>t>=e),"i32"],"i64.ge_u":[qt((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($e(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":[$e,"f64"],"i32.reinterpret_f32":[wr,"i32"],"f32.reinterpret_i32":[vr,"f32"],"i64.reinterpret_f64":[Ar,"i64"],"f64.reinterpret_i64":[br,"f64"],"f32.convert_i32_s":[t=>Math.fround(t|0),"f32"],"f32.convert_i32_u":[t=>Math.fround(t>>>0),"f32"],"f32.convert_i64_s":[t=>Math.fround(Number(BigInt.asIntN(64,t))),"f32"],"f32.convert_i64_u":[t=>Math.fround(Number(BigInt.asUintN(64,t))),"f32"],"f64.convert_i32_s":[t=>t|0,"f64"],"f64.convert_i32_u":[t=>t>>>0,"f64"],"f64.convert_i64_s":[t=>Number(BigInt.asIntN(64,t)),"f64"],"f64.convert_i64_u":[t=>Number(BigInt.asUintN(64,t)),"f64"],"f32.demote_f64":[t=>Math.fround(t),"f32"],"f64.promote_f32":[t=>Math.fround(t),"f64"]},Ir=(t,e=t?.indexOf?.("nan"))=>{if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),i=t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?BigInt(r):0x8000000000000n;return Qt[0]=BigInt.asIntN(64,i|0x7ff0000000000000n|(t[0]==="-"?1n<<63n:0n)),Kt[0]},kr=(t,e=t?.indexOf?.("nan"))=>{if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),i=t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?parseInt(r):4194304;return te[0]=i|2139095040|(t[0]==="-"?2147483648:0)|0,Jt[0]},z=t=>{if(!Array.isArray(t)||t.length!==2)return null;let[e,r]=t;if(e==="i32.const")return{type:"i32",value:Number(r)|0};if(e==="i64.const")return{type:"i64",value:BigInt(r)};if(e==="f32.const"){let i=kr(r);return{type:"f32",value:i!==null?i:Math.fround(Number(r))}}if(e==="f64.const"){let i=Ir(r);return{type:"f64",value:i!==null?i:Number(r)}}return null},Ie=(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,Mr=t=>W(t,e=>{if(!Array.isArray(e))return;let r=$r[e[0]];if(!r)return;let[i,s]=r;if(i.length===1&&e.length===2){let n=z(e[1]);if(!n)return;let l=i(n.value);return l===null?void 0:Ie(s,l)}if(i.length===2&&e.length===3){let n=z(e[1]),l=z(e[2]);if(!n||!l)return;let f=i(n.value,l.value);return f===null?void 0:Ie(s,f)}}),lt=t=>(e,r)=>{let i=z(e),s=z(r);return i?.value===t?r:s?.value===t?e:null},Q=t=>(e,r)=>z(r)?.value===t?e:null,Br={"i32.add":lt(0),"i64.add":lt(0n),"i32.sub":Q(0),"i64.sub":Q(0n),"i32.mul":lt(1),"i64.mul":lt(1n),"i32.div_s":Q(1),"i32.div_u":Q(1),"i64.div_s":Q(1n),"i64.div_u":Q(1n),"i32.and":lt(-1),"i64.and":lt(-1n),"i32.or":lt(0),"i64.or":lt(0n),"i32.xor":lt(0),"i64.xor":lt(0n),"i32.shl":Q(0),"i32.shr_s":Q(0),"i32.shr_u":Q(0),"i64.shl":Q(0n),"i64.shr_s":Q(0n),"i64.shr_u":Q(0n)},Nr=t=>W(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=Br[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Sr=t=>W(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1)){let f=Math.log2(n.value);if(Number.isInteger(f))return["i32.shl",i,["i32.const",f]]}let l=z(i);if(l&&l.value>0&&!(l.value&l.value-1)){let f=Math.log2(l.value);if(Number.isInteger(f))return["i32.shl",s,["i32.const",f]]}}if(r==="i64.mul"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let f=BigInt(n.value.toString(2).length-1);return["i64.shl",i,["i64.const",f]]}let l=z(i);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let f=BigInt(l.value.toString(2).length-1);return["i64.shl",s,["i64.const",f]]}}if(r==="i32.div_u"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1)){let l=Math.log2(n.value);if(Number.isInteger(l))return["i32.shr_u",i,["i32.const",l]]}}if(r==="i64.div_u"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let l=BigInt(n.value.toString(2).length-1);return["i64.shr_u",i,["i64.const",l]]}}if(r==="i32.rem_u"){let n=z(s);if(n&&n.value>0&&!(n.value&n.value-1))return["i32.and",i,["i32.const",n.value-1]]}if(r==="i64.rem_u"){let n=z(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n)return["i64.and",i,["i64.const",n.value-1n]]}}),zr=t=>W(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Lt(e),l=z(i);if(!l)return;let f=l.value!==0&&l.value!==0n?s:n;if(f&&f.length>1){let o=f.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=z(i);return s?s.value===0||s.value===0n?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let i=e[e.length-1],s=z(i);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),ke=new Set(["unreachable","return","br","br_table"]),Tr=t=>(C(t,e=>{if(!Array.isArray(e))return;let r=e[0];if((r==="func"||r==="block"||r==="loop")&&Me(e),r==="if")for(let i=1;i<e.length;i++)Array.isArray(e[i])&&(e[i][0]==="then"||e[i][0]==="else")&&Me(e[i])}),t),Me=t=>{let e=!1,r=-1;for(let i=1;i<t.length;i++){let s=t[i];if(Array.isArray(s)){let n=s[0];if(n==="param"||n==="result"||n==="local"||n==="type"||n==="export")continue;e&&r===-1&&(r=i),ke.has(n)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),ke.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},Er=t=>(C(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=[],i=new Map,s=new Set;for(let n=1;n<e.length;n++){let l=e[n];Array.isArray(l)&&(l[0]==="local"&&(r.push({node:l,idx:n}),typeof l[1]=="string"&&l[1][0]==="$"&&i.set(l[1],l[2])),l[0]==="param"&&typeof l[1]=="string"&&l[1][0]==="$"&&(i.set(l[1],l[2]),s.add(l[1])))}C(e,n=>{if(!Array.isArray(n))return;let l=n[0];if(l==="local.get"||l==="local.set"||l==="local.tee"){let f=n[1];typeof f=="string"&&s.add(f)}});for(let n=r.length-1;n>=0;n--){let{idx:l,node:f}=r[n],o=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;o&&!s.has(o)&&e.splice(l,1)}}),t),Ur=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"]),qr=[".store","memory.",".atomic."],xt=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||Ur.has(e))return!1;for(let r of qr)if(e.includes(r))return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!xt(t[r]))return!1;return!0},Fr=t=>{let e=new Map,r=i=>(e.has(i)||e.set(i,{gets:0,sets:0,tees:0}),e.get(i));return C(t,i=>{!Array.isArray(i)||i.length<2||typeof i[1]!="string"||(i[0]==="local.get"?r(i[1]).gets++:i[0]==="local.set"?r(i[1]).sets++:i[0]==="local.tee"&&r(i[1]).tees++)}),e},Or=t=>{let e=z(t);if(!e)return!1;if(e.type==="i32"){let r=e.value|0;return r>=-64&&r<=63}if(e.type==="i64"){let r=typeof e.value=="bigint"?e.value:BigInt(e.value);return r>=-64n&&r<=63n}return!1},Ee=t=>t.pure&&t.singleUse||Or(t.val),Yt=(t,e)=>{for(let[r,i]of t){let s=!1;C(i.val,n=>{Array.isArray(n)&&(n[0]==="local.get"||n[0]==="local.tee")&&n[1]===e&&(s=!0)}),s&&t.delete(r)}},Ue=t=>{if(!Array.isArray(t))return!1;let e=t[0];if(typeof e=="string"&&(e.includes(".load")||e==="memory.copy"||e==="memory.size"))return!0;for(let r=1;r<t.length;r++)if(Ue(t[r]))return!0;return!1},Xt=t=>{if(!Array.isArray(t))return!1;let e=t[0];if(typeof e=="string"&&(e.endsWith(".store")||e==="memory.copy"||e==="memory.fill"||e==="memory.init"||e.includes(".atomic.")&&!e.endsWith(".load")))return!0;for(let r=1;r<t.length;r++)if(Xt(t[r]))return!0;return!1},Zt=(t,e)=>{if(!Array.isArray(t))return t;let r=t[0];if(r==="local.get"&&t.length===2){let s=typeof t[1]=="string"&&e.get(t[1]);return s&&Ee(s)?J(s.val):t}let i=e;if(r==="block"||r==="loop"||r==="if"){let s=null;C(t,n=>{Array.isArray(n)&&(n[0]==="local.set"||n[0]==="local.tee")&&typeof n[1]=="string"&&e.has(n[1])&&(s||(s=new Map(e)),s.delete(n[1]))}),s&&(i=s)}for(let s=1;s<t.length;s++){let n=Zt(t[s],i);n!==t[s]&&(t[s]=n),s+1<t.length&&Array.isArray(t[s])&&C(t[s],l=>{Array.isArray(l)&&(l[0]==="local.set"||l[0]==="local.tee")&&typeof l[1]=="string"&&(i===e&&(i=new Map(e)),i.delete(l[1]),Yt(i,l[1]))})}return t},Lr=(t,e,r)=>{let i=!1,s=l=>r.get(l)||{gets:0,sets:0,tees:0},n=new Map;for(let l=1;l<t.length;l++){let f=t[l];if(!Array.isArray(f))continue;let o=f[0];if(!(o==="param"||o==="result"||o==="local"||o==="type"||o==="export")){if((o==="local.set"||o==="local.tee")&&f.length===3&&typeof f[1]=="string"){let a=Zt(f[2],n);a!==f[2]&&(f[2]=a,i=!0);let c=s(f[1]);if(Yt(n,f[1]),Xt(f[2]))for(let[u,m]of n)m.readsMem&&n.delete(u);n.set(f[1],{val:f[2],pure:xt(f[2]),readsMem:Ue(f[2]),singleUse:c.gets<=1&&c.sets<=1&&c.tees===0});continue}if((o==="block"||o==="loop"||o==="if")&&n.clear(),o==="call"||o==="call_indirect"||o==="return_call"||o==="return_call_indirect")for(let[a,c]of n)z(c.val)||n.delete(a);if(o==="local.get"&&f.length===2&&typeof f[1]=="string"){let a=n.get(f[1]);if(a&&Ee(a)){let c=J(a.val);f.length=0,f.push(...Array.isArray(c)?c:[c]),i=!0;continue}}if(o!=="block"&&o!=="loop"&&o!=="if"){let a=J(f);if(Zt(f,n),T(a,f)||(i=!0),C(f,c=>{Array.isArray(c)&&(c[0]==="local.set"||c[0]==="local.tee")&&typeof c[1]=="string"&&(n.delete(c[1]),Yt(n,c[1]))}),Xt(f))for(let[c,u]of n)u.readsMem&&n.delete(c)}}}return i},Cr=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let f=n[1];if(l[1]!==f||e.has(f))continue;let o=r.get(f)||{gets:0,sets:0,tees:0};if(o.sets!==1||o.gets!==1||o.tees!==0)continue;let a=J(n[2]);t.splice(s,2,...Array.isArray(a)?[a]:[a]),i=!0,s--}return i},Dr=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let f=n[1];if(l[1]!==f||e.has(f))continue;let o=r.get(f)||{gets:0,sets:0,tees:0};o.sets+o.gets+o.tees<=2||(t.splice(s,2,["local.tee",f,J(n[2])]),i=!0)}return i},Rr=(t,e,r)=>{let i=!1,s=n=>r.get(n)||{gets:0,sets:0,tees:0};for(let n=t.length-1;n>=1;n--){let l=t[n];if(!Array.isArray(l))continue;let f=typeof l[1]=="string"?l[1]:null;if(!f||e.has(f))continue;let o=s(f);l[0]==="local.set"&&o.gets===0&&o.tees===0?l.length===3?xt(l[2])&&(t.splice(n,1),i=!0):l.length===2&&(t[n]=["drop"],i=!0):l[0]==="local"&&f[0]==="$"&&o.gets===0&&o.sets===0&&o.tees===0&&(t.splice(n,1),i=!0)}return i},qe=t=>Array.isArray(t)&&(t[0]==="func"||t[0]==="block"||t[0]==="loop"||t[0]==="then"||t[0]==="else"),Be=t=>(C(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Set;for(let s of e)Array.isArray(s)&&s[0]==="param"&&typeof s[1]=="string"&&r.add(s[1]);let i=[];W(e,s=>{qe(s)&&i.push(s)});for(let s=0;s<6;s++){let n=Fr(e),l=!1;for(let f of i)Lr(f,r,n)&&(l=!0),Cr(f,r,n)&&(l=!0),Dr(f,r,n)&&(l=!0),Rr(f,r,n)&&(l=!0);if(!l)break}}),t),Wr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map;for(let r of t.slice(1)){if(!Array.isArray(r)||r[0]!=="func")continue;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i)continue;let s=[],n=[],l=!1,f=!1;for(let o=1;o<r.length;o++){let a=r[o];if(Array.isArray(a))if(a[0]==="param")if(typeof a[1]=="string"&&a[1][0]==="$")s.push({name:a[1],type:a[2]});else{s=null;break}else a[0]==="local"?l=!0:a[0]==="export"?f=!0:a[0]!=="result"&&a[0]!=="type"&&n.push(a)}if(s&&!l&&!f&&s.length<=4&&n.length===1){let o=new Set(s.map(u=>u.name)),a=!1,c=!1;C(n[0],u=>{Array.isArray(u)&&((u[0]==="local.set"||u[0]==="local.tee")&&o.has(u[1])&&(a=!0),(u[0]==="return"||u[0]==="return_call"||u[0]==="return_call_indirect")&&(c=!0))}),!a&&!c&&e.set(i,{body:n[0],params:s})}}return e.size===0||W(t,r=>{if(!Array.isArray(r)||r[0]!=="call")return;let i=r[1];if(!e.has(i))return;let{body:s,params:n}=e.get(i),l=r.slice(2);if(n.length===0)return J(s);let f=J(s);return W(f,o=>{if(!Array.isArray(o)||o[0]!=="local.get")return;let a=o[1],c=n.findIndex(u=>u.name===a);if(c!==-1&&l[c])return J(l[c])}),f}),t},Pr=0,jr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set(["export","type","param","result","local"]),r=a=>{let c=2;for(;c<a.length&&(typeof a[c]=="string"||Array.isArray(a[c])&&e.has(a[c][0]));)c++;return c},i=a=>a==="br"||a==="br_if"||a==="br_table",s=a=>{if(!Array.isArray(a))return!1;let c=a[0];if(c==="return_call"||c==="return_call_indirect"||c==="return_call_ref"||c==="try"||c==="try_table"||c==="delegate"||c==="rethrow")return!0;if(i(c)){for(let u=1;u<a.length;u++)if(typeof a[u]=="number"||typeof a[u]=="string"&&/^\d+$/.test(a[u]))return!0}for(let u=1;u<a.length;u++)if(s(a[u]))return!0;return!1},n=(a,c)=>{if(!Array.isArray(a))return!1;if((a[0]==="call"||a[0]==="return_call")&&a[1]===c)return!0;for(let u=1;u<a.length;u++)if(n(a[u],c))return!0;return!1},l=a=>a==="i32"?["i32.const",0]:a==="i64"?["i64.const",0n]:a==="f32"?["f32.const",0]:a==="f64"?["f64.const",0]:a==="v128"?["v128.const","i64x2",0n,0n]:null,f=(a,c)=>{let u=!1,m=!1,y=0,g=p=>{if(u||!Array.isArray(p))return;let _=p[0],b=_==="local.set"||_==="local.tee";if((b||_==="local.get")&&p[1]===c){if(b)for(let A=2;A<p.length&&!u;A++)g(p[A]);if(u)return;u=!0,(_==="local.get"||y>0)&&(m=!0);return}let v=_==="if";for(let A=1;A<p.length&&!u;A++){let S=p[A],I=v&&Array.isArray(S)&&(S[0]==="then"||S[0]==="else");I&&y++,g(S),I&&y--}};for(let p of a){if(u)break;g(p)}return u?m:!1},o=(a,c)=>{if(!Array.isArray(a))return;let u=a[0];if(u==="export"&&Array.isArray(a[2])&&a[2][0]==="func"&&typeof a[2][1]=="string")c.add(a[2][1]);else if(u==="start"&&typeof a[1]=="string")c.add(a[1]);else if(u==="ref.func"&&typeof a[1]=="string")c.add(a[1]);else if(u==="elem")for(let m of a)typeof m=="string"&&m[0]==="$"&&c.add(m);for(let m of a)o(m,c)};for(let a=0;a<16;a++){let c=t.filter(w=>Array.isArray(w)&&w[0]==="func"),u=new Map;for(let w of c)typeof w[1]=="string"&&u.set(w[1],w);let m=new Map,y=new Set,g=w=>{if(!Array.isArray(w))return;let N=w[0];N==="call"&&typeof w[1]=="string"?m.set(w[1],(m.get(w[1])||0)+1):N==="return_call"&&typeof w[1]=="string"&&y.add(w[1]);for(let U=1;U<w.length;U++)g(w[U])};g(t);let p=new Set;for(let w of t)(!Array.isArray(w)||w[0]!=="func")&&o(w,p);let _=null;for(let[w,N]of u){if(p.has(w)||y.has(w)||m.get(w)!==1||n(N,w))continue;let U=!0,it=0;for(let V=2;V<N.length;V++){let j=N[V];if(typeof j!="string"){if(!Array.isArray(j)){U=!1;break}if(j[0]==="param"||j[0]==="local"){if(typeof j[1]!="string"||j[1][0]!=="$"){U=!1;break}if(j[0]==="local"&&!l(j[2])){U=!1;break}}else if(j[0]==="result")it+=j.length-1;else if(j[0]==="export"){U=!1;break}else{if(j[0]==="type")continue;break}}}if(!U||it>1)continue;let st=!1;for(let V=r(N);V<N.length;V++)if(s(N[V])){st=!0;break}if(!st){_=w;break}}if(!_)break;let b=u.get(_),v=[],A=[],S=null;for(let w=2;w<b.length;w++){let N=b[w];if(!(typeof N=="string"||!Array.isArray(N)))if(N[0]==="param")v.push({name:N[1],type:N[2]});else if(N[0]==="result")N.length>1&&(S=N[1]);else if(N[0]==="local")A.push({name:N[1],type:N[2]});else{if(N[0]==="export"||N[0]==="type")continue;break}}let I=b.slice(r(b)),M=++Pr,F=`$__inl${M}`,q=new Map;for(let w of v)q.set(w.name,`$__inl${M}_${w.name.slice(1)}`);for(let w of A)q.set(w.name,`$__inl${M}_${w.name.slice(1)}`);let E=w=>w==="block"||w==="loop"||w==="if",x=new Map,d=w=>{if(Array.isArray(w)){E(w[0])&&typeof w[1]=="string"&&w[1][0]==="$"&&!x.has(w[1])&&x.set(w[1],`$__inl${M}L_${w[1].slice(1)}`);for(let N=1;N<w.length;N++)d(w[N])}};for(let w of I)d(w);let k=w=>{if(!Array.isArray(w))return w;let N=w[0];return(N==="local.get"||N==="local.set"||N==="local.tee")&&typeof w[1]=="string"&&q.has(w[1])?[N,q.get(w[1]),...w.slice(2).map(k)]:N==="return"?["br",F,...w.slice(1).map(k)]:E(N)&&typeof w[1]=="string"&&x.has(w[1])?[N,x.get(w[1]),...w.slice(2).map(k)]:i(N)?[N,...w.slice(1).map(U=>typeof U=="string"&&x.has(U)?x.get(U):k(U))]:w.map((U,it)=>it===0?U:k(U))},L=!1;for(let w of c){if(w===b||L)continue;let N=r(w);for(let U=N;U<w.length;U++){let it=W(w[U],st=>{if(L||!Array.isArray(st)||st[0]!=="call"||st[1]!==_)return;let V=st.slice(2);if(V.length!==v.length)return;let j=v.map((yt,De)=>["local.set",q.get(yt.name),V[De]]),re=A.filter(yt=>f(I,yt.name)).map(yt=>["local.set",q.get(yt.name),l(yt.type)]),ie=I.map(k);return L=!0,S?["block",F,["result",S],...j,...re,...ie]:["block",F,...j,...re,...ie]});if(it!==w[U]&&(w[U]=it),L){let st=[...v,...A].map(V=>["local",q.get(V.name),V.type]);st.length&&w.splice(r(w),0,...st);break}}if(L)break}if(!L)break;let rt=t.indexOf(b);rt>=0&&t.splice(rt,1)}return t},Ft=(t,e)=>{let r=!1,i=(s,n)=>{if(r||!Array.isArray(s))return;let l=s[0],f=n;if((l==="block"||l==="loop")&&typeof s[1]=="string"&&s[1]===e&&(f=!0),!n){if(l==="br"||l==="br_if"||l==="br_on_null"||l==="br_on_non_null"||l==="br_on_cast"||l==="br_on_cast_fail"){if(s[1]===e){r=!0;return}}else if(l==="br_table"){for(let o=1;o<s.length&&typeof s[o]=="string";o++)if(s[o]===e){r=!0;return}}else if(l==="catch"||l==="catch_ref"){if(s[2]===e){r=!0;return}}else if((l==="catch_all"||l==="catch_all_ref")&&s[1]===e){r=!0;return}}for(let o=1;o<s.length;o++)i(s[o],f)};for(let s of t)i(s,!1);return r},Gr=t=>(W(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let r=1,i=null;typeof e[1]=="string"&&e[1][0]==="$"&&(i=e[1],r=2);let s=!1;for(;r<e.length;){let f=e[r];if(Array.isArray(f)&&(f[0]==="param"||f[0]==="type")){r++;continue}if(Array.isArray(f)&&f[0]==="result"){s=!0,r++;continue}break}let n=e.slice(r);if(!s||n.length!==1)return;let l=n[0];if(Array.isArray(l)&&!(i&&Ft(n,i))){e.length=0;for(let f of l)e.push(f)}}),C(t,e=>{if(!qe(e))return;let r=1;for(;r<e.length;){let i=e[r];if(!Array.isArray(i)){r++;continue}{let f=i[0],o=f==="local.set"||f==="global.set"?2:f==="drop"?1:-1;if(o>=0&&i.length===o+1){let a=i[o];if(Array.isArray(a)&&a[0]==="block"){let c=1,u=null;typeof a[1]=="string"&&a[1][0]==="$"&&(u=a[1],c=2);let m=!1;for(;c<a.length;){let g=a[c];if(Array.isArray(g)&&(g[0]==="param"||g[0]==="type")){c++;continue}if(Array.isArray(g)&&g[0]==="result"){m=!0,c++;continue}break}let y=m?a.slice(c):null;if(y&&y.length>=2&&!(u&&Ft(y,u))){let g=y[y.length-1],p=y.slice(0,-1);i[o]=g,e.splice(r,1,...p,i);continue}}}}if(i[0]!=="block"){r++;continue}let s=1,n=null;for(typeof i[1]=="string"&&i[1][0]==="$"&&(n=i[1],s=2);s<i.length;){let f=i[s];if(Array.isArray(f)&&(f[0]==="param"||f[0]==="result"||f[0]==="type")){s++;continue}break}let l=i.slice(s);if(n&&Ft(l,n)){r++;continue}e.splice(r,1,...l),r+=l.length}}),t),Hr=t=>(C(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Map;for(let m of e)Array.isArray(m)&&m[0]==="local"&&typeof m[1]=="string"&&m[1][0]==="$"&&typeof m[2]=="string"&&r.set(m[1],m[2]);if(r.size<2)return;let i=new Map,s=[],n=0,l=!1,f=0,o=m=>{if(l||!Array.isArray(m))return;let y=m[0],g=y==="loop";g&&s.push({start:n,end:n});let p=y==="local.set"||y==="local.tee";if(p||y==="local.get"){let _=m[1];if(typeof _!="string"||_[0]!=="$"){l=!0;return}if(p)for(let v=2;v<m.length;v++)o(m[v]);let b=n++;if(r.has(_)){let v=i.get(_);v||(v={start:b,end:b,firstOp:y,firstCond:f>0,loops:new Set},i.set(_,v)),b>v.end&&(v.end=b);for(let A of s)v.loops.add(A)}}else{n++;let _=y==="if";for(let b=1;b<m.length;b++){let v=m[b],A=_&&Array.isArray(v)&&(v[0]==="then"||v[0]==="else");A&&f++,o(v),A&&f--}}if(g){let _=s.pop();_.end=n}};if(o(e),l)return;for(let m of i.values())for(let y of m.loops)y.start<m.start&&(m.start=y.start),y.end>m.end&&(m.end=y.end);let a=[...i.entries()].sort((m,y)=>m[1].start-y[1].start),c=new Map,u=[];for(let[m,y]of a){let g=y.firstOp==="local.get"||y.firstCond,p=r.get(m),_=g?null:u.find(b=>b.type===p&&b.end<y.start);_?(c.set(m,_.primary),y.end>_.end&&(_.end=y.end)):u.push({primary:m,type:p,end:y.end})}c.size!==0&&C(e,m=>{Array.isArray(m)&&(m[0]==="local.get"||m[0]==="local.set"||m[0]==="local.tee")&&c.has(m[1])&&(m[1]=c.get(m[1]))})}),t),Vr=t=>W(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="nop")return["nop"];if(r==="drop"&&e.length===2&&xt(e[1]))return["nop"];if(r==="select"&&e.length>=4&&T(e[1],e[2]))return e[1];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Lt(e),l=!s||s.length<=1,f=!n||n.length<=1;if(l&&f)return xt(i)?["nop"]:["drop",i];if(n&&f&&!l)return e.filter(o=>o!==n)}if(r==="func"||r==="block"||r==="loop"||r==="then"||r==="else"){let i=[r];for(let s=1;s<e.length;s++){let n=e[s];if(n==="nop"||Array.isArray(n)&&n[0]==="nop")continue;let l=e[s+1],f=l==="drop"||Array.isArray(l)&&l[0]==="drop"&&l.length===1;if(Array.isArray(n)&&xt(n)&&f){s++;continue}i.push(n)}if(i.length!==e.length)return i}}),Yr={"i32.sub":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.sub":(t,e)=>T(t,e)?["i64.const",0n]:null,"i32.xor":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.xor":(t,e)=>T(t,e)?["i64.const",0n]:null,"i32.and":(t,e)=>T(t,e)?t:null,"i64.and":(t,e)=>T(t,e)?t:null,"i32.or":(t,e)=>T(t,e)?t:null,"i64.or":(t,e)=>T(t,e)?t:null,"i32.eq":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.eq":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ne":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.ne":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.lt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.lt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.gt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.gt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.le_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.le_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ge_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ge_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.lt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.lt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.gt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.gt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.le_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.le_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.ge_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.ge_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.mul":(t,e)=>{let r=z(t),i=z(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.mul":(t,e)=>{let r=z(t),i=z(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.and":(t,e)=>{let r=z(t),i=z(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.and":(t,e)=>{let r=z(t),i=z(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.or":(t,e)=>{let r=z(t),i=z(e);return r?.value===-1||i?.value===-1?["i32.const",-1]:null},"i64.or":(t,e)=>{let r=z(t),i=z(e);return r?.value===-1n||i?.value===-1n?["i64.const",-1n]:null},"local.set":(t,e)=>Array.isArray(e)&&e[0]==="local.get"&&e[1]===t?["nop"]:null},Xr=t=>W(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=Yr[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Zr=t=>{let e=typeof t=="bigint"?t:BigInt(Math.trunc(Number(t)||0)),r=1;for(;;){let i=e&0x7fn;if(e>>=7n,e===0n&&(i&0x40n)===0n||e===-1n&&(i&0x40n)!==0n)return r;r++}},Kr=t=>{if(!Array.isArray(t))return 4;switch(t[0]){case"i32.const":case"i64.const":return 1+Zr(t[1]);case"f32.const":return 5;case"f64.const":return 9;case"v128.const":return 18;default:return 4}},Qr=2,Jr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Set;for(let n of t.slice(1)){if(!Array.isArray(n))continue;if(n[0]==="export"&&Array.isArray(n[2])&&n[2][0]==="global"&&typeof n[2][1]=="string"){r.add(n[2][1]);continue}if(n[0]!=="global")continue;let l=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null;if(!l)continue;n.some(a=>Array.isArray(a)&&a[0]==="export")&&r.add(l);let f=n[2];if(Array.isArray(f)&&f[0]==="mut"||Array.isArray(f)&&f[0]==="import")continue;let o=n[3];z(o)&&e.set(l,o)}if(e.size===0)return t;let i=new Map;C(t,n=>{if(!Array.isArray(n))return;let l=n[1];typeof l!="string"||l[0]!=="$"||(n[0]==="global.set"?e.delete(l):n[0]==="global.get"&&i.set(l,(i.get(l)||0)+1))});let s=new Set;for(let[n,l]of e){let f=i.get(n)||0;if(f===0)continue;let o=Kr(l),a=o+2,c=f*Qr+a;f*o+(r.has(n)?a:0)<=c&&s.add(n)}if(s.size===0)return t;W(t,n=>{if(!(!Array.isArray(n)||n[0]!=="global.get"||n.length!==2)&&s.has(n[1]))return J(e.get(n[1]))});for(let n=t.length-1;n>=1;n--){let l=t[n];Array.isArray(l)&&l[0]==="global"&&typeof l[1]=="string"&&s.has(l[1])&&!r.has(l[1])&&t.splice(n,1)}return t},ti=t=>W(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(typeof r!="string"||!r.endsWith("load")&&!r.endsWith("store"))return;let i=r.endsWith("store"),s=0,n=null,l=1;for(typeof e[1]=="string"&&(e[1][0]==="$"||!isNaN(e[1]))&&(n=e[1],l=2);l<e.length&&typeof e[l]=="string"&&(e[l].startsWith("offset=")||e[l].startsWith("align="));)e[l].startsWith("offset=")&&(s=+e[l].slice(7)),l++;let f=i?e.length-2:e.length-1,o=i?e.length-1:-1;if(f<l)return;let a=e[f];if(!Array.isArray(a)||a[0]!=="i32.add"||a.length!==3)return;let c=a[1],u=a[2],m=z(c),y=z(u),g=null,p=null;if(m&&m.type==="i32"?(p=m.value,g=u):y&&y.type==="i32"&&(p=y.value,g=c),g===null||p===null)return;let _=s+p,b=[r];n!==null&&b.push(n),b.push(`offset=${_}`);let v=null;for(let A=l;A<f;A++)typeof e[A]=="string"&&e[A].startsWith("align=")&&(v=e[A]);return v&&b.push(v),b.push(g),i&&b.push(e[o]),b}),ei=t=>(C(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let i=1,s=null;if(typeof e[1]=="string"&&e[1][0]==="$"&&(s=e[1],i=2),!s)return;let n=-1;for(let f=e.length-1;f>=i;f--){let o=e[f];if(!Array.isArray(o)){o!=="nop"&&o!=="end"&&(n=f);continue}let a=o[0];if(!(a==="param"||a==="result"||a==="local"||a==="type"||a==="export")){n=f;break}}if(n<0)return;let l=e[n];Array.isArray(l)&&l[0]==="br"&&l[1]===s&&e.splice(n,1,...l.slice(2))}),t),ri=t=>(C(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let r=1,i=null;if(typeof e[1]=="string"&&e[1][0]==="$"&&(i=e[1],r=2),!i)return;for(;r<e.length;){let g=e[r];if(Array.isArray(g)&&g[0]==="type"){r++;continue}if(Array.isArray(g)&&(g[0]==="param"||g[0]==="result"))return;break}if(e.length-r!==1)return;let s=e[r];if(!Array.isArray(s)||s[0]!=="loop")return;let n=1,l=null;typeof s[1]=="string"&&s[1][0]==="$"&&(l=s[1],n=2);let f=[];for(;n<s.length;){let g=s[n];if(Array.isArray(g)&&g[0]==="type"){f.push(g),n++;continue}if(Array.isArray(g)&&(g[0]==="param"||g[0]==="result"))return;break}let o=s.slice(n);if(o.length<2)return;let a=o[0],c=o[o.length-1];if(!Array.isArray(a)||a[0]!=="br_if"||a[1]!==i||a.length!==3||!Array.isArray(c)||c[0]!=="br"||c[1]!==l||c.length!==2)return;let u=o.slice(1,-1);if(Ft(u,i))return;let m=a[2];Array.isArray(m)&&m[0]==="i32.eqz"&&m.length===2?m=m[1]:m=["i32.eqz",m];let y=["loop"];l&&y.push(l);for(let g of f)y.push(g);y.push(["if",m,["then",...u,c]]),e.length=0;for(let g of y)e.push(g)}),t),ii=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set;return C(t,r=>{Array.isArray(r)&&r[0]==="global.set"&&typeof r[1]=="string"&&e.add(r[1])}),W(t,r=>{if(!Array.isArray(r)||r[0]!=="global")return;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i||e.has(i))return;let s=typeof r[1]=="string"&&r[1][0]==="$",n=s?r[2]:r[1];if(Array.isArray(n)&&n[0]==="mut"){let l=[...r];return l[s?2:1]=n[1],l}})},si=t=>W(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{cond:r,thenBranch:i,elseBranch:s}=Lt(e),n=!i||i.length<=1,l=!s||s.length<=1;if(!n&&l&&i.length===2){let f=i[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],r]}if(n&&!l&&s.length===2){let f=s[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],["i32.eqz",r]]}}),ni=t=>W(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{thenBranch:r,elseBranch:i}=Lt(e);if(!r||!i||r.length<=1||i.length<=1||!e.some(m=>Array.isArray(m)&&m[0]==="result"))return;let n=0,l=Math.min(r.length,i.length);for(let m=1;m<l&&T(r[r.length-m],i[i.length-m]);m++)n++;if(n===0)return;let f=r.slice(r.length-n),o=r.slice(0,r.length-n),a=i.slice(0,i.length-n),c=["block"];for(let m=1;m<e.length;m++){let y=e[m];if(Array.isArray(y)&&(y[0]==="then"||y[0]==="else"))break;Array.isArray(y)&&(y[0]==="result"||y[0]==="type")&&c.push(y)}let u=["if"];for(let m=1;m<e.length;m++){let y=e[m];if(Array.isArray(y)&&(y[0]==="then"||y[0]==="else"))break;Array.isArray(y)&&(y[0]==="result"||y[0]==="type")||u.push(y)}return u.push(o.length>1?o:["then"]),u.push(a.length>1?a:["else"]),c.push(u,...f),c}),Fe=(t,e)=>{let r=[],i=[t];for(;i.length;){let s=i.pop();if(Array.isArray(s)){i.push("|");for(let n=s.length-1;n>=0;n--)i.push(s[n]);i.push("[")}else typeof s=="string"?r.push(e.has(s)?"$__L":s):typeof s=="bigint"?r.push(s.toString()+"n"):typeof s=="number"?r.push(s.toString()):s===null?r.push("null"):s===!0?r.push("t"):s===!1?r.push("f"):r.push(String(s))}return r.join(",")},li=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="func")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=new Set;typeof i[1]=="string"&&i[1][0]==="$"&&n.add(i[1]),C(i,f=>{if(!Array.isArray(f)||typeof f[1]!="string"||f[1][0]!=="$")return;let o=f[0];(o==="param"||o==="local"||o==="block"||o==="loop"||o==="if")&&n.add(f[1])});let l=Fe(i,n);e.has(l)?r.set(s,e.get(l)):e.set(l,s)}return r.size===0||W(t,i=>{if(!Array.isArray(i))return;let s=i[0];if((s==="call"||s==="return_call")&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(s==="ref.func"&&r.has(i[1]))return["ref.func",r.get(i[1])];if(s==="elem"){let n=i[i.length-1];if(Array.isArray(n))return[...i.slice(0,-1),n.map(l=>r.get(l)||l)]}if(s==="call_indirect"&&i.length>=3){let n=i[1];if(typeof n=="string"&&r.has(n))return["call_indirect",r.get(n),...i.slice(2)]}}),t},fi=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="type")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=Fe(i,new Set([s]));e.has(n)?r.set(s,e.get(n)):e.set(n,s)}if(r.size===0)return t;for(let i=t.length-1;i>=0;i--){let s=t[i];if(Array.isArray(s)&&s[0]==="type"){let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;n&&r.has(n)&&t.splice(i,1)}}return W(t,i=>{if(!Array.isArray(i))return;let s=i[0];if(s==="func")for(let n=1;n<i.length;n++){let l=i[n];Array.isArray(l)&&l[0]==="type"&&typeof l[1]=="string"&&r.has(l[1])&&(i[n]=["type",r.get(l[1])])}if(s==="import")for(let n=1;n<i.length;n++){let l=i[n];if(Array.isArray(l))for(let f=1;f<l.length;f++){let o=l[f];Array.isArray(o)&&o[0]==="type"&&typeof o[1]=="string"&&r.has(o[1])&&(l[f]=["type",r.get(o[1])])}}if(s==="call_indirect"||s==="return_call_indirect"){if(typeof i[1]=="string"&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(Array.isArray(i[1])&&i[1][0]==="type"&&typeof i[1][1]=="string"&&r.has(i[1][1]))return[s,["type",r.get(i[1][1])],...i.slice(2)]}}),t},Ot=t=>{if(typeof t!="string"||t.length<2||t[0]!=='"')return new Uint8Array;let e=t.slice(1,-1),r=[];for(let i=0;i<e.length;i++)if(e[i]==="\\"){let s=e[++i];s==="x"||s==="X"?(r.push(parseInt(e.slice(i+1,i+3),16)),i+=2):/[0-9a-fA-F]/.test(s)&&/[0-9a-fA-F]/.test(e[i+1])?(r.push(parseInt(e.slice(i,i+2),16)),i++):s==="n"?r.push(10):s==="t"?r.push(9):s==="r"?r.push(13):s==="\\"?r.push(92):s==='"'?r.push(34):r.push(s.charCodeAt(0))}else r.push(e.charCodeAt(i));return new Uint8Array(r)},Oe=t=>{let e='"';for(let r=0;r<t.length;r++){let i=t[r];i>=32&&i<127&&i!==34&&i!==92?e+=String.fromCharCode(i):e+="\\"+i.toString(16).padStart(2,"0")}return e+'"'},ai=t=>{let e=[];for(let i of t)if(typeof i=="string")e.push(...Ot(i));else if(Array.isArray(i)&&i[0]==="i8")for(let s=1;s<i.length;s++)e.push(Number(i[s])&255);else return t;let r=e.length;for(;r>0&&e[r-1]===0;)r--;return r===e.length?t:r===0?[]:[Oe(new Uint8Array(e.slice(0,r)))]},oi=t=>{let e=1;if(typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"){let i=t[e][1];e++;let s=t[e];return Array.isArray(s)&&(s[0]==="i32.const"||s[0]==="i64.const")?{memidx:i,offset:Number(s[1])}:null}let r=t[e];return Array.isArray(r)&&(r[0]==="i32.const"||r[0]==="i64.const")?{memidx:0,offset:Number(r[1])}:null},Ne=t=>{let e=1;typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"&&e++,Array.isArray(t[e])&&typeof t[e][0]=="string"&&!t[e][0].startsWith('"')&&e++;let r=0;for(let i=e;i<t.length;i++){let s=t[i];if(typeof s=="string")r+=Ot(s).length;else if(Array.isArray(s)&&s[0]==="i8")r+=s.length-1;else return null}return r},ci=(t,e)=>{let r=1;typeof t[r]=="string"&&t[r][0]==="$"&&r++,Array.isArray(t[r])&&t[r][0]==="memory"&&r++,Array.isArray(t[r])&&typeof t[r][0]=="string"&&!t[r][0].startsWith('"')&&r++;let i=1;typeof e[i]=="string"&&e[i][0]==="$"&&i++,Array.isArray(e[i])&&e[i][0]==="memory"&&i++,Array.isArray(e[i])&&typeof e[i][0]=="string"&&!e[i][0].startsWith('"')&&i++;let s=t.slice(r),n=e.slice(i);if(s.length===1&&n.length===1&&typeof s[0]=="string"&&typeof n[0]=="string"){let l=Ot(s[0]),f=Ot(n[0]),o=new Uint8Array(l.length+f.length);return o.set(l),o.set(f,l.length),t.length=r,t.push(Oe(o)),!0}return t.length=r,t.push(...s,...n),!0},ui=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;for(let i of t){if(!Array.isArray(i)||i[0]!=="data")continue;let s=1;typeof i[1]=="string"&&i[1][0]==="$"&&(s=2),s<i.length&&Array.isArray(i[s])&&typeof i[s][0]=="string"&&!i[s][0].startsWith('"')&&s++;let n=i.slice(s);if(n.length===0)continue;let l=ai(n);(l.length!==n.length||l.length>0&&l[0]!==n[0])&&(i.length=s,i.push(...l))}let e=[];for(let i=0;i<t.length;i++){let s=t[i];if(Array.isArray(s)&&s[0]==="data"){let n=oi(s);if(n){let l=Ne(s);l!==null&&e.push({...n,node:s,index:i,len:l})}}}e.sort((i,s)=>{let n=String(i.memidx),l=String(s.memidx);return n!==l?n.localeCompare(l):i.offset-s.offset});let r=new Set;for(let i=0;i<e.length-1;i++){let s=e[i],n=e[i+1];r.has(s.index)||String(s.memidx)!==String(n.memidx)||s.offset+s.len===n.offset&&ci(s.node,n.node)&&(r.add(n.index),s.len=Ne(s.node))}return r.size>0&&(t=t.filter((i,s)=>!r.has(s))),t},Se=()=>{let t=new Map,e=0;return r=>{if(!t.has(r)){let i="",s=e++;do i=String.fromCharCode(97+s%26)+i,s=Math.floor(s/26)-1;while(s>=0);t.set(r,i||"a")}return t.get(r)}},yi=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=Se(),r=Se();for(let i of t)!Array.isArray(i)||i[0]!=="import"||(typeof i[1]=="string"&&i[1][0]==='"'&&(i[1]='"'+e(i[1].slice(1,-1))+'"'),typeof i[2]=="string"&&i[2][0]==='"'&&(i[2]='"'+r(i[2].slice(1,-1))+'"'));return t},mi=t=>{let e=!0;return C(t,r=>{if(!e||!Array.isArray(r))return;let i=r[0];if(i==="func"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if((i==="call"||i==="return_call"||i==="ref.func")&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="start"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="elem")for(let s of r){if(typeof s=="string"&&s[0]!=="$"&&/^\d/.test(s)){e=!1;break}if(Array.isArray(s)&&s[0]==="ref.func"&&(typeof s[1]!="string"||s[1][0]!=="$")){e=!1;break}}}),e},pi=t=>{if(!Array.isArray(t)||t[0]!=="module"||!mi(t))return t;let e=new Map;C(t,n=>{Array.isArray(n)&&(n[0]==="call"||n[0]==="return_call")&&e.set(n[1],(e.get(n[1])||0)+1)});let r=[],i=[],s=[];for(let n of t.slice(1)){if(!Array.isArray(n)){s.push(n);continue}n[0]==="import"?r.push(n):n[0]==="func"?i.push(n):s.push(n)}return i.sort((n,l)=>(e.get(l[1])||0)-(e.get(n[1])||0)),["module",...r,...i,...s]};function Ct(t,e=!0){typeof t=="string"&&(t=Z(t));let r=e===!0;e=xr(e);let i=e.log?(l,f)=>e.log(l,f):()=>{},s=e.verbose||e.log;t=J(t);let n=null;for(let l=0;l<3;l++){n=J(t);let f=ve(t);e.stripmut&&(t=ii(t)),e.globals&&(t=Jr(t)),e.fold&&(t=Mr(t)),e.identity&&(t=Nr(t)),e.peephole&&(t=Xr(t)),e.strength&&(t=Sr(t)),e.branch&&(t=zr(t)),e.propagate&&(t=Be(t)),e.inlineOnce&&(t=jr(t)),e.inline&&(t=Wr(t)),e.offset&&(t=ti(t)),e.unbranch&&(t=ei(t)),e.loopify&&(t=ri(t)),e.brif&&(t=si(t)),e.foldarms&&(t=ni(t)),e.deadcode&&(t=Tr(t)),e.vacuum&&(t=Vr(t)),e.mergeBlocks&&(t=Gr(t)),e.coalesce&&(t=Hr(t)),e.locals&&(t=Er(t)),e.dedupe&&(t=li(t)),e.dedupTypes&&(t=fi(t)),e.packData&&(t=ui(t)),e.reorder&&(t=pi(t)),e.treeshake&&(t=dr(t)),e.minifyImports&&(t=yi(t)),e.propagate&&(e.inlineOnce||e.inline)&&(t=Be(t));let a=ve(t)-f;if((s||a!==0)&&i(` round ${l+1}: ${a>0?"+":""}${a} bytes`,a),a>(r?0:16)){s&&i(` \u26A0 round ${l+1} inflated by ${a} bytes, reverting`,a),t=n;break}if(T(n,t))break}return t}var Le="\uE000",Ce=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},gi=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t;return Ce(r)?Ce(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 ee(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=ee(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function _i(t,e){let r=[],i=new Map;return ee(t,s=>{if(!Array.isArray(s))return s;if(s[0]==="call"&&typeof s[1]=="function"){let n=s[1];if(!i.has(n)){let f=[];for(let c=2;c<s.length;c++){let u=gi(s[c]);u&&f.push(u)}let o=r.length,a=n.name||`$fn${o}`;i.set(n,{idx:o,name:a.startsWith("$")?a:"$"+a,params:f,fn:n}),r.push(i.get(n))}let l=i.get(n);s[1]=l.name}return s}),r}function hi(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function xi(t,...e){let r={};if(!Array.isArray(t)&&e.length&&typeof e[e.length-1]=="object"&&e[e.length-1]!==null&&!e[e.length-1].byteLength&&(r=e.pop()),Array.isArray(t)&&t.raw){let i=t[0];for(let a=0;a<e.length;a++)i+=Le+t[a+1];let s=Z(i),n=[],l=0;s=ee(s,a=>{if(a===Le){let c=e[l++];if(typeof c=="function")return n.push(c),c;if(typeof c=="string"&&(c[0]==="("||/^\s*\(/.test(c))){let u=Z(c);return Array.isArray(u)&&Array.isArray(u[0])&&(u._splice=!0),u}return c.byteLength!==void 0?[...c]:c}return a});let f=null;if(n.length){let a=_i(s,n);if(a.length){let c=hi(a);s[0]==="module"?s.splice(1,0,...c):typeof s[0]=="string"?s=[...c,s]:s.unshift(...c),f={env:{}};for(let u of a)f.env[u.name.slice(1)]=u.fn}}r.polyfill&&(s=Et(s,r.polyfill)),r.optimize&&(s=Ct(s,r.optimize));let o=ct(s);return f&&(o._imports=f),o}if(r.polyfill||r.optimize){let i=typeof t=="string"?Z(t):t;return r.polyfill&&(i=Et(i,r.polyfill)),r.optimize&&(i=Ct(i,r.optimize)),ct(i)}return ct(t)}function di(t,...e){let r=xi(t,...e),i=new WebAssembly.Module(r);return new WebAssembly.Instance(i,r._imports).exports}var ji=di;export{xi as compile,ji as default,Ct as optimize,Z as parse,Et as polyfill,he as print,di as watr};
|
package/dist/watr.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/src/optimize.js
CHANGED
|
@@ -1184,9 +1184,19 @@ const eliminateDeadStores = (funcNode, params, useCounts) => {
|
|
|
1184
1184
|
const name = typeof sub[1] === 'string' ? sub[1] : null
|
|
1185
1185
|
if (!name || params.has(name)) continue
|
|
1186
1186
|
const uses = getPostUseCount(name)
|
|
1187
|
-
// Dead store: set but never read
|
|
1188
|
-
if (sub[0] === 'local.set' && uses.gets === 0 && uses.tees === 0
|
|
1189
|
-
|
|
1187
|
+
// Dead store: set but never read.
|
|
1188
|
+
if (sub[0] === 'local.set' && uses.gets === 0 && uses.tees === 0) {
|
|
1189
|
+
// `(local.set $x VALUE)` — drop the store with its value, but only when
|
|
1190
|
+
// VALUE is pure (its side effects would otherwise still need to run).
|
|
1191
|
+
if (sub.length === 3) {
|
|
1192
|
+
if (isPure(sub[2])) { funcNode.splice(i, 1); changed = true }
|
|
1193
|
+
}
|
|
1194
|
+
// Bare `(local.set $x)` — the value is implicit on the stack (e.g. an
|
|
1195
|
+
// exception payload landing from a `try_table` catch). Demote to `drop`
|
|
1196
|
+
// so the dead store goes away without unbalancing the stack.
|
|
1197
|
+
else if (sub.length === 2) {
|
|
1198
|
+
funcNode[i] = ['drop']; changed = true
|
|
1199
|
+
}
|
|
1190
1200
|
}
|
|
1191
1201
|
// Unused local declaration
|
|
1192
1202
|
else if (sub[0] === 'local' && name[0] === '$' && uses.gets === 0 && uses.sets === 0 && uses.tees === 0) {
|
|
@@ -1634,6 +1644,13 @@ const targetsLabel = (body, label) => {
|
|
|
1634
1644
|
if (typeof n[j] === 'string') { if (n[j] === label) { found = true; return } }
|
|
1635
1645
|
else break
|
|
1636
1646
|
}
|
|
1647
|
+
} else if (op === 'catch' || op === 'catch_ref') {
|
|
1648
|
+
// `try_table` catch clause `(catch $tag $label)` / `(catch_ref $tag $label)`
|
|
1649
|
+
// branches to an enclosing block label just like `br` does.
|
|
1650
|
+
if (n[2] === label) { found = true; return }
|
|
1651
|
+
} else if (op === 'catch_all' || op === 'catch_all_ref') {
|
|
1652
|
+
// `(catch_all $label)` / `(catch_all_ref $label)`
|
|
1653
|
+
if (n[1] === label) { found = true; return }
|
|
1637
1654
|
}
|
|
1638
1655
|
}
|
|
1639
1656
|
for (let i = 1; i < n.length; i++) search(n[i], inner)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AA02FA;;;;;;;;;;;GAWG;AACH,sCATW,QAAM,MAAM,SACZ,OAAO,GAAC,MAAM,MAAO,SAkF/B;AAp5FD;;;;GAIG;AACH,4BAHW,GAAG,GACD,MAAM,CAOlB;AAED;;;;GAIG;AACH,wCAFa,MAAM,CAIlB;AAwGD;;;;;GAKG;AACH,6CAgJC;AAuMD;;;;GAIG;AACH,wCAwBC;AAoMD;;;;GAIG;AACH,4CAqBC;AA+CD;;;;;GAKG;AACH,8CAmDC;AA7QD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CA6DC;AAID;;;;GAIG;AACH,0CAuCC;AAoeD,yCAoCC;AAID;;;;GAIG;AACH,0CAiGC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,8CAmOC;AAvgDD;;;;GAIG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAa/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6vDD;;;;;GAKG;AACH,0CAgDC;AAyED;;;;GAIG;AACH,4CAQC;AA4BD;;;;;;;;;;;GAWG;AACH,2CAyDC;AAID,2EAA2E;AAC3E,sCAgEC;AAID;;;;GAIG;AACH,4CAyCC;AAID;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,2CAiDC;AAID;;;;;GAKG;AACH,4CAqBC;AAID;;;;;;GAMG;AACH,wCAmBC;AAID;;;;;GAKG;AACH,4CAiDC;AAoCD;;;;;GAKG;AACH,0CA8DC;AAiWD,uCAyBC;AAtXD;;;;;GAKG;AACH,8CAyEC;AAoID;;;;GAIG;AACH,4CAyDC;AAqBD;;;;;GAKG;AACH,iDAgBC;AA/qCD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,+CAiFC;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,kDAyFC"}
|