-
Notifications
You must be signed in to change notification settings - Fork 0
/
jelly-bf-worker.min.js
1 lines (1 loc) · 26.5 KB
/
jelly-bf-worker.min.js
1
var t=function(){this._buffer=new ArrayBuffer(8),this._data=new Uint8Array(this._buffer),this._size=0};t.prototype.size=function(){return this._size},t.prototype.get=function(t){return this._data[t]},t.prototype.set=function(t,n){this._data[t]=n},t.prototype.reserve_extra=function(t){if(this._size+t>this._data.length){for(var n=new ArrayBuffer(Math.max(2*this._data.length,this._size+t)),e=new Uint8Array(n),i=0;this._size>i;++i)e[i]=this._data[i];this._buffer=n,this._data=e}},t.prototype.push=function(t){this.reserve_extra(1),this._data[this._size++]=t},t.prototype.append=function(t){this.reserve_extra(t.length);for(var n=0;t.length>n;++n)this._data[this._size++]=t[n]},t.prototype.pop=function(){return this._data[--this._size]},t.prototype.insert_arr=function(t,n){this.reserve_extra(n.length);for(var e=this._size-1;e>=t;--e)this._data[e+n.length]=this._data[e];for(var e=0;n.length>e;++e)this._data[t+e]=n[e];this._size+=n.length},t.prototype.toUint8Array=function(){for(var t=new Uint8Array(this._size),n=0;this._size>n;++n)t[n]=this._data[n];return t};var n=function(t){return(new TextEncoder).encode(t)},e={};e.encodeUInt=function(n){0>n||n!==Math.floor(n);for(var e=new t;;){var i=n%128;if(n=Math.floor(n/128),0>=n){e.push(i);break}e.push(128+i)}return e.toUint8Array()},e.encodeInt=function(n){n!==Math.floor(n);var e=new t,i=0>n;for(i&&(n=-n-1);;){var r=n%128;if(n=Math.floor(n/128),0>=n&&64>r){e.push(i?127&~r:r);break}e.push(i?255&~r:128+r)}return e.toUint8Array()};var i={i32:127,i64:126,f32:125,f64:124,anyfunc:112,func:96,none:64},r={function:0,table:1,memory:2,global:3},o=function(t,n){this._param_types=t?t:[],this._result_types=n?n:[]};o.prototype.toUint8Array=function(){var n=new t;n.push(i.func),n.append(e.encodeUInt(this._param_types.length));for(var r=0;this._param_types.length>r;++r)n.push(this._param_types[r]);n.append(e.encodeUInt(this._result_types.length));for(var r=0;this._result_types.length>r;++r)n.push(this._result_types[r]);return n.toUint8Array()};var s=function(t){this._type=t};s.prototype.toUint8Array=function(){var n=new t;return n.append(e.encodeUInt(this._type)),n.toUint8Array()};var a=function(n){this._localTypes=n?n:[],this._data=new t,this._functionlinks=[]};a.prototype.setName=function(t){this._functionname=t},a.prototype.setType=function(t){this._functiontype=t},a.prototype.setLocalTypes=function(t){this._localTypes=t?t:[]},a.instruction={unreachable:0,nop:1,block:2,loop:3,if:4,else:5,end:11,br:12,br_if:13,br_table:14,return:15,call:16,call_indirect:17,drop:26,select:27,get_local:32,set_local:33,tee_local:34,get_global:35,set_global:36,i32_load:40,i64_load:41,f32_load:42,f64_load:43,i32_load8_s:44,i32_load8_u:45,i32_load16_s:46,i32_load16_u:47,i64_load8_s:48,i64_load8_u:49,i64_load16_s:50,i64_load16_u:51,i64_load32_s:52,i64_load32_u:53,i32_store:54,i64_store:55,f32_store:56,f64_store:57,i32_store8:58,i32_store16:59,i64_store8:60,i64_store16:61,i64_store32:62,current_memory:63,grow_memory:64,i32_const:65,i64_const:66,f32_const:67,f64_const:68,i32_eqz:69,i32_eq:70,i32_ne:71,i32_add:106,i32_sub:107,i32_mul:108},a.prototype.writeRawBytes=function(){for(var t=0;arguments.length>t;++t)this._data.push(arguments[t])},a.prototype.writeUint8Array=function(t){this._data.append(t)},a.prototype.unreachable=function(){this.writeRawBytes(a.instruction.unreachable)},a.prototype.nop=function(){this.writeRawBytes(a.instruction.nop)},a.prototype.block=function(t){this.writeRawBytes(a.instruction.block,t)},a.prototype.loop=function(t){this.writeRawBytes(a.instruction.loop,t)},a.prototype.if=function(t){this.writeRawBytes(a.instruction.if,t)},a.prototype.else=function(){this.writeRawBytes(a.instruction.else)},a.prototype.end=function(){this.writeRawBytes(a.instruction.end)},a.prototype.br=function(t){this.writeRawBytes(a.instruction.br),this.writeUint8Array(e.encodeUInt(t))},a.prototype.br_if=function(t){this.writeRawBytes(a.instruction.br_if),this.writeUint8Array(e.encodeUInt(t))},a.prototype.return=function(){this.writeRawBytes(a.instruction.return)},a.prototype.call=function(t){"number"==typeof t?(this.writeRawBytes(a.instruction.call),this.writeUint8Array(e.encodeUInt(t))):(this.writeRawBytes(a.instruction.call),this._functionlinks.push({location:this._data.size(),name:t}))},a.prototype.drop=function(){this.writeRawBytes(a.instruction.drop)},a.prototype.select=function(){this.writeRawBytes(a.instruction.select)},a.prototype.get_local=function(t){this.writeRawBytes(a.instruction.get_local),this.writeUint8Array(e.encodeUInt(t))},a.prototype.set_local=function(t){this.writeRawBytes(a.instruction.set_local),this.writeUint8Array(e.encodeUInt(t))},a.prototype.tee_local=function(t){this.writeRawBytes(a.instruction.tee_local),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i32_load=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i32_load),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i64_load=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i64_load),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.f32_load=function(t,n){n=n||0,this.writeRawBytes(a.instruction.f32_load),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.f64_load=function(t,n){n=n||0,this.writeRawBytes(a.instruction.f64_load),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i32_load8_s=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i32_load8_s),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i32_load8_u=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i32_load8_u),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i32_load16_s=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i32_load16_s),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i32_load16_u=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i32_load16_u),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i64_load8_s=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i64_load8_s),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i64_load8_u=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i64_load8_u),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i64_load16_s=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i64_load16_s),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i64_load16_u=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i64_load16_u),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i64_load32_s=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i64_load32_s),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i64_load32_u=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i64_load32_u),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i32_store=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i32_store),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i64_store=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i64_store),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.f32_store=function(t,n){n=n||0,this.writeRawBytes(a.instruction.f32_store),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.f64_store=function(t,n){n=n||0,this.writeRawBytes(a.instruction.f64_store),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i32_store8=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i32_store8),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i32_store16=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i32_store16),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i64_store8=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i64_store8),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i64_store16=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i64_store16),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.i64_store32=function(t,n){n=n||0,this.writeRawBytes(a.instruction.i64_store32),this.writeUint8Array(e.encodeUInt(n)),this.writeUint8Array(e.encodeUInt(t))},a.prototype.current_memory=function(){this.writeRawBytes(a.instruction.current_memory,0)},a.prototype.grow_memory=function(){this.writeRawBytes(a.instruction.grow_memory,0)},a.prototype.i32_const=function(t){this.writeRawBytes(a.instruction.i32_const),this.writeUint8Array(e.encodeInt(t))},a.prototype.i64_const=function(t){this.writeRawBytes(a.instruction.i64_const),this.writeUint8Array(e.encodeInt(t))},a.prototype.i32_eqz=function(){this.writeRawBytes(a.instruction.i32_eqz)},a.prototype.i32_eq=function(){this.writeRawBytes(a.instruction.i32_eq)},a.prototype.i32_ne=function(){this.writeRawBytes(a.instruction.i32_ne)},a.prototype.i32_add=function(){this.writeRawBytes(a.instruction.i32_add)},a.prototype.i32_sub=function(){this.writeRawBytes(a.instruction.i32_sub)},a.prototype.i32_mul=function(){this.writeRawBytes(a.instruction.i32_mul)},a.prototype.toUint8Array=function(){var n=new t;n.append(e.encodeUInt(this._localTypes.length));for(var i=0;this._localTypes.length>i;++i)n.push(1),n.push(this._localTypes[i]);return n.append(this._data.toUint8Array()),n.insert_arr(0,e.encodeUInt(n.size())),n.toUint8Array()};var c=function(t,n,e){this._field=t,this._kind=n,this._index=e};c.prototype.setName=function(t){this._functionname=t},c.prototype.toUint8Array=function(){var i=new t,r=n(this._field);return i.append(e.encodeUInt(r.length)),i.append(r),i.push(this._kind),i.append(e.encodeUInt(this._index)),i.toUint8Array()};var u=function(t,n,e){this._module=t,this._field=n,this._kind=e};u.prototype.setName=function(t){this._functionname=t},u.prototype.setType=function(t){this._functiontype=t},u.prototype.toUint8Array=function(){var i=new t,r=n(this._module),o=n(this._field);return i.push(e.encodeUInt(r.length)),i.append(r),i.push(e.encodeUInt(o.length)),i.append(o),i.push(this._kind),i.append(e.encodeUInt(this._type)),i.toUint8Array()};var _=function(t,n){this._initial_pages=t,n&&(this._maximum_pages=n)};_.prototype.toUint8Array=function(){var n=new t;return this._maximum_pages?(n.push(1),n.append(e.encodeUInt(this._initial_pages)),n.append(e.encodeUInt(this._maximum_pages))):(n.push(0),n.append(e.encodeUInt(this._initial_pages))),n.toUint8Array()};var h=function(){this._types=[],this._imports=[],this._functions=[],this._memory=[],this._exports=[],this._codes=[]};h.sectionCode={TYPE:1,IMPORT:2,FUNCTION:3,TABLE:4,MEMORY:5,GLOBAL:6,EXPORT:7,START:8,ELEMENT:9,CODE:10,DATA:11},h.prototype.setMemory=function(t){this._memory=[t]},h.prototype.exportFunction=function(t,n){n=n||t;var e=new c(n,r.function);e.setName(t),this._exports.push(e)},h.prototype.importFunction=function(t,n,e,i){var o=new u(e,i,r.function);o.setName(t),o.setType(n),this._imports.push(o)},h.prototype.addFunction=function(t,n,e){e.setName(t),e.setType(n),this._codes.push(e)},h.prototype.generateModule=function(){var n=[],i=this._types.length,r=function(t){return function(n){if(n.length!=t.length)return!1;for(var e=0;n.length>e;++e)if(n[e]!=t[e])return!1;return!0}},o=[],a=this._functions.length;this._imports.forEach(function(t){var n=t._functionname;if(n){if(o.findIndex(function(t){return t.name===n})!==-1)throw'Repeated function "'+n+'".';o.push({name:n,funcType:t._functiontype})}}),this._codes.forEach(function(t){var n=t._functionname;if(n){if(o.findIndex(function(t){return t.name===n})!==-1)throw'Repeated function "'+n+'".';o.push({name:n,funcType:t._functiontype})}}),o.forEach(function(t){n.findIndex(r(t.funcType))===-1&&n.push(t.funcType)});var c=this;n.forEach(function(t){c._types.push(t)});var c=this;this._codes.forEach(function(t){if(t._functiontype){var e=n.findIndex(r(t._functiontype))+i;if(e===-1)throw"Weird assembler bug.";c._functions.push(new s(e))}}),this._imports.forEach(function(t){var e=t._functiontype;if(e){var o=n.findIndex(r(e))+i;if(o===-1)throw"Weird assembler bug.";t._type=o}}),this._codes.forEach(function(t){var n=t._functionlinks;n.sort(function(t,n){return n.location-t.location}),n.forEach(function(n){var i=o.findIndex(function(t){return t.name===n.name})+a;if(i===-1)throw'Undeclared function "'+n.name+'".';t._data.insert_arr(n.location,e.encodeUInt(i))})}),this._exports.forEach(function(t){var n=t._functionname;if(n){var e=o.findIndex(function(t){return t.name===n})+a;if(e===-1)throw'Undeclared function "'+functionLink.name+'".';t._index=e}}),this._exports.forEach(function(t){t._functionname&&(t._functionname=void 0)}),this._imports.forEach(function(t){t._functionname&&(t._functionname=void 0,t._functiontype=void 0)}),this._codes.forEach(function(t){t._functionname&&(t._functionname=void 0,t._functiontype=void 0)});var u=new t,_=new Uint8Array(8);if(_[0]=0,_[1]=97,_[2]=115,_[3]=109,_[4]=1,_[5]=0,_[6]=0,_[7]=0,u.append(_),this._types.length>0){u.push(h.sectionCode.TYPE);var p=u.size();u.append(e.encodeUInt(this._types.length));for(var f=0;this._types.length>f;++f)u.append(this._types[f]);u.insert_arr(p,e.encodeUInt(u.size()-p))}if(this._imports.length>0){u.push(h.sectionCode.IMPORT);var p=u.size();u.append(e.encodeUInt(this._imports.length));for(var f=0;this._imports.length>f;++f)u.append(this._imports[f].toUint8Array());u.insert_arr(p,e.encodeUInt(u.size()-p))}if(this._functions.length>0){u.push(h.sectionCode.FUNCTION);var p=u.size();u.append(e.encodeUInt(this._functions.length));for(var f=0;this._functions.length>f;++f)u.append(this._functions[f].toUint8Array());u.insert_arr(p,e.encodeUInt(u.size()-p))}if(this._memory.length>0){u.push(h.sectionCode.MEMORY);var p=u.size();u.append(e.encodeUInt(this._memory.length));for(var f=0;this._memory.length>f;++f)u.append(this._memory[f].toUint8Array());u.insert_arr(p,e.encodeUInt(u.size()-p))}if(this._exports.length>0){u.push(h.sectionCode.EXPORT);var p=u.size();u.append(e.encodeUInt(this._exports.length));for(var f=0;this._exports.length>f;++f)u.append(this._exports[f].toUint8Array());u.insert_arr(p,e.encodeUInt(u.size()-p))}if(this._codes.length>0){u.push(h.sectionCode.CODE);var p=u.size();u.append(e.encodeUInt(this._codes.length));for(var f=0;this._codes.length>f;++f)u.append(this._codes[f].toUint8Array());u.insert_arr(p,e.encodeUInt(u.size()-p))}return u.toUint8Array()};var p={};p.compile=function(t,n){if(void 0===n.wraparound&&(n.wraparound=!0),void 0===n.infiniteloops&&(n.infiniteloops=!0),void 0===n.bitwidth&&(n.bitwidth=8),8===n.bitwidth||16===n.bitwidth||32===n.bitwidth){for(var e=[],i=0;t.length>i;++i)switch(t[i]){case"+":var r=new g;r.addDelta(0,1),R(e,r);break;case"-":var r=new g;r.addDelta(0,-1),R(e,r);break;case">":var r=new g;r.addExitDelta(1),R(e,r);break;case"<":var r=new g;r.addExitDelta(-1),R(e,r);break;case"[":e.push("[");break;case"]":T(e,n);break;case",":e.push(",");break;case".":e.push(".")}for(var i=(new b(!0),0);e.length>i;++i);return f(e)}};var f=function(t){var n=new h;n.setMemory(new _(16,16));var e=new a([i.i32]);e.i32_const(524288),e.set_local(0);for(var r=1,s=0;t.length>s;++s)if(t[s]instanceof g){var c=t[s];if(c._data.length>0){var u=1,p=[];c._data.forEach(function(t){t._combination.isZero(),t._combination._terms.forEach(function(t){t._parts.forEach(function(t){if(t instanceof m){var n=p.findIndex(function(n){return n>=t._index});n===-1?p.push(t._index):p[n]!==t._index&&p.splice(n,0,t._index)}})})});var f=Math.min(c._data[0]._index,c._exitindex);p.length>0&&(f=Math.min(f,p[0])),0!==f&&(e.get_local(0),e.i32_const(f),e.i32_add(),e.set_local(0)),p.forEach(function(t,n){var i=u+n,r=t-f;e.get_local(0),e.i32_load8_u(r),e.set_local(i)}),c._data.forEach(function(t){t._combination.isZero();var n=t._index-f;e.get_local(0),e.get_local(0),e.i32_load8_u(n),t._combination._terms.forEach(function(t){if(1===t._parts.length&&1===t._coefficient){var n=t._parts[0];n instanceof m&&e.get_local(u+p.findIndex(function(t){return t>=n._index}))}else e.i32_const(t._coefficient),t._parts.forEach(function(t){t instanceof m&&(e.get_local(u+p.findIndex(function(n){return n>=t._index})),e.i32_mul())});e.i32_add()}),e.i32_store8(n)}),c._exitindex-f!==0&&(e.get_local(0),e.i32_const(c._exitindex-f),e.i32_add(),e.set_local(0)),r=Math.max(r,u+p.length)}else 0!==c._exitindex&&(e.get_local(0),e.i32_const(t[s]._exitindex),e.i32_add(),e.set_local(0))}else switch(t[s]){case"[":e.get_local(0),e.i32_load8_u(0),e.if(i.none),e.loop(i.none);break;case"]":e.get_local(0),e.i32_load8_u(0),e.br_if(0),e.end(),e.end();break;case",":e.get_local(0),e.call("input"),e.i32_store8(0);break;case".":e.get_local(0),e.i32_load8_u(0),e.call("output")}e.end();for(var d=[],s=0;r>s;++s)d.push(i.i32);return e.setLocalTypes(d),n.addFunction("main",new o([],[]).toUint8Array(),e),n.exportFunction("main","main"),n.importFunction("input",new o([],[i.i32]).toUint8Array(),"interaction","input"),n.importFunction("output",new o([i.i32],[]).toUint8Array(),"interaction","output"),n.generateModule()},d=function(t,n){this._index=t,this._delta=n},l=function(){this._data=[],this._exitindex=0};l.prototype.applyDelta=function(t,n){var e=this._data.findIndex(function(n){return n._index>=t});e===-1?0!==n&&this._data.push(new d(t,n)):this._data[e]._index===t?(this._data[e]._delta+=n,0===this._data[e]._delta&&this._data.splice(e,1)):0!==n&&this._data.splice(e,0,new d(t,n))},l.prototype.applyExitDelta=function(t){this._exitindex+=t},l.prototype.coalesceWith=function(t){var n=this;t._data.forEach(function(t){n.applyDelta(n._exitindex+t._index,t._delta)}),this._exitindex+=t._exitindex};var y=function(t,n){if(n>t){var e=t;t=n,n=e}return 0===n?t:y(n,t%n)},w=function(t,n){this._sgn=0>t,this._num=Math.abs(t),this._den=n};w.prototype.reduce=function(){var t=y(this._num,this._den);this._num/=t,this._den/=t},w.prototype.multiplyWith=function(t){t instanceof w?(this._sgn=this._sgn!==t._sgn,this._num*=t._num,this._den*=t._den,this.reduce()):(this._sgn=this.sgn!==0>t,this.num*=Math.abs(t),this.reduce())};var m=function(t){this._index=t};m.sortOrder=1,m.Comparer=function(t,n){return t._index-n._index},m.prototype.addShift=function(t){this._index+=t},m.prototype.clone=function(){return new m(this._index)};var U=function(t){this._index=t};U.sortOrder=2,U.Comparer=function(t,n){return t._index-n._index},U.prototype.addShift=function(t,n){this._index+=n},U.prototype.clone=function(){return new U(this._index)};var v={};v.Comparer=function(t,n){var e=t.constructor,i=n.constructor;return e!==i?e.sortOrder-i.sortOrder:e.Comparer(t,n)},v.FinderLow=function(t){return function(n){return v.Comparer(n,t)>=0}};var I=function(t){this._parts=[],this._coefficient=t};I.makeConstant=function(t){var n=new I;return n._coefficient=t,n},I.makeFromPart=function(t){var n=new I(1);return n._parts=[t],n},I.Comparer=function(t,n){for(var e=Math.max(t._parts.length,n._parts.length),i=0;e>i;++i){if(i>=t._parts.length)return-1;if(i>=n._parts.length)return 1;var r=v.Comparer(t._parts[i],n._parts[i]);if(0!==r)return r}return 0},I.FinderLow=function(t){return function(n){return I.Comparer(n,t)>=0}},I.IsEqual=function(t,n){if(t._parts.length!==n._parts.length)return!1;for(var e=t._parts.length,i=0;e>i;++i)if(0!==v.Comparer(t._parts[i],n._parts[i]))return!1;return!0},I.prototype.addWith=function(t){this._coefficient+=t._coefficient},I.prototype.multiplyWith=function(t){t.isZero();var n=this._parts;t._parts.forEach(function(t){var e=n.findIndex(v.FinderLow(t));e===-1?n.push(t):n.splice(e,0,t)}),this._coefficient*=t._coefficient},I.prototype.isZero=function(){return 0===this._coefficient},I.prototype.clone=function(){var t=new I(this._coefficient);return this._parts.forEach(function(n){t._parts.push(n.clone())}),t};var x=function(){this._terms=[]};x.prototype.addTerm=function(t){t.isZero();var n=this._terms.findIndex(I.FinderLow(t));n===-1?this._terms.push(t):I.IsEqual(this._terms[n],t)?(this._terms[n].addWith(t),this._terms[n].isZero()&&this._terms.splice(n,1)):this._terms.splice(n,0,t)},x.prototype.multiplyTerm=function(t){t.isZero(),this._terms.forEach(function(n){n.multiplyWith(t.clone())})},x.prototype.multiplyLinear=function(t){var n=this._terms,e=[];t._terms.forEach(function(t){n.forEach(function(n){var i=n.clone();i.multiplyWith(t.clone()),e.push(i)})}),e.sort(I.Comparer),this._terms=e},x.prototype.isZero=function(){return 0===this._terms.length},x.prototype.clone=function(){var t=new x;return this._terms.forEach(function(n){t._terms.push(n.clone())}),t},x.prototype.coalesceWith=function(t){var n=this;t._terms.forEach(function(t){n.addTerm(t)})},x.prototype.expandState=function(t){var n=[];this._terms.forEach(function(e){var i=[],r=new I(e._coefficient);e._parts.forEach(function(t){t instanceof m?i.push(t._index):t instanceof JellyBFLinearOutputRef&&r.push(t)});var o=new x;o.addTerm(I.makeConstant(1)),i.forEach(function(n){var e=t._data.findIndex(A.FinderEqualIndex(n)),i=new x;i.addTerm(I.makeFromPart(new m(n))),e!==-1&&i.coalesceWith(t._data[e]._combination.clone()),o.multiplyLinear(i)}),o.multiplyTerm(r),o._terms.forEach(function(t){n.push(t)})}),this._terms=[];var e=this;n.forEach(function(t){e.addTerm(t)})},x.IsExactSame=function(t,n){if(t._terms.length!==n._terms.length)return!1;for(var e=t._terms.length,i=0;e>i;++i){if(!I.IsEqual(t._terms[i],n._terms[i]))return!1;if(t._terms[i]._coefficient!==n._terms[i]._coefficient)return!1}return!0};var A=function(t){this._index=t,this._combination=new x};A.Comparer=function(t,n){return t._index-n._index},A.FinderLow=function(t){return function(n){return n._index>=t._index}},A.FinderLowIndex=function(t){return function(n){return n._index>=t}},A.FinderEqual=function(t){return function(n){return n._index===t._index}},A.FinderEqualIndex=function(t){return function(n){return n._index===t}},A.IsEqual=function(t,n){return t._index===n._index},A.IsEqualIndex=function(t,n){return t._index===n},A.prototype.addTerm=function(t){this._combination.addTerm(t)},A.prototype.multiplyTerm=function(t){this._combination.multiplyTerm(t)},A.prototype.isZero=function(){return this._combination.isZero()},A.prototype.coalesceWith=function(t){this._combination.coalesceWith(t._combination)},A.makeFromTerm=function(t,n){var e=new A(t);return e.addTerm(n),e};var g=function(){this._data=[],this._outputs=[],this._exitindex=0,this._inputcount=0};g.prototype.addEntry=function(t){var n=this._data.findIndex(A.FinderLow(t));n===-1?this._data.push(t):A.IsEqual(this._data[n],t)?(this._data[n].coalesceWith(t),this._data[n].isZero()&&this._data.splice(n,1)):this._data.splice(n,0,t)},g.prototype.addDelta=function(t,n){var e=this._data.findIndex(A.FinderLowIndex(t));e===-1?0!==n&&this._data.push(A.makeFromTerm(t,I.makeConstant(n))):A.IsEqualIndex(this._data[e],t)?(this._data[e].addTerm(I.makeConstant(n)),this._data[e].isZero()&&this._data.splice(e,1)):0!==n&&this._data.splice(e,0,A.makeFromTerm(t,I.makeConstant(n)))},g.prototype.addExitDelta=function(t){this._exitindex+=t},g.prototype.coalesceWith=function(t){var n=this,e=this._exitindex,i=this._inputcount;t._data.forEach(function(t){t._index+=e,t._combination._terms.forEach(function(t){t._parts.forEach(function(t){t.addShift(e,i)})})}),t._outputs.forEach(function(t){t._terms.forEach(function(t){t._parts.forEach(function(t){t.addShift(e,i)})})});var r=[];t._data.forEach(function(t){t._combination.expandState(n),r.push(t)}),t._outputs.forEach(function(t){t.expandState(n),n._outputs.push(t)}),r.forEach(function(t){n.addEntry(t)});for(var o=this._data.length-1;o>=0;--o)this._data[o].isZero()&&this._data.splice(o,1);this._exitindex+=t._exitindex,this._inputcount+=t._inputcount},g.prototype.wrapWithLoop=function(){if(0===this._exitindex){var t=this._data.findIndex(A.FinderEqualIndex(0));if(t===-1)return!1;if(x.IsExactSame(this._data[t]._combination,A.makeFromTerm(0,I.makeConstant(-1))._combination)){var n=!0;return this._data.forEach(function(t){t._combination._terms.forEach(function(t){0!==t._parts.length&&(n=!1)})}),!!n&&(this._data.forEach(function(t){var n=new I(1);n._parts.push(new m(0)),t.multiplyTerm(n)}),!0)}return!1}return!1},g.prototype.writeCode=function(){};var E=function(t,n){this._index=t,this._value=n};E.FinderLowIndex=function(t){return function(n){return n._index>=t}};var b=function(t){this.emptyIsZero=t,this._data=[]};b.prototype.getState=function(t){var n=this._data.findIndex(E.FinderLowIndex(t));return n===-1?this.emptyIsZero?0:void 0:this._data[n]._value},b.prototype.setState=function(t,n){var e=this._data.findIndex(E.FinderLowIndex(t));e===-1?(this.emptyIsZero&&0!==n||!this.emptyIsZero&&void 0!==n)&&this._data.splice(e,0,new E(t,n)):this.emptyIsZero&&0===n||!this.emptyIsZero&&void 0===n?this._data.splice(e,1):this._data[e]._value=n};var R=function(t,n){t.length>0&&t[t.length-1]instanceof g?t[t.length-1].coalesceWith(n):t.push(n)},T=function(t,n){if(t.length>0&&"["===t[t.length-1])n.infiniteloops?t.push("]"):t.pop();else if(t.length>1&&t[t.length-1]instanceof g&&"["===t[t.length-2]){var e=t.pop();e.wrapWithLoop(n)?(t.pop(),R(t,e)):(t.push(e),t.push("]"))}else t.push("]")},B={compile:function(t,n){return new WebAssembly.Module(p.compile(t,n))},execute:function(n,e,i){i.eof_value=i.eof_value||0;var r=0,o=new t,s=function(){return e.length>r?e[r++]:i.eof_value},a=function(t){o.push(t)};return new WebAssembly.Instance(n,{interaction:{input:s,output:a}}).exports.main(),o.toUint8Array()},executeInteractive:function(t,n,e,i,r,o){var s={READ_HEAD:0,WRITE_HEAD:1,TERMINATED_FLAG:2};o.bufferlength=o.bufferlength||1024,o.eof_value=o.eof_value||0;var a=0,c=0,u=!1,_=function(){if(a===c&&(Atomics.wait(i,s.WRITE_HEAD,c),c=Atomics.load(i,s.WRITE_HEAD),u||(u=0!==Atomics.load(i,s.TERMINATED_FLAG))),!u||c>a+1){var t=Atomics.load(n,a++%o.bufferlength);return Atomics.store(i,s.READ_HEAD,a),t}return o.eof_value},h=0,p=0,f=function(t){h+o.bufferlength===p&&(Atomics.wait(r,s.READ_HEAD,h),h=Atomics.load(r,s.READ_HEAD)),Atomics.store(e,p++%o.bufferlength,t),Atomics.store(r,s.WRITE_HEAD,p)},d=function(){h+o.bufferlength===p&&(Atomics.wait(r,s.READ_HEAD,h),h=Atomics.load(r,s.READ_HEAD)),Atomics.store(r,s.TERMINATED_FLAG,1),Atomics.store(r,s.WRITE_HEAD,p+1)};return new WebAssembly.Instance(t,{interaction:{input:_,output:f}}).exports.main(),d(),!0}};!function(){var t=void 0;self.addEventListener("message",function(n){var e=n.data;switch(e.type){case"compile":var i=e.sourcecode,r=e.options;t=B.compile(i,r),self.postMessage({type:"compiled"});break;case"execute-interactive":var o=e.inputbuffer,s=e.outputbuffer,a=e.inputwaitbuffer,c=e.outputwaitbuffer,r=e.options;B.executeInteractive(t,UInt8Array(o),UInt8Array(s),Int32Array(a),Int32Array(c),r),self.postMessage({type:"executed"});break;case"execute":var u=e.inputuint8array,r=e.options,_=B.execute(t,u,r);self.postMessage({type:"executed",outputuint8array:_},[_.buffer])}}),self.postMessage({type:"ready"})}();