Comparing version 0.0.13 to 0.0.14
@@ -672,3 +672,3 @@ /* parser generated by jison 0.4.18 */ | ||
exports.parse = function () { return parser.parse.apply(parser, arguments); }; | ||
exports.main = function () { }; | ||
exports.main = () => { }; | ||
if (typeof module !== 'undefined' && require.main === module) { | ||
@@ -675,0 +675,0 @@ exports.main(process.argv.slice(1)); |
@@ -1,1 +0,1 @@ | ||
(function () {var ia={};var oa={};function Ja(r,e){var o={destCol:1,srcCol:1,srcLine:1};r.forEach(function(r){r.destCol>e||(o=r)});var t=e-o.destCol;return{column:o.srcCol+t,line:o.srcLine}}function mb(r){for(var e=[],o=1,t="",s=0,$=!1,c=!1,n=!1,l=0;l<r.length;l++){var p=r[l];if(n){var i=t.length+1,a=l-s+1;e.push({destCol:i,srcCol:a,srcLine:o}),n=!1}"\n"===p?($=!1,o++,s=l+1,n=!0):"\r"===p&&"\n"===r[l+1]?($=!1,o++,s=++l+1,n=!0):c&&"*"===p&&"/"===r[l+1]?(c=!1,l++,n=!0):"\\"===p&&"\\"===r[l+1]||"/"===p&&"/"===r[l+1]?($=!0,l++):"/"===p&&"*"===r[l+1]?(c=!0,l++):$||c||(t+=p)}return[t,e]}var ja,ka,nb={},G=nb={};function ya(){throw new Error("setTimeout has not been defined")}function za(){throw new Error("clearTimeout has not been defined")}function Ka($){if(ja===setTimeout)return setTimeout($,0);if((ja===ya||!ja)&&setTimeout)return ja=setTimeout,setTimeout($,0);try{return ja($,0)}catch(e){try{return ja.call(null,$,0)}catch(e){return ja.call(this,$,0)}}}function ob($){if(ka===clearTimeout)return clearTimeout($);if((ka===za||!ka)&&clearTimeout)return ka=clearTimeout,clearTimeout($);try{return ka($)}catch(e){try{return ka.call(null,$)}catch(e){return ka.call(this,$)}}}!function(){try{ja="function"==typeof setTimeout?setTimeout:ya}catch($){ja=ya}try{ka="function"==typeof clearTimeout?clearTimeout:za}catch($){ka=za}}();var pa,ga=[],Aa=!1,La=-1;function pb(){Aa&&pa&&(Aa=!1,pa.length?ga=pa.concat(ga):La=-1,ga.length&&Ma())}function Ma(){if(!Aa){var $=Ka(pb);Aa=!0;for(var e=ga.length;e;){for(pa=ga,ga=[];++La<e;)pa&&pa[La].run();La=-1,e=ga.length}pa=null,Aa=!1,ob($)}}function Na($,e){this.fun=$,this.array=e}function Z(){}G.nextTick=function($){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];ga.push(new Na($,e)),1!==ga.length||Aa||Ka(Ma)},Na.prototype.run=function(){this.fun.apply(null,this.array)},G.title="browser",G.env={},G.argv=[],G.version="",G.versions={},G.on=Z,G.addListener=Z,G.once=Z,G.off=Z,G.removeListener=Z,G.removeAllListeners=Z,G.emit=Z,G.prependListener=Z,G.prependOnceListener=Z,G.listeners=function($){return[]},G.binding=function($){throw new Error("process.binding is not supported")},G.cwd=function(){return"/"},G.chdir=function($){throw new Error("process.chdir is not supported")},G.umask=function(){return 0};var qb=function(){var t={exports:this},i=function(){var t=function(t,e,i,s){for(i=i||{},s=t.length;s--;i[t[s]]=e);return i},e=[1,18],i=[1,7],s=[1,19],n=[1,20],r=[1,14],h=[1,15],o=[1,16],a=[1,33],c=[1,31],l=[1,23],y=[1,22],u=[1,24],p=[1,25],_=[1,26],f=[1,27],g=[1,28],m=[1,29],E=[1,30],k=[5,8,15,18,20,28,29,32,33,34,35,36,37,38],I=[5,15,18],b=[5,12,15,17,18,24,25,28,29,30],S=[1,57],d=[5,8,12,15,17,18,24,25,28,29,30],N=[15,18],O=[5,8,15,18,28,29,38],$=[5,8,15,18,28,29,32,33,38],x=[5,8,15,18,28,29,32,33,34,37,38],A=[5,8,15,18,28,29,32,33,34,35,36,37,38],R=[5,8,15,18],v=[5,8,15,18,20,22,28,29,32,33,34,35,36,37,38],T={trace:function(){},yy:{},symbols_:{error:2,SCRIPT:3,expression:4,EOF:5,expressionsOptionalTrailingSemi:6,separator:7,";":8,expressions:9,EXPRESSION_BLOCK:10,IDENTIFIER:11,IDENTIFIER_TOKEN:12,argument:13,arguments:14,",":15,FUNCTION_CALL:16,"(":17,")":18,LOGICAL_EXPRESSION:19,LOGICAL_OPERATOR_TOKEN:20,ASSIGNMENT:21,ASSIGNMENT_OPERATOR_TOKEN:22,number:23,DIGITS_TOKEN:24,".":25,NUMBER_LITERAL:26,UNARY_EXPRESSION:27,"-":28,"+":29,"!":30,BINARY_EXPRESSION:31,"*":32,"/":33,"%":34,"&":35,"|":36,"^":37,COMPARISON_TOKEN:38,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",8:";",12:"IDENTIFIER_TOKEN",15:",",17:"(",18:")",20:"LOGICAL_OPERATOR_TOKEN",22:"ASSIGNMENT_OPERATOR_TOKEN",24:"DIGITS_TOKEN",25:".",28:"-",29:"+",30:"!",32:"*",33:"/",34:"%",35:"&",36:"|",37:"^",38:"COMPARISON_TOKEN"},productions_:[0,[3,2],[3,2],[3,1],[7,1],[7,2],[9,2],[9,3],[6,1],[6,2],[10,1],[11,1],[13,1],[13,1],[14,1],[14,3],[16,3],[16,4],[19,3],[21,3],[21,3],[23,1],[23,2],[23,3],[23,2],[23,1],[26,1],[27,2],[27,2],[27,2],[31,3],[31,3],[31,3],[31,3],[31,3],[31,3],[31,3],[31,3],[31,3],[4,1],[4,1],[4,3],[4,1],[4,1],[4,1],[4,1],[4,1],[4,3]],performAction:function(t,e,i,s,n,r,h){var o=r.length-1;switch(n){case 1:return{type:"SCRIPT",body:[r[o-1]],loc:this._$};case 2:return{type:"SCRIPT",body:r[o-1],loc:this._$};case 3:return{type:"SCRIPT",body:[],loc:this._$};case 6:this.$=[r[o-1]];break;case 7:this.$=r[o-2].concat([r[o-1]]);break;case 8:this.$=r[o];break;case 9:this.$=r[o-1].concat([r[o]]);break;case 10:this.$={type:"EXPRESSION_BLOCK",body:r[o],loc:this._$};break;case 11:this.$={type:"IDENTIFIER",value:r[o].toLowerCase(),loc:this._$};break;case 14:this.$=[r[o]];break;case 15:this.$=r[o-2].concat([r[o]]);break;case 16:this.$={type:"CALL_EXPRESSION",callee:r[o-2],arguments:[],loc:this._$};break;case 17:this.$={type:"CALL_EXPRESSION",callee:r[o-3],arguments:r[o-1],loc:this._$};break;case 18:this.$={type:"LOGICAL_EXPRESSION",left:r[o-2],right:r[o],operator:r[o-1],loc:this._$};break;case 19:case 20:this.$={type:"ASSIGNMENT_EXPRESSION",left:r[o-2],operator:r[o-1],right:r[o],loc:this._$};break;case 21:this.$=Number(r[o]);break;case 22:this.$=Number(r[o-1]);break;case 23:this.$=Number(r[o-2]+r[o-1]+r[o]);break;case 24:this.$=Number("0"+r[o-1]+r[o]);break;case 25:this.$=0;break;case 26:this.$={type:"NUMBER_LITERAL",value:r[o],loc:this._$};break;case 27:case 28:case 29:this.$={type:"UNARY_EXPRESSION",value:r[o],operator:r[o-1],loc:this._$};break;case 30:case 31:case 32:case 33:case 34:case 35:case 36:case 37:case 38:this.$={type:"BINARY_EXPRESSION",left:r[o-2],right:r[o],operator:r[o-1],loc:this._$};break;case 41:case 47:this.$=r[o-1];}},table:[{3:1,4:2,5:[1,4],6:3,9:13,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{1:[3]},{5:[1,21],7:32,8:a,20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E},{5:[1,34]},{1:[2,3]},t(k,[2,39]),t(k,[2,40]),{4:35,6:37,9:13,10:36,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},t(k,[2,42]),t(k,[2,43]),t(k,[2,44],{22:[1,38]}),t(k,[2,45],{17:[1,40],22:[1,39]}),t(k,[2,46]),t(I,[2,8],{31:5,27:6,26:8,21:9,16:10,11:11,19:12,23:17,4:41,12:e,17:i,24:s,25:n,28:r,29:h,30:o}),{4:42,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:43,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:44,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},t(k,[2,26]),t([5,8,15,17,18,20,22,28,29,32,33,34,35,36,37,38],[2,11]),t(k,[2,21],{25:[1,45]}),t(k,[2,25],{24:[1,46]}),{1:[2,1]},{4:47,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:48,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:49,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:50,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:51,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:52,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:53,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:54,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:55,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:56,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},t(b,[2,6],{8:S}),t(d,[2,4]),{1:[2,2]},{7:32,8:a,18:[1,58],20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E},{18:[1,59]},t(N,[2,10]),{4:60,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:61,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:65,6:37,9:13,10:66,11:11,12:e,13:64,14:63,16:10,17:i,18:[1,62],19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},t(I,[2,9],{7:67,8:a,20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E}),t(O,[2,27],{20:c,32:u,33:p,34:_,35:f,36:g,37:m}),t(O,[2,28],{20:c,32:u,33:p,34:_,35:f,36:g,37:m}),t(O,[2,29],{20:c,32:u,33:p,34:_,35:f,36:g,37:m}),t(k,[2,22],{24:[1,68]}),t(k,[2,24]),t(O,[2,30],{20:c,32:u,33:p,34:_,35:f,36:g,37:m}),t(O,[2,31],{20:c,32:u,33:p,34:_,35:f,36:g,37:m}),t($,[2,32],{20:c,34:_,35:f,36:g,37:m}),t($,[2,33],{20:c,34:_,35:f,36:g,37:m}),t(x,[2,34],{20:c,35:f,36:g}),t(A,[2,35],{20:c}),t(A,[2,36],{20:c}),t(x,[2,37],{20:c,35:f,36:g}),t(R,[2,38],{20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E}),t(k,[2,18]),t(d,[2,5]),t(k,[2,41]),t(k,[2,47]),t(R,[2,20],{20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E}),t(R,[2,19],{20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E}),t(v,[2,16]),{15:[1,70],18:[1,69]},t(N,[2,14]),t(N,[2,12],{7:32,8:a,20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E}),t(N,[2,13]),t(b,[2,7],{8:S}),t(k,[2,23]),t(v,[2,17]),{4:65,6:37,9:13,10:66,11:11,12:e,13:71,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},t(N,[2,15])],defaultActions:{4:[2,3],21:[2,1],34:[2,2]},parseError:function(t,e){if(!e.recoverable){var i=new Error(t);throw i.hash=e,i}this.trace(t)},parse:function(t){var e=this,i=[0],s=[null],n=[],r=this.table,h="",o=0,a=0,c=0,l=n.slice.call(arguments,1),y=Object.create(this.lexer),u={yy:{}};for(var p in this.yy)Object.prototype.hasOwnProperty.call(this.yy,p)&&(u.yy[p]=this.yy[p]);y.setInput(t,u.yy),u.yy.lexer=y,u.yy.parser=this,void 0===y.yylloc&&(y.yylloc={});var _=y.yylloc;n.push(_);var f=y.options&&y.options.ranges;"function"==typeof u.yy.parseError?this.parseError=u.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var g,m,E,k,I,b,S,d,N,O=function(){var t;return"number"!=typeof(t=y.lex()||1)&&(t=e.symbols_[t]||t),t},$={};;){if(E=i[i.length-1],this.defaultActions[E]?k=this.defaultActions[E]:(null==g&&(g=O()),k=r[E]&&r[E][g]),void 0===k||!k.length||!k[0]){var x="";for(b in N=[],r[E])this.terminals_[b]&&b>2&&N.push("'"+this.terminals_[b]+"'");x=y.showPosition?"Parse error on line "+(o+1)+":\n"+y.showPosition()+"\nExpecting "+N.join(", ")+", got '"+(this.terminals_[g]||g)+"'":"Parse error on line "+(o+1)+": Unexpected "+(1==g?"end of input":"'"+(this.terminals_[g]||g)+"'"),this.parseError(x,{text:y.match,token:this.terminals_[g]||g,line:y.yylineno,loc:_,expected:N})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+E+", token: "+g);switch(k[0]){case 1:i.push(g),s.push(y.yytext),n.push(y.yylloc),i.push(k[1]),g=null,m?(g=m,m=null):(a=y.yyleng,h=y.yytext,o=y.yylineno,_=y.yylloc,c>0&&c--);break;case 2:if(S=this.productions_[k[1]][1],$.$=s[s.length-S],$._$={first_line:n[n.length-(S||1)].first_line,last_line:n[n.length-1].last_line,first_column:n[n.length-(S||1)].first_column,last_column:n[n.length-1].last_column},f&&($._$.range=[n[n.length-(S||1)].range[0],n[n.length-1].range[1]]),void 0!==(I=this.performAction.apply($,[h,a,o,u.yy,k[1],s,n].concat(l))))return I;S&&(i=i.slice(0,-1*S*2),s=s.slice(0,-1*S),n=n.slice(0,-1*S)),i.push(this.productions_[k[1]][0]),s.push($.$),n.push($._$),d=r[i[i.length-2]][i[i.length-1]],i.push(d);break;case 3:return!0;}}return!0}},P={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,i=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var s=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),i.length-1&&(this.yylineno-=i.length-1);var n=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:i?(i.length===s.length?this.yylloc.first_column:0)+s[s.length-i.length].length-i[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[n[0],n[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var i,s,n;if(this.options.backtrack_lexer&&(n={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(n.yylloc.range=this.yylloc.range.slice(0))),(s=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=s.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:s?s[s.length-1].length-s[s.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],i=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),i)return i;if(this._backtrack){for(var r in n)this[r]=n[r];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,i,s;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var n=this._currentRules(),r=0;r<n.length;r++)if((i=this._input.match(this.rules[n[r]]))&&(!e||i[0].length>e[0].length)){if(e=i,s=r,this.options.backtrack_lexer){if(!1!==(t=this.test_match(i,n[r])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,n[s]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var t=this.next();return t||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(t,e,i,s){switch(i){case 0:break;case 1:return 24;case 2:return 38;case 3:return 22;case 4:return 20;case 5:return 12;case 6:return 5;case 7:return e.yytext[0];}},rules:[/^(?:\s+)/,/^(?:[0-9]+)/,/^(?:(==|!=|<=|>=|<|>))/,/^(?:[+\-*/%]?=)/,/^(?:(\&\&)|\|\|)/,/^(?:[a-zA-Z_][a-zA-Z0-9._]*)/,/^(?:$)/,/^(?:.)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7],inclusive:!0}}};function L(){this.yy={}}return T.lexer=P,L.prototype=T,T.Parser=L,new L}();return"undefined"!=typeof require&&void 0!==this&&(this.parser=i,this.Parser=i.Parser,this.parse=function(){return i.parse.apply(i,arguments)},this.main=function(){},void 0!==t&&require.main===t&&this.main(nb.argv.slice(1))),t.exports}.call({});var rb={};rb={parse:qb.parse};function Oa(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function Pa(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?Oa(Object(t),!0).forEach(function(r){Ba(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):Oa(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function Ba(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var sb={ASSIGNMENT_EXPRESSION:[{type:"NODE",key:"right"}],SCRIPT:[{type:"ARRAY",key:"body"}],EXPRESSION_BLOCK:[{type:"ARRAY",key:"body"}],UNARY_EXPRESSION:[{type:"NODE",key:"value"}],NUMBER_LITERAL:[],IDENTIFIER:[],CALL_EXPRESSION:[{type:"ARRAY",key:"arguments"},{type:"NODE",key:"callee"}],BINARY_EXPRESSION:[{type:"NODE",key:"left"},{type:"NODE",key:"right"}],LOGICAL_EXPRESSION:[{type:"NODE",key:"left"},{type:"NODE",key:"right"}]};function Ca(e,r){var t=sb[e.type],n=e;if(null==t)throw new Error("Unknown children definition for ".concat(e.type));return t.forEach(function(t){if("NODE"===t.type){var o=e[t.key],$=Ca(o,r);$!==o&&(n=Pa({},n,Ba({},t.key,$)))}else if("ARRAY"===t.type){var p=e[t.key],y=p.map(function(e){return Ca(e,r)});p.some(function(e,r){return e!==y[r]})&&(n=Pa({},n,Ba({},t.key,y)))}}),r(n)}var qa={};var U={},Qa=U&&U.__read||function(r,t){var n="function"==typeof Symbol&&r[Symbol.iterator];if(!n)return r;var e,$,o=n.call(r),a=[];try{for(;(void 0===t||t-->0)&&!(e=o.next()).done;)a.push(e.value)}catch(p){$={error:p}}finally{try{e&&!e.done&&(n=o.return)&&n.call(o)}finally{if($)throw $.error}}return a},tb=U&&U.__spread||function(){for(var r=[],t=0;t<arguments.length;t++)r=r.concat(Qa(arguments[t]));return r};function Ra(r,t){for(var n=[],e=0;e<r.length;e++){n.push(r[e]),e===r.length-1||n.push(t)}return n}function wa(r){var t=[];return r.forEach(function(r){t.push.apply(t,tb(r))}),t}U.arrayJoin=Ra,U.flatten=wa;var Sa=function(r){return[].concat.apply([],r)};function Ta(r,t){return new Array(r).fill(null).map(function(r,n){return t(n)})}function Da(r,t){return new Array(r).fill(t).join("")}U.flattenTwice=Sa,U.times=Ta,U.repeat=Da;var Ua=function(){function r(){this._list=[]}return r.prototype.get=function(r,t){var n=this._list.findIndex(function(n){var e=Qa(n,2),$=e[0],o=e[1];return $===r&&o===t});return-1===n?(this._list.push([r,t]),this._list.length-1):n},r.prototype.size=function(){return this._list.length},r}();function Va(r){if(0===r.length)throw new Error("Cannot format an empty list");if(1===r.length)return r[0];var t=r.map(function(r){return"\""+r+"\""}),n=t.pop();return t.join(", ")+" and "+n}U.ScopedIdMap=Ua,U.formatList=Va;var Wa=qa&&qa.__extends||function(){var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,t){r.__proto__=t}||function(r,t){for(var e in t)t.hasOwnProperty(e)&&(r[e]=t[e])})(t,e)};return function(t,e){function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}}();function Xa(r,t,e){void 0===e&&(e=1);var o=Math.max(r.first_line-1-e,0),n=r.last_line+e,$=t.split("\n").slice(o,n).map(function(t,e){var n=e+o+1;return(n>=r.first_line&&n<=r.last_line?">":" ")+" "+n+" | "+t});if(r.first_line===r.last_line){var i=Da(r.first_column," "),p=Da(r.last_column-r.first_column,"^"),a=r.first_line-o;$.splice(a,0," | "+i+p)}return $.join("\n")}qa.printLoc=Xa;var Ya=function(r){function t(t,e,o){var n=r.call(this,t)||this;return n.sourceContext=Xa(e,o),n.loc=e,n}return Wa(t,r),t}(Error),ub=function(r){function t(){return null!==r&&r.apply(this,arguments)||this}return Wa(t,r),t}(Ya);function da(r,t,e){return new ub(r,t,e)}function aa(r,t,e){return new Ya(r,t,e)}qa.createUserError=da,qa.createCompilerError=aa;var Za=oa&&oa.__assign||function(){return(Za=Object.assign||function(r){for(var e,$=1,t=arguments.length;$<t;$++)for(var o in e=arguments[$])Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o]);return r}).apply(this,arguments)},vb=oa&&oa.__read||function(r,e){var $="function"==typeof Symbol&&r[Symbol.iterator];if(!$)return r;var t,o,a=$.call(r),n=[];try{for(;(void 0===e||e-->0)&&!(t=a.next()).done;)n.push(t.value)}catch(i){o={error:i}}finally{try{t&&!t.done&&($=a.return)&&$.call(a)}finally{if(o)throw o.error}}return n};function $a(r,e){var $=Ja(e,r.first_column),t=Ja(e,r.last_column);return{first_column:$.column,last_column:t.column,first_line:$.line,last_line:t.line}}function Ea(r){var e=vb(mb(r),2),$=e[0],t=e[1];try{var o=rb.parse($);return Ca(o,function(e){if(1!==e.loc.first_line||1!=e.loc.last_line)throw aa("Unexpected multiline",e.loc,r);return Za(Za({},e),{loc:$a(e.loc,t)})})}catch(a){if(null==a.hash)throw a;throw da("Parse Error: "+a.message.split("\n")[3],$a(a.hash.loc,t),r)}}oa.parse=Ea;var ra={};var sa={};var B={};function wb(a,t){var o,r,h,p=52,M=64-p-1,w=(1<<M)-1,$=w>>1,e=23===p?Math.pow(2,-24)-Math.pow(2,-77):0,i=0,c=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(r=isNaN(t)?1:0,o=w):(o=Math.floor(Math.log(t)/Math.LN2),t*(h=Math.pow(2,-o))<1&&(o--,h*=2),(t+=o+$>=1?e/h:e*Math.pow(2,1-$))*h>=2&&(o++,h/=2),o+$>=w?(r=0,o=w):o+$>=1?(r=(t*h-1)*Math.pow(2,p),o+=$):(r=t*Math.pow(2,$-1)*Math.pow(2,p),o=0));p>=8;a[0+i]=255&r,i+=1,r/=256,p-=8);for(o=o<<p|r,M+=p;M>0;a[0+i]=255&o,i+=1,o/=256,M-=8);a[0+i-1]|=128*c}var xb=B&&B.__read||function($,r){var e="function"==typeof Symbol&&$[Symbol.iterator];if(!e)return $;var x,t,o=e.call($),n=[];try{for(;(void 0===r||r-->0)&&!(x=o.next()).done;)n.push(x.value)}catch(_){t={error:_}}finally{try{x&&!x.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}return n},K=B&&B.__spread||function(){for(var $=[],r=0;r<arguments.length;r++)$=$.concat(xb(arguments[r]));return $},_a=[0,97,115,109];B.MAGIC=_a;var ab=[1,0,0,0];B.WASM_VERSION=ab;var xa=1e-5;B.EPSILON=xa;var ea={TYPE:1,IMPORT:2,FUNC:3,MEMORY:5,GLOBAL:6,EXPORT:7,CODE:10};B.SECTION=ea;var bb={FUNC:0,TABLE:1,MEMORY:2,GLOBAL:3};B.EXPORT_TYPE=bb;var j={block:function($){return[2,$]},loop:function($){return[3,$]},if:function($){return[4,$]},else:5,end:11,br_if:function($){return K([13],H($))},call:function($){return K([16],H($))},drop:26,select:27,local_get:function($){return K([32],H($))},local_set:function($){return K([33],H($))},local_tee:function($){return K([34],H($))},global_get:function($){return K([35],H($))},global_set:function($){return K([36],H($))},f64_load:function($,r){return K([43],H($),H(r))},f64_store:function($,r){return K([57],H($),H(r))},i32_const:function($){return K([65],gb($))},f64_const:function($){return K([68],fb($))},i32_eqz:69,i32_ne:71,i32_lt_s:72,i32_lt_u:73,i32_gt_s:74,i32_le_s:76,i32_le_u:77,i32_ge_s:78,f64_eq:97,f64_ne:98,f64_lt:99,f64_gt:100,f64_le:101,f64_ge:102,i32_add:106,i32_sub:107,i32_mul:108,i32_and:113,i32_or:114,i64_rem_s:129,i64_and:131,i64_or:132,f64_abs:153,f64_neg:154,f64_ceil:155,f64_floor:156,f64_sqrt:159,f64_add:160,f64_sub:161,f64_mul:162,f64_div:163,f64_min:164,f64_max:165,i32_trunc_f64_s:170,i64_trunc_s_f64:176,f64_convert_i64_s:185,f64_convert_i32_s:183};B.op=j;var q={i32:127,i64:126,f32:125,f64:124};B.VAL_TYPE=q;var Fa={const:0,var:1};B.MUTABILITY=Fa;var Q={void:64,i32:127,i64:126,f32:125,f64:124};B.BLOCK=Q;var cb=96;B.FUNCTION_TYPE=cb;var yb=2;B.MEMORY_IDX=yb;var db=3;B.GLOBAL_TYPE=db;var eb=0;B.TYPE_IDX=eb;var la=K([j.f64_abs],j.f64_const(xa),[j.f64_lt]);B.IS_ZEROISH=la;var Y=K([j.f64_abs],j.f64_const(xa),[j.f64_gt]);function fb($){var r=new Uint8Array(8);return wb(r,$),r}B.IS_NOT_ZEROISH=Y,B.encodef64=fb;var ma=function($){return K([$.length],$.split("").map(function($){return $.charCodeAt(0)}))};function H($){var r=[];do{var e=127&$;0!==($>>>=7)&&(e|=128),r.push(e)}while(0!==$);return r}function gb($){for(var r=[],e=0,x=Math.ceil(Math.log2(Math.abs($))),t=$<0,o=!0;o;)e=127&$,$>>=7,t&&($|=-(1<<x-7)),0==$&&0==(64&e)||-1==$&&64==(64&e)?o=!1:e|=128,r.push(e);return r}B.encodeString=ma,B.unsignedLEB128=H,B.signedLEB128=gb;var ha=function($){return K(H($.length),Sa($))};function fa($,r){return 0===r.length?[]:K([$],ha(ha(r)))}B.encodeVector=ha,B.encodeSection=fa;var zb=1e-5,ta={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,atan2:Math.atan2,rand:function(a){return Math.random()*a},pow:Math.pow,log:Math.log,log10:Math.log10,exp:Math.exp,sigmoid:function(a,t){var n=1+Math.exp(-a*t);return Math.abs(n)>zb?1/n:0}};var ua={};var Ab=65536,Bb=8,Cb=2,Db=1048576;var Ga=8388608;var hb=Math.ceil(Ga*Bb*Cb/Ab);var Eb=ua&&ua.__read||function($,o){var r="function"==typeof Symbol&&$[Symbol.iterator];if(!r)return $;var e,n,p=r.call($),t=[];try{for(;(void 0===o||o-->0)&&!(e=p.next()).done;)t.push(e.value)}catch(i){n={error:i}}finally{try{e&&!e.done&&(r=p.return)&&r.call(p)}finally{if(n)throw n.error}}return t},ba=ua&&ua.__spread||function(){for(var $=[],o=0;o<arguments.length;o++)$=$.concat(Eb(arguments[o]));return $},va={sqr:{args:[q.f64],returns:[q.f64],binary:ba(j.local_get(0),j.local_get(0),[j.f64_mul])},bor:{args:[q.f64,q.f64],returns:[q.f64],binary:ba(j.local_get(0),Y,j.local_get(1),Y,[j.i32_or],j.i32_const(0),[j.i32_ne,j.f64_convert_i32_s])},band:{args:[q.f64,q.f64],returns:[q.f64],binary:ba(j.local_get(0),Y,j.local_get(1),Y,[j.i32_and],j.i32_const(0),[j.i32_ne,j.f64_convert_i32_s])},sign:{args:[q.f64],returns:[q.f64],binary:ba(j.f64_const(0),j.local_get(0),[j.f64_lt],j.local_get(0),j.f64_const(0),[j.f64_lt,j.i32_sub,j.f64_convert_i32_s])},mod:{args:[q.f64,q.f64],returns:[q.f64],binary:ba(j.local_get(1),j.f64_const(0),[j.f64_ne],j.if(Q.f64),j.local_get(0),[j.i64_trunc_s_f64],j.local_get(1),[j.i64_trunc_s_f64,j.i64_rem_s,j.f64_convert_i64_s,j.else],j.f64_const(0),[j.end])},bitwiseOr:{args:[q.f64,q.f64],returns:[q.f64],binary:ba(j.local_get(0),[j.i64_trunc_s_f64],j.local_get(1),[j.i64_trunc_s_f64,j.i64_or,j.f64_convert_i64_s])},bitwiseAnd:{args:[q.f64,q.f64],returns:[q.f64],binary:ba(j.local_get(0),[j.i64_trunc_s_f64],j.local_get(1),[j.i64_trunc_s_f64,j.i64_and,j.f64_convert_i64_s])},div:{args:[q.f64,q.f64],returns:[q.f64],localVariables:[q.i32],binary:ba(j.local_get(1),j.f64_const(0),[j.f64_ne],j.if(Q.f64),j.local_get(0),j.local_get(1),[j.f64_div,j.else],j.f64_const(0),[j.end])},_getBufferIndex:{args:[q.f64],returns:[q.i32],localVariables:[q.f64,q.i32],binary:ba(j.f64_const(xa),j.local_get(0),[j.f64_add],j.local_tee(1),[j.i32_trunc_f64_s],j.local_set(2),j.i32_const(-1),j.local_get(2),j.i32_const(8),[j.i32_mul],j.local_get(2),j.i32_const(0),[j.i32_lt_s],j.local_get(2),j.i32_const(Ga-1),[j.i32_gt_s,j.i32_or,j.select])}};ua.localFuncMap=va;var ib=sa&&sa.__read||function($,r){var o="function"==typeof Symbol&&$[Symbol.iterator];if(!o)return $;var e,t,p=o.call($),i=[];try{for(;(void 0===r||r-->0)&&!(e=p.next()).done;)i.push(e.value)}catch(a){t={error:a}}finally{try{e&&!e.done&&(o=p.return)&&o.call(p)}finally{if(t)throw t.error}}return i},z=sa&&sa.__spread||function(){for(var $=[],r=0;r<arguments.length;r++)$=$.concat(ib(arguments[r]));return $};function F($,r){switch($.type){case"SCRIPT":var o=$.body.map(function($,o){return z(F($,r),[j.drop])});return wa(o);case"EXPRESSION_BLOCK":return Ha($.body,r);case"BINARY_EXPRESSION":var e=F($.left,r),t=F($.right,r);if(null==(L={"+":[j.f64_add],"-":[j.f64_sub],"*":[j.f64_mul],"/":r.resolveFunc("div"),"%":r.resolveFunc("mod"),"|":r.resolveFunc("bitwiseOr"),"&":r.resolveFunc("bitwiseAnd"),"^":r.resolveFunc("pow"),"==":z([j.f64_sub],la,[j.f64_convert_i32_s]),"!=":z([j.f64_sub],Y,[j.f64_convert_i32_s]),"<":[j.f64_lt,j.f64_convert_i32_s],">":[j.f64_gt,j.f64_convert_i32_s],"<=":[j.f64_le,j.f64_convert_i32_s],">=":[j.f64_ge,j.f64_convert_i32_s]}[$.operator]))throw aa("Unknown binary expression operator "+$.operator,$.loc,r.rawSource);return z(e,t,L);case"CALL_EXPRESSION":var p=$.callee.value,i=$.arguments,a=function(o){if(i.length<o)throw da("Too few arguments passed to `"+p+"()`. Expected "+o+" but only got "+i.length+".",$.loc,r.rawSource);if(i.length>o)throw da("Too many arguments passed to `"+p+"()`. Expected "+o+" but got "+i.length+".",i[o].loc,r.rawSource)};switch(p){case"exec2":return a(2),Ha($.arguments,r);case"exec3":return a(3),Ha($.arguments,r);case"if":a(3);var m=ib($.arguments,3);return Hb(m[0],m[1],m[2],r);case"while":return a(1),Fb($.arguments[0],r);case"loop":return a(2),Gb($.arguments[0],$.arguments[1],r);case"megabuf":case"gmegabuf":a(1);var V=r.resolveLocal(q.i32);return z(F($.arguments[0],r),r.resolveFunc("_getBufferIndex"),j.local_tee(V),j.i32_const(-1),[j.i32_ne],j.if(Q.f64),j.local_get(V),j.f64_load(3,jb(p)),[j.else],j.f64_const(0),[j.end]);case"assign":a(2);var W=$.arguments[0];if("IDENTIFIER"!=W.type)throw da("Expected the first argument of `assign()` to be an identifier.",W.loc,r.rawSource);var n=r.resolveVar(W.value);return z(F($.arguments[1],r),j.global_set(n),j.global_get(n));}var s=wa($.arguments.map(function($){return F($,r)}));switch(p){case"abs":return a(1),z(s,[j.f64_abs]);case"sqrt":return a(1),z(s,[j.f64_abs,j.f64_sqrt]);case"int":return a(1),z(s,[j.f64_floor]);case"min":return a(2),z(s,[j.f64_min]);case"max":return a(2),z(s,[j.f64_max]);case"above":return a(2),z(s,[j.f64_gt,j.f64_convert_i32_s]);case"below":return a(2),z(s,[j.f64_lt,j.f64_convert_i32_s]);case"equal":return a(2),z(s,[j.f64_sub],la,[j.f64_convert_i32_s]);case"bnot":return a(1),z(s,la,[j.f64_convert_i32_s]);case"floor":return a(1),z(s,[j.f64_floor]);case"ceil":return a(1),z(s,[j.f64_ceil]);}var _=r.resolveFunc(p);if(null==_||p.startsWith("_"))throw da("\""+p+"\" is not defined.",$.callee.loc,r.rawSource);if(null!=ta[p])a(ta[p].length);else{if(null==va[p])throw aa("Missing arity information for the function `"+p+"()`",$.callee.loc,r.rawSource);a(va[p].args.length)}return z(s,_);case"ASSIGNMENT_EXPRESSION":e=$.left;var l=F($.right,r),c=Ib($,r);if("IDENTIFIER"===e.type){n=r.resolveVar(e.value);var u=j.global_get(n),f=j.global_set(n);return null===c?z(l,f,u):z(u,l,c,f,u)}if("CALL_EXPRESSION"!==e.type)throw aa("Unexpected left hand side type for assignment: "+e.type,$.loc,r.rawSource);var v=r.resolveLocal(q.i32);if(1!==e.arguments.length)throw da("Expected 1 argument when assinging to a buffer but got "+e.arguments.length+".",0===e.arguments.length?e.loc:e.arguments[1].loc,r.rawSource);var d=e.callee.value;if("gmegabuf"!==d&&"megabuf"!==d)throw da("The only function calls which may be assigned to are `gmegabuf()` and `megabuf()`.",e.callee.loc,r.rawSource);var g=jb(d);if(null===c){var E=r.resolveLocal(q.i32),S=r.resolveLocal(q.f64);return z(l,j.local_set(S),F(e.arguments[0],r),r.resolveFunc("_getBufferIndex"),j.local_tee(E),j.i32_const(0),[j.i32_lt_s],j.if(Q.f64),j.f64_const(0),[j.else],j.local_get(E),j.local_tee(v),j.local_get(S),j.f64_store(3,g),j.local_get(S),[j.end])}V=r.resolveLocal(q.i32);var h=r.resolveLocal(q.i32),x=r.resolveLocal(q.f64),w=r.resolveLocal(q.f64);return z(l,j.local_set(x),F(e.arguments[0],r),r.resolveFunc("_getBufferIndex"),j.local_tee(V),j.i32_const(-1),[j.i32_ne],j.local_tee(h),j.if(Q.f64),j.local_get(V),j.f64_load(3,g),[j.else],j.f64_const(0),[j.end],j.local_get(x),c,j.local_tee(w),j.local_get(h),j.if(Q.void),j.local_get(V),j.local_get(w),j.f64_store(3,g),[j.end]);case"LOGICAL_EXPRESSION":e=F($.left,r),t=F($.right,r);var I={"&&":{comparison:la,shortCircutValue:0},"||":{comparison:Y,shortCircutValue:1}}[$.operator];if(null==I)throw aa("Unknown logical expression operator "+$.operator,$.loc,r.rawSource);var b=I.comparison,O=I.shortCircutValue;return z(e,b,j.if(Q.f64),j.f64_const(O),[j.else],t,Y,[j.f64_convert_i32_s,j.end]);case"UNARY_EXPRESSION":var L,y=F($.value,r);if(null==(L={"-":[j.f64_neg],"+":[],"!":z(la,[j.f64_convert_i32_s])}[$.operator]))throw aa("Unknown logical unary operator "+$.operator,$.loc,r.rawSource);return z(y,L);case"IDENTIFIER":var C=$.value;return j.global_get(r.resolveVar(C));case"NUMBER_LITERAL":return j.f64_const($.value);default:throw aa("Unknown AST node type "+$.type,$.loc,r.rawSource);}}function Ha($,r){var o=$.map(function($,o){return F($,r)});return wa(Ra(o,[j.drop]))}function Fb($,r){var o=F($,r),e=r.resolveLocal(q.i32);return z(j.i32_const(0),j.local_set(e),j.loop(Q.void),j.local_get(e),j.i32_const(1),[j.i32_add],j.local_tee(e),j.i32_const(Db),[j.i32_lt_u],o,Y,[j.i32_and],j.br_if(0),[j.end],j.f64_const(0))}function Gb($,r,o){var e=F(r,o),t=o.resolveLocal(q.i32);return z(j.block(Q.void),F($,o),[j.i32_trunc_f64_s],j.local_tee(t),j.i32_const(0),[j.i32_le_s],j.br_if(1),j.loop(Q.void),e,[j.drop],j.local_get(t),j.i32_const(1),[j.i32_sub],j.local_tee(t),j.i32_const(0),[j.i32_ne],j.br_if(0),[j.end,j.end],j.f64_const(0))}function Hb($,r,o,e){return z(F($,e),Y,j.if(Q.f64),F(r,e),[j.else],F(o,e),[j.end])}function jb($){switch($){case"gmegabuf":return 8*Ga;case"megabuf":return 0;}}function Ib($,r){var o={"+=":[j.f64_add],"-=":[j.f64_sub],"*=":[j.f64_mul],"/=":[j.f64_div],"%=":r.resolveFunc("mod"),"=":null}[$.operator];if(void 0===o)throw aa("Unknown assignment operator \""+$.operator+"\"",$.loc,r.rawSource);return o}sa.emit=F;var na=ra&&ra.__read||function(r,$){var e="function"==typeof Symbol&&r[Symbol.iterator];if(!e)return r;var o,t,n=e.call(r),d=[];try{for(;(void 0===$||$-->0)&&!(o=n.next()).done;)d.push(o.value)}catch(i){t={error:i}}finally{try{o&&!o.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}return d},J=ra&&ra.__spread||function(){for(var r=[],$=0;$<arguments.length;$++)r=r.concat(na(arguments[$]));return r};function Ia(r){var $=r.pools,e=r.functions,o=r.eelVersion,t=void 0===o?2:o,n=r.preParsed,d=void 0!==n&&n;if(Object.keys($).includes("shims"))throw new Error("You may not name a pool \"shims\". \"shims\" is reserved for injected JavaScript functions.");var i=[];Object.entries($).forEach(function(r){var $=na(r,2),e=$[0];$[1].forEach(function(r){i.push([e,r])})});var a=new Ua;i.forEach(function(r){var $=na(r,2),e=$[0],o=$[1];a.get(e,o)});var p=Object.entries(ta).map(function(r){var $=na(r,2),e=$[0],o=$[1];return{args:new Array(o.length).fill(null).map(function(r){return q.f64}),returns:[q.f64],name:e}}),c=[],s=[];Object.entries(e).forEach(function(r){var e=na(r,2),o=e[0],n=e[1],i=n.pool,u=n.code;if(null==$[i]){var X=Object.keys($);if(0===X.length)throw new Error("The function \""+o+"\" was declared as using a variable pool named \""+i+"\" but no pools were defined.");throw new Error("The function \""+o+"\" was declared as using a variable pool named \""+i+"\" which is not among the variable pools defined. The defined variable pools are: "+Va(X)+".")}var D=d?u:Ea(u);if("string"==typeof D)throw new Error("Got passed unparsed code without setting the preParsed flag");if("SCRIPT"!==D.type)throw new Error("Invalid AST");if(0!==D.body.length){var l=[],m=F(D,{resolveVar:function(r){return /^reg\d\d$/.test(r)?a.get(null,r):a.get(i,r)},resolveLocal:function(r){return l.push(r),l.length-1},resolveFunc:function(r){var $=p.findIndex(function($){return $.name===r});if(-1!==$){var e=j.call($);return"rand"===r&&1===t?J(e,[j.f64_floor]):e}if(null==va[r])return null;var o=c.indexOf(r);return-1===o&&(c.push(r),o=c.length-1),j.call(o+p.length)},rawSource:u});s.push({binary:m,exportName:o,args:[],returns:[],localVariables:l})}});var u=c.map(function(r){var $=va[r];if(null==$)throw new Error("Undefined local function \""+r+"\"");return $}),X=function(r){return J(r.args,["|"],r.returns).join("-")},D=[],l=new Map;function m(r){var $=X(r),e=l.get($);if(null==e)throw new Error("Failed to get a type index for key "+$);return e}J(p,u,s).forEach(function(r){var $=X(r);l.has($)||(D.push(J([cb],ha(r.args),ha(r.returns))),l.set($,D.length-1))});var f=J(i.map(function(r){var $=na(r,2),e=$[0],o=$[1];return J(ma(e),ma(o),[db,q.f64,Fa.var])}),p.map(function(r,$){var e=m(r);return J(ma("shims"),ma(r.name),J([eb],H(e)))})),v=J(u,s).map(function(r){var $=m(r);return H($)}),_=[J([1],H(hb),H(hb))],h=a.size()-i.length,E=Ta(h,function(){return J([q.f64,Fa.var],j.f64_const(0),[j.end])}),g=J(s).map(function(r,$){var e=$+p.length+u.length;return J(ma(r.exportName),[bb.FUNC],H(e))}),S=J(u,s).map(function(r){var $,e=(null!==($=r.localVariables)&&void 0!==$?$:[]).map(function(r){return J(H(1),[r])});return ha(J(ha(e),r.binary,[j.end]))});return new Uint8Array(J(_a,ab,fa(ea.TYPE,D),fa(ea.IMPORT,f),fa(ea.FUNC,v),fa(ea.MEMORY,_),fa(ea.GLOBAL,E),fa(ea.EXPORT,g),fa(ea.CODE,S)))}ra.compileModule=Ia;var ca={};var kb=ca&&ca.__assign||function(){return(kb=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)},Jb=ca&&ca.__awaiter||function(e,r,t,n){return new(t||(t=Promise))(function(o,a){function l(e){try{i(n.next(e))}catch(r){a(r)}}function u(e){try{i(n.throw(e))}catch(r){a(r)}}function i(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t(function(e){e(r)})).then(l,u)}i((n=n.apply(e,r||[])).next())})},Kb=ca&&ca.__generator||function(e,r){var t,n,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(t)throw new TypeError("Generator is already executing.");for(;l;)try{if(t=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return l.label++,{value:a[1],done:!1};case 5:l.label++,n=a[1],a=[0];continue;case 7:a=l.ops.pop(),l.trys.pop();continue;default:if(!(o=(o=l.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){l=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){l.label=a[1];break}if(6===a[0]&&l.label<o[1]){l.label=o[1],o=a;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(a);break}o[2]&&l.ops.pop(),l.trys.pop();continue;}a=r.call(e,l)}catch(u){a=[6,u],n=0}finally{t=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},Lb=ca&&ca.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,a=t.call(e),l=[];try{for(;(void 0===r||r-->0)&&!(n=a.next()).done;)l.push(n.value)}catch(u){o={error:u}}finally{try{n&&!n.done&&(t=a.return)&&t.call(a)}finally{if(o)throw o.error}}return l};function lb(e){var r=e.pools,t=e.functions,n=e.eelVersion,o=void 0===n?2:n;return Jb(this,void 0,void 0,function(){var e,n,a,l;return Kb(this,function(u){switch(u.label){case 0:return e={},Object.entries(r).forEach(function(r){var t=Lb(r,2),n=t[0],o=t[1];e[n]=new Set(Object.keys(o))}),n=Ia({pools:e,functions:t,eelVersion:o}),[4,WebAssembly.compile(n)];case 1:return a=u.sent(),l=kb(kb({},r),{shims:ta}),[4,WebAssembly.instantiate(a,l)];case 2:return[2,u.sent()];}})})}ca.loadModule=lb;ia.loadModule=lb,ia.shims=ta,ia.compileModule=Ia,ia.parse=Ea;if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=ia}else if(typeof define==="function"&&define.amd){define(function(){return ia})}})(); | ||
(function () {var Da={};function Hb(r,e){var o={destCol:1,srcCol:1,srcLine:1};r.forEach(function(r){r.destCol>e||(o=r)});var $=e-o.destCol;return{column:o.srcCol+$,line:o.srcLine}}Object.defineProperty(Da,"__esModule",{value:!0});var Ea=Hb;function Ib(r){for(var e=[],o=1,$="",s=0,t=!1,c=!1,n=!1,p=0;p<r.length;p++){var a=r[p];if(n){var j=$.length+1,l=p-s+1;e.push({destCol:j,srcCol:l,srcLine:o}),n=!1}"\n"===a?(t=!1,o++,s=p+1,n=!0):"\r"===a&&"\n"===r[p+1]?(t=!1,o++,s=++p+1,n=!0):c&&"*"===a&&"/"===r[p+1]?(c=!1,p++,n=!0):"\\"===a&&"\\"===r[p+1]||"/"===a&&"/"===r[p+1]?(t=!0,p++):"/"===a&&"*"===r[p+1]?(c=!0,p++):t||c||($+=a)}return[$,e]}Da.getLoc=Ea;var Za=Ib;Da.preProcess=Za;var ma,na,Jb={},Q=Jb={};function Fa(){throw new Error("setTimeout has not been defined")}function Ga(){throw new Error("clearTimeout has not been defined")}function $a($){if(ma===setTimeout)return setTimeout($,0);if((ma===Fa||!ma)&&setTimeout)return ma=setTimeout,setTimeout($,0);try{return ma($,0)}catch(e){try{return ma.call(null,$,0)}catch(e){return ma.call(this,$,0)}}}function Kb($){if(na===clearTimeout)return clearTimeout($);if((na===Ga||!na)&&clearTimeout)return na=clearTimeout,clearTimeout($);try{return na($)}catch(e){try{return na.call(null,$)}catch(e){return na.call(this,$)}}}!function(){try{ma="function"==typeof setTimeout?setTimeout:Fa}catch($){ma=Fa}try{na="function"==typeof clearTimeout?clearTimeout:Ga}catch($){na=Ga}}();var sa,ka=[],Ha=!1,_a=-1;function Lb(){Ha&&sa&&(Ha=!1,sa.length?ka=sa.concat(ka):_a=-1,ka.length&&ab())}function ab(){if(!Ha){var $=$a(Lb);Ha=!0;for(var e=ka.length;e;){for(sa=ka,ka=[];++_a<e;)sa&&sa[_a].run();_a=-1,e=ka.length}sa=null,Ha=!1,Kb($)}}function bb($,e){this.fun=$,this.array=e}function da(){}Q.nextTick=function($){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];ka.push(new bb($,e)),1!==ka.length||Ha||$a(ab)},bb.prototype.run=function(){this.fun.apply(null,this.array)},Q.title="browser",Q.env={},Q.argv=[],Q.version="",Q.versions={},Q.on=da,Q.addListener=da,Q.once=da,Q.off=da,Q.removeListener=da,Q.removeAllListeners=da,Q.emit=da,Q.prependListener=da,Q.prependOnceListener=da,Q.listeners=function($){return[]},Q.binding=function($){throw new Error("process.binding is not supported")},Q.cwd=function(){return"/"},Q.chdir=function($){throw new Error("process.chdir is not supported")},Q.umask=function(){return 0};var Mb=function(){var t={exports:this},i=function(){var t=function(t,e,i,s){for(i=i||{},s=t.length;s--;i[t[s]]=e);return i},e=[1,18],i=[1,7],s=[1,19],n=[1,20],r=[1,14],h=[1,15],o=[1,16],a=[1,33],c=[1,31],l=[1,23],y=[1,22],u=[1,24],p=[1,25],_=[1,26],f=[1,27],g=[1,28],m=[1,29],E=[1,30],k=[5,8,15,18,20,28,29,32,33,34,35,36,37,38],I=[5,15,18],b=[5,12,15,17,18,24,25,28,29,30],S=[1,57],d=[5,8,12,15,17,18,24,25,28,29,30],N=[15,18],O=[5,8,15,18,28,29,38],$=[5,8,15,18,28,29,32,33,38],x=[5,8,15,18,28,29,32,33,34,37,38],A=[5,8,15,18,28,29,32,33,34,35,36,37,38],R=[5,8,15,18],v=[5,8,15,18,20,22,28,29,32,33,34,35,36,37,38],T={trace:function(){},yy:{},symbols_:{error:2,SCRIPT:3,expression:4,EOF:5,expressionsOptionalTrailingSemi:6,separator:7,";":8,expressions:9,EXPRESSION_BLOCK:10,IDENTIFIER:11,IDENTIFIER_TOKEN:12,argument:13,arguments:14,",":15,FUNCTION_CALL:16,"(":17,")":18,LOGICAL_EXPRESSION:19,LOGICAL_OPERATOR_TOKEN:20,ASSIGNMENT:21,ASSIGNMENT_OPERATOR_TOKEN:22,number:23,DIGITS_TOKEN:24,".":25,NUMBER_LITERAL:26,UNARY_EXPRESSION:27,"-":28,"+":29,"!":30,BINARY_EXPRESSION:31,"*":32,"/":33,"%":34,"&":35,"|":36,"^":37,COMPARISON_TOKEN:38,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",8:";",12:"IDENTIFIER_TOKEN",15:",",17:"(",18:")",20:"LOGICAL_OPERATOR_TOKEN",22:"ASSIGNMENT_OPERATOR_TOKEN",24:"DIGITS_TOKEN",25:".",28:"-",29:"+",30:"!",32:"*",33:"/",34:"%",35:"&",36:"|",37:"^",38:"COMPARISON_TOKEN"},productions_:[0,[3,2],[3,2],[3,1],[7,1],[7,2],[9,2],[9,3],[6,1],[6,2],[10,1],[11,1],[13,1],[13,1],[14,1],[14,3],[16,3],[16,4],[19,3],[21,3],[21,3],[23,1],[23,2],[23,3],[23,2],[23,1],[26,1],[27,2],[27,2],[27,2],[31,3],[31,3],[31,3],[31,3],[31,3],[31,3],[31,3],[31,3],[31,3],[4,1],[4,1],[4,3],[4,1],[4,1],[4,1],[4,1],[4,1],[4,3]],performAction:function(t,e,i,s,n,r,h){var o=r.length-1;switch(n){case 1:return{type:"SCRIPT",body:[r[o-1]],loc:this._$};case 2:return{type:"SCRIPT",body:r[o-1],loc:this._$};case 3:return{type:"SCRIPT",body:[],loc:this._$};case 6:this.$=[r[o-1]];break;case 7:this.$=r[o-2].concat([r[o-1]]);break;case 8:this.$=r[o];break;case 9:this.$=r[o-1].concat([r[o]]);break;case 10:this.$={type:"EXPRESSION_BLOCK",body:r[o],loc:this._$};break;case 11:this.$={type:"IDENTIFIER",value:r[o].toLowerCase(),loc:this._$};break;case 14:this.$=[r[o]];break;case 15:this.$=r[o-2].concat([r[o]]);break;case 16:this.$={type:"CALL_EXPRESSION",callee:r[o-2],arguments:[],loc:this._$};break;case 17:this.$={type:"CALL_EXPRESSION",callee:r[o-3],arguments:r[o-1],loc:this._$};break;case 18:this.$={type:"LOGICAL_EXPRESSION",left:r[o-2],right:r[o],operator:r[o-1],loc:this._$};break;case 19:case 20:this.$={type:"ASSIGNMENT_EXPRESSION",left:r[o-2],operator:r[o-1],right:r[o],loc:this._$};break;case 21:this.$=Number(r[o]);break;case 22:this.$=Number(r[o-1]);break;case 23:this.$=Number(r[o-2]+r[o-1]+r[o]);break;case 24:this.$=Number("0"+r[o-1]+r[o]);break;case 25:this.$=0;break;case 26:this.$={type:"NUMBER_LITERAL",value:r[o],loc:this._$};break;case 27:case 28:case 29:this.$={type:"UNARY_EXPRESSION",value:r[o],operator:r[o-1],loc:this._$};break;case 30:case 31:case 32:case 33:case 34:case 35:case 36:case 37:case 38:this.$={type:"BINARY_EXPRESSION",left:r[o-2],right:r[o],operator:r[o-1],loc:this._$};break;case 41:case 47:this.$=r[o-1];}},table:[{3:1,4:2,5:[1,4],6:3,9:13,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{1:[3]},{5:[1,21],7:32,8:a,20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E},{5:[1,34]},{1:[2,3]},t(k,[2,39]),t(k,[2,40]),{4:35,6:37,9:13,10:36,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},t(k,[2,42]),t(k,[2,43]),t(k,[2,44],{22:[1,38]}),t(k,[2,45],{17:[1,40],22:[1,39]}),t(k,[2,46]),t(I,[2,8],{31:5,27:6,26:8,21:9,16:10,11:11,19:12,23:17,4:41,12:e,17:i,24:s,25:n,28:r,29:h,30:o}),{4:42,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:43,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:44,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},t(k,[2,26]),t([5,8,15,17,18,20,22,28,29,32,33,34,35,36,37,38],[2,11]),t(k,[2,21],{25:[1,45]}),t(k,[2,25],{24:[1,46]}),{1:[2,1]},{4:47,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:48,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:49,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:50,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:51,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:52,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:53,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:54,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:55,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:56,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},t(b,[2,6],{8:S}),t(d,[2,4]),{1:[2,2]},{7:32,8:a,18:[1,58],20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E},{18:[1,59]},t(N,[2,10]),{4:60,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:61,11:11,12:e,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},{4:65,6:37,9:13,10:66,11:11,12:e,13:64,14:63,16:10,17:i,18:[1,62],19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},t(I,[2,9],{7:67,8:a,20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E}),t(O,[2,27],{20:c,32:u,33:p,34:_,35:f,36:g,37:m}),t(O,[2,28],{20:c,32:u,33:p,34:_,35:f,36:g,37:m}),t(O,[2,29],{20:c,32:u,33:p,34:_,35:f,36:g,37:m}),t(k,[2,22],{24:[1,68]}),t(k,[2,24]),t(O,[2,30],{20:c,32:u,33:p,34:_,35:f,36:g,37:m}),t(O,[2,31],{20:c,32:u,33:p,34:_,35:f,36:g,37:m}),t($,[2,32],{20:c,34:_,35:f,36:g,37:m}),t($,[2,33],{20:c,34:_,35:f,36:g,37:m}),t(x,[2,34],{20:c,35:f,36:g}),t(A,[2,35],{20:c}),t(A,[2,36],{20:c}),t(x,[2,37],{20:c,35:f,36:g}),t(R,[2,38],{20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E}),t(k,[2,18]),t(d,[2,5]),t(k,[2,41]),t(k,[2,47]),t(R,[2,20],{20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E}),t(R,[2,19],{20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E}),t(v,[2,16]),{15:[1,70],18:[1,69]},t(N,[2,14]),t(N,[2,12],{7:32,8:a,20:c,28:l,29:y,32:u,33:p,34:_,35:f,36:g,37:m,38:E}),t(N,[2,13]),t(b,[2,7],{8:S}),t(k,[2,23]),t(v,[2,17]),{4:65,6:37,9:13,10:66,11:11,12:e,13:71,16:10,17:i,19:12,21:9,23:17,24:s,25:n,26:8,27:6,28:r,29:h,30:o,31:5},t(N,[2,15])],defaultActions:{4:[2,3],21:[2,1],34:[2,2]},parseError:function(t,e){if(!e.recoverable){var i=new Error(t);throw i.hash=e,i}this.trace(t)},parse:function(t){var e=this,i=[0],s=[null],n=[],r=this.table,h="",o=0,a=0,c=0,l=n.slice.call(arguments,1),y=Object.create(this.lexer),u={yy:{}};for(var p in this.yy)Object.prototype.hasOwnProperty.call(this.yy,p)&&(u.yy[p]=this.yy[p]);y.setInput(t,u.yy),u.yy.lexer=y,u.yy.parser=this,void 0===y.yylloc&&(y.yylloc={});var _=y.yylloc;n.push(_);var f=y.options&&y.options.ranges;"function"==typeof u.yy.parseError?this.parseError=u.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var g,m,E,k,I,b,S,d,N,O=function(){var t;return"number"!=typeof(t=y.lex()||1)&&(t=e.symbols_[t]||t),t},$={};;){if(E=i[i.length-1],this.defaultActions[E]?k=this.defaultActions[E]:(null==g&&(g=O()),k=r[E]&&r[E][g]),void 0===k||!k.length||!k[0]){var x="";for(b in N=[],r[E])this.terminals_[b]&&b>2&&N.push("'"+this.terminals_[b]+"'");x=y.showPosition?"Parse error on line "+(o+1)+":\n"+y.showPosition()+"\nExpecting "+N.join(", ")+", got '"+(this.terminals_[g]||g)+"'":"Parse error on line "+(o+1)+": Unexpected "+(1==g?"end of input":"'"+(this.terminals_[g]||g)+"'"),this.parseError(x,{text:y.match,token:this.terminals_[g]||g,line:y.yylineno,loc:_,expected:N})}if(k[0]instanceof Array&&k.length>1)throw new Error("Parse Error: multiple actions possible at state: "+E+", token: "+g);switch(k[0]){case 1:i.push(g),s.push(y.yytext),n.push(y.yylloc),i.push(k[1]),g=null,m?(g=m,m=null):(a=y.yyleng,h=y.yytext,o=y.yylineno,_=y.yylloc,c>0&&c--);break;case 2:if(S=this.productions_[k[1]][1],$.$=s[s.length-S],$._$={first_line:n[n.length-(S||1)].first_line,last_line:n[n.length-1].last_line,first_column:n[n.length-(S||1)].first_column,last_column:n[n.length-1].last_column},f&&($._$.range=[n[n.length-(S||1)].range[0],n[n.length-1].range[1]]),void 0!==(I=this.performAction.apply($,[h,a,o,u.yy,k[1],s,n].concat(l))))return I;S&&(i=i.slice(0,-1*S*2),s=s.slice(0,-1*S),n=n.slice(0,-1*S)),i.push(this.productions_[k[1]][0]),s.push($.$),n.push($._$),d=r[i[i.length-2]][i[i.length-1]],i.push(d);break;case 3:return!0;}}return!0}},P={EOF:1,parseError:function(t,e){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,e)},setInput:function(t,e){return this.yy=e||this.yy||{},this._input=t,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var t=this._input[0];return this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t,t.match(/(?:\r\n?|\n).*/g)?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),t},unput:function(t){var e=t.length,i=t.split(/(?:\r\n?|\n)/g);this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-e),this.offset-=e;var s=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),i.length-1&&(this.yylineno-=i.length-1);var n=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:i?(i.length===s.length?this.yylloc.first_column:0)+s[s.length-i.length].length-i[0].length:this.yylloc.first_column-e},this.options.ranges&&(this.yylloc.range=[n[0],n[0]+this.yyleng-e]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(t){this.unput(this.match.slice(t))},pastInput:function(){var t=this.matched.substr(0,this.matched.length-this.match.length);return(t.length>20?"...":"")+t.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var t=this.match;return t.length<20&&(t+=this._input.substr(0,20-t.length)),(t.substr(0,20)+(t.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var t=this.pastInput(),e=new Array(t.length+1).join("-");return t+this.upcomingInput()+"\n"+e+"^"},test_match:function(t,e){var i,s,n;if(this.options.backtrack_lexer&&(n={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(n.yylloc.range=this.yylloc.range.slice(0))),(s=t[0].match(/(?:\r\n?|\n).*/g))&&(this.yylineno+=s.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:s?s[s.length-1].length-s[s.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],i=this.performAction.call(this,this.yy,this,e,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),i)return i;if(this._backtrack){for(var r in n)this[r]=n[r];return!1}return!1},next:function(){if(this.done)return this.EOF;var t,e,i,s;this._input||(this.done=!0),this._more||(this.yytext="",this.match="");for(var n=this._currentRules(),r=0;r<n.length;r++)if((i=this._input.match(this.rules[n[r]]))&&(!e||i[0].length>e[0].length)){if(e=i,s=r,this.options.backtrack_lexer){if(!1!==(t=this.test_match(i,n[r])))return t;if(this._backtrack){e=!1;continue}return!1}if(!this.options.flex)break}return e?!1!==(t=this.test_match(e,n[s]))&&t:""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var t=this.next();return t||this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.length-1>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(t){return(t=this.conditionStack.length-1-Math.abs(t||0))>=0?this.conditionStack[t]:"INITIAL"},pushState:function(t){this.begin(t)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(t,e,i,s){switch(i){case 0:break;case 1:return 24;case 2:return 38;case 3:return 22;case 4:return 20;case 5:return 12;case 6:return 5;case 7:return e.yytext[0];}},rules:[/^(?:\s+)/,/^(?:[0-9]+)/,/^(?:(==|!=|<=|>=|<|>))/,/^(?:[+\-*/%]?=)/,/^(?:(\&\&)|\|\|)/,/^(?:[a-zA-Z_][a-zA-Z0-9._]*)/,/^(?:$)/,/^(?:.)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7],inclusive:!0}}};function L(){this.yy={}}return T.lexer=P,L.prototype=T,T.Parser=L,new L}();return"undefined"!=typeof require&&void 0!==this&&(this.parser=i,this.Parser=i.Parser,this.parse=function(){return i.parse.apply(i,arguments)},this.main=function(){},void 0!==t&&require.main===t&&this.main(Jb.argv.slice(1))),t.exports}.call({});var Nb={};Nb={parse:Mb.parse};function cb(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function db(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?cb(Object(t),!0).forEach(function(r){Ia(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):cb(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function Ia(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var Ob={ASSIGNMENT_EXPRESSION:[{type:"NODE",key:"right"}],SCRIPT:[{type:"ARRAY",key:"body"}],EXPRESSION_BLOCK:[{type:"ARRAY",key:"body"}],UNARY_EXPRESSION:[{type:"NODE",key:"value"}],NUMBER_LITERAL:[],IDENTIFIER:[],CALL_EXPRESSION:[{type:"ARRAY",key:"arguments"},{type:"NODE",key:"callee"}],BINARY_EXPRESSION:[{type:"NODE",key:"left"},{type:"NODE",key:"right"}],LOGICAL_EXPRESSION:[{type:"NODE",key:"left"},{type:"NODE",key:"right"}]};function Ja(e,r){var t=Ob[e.type],n=e;if(null==t)throw new Error("Unknown children definition for ".concat(e.type));return t.forEach(function(t){if("NODE"===t.type){var o=e[t.key],$=Ja(o,r);$!==o&&(n=db({},n,Ia({},t.key,$)))}else if("ARRAY"===t.type){var p=e[t.key],y=p.map(function(e){return Ja(e,r)});p.some(function(e,r){return e!==y[r]})&&(n=db({},n,Ia({},t.key,y)))}}),r(n)}var ga={};function Pb(n,r){if(!(n instanceof r))throw new TypeError("Cannot call a class as a function")}function eb(n,r){for(var e=0;e<r.length;e++){var t=r[e];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(n,t.key,t)}}function Qb(n,r,e){return r&&eb(n.prototype,r),e&&eb(n,e),n}function Rb(n,r){for(var e=[],t=0;t<n.length;t++){e.push(n[t]),t===n.length-1||e.push(r)}return e}Object.defineProperty(ga,"__esModule",{value:!0});var fb=Rb;function Sb(n){return[].concat.apply([],n)}ga.arrayJoin=fb;var ta=Sb;function Tb(n,r){return new Array(n).fill(null).map(function(n,e){return r(e)})}ga.flatten=ta;var Ub=Tb;function Vb(n,r){return new Array(n).fill(r).join("")}ga.times=Ub;var Ka=Vb;ga.repeat=Ka;var Wb=function(){function n(){Pb(this,n),this._map=new Map}return Qb(n,[{key:"get",value:function(n,r){var e=null==n?r:"".concat(n,"::").concat(r);return this._map.has(e)||this._map.set(e,this._map.size),this._map.get(e)}},{key:"size",value:function(){return this._map.size}}]),n}(),Xb=Wb;function Yb(n){if(0===n.length)throw new Error("Cannot format an empty list");if(1===n.length)return n[0];var r=n.map(function(n){return"\"".concat(n,"\"")}),e=r.pop();return r.join(", ")+" and ".concat(e)}ga.ScopedIdMap=Xb;var Zb=Yb;ga.formatList=Zb;var xa={};function $b(r){return($b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function gb(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}function hb(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),t&&La(r,t)}function ib(r){return function(){var t,e=Ma(r);if(jb()){var o=Ma(this).constructor;t=Reflect.construct(e,arguments,o)}else t=e.apply(this,arguments);return _b(this,t)}}function _b(r,t){return!t||"object"!==$b(t)&&"function"!=typeof t?ac(r):t}function ac(r){if(void 0===r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function bc(r){var t="function"==typeof Map?new Map:void 0;return(bc=function(r){if(null===r||!dc(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(r))return t.get(r);t.set(r,e)}function e(){return cc(r,arguments,Ma(this).constructor)}return e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),La(e,r)})(r)}function cc(r,t,e){return(cc=jb()?Reflect.construct:function(r,t,e){var o=[null];o.push.apply(o,t);var n=new(Function.bind.apply(r,o));return e&&La(n,e.prototype),n}).apply(null,arguments)}function jb(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(r){return!1}}function dc(r){return-1!==Function.toString.call(r).indexOf("[native code]")}function La(r,t){return(La=Object.setPrototypeOf||function(r,t){return r.__proto__=t,r})(r,t)}function Ma(r){return(Ma=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}Object.defineProperty(xa,"__esModule",{value:!0});function kb(r,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,o=Math.max(r.first_line-1-e,0),n=r.last_line+e,$=t.split("\n").slice(o,n).map(function(t,e){var n=e+o+1,$=n>=r.first_line&&n<=r.last_line;return"".concat($?">":" "," ").concat(n," | ").concat(t)});if(r.first_line===r.last_line){var a=Ka(r.first_column," "),i=Ka(r.last_column-r.first_column,"^"),c=r.first_line-o;$.splice(c,0," | ".concat(a).concat(i))}return $.join("\n")}var ec=kb;xa.printLoc=ec;var lb=function(r){hb(e,bc(Error));var t=ib(e);function e(r,o,n){var $;return gb(this,e),($=t.call(this,r)).sourceContext=kb(o,n),$.loc=o,$}return e}(),fc=function(r){hb(e,lb);var t=ib(e);function e(){return gb(this,e),t.apply(this,arguments)}return e}();function gc(r,t,e){return new fc(r,t,e)}var ha=gc;function hc(r,t,e){return new lb(r,t,e)}xa.createUserError=ha;var ea=hc;xa.createCompilerError=ea;var mb={};function ic(r,e){return mc(r)||lc(r,e)||kc(r,e)||jc()}function jc(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function kc(r,e){if(r){if("string"==typeof r)return nb(r,e);var a=Object.prototype.toString.call(r).slice(8,-1);return"Object"===a&&r.constructor&&(a=r.constructor.name),"Map"===a||"Set"===a?Array.from(a):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?nb(r,e):void 0}}function nb(r,e){(null==e||e>r.length)&&(e=r.length);for(var a=0,t=new Array(e);a<e;a++)t[a]=r[a];return t}function lc(r,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(r)){var a=[],t=!0,$=!1,o=void 0;try{for(var n,v=r[Symbol.iterator]();!(t=(n=v.next()).done)&&(a.push(n.value),!e||a.length!==e);t=!0);}catch(i){$=!0,o=i}finally{try{t||null==v.return||v.return()}finally{if($)throw o}}return a}}function mc(r){if(Array.isArray(r))return r}Object.defineProperty(mb,"__esModule",{value:!0});function ob(r,e){var a=Ea(e,r.first_column),t=Ea(e,r.last_column);return{first_column:a.column,last_column:t.column,first_line:a.line,last_line:t.line}}function nc(r){var e=ic(Za(r),2),a=e[0],t=e[1];try{var $=Nb.parse(a);return Ja($,function(e){if(1!==e.loc.first_line||1!=e.loc.last_line)throw ea("Unexpected multiline",e.loc,r);return Object.assign(Object.assign({},e),{loc:ob(e.loc,t)})})}catch(o){if(null==o.hash)throw o;throw ha("Parse Error: ".concat(o.message.split("\n")[3]),ob(o.hash.loc,t),r)}}var Na=nc;mb.parse=Na;var Oa={};function oc(a,t){var o,r,$,e=52,p=64-e-1,w=(1<<p)-1,M=w>>1,h=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,c=0,i=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(r=isNaN(t)?1:0,o=w):(o=Math.floor(Math.log(t)/Math.LN2),t*($=Math.pow(2,-o))<1&&(o--,$*=2),(t+=o+M>=1?h/$:h*Math.pow(2,1-M))*$>=2&&(o++,$/=2),o+M>=w?(r=0,o=w):o+M>=1?(r=(t*$-1)*Math.pow(2,e),o+=M):(r=t*Math.pow(2,M-1)*Math.pow(2,e),o=0));e>=8;a[0+c]=255&r,c+=1,r/=256,e-=8);for(o=o<<e|r,p+=e;p>0;a[0+c]=255&o,c+=1,o/=256,p-=8);a[0+c-1]|=128*i}Object.defineProperty(Oa,"__esModule",{value:!0});var pc=oc;Oa.write=pc;var K={};function Z(r){return tc(r)||sc(r)||rc(r)||qc()}function qc(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function rc(r,$){if(r){if("string"==typeof r)return Pa(r,$);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(e):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?Pa(r,$):void 0}}function sc(r){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(r))return Array.from(r)}function tc(r){if(Array.isArray(r))return Pa(r)}function Pa(r,$){(null==$||$>r.length)&&($=r.length);for(var e=0,t=new Array($);e<$;e++)t[e]=r[e];return t}var uc=K&&K.__importStar||function(r){if(r&&r.__esModule)return r;var $={};if(null!=r)for(var e in r)Object.hasOwnProperty.call(r,e)&&($[e]=r[e]);return $.default=r,$};Object.defineProperty(K,"__esModule",{value:!0});var vc=uc(Oa),pb=[0,97,115,109];K.MAGIC=pb;var qb=[1,0,0,0];K.WASM_VERSION=qb;var ya=1e-5;K.EPSILON=ya;var ia={TYPE:1,IMPORT:2,FUNC:3,MEMORY:5,GLOBAL:6,EXPORT:7,CODE:10};K.SECTION=ia;var rb={FUNC:0,TABLE:1,MEMORY:2,GLOBAL:3};K.EXPORT_TYPE=rb;var q={block:function(r){return[2,r]},loop:function(r){return[3,r]},if:function(r){return[4,r]},else:5,end:11,br_if:function(r){return[13].concat(Z(aa(r)))},call:function(r){return[16].concat(Z(aa(r)))},drop:26,select:27,local_get:function(r){return[32].concat(Z(aa(r)))},local_set:function(r){return[33].concat(Z(aa(r)))},local_tee:function(r){return[34].concat(Z(aa(r)))},global_get:function(r){return[35].concat(Z(aa(r)))},global_set:function(r){return[36].concat(Z(aa(r)))},f64_load:function(r,$){return[43].concat(Z(aa(r)),Z(aa($)))},f64_store:function(r,$){return[57].concat(Z(aa(r)),Z(aa($)))},i32_const:function(r){return[65].concat(Z(wb(r)))},f64_const:function(r){return[68].concat(Z(vb(r)))},i32_eqz:69,i32_ne:71,i32_lt_s:72,i32_lt_u:73,i32_gt_s:74,i32_le_s:76,i32_le_u:77,i32_ge_s:78,f64_eq:97,f64_ne:98,f64_lt:99,f64_gt:100,f64_le:101,f64_ge:102,i32_add:106,i32_sub:107,i32_mul:108,i32_and:113,i32_or:114,i64_rem_s:129,i64_and:131,i64_or:132,f64_abs:153,f64_neg:154,f64_ceil:155,f64_floor:156,f64_sqrt:159,f64_add:160,f64_sub:161,f64_mul:162,f64_div:163,f64_min:164,f64_max:165,i32_trunc_f64_s:170,i64_trunc_s_f64:176,f64_convert_i64_s:185,f64_convert_i32_s:183};K.op=q;var H={i32:127,i64:126,f32:125,f64:124};K.VAL_TYPE=H;var Qa={const:0,var:1};K.MUTABILITY=Qa;var ba={void:64,i32:127,i64:126,f32:125,f64:124};K.BLOCK=ba;var sb=96;K.FUNCTION_TYPE=sb;var wc=2;K.MEMORY_IDX=wc;var tb=3;K.GLOBAL_TYPE=tb;var ub=0;K.TYPE_IDX=ub;var oa=[q.f64_abs].concat(Z(q.f64_const(ya)),[q.f64_lt]);K.IS_ZEROISH=oa;var ca=[q.f64_abs].concat(Z(q.f64_const(ya)),[q.f64_gt]);function vb(r){var $=new Uint8Array(8);return vc.write($,r),$}K.IS_NOT_ZEROISH=ca;var xc=vb;K.encodef64=xc;var pa=function(r){return[r.length].concat(r.split("").map(function(r){return r.charCodeAt(0)}))};function aa(r){var $=[];do{var e=127&r;0!==(r>>>=7)&&(e|=128),$.push(e)}while(0!==r);return $}K.encodeString=pa;var la=aa;function wb(r){for(var $=[],e=0,t=Math.ceil(Math.log2(Math.abs(r))),o=r<0,n=!0;n;)e=127&r,r>>=7,o&&(r|=-(1<<t-7)),0==r&&0==(64&e)||-1==r&&64==(64&e)?n=!1:e|=128,$.push(e);return $}K.unsignedLEB128=la;var yc=wb;K.signedLEB128=yc;var ua=function(r){return aa(r.length).concat(r)};K.encodeFlatVector=ua;var Ra=function(r){return aa(r.length).concat(ta(r))};function zc(r,$){if(0===$.length)return[];var e=ua(Ra($));return e.unshift(r),e}K.encodeNestedVector=Ra;var ja=zc;K.encodeSection=ja;var qa={};Object.defineProperty(qa,"__esModule",{value:!0});var Ac=1e-5,Bc={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,atan2:Math.atan2,rand:function(a){return Math.random()*a},pow:Math.pow,log:Math.log,log10:Math.log10,exp:Math.exp,sigmoid:function(a,t){var $=1+Math.exp(-a*t);return Math.abs($)>Ac?1/$:0}},Cc=Bc;qa.default=Cc;var za={};Object.defineProperty(za,"__esModule",{value:!0});var Dc=65536,Ec=8,Fc=2,xb=1048576;za.MAX_LOOP_COUNT=xb;var Aa=8388608;za.BUFFER_SIZE=Aa;var Sa=Math.ceil(Aa*Ec*Fc/Dc);za.WASM_MEMORY_SIZE=Sa;var yb={};function G(n){return Jc(n)||Ic(n)||Hc(n)||Gc()}function Gc(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function Hc(n,$){if(n){if("string"==typeof n)return Ta(n,$);var e=Object.prototype.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(e):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?Ta(n,$):void 0}}function Ic(n){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(n))return Array.from(n)}function Jc(n){if(Array.isArray(n))return Ta(n)}function Ta(n,$){(null==$||$>n.length)&&($=n.length);for(var e=0,r=new Array($);e<$;e++)r[e]=n[e];return r}Object.defineProperty(yb,"__esModule",{value:!0});var va={sqr:{args:[H.f64],returns:[H.f64],binary:[].concat(G(q.local_get(0)),G(q.local_get(0)),[q.f64_mul])},bor:{args:[H.f64,H.f64],returns:[H.f64],binary:[].concat(G(q.local_get(0)),G(ca),G(q.local_get(1)),G(ca),[q.i32_or],G(q.i32_const(0)),[q.i32_ne,q.f64_convert_i32_s])},band:{args:[H.f64,H.f64],returns:[H.f64],binary:[].concat(G(q.local_get(0)),G(ca),G(q.local_get(1)),G(ca),[q.i32_and],G(q.i32_const(0)),[q.i32_ne,q.f64_convert_i32_s])},sign:{args:[H.f64],returns:[H.f64],binary:[].concat(G(q.f64_const(0)),G(q.local_get(0)),[q.f64_lt],G(q.local_get(0)),G(q.f64_const(0)),[q.f64_lt,q.i32_sub,q.f64_convert_i32_s])},mod:{args:[H.f64,H.f64],returns:[H.f64],binary:[].concat(G(q.local_get(1)),G(q.f64_const(0)),[q.f64_ne],G(q.if(ba.f64)),G(q.local_get(0)),[q.i64_trunc_s_f64],G(q.local_get(1)),[q.i64_trunc_s_f64,q.i64_rem_s,q.f64_convert_i64_s,q.else],G(q.f64_const(0)),[q.end])},bitwiseOr:{args:[H.f64,H.f64],returns:[H.f64],binary:[].concat(G(q.local_get(0)),[q.i64_trunc_s_f64],G(q.local_get(1)),[q.i64_trunc_s_f64,q.i64_or,q.f64_convert_i64_s])},bitwiseAnd:{args:[H.f64,H.f64],returns:[H.f64],binary:[].concat(G(q.local_get(0)),[q.i64_trunc_s_f64],G(q.local_get(1)),[q.i64_trunc_s_f64,q.i64_and,q.f64_convert_i64_s])},div:{args:[H.f64,H.f64],returns:[H.f64],localVariables:[H.i32],binary:[].concat(G(q.local_get(1)),G(q.f64_const(0)),[q.f64_ne],G(q.if(ba.f64)),G(q.local_get(0)),G(q.local_get(1)),[q.f64_div,q.else],G(q.f64_const(0)),[q.end])},_getBufferIndex:{args:[H.f64],returns:[H.i32],localVariables:[H.f64,H.i32],binary:[].concat(G(q.f64_const(ya)),G(q.local_get(0)),[q.f64_add],G(q.local_tee(1)),[q.i32_trunc_f64_s],G(q.local_set(2)),G(q.i32_const(-1)),G(q.local_get(2)),G(q.i32_const(8)),[q.i32_mul],G(q.local_get(2)),G(q.i32_const(0)),[q.i32_lt_s],G(q.local_get(2)),G(q.i32_const(Aa-1)),[q.i32_gt_s,q.i32_or,q.select])}};yb.localFuncMap=va;var Ba={};function Kc(r,$){return Nc(r)||Mc(r,$)||zb(r,$)||Lc()}function Lc(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function Mc(r,$){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(r)){var a=[],o=!0,e=!1,n=void 0;try{for(var t,_=r[Symbol.iterator]();!(o=(t=_.next()).done)&&(a.push(t.value),!$||a.length!==$);o=!0);}catch(c){e=!0,n=c}finally{try{o||null==_.return||_.return()}finally{if(e)throw n}}return a}}function Nc(r){if(Array.isArray(r))return r}function z(r){return Qc(r)||Pc(r)||zb(r)||Oc()}function Oc(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function zb(r,$){if(r){if("string"==typeof r)return Ua(r,$);var a=Object.prototype.toString.call(r).slice(8,-1);return"Object"===a&&r.constructor&&(a=r.constructor.name),"Map"===a||"Set"===a?Array.from(a):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?Ua(r,$):void 0}}function Pc(r){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(r))return Array.from(r)}function Qc(r){if(Array.isArray(r))return Ua(r)}function Ua(r,$){(null==$||$>r.length)&&($=r.length);for(var a=0,o=new Array($);a<$;a++)o[a]=r[a];return o}var Rc=Ba&&Ba.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ba,"__esModule",{value:!0});var Ab=Rc(qa);function Y(r,$){var a,o,e;switch(r.type){case"SCRIPT":var n=r.body.map(function(r,a){return[].concat(z(Y(r,$)),[q.drop])});return ta(n);case"EXPRESSION_BLOCK":return Va(r.body,$);case"BINARY_EXPRESSION":var t=Y(r.left,$),_=Y(r.right,$),c={"+":[q.f64_add],"-":[q.f64_sub],"*":[q.f64_mul],"/":$.resolveFunc("div"),"%":$.resolveFunc("mod"),"|":$.resolveFunc("bitwiseOr"),"&":$.resolveFunc("bitwiseAnd"),"^":$.resolveFunc("pow"),"==":[q.f64_sub].concat(z(oa),[q.f64_convert_i32_s]),"!=":[q.f64_sub].concat(z(ca),[q.f64_convert_i32_s]),"<":[q.f64_lt,q.f64_convert_i32_s],">":[q.f64_gt,q.f64_convert_i32_s],"<=":[q.f64_le,q.f64_convert_i32_s],">=":[q.f64_ge,q.f64_convert_i32_s]}[r.operator];if(null==c)throw ea("Unknown binary expression operator ".concat(r.operator),r.loc,$.rawSource);return[].concat(z(t),z(_),z(c));case"CALL_EXPRESSION":var i=r.callee.value,v=r.arguments,l=function(a){if(v.length<a)throw ha("Too few arguments passed to `".concat(i,"()`. Expected ").concat(a," but only got ").concat(v.length,"."),r.loc,$.rawSource);if(v.length>a)throw ha("Too many arguments passed to `".concat(i,"()`. Expected ").concat(a," but got ").concat(v.length,"."),v[a].loc,$.rawSource)};switch(i){case"exec2":return l(2),Va(r.arguments,$);case"exec3":return l(3),Va(r.arguments,$);case"if":l(3);var V=Kc(r.arguments,3);return Uc(V[0],V[1],V[2],$);case"while":return l(1),Sc(r.arguments[0],$);case"loop":return l(2),Tc(r.arguments[0],r.arguments[1],$);case"megabuf":case"gmegabuf":l(1);var s=$.resolveLocal(H.i32);return[].concat(z(Y(r.arguments[0],$)),z(null!==(a=$.resolveFunc("_getBufferIndex"))&&void 0!==a?a:[]),z(q.local_tee(s)),z(q.i32_const(-1)),[q.i32_ne],z(q.if(ba.f64)),z(q.local_get(s)),z(q.f64_load(3,Cb(i))),[q.else],z(q.f64_const(0)),[q.end]);case"assign":l(2);var W=r.arguments[0];if("IDENTIFIER"!=W.type)throw ha("Expected the first argument of `assign()` to be an identifier.",W.loc,$.rawSource);var u=$.resolveVar(W.value);return[].concat(z(Y(r.arguments[1],$)),z(q.global_set(u)),z(q.global_get(u)));}var g=ta(r.arguments.map(function(r){return Y(r,$)}));switch(i){case"abs":return l(1),[].concat(z(g),[q.f64_abs]);case"sqrt":return l(1),[].concat(z(g),[q.f64_abs,q.f64_sqrt]);case"int":return l(1),[].concat(z(g),[q.f64_floor]);case"min":return l(2),[].concat(z(g),[q.f64_min]);case"max":return l(2),[].concat(z(g),[q.f64_max]);case"above":return l(2),[].concat(z(g),[q.f64_gt,q.f64_convert_i32_s]);case"below":return l(2),[].concat(z(g),[q.f64_lt,q.f64_convert_i32_s]);case"equal":return l(2),[].concat(z(g),[q.f64_sub],z(oa),[q.f64_convert_i32_s]);case"bnot":return l(1),[].concat(z(g),z(oa),[q.f64_convert_i32_s]);case"floor":return l(1),[].concat(z(g),[q.f64_floor]);case"ceil":return l(1),[].concat(z(g),[q.f64_ceil]);}var d=$.resolveFunc(i);if(null==d||i.startsWith("_"))throw ha("\"".concat(i,"\" is not defined."),r.callee.loc,$.rawSource);if(null!=Ab.default[i])l(Ab.default[i].length);else{if(null==va[i])throw ea("Missing arity information for the function `".concat(i,"()`"),r.callee.loc,$.rawSource);l(va[i].args.length)}return[].concat(z(g),z(d));case"ASSIGNMENT_EXPRESSION":var m=r.left,p=Y(r.right,$),b=Vc(r,$);if("IDENTIFIER"===m.type){var y=$.resolveVar(m.value),f=q.global_get(y),A=q.global_set(y);return null===b?[].concat(z(p),z(A),z(f)):[].concat(z(f),z(p),z(b),z(A),z(f))}if("CALL_EXPRESSION"!==m.type)throw ea("Unexpected left hand side type for assignment: ".concat(m.type),r.loc,$.rawSource);var C=$.resolveLocal(H.i32);if(1!==m.arguments.length)throw ha("Expected 1 argument when assinging to a buffer but got ".concat(m.arguments.length,"."),0===m.arguments.length?m.loc:m.arguments[1].loc,$.rawSource);var E=m.callee.value;if("gmegabuf"!==E&&"megabuf"!==E)throw ha("The only function calls which may be assigned to are `gmegabuf()` and `megabuf()`.",m.callee.loc,$.rawSource);var h=Cb(E);if(null===b){var S=$.resolveLocal(H.i32),I=$.resolveLocal(H.f64);return[].concat(z(p),z(q.local_set(I)),z(Y(m.arguments[0],$)),z(null!==(o=$.resolveFunc("_getBufferIndex"))&&void 0!==o?o:[]),z(q.local_tee(S)),z(q.i32_const(0)),[q.i32_lt_s],z(q.if(ba.f64)),z(q.f64_const(0)),[q.else],z(q.local_get(S)),z(q.local_tee(C)),z(q.local_get(I)),z(q.f64_store(3,h)),z(q.local_get(I)),[q.end])}var w=$.resolveLocal(H.i32),L=$.resolveLocal(H.i32),O=$.resolveLocal(H.f64),T=$.resolveLocal(H.f64);return[].concat(z(p),z(q.local_set(O)),z(Y(m.arguments[0],$)),z(null!==(e=$.resolveFunc("_getBufferIndex"))&&void 0!==e?e:[]),z(q.local_tee(w)),z(q.i32_const(-1)),[q.i32_ne],z(q.local_tee(L)),z(q.if(ba.f64)),z(q.local_get(w)),z(q.f64_load(3,h)),[q.else],z(q.f64_const(0)),[q.end],z(q.local_get(O)),z(b),z(q.local_tee(T)),z(q.local_get(L)),z(q.if(ba.void)),z(q.local_get(w)),z(q.local_get(T)),z(q.f64_store(3,h)),[q.end]);case"LOGICAL_EXPRESSION":var U=Y(r.left,$),R=Y(r.right,$),x={"&&":{comparison:oa,shortCircutValue:0},"||":{comparison:ca,shortCircutValue:1}}[r.operator];if(null==x)throw ea("Unknown logical expression operator ".concat(r.operator),r.loc,$.rawSource);var F=x.comparison,N=x.shortCircutValue;return[].concat(z(U),z(F),z(q.if(ba.f64)),z(q.f64_const(N)),[q.else],z(R),z(ca),[q.f64_convert_i32_s,q.end]);case"UNARY_EXPRESSION":var B=Y(r.value,$),P={"-":[q.f64_neg],"+":[],"!":[].concat(z(oa),[q.f64_convert_i32_s])}[r.operator];if(null==P)throw ea("Unknown logical unary operator ".concat(r.operator),r.loc,$.rawSource);return[].concat(z(B),z(P));case"IDENTIFIER":var k=r.value;return q.global_get($.resolveVar(k));case"NUMBER_LITERAL":return q.f64_const(r.value);default:throw ea("Unknown AST node type ".concat(r.type),r.loc,$.rawSource);}}var Bb=Y;function Va(r,$){var a=r.map(function(r,a){return Y(r,$)});return ta(fb(a,[q.drop]))}function Sc(r,$){var a=Y(r,$),o=$.resolveLocal(H.i32);return[].concat(z(q.i32_const(0)),z(q.local_set(o)),z(q.loop(ba.void)),z(q.local_get(o)),z(q.i32_const(1)),[q.i32_add],z(q.local_tee(o)),z(q.i32_const(xb)),[q.i32_lt_u],z(a),z(ca),[q.i32_and],z(q.br_if(0)),[q.end],z(q.f64_const(0)))}function Tc(r,$,a){var o=Y($,a),e=a.resolveLocal(H.i32);return[].concat(z(q.block(ba.void)),z(Y(r,a)),[q.i32_trunc_f64_s],z(q.local_tee(e)),z(q.i32_const(0)),[q.i32_le_s],z(q.br_if(1)),z(q.loop(ba.void)),z(o),[q.drop],z(q.local_get(e)),z(q.i32_const(1)),[q.i32_sub],z(q.local_tee(e)),z(q.i32_const(0)),[q.i32_ne],z(q.br_if(0)),[q.end,q.end],z(q.f64_const(0)))}function Uc(r,$,a,o){return[].concat(z(Y(r,o)),z(ca),z(q.if(ba.f64)),z(Y($,o)),[q.else],z(Y(a,o)),[q.end])}function Cb(r){switch(r){case"gmegabuf":return 8*Aa;case"megabuf":return 0;}}function Vc(r,$){var a={"+=":[q.f64_add],"-=":[q.f64_sub],"*=":[q.f64_mul],"/=":[q.f64_div],"%=":$.resolveFunc("mod"),"=":null}[r.operator];if(void 0===a)throw ea("Unknown assignment operator \"".concat(r.operator,"\""),r.loc,$.rawSource);return a}Ba.emit=Bb;var ra={};function J(r){return Yc(r)||Xc(r)||Db(r)||Wc()}function Wc(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function Xc(r){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(r))return Array.from(r)}function Yc(r){if(Array.isArray(r))return Wa(r)}function wa(r,e){return _c(r)||$c(r,e)||Db(r,e)||Zc()}function Zc(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function Db(r,e){if(r){if("string"==typeof r)return Wa(r,e);var a=Object.prototype.toString.call(r).slice(8,-1);return"Object"===a&&r.constructor&&(a=r.constructor.name),"Map"===a||"Set"===a?Array.from(a):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?Wa(r,e):void 0}}function Wa(r,e){(null==e||e>r.length)&&(e=r.length);for(var a=0,n=new Array(e);a<e;a++)n[a]=r[a];return n}function $c(r,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(r)){var a=[],n=!0,$=!1,o=void 0;try{for(var t,d=r[Symbol.iterator]();!(n=(t=d.next()).done)&&(a.push(t.value),!e||a.length!==e);n=!0);}catch(i){$=!0,o=i}finally{try{n||null==d.return||d.return()}finally{if($)throw o}}return a}}function _c(r){if(Array.isArray(r))return r}var ad=ra&&ra.__importDefault||function(r){return r&&r.__esModule?r:{default:r}},bd=ra&&ra.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(null!=r)for(var a in r)Object.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e.default=r,e};Object.defineProperty(ra,"__esModule",{value:!0});var cd=ad(qa),Xa=bd(ga);function dd(r){var e=r.pools,a=r.functions,n=r.eelVersion,$=void 0===n?2:n,o=r.preParsed,t=void 0!==o&&o;if(Object.keys(e).includes("shims"))throw new Error("You may not name a pool \"shims\". \"shims\" is reserved for injected JavaScript functions.");var d=[];Object.entries(e).forEach(function(r){var e=wa(r,2),a=e[0];e[1].forEach(function(r){d.push([a,r])})});var i=new Xa.ScopedIdMap;d.forEach(function(r){var e=wa(r,2),a=e[0],n=e[1];i.get(a,n)});var c=Object.entries(cd.default).map(function(r){var e=wa(r,2),a=e[0],n=e[1];return{args:new Array(n.length).fill(null).map(function(r){return H.f64}),returns:[H.f64],name:a}}),l=[],u=[];Object.entries(a).forEach(function(r){var a=wa(r,2),n=a[0],o=a[1],d=o.pool,v=o.code;if(null==e[d]){var s=Object.keys(e);if(0===s.length)throw new Error("The function \"".concat(n,"\" was declared as using a variable ")+"pool named \"".concat(d,"\" but no pools were defined."));throw new Error("The function \"".concat(n,"\" was declared as using a variable ")+"pool named \"".concat(d,"\" which is not among the variable ")+"pools defined. The defined variable pools are: "+"".concat(Xa.formatList(s),"."))}var _=t?v:Na(v);if("string"==typeof _)throw new Error("Got passed unparsed code without setting the preParsed flag");if("SCRIPT"!==_.type)throw new Error("Invalid AST");if(0!==_.body.length){var D=[],X={resolveVar:function(r){return /^reg\d\d$/.test(r)?i.get(null,r):i.get(d,r)},resolveLocal:function(r){return D.push(r),D.length-1},resolveFunc:function(r){var e=c.findIndex(function(e){return e.name===r});if(-1!==e){var a=q.call(e);return"rand"===r&&1===$?[].concat(J(a),[q.f64_floor]):a}if(null==va[r])return null;var n=l.indexOf(r);return-1===n&&(l.push(r),n=l.length-1),q.call(n+c.length)},rawSource:v},f=Bb(_,X);u.push({binary:f,exportName:n,args:[],returns:[],localVariables:D})}});var v=l.map(function(r){var e=va[r];if(null==e)throw new Error("Undefined local function \"".concat(r,"\""));return e}),s=function(r){return[].concat(J(r.args),["|"],J(r.returns)).join("-")},_=[],D=new Map;function X(r){var e=s(r),a=D.get(e);if(null==a)throw new Error("Failed to get a type index for key ".concat(e));return a}[].concat(J(c),J(v),u).forEach(function(r){var e=s(r);D.has(e)||(_.push([sb].concat(J(ua(r.args)),J(ua(r.returns)))),D.set(e,_.length-1))});var f=[].concat(J(d.map(function(r){var e=wa(r,2),a=e[0],n=e[1];return[].concat(J(pa(a)),J(pa(n)),[tb,H.f64,Qa.var])})),J(c.map(function(r,e){var a=X(r);return[].concat(J(pa("shims")),J(pa(r.name)),[ub].concat(J(la(a))))}))),m=[].concat(J(v),u).map(function(r){var e=X(r);return la(e)}),y=[[1].concat(J(la(Sa)),J(la(Sa)))],p=i.size()-d.length,g=Xa.times(p,function(){return[H.f64,Qa.var].concat(J(q.f64_const(0)),[q.end])}),b=[].concat(u).map(function(r,e){var a=e+c.length+v.length;return[].concat(J(pa(r.exportName)),[rb.FUNC],J(la(a)))}),A=[].concat(J(v),u).map(function(r){var e,a=(null!==(e=r.localVariables)&&void 0!==e?e:[]).map(function(r){return[].concat(J(la(1)),[r])});return ua([].concat(J(Ra(a)),J(r.binary),[q.end]))});return new Uint8Array([].concat(J(pb),J(qb),J(ja(ia.TYPE,_)),J(ja(ia.IMPORT,f)),J(ja(ia.FUNC,m)),J(ja(ia.MEMORY,y)),J(ja(ia.GLOBAL,g)),J(ja(ia.EXPORT,b)),J(ja(ia.CODE,A))))}var Ya=dd;ra.compileModule=Ya;var Ca={};function ed(r,e){return id(r)||hd(r,e)||gd(r,e)||fd()}function fd(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function gd(r,e){if(r){if("string"==typeof r)return Eb(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?Eb(r,e):void 0}}function Eb(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,a=new Array(e);t<e;t++)a[t]=r[t];return a}function hd(r,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(r)){var t=[],a=!0,n=!1,o=void 0;try{for(var u,l=r[Symbol.iterator]();!(a=(u=l.next()).done)&&(t.push(u.value),!e||t.length!==e);a=!0);}catch($){n=!0,o=$}finally{try{a||null==l.return||l.return()}finally{if(n)throw o}}return t}}function id(r){if(Array.isArray(r))return r}function Fb(r,e,t,a,n,o,u){try{var l=r[o](u),$=l.value}catch(i){return void t(i)}l.done?e($):Promise.resolve($).then(a,n)}function jd(r){return function(){var e=this,t=arguments;return new Promise(function(a,n){var o=r.apply(e,t);function u(r){Fb(o,a,n,u,l,"next",r)}function l(r){Fb(o,a,n,u,l,"throw",r)}u(void 0)})}}var kd=Ca&&Ca.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ca,"__esModule",{value:!0});var ld=kd(qa);function md(r){return nd.apply(this,arguments)}function nd(){return(nd=jd(regeneratorRuntime.mark(function r(e){var t,a,n,o,u,l,$,i;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return t=e.pools,a=e.functions,n=e.eelVersion,o=void 0===n?2:n,u={},Object.entries(t).forEach(function(r){var e=ed(r,2),t=e[0],a=e[1];u[t]=new Set(Object.keys(a))}),l=Ya({pools:u,functions:a,eelVersion:o}),r.next=6,WebAssembly.compile(l);case 6:return $=r.sent,i=Object.assign(Object.assign({},t),{shims:ld.default}),r.next=10,WebAssembly.instantiate($,i);case 10:return r.abrupt("return",r.sent);case 11:case"end":return r.stop();}},r)}))).apply(this,arguments)}var Gb=md;Ca.loadModule=Gb;var fa={},od=fa&&fa.__importDefault||function($){return $&&$.__esModule?$:{default:$}};Object.defineProperty(fa,"__esModule",{value:!0});var pd=Na;fa.parse=pd;var qd=Ya;fa.compileModule=qd;var rd=od(qa),sd=rd.default;fa.shims=sd;var td=Gb;fa.loadModule=td;if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=fa}else if(typeof define==="function"&&define.amd){define(function(){return fa})}})(); |
@@ -5,19 +5,19 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
var fs_1 = __importDefault(require("fs")); | ||
var path_1 = __importDefault(require("path")); | ||
var compiler_1 = require("../compiler"); | ||
var errorUtils_1 = require("../errorUtils"); | ||
var DIR = path_1["default"].join(__dirname, "../../fixtures/errors"); | ||
var testCases = fs_1["default"].readdirSync(DIR); | ||
testCases.forEach(function (filename) { | ||
var testFunc = filename.startsWith("only.") ? test.only : test; | ||
var testName = filename.replace(/^only\./, ""); | ||
testFunc("" + testName, function () { | ||
var eel = fs_1["default"].readFileSync(path_1["default"].join(DIR, filename), { encoding: "utf8" }); | ||
var compilerError = null; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const compiler_1 = require("../compiler"); | ||
const errorUtils_1 = require("../errorUtils"); | ||
const DIR = path_1.default.join(__dirname, "../../fixtures/errors"); | ||
const testCases = fs_1.default.readdirSync(DIR); | ||
testCases.forEach((filename) => { | ||
const testFunc = filename.startsWith("only.") ? test.only : test; | ||
const testName = filename.replace(/^only\./, ""); | ||
testFunc(`${testName}`, () => { | ||
const eel = fs_1.default.readFileSync(path_1.default.join(DIR, filename), { encoding: "utf8" }); | ||
let compilerError = null; | ||
try { | ||
compiler_1.compileModule({ | ||
pools: { main: new Set() }, | ||
functions: { run: { pool: "main", code: eel } } | ||
functions: { run: { pool: "main", code: eel } }, | ||
}); | ||
@@ -36,9 +36,14 @@ } | ||
}); | ||
describe("printLoc", function () { | ||
test("One line", function () { | ||
var frame = errorUtils_1.printLoc({ first_line: 1, first_column: 6, last_line: 1, last_column: 11 }, "Hello there this is a string"); | ||
expect("\n" + frame + "\n").toMatchInlineSnapshot("\n \"\n > 1 | Hello there this is a string\n | ^^^^^\n \"\n "); | ||
describe("printLoc", () => { | ||
test("One line", () => { | ||
const frame = errorUtils_1.printLoc({ first_line: 1, first_column: 6, last_line: 1, last_column: 11 }, "Hello there this is a string"); | ||
expect("\n" + frame + "\n").toMatchInlineSnapshot(` | ||
" | ||
> 1 | Hello there this is a string | ||
| ^^^^^ | ||
" | ||
`); | ||
}); | ||
test("One line within multiple lines", function () { | ||
var frame = errorUtils_1.printLoc({ first_line: 4, first_column: 6, last_line: 4, last_column: 11 }, [ | ||
test("One line within multiple lines", () => { | ||
const frame = errorUtils_1.printLoc({ first_line: 4, first_column: 6, last_line: 4, last_column: 11 }, [ | ||
"Hello there this is a string", | ||
@@ -52,6 +57,13 @@ "Hello there this is a string", | ||
].join("\n")); | ||
expect("\n" + frame + "\n").toMatchInlineSnapshot("\n \"\n 3 | Hello there this is a string\n > 4 | Hello there this is a string\n | ^^^^^\n 5 | Hello there this is a string\n \"\n "); | ||
expect("\n" + frame + "\n").toMatchInlineSnapshot(` | ||
" | ||
3 | Hello there this is a string | ||
> 4 | Hello there this is a string | ||
| ^^^^^ | ||
5 | Hello there this is a string | ||
" | ||
`); | ||
}); | ||
test("One line within multiple lines + 2 lines of context", function () { | ||
var frame = errorUtils_1.printLoc({ first_line: 4, first_column: 6, last_line: 4, last_column: 11 }, [ | ||
test("One line within multiple lines + 2 lines of context", () => { | ||
const frame = errorUtils_1.printLoc({ first_line: 4, first_column: 6, last_line: 4, last_column: 11 }, [ | ||
"Hello there this is a string", | ||
@@ -65,10 +77,24 @@ "Hello there this is a string", | ||
].join("\n"), 2); | ||
expect("\n" + frame + "\n").toMatchInlineSnapshot("\n \"\n 2 | Hello there this is a string\n 3 | Hello there this is a string\n > 4 | Hello there this is a string\n | ^^^^^\n 5 | Hello there this is a string\n 6 | Hello there this is a string\n \"\n "); | ||
expect("\n" + frame + "\n").toMatchInlineSnapshot(` | ||
" | ||
2 | Hello there this is a string | ||
3 | Hello there this is a string | ||
> 4 | Hello there this is a string | ||
| ^^^^^ | ||
5 | Hello there this is a string | ||
6 | Hello there this is a string | ||
" | ||
`); | ||
}); | ||
test("Multiple lines", function () { | ||
var frame = errorUtils_1.printLoc({ first_line: 1, first_column: 6, last_line: 2, last_column: 11 }, "Hello there this is a string\nHello there this is a string"); | ||
expect("\n" + frame + "\n").toMatchInlineSnapshot("\n \"\n > 1 | Hello there this is a string\n > 2 | Hello there this is a string\n \"\n "); | ||
test("Multiple lines", () => { | ||
const frame = errorUtils_1.printLoc({ first_line: 1, first_column: 6, last_line: 2, last_column: 11 }, "Hello there this is a string\nHello there this is a string"); | ||
expect("\n" + frame + "\n").toMatchInlineSnapshot(` | ||
" | ||
> 1 | Hello there this is a string | ||
> 2 | Hello there this is a string | ||
" | ||
`); | ||
}); | ||
test("Multiple lines within multiple lines", function () { | ||
var frame = errorUtils_1.printLoc({ first_line: 3, first_column: 6, last_line: 5, last_column: 11 }, [ | ||
test("Multiple lines within multiple lines", () => { | ||
const frame = errorUtils_1.printLoc({ first_line: 3, first_column: 6, last_line: 5, last_column: 11 }, [ | ||
"Hello there this is a string", | ||
@@ -82,5 +108,13 @@ "Hello there this is a string", | ||
].join("\n")); | ||
expect("\n" + frame + "\n").toMatchInlineSnapshot("\n \"\n 2 | Hello there this is a string\n > 3 | Hello there this is a string\n > 4 | Hello there this is a string\n > 5 | Hello there this is a string\n 6 | Hello there this is a string\n \"\n "); | ||
expect("\n" + frame + "\n").toMatchInlineSnapshot(` | ||
" | ||
2 | Hello there this is a string | ||
> 3 | Hello there this is a string | ||
> 4 | Hello there this is a string | ||
> 5 | Hello there this is a string | ||
6 | Hello there this is a string | ||
" | ||
`); | ||
}); | ||
}); | ||
//# sourceMappingURL=errorsUtils.test.js.map |
@@ -1,286 +0,186 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
const { loadModule } = require("../loader"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const MILKDROP_GLOBALS = require("../../tools/milkdropGlobals"); | ||
const { parse } = require("../parser"); | ||
const { default: testCases } = require("../../tools/testCases"); | ||
test("Minimal example", async () => { | ||
// Initialize global values avaliable to your EEL scripts (and JS). | ||
const globals = { | ||
x: new WebAssembly.Global({ value: "f64", mutable: true }, 0), | ||
y: new WebAssembly.Global({ value: "f64", mutable: true }, 0), | ||
}; | ||
// Build (compile/initialize) the Wasm module | ||
const mod = await loadModule({ | ||
pools: { main: globals }, | ||
functions: { | ||
ten: { pool: "main", code: "x = 10" }, | ||
setXToY: { pool: "main", code: "x = y" }, | ||
}, | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
// Assert that x starts as zero | ||
expect(globals.x.value).toBe(0); | ||
// Run a compiled EEL script and assert that it ran | ||
mod.exports.ten(); | ||
expect(globals.x.value).toBe(10); | ||
// Change a global value from JS, and assert that EEL code uses the new value | ||
globals.y.value = 5; | ||
mod.exports.setXToY(); | ||
expect(globals.x.value).toBe(5); | ||
}); | ||
test("parse", () => { | ||
expect(parse("1;")).toMatchInlineSnapshot(` | ||
Object { | ||
"body": Array [ | ||
Object { | ||
"loc": Object { | ||
"first_column": 0, | ||
"first_line": 1, | ||
"last_column": 1, | ||
"last_line": 1, | ||
}, | ||
"type": "NUMBER_LITERAL", | ||
"value": 1, | ||
}, | ||
], | ||
"loc": Object { | ||
"first_column": 0, | ||
"first_line": 1, | ||
"last_column": 2, | ||
"last_line": 1, | ||
}, | ||
"type": "SCRIPT", | ||
} | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var _this = this; | ||
var loadModule = require("../loader").loadModule; | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var MILKDROP_GLOBALS = require("../../tools/milkdropGlobals"); | ||
var parse = require("../parser").parse; | ||
var testCases = require("../../tools/testCases")["default"]; | ||
test("Minimal example", function () { return __awaiter(_this, void 0, void 0, function () { | ||
var globals, mod; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
globals = { | ||
x: new WebAssembly.Global({ value: "f64", mutable: true }, 0), | ||
y: new WebAssembly.Global({ value: "f64", mutable: true }, 0) | ||
}; | ||
return [4 /*yield*/, loadModule({ | ||
pools: { main: globals }, | ||
functions: { | ||
ten: { pool: "main", code: "x = 10" }, | ||
setXToY: { pool: "main", code: "x = y" } | ||
} | ||
})]; | ||
case 1: | ||
mod = _a.sent(); | ||
// Assert that x starts as zero | ||
expect(globals.x.value).toBe(0); | ||
// Run a compiled EEL script and assert that it ran | ||
mod.exports.ten(); | ||
expect(globals.x.value).toBe(10); | ||
// Change a global value from JS, and assert that EEL code uses the new value | ||
globals.y.value = 5; | ||
mod.exports.setXToY(); | ||
expect(globals.x.value).toBe(5); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test("parse", function () { | ||
expect(parse("1;")).toMatchInlineSnapshot("\n Object {\n \"body\": Array [\n Object {\n \"loc\": Object {\n \"first_column\": 0,\n \"first_line\": 1,\n \"last_column\": 1,\n \"last_line\": 1,\n },\n \"type\": \"NUMBER_LITERAL\",\n \"value\": 1,\n },\n ],\n \"loc\": Object {\n \"first_column\": 0,\n \"first_line\": 1,\n \"last_column\": 2,\n \"last_line\": 1,\n },\n \"type\": \"SCRIPT\",\n }\n "); | ||
`); | ||
}); | ||
describe("Small test cases", function () { | ||
testCases.forEach(function (testCase, i) { | ||
var _a = __read(testCase, 3), description = _a[0], expression = _a[1], expectedResult = _a[2]; | ||
describe("Small test cases", () => { | ||
testCases.forEach((testCase, i) => { | ||
const [description, expression, expectedResult] = testCase; | ||
// Hack: Set this number to the number of the test in order to isolate just one. | ||
var testFunction = i === -1 ? test.only : test; | ||
testFunction(i + ". " + description + ": \"" + expression + "\"", function () { return __awaiter(_this, void 0, void 0, function () { | ||
var x, g, mod; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
x = new WebAssembly.Global({ value: "f64", mutable: true }, 10); | ||
g = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
return [4 /*yield*/, loadModule({ | ||
pools: { main: { g: g, x: x } }, | ||
functions: { | ||
run: { pool: "main", code: expression } | ||
} | ||
})]; | ||
case 1: | ||
mod = _a.sent(); | ||
mod.exports.run(); | ||
expect(g.value).toBe(expectedResult); | ||
return [2 /*return*/]; | ||
} | ||
const testFunction = i === -1 ? test.only : test; | ||
testFunction(`${i}. ${description}: "${expression}"`, async () => { | ||
const x = new WebAssembly.Global({ value: "f64", mutable: true }, 10); | ||
const g = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
const mod = await loadModule({ | ||
pools: { main: { g, x } }, | ||
functions: { | ||
run: { pool: "main", code: expression }, | ||
}, | ||
}); | ||
}); }); | ||
mod.exports.run(); | ||
expect(g.value).toBe(expectedResult); | ||
}); | ||
}); | ||
}); | ||
// This | ||
test("Empty equations are not created", function () { return __awaiter(_this, void 0, void 0, function () { | ||
var mod; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, loadModule({ | ||
pools: { main: {} }, | ||
functions: { | ||
empty: { pool: "main", code: "" }, | ||
whiteSpace: { pool: "main", code: " \n\t " }, | ||
comment: { pool: "main", code: "// IGNORE THIS" }, | ||
hasCode: { pool: "main", code: "1" } | ||
} | ||
})]; | ||
case 1: | ||
mod = _a.sent(); | ||
expect(mod.exports.empty).toBe(undefined); | ||
expect(mod.exports.whiteSpace).toBe(undefined); | ||
expect(mod.exports.comment).toBe(undefined); | ||
expect(mod.exports.hasCode).not.toBe(undefined); | ||
return [2 /*return*/]; | ||
} | ||
test("Empty equations are not created", async () => { | ||
const mod = await loadModule({ | ||
pools: { main: {} }, | ||
functions: { | ||
empty: { pool: "main", code: "" }, | ||
whiteSpace: { pool: "main", code: " \n\t " }, | ||
comment: { pool: "main", code: "// IGNORE THIS" }, | ||
hasCode: { pool: "main", code: "1" }, | ||
}, | ||
}); | ||
}); }); | ||
describe("Scopes", function () { | ||
test("isolate variables", function () { return __awaiter(_this, void 0, void 0, function () { | ||
var ax, bx, mod; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
ax = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
bx = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
return [4 /*yield*/, loadModule({ | ||
pools: { | ||
a: { x: ax }, | ||
b: { x: bx } | ||
}, | ||
functions: { | ||
setInA: { pool: "a", code: "x = 10;" }, | ||
setInB: { pool: "b", code: "x = 20;" } | ||
} | ||
})]; | ||
case 1: | ||
mod = _a.sent(); | ||
expect(ax.value).toBe(0); | ||
expect(bx.value).toBe(0); | ||
mod.exports.setInA(); | ||
expect(ax.value).toBe(10); | ||
expect(bx.value).toBe(0); | ||
mod.exports.setInB(); | ||
expect(ax.value).toBe(10); | ||
expect(bx.value).toBe(20); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test("share reg variables", function () { return __awaiter(_this, void 0, void 0, function () { | ||
var g, mod; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
g = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
return [4 /*yield*/, loadModule({ | ||
pools: { | ||
a: {}, | ||
b: { g: g } | ||
}, | ||
functions: { | ||
setRegOne: { pool: "a", code: "reg01 = 10;" }, | ||
setRegNintyNine: { pool: "a", code: "reg99 = 10;" }, | ||
getRegOne: { pool: "b", code: "g = reg01;" }, | ||
getRegNintyNine: { pool: "b", code: "g = reg99;" } | ||
} | ||
})]; | ||
case 1: | ||
mod = _a.sent(); | ||
mod.exports.getRegOne(); | ||
expect(g.value).toBe(0); | ||
mod.exports.setRegOne(); | ||
mod.exports.getRegOne(); | ||
expect(g.value).toBe(10); | ||
mod.exports.getRegNintyNine(); | ||
expect(g.value).toBe(0); | ||
mod.exports.setRegNintyNine(); | ||
mod.exports.getRegNintyNine(); | ||
expect(g.value).toBe(10); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
expect(mod.exports.empty).toBe(undefined); | ||
expect(mod.exports.whiteSpace).toBe(undefined); | ||
expect(mod.exports.comment).toBe(undefined); | ||
expect(mod.exports.hasCode).not.toBe(undefined); | ||
}); | ||
describe("Invalid pool for function", function () { | ||
test("function pool is not among defined", function () { return __awaiter(_this, void 0, void 0, function () { | ||
var ax, bx, moduleOptions; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
ax = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
bx = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
moduleOptions = { | ||
pools: { | ||
a: { x: ax }, | ||
b: { x: bx } | ||
}, | ||
functions: { | ||
myInvalidFunction: { pool: "c", code: "x = 10;" } | ||
} | ||
}; | ||
return [4 /*yield*/, expect(loadModule(moduleOptions)).rejects.toEqual(new Error("The function \"myInvalidFunction\" was declared as using a variable pool named \"c\" which is not among the variable pools defined. The defined variable pools are: \"a\" and \"b\"."))]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
describe("Scopes", () => { | ||
test("isolate variables", async () => { | ||
const ax = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
const bx = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
const mod = await loadModule({ | ||
pools: { | ||
a: { x: ax }, | ||
b: { x: bx }, | ||
}, | ||
functions: { | ||
setInA: { pool: "a", code: "x = 10;" }, | ||
setInB: { pool: "b", code: "x = 20;" }, | ||
}, | ||
}); | ||
}); }); | ||
test("no function pools are defined", function () { return __awaiter(_this, void 0, void 0, function () { | ||
var moduleOptions; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
moduleOptions = { | ||
pools: {}, | ||
functions: { | ||
myInvalidFunction: { pool: "c", code: "x = 10;" } | ||
} | ||
}; | ||
return [4 /*yield*/, expect(loadModule(moduleOptions)).rejects.toEqual(new Error("The function \"myInvalidFunction\" was declared as using a variable pool named \"c\" but no pools were defined."))]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
expect(ax.value).toBe(0); | ||
expect(bx.value).toBe(0); | ||
mod.exports.setInA(); | ||
expect(ax.value).toBe(10); | ||
expect(bx.value).toBe(0); | ||
mod.exports.setInB(); | ||
expect(ax.value).toBe(10); | ||
expect(bx.value).toBe(20); | ||
}); | ||
test("share reg variables", async () => { | ||
const g = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
const mod = await loadModule({ | ||
pools: { | ||
a: {}, | ||
b: { g }, | ||
}, | ||
functions: { | ||
setRegOne: { pool: "a", code: "reg01 = 10;" }, | ||
setRegNintyNine: { pool: "a", code: "reg99 = 10;" }, | ||
getRegOne: { pool: "b", code: "g = reg01;" }, | ||
getRegNintyNine: { pool: "b", code: "g = reg99;" }, | ||
}, | ||
}); | ||
}); }); | ||
mod.exports.getRegOne(); | ||
expect(g.value).toBe(0); | ||
mod.exports.setRegOne(); | ||
mod.exports.getRegOne(); | ||
expect(g.value).toBe(10); | ||
mod.exports.getRegNintyNine(); | ||
expect(g.value).toBe(0); | ||
mod.exports.setRegNintyNine(); | ||
mod.exports.getRegNintyNine(); | ||
expect(g.value).toBe(10); | ||
}); | ||
}); | ||
test("Some actual equations", function () { return __awaiter(_this, void 0, void 0, function () { | ||
var globals, perFrame, perPixel, mod; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
globals = {}; | ||
MILKDROP_GLOBALS.forEach(function (name) { | ||
globals[name] = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
}); | ||
perFrame = fs.readFileSync(path.join(__dirname, "../../fixtures/youtube_broadcast_yourself_per_frame.eel"), { encoding: "utf8" }); | ||
perPixel = fs.readFileSync(path.join(__dirname, "../../fixtures/youtube_broadcast_yourself_per_pixel.eel"), { encoding: "utf8" }); | ||
return [4 /*yield*/, loadModule({ | ||
pools: { | ||
main: globals | ||
}, | ||
functions: { | ||
perFrame: { pool: "main", code: perFrame }, | ||
perPixel: { pool: "main", code: perPixel } | ||
} | ||
})]; | ||
case 1: | ||
mod = _a.sent(); | ||
expect(function () { | ||
mod.exports.perFrame(); | ||
mod.exports.perPixel(); | ||
}).not.toThrow(); | ||
return [2 /*return*/]; | ||
} | ||
describe("Invalid pool for function", () => { | ||
test("function pool is not among defined", async () => { | ||
const ax = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
const bx = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
const moduleOptions = { | ||
pools: { | ||
a: { x: ax }, | ||
b: { x: bx }, | ||
}, | ||
functions: { | ||
myInvalidFunction: { pool: "c", code: "x = 10;" }, | ||
}, | ||
}; | ||
await expect(loadModule(moduleOptions)).rejects.toEqual(new Error(`The function "myInvalidFunction" was declared as using a variable pool named "c" which is not among the variable pools defined. The defined variable pools are: "a" and "b".`)); | ||
}); | ||
}); }); | ||
test("no function pools are defined", async () => { | ||
const moduleOptions = { | ||
pools: {}, | ||
functions: { | ||
myInvalidFunction: { pool: "c", code: "x = 10;" }, | ||
}, | ||
}; | ||
await expect(loadModule(moduleOptions)).rejects.toEqual(new Error(`The function "myInvalidFunction" was declared as using a variable pool named "c" but no pools were defined.`)); | ||
}); | ||
}); | ||
test("Some actual equations", async () => { | ||
const globals = {}; | ||
MILKDROP_GLOBALS.forEach(name => { | ||
globals[name] = new WebAssembly.Global({ value: "f64", mutable: true }, 0); | ||
}); | ||
const perFrame = fs.readFileSync(path.join(__dirname, "../../fixtures/youtube_broadcast_yourself_per_frame.eel"), { encoding: "utf8" }); | ||
const perPixel = fs.readFileSync(path.join(__dirname, "../../fixtures/youtube_broadcast_yourself_per_pixel.eel"), { encoding: "utf8" }); | ||
const mod = await loadModule({ | ||
pools: { | ||
main: globals, | ||
}, | ||
functions: { | ||
perFrame: { pool: "main", code: perFrame }, | ||
perPixel: { pool: "main", code: perPixel }, | ||
}, | ||
}); | ||
expect(() => { | ||
mod.exports.perFrame(); | ||
mod.exports.perPixel(); | ||
}).not.toThrow(); | ||
}); | ||
//# sourceMappingURL=integration.test.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
var parser_1 = require("../parser"); | ||
var testCases_1 = __importDefault(require("../../tools/testCases")); | ||
var javaScriptEmitter_1 = require("../javaScriptEmitter"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const parser_1 = require("../parser"); | ||
const testCases_1 = __importDefault(require("../../tools/testCases")); | ||
const javaScriptEmitter_1 = require("../javaScriptEmitter"); | ||
function compileToJavaScript(code) { | ||
var ast = parser_1.parse(code); | ||
const ast = parser_1.parse(code); | ||
return javaScriptEmitter_1.emitter(ast, { rawSource: code }); | ||
} | ||
describe.skip("Small test cases", function () { | ||
var onlyIndex = null; | ||
testCases_1["default"].forEach(function (testCase, i) { | ||
var _a = __read(testCase, 3), description = _a[0], expression = _a[1], expectedResult = _a[2]; | ||
var testFn = onlyIndex === i ? test.only : test; | ||
testFn("(" + i + "): " + description + ": \"" + expression + "\"", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var javaScriptSource, fn, a; | ||
return __generator(this, function (_a) { | ||
javaScriptSource = compileToJavaScript(expression); | ||
fn = new Function("a", javaScriptSource); | ||
a = { g: 0, x: 10 }; | ||
fn(a); | ||
expect(a.g).toBe(expectedResult); | ||
return [2 /*return*/]; | ||
}); | ||
}); }); | ||
describe.skip("Small test cases", () => { | ||
const onlyIndex = null; | ||
testCases_1.default.forEach((testCase, i) => { | ||
const [description, expression, expectedResult] = testCase; | ||
const testFn = onlyIndex === i ? test.only : test; | ||
testFn(`(${i}): ${description}: "${expression}"`, async () => { | ||
const javaScriptSource = compileToJavaScript(expression); | ||
// console.log(javaScriptSource); | ||
const fn = new Function("a", javaScriptSource); | ||
const a = { g: 0, x: 10 }; | ||
fn(a); | ||
expect(a.g).toBe(expectedResult); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=javaScriptCompiler.test.js.map |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
exports.__esModule = true; | ||
var preProcessor_1 = require("../preProcessor"); | ||
describe("getLoc", function () { | ||
test("basic", function () { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const preProcessor_1 = require("../preProcessor"); | ||
describe("getLoc", () => { | ||
test("basic", () => { | ||
expect(preProcessor_1.getLoc([], 10)).toEqual({ line: 1, column: 10 }); | ||
}); | ||
test("after first anchor", function () { | ||
test("after first anchor", () => { | ||
expect(preProcessor_1.getLoc([{ destCol: 5, srcCol: 5, srcLine: 5 }], 10)).toEqual({ | ||
line: 5, | ||
column: 10 | ||
column: 10, | ||
}); | ||
}); | ||
test("before first anchor", function () { | ||
test("before first anchor", () => { | ||
expect(preProcessor_1.getLoc([{ destCol: 5, srcCol: 5, srcLine: 5 }], 3)).toEqual({ | ||
line: 1, | ||
column: 3 | ||
column: 3, | ||
}); | ||
}); | ||
test("between two anchors", function () { | ||
test("between two anchors", () => { | ||
expect(preProcessor_1.getLoc([ | ||
@@ -42,76 +26,76 @@ { destCol: 5, srcCol: 5, srcLine: 5 }, | ||
line: 5, | ||
column: 8 | ||
column: 8, | ||
}); | ||
}); | ||
}); | ||
describe("Windows Newlines", function () { | ||
test("basic", function () { | ||
var _a = __read(preProcessor_1.preProcess("No\r\n new \r\nline."), 1), actual = _a[0]; | ||
var expected = "No new line."; | ||
describe("Windows Newlines", () => { | ||
test("basic", () => { | ||
const [actual] = preProcessor_1.preProcess("No\r\n new \r\nline."); | ||
const expected = "No new line."; | ||
expect(actual).toBe(expected); | ||
}); | ||
test("within token", function () { | ||
var _a = __read(preProcessor_1.preProcess("55\r\n55"), 1), actual = _a[0]; | ||
var expected = "5555"; | ||
test("within token", () => { | ||
const [actual] = preProcessor_1.preProcess("55\r\n55"); | ||
const expected = "5555"; | ||
expect(actual).toBe(expected); | ||
}); | ||
}); | ||
describe("Newlines", function () { | ||
test("basic", function () { | ||
var _a = __read(preProcessor_1.preProcess("No\n new \nline."), 1), actual = _a[0]; | ||
var expected = "No new line."; | ||
describe("Newlines", () => { | ||
test("basic", () => { | ||
const [actual] = preProcessor_1.preProcess("No\n new \nline."); | ||
const expected = "No new line."; | ||
expect(actual).toBe(expected); | ||
}); | ||
test("within token", function () { | ||
var _a = __read(preProcessor_1.preProcess("55\n55"), 1), actual = _a[0]; | ||
var expected = "5555"; | ||
test("within token", () => { | ||
const [actual] = preProcessor_1.preProcess("55\n55"); | ||
const expected = "5555"; | ||
expect(actual).toBe(expected); | ||
}); | ||
}); | ||
describe("Comments", function () { | ||
test("regular", function () { | ||
var _a = __read(preProcessor_1.preProcess("No // Comment."), 1), actual = _a[0]; | ||
var expected = "No "; | ||
describe("Comments", () => { | ||
test("regular", () => { | ||
const [actual] = preProcessor_1.preProcess("No // Comment."); | ||
const expected = "No "; | ||
expect(actual).toBe(expected); | ||
}); | ||
test("backwards", function () { | ||
var _a = __read(preProcessor_1.preProcess("No \\\\ Comment."), 1), actual = _a[0]; | ||
var expected = "No "; | ||
test("backwards", () => { | ||
const [actual] = preProcessor_1.preProcess("No \\\\ Comment."); | ||
const expected = "No "; | ||
expect(actual).toBe(expected); | ||
}); | ||
test("with newline", function () { | ||
var _a = __read(preProcessor_1.preProcess("No // freaking\r\nway."), 1), actual = _a[0]; | ||
var expected = "No way."; | ||
test("with newline", () => { | ||
const [actual] = preProcessor_1.preProcess("No // freaking\r\nway."); | ||
const expected = "No way."; | ||
expect(actual).toBe(expected); | ||
}); | ||
test("multiline", function () { | ||
var _a = __read(preProcessor_1.preProcess("No /* freaking\r\n fracking\r\n */way."), 1), actual = _a[0]; | ||
var expected = "No way."; | ||
test("multiline", () => { | ||
const [actual] = preProcessor_1.preProcess("No /* freaking\r\n fracking\r\n */way."); | ||
const expected = "No way."; | ||
expect(actual).toBe(expected); | ||
}); | ||
test("unbalanced multiline", function () { | ||
var _a = __read(preProcessor_1.preProcess("*/ I actually want this."), 1), actual = _a[0]; | ||
var expected = "*/ I actually want this."; | ||
test("unbalanced multiline", () => { | ||
const [actual] = preProcessor_1.preProcess("*/ I actually want this."); | ||
const expected = "*/ I actually want this."; | ||
expect(actual).toBe(expected); | ||
}); | ||
}); | ||
test("getLoc", function () { | ||
var point = preProcessor_1.getLoc([{ destCol: 1, srcCol: 1, srcLine: 10 }], 5); | ||
test("getLoc", () => { | ||
const point = preProcessor_1.getLoc([{ destCol: 1, srcCol: 1, srcLine: 10 }], 5); | ||
expect(point).toEqual({ line: 10, column: 5 }); | ||
}); | ||
test("basic", function () { | ||
var _a = __read(preProcessor_1.preProcess("No\r\n new \r\nline."), 2), out = _a[0], mapper = _a[1]; | ||
var expected = "No new line."; | ||
test("basic", () => { | ||
const [out, mapper] = preProcessor_1.preProcess("No\r\n new \r\nline."); | ||
const expected = "No new line."; | ||
expect(out).toBe(expected); | ||
expect(preProcessor_1.getLoc(mapper, 1)).toEqual({ | ||
line: 1, | ||
column: 1 | ||
column: 1, | ||
}); | ||
expect(preProcessor_1.getLoc(mapper, 3)).toEqual({ | ||
line: 2, | ||
column: 1 | ||
column: 1, | ||
}); | ||
}); | ||
test("Consecutive newlines", function () { | ||
var _a = __read(preProcessor_1.preProcess("No\r\n\r\n new \r\nline."), 2), out = _a[0], mapper = _a[1]; | ||
test("Consecutive newlines", () => { | ||
const [out, mapper] = preProcessor_1.preProcess("No\r\n\r\n new \r\nline."); | ||
expect(mapper).toEqual([ | ||
@@ -122,25 +106,25 @@ { destCol: 3, srcCol: 1, srcLine: 2 }, | ||
]); | ||
var expected = "No new line."; | ||
const expected = "No new line."; | ||
expect(out).toBe(expected); | ||
expect(preProcessor_1.getLoc(mapper, 3)).toEqual({ | ||
line: 3, | ||
column: 1 | ||
column: 1, | ||
}); | ||
}); | ||
test("Block comment", function () { | ||
var _a = __read(preProcessor_1.preProcess("Nothing/* lol */ to see here"), 2), out = _a[0], mapper = _a[1]; | ||
test("Block comment", () => { | ||
const [out, mapper] = preProcessor_1.preProcess("Nothing/* lol */ to see here"); | ||
// expect(mapper).toEqual([{ destCol: 8, srcCol: 17, srcLine: 1 }]); | ||
var expected = "Nothing to see here"; | ||
const expected = "Nothing to see here"; | ||
expect(out).toBe(expected); | ||
expect(preProcessor_1.getLoc(mapper, 7)).toEqual({ | ||
line: 1, | ||
column: 7 | ||
column: 7, | ||
}); | ||
expect(preProcessor_1.getLoc(mapper, 9)).toEqual({ | ||
line: 1, | ||
column: 18 | ||
column: 18, | ||
}); | ||
}); | ||
test("Block comment second line", function () { | ||
var _a = __read(preProcessor_1.preProcess("No\r\nthing/* lol */ to see here"), 2), out = _a[0], mapper = _a[1]; | ||
test("Block comment second line", () => { | ||
const [out, mapper] = preProcessor_1.preProcess("No\r\nthing/* lol */ to see here"); | ||
expect(mapper).toEqual([ | ||
@@ -150,13 +134,13 @@ { destCol: 3, srcCol: 1, srcLine: 2 }, | ||
]); | ||
var expected = "Nothing to see here"; | ||
const expected = "Nothing to see here"; | ||
expect(out).toBe(expected); | ||
expect(preProcessor_1.getLoc(mapper, 7)).toEqual({ | ||
line: 2, | ||
column: 5 | ||
column: 5, | ||
}); | ||
expect(preProcessor_1.getLoc(mapper, 9)).toEqual({ | ||
line: 2, | ||
column: 16 | ||
column: 16, | ||
}); | ||
}); | ||
//# sourceMappingURL=preProcessor.test.js.map |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
exports.__esModule = true; | ||
var CHILDREN = { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const CHILDREN = { | ||
ASSIGNMENT_EXPRESSION: [ | ||
@@ -34,27 +23,24 @@ { type: "NODE", key: "right" }, | ||
{ type: "NODE", key: "right" }, | ||
] | ||
], | ||
}; | ||
function mapAst(ast, cb) { | ||
var children = CHILDREN[ast.type]; | ||
var newAst = ast; | ||
const children = CHILDREN[ast.type]; | ||
let newAst = ast; | ||
if (children == null) { | ||
throw new Error("Unknown children definition for " + ast.type); | ||
throw new Error(`Unknown children definition for ${ast.type}`); | ||
} | ||
children.forEach(function (child) { | ||
var _a, _b; | ||
children.forEach(child => { | ||
if (child.type === "NODE") { | ||
var orignalChild = ast[child.key]; | ||
var newChild = mapAst(orignalChild, cb); | ||
const orignalChild = ast[child.key]; | ||
const newChild = mapAst(orignalChild, cb); | ||
if (newChild !== orignalChild) { | ||
newAst = __assign(__assign({}, newAst), (_a = {}, _a[child.key] = newChild, _a)); | ||
newAst = Object.assign(Object.assign({}, newAst), { [child.key]: newChild }); | ||
} | ||
} | ||
else if (child.type === "ARRAY") { | ||
var orignalChildren = ast[child.key]; | ||
var newChildren_1 = orignalChildren.map(function (originalChild) { | ||
return mapAst(originalChild, cb); | ||
}); | ||
var childrenHaveChanged = orignalChildren.some(function (child, i) { return child !== newChildren_1[i]; }); | ||
const orignalChildren = ast[child.key]; | ||
const newChildren = orignalChildren.map(originalChild => mapAst(originalChild, cb)); | ||
const childrenHaveChanged = orignalChildren.some((child, i) => child !== newChildren[i]); | ||
if (childrenHaveChanged) { | ||
newAst = __assign(__assign({}, newAst), (_b = {}, _b[child.key] = newChildren_1, _b)); | ||
newAst = Object.assign(Object.assign({}, newAst), { [child.key]: newChildren }); | ||
} | ||
@@ -61,0 +47,0 @@ } |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -32,12 +12,11 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
var parser_1 = require("./parser"); | ||
var emitter_1 = require("./emitter"); | ||
var encoding_1 = require("./encoding"); | ||
var shims_1 = __importDefault(require("./shims")); | ||
var Utils = __importStar(require("./utils")); | ||
var wasmFunctions_1 = require("./wasmFunctions"); | ||
var constants_1 = require("./constants"); | ||
function compileModule(_a) { | ||
var pools = _a.pools, funcs = _a.functions, _b = _a.eelVersion, eelVersion = _b === void 0 ? 2 : _b, _c = _a.preParsed, preParsed = _c === void 0 ? false : _c; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const parser_1 = require("./parser"); | ||
const emitter_1 = require("./emitter"); | ||
const encoding_1 = require("./encoding"); | ||
const shims_1 = __importDefault(require("./shims")); | ||
const Utils = __importStar(require("./utils")); | ||
const wasmFunctions_1 = require("./wasmFunctions"); | ||
const constants_1 = require("./constants"); | ||
function compileModule({ pools, functions: funcs, eelVersion = 2, preParsed = false, }) { | ||
if (Object.keys(pools).includes("shims")) { | ||
@@ -47,6 +26,5 @@ throw new Error('You may not name a pool "shims". "shims" is reserved for injected JavaScript functions.'); | ||
// Collect all the globals that we expect to get as imports. | ||
var importedVars = []; | ||
Object.entries(pools).forEach(function (_a) { | ||
var _b = __read(_a, 2), poolName = _b[0], pool = _b[1]; | ||
pool.forEach(function (variableName) { | ||
const importedVars = []; | ||
Object.entries(pools).forEach(([poolName, pool]) => { | ||
pool.forEach(variableName => { | ||
importedVars.push([poolName, variableName]); | ||
@@ -56,32 +34,29 @@ }); | ||
// Ensure all the imported globals get the first ids. | ||
var varResolver = new Utils.ScopedIdMap(); | ||
importedVars.forEach(function (_a) { | ||
var _b = __read(_a, 2), poolName = _b[0], variableName = _b[1]; | ||
const varResolver = new Utils.ScopedIdMap(); | ||
importedVars.forEach(([poolName, variableName]) => { | ||
varResolver.get(poolName, variableName); | ||
}); | ||
var functionImports = Object.entries(shims_1["default"]).map(function (_a) { | ||
var _b = __read(_a, 2), name = _b[0], func = _b[1]; | ||
const functionImports = Object.entries(shims_1.default).map(([name, func]) => { | ||
return { | ||
args: new Array(func.length).fill(null).map(function (_) { return encoding_1.VAL_TYPE.f64; }), | ||
args: new Array(func.length).fill(null).map(_ => encoding_1.VAL_TYPE.f64), | ||
// Shims implicitly always return a number | ||
returns: [encoding_1.VAL_TYPE.f64], | ||
name: name | ||
name, | ||
}; | ||
}); | ||
var localFuncOrder = []; | ||
var moduleFuncs = []; | ||
Object.entries(funcs).forEach(function (_a) { | ||
var _b = __read(_a, 2), name = _b[0], _c = _b[1], pool = _c.pool, code = _c.code; | ||
const localFuncOrder = []; | ||
const moduleFuncs = []; | ||
Object.entries(funcs).forEach(([name, { pool, code }]) => { | ||
if (pools[pool] == null) { | ||
var poolsList = Object.keys(pools); | ||
const poolsList = Object.keys(pools); | ||
if (poolsList.length === 0) { | ||
throw new Error("The function \"" + name + "\" was declared as using a variable " + | ||
("pool named \"" + pool + "\" but no pools were defined.")); | ||
throw new Error(`The function "${name}" was declared as using a variable ` + | ||
`pool named "${pool}" but no pools were defined.`); | ||
} | ||
throw new Error("The function \"" + name + "\" was declared as using a variable " + | ||
("pool named \"" + pool + "\" which is not among the variable ") + | ||
"pools defined. The defined variable pools are: " + | ||
(Utils.formatList(poolsList) + ".")); | ||
throw new Error(`The function "${name}" was declared as using a variable ` + | ||
`pool named "${pool}" which is not among the variable ` + | ||
`pools defined. The defined variable pools are: ` + | ||
`${Utils.formatList(poolsList)}.`); | ||
} | ||
var ast = preParsed ? code : parser_1.parse(code); | ||
const ast = preParsed ? code : parser_1.parse(code); | ||
if (typeof ast === "string") { | ||
@@ -97,5 +72,5 @@ // TODO: Change the API so this can be enforced by types | ||
} | ||
var localVariables = []; | ||
var context = { | ||
resolveVar: function (name) { | ||
const localVariables = []; | ||
const context = { | ||
resolveVar: name => { | ||
// The `reg00`-`reg99` variables are special in that they are shared between all pools. | ||
@@ -107,3 +82,3 @@ if (/^reg\d\d$/.test(name)) { | ||
}, | ||
resolveLocal: function (type) { | ||
resolveLocal: type => { | ||
// TODO: We could provide a way for the emitter to release a local | ||
@@ -115,9 +90,9 @@ // variable so that we can reuse it, much in the same way a traditional | ||
}, | ||
resolveFunc: function (name) { | ||
resolveFunc: name => { | ||
// If this is a shim, return the shim index. | ||
var shimdex = functionImports.findIndex(function (func) { return func.name === name; }); | ||
const shimdex = functionImports.findIndex(func => func.name === name); | ||
if (shimdex !== -1) { | ||
var call = encoding_1.op.call(shimdex); | ||
const call = encoding_1.op.call(shimdex); | ||
if (name === "rand" && eelVersion === 1) { | ||
return __spread(call, [encoding_1.op.f64_floor]); | ||
return [...call, encoding_1.op.f64_floor]; | ||
} | ||
@@ -131,3 +106,3 @@ return call; | ||
} | ||
var index = localFuncOrder.indexOf(name); | ||
let index = localFuncOrder.indexOf(name); | ||
if (index === -1) { | ||
@@ -139,19 +114,19 @@ localFuncOrder.push(name); | ||
}, | ||
rawSource: code | ||
rawSource: code, | ||
}; | ||
var binary = emitter_1.emit(ast, context); | ||
const binary = emitter_1.emit(ast, context); | ||
moduleFuncs.push({ | ||
binary: binary, | ||
binary, | ||
exportName: name, | ||
args: [], | ||
returns: [], | ||
localVariables: localVariables | ||
localVariables, | ||
}); | ||
}); | ||
var localFuncs = localFuncOrder.map(function (name) { | ||
var func = wasmFunctions_1.localFuncMap[name]; | ||
const localFuncs = localFuncOrder.map(name => { | ||
const func = wasmFunctions_1.localFuncMap[name]; | ||
// This check is technicaly redundant since we check inside resolveLocalFunc | ||
// in the compiler context. It's here just to catch potential compiler bugs. | ||
if (func == null) { | ||
throw new Error("Undefined local function \"" + name + "\""); | ||
throw new Error(`Undefined local function "${name}"`); | ||
} | ||
@@ -161,23 +136,25 @@ return func; | ||
// Given a function definition, return a hashable string representation of its signature. | ||
var getSignatureKey = function (func) { | ||
return __spread(func.args, ["|"], func.returns).join("-"); | ||
const getSignatureKey = (func) => { | ||
return [...func.args, "|", ...func.returns].join("-"); | ||
}; | ||
// https://webassembly.github.io/spec/core/binary/modules.html#type-section | ||
var types = []; | ||
var typeIndexByKey = new Map(); | ||
__spread(functionImports, localFuncs, moduleFuncs).forEach(function (func) { | ||
var key = getSignatureKey(func); | ||
const types = []; | ||
const typeIndexByKey = new Map(); | ||
[...functionImports, ...localFuncs, ...moduleFuncs].forEach(func => { | ||
const key = getSignatureKey(func); | ||
if (typeIndexByKey.has(key)) { | ||
return; | ||
} | ||
types.push(__spread([ | ||
encoding_1.FUNCTION_TYPE | ||
], encoding_1.encodeVector(func.args), encoding_1.encodeVector(func.returns))); | ||
types.push([ | ||
encoding_1.FUNCTION_TYPE, | ||
...encoding_1.encodeFlatVector(func.args), | ||
...encoding_1.encodeFlatVector(func.returns), | ||
]); | ||
typeIndexByKey.set(key, types.length - 1); | ||
}); | ||
function getTypeIndex(func) { | ||
var key = getSignatureKey(func); | ||
var typeIndex = typeIndexByKey.get(key); | ||
const key = getSignatureKey(func); | ||
const typeIndex = typeIndexByKey.get(key); | ||
if (typeIndex == null) { | ||
throw new Error("Failed to get a type index for key " + key); | ||
throw new Error(`Failed to get a type index for key ${key}`); | ||
} | ||
@@ -187,9 +164,19 @@ return typeIndex; | ||
// https://webassembly.github.io/spec/core/binary/modules.html#import-section | ||
var imports = __spread(importedVars.map(function (_a) { | ||
var _b = __read(_a, 2), namespace = _b[0], name = _b[1]; | ||
return __spread(encoding_1.encodeString(namespace), encoding_1.encodeString(name), [encoding_1.GLOBAL_TYPE, encoding_1.VAL_TYPE.f64, encoding_1.MUTABILITY["var"]]); | ||
}), functionImports.map(function (func, i) { | ||
var typeIndex = getTypeIndex(func); | ||
return __spread(encoding_1.encodeString("shims"), encoding_1.encodeString(func.name), __spread([encoding_1.TYPE_IDX], encoding_1.unsignedLEB128(typeIndex))); | ||
})); | ||
const imports = [ | ||
...importedVars.map(([namespace, name]) => { | ||
return [ | ||
...encoding_1.encodeString(namespace), | ||
...encoding_1.encodeString(name), | ||
...[encoding_1.GLOBAL_TYPE, encoding_1.VAL_TYPE.f64, encoding_1.MUTABILITY.var], | ||
]; | ||
}), | ||
...functionImports.map((func, i) => { | ||
const typeIndex = getTypeIndex(func); | ||
return [ | ||
...encoding_1.encodeString("shims"), | ||
...encoding_1.encodeString(func.name), | ||
...[encoding_1.TYPE_IDX, ...encoding_1.unsignedLEB128(typeIndex)], | ||
]; | ||
}), | ||
]; | ||
// https://webassembly.github.io/spec/core/binary/modules.html#function-section | ||
@@ -199,27 +186,32 @@ // | ||
// > index not referencing a function import. | ||
var functions = __spread(localFuncs, moduleFuncs).map(function (func) { | ||
var typeIndex = getTypeIndex(func); | ||
const functions = [...localFuncs, ...moduleFuncs].map(func => { | ||
const typeIndex = getTypeIndex(func); | ||
return encoding_1.unsignedLEB128(typeIndex); | ||
}); | ||
var memories = [ | ||
__spread([ | ||
0x01 | ||
], encoding_1.unsignedLEB128(constants_1.WASM_MEMORY_SIZE), encoding_1.unsignedLEB128(constants_1.WASM_MEMORY_SIZE)), | ||
const memories = [ | ||
// Only one memory | ||
[ | ||
0x01, | ||
...encoding_1.unsignedLEB128(constants_1.WASM_MEMORY_SIZE), | ||
...encoding_1.unsignedLEB128(constants_1.WASM_MEMORY_SIZE), | ||
], | ||
]; | ||
// https://webassembly.github.io/spec/core/binary/modules.html#global-section | ||
var globalCount = varResolver.size() - importedVars.length; | ||
var globals = Utils.times(globalCount, function () { | ||
return __spread([ | ||
const globalCount = varResolver.size() - importedVars.length; | ||
const globals = Utils.times(globalCount, () => { | ||
return [ | ||
encoding_1.VAL_TYPE.f64, | ||
encoding_1.MUTABILITY["var"] | ||
], encoding_1.op.f64_const(0), [ | ||
encoding_1.MUTABILITY.var, | ||
...encoding_1.op.f64_const(0), | ||
encoding_1.op.end, | ||
]); | ||
]; | ||
}); | ||
// https://webassembly.github.io/spec/core/binary/modules.html#binary-exportsec | ||
var xports = __spread(moduleFuncs).map(function (func, i) { | ||
var funcIndex = i + functionImports.length + localFuncs.length; | ||
return __spread(encoding_1.encodeString(func.exportName), [ | ||
encoding_1.EXPORT_TYPE.FUNC | ||
], encoding_1.unsignedLEB128(funcIndex)); | ||
const xports = [...moduleFuncs].map((func, i) => { | ||
const funcIndex = i + functionImports.length + localFuncs.length; | ||
return [ | ||
...encoding_1.encodeString(func.exportName), | ||
encoding_1.EXPORT_TYPE.FUNC, | ||
...encoding_1.unsignedLEB128(funcIndex), | ||
]; | ||
}); | ||
@@ -234,8 +226,8 @@ /* Uncomment this to expose memory | ||
// https://webassembly.github.io/spec/core/binary/modules.html#code-section | ||
var codes = __spread(localFuncs, moduleFuncs).map(function (func) { | ||
const codes = [...localFuncs, ...moduleFuncs].map(func => { | ||
var _a; | ||
// TODO: We could collapose consecutive types here, or even move to a two | ||
// pass approach where ids are resolved after the emitter is run. | ||
var localTypes = ((_a = func.localVariables) !== null && _a !== void 0 ? _a : []).map(function (type) { | ||
return __spread(encoding_1.unsignedLEB128(1), [type]); | ||
const localTypes = ((_a = func.localVariables) !== null && _a !== void 0 ? _a : []).map(type => { | ||
return [...encoding_1.unsignedLEB128(1), type]; | ||
}); | ||
@@ -245,7 +237,23 @@ // It's a bit odd that every other section is an array of arrays and this | ||
// the binary functions can be skipped efficiently. | ||
return encoding_1.encodeVector(__spread(encoding_1.encodeVector(localTypes), func.binary, [encoding_1.op.end])); | ||
return encoding_1.encodeFlatVector([ | ||
...encoding_1.encodeNestedVector(localTypes), | ||
...func.binary, | ||
encoding_1.op.end, | ||
]); | ||
}); | ||
return new Uint8Array(__spread(encoding_1.MAGIC, encoding_1.WASM_VERSION, encoding_1.encodeSection(encoding_1.SECTION.TYPE, types), encoding_1.encodeSection(encoding_1.SECTION.IMPORT, imports), encoding_1.encodeSection(encoding_1.SECTION.FUNC, functions), encoding_1.encodeSection(encoding_1.SECTION.MEMORY, memories), encoding_1.encodeSection(encoding_1.SECTION.GLOBAL, globals), encoding_1.encodeSection(encoding_1.SECTION.EXPORT, xports), encoding_1.encodeSection(encoding_1.SECTION.CODE, codes))); | ||
return new Uint8Array([ | ||
// Magic module header | ||
...encoding_1.MAGIC, | ||
// Version number | ||
...encoding_1.WASM_VERSION, | ||
...encoding_1.encodeSection(encoding_1.SECTION.TYPE, types), | ||
...encoding_1.encodeSection(encoding_1.SECTION.IMPORT, imports), | ||
...encoding_1.encodeSection(encoding_1.SECTION.FUNC, functions), | ||
...encoding_1.encodeSection(encoding_1.SECTION.MEMORY, memories), | ||
...encoding_1.encodeSection(encoding_1.SECTION.GLOBAL, globals), | ||
...encoding_1.encodeSection(encoding_1.SECTION.EXPORT, xports), | ||
...encoding_1.encodeSection(encoding_1.SECTION.CODE, codes), | ||
]); | ||
} | ||
exports.compileModule = compileModule; | ||
//# sourceMappingURL=compiler.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// https://webassembly.github.io/spec/core/exec/runtime.html#page-size | ||
var WASM_PAGE_SIZE = 65536; | ||
var BYTES_PER_F64 = 8; | ||
var BUFFER_COUNT = 2; | ||
const WASM_PAGE_SIZE = 65536; | ||
const BYTES_PER_F64 = 8; | ||
const BUFFER_COUNT = 2; | ||
// https://github.com/WACUP/vis_milk2/blob/de9625a89e724afe23ed273b96b8e48496095b6c/ns-eel2/ns-eel.h#L136 | ||
@@ -8,0 +8,0 @@ exports.MAX_LOOP_COUNT = 1048576; |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
var encoding_1 = require("./encoding"); | ||
var shims_1 = __importDefault(require("./shims")); | ||
var errorUtils_1 = require("./errorUtils"); | ||
var wasmFunctions_1 = require("./wasmFunctions"); | ||
var utils_1 = require("./utils"); | ||
var constants_1 = require("./constants"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const encoding_1 = require("./encoding"); | ||
const shims_1 = __importDefault(require("./shims")); | ||
const errorUtils_1 = require("./errorUtils"); | ||
const wasmFunctions_1 = require("./wasmFunctions"); | ||
const utils_1 = require("./utils"); | ||
const constants_1 = require("./constants"); | ||
function emit(ast, context) { | ||
var _a, _b, _c; | ||
switch (ast.type) { | ||
case "SCRIPT": { | ||
var body = ast.body.map(function (statement, i) { | ||
return __spread(emit(statement, context), [encoding_1.op.drop]); | ||
const body = ast.body.map((statement, i) => { | ||
return [...emit(statement, context), encoding_1.op.drop]; | ||
}); | ||
@@ -44,5 +25,5 @@ return utils_1.flatten(body); | ||
case "BINARY_EXPRESSION": { | ||
var left = emit(ast.left, context); | ||
var right = emit(ast.right, context); | ||
var operatorToOps = { | ||
const left = emit(ast.left, context); | ||
const right = emit(ast.right, context); | ||
const operatorToOps = { | ||
"+": [encoding_1.op.f64_add], | ||
@@ -57,29 +38,29 @@ "-": [encoding_1.op.f64_sub], | ||
// Comparison operators | ||
"==": __spread([encoding_1.op.f64_sub], encoding_1.IS_ZEROISH, [encoding_1.op.f64_convert_i32_s]), | ||
"!=": __spread([encoding_1.op.f64_sub], encoding_1.IS_NOT_ZEROISH, [encoding_1.op.f64_convert_i32_s]), | ||
"==": [encoding_1.op.f64_sub, ...encoding_1.IS_ZEROISH, encoding_1.op.f64_convert_i32_s], | ||
"!=": [encoding_1.op.f64_sub, ...encoding_1.IS_NOT_ZEROISH, encoding_1.op.f64_convert_i32_s], | ||
"<": [encoding_1.op.f64_lt, encoding_1.op.f64_convert_i32_s], | ||
">": [encoding_1.op.f64_gt, encoding_1.op.f64_convert_i32_s], | ||
"<=": [encoding_1.op.f64_le, encoding_1.op.f64_convert_i32_s], | ||
">=": [encoding_1.op.f64_ge, encoding_1.op.f64_convert_i32_s] | ||
">=": [encoding_1.op.f64_ge, encoding_1.op.f64_convert_i32_s], | ||
}; | ||
var code = operatorToOps[ast.operator]; | ||
const code = operatorToOps[ast.operator]; | ||
if (code == null) { | ||
throw errorUtils_1.createCompilerError("Unknown binary expression operator " + ast.operator, ast.loc, context.rawSource); | ||
throw errorUtils_1.createCompilerError(`Unknown binary expression operator ${ast.operator}`, ast.loc, context.rawSource); | ||
} | ||
return __spread(left, right, code); | ||
return [...left, ...right, ...code]; | ||
} | ||
case "CALL_EXPRESSION": { | ||
var functionName_1 = ast.callee.value; | ||
const functionName = ast.callee.value; | ||
// Destructure this so that TypeScript knows it won't get mutated. | ||
var argList_1 = ast.arguments; | ||
var assertArity = function (arity) { | ||
if (argList_1.length < arity) { | ||
throw errorUtils_1.createUserError("Too few arguments passed to `" + functionName_1 + "()`. Expected " + arity + " but only got " + argList_1.length + ".", ast.loc, context.rawSource); | ||
const argList = ast.arguments; | ||
const assertArity = (arity) => { | ||
if (argList.length < arity) { | ||
throw errorUtils_1.createUserError(`Too few arguments passed to \`${functionName}()\`. Expected ${arity} but only got ${argList.length}.`, ast.loc, context.rawSource); | ||
} | ||
if (argList_1.length > arity) { | ||
throw errorUtils_1.createUserError("Too many arguments passed to `" + functionName_1 + "()`. Expected " + arity + " but got " + argList_1.length + ".", argList_1[arity].loc, context.rawSource); | ||
if (argList.length > arity) { | ||
throw errorUtils_1.createUserError(`Too many arguments passed to \`${functionName}()\`. Expected ${arity} but got ${argList.length}.`, argList[arity].loc, context.rawSource); | ||
} | ||
}; | ||
// Some functions have special behavior | ||
switch (functionName_1) { | ||
switch (functionName) { | ||
case "exec2": | ||
@@ -93,4 +74,4 @@ assertArity(2); | ||
assertArity(3); | ||
var _a = __read(ast.arguments, 3), test_1 = _a[0], consiquent = _a[1], alternate = _a[2]; | ||
return emitConditional(test_1, consiquent, alternate, context); | ||
const [test, consiquent, alternate] = ast.arguments; | ||
return emitConditional(test, consiquent, alternate, context); | ||
case "while": | ||
@@ -105,58 +86,69 @@ assertArity(1); | ||
assertArity(1); | ||
var index = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
return __spread(emit(ast.arguments[0], context), context.resolveFunc("_getBufferIndex"), encoding_1.op.local_tee(index), encoding_1.op.i32_const(-1), [ | ||
encoding_1.op.i32_ne | ||
], encoding_1.op["if"](encoding_1.BLOCK.f64), encoding_1.op.local_get(index), encoding_1.op.f64_load(3, emitAddMemoryOffset(functionName_1)), [ | ||
encoding_1.op["else"] | ||
], encoding_1.op.f64_const(0), [ | ||
const index = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
return [ | ||
...emit(ast.arguments[0], context), | ||
...((_a = context.resolveFunc("_getBufferIndex")) !== null && _a !== void 0 ? _a : []), | ||
...encoding_1.op.local_tee(index), | ||
...encoding_1.op.i32_const(-1), | ||
encoding_1.op.i32_ne, | ||
// STACK: [in range] | ||
...encoding_1.op.if(encoding_1.BLOCK.f64), | ||
...encoding_1.op.local_get(index), | ||
...encoding_1.op.f64_load(3, emitAddMemoryOffset(functionName)), | ||
encoding_1.op.else, | ||
...encoding_1.op.f64_const(0), | ||
encoding_1.op.end, | ||
]); | ||
]; | ||
case "assign": | ||
assertArity(2); | ||
var variableIdentifier = ast.arguments[0]; | ||
const variableIdentifier = ast.arguments[0]; | ||
if (variableIdentifier.type != "IDENTIFIER") { | ||
throw errorUtils_1.createUserError("Expected the first argument of `assign()` to be an identifier.", variableIdentifier.loc, context.rawSource); | ||
} | ||
var resolvedName = context.resolveVar(variableIdentifier.value); | ||
return __spread(emit(ast.arguments[1], context), encoding_1.op.global_set(resolvedName), encoding_1.op.global_get(resolvedName)); | ||
const resolvedName = context.resolveVar(variableIdentifier.value); | ||
return [ | ||
...emit(ast.arguments[1], context), | ||
...encoding_1.op.global_set(resolvedName), | ||
...encoding_1.op.global_get(resolvedName), | ||
]; | ||
} | ||
// Function calls which can be linlined | ||
var args = utils_1.flatten(ast.arguments.map(function (node) { return emit(node, context); })); | ||
const args = utils_1.flatten(ast.arguments.map(node => emit(node, context))); | ||
// This is just a continuation of the above switch statement, but it's for functions which all parse their args the same. | ||
switch (functionName_1) { | ||
switch (functionName) { | ||
case "abs": | ||
assertArity(1); | ||
return __spread(args, [encoding_1.op.f64_abs]); | ||
return [...args, encoding_1.op.f64_abs]; | ||
case "sqrt": | ||
assertArity(1); | ||
return __spread(args, [encoding_1.op.f64_abs, encoding_1.op.f64_sqrt]); | ||
return [...args, encoding_1.op.f64_abs, encoding_1.op.f64_sqrt]; | ||
case "int": | ||
assertArity(1); | ||
return __spread(args, [encoding_1.op.f64_floor]); | ||
return [...args, encoding_1.op.f64_floor]; | ||
case "min": | ||
assertArity(2); | ||
return __spread(args, [encoding_1.op.f64_min]); | ||
return [...args, encoding_1.op.f64_min]; | ||
case "max": | ||
assertArity(2); | ||
return __spread(args, [encoding_1.op.f64_max]); | ||
return [...args, encoding_1.op.f64_max]; | ||
case "above": | ||
assertArity(2); | ||
return __spread(args, [encoding_1.op.f64_gt, encoding_1.op.f64_convert_i32_s]); | ||
return [...args, encoding_1.op.f64_gt, encoding_1.op.f64_convert_i32_s]; | ||
case "below": | ||
assertArity(2); | ||
return __spread(args, [encoding_1.op.f64_lt, encoding_1.op.f64_convert_i32_s]); | ||
return [...args, encoding_1.op.f64_lt, encoding_1.op.f64_convert_i32_s]; | ||
case "equal": | ||
assertArity(2); | ||
return __spread(args, [encoding_1.op.f64_sub], encoding_1.IS_ZEROISH, [encoding_1.op.f64_convert_i32_s]); | ||
return [...args, encoding_1.op.f64_sub, ...encoding_1.IS_ZEROISH, encoding_1.op.f64_convert_i32_s]; | ||
case "bnot": | ||
assertArity(1); | ||
return __spread(args, encoding_1.IS_ZEROISH, [encoding_1.op.f64_convert_i32_s]); | ||
return [...args, ...encoding_1.IS_ZEROISH, encoding_1.op.f64_convert_i32_s]; | ||
case "floor": | ||
assertArity(1); | ||
return __spread(args, [encoding_1.op.f64_floor]); | ||
return [...args, encoding_1.op.f64_floor]; | ||
case "ceil": | ||
assertArity(1); | ||
return __spread(args, [encoding_1.op.f64_ceil]); | ||
return [...args, encoding_1.op.f64_ceil]; | ||
} | ||
var invocation = context.resolveFunc(functionName_1); | ||
const invocation = context.resolveFunc(functionName); | ||
if (invocation == null || | ||
@@ -168,22 +160,22 @@ // Ensure this isn't a private function. This is a bit awkward becuase | ||
// the compiler. | ||
functionName_1.startsWith("_")) { | ||
throw errorUtils_1.createUserError("\"" + functionName_1 + "\" is not defined.", ast.callee.loc, context.rawSource); | ||
functionName.startsWith("_")) { | ||
throw errorUtils_1.createUserError(`"${functionName}" is not defined.`, ast.callee.loc, context.rawSource); | ||
} | ||
if (shims_1["default"][functionName_1] != null) { | ||
assertArity(shims_1["default"][functionName_1].length); | ||
if (shims_1.default[functionName] != null) { | ||
assertArity(shims_1.default[functionName].length); | ||
} | ||
else if (wasmFunctions_1.localFuncMap[functionName_1] != null) { | ||
assertArity(wasmFunctions_1.localFuncMap[functionName_1].args.length); | ||
else if (wasmFunctions_1.localFuncMap[functionName] != null) { | ||
assertArity(wasmFunctions_1.localFuncMap[functionName].args.length); | ||
} | ||
else { | ||
throw errorUtils_1.createCompilerError("Missing arity information for the function `" + functionName_1 + "()`", ast.callee.loc, context.rawSource); | ||
throw errorUtils_1.createCompilerError(`Missing arity information for the function \`${functionName}()\``, ast.callee.loc, context.rawSource); | ||
} | ||
return __spread(args, invocation); | ||
return [...args, ...invocation]; | ||
} | ||
case "ASSIGNMENT_EXPRESSION": { | ||
var left = ast.left; | ||
var rightCode = emit(ast.right, context); | ||
var mutationCode = getAssignmentOperatorMutation(ast, context); | ||
const { left } = ast; | ||
const rightCode = emit(ast.right, context); | ||
const mutationCode = getAssignmentOperatorMutation(ast, context); | ||
if (left.type === "IDENTIFIER") { | ||
var resolvedName = context.resolveVar(left.value); | ||
const resolvedName = context.resolveVar(left.value); | ||
// TODO: In lots of cases we don't care about the return value. In those | ||
@@ -193,9 +185,9 @@ // cases we should try to find a way to omit the `get/drop` combo. | ||
// https://en.wikipedia.org/wiki/Peephole_optimization | ||
var get = encoding_1.op.global_get(resolvedName); | ||
var set = encoding_1.op.global_set(resolvedName); | ||
const get = encoding_1.op.global_get(resolvedName); | ||
const set = encoding_1.op.global_set(resolvedName); | ||
// `=` is a special case in that it does not need the original value. | ||
if (mutationCode === null) { | ||
return __spread(rightCode, set, get); | ||
return [...rightCode, ...set, ...get]; | ||
} | ||
return __spread(get, rightCode, mutationCode, set, get); | ||
return [...get, ...rightCode, ...mutationCode, ...set, ...get]; | ||
} | ||
@@ -205,84 +197,125 @@ if (left.type !== "CALL_EXPRESSION") { | ||
// @ts-ignore This is a guard in case the parser has an error | ||
"Unexpected left hand side type for assignment: " + left.type, ast.loc, context.rawSource); | ||
`Unexpected left hand side type for assignment: ${left.type}`, ast.loc, context.rawSource); | ||
} | ||
// Special assignment case for `megabuf(n) = e` and `gmegabuf(n) = e`. | ||
var localIndex = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
const localIndex = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
if (left.arguments.length !== 1) { | ||
throw errorUtils_1.createUserError("Expected 1 argument when assinging to a buffer but got " + left.arguments.length + ".", left.arguments.length === 0 ? left.loc : left.arguments[1].loc, context.rawSource); | ||
throw errorUtils_1.createUserError(`Expected 1 argument when assinging to a buffer but got ${left.arguments.length}.`, left.arguments.length === 0 ? left.loc : left.arguments[1].loc, context.rawSource); | ||
} | ||
var bufferName = left.callee.value; | ||
const bufferName = left.callee.value; | ||
if (bufferName !== "gmegabuf" && bufferName !== "megabuf") { | ||
throw errorUtils_1.createUserError("The only function calls which may be assigned to are `gmegabuf()` and `megabuf()`.", left.callee.loc, context.rawSource); | ||
} | ||
var addOffset = emitAddMemoryOffset(bufferName); | ||
const addOffset = emitAddMemoryOffset(bufferName); | ||
if (mutationCode === null) { | ||
// TODO: Move this to wasmFunctions once we know how to call functions | ||
// from within functions (need to get the offset). | ||
var unnormalizedIndex = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
var rightValue_1 = context.resolveLocal(encoding_1.VAL_TYPE.f64); | ||
return __spread(rightCode, encoding_1.op.local_set(rightValue_1), emit(left.arguments[0], context), context.resolveFunc("_getBufferIndex"), encoding_1.op.local_tee(unnormalizedIndex), encoding_1.op.i32_const(0), [ | ||
encoding_1.op.i32_lt_s | ||
], encoding_1.op["if"](encoding_1.BLOCK.f64), encoding_1.op.f64_const(0), [ | ||
encoding_1.op["else"] | ||
], encoding_1.op.local_get(unnormalizedIndex), encoding_1.op.local_tee(localIndex), encoding_1.op.local_get(rightValue_1), encoding_1.op.f64_store(3, addOffset), encoding_1.op.local_get(rightValue_1), [ | ||
const unnormalizedIndex = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
const rightValue = context.resolveLocal(encoding_1.VAL_TYPE.f64); | ||
return [ | ||
// Emit the right hand side unconditionally to ensure it always runs. | ||
...rightCode, | ||
...encoding_1.op.local_set(rightValue), | ||
...emit(left.arguments[0], context), | ||
...((_b = context.resolveFunc("_getBufferIndex")) !== null && _b !== void 0 ? _b : []), | ||
...encoding_1.op.local_tee(unnormalizedIndex), | ||
...encoding_1.op.i32_const(0), | ||
encoding_1.op.i32_lt_s, | ||
// STACK: [is the index out of range?] | ||
...encoding_1.op.if(encoding_1.BLOCK.f64), | ||
...encoding_1.op.f64_const(0), | ||
encoding_1.op.else, | ||
...encoding_1.op.local_get(unnormalizedIndex), | ||
...encoding_1.op.local_tee(localIndex), | ||
// STACK: [buffer index] | ||
...encoding_1.op.local_get(rightValue), | ||
// STACK: [buffer index, right] | ||
...encoding_1.op.f64_store(3, addOffset), | ||
// STACK: [] | ||
...encoding_1.op.local_get(rightValue), | ||
// STACK: [Right/Buffer value] | ||
encoding_1.op.end, | ||
]); | ||
]; | ||
} | ||
// TODO: Move this to wasmFunctions once we know how to call functions | ||
// from within functions (need to get the offset). | ||
var index = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
var inBounds = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
var rightValue = context.resolveLocal(encoding_1.VAL_TYPE.f64); | ||
var result = context.resolveLocal(encoding_1.VAL_TYPE.f64); | ||
return __spread(rightCode, encoding_1.op.local_set(rightValue), emit(left.arguments[0], context), context.resolveFunc("_getBufferIndex"), encoding_1.op.local_tee(index), encoding_1.op.i32_const(-1), [ | ||
encoding_1.op.i32_ne | ||
], encoding_1.op.local_tee(inBounds), encoding_1.op["if"](encoding_1.BLOCK.f64), encoding_1.op.local_get(index), encoding_1.op.f64_load(3, addOffset), [ | ||
encoding_1.op["else"] | ||
], encoding_1.op.f64_const(0), [ | ||
encoding_1.op.end | ||
], encoding_1.op.local_get(rightValue), mutationCode, encoding_1.op.local_tee(result), encoding_1.op.local_get(inBounds), encoding_1.op["if"](encoding_1.BLOCK["void"]), encoding_1.op.local_get(index), encoding_1.op.local_get(result), encoding_1.op.f64_store(3, addOffset), [ | ||
const index = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
const inBounds = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
const rightValue = context.resolveLocal(encoding_1.VAL_TYPE.f64); | ||
const result = context.resolveLocal(encoding_1.VAL_TYPE.f64); | ||
return [ | ||
...rightCode, | ||
...encoding_1.op.local_set(rightValue), | ||
...emit(left.arguments[0], context), | ||
...((_c = context.resolveFunc("_getBufferIndex")) !== null && _c !== void 0 ? _c : []), | ||
...encoding_1.op.local_tee(index), | ||
// STACK: [index] | ||
...encoding_1.op.i32_const(-1), | ||
encoding_1.op.i32_ne, | ||
...encoding_1.op.local_tee(inBounds), | ||
...encoding_1.op.if(encoding_1.BLOCK.f64), | ||
...encoding_1.op.local_get(index), | ||
...encoding_1.op.f64_load(3, addOffset), | ||
encoding_1.op.else, | ||
...encoding_1.op.f64_const(0), | ||
encoding_1.op.end, | ||
]); | ||
// STACK: [current value from memory || 0] | ||
// Apply the mutation | ||
...encoding_1.op.local_get(rightValue), | ||
...mutationCode, | ||
...encoding_1.op.local_tee(result), | ||
// STACK: [new value] | ||
...encoding_1.op.local_get(inBounds), | ||
...encoding_1.op.if(encoding_1.BLOCK.void), | ||
...encoding_1.op.local_get(index), | ||
...encoding_1.op.local_get(result), | ||
...encoding_1.op.f64_store(3, addOffset), | ||
encoding_1.op.end, | ||
]; | ||
} | ||
case "LOGICAL_EXPRESSION": { | ||
var left = emit(ast.left, context); | ||
var right = emit(ast.right, context); | ||
var behaviorMap = { | ||
const left = emit(ast.left, context); | ||
const right = emit(ast.right, context); | ||
const behaviorMap = { | ||
"&&": { | ||
comparison: encoding_1.IS_ZEROISH, | ||
shortCircutValue: 0 | ||
shortCircutValue: 0, | ||
}, | ||
"||": { | ||
comparison: encoding_1.IS_NOT_ZEROISH, | ||
shortCircutValue: 1 | ||
} | ||
shortCircutValue: 1, | ||
}, | ||
}; | ||
var behavior = behaviorMap[ast.operator]; | ||
const behavior = behaviorMap[ast.operator]; | ||
if (behavior == null) { | ||
throw errorUtils_1.createCompilerError("Unknown logical expression operator " + ast.operator, ast.loc, context.rawSource); | ||
throw errorUtils_1.createCompilerError(`Unknown logical expression operator ${ast.operator}`, ast.loc, context.rawSource); | ||
} | ||
var comparison = behavior.comparison, shortCircutValue = behavior.shortCircutValue; | ||
return __spread(left, comparison, encoding_1.op["if"](encoding_1.BLOCK.f64), encoding_1.op.f64_const(shortCircutValue), [ | ||
encoding_1.op["else"] | ||
], right, encoding_1.IS_NOT_ZEROISH, [ | ||
const { comparison, shortCircutValue } = behavior; | ||
return [ | ||
...left, | ||
...comparison, | ||
...encoding_1.op.if(encoding_1.BLOCK.f64), | ||
...encoding_1.op.f64_const(shortCircutValue), | ||
encoding_1.op.else, | ||
...right, | ||
...encoding_1.IS_NOT_ZEROISH, | ||
encoding_1.op.f64_convert_i32_s, | ||
encoding_1.op.end, | ||
]); | ||
]; | ||
} | ||
case "UNARY_EXPRESSION": { | ||
var value = emit(ast.value, context); | ||
var operatorToCode = { | ||
const value = emit(ast.value, context); | ||
const operatorToCode = { | ||
"-": [encoding_1.op.f64_neg], | ||
"+": [], | ||
"!": __spread(encoding_1.IS_ZEROISH, [encoding_1.op.f64_convert_i32_s]) | ||
"!": [...encoding_1.IS_ZEROISH, encoding_1.op.f64_convert_i32_s], | ||
}; | ||
var code = operatorToCode[ast.operator]; | ||
const code = operatorToCode[ast.operator]; | ||
if (code == null) { | ||
throw errorUtils_1.createCompilerError("Unknown logical unary operator " + ast.operator, ast.loc, context.rawSource); | ||
throw errorUtils_1.createCompilerError(`Unknown logical unary operator ${ast.operator}`, ast.loc, context.rawSource); | ||
} | ||
return __spread(value, code); | ||
return [...value, ...code]; | ||
} | ||
case "IDENTIFIER": | ||
var variableName = ast.value; | ||
const variableName = ast.value; | ||
// TODO: It's a bit odd that not every IDENTIFIER node gets emitted. In | ||
@@ -297,3 +330,3 @@ // function calls and assignments we just peek at the name and never emit | ||
// @ts-ignore This runtime check is here because the caller may not be type-checked | ||
"Unknown AST node type " + ast.type, | ||
`Unknown AST node type ${ast.type}`, | ||
// @ts-ignore This runtime check is here because the caller may not be type-checked | ||
@@ -305,3 +338,3 @@ ast.loc, context.rawSource); | ||
function emitExpressionBlock(body, context) { | ||
var statements = body.map(function (statement, i) { | ||
const statements = body.map((statement, i) => { | ||
return emit(statement, context); | ||
@@ -312,32 +345,55 @@ }); | ||
function emitWhile(expression, context) { | ||
var body = emit(expression, context); | ||
var iterationCount = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
return __spread(encoding_1.op.i32_const(0), encoding_1.op.local_set(iterationCount), encoding_1.op.loop(encoding_1.BLOCK["void"]), encoding_1.op.local_get(iterationCount), encoding_1.op.i32_const(1), [ | ||
encoding_1.op.i32_add | ||
], encoding_1.op.local_tee(iterationCount), encoding_1.op.i32_const(constants_1.MAX_LOOP_COUNT), [ | ||
encoding_1.op.i32_lt_u | ||
], body, encoding_1.IS_NOT_ZEROISH, [ | ||
const body = emit(expression, context); | ||
const iterationCount = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
return [ | ||
...encoding_1.op.i32_const(0), | ||
...encoding_1.op.local_set(iterationCount), | ||
...encoding_1.op.loop(encoding_1.BLOCK.void), | ||
// Increment and check loop count | ||
...encoding_1.op.local_get(iterationCount), | ||
...encoding_1.op.i32_const(1), | ||
encoding_1.op.i32_add, | ||
...encoding_1.op.local_tee(iterationCount), | ||
// STACK: [iteration count] | ||
...encoding_1.op.i32_const(constants_1.MAX_LOOP_COUNT), | ||
encoding_1.op.i32_lt_u, | ||
// STACK: [loop in range] | ||
...body, | ||
...encoding_1.IS_NOT_ZEROISH, | ||
// STACK: [loop in range, body is truthy] | ||
encoding_1.op.i32_and | ||
], encoding_1.op.br_if(0), [ | ||
encoding_1.op.end | ||
], encoding_1.op.f64_const(0)); | ||
encoding_1.op.i32_and, | ||
// STACK: [can continue] | ||
...encoding_1.op.br_if(0), | ||
encoding_1.op.end, | ||
...encoding_1.op.f64_const(0), | ||
]; | ||
} | ||
function emitLoop(count, expression, context) { | ||
var body = emit(expression, context); | ||
var localIndex = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
return __spread(encoding_1.op.block(encoding_1.BLOCK["void"]), emit(count, context), [ | ||
encoding_1.op.i32_trunc_f64_s | ||
], encoding_1.op.local_tee(localIndex), encoding_1.op.i32_const(0), [ | ||
encoding_1.op.i32_le_s | ||
], encoding_1.op.br_if(1), encoding_1.op.loop(encoding_1.BLOCK["void"]), body, [ | ||
encoding_1.op.drop | ||
], encoding_1.op.local_get(localIndex), encoding_1.op.i32_const(1), [ | ||
encoding_1.op.i32_sub | ||
], encoding_1.op.local_tee(localIndex), encoding_1.op.i32_const(0), [ | ||
encoding_1.op.i32_ne | ||
], encoding_1.op.br_if(0), [ | ||
const body = emit(expression, context); | ||
const localIndex = context.resolveLocal(encoding_1.VAL_TYPE.i32); | ||
return [ | ||
...encoding_1.op.block(encoding_1.BLOCK.void), | ||
// Assign the count to a variable | ||
...emit(count, context), | ||
encoding_1.op.i32_trunc_f64_s, | ||
...encoding_1.op.local_tee(localIndex), | ||
...encoding_1.op.i32_const(0), | ||
encoding_1.op.i32_le_s, | ||
...encoding_1.op.br_if(1), | ||
...encoding_1.op.loop(encoding_1.BLOCK.void), | ||
// Run the body | ||
...body, | ||
encoding_1.op.drop, | ||
// Decrement the count | ||
...encoding_1.op.local_get(localIndex), | ||
...encoding_1.op.i32_const(1), | ||
encoding_1.op.i32_sub, | ||
...encoding_1.op.local_tee(localIndex), | ||
...encoding_1.op.i32_const(0), | ||
encoding_1.op.i32_ne, | ||
...encoding_1.op.br_if(0), | ||
encoding_1.op.end, | ||
encoding_1.op.end | ||
], encoding_1.op.f64_const(0)); | ||
encoding_1.op.end, | ||
...encoding_1.op.f64_const(0), | ||
]; | ||
} | ||
@@ -347,7 +403,11 @@ function emitConditional(test, consiquent, alternate, context) { | ||
// Is that an optimization that we might want as well? | ||
return __spread(emit(test, context), encoding_1.IS_NOT_ZEROISH, encoding_1.op["if"](encoding_1.BLOCK.f64), emit(consiquent, context), [ | ||
encoding_1.op["else"] | ||
], emit(alternate, context), [ | ||
return [ | ||
...emit(test, context), | ||
...encoding_1.IS_NOT_ZEROISH, | ||
...encoding_1.op.if(encoding_1.BLOCK.f64), | ||
...emit(consiquent, context), | ||
encoding_1.op.else, | ||
...emit(alternate, context), | ||
encoding_1.op.end, | ||
]); | ||
]; | ||
} | ||
@@ -365,3 +425,3 @@ // There are two sections of memory. This function emits code to add the correct | ||
function getAssignmentOperatorMutation(ast, context) { | ||
var operatorToCode = { | ||
const operatorToCode = { | ||
"+=": [encoding_1.op.f64_add], | ||
@@ -372,7 +432,7 @@ "-=": [encoding_1.op.f64_sub], | ||
"%=": context.resolveFunc("mod"), | ||
"=": null | ||
"=": null, | ||
}; | ||
var operatorCode = operatorToCode[ast.operator]; | ||
const operatorCode = operatorToCode[ast.operator]; | ||
if (operatorCode === undefined) { | ||
throw errorUtils_1.createCompilerError("Unknown assignment operator \"" + ast.operator + "\"", ast.loc, context.rawSource); | ||
throw errorUtils_1.createCompilerError(`Unknown assignment operator "${ast.operator}"`, ast.loc, context.rawSource); | ||
} | ||
@@ -379,0 +439,0 @@ return operatorCode; |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
@@ -29,5 +9,5 @@ if (mod && mod.__esModule) return mod; | ||
}; | ||
exports.__esModule = true; | ||
var ieee754 = __importStar(require("./ieee754")); | ||
var utils_1 = require("./utils"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ieee754 = __importStar(require("./ieee754")); | ||
const utils_1 = require("./utils"); | ||
exports.MAGIC = [0x00, 0x61, 0x73, 0x6d]; | ||
@@ -59,3 +39,3 @@ exports.WASM_VERSION = [0x01, 0x00, 0x00, 0x00]; | ||
EXPORT: 7, | ||
CODE: 10 | ||
CODE: 10, | ||
}; | ||
@@ -66,3 +46,3 @@ exports.EXPORT_TYPE = { | ||
MEMORY: 0x02, | ||
GLOBAL: 0x03 | ||
GLOBAL: 0x03, | ||
}; | ||
@@ -76,12 +56,12 @@ exports.op = { | ||
// nop: 0x01, | ||
block: function (blockType) { return [0x02, blockType]; }, | ||
loop: function (blockType) { return [0x03, blockType]; }, | ||
"if": function (retType) { return [0x04, retType]; }, | ||
"else": 0x05, | ||
block: (blockType) => [0x02, blockType], | ||
loop: (blockType) => [0x03, blockType], | ||
if: (retType) => [0x04, retType], | ||
else: 0x05, | ||
end: 0x0b, | ||
// br: (i: number) => [0x0c, ...signedLEB128(i)], | ||
br_if: function (i) { return __spread([0x0d], unsignedLEB128(i)); }, | ||
br_if: (i) => [0x0d, ...unsignedLEB128(i)], | ||
// br_table: 0x0d, | ||
// return: 0x0f, | ||
call: function (i) { return __spread([0x10], unsignedLEB128(i)); }, | ||
call: (i) => [0x10, ...unsignedLEB128(i)], | ||
// call_indirect: 0x11, | ||
@@ -98,7 +78,7 @@ /* | ||
*/ | ||
local_get: function (i) { return __spread([0x20], unsignedLEB128(i)); }, | ||
local_set: function (i) { return __spread([0x21], unsignedLEB128(i)); }, | ||
local_tee: function (i) { return __spread([0x22], unsignedLEB128(i)); }, | ||
global_get: function (i) { return __spread([0x23], unsignedLEB128(i)); }, | ||
global_set: function (i) { return __spread([0x24], unsignedLEB128(i)); }, | ||
local_get: (i) => [0x20, ...unsignedLEB128(i)], | ||
local_set: (i) => [0x21, ...unsignedLEB128(i)], | ||
local_tee: (i) => [0x22, ...unsignedLEB128(i)], | ||
global_get: (i) => [0x23, ...unsignedLEB128(i)], | ||
global_set: (i) => [0x24, ...unsignedLEB128(i)], | ||
/* | ||
@@ -108,8 +88,12 @@ * Memory Instructions | ||
*/ | ||
f64_load: function (align, offset) { return __spread([ | ||
0x2b | ||
], unsignedLEB128(align), unsignedLEB128(offset)); }, | ||
f64_store: function (align, offset) { return __spread([ | ||
0x39 | ||
], unsignedLEB128(align), unsignedLEB128(offset)); }, | ||
f64_load: (align, offset) => [ | ||
0x2b, | ||
...unsignedLEB128(align), | ||
...unsignedLEB128(offset), | ||
], | ||
f64_store: (align, offset) => [ | ||
0x39, | ||
...unsignedLEB128(align), | ||
...unsignedLEB128(offset), | ||
], | ||
/* | ||
@@ -119,6 +103,6 @@ * Numeric Instructions | ||
*/ | ||
i32_const: function (i) { return __spread([0x41], signedLEB128(i)); }, | ||
i32_const: (i) => [0x41, ...signedLEB128(i)], | ||
// i64_const: 0x42, | ||
// f32_const: 0x43, | ||
f64_const: function (i) { return __spread([0x44], encodef64(i)); }, | ||
f64_const: (i) => [0x44, ...encodef64(i)], | ||
i32_eqz: 0x45, | ||
@@ -179,3 +163,3 @@ // i32_eq: 0x46, | ||
f64_convert_i64_s: 0xb9, | ||
f64_convert_i32_s: 0xb7 | ||
f64_convert_i32_s: 0xb7, | ||
}; | ||
@@ -187,14 +171,14 @@ // https://webassembly.github.io/spec/core/binary/instructions.html#binary-blocktype | ||
f32: 0x7d, | ||
f64: 0x7c | ||
f64: 0x7c, | ||
}; | ||
exports.MUTABILITY = { | ||
"const": 0x00, | ||
"var": 0x01 | ||
const: 0x00, | ||
var: 0x01, | ||
}; | ||
exports.BLOCK = { | ||
"void": 0x40, | ||
void: 0x40, | ||
i32: 0x7f, | ||
i64: 0x7e, | ||
f32: 0x7d, | ||
f64: 0x7c | ||
f64: 0x7c, | ||
}; | ||
@@ -209,15 +193,15 @@ // http://webassembly.github.io/spec/core/binary/types.html#function-types | ||
// within epsilon of zero. | ||
exports.IS_ZEROISH = __spread([ | ||
exports.op.f64_abs | ||
], exports.op.f64_const(exports.EPSILON), [ | ||
exports.IS_ZEROISH = [ | ||
exports.op.f64_abs, | ||
...exports.op.f64_const(exports.EPSILON), | ||
exports.op.f64_lt, | ||
]); | ||
exports.IS_NOT_ZEROISH = __spread([ | ||
exports.op.f64_abs | ||
], exports.op.f64_const(exports.EPSILON), [ | ||
]; | ||
exports.IS_NOT_ZEROISH = [ | ||
exports.op.f64_abs, | ||
...exports.op.f64_const(exports.EPSILON), | ||
exports.op.f64_gt, | ||
]); | ||
]; | ||
// f64 | ||
function encodef64(num) { | ||
var arr = new Uint8Array(8); | ||
const arr = new Uint8Array(8); | ||
ieee754.write(arr, num); | ||
@@ -227,9 +211,7 @@ return arr; | ||
exports.encodef64 = encodef64; | ||
exports.encodeString = function (str) { return __spread([ | ||
str.length | ||
], str.split("").map(function (s) { return s.charCodeAt(0); })); }; | ||
exports.encodeString = (str) => [str.length].concat(str.split("").map(s => s.charCodeAt(0))); | ||
function unsignedLEB128(n) { | ||
var buffer = []; | ||
const buffer = []; | ||
do { | ||
var byte = n & 0x7f; | ||
let byte = n & 0x7f; | ||
n >>>= 7; | ||
@@ -246,7 +228,7 @@ if (n !== 0) { | ||
function signedLEB128(value) { | ||
var bytes = []; | ||
var byte = 0x00; | ||
var size = Math.ceil(Math.log2(Math.abs(value))); | ||
var negative = value < 0; | ||
var more = true; | ||
let bytes = []; | ||
let byte = 0x00; | ||
let size = Math.ceil(Math.log2(Math.abs(value))); | ||
let negative = value < 0; | ||
let more = true; | ||
while (more) { | ||
@@ -272,3 +254,4 @@ byte = value & 127; | ||
// Vectors are encoded with their length followed by their element sequence | ||
exports.encodeVector = function (data) { return __spread(unsignedLEB128(data.length), utils_1.flattenTwice(data)); }; | ||
exports.encodeFlatVector = (data) => unsignedLEB128(data.length).concat(data); | ||
exports.encodeNestedVector = (data) => unsignedLEB128(data.length).concat(utils_1.flatten(data)); | ||
// subSections is an array of arrays | ||
@@ -284,5 +267,7 @@ function encodeSection(type, subSections) { | ||
// TODO: Remove this assertion once we are more confident in our output. | ||
return __spread([type], exports.encodeVector(exports.encodeVector(subSections))); | ||
const vec = exports.encodeFlatVector(exports.encodeNestedVector(subSections)); | ||
vec.unshift(type); | ||
return vec; | ||
} | ||
exports.encodeSection = encodeSection; | ||
//# sourceMappingURL=encoding.js.map |
// This module is in charge of selecting either the pre-built module or the one | ||
// that builds it a runtime with jison. | ||
var parserImpl = require("../build/parser"); | ||
let parserImpl = require("../build/parser"); | ||
/* | ||
@@ -5,0 +5,0 @@ let parserImpl = null; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
exports.__esModule = true; | ||
var utils_1 = require("./utils"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("./utils"); | ||
/* Build up a string showing a formatted source location in context with line numbers. | ||
@@ -24,18 +11,17 @@ * | ||
*/ | ||
function printLoc(loc, rawSource, contextLines) { | ||
if (contextLines === void 0) { contextLines = 1; } | ||
var firstIndex = Math.max(loc.first_line - 1 - contextLines, 0); | ||
var lastIndex = loc.last_line + contextLines; | ||
var sourceLines = rawSource.split("\n").slice(firstIndex, lastIndex); | ||
var annotatedLines = sourceLines.map(function (line, i) { | ||
var lineNumber = i + firstIndex + 1; | ||
var inRange = lineNumber >= loc.first_line && lineNumber <= loc.last_line; | ||
var gutter = inRange ? ">" : " "; | ||
return gutter + " " + lineNumber + " | " + line; | ||
function printLoc(loc, rawSource, contextLines = 1) { | ||
const firstIndex = Math.max(loc.first_line - 1 - contextLines, 0); | ||
const lastIndex = loc.last_line + contextLines; | ||
const sourceLines = rawSource.split("\n").slice(firstIndex, lastIndex); | ||
const annotatedLines = sourceLines.map((line, i) => { | ||
const lineNumber = i + firstIndex + 1; | ||
const inRange = lineNumber >= loc.first_line && lineNumber <= loc.last_line; | ||
const gutter = inRange ? ">" : " "; | ||
return `${gutter} ${lineNumber} | ${line}`; | ||
}); | ||
if (loc.first_line === loc.last_line) { | ||
var padding = utils_1.repeat(loc.first_column, " "); | ||
var underline = utils_1.repeat(loc.last_column - loc.first_column, "^"); | ||
var insertIndex = loc.first_line - firstIndex; | ||
annotatedLines.splice(insertIndex, 0, " | " + padding + underline); | ||
const padding = utils_1.repeat(loc.first_column, " "); | ||
const underline = utils_1.repeat(loc.last_column - loc.first_column, "^"); | ||
const insertIndex = loc.first_line - firstIndex; | ||
annotatedLines.splice(insertIndex, 0, ` | ${padding}${underline}`); | ||
} | ||
@@ -45,22 +31,14 @@ return annotatedLines.join("\n"); | ||
exports.printLoc = printLoc; | ||
var CompilerError = /** @class */ (function (_super) { | ||
__extends(CompilerError, _super); | ||
function CompilerError(message, loc, rawSource) { | ||
var _this = _super.call(this, message) || this; | ||
class CompilerError extends Error { | ||
constructor(message, loc, rawSource) { | ||
super(message); | ||
// TODO: Create an error message that encourages users to open an issue at | ||
// https://github.com/captbaritone/eel-wasm/issues is they see this, and gives | ||
// Them an easy way to attach the right context. | ||
_this.sourceContext = printLoc(loc, rawSource); | ||
_this.loc = loc; | ||
return _this; | ||
this.sourceContext = printLoc(loc, rawSource); | ||
this.loc = loc; | ||
} | ||
return CompilerError; | ||
}(Error)); | ||
var UserError = /** @class */ (function (_super) { | ||
__extends(UserError, _super); | ||
function UserError() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
return UserError; | ||
}(CompilerError)); | ||
} | ||
class UserError extends CompilerError { | ||
} | ||
function createUserError(message, loc, rawSource) { | ||
@@ -67,0 +45,0 @@ return new UserError(message, loc, rawSource); |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Copied from https://github.com/feross/ieee754/blob/master/index.js | ||
function write(buffer, value) { | ||
// Originally these four were arguments, but we only ever use it like this. | ||
var offset = 0; | ||
var isLE = true; | ||
var mLen = 52; | ||
var nBytes = 8; | ||
const offset = 0; | ||
const isLE = true; | ||
let mLen = 52; | ||
const nBytes = 8; | ||
var e, m, c; | ||
@@ -11,0 +11,0 @@ var eLen = nBytes * 8 - mLen - 1; |
@@ -5,11 +5,11 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
var parser_1 = require("./parser"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const parser_1 = require("./parser"); | ||
exports.parse = parser_1.parse; | ||
var compiler_1 = require("./compiler"); | ||
const compiler_1 = require("./compiler"); | ||
exports.compileModule = compiler_1.compileModule; | ||
var shims_1 = __importDefault(require("./shims")); | ||
exports.shims = shims_1["default"]; | ||
var loader_1 = require("./loader"); | ||
const shims_1 = __importDefault(require("./shims")); | ||
exports.shims = shims_1.default; | ||
const loader_1 = require("./loader"); | ||
exports.loadModule = loader_1.loadModule; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
var errorUtils_1 = require("./errorUtils"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const errorUtils_1 = require("./errorUtils"); | ||
function isZeroish(num) { | ||
return "(Math.abs(" + num + ") < 0.00001)"; | ||
return `(Math.abs(${num}) < 0.00001)`; | ||
} | ||
function isNotZeroish(num) { | ||
return "(Math.abs(" + num + ") > 0.00001)"; | ||
return `(Math.abs(${num}) > 0.00001)`; | ||
} | ||
// prettier-ignore | ||
var MATH_FUNCS = new Set(["abs", "min", "max", "sqrt", "sin", "cos", "tan", "asin", "acos", "atan", "atan2", "pow", "log", "log10", "floor", "ceil", "exp"]); | ||
var standardLibrary = "\nconst megabuf = new Array(1048576).fill(0);\nconst gmegabuf = new Array(1048576).fill(0);\nfunction sigmoid(x, y) {\n const t = 1 + Math.exp(-x * y);\n return Math.abs(t) > 0.00001 ? 1.0 / t : 0;\n}\n"; | ||
const MATH_FUNCS = new Set(["abs", "min", "max", "sqrt", "sin", "cos", "tan", "asin", "acos", "atan", "atan2", "pow", "log", "log10", "floor", "ceil", "exp"]); | ||
const standardLibrary = ` | ||
const megabuf = new Array(1048576).fill(0); | ||
const gmegabuf = new Array(1048576).fill(0); | ||
function sigmoid(x, y) { | ||
const t = 1 + Math.exp(-x * y); | ||
return Math.abs(t) > 0.00001 ? 1.0 / t : 0; | ||
} | ||
`; | ||
function emitter(ast, context) { | ||
switch (ast.type) { | ||
case "SCRIPT": { | ||
var expressions = ast.body.map(function (node) { | ||
const expressions = ast.body.map(node => { | ||
return emitter(node, context); | ||
@@ -22,66 +29,66 @@ }); | ||
case "EXPRESSION_BLOCK": { | ||
var expressions = ast.body.map(function (node) { | ||
const expressions = ast.body.map(node => { | ||
return emitter(node, context); | ||
}); | ||
return "(" + expressions.join(",") + ")"; | ||
return `(${expressions.join(",")})`; | ||
} | ||
case "ASSIGNMENT_EXPRESSION": { | ||
var right = emitter(ast.right, context); | ||
var assignee = void 0; | ||
const right = emitter(ast.right, context); | ||
let assignee; | ||
if (ast.left.type === "CALL_EXPRESSION") { | ||
var left = ast.left; | ||
const { left } = ast; | ||
if (left.arguments.length !== 1) { | ||
throw errorUtils_1.createUserError("Expected 1 argument when assinging to a buffer but got " + left.arguments.length + ".", left.arguments.length === 0 ? left.loc : left.arguments[1].loc, context.rawSource); | ||
throw errorUtils_1.createUserError(`Expected 1 argument when assinging to a buffer but got ${left.arguments.length}.`, left.arguments.length === 0 ? left.loc : left.arguments[1].loc, context.rawSource); | ||
} | ||
var bufferName = left.callee.value; | ||
const bufferName = left.callee.value; | ||
if (bufferName !== "gmegabuf" && bufferName !== "megabuf") { | ||
throw errorUtils_1.createUserError("The only function calls which may be assigned to are `gmegabuf()` and `megabuf()`.", left.callee.loc, context.rawSource); | ||
} | ||
var index = emitter(ast.left.arguments[0], context); | ||
assignee = bufferName + "[" + index + "]"; | ||
const index = emitter(ast.left.arguments[0], context); | ||
assignee = `${bufferName}[${index}]`; | ||
} | ||
else { | ||
assignee = "a[\"" + ast.left.value + "\"]"; | ||
assignee = `a["${ast.left.value}"]`; | ||
} | ||
return "(" + assignee + " " + ast.operator + " " + right + ")"; | ||
return `(${assignee} ${ast.operator} ${right})`; | ||
} | ||
case "BINARY_EXPRESSION": { | ||
var left = emitter(ast.left, context); | ||
var right = emitter(ast.right, context); | ||
var operator = ast.operator; | ||
const left = emitter(ast.left, context); | ||
const right = emitter(ast.right, context); | ||
const { operator } = ast; | ||
switch (operator) { | ||
case "^": | ||
return "Math.pow(" + left + ", " + right + ")"; | ||
return `Math.pow(${left}, ${right})`; | ||
case "==": { | ||
return "+" + isZeroish(left + " - " + right); | ||
return `+${isZeroish(`${left} - ${right}`)}`; | ||
} | ||
case "!=": { | ||
return "+" + isNotZeroish(left + " - " + right); | ||
return `+${isNotZeroish(`${left} - ${right}`)}`; | ||
} | ||
default: | ||
return "+(" + left + " " + ast.operator + " " + right + ")"; | ||
return `+(${left} ${ast.operator} ${right})`; | ||
} | ||
} | ||
case "UNARY_EXPRESSION": { | ||
var value = emitter(ast.value, context); | ||
var operator = ast.operator; | ||
const value = emitter(ast.value, context); | ||
const { operator } = ast; | ||
switch (operator) { | ||
case "!": | ||
return "+" + isZeroish(value); | ||
return `+${isZeroish(value)}`; | ||
default: | ||
return "(" + ast.operator + value + ")"; | ||
return `(${ast.operator}${value})`; | ||
} | ||
} | ||
case "LOGICAL_EXPRESSION": { | ||
var left = emitter(ast.left, context); | ||
var right = emitter(ast.right, context); | ||
return "+(!!(" + left + " " + ast.operator + " " + right + "))"; | ||
const left = emitter(ast.left, context); | ||
const right = emitter(ast.right, context); | ||
return `+(!!(${left} ${ast.operator} ${right}))`; | ||
} | ||
case "CALL_EXPRESSION": { | ||
var functionName = ast.callee.value; | ||
var args = ast.arguments.map(function (arg) { | ||
const functionName = ast.callee.value; | ||
const args = ast.arguments.map(arg => { | ||
return emitter(arg, context); | ||
}); | ||
if (MATH_FUNCS.has(functionName)) { | ||
return "Math." + functionName + "(" + args.join(",") + ")"; | ||
return `Math.${functionName}(${args.join(",")})`; | ||
} | ||
@@ -91,44 +98,55 @@ switch (functionName) { | ||
// Hack to handle -0 https://stackoverflow.com/a/53135516/12631177 | ||
return "(Math.sign(" + args[0] + ")+0)"; | ||
return `(Math.sign(${args[0]})+0)`; | ||
case "int": | ||
return "Math.floor(" + args[0] + ")"; | ||
return `Math.floor(${args[0]})`; | ||
case "bor": | ||
return "(function() {\n var x = " + isNotZeroish(args[0]) + "\n var y = " + isNotZeroish(args[1]) + "\n return x ? 1 : +y;\n })()"; | ||
return `(function() { | ||
var x = ${isNotZeroish(args[0])} | ||
var y = ${isNotZeroish(args[1])} | ||
return x ? 1 : +y; | ||
})()`; | ||
case "band": | ||
return "(function() {\n var x = " + isNotZeroish(args[0]) + "\n var y = " + isNotZeroish(args[1]) + "\n return x ? +y : 0;\n })()"; | ||
return `(function() { | ||
var x = ${isNotZeroish(args[0])} | ||
var y = ${isNotZeroish(args[1])} | ||
return x ? +y : 0; | ||
})()`; | ||
case "bnot": | ||
return "+" + isZeroish(args[0]); | ||
return `+${isZeroish(args[0])}`; | ||
case "sqr": | ||
return "(function(){\n var temp = " + args[0] + ";\n return temp * temp;\n })()"; | ||
return `(function(){ | ||
var temp = ${args[0]}; | ||
return temp * temp; | ||
})()`; | ||
case "assign": { | ||
var identifier = ast.arguments[0]; | ||
const identifier = ast.arguments[0]; | ||
if (identifier.type !== "IDENTIFIER") { | ||
throw errorUtils_1.createUserError("Expected the first argument of `assign()` to be an identifier.", identifier.loc, context.rawSource); | ||
} | ||
return "(a[\"" + identifier.value + "\"] = " + args[1] + ")"; | ||
return `(a["${identifier.value}"] = ${args[1]})`; | ||
} | ||
case "if": | ||
return "(" + args[0] + " ? " + args[1] + " : " + args[2] + ")"; | ||
return `(${args[0]} ? ${args[1]} : ${args[2]})`; | ||
case "above": | ||
return "+(" + args[0] + " > " + args[1] + ")"; | ||
return `+(${args[0]} > ${args[1]})`; | ||
case "below": | ||
return "+(" + args[0] + " < " + args[1] + ")"; | ||
return `+(${args[0]} < ${args[1]})`; | ||
case "equal": | ||
return "+(" + args[0] + " === " + args[1] + ")"; | ||
return `+(${args[0]} === ${args[1]})`; | ||
case "sigmoid": | ||
return "sigmoid(" + args[0] + ", " + args[1] + ")"; | ||
return `sigmoid(${args[0]}, ${args[1]})`; | ||
case "exec2": | ||
case "exec3": | ||
return "(" + args.join(", ") + ")"; | ||
return `(${args.join(", ")})`; | ||
// TODO: Should loop or while return something? | ||
case "loop": | ||
return "for(var count = " + args[0] + "; count > 0; count--) " + args[1]; | ||
return `for(var count = ${args[0]}; count > 0; count--) ${args[1]}`; | ||
case "while": | ||
return "while(" + args[0] + ") {}"; | ||
return `while(${args[0]}) {}`; | ||
case "megabuf": | ||
return "megabuf[" + args[0] + "]"; | ||
return `megabuf[${args[0]}]`; | ||
case "gmegabuf": | ||
return "gmegabuf[" + args[0] + "]"; | ||
return `gmegabuf[${args[0]}]`; | ||
default: | ||
throw new Error("Unknown function " + functionName); | ||
throw new Error(`Unknown function ${functionName}`); | ||
} | ||
@@ -140,3 +158,3 @@ } | ||
case "IDENTIFIER": { | ||
return "a[\"" + ast.value + "\"]"; | ||
return `a["${ast.value}"]`; | ||
} | ||
@@ -143,0 +161,0 @@ } |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
var shims_1 = __importDefault(require("./shims")); | ||
var compiler_1 = require("./compiler"); | ||
function loadModule(_a) { | ||
var pools = _a.pools, functions = _a.functions, _b = _a.eelVersion, eelVersion = _b === void 0 ? 2 : _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var compilerPools, buffer, mod, importObject; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
compilerPools = {}; | ||
Object.entries(pools).forEach(function (_a) { | ||
var _b = __read(_a, 2), key = _b[0], globals = _b[1]; | ||
compilerPools[key] = new Set(Object.keys(globals)); | ||
}); | ||
buffer = compiler_1.compileModule({ | ||
pools: compilerPools, | ||
functions: functions, | ||
eelVersion: eelVersion | ||
}); | ||
return [4 /*yield*/, WebAssembly.compile(buffer)]; | ||
case 1: | ||
mod = _c.sent(); | ||
importObject = __assign(__assign({}, pools), { shims: shims_1["default"] }); | ||
return [4 /*yield*/, WebAssembly.instantiate(mod, importObject)]; | ||
case 2: return [2 /*return*/, _c.sent()]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const shims_1 = __importDefault(require("./shims")); | ||
const compiler_1 = require("./compiler"); | ||
async function loadModule({ pools, functions, eelVersion = 2, }) { | ||
let compilerPools = {}; | ||
Object.entries(pools).forEach(([key, globals]) => { | ||
compilerPools[key] = new Set(Object.keys(globals)); | ||
}); | ||
const buffer = compiler_1.compileModule({ | ||
pools: compilerPools, | ||
functions, | ||
eelVersion, | ||
}); | ||
const mod = await WebAssembly.compile(buffer); | ||
var importObject = Object.assign(Object.assign({}, pools), { shims: shims_1.default }); | ||
return await WebAssembly.instantiate(mod, importObject); | ||
} | ||
exports.loadModule = loadModule; | ||
//# sourceMappingURL=loader.js.map |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
exports.__esModule = true; | ||
var preProcessor_1 = require("./preProcessor"); | ||
var envParser_1 = require("./envParser"); | ||
var astUtils_1 = require("./astUtils"); | ||
var errorUtils_1 = require("./errorUtils"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const preProcessor_1 = require("./preProcessor"); | ||
const envParser_1 = require("./envParser"); | ||
const astUtils_1 = require("./astUtils"); | ||
const errorUtils_1 = require("./errorUtils"); | ||
function mapLoc(loc, mapper) { | ||
var first = preProcessor_1.getLoc(mapper, loc.first_column); | ||
var last = preProcessor_1.getLoc(mapper, loc.last_column); | ||
const first = preProcessor_1.getLoc(mapper, loc.first_column); | ||
const last = preProcessor_1.getLoc(mapper, loc.last_column); | ||
return { | ||
@@ -41,14 +14,14 @@ first_column: first.column, | ||
first_line: first.line, | ||
last_line: last.line | ||
last_line: last.line, | ||
}; | ||
} | ||
function parse(code) { | ||
var _a = __read(preProcessor_1.preProcess(code), 2), processedCode = _a[0], mapper = _a[1]; | ||
const [processedCode, mapper] = preProcessor_1.preProcess(code); | ||
try { | ||
var ast = envParser_1.parse(processedCode); | ||
return astUtils_1.mapAst(ast, function (node) { | ||
const ast = envParser_1.parse(processedCode); | ||
return astUtils_1.mapAst(ast, (node) => { | ||
if (node.loc.first_line !== 1 || node.loc.last_line != 1) { | ||
throw errorUtils_1.createCompilerError("Unexpected multiline", node.loc, code); | ||
} | ||
return __assign(__assign({}, node), { loc: mapLoc(node.loc, mapper) }); | ||
return Object.assign(Object.assign({}, node), { loc: mapLoc(node.loc, mapper) }); | ||
}); | ||
@@ -60,3 +33,3 @@ } | ||
} | ||
throw errorUtils_1.createUserError("Parse Error: " + e.message.split("\n")[3], mapLoc(e.hash.loc, mapper), code); | ||
throw errorUtils_1.createUserError(`Parse Error: ${e.message.split("\n")[3]}`, mapLoc(e.hash.loc, mapper), code); | ||
} | ||
@@ -63,0 +36,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function getLoc(mapper, destCol) { | ||
var previousAnchor = { destCol: 1, srcCol: 1, srcLine: 1 }; | ||
let previousAnchor = { destCol: 1, srcCol: 1, srcLine: 1 }; | ||
// Find the last anchor with a destCol > destCol. | ||
// Reversed: Find the first anchor with a destCol <= destCol | ||
// TODO: Use binary search | ||
mapper.forEach(function (anchor) { | ||
mapper.forEach(anchor => { | ||
if (anchor.destCol > destCol) { | ||
@@ -14,6 +14,6 @@ return; | ||
}); | ||
var remainingColumns = destCol - previousAnchor.destCol; | ||
const remainingColumns = destCol - previousAnchor.destCol; | ||
return { | ||
column: previousAnchor.srcCol + remainingColumns, | ||
line: previousAnchor.srcLine | ||
line: previousAnchor.srcLine, | ||
}; | ||
@@ -24,15 +24,15 @@ } | ||
function preProcess(src) { | ||
var mapper = []; | ||
var srcLine = 1; | ||
var dest = ""; | ||
var lineStart = 0; | ||
var inlineComment = false; | ||
var blockComment = false; | ||
var emitAnchor = false; | ||
for (var i = 0; i < src.length; i++) { | ||
var char = src[i]; | ||
const mapper = []; | ||
let srcLine = 1; | ||
let dest = ""; | ||
let lineStart = 0; | ||
let inlineComment = false; | ||
let blockComment = false; | ||
let emitAnchor = false; | ||
for (let i = 0; i < src.length; i++) { | ||
const char = src[i]; | ||
if (emitAnchor) { | ||
var destCol = dest.length + 1; | ||
var srcCol = i - lineStart + 1; | ||
mapper.push({ destCol: destCol, srcCol: srcCol, srcLine: srcLine }); | ||
const destCol = dest.length + 1; | ||
const srcCol = i - lineStart + 1; | ||
mapper.push({ destCol, srcCol, srcLine }); | ||
emitAnchor = false; | ||
@@ -39,0 +39,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
var EPSILON = 0.00001; | ||
var shims = { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const EPSILON = 0.00001; | ||
const shims = { | ||
// TODO: Reimplement some of these functions natively in Wasm? | ||
@@ -13,3 +13,3 @@ sin: Math.sin, | ||
atan2: Math.atan2, | ||
rand: function (a) { return Math.random() * a; }, | ||
rand: a => Math.random() * a, | ||
pow: Math.pow, | ||
@@ -20,7 +20,7 @@ log: Math.log, | ||
sigmoid: function (x, y) { | ||
var t = 1 + Math.exp(-x * y); | ||
const t = 1 + Math.exp(-x * y); | ||
return Math.abs(t) > EPSILON ? 1.0 / t : 0; | ||
} | ||
}, | ||
}; | ||
exports["default"] = shims; | ||
exports.default = shims; | ||
//# sourceMappingURL=shims.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=types.js.map |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function arrayJoin(arr, joiner) { | ||
var newArr = []; | ||
for (var i = 0; i < arr.length; i++) { | ||
const newArr = []; | ||
for (let i = 0; i < arr.length; i++) { | ||
newArr.push(arr[i]); | ||
var last = i === arr.length - 1; | ||
const last = i === arr.length - 1; | ||
if (!last) { | ||
@@ -36,14 +16,7 @@ newArr.push(joiner); | ||
function flatten(arr) { | ||
var newArr = []; | ||
arr.forEach(function (subArr) { | ||
newArr.push.apply(newArr, __spread(subArr)); | ||
}); | ||
return newArr; | ||
return [].concat.apply([], arr); | ||
} | ||
exports.flatten = flatten; | ||
exports.flattenTwice = function (arr) { | ||
return [].concat.apply([], arr); | ||
}; | ||
function times(n, cb) { | ||
return new Array(n).fill(null).map(function (_, i) { return cb(i); }); | ||
return new Array(n).fill(null).map((_, i) => cb(i)); | ||
} | ||
@@ -63,26 +36,19 @@ exports.times = times; | ||
// variable that exists in all namespaces. | ||
// | ||
// TODO: We could improve this with a map to get constant time lookups, but I | ||
// suspect it's not worth the complexity. | ||
var ScopedIdMap = /** @class */ (function () { | ||
function ScopedIdMap() { | ||
this._list = []; | ||
class ScopedIdMap { | ||
constructor() { | ||
this._map = new Map(); | ||
} | ||
// Get the index of a given namespace/key pair | ||
ScopedIdMap.prototype.get = function (namespace, key) { | ||
var i = this._list.findIndex(function (_a) { | ||
var _b = __read(_a, 2), n = _b[0], k = _b[1]; | ||
return n === namespace && k === key; | ||
}); | ||
if (i === -1) { | ||
this._list.push([namespace, key]); | ||
return this._list.length - 1; | ||
get(namespace, key) { | ||
const jointKey = namespace == null ? key : `${namespace}::${key}`; | ||
if (!this._map.has(jointKey)) { | ||
this._map.set(jointKey, this._map.size); | ||
} | ||
return i; | ||
}; | ||
ScopedIdMap.prototype.size = function () { | ||
return this._list.length; | ||
}; | ||
return ScopedIdMap; | ||
}()); | ||
// @ts-ignore We know the key is here. | ||
return this._map.get(jointKey); | ||
} | ||
size() { | ||
return this._map.size; | ||
} | ||
} | ||
exports.ScopedIdMap = ScopedIdMap; | ||
@@ -96,7 +62,7 @@ function formatList(list) { | ||
} | ||
var quoted = list.map(function (name) { return "\"" + name + "\""; }); | ||
var last = quoted.pop(); | ||
return quoted.join(", ") + (" and " + last); | ||
const quoted = list.map(name => `"${name}"`); | ||
const last = quoted.pop(); | ||
return quoted.join(", ") + ` and ${last}`; | ||
} | ||
exports.formatList = formatList; | ||
//# sourceMappingURL=utils.js.map |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
exports.__esModule = true; | ||
var encoding_1 = require("./encoding"); | ||
var constants_1 = require("./constants"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const encoding_1 = require("./encoding"); | ||
const constants_1 = require("./constants"); | ||
exports.localFuncMap = { | ||
@@ -29,3 +9,3 @@ sqr: { | ||
returns: [encoding_1.VAL_TYPE.f64], | ||
binary: __spread(encoding_1.op.local_get(0), encoding_1.op.local_get(0), [encoding_1.op.f64_mul]) | ||
binary: [...encoding_1.op.local_get(0), ...encoding_1.op.local_get(0), encoding_1.op.f64_mul], | ||
}, | ||
@@ -35,8 +15,12 @@ bor: { | ||
returns: [encoding_1.VAL_TYPE.f64], | ||
binary: __spread(encoding_1.op.local_get(0), encoding_1.IS_NOT_ZEROISH, encoding_1.op.local_get(1), encoding_1.IS_NOT_ZEROISH, [ | ||
encoding_1.op.i32_or | ||
], encoding_1.op.i32_const(0), [ | ||
binary: [ | ||
...encoding_1.op.local_get(0), | ||
...encoding_1.IS_NOT_ZEROISH, | ||
...encoding_1.op.local_get(1), | ||
...encoding_1.IS_NOT_ZEROISH, | ||
encoding_1.op.i32_or, | ||
...encoding_1.op.i32_const(0), | ||
encoding_1.op.i32_ne, | ||
encoding_1.op.f64_convert_i32_s, | ||
]) | ||
], | ||
}, | ||
@@ -46,8 +30,12 @@ band: { | ||
returns: [encoding_1.VAL_TYPE.f64], | ||
binary: __spread(encoding_1.op.local_get(0), encoding_1.IS_NOT_ZEROISH, encoding_1.op.local_get(1), encoding_1.IS_NOT_ZEROISH, [ | ||
encoding_1.op.i32_and | ||
], encoding_1.op.i32_const(0), [ | ||
binary: [ | ||
...encoding_1.op.local_get(0), | ||
...encoding_1.IS_NOT_ZEROISH, | ||
...encoding_1.op.local_get(1), | ||
...encoding_1.IS_NOT_ZEROISH, | ||
encoding_1.op.i32_and, | ||
...encoding_1.op.i32_const(0), | ||
encoding_1.op.i32_ne, | ||
encoding_1.op.f64_convert_i32_s, | ||
]) | ||
], | ||
}, | ||
@@ -57,9 +45,12 @@ sign: { | ||
returns: [encoding_1.VAL_TYPE.f64], | ||
binary: __spread(encoding_1.op.f64_const(0), encoding_1.op.local_get(0), [ | ||
encoding_1.op.f64_lt | ||
], encoding_1.op.local_get(0), encoding_1.op.f64_const(0), [ | ||
binary: [ | ||
...encoding_1.op.f64_const(0), | ||
...encoding_1.op.local_get(0), | ||
encoding_1.op.f64_lt, | ||
...encoding_1.op.local_get(0), | ||
...encoding_1.op.f64_const(0), | ||
encoding_1.op.f64_lt, | ||
encoding_1.op.i32_sub, | ||
encoding_1.op.f64_convert_i32_s, | ||
]) | ||
], | ||
}, | ||
@@ -70,14 +61,17 @@ mod: { | ||
// TODO: Simplify all this type coersion | ||
binary: __spread(encoding_1.op.local_get(1), encoding_1.op.f64_const(0), [ | ||
encoding_1.op.f64_ne | ||
], encoding_1.op["if"](encoding_1.BLOCK.f64), encoding_1.op.local_get(0), [ | ||
encoding_1.op.i64_trunc_s_f64 | ||
], encoding_1.op.local_get(1), [ | ||
binary: [ | ||
...encoding_1.op.local_get(1), | ||
...encoding_1.op.f64_const(0), | ||
encoding_1.op.f64_ne, | ||
...encoding_1.op.if(encoding_1.BLOCK.f64), | ||
...encoding_1.op.local_get(0), | ||
encoding_1.op.i64_trunc_s_f64, | ||
...encoding_1.op.local_get(1), | ||
encoding_1.op.i64_trunc_s_f64, | ||
encoding_1.op.i64_rem_s, | ||
encoding_1.op.f64_convert_i64_s, | ||
encoding_1.op["else"] | ||
], encoding_1.op.f64_const(0), [ | ||
encoding_1.op.else, | ||
...encoding_1.op.f64_const(0), | ||
encoding_1.op.end, | ||
]) | ||
], | ||
}, | ||
@@ -87,9 +81,10 @@ bitwiseOr: { | ||
returns: [encoding_1.VAL_TYPE.f64], | ||
binary: __spread(encoding_1.op.local_get(0), [ | ||
encoding_1.op.i64_trunc_s_f64 | ||
], encoding_1.op.local_get(1), [ | ||
binary: [ | ||
...encoding_1.op.local_get(0), | ||
encoding_1.op.i64_trunc_s_f64, | ||
...encoding_1.op.local_get(1), | ||
encoding_1.op.i64_trunc_s_f64, | ||
encoding_1.op.i64_or, | ||
encoding_1.op.f64_convert_i64_s, | ||
]) | ||
], | ||
}, | ||
@@ -99,9 +94,10 @@ bitwiseAnd: { | ||
returns: [encoding_1.VAL_TYPE.f64], | ||
binary: __spread(encoding_1.op.local_get(0), [ | ||
encoding_1.op.i64_trunc_s_f64 | ||
], encoding_1.op.local_get(1), [ | ||
binary: [ | ||
...encoding_1.op.local_get(0), | ||
encoding_1.op.i64_trunc_s_f64, | ||
...encoding_1.op.local_get(1), | ||
encoding_1.op.i64_trunc_s_f64, | ||
encoding_1.op.i64_and, | ||
encoding_1.op.f64_convert_i64_s, | ||
]) | ||
], | ||
}, | ||
@@ -112,10 +108,14 @@ div: { | ||
localVariables: [encoding_1.VAL_TYPE.i32], | ||
binary: __spread(encoding_1.op.local_get(1), encoding_1.op.f64_const(0), [ | ||
encoding_1.op.f64_ne | ||
], encoding_1.op["if"](encoding_1.BLOCK.f64), encoding_1.op.local_get(0), encoding_1.op.local_get(1), [ | ||
binary: [ | ||
...encoding_1.op.local_get(1), | ||
...encoding_1.op.f64_const(0), | ||
encoding_1.op.f64_ne, | ||
...encoding_1.op.if(encoding_1.BLOCK.f64), | ||
...encoding_1.op.local_get(0), | ||
...encoding_1.op.local_get(1), | ||
encoding_1.op.f64_div, | ||
encoding_1.op["else"] | ||
], encoding_1.op.f64_const(0), [ | ||
encoding_1.op.else, | ||
...encoding_1.op.f64_const(0), | ||
encoding_1.op.end, | ||
]) | ||
], | ||
}, | ||
@@ -140,12 +140,25 @@ // Takes a float buffer index and converts it to an int. Values out of range | ||
], | ||
binary: __spread(encoding_1.op.f64_const(encoding_1.EPSILON), encoding_1.op.local_get(0), [ | ||
encoding_1.op.f64_add | ||
], encoding_1.op.local_tee(1), [ | ||
encoding_1.op.i32_trunc_f64_s | ||
], encoding_1.op.local_set(2), encoding_1.op.i32_const(-1), encoding_1.op.local_get(2), encoding_1.op.i32_const(8), [ | ||
encoding_1.op.i32_mul | ||
], encoding_1.op.local_get(2), encoding_1.op.i32_const(0), [ | ||
binary: [ | ||
...encoding_1.op.f64_const(encoding_1.EPSILON), | ||
...encoding_1.op.local_get(0), | ||
encoding_1.op.f64_add, | ||
// STACK: [$i + EPSILON] | ||
...encoding_1.op.local_tee(1), | ||
encoding_1.op.i32_trunc_f64_s, | ||
// TODO We could probably make this a tee and get rid of the next get if we swap the final condition | ||
...encoding_1.op.local_set(2), | ||
// STACK: [] | ||
...encoding_1.op.i32_const(-1), | ||
...encoding_1.op.local_get(2), | ||
// STACK: [-1, $truncated] | ||
...encoding_1.op.i32_const(8), | ||
encoding_1.op.i32_mul, | ||
// STACK: [-1, $truncated * 8] | ||
...encoding_1.op.local_get(2), | ||
...encoding_1.op.i32_const(0), | ||
// STACK: [-1, $truncated * 8, $truncated, 0] | ||
encoding_1.op.i32_lt_s | ||
], encoding_1.op.local_get(2), encoding_1.op.i32_const(constants_1.BUFFER_SIZE - 1), [ | ||
encoding_1.op.i32_lt_s, | ||
// STACK: [-1, $truncated * 8, <is index less than 0>] | ||
...encoding_1.op.local_get(2), | ||
...encoding_1.op.i32_const(constants_1.BUFFER_SIZE - 1), | ||
encoding_1.op.i32_gt_s, | ||
@@ -156,5 +169,5 @@ // STACK: [-1, $truncated * 8, <is index less than 0>, <is index more than MAX>] | ||
encoding_1.op.select, | ||
]) | ||
} | ||
], | ||
}, | ||
}; | ||
//# sourceMappingURL=wasmFunctions.js.map |
@@ -1,2 +0,2 @@ | ||
var MILKDROP_GLOBALS = [ | ||
const MILKDROP_GLOBALS = [ | ||
// Per frame | ||
@@ -145,12 +145,12 @@ "enabled", | ||
// q1 - q32 | ||
for (var i = 1; i <= 32; i++) { | ||
MILKDROP_GLOBALS.push("q" + i); | ||
for (let i = 1; i <= 32; i++) { | ||
MILKDROP_GLOBALS.push(`q${i}`); | ||
} | ||
// t1-t8 | ||
for (var i = 1; i <= 8; i++) { | ||
MILKDROP_GLOBALS.push("t" + i); | ||
for (let i = 1; i <= 8; i++) { | ||
MILKDROP_GLOBALS.push(`t${i}`); | ||
} | ||
// reg00-reg99 | ||
for (var i = 0; i <= 99; i++) { | ||
MILKDROP_GLOBALS.push("reg" + i); | ||
for (let i = 0; i <= 99; i++) { | ||
MILKDROP_GLOBALS.push(`reg${i}`); | ||
} | ||
@@ -157,0 +157,0 @@ // TODO: Arrays megabuf and gmegabuf |
"use strict"; | ||
exports.__esModule = true; | ||
var testCases = [ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const testCases = [ | ||
["Expressions", "g = ((6- -7)+ 3);", 16], | ||
@@ -203,3 +203,3 @@ ["Number", "g = 5;", 5], | ||
]; | ||
exports["default"] = testCases; | ||
exports.default = testCases; | ||
//# sourceMappingURL=testCases.js.map |
{ | ||
"name": "eel-wasm", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
336729
3564