diff --git a/bin/gpu-core.js b/bin/gpu-core.js index 9c3c1be4..2dd2178c 100644 --- a/bin/gpu-core.js +++ b/bin/gpu-core.js @@ -4,8 +4,8 @@ * * GPU Accelerated JavaScript * - * @version 1.10.3 - * @date Sun Nov 18 2018 14:38:47 GMT-0500 (EST) + * @version 1.10.4 + * @date Sun Nov 18 2018 15:47:22 GMT-0500 (EST) * * @license MIT * The MIT License diff --git a/bin/gpu-core.min.js b/bin/gpu-core.min.js index ce0063f9..3839543e 100644 --- a/bin/gpu-core.min.js +++ b/bin/gpu-core.min.js @@ -4,8 +4,8 @@ * * GPU Accelerated JavaScript * - * @version 1.10.3 - * @date Sun Nov 18 2018 14:38:47 GMT-0500 (EST) + * @version 1.10.4 + * @date Sun Nov 18 2018 15:47:22 GMT-0500 (EST) * * @license MIT * The MIT License diff --git a/bin/gpu.js b/bin/gpu.js index aed72119..8175c3a5 100644 --- a/bin/gpu.js +++ b/bin/gpu.js @@ -4,8 +4,8 @@ * * GPU Accelerated JavaScript * - * @version 1.10.3 - * @date Sun Nov 18 2018 14:38:47 GMT-0500 (EST) + * @version 1.10.4 + * @date Sun Nov 18 2018 15:47:22 GMT-0500 (EST) * * @license MIT * The MIT License @@ -890,7 +890,9 @@ module.exports = function (_KernelBase) { this.setupParams(arguments); this.validateOptions(); var canvas = this._canvas; - this._canvasCtx = canvas.getContext('2d'); + if (canvas) { + this._canvasCtx = canvas.getContext('2d'); + } var threadDim = this.threadDim = utils.clone(this.output); while (threadDim.length < 3) { @@ -898,8 +900,12 @@ module.exports = function (_KernelBase) { } if (this.graphical) { - canvas.width = threadDim[0]; - canvas.height = threadDim[1]; + var _canvas = this._canvas; + if (!_canvas) { + throw new Error('no canvas available for using graphical output'); + } + _canvas.width = threadDim[0]; + _canvas.height = threadDim[1]; this._imageData = this._canvasCtx.createImageData(threadDim[0], threadDim[1]); this._colorData = new Uint8ClampedArray(threadDim[0] * threadDim[1] * 4); } diff --git a/bin/gpu.min.js b/bin/gpu.min.js index 7377dbc6..f4ee9c0c 100644 --- a/bin/gpu.min.js +++ b/bin/gpu.min.js @@ -4,16 +4,16 @@ * * GPU Accelerated JavaScript * - * @version 1.10.3 - * @date Sun Nov 18 2018 14:38:47 GMT-0500 (EST) + * @version 1.10.4 + * @date Sun Nov 18 2018 15:47:22 GMT-0500 (EST) * * @license MIT * The MIT License * * Copyright (c) 2018 gpu.js Team */ -"use strict";!function(){function t(e,n,r){function i(a,o){if(!n[a]){if(!e[a]){var u="function"==typeof require&&require;if(!o&&u)return u(a,!0);if(s)return s(a,!0);var h=new Error("Cannot find module '"+a+"'");throw h.code="MODULE_NOT_FOUND",h}var c=n[a]={exports:{}};e[a][0].call(c.exports,function(t){var n=e[a][1][t];return i(n||t)},c,c.exports,t,e,n,r)}return n[a].exports}for(var s="function"==typeof require&&require,a=0;a0&&e.push(", "),e.push("user_"),e.push(this.paramNames[n]);return e.push(");\n"),e}},{key:"astFunctionExpression",value:function(t,e){if(!this.isRootKernel){e.push("function"),e.push(" "),e.push(this.functionName),e.push("(");for(var n=0;n0&&e.push(", "),e.push("user_"),e.push(r)}e.push(") {\n")}for(var i=0;i1){for(var s=null,a=0;a0&&e.push(","),this.astGeneric(t.declarations[n],e);return e.push(";"),e}},{key:"astVariableDeclarator",value:function(t,e){return this.astGeneric(t.id,e),null!==t.init&&(e.push("="),this.astGeneric(t.init,e)),e}},{key:"astIfStatement",value:function(t,e){return e.push("if ("),this.astGeneric(t.test,e),e.push(")"),"BlockStatement"===t.consequent.type?this.astGeneric(t.consequent,e):(e.push(" {\n"),this.astGeneric(t.consequent,e),e.push("\n}\n")),t.alternate&&(e.push("else "),"BlockStatement"===t.alternate.type?this.astGeneric(t.alternate,e):(e.push(" {\n"),this.astGeneric(t.alternate,e),e.push("\n}\n"))),e}},{key:"astBreakStatement",value:function(t,e){return e.push("break;\n"),e}},{key:"astContinueStatement",value:function(t,e){return e.push("continue;\n"),e}},{key:"astLogicalExpression",value:function(t,e){return e.push("("),this.astGeneric(t.left,e),e.push(t.operator),this.astGeneric(t.right,e),e.push(")"),e}},{key:"astUpdateExpression",value:function(t,e){return t.prefix?(e.push(t.operator),this.astGeneric(t.argument,e)):(this.astGeneric(t.argument,e),e.push(t.operator)),e}},{key:"astUnaryExpression",value:function(t,e){return t.prefix?(e.push(t.operator),this.astGeneric(t.argument,e)):(this.astGeneric(t.argument,e),e.push(t.operator)),e}},{key:"astThisExpression",value:function(t,e){return e.push("_this"),e}},{key:"astMemberExpression",value:function(t,e){if(t.computed)if("Identifier"===t.object.type||"MemberExpression"===t.object.type&&t.object.object.object&&"ThisExpression"===t.object.object.object.type&&"constants"===t.object.object.property.name)this.pushState("identifier"),this.astGeneric(t.object,e),this.popState("identifier"),e.push("["),this.isInput(t.object.name)?this.astGeneric(t.property,e):this.astGeneric(t.property,e),e.push("]");else if(t.object.object)if(t.object.object.object&&this.isInput(t.object.object.object.name)){this.pushMemberState(t.object.object.object.name),this.pushState("input-index-z"),this.astGeneric(t.object,e);var n=e.pop();e.push(" + "),this.popState("input-index-z"),this.pushState("input-index"),this.astGeneric(t.property,e),this.popState("input-index"),e.push(n),this.popMemberState(t.object.object.object.name)}else if(this.isInput(t.object.object.name)){this.pushMemberState(t.object.object.name),this.isState("input-index-z")||this.pushState("input-index-y"),this.astGeneric(t.object,e);var r=e.pop();e.push(" + "),this.isState("input-index-z")||this.popState("input-index-y");var i=this.isState("input-index-z");i?this.pushState("input-index-y"):this.pushState("input-index"),this.astGeneric(t.property,e),i?this.popState("input-index-y"):this.popState("input-index"),e.push(r),this.popMemberState(t.object.object.name)}else{this.astGeneric(t.object,e);var s=e.pop();e.push("]["),this.astGeneric(t.property,e),e.push(s)}else{this.astGeneric(t.object,e);var a=e.pop();e.push("]["),this.astGeneric(t.property,e),e.push(a)}else{var o=this.astMemberExpressionUnroll(t);switch("Identifier"===t.property.type&&t.computed&&(o="user_"+o),0===o.indexOf("this.constants")?o="constants_"+o.substring(15):0===o.indexOf("this")&&(o="_"+o),this.state){case"input-index-y":case"input-index-z":e.push("(")}switch(o){case"_this.output.x":e.push(this.output[0]);break;case"_this.output.y":e.push(this.output[1]);break;case"_this.output.z":e.push(this.output[2]);break;default:t.object&&t.object.name&&this.declarations[t.object.name]&&e.push("user_"),e.push(o)}switch(this.state){case"input-index-y":var u=this.paramSizes[this.paramNames.indexOf(this.memberState)];e.push(" * "+u[0]+")");break;case"input-index-z":var h=this.paramSizes[this.paramNames.indexOf(this.memberState)];e.push(" * "+h[0]*h[1]+")")}}return e}},{key:"astSequenceExpression",value:function(t,e){for(var n=0;n0&&e.push(","),this.astGeneric(t.expressions,e);return e}},{key:"astCallExpression",value:function(t,e){if(t.callee){var n=this.astMemberExpressionUnroll(t.callee);this.calledFunctions.indexOf(n)<0&&this.calledFunctions.push(n),this.hasOwnProperty("funcName")||(this.calledFunctionsArguments[n]=[]);var r=[];this.calledFunctionsArguments[n].push(r),e.push(n),e.push("(");for(var i=0;i0&&e.push(", "),this.astGeneric(s,e),"Identifier"===s.type){var a=this.paramNames.indexOf(s.name);a===-1?r.push(null):r.push({name:s.name,type:this.paramTypes[a]})}else r.push(null)}return e.push(")"),e}throw this.astErrorOutput("Unknown CallExpression",t)}},{key:"astArrayExpression",value:function(t,e){var n=t.elements.length;e.push("[");for(var r=0;r0&&e.push(", ");var i=t.elements[r];this.astGeneric(i,e)}return e.push("]"),e}},{key:"astDebuggerStatement",value:function(t,e){return e.push("debugger;"),e}},{key:"memberState",get:function(){return this.memberStates[this.memberStates.length-1]}}]),e}(o)},{"../../core/utils":32,"../function-node-base":7}],3:[function(t,e,n){function r(t){return/^function /.test(t)&&(t=t.substring(9)),t.replace(/[_]typeof/g,"typeof")}function i(t){return t.replace(/[_]typeof/g,"typeof")}var s=t("../../core/utils"),a=t("../kernel-run-shortcut");e.exports=function(t,e){return"() => {\n "+a.toString()+";\n const utils = {\n allPropertiesOf: "+i(s.allPropertiesOf.toString())+",\n clone: "+i(s.clone.toString())+",\n checkOutput: "+i(s.checkOutput.toString())+"\n };\n const Utils = utils;\n let Input = function() {};\n class "+(e||"Kernel")+" {\n constructor() { \n this.argumentsLength = 0;\n this._canvas = null;\n this._webGl = null;\n this.built = false;\n this.program = null;\n this.paramNames = "+JSON.stringify(t.paramNames)+";\n this.paramTypes = "+JSON.stringify(t.paramTypes)+";\n this.texSize = "+JSON.stringify(t.texSize)+";\n this.output = "+JSON.stringify(t.output)+";\n this._kernelString = `"+t._kernelString+"`;\n this.output = "+JSON.stringify(t.output)+";\n\t\t this.run = function() {\n this.run = null;\n this.build();\n return this.run.apply(this, arguments);\n }.bind(this);\n this.thread = {\n x: 0,\n y: 0,\n z: 0\n };\n }\n setCanvas(canvas) { this._canvas = canvas; return this; }\n setWebGl(webGl) { this._webGl = webGl; return this; }\n setInput(Type) { Input = Type; }\n "+r(t.build.toString())+"\n "+r(t.setupParams.toString())+"\n "+r(t.setupConstants.toString())+"\n run () { "+t.kernelString+" }\n getKernelString() { return this._kernelString; }\n "+r(t.validateOptions.toString())+"\n };\n return kernelRunShortcut(new Kernel());\n };"}},{"../../core/utils":32,"../kernel-run-shortcut":9}],4:[function(t,e,n){function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var a=function(){function t(t,e){for(var n=0;n1?o=o.filter(function(t){return/^function/.test(t)?t:(h=t,!1)}):h=o.shift();var c=this._kernelString="\n\t\tvar LOOP_MAX = "+this._getLoopMaxString()+"\n\t\tvar constants = this.constants;\n\t\tvar _this = this;\n return function ("+this.paramNames.map(function(t){return"user_"+t}).join(", ")+") {\n "+this._processConstants()+"\n "+this._processParams()+"\n "+this._kernelLoop(h)+"\n if (this.graphical) {\n this._imageData.data.set(this._colorData);\n this._canvasCtx.putImageData(this._imageData, 0, 0);\n return;\n }\n "+this._kernelOutput()+"\n "+(o.length>0?o.join("\n"):"")+"\n }.bind(this);";return c}},{key:"toString",value:function(){return h(this)}},{key:"_getLoopMaxString",value:function(){return this.loopMaxIterations?" "+parseInt(this.loopMaxIterations)+";\n":" 1000;\n"}},{key:"_processConstants",value:function(){if(!this.constants)return"";var t=[];for(var e in this.constants){var n=this.constantTypes[e];switch(n){case"HTMLImage":t.push(" var constants_"+e+" = this._imageTo2DArray(this.constants."+e+")");break;case"HTMLImageArray":t.push(" var constants_"+e+" = this._imageTo3DArray(this.constants."+e+")");break;case"Input":t.push(" var constants_"+e+" = this.constants."+e+".value");break;default:t.push(" var constants_"+e+" = this.constants."+e)}}return t.join("\n")}},{key:"_processParams",value:function(){for(var t=[],e=0;e=0;a--){i[a]=new Array(t.width);for(var o=0;o=0||e.push(t)),e}},{key:"addKernel",value:function(t,e){var n=new this.Node("kernel",t,e);return n.setBuilder(this),n.isRootKernel=!0,this.addFunctionNode(n),n}},{key:"addSubKernel",value:function(t,e){var n=new this.Node(null,t,e);return n.setBuilder(this),n.isSubKernel=!0,this.addFunctionNode(n),n}},{key:"getPrototypeString",value:function(t){return this.getPrototypes(t).join("\n")}},{key:"getPrototypes",value:function(t){return this.rootKernel.generate(),t?this.getPrototypesFromFunctionNames(this.traceFunctionCalls(t,[]).reverse()):this.getPrototypesFromFunctionNames(Object.keys(this.nodeMap))}},{key:"getStringFromFunctionNames",value:function(t){for(var e=[],n=0;n ("+r.length+","+this.paramNames.length+")";this.paramTypes=r}else if("object"===("undefined"==typeof r?"undefined":_typeof(r))){var s=Object.keys(r);if(r.hasOwnProperty("returns")&&(this.returnType=r.returns,s.splice(s.indexOf("returns"),1)),s.length>0&&s.length!==this.paramNames.length)throw"Invalid argument type array length, against function length -> ("+s.length+","+this.paramNames.length+")";this.paramTypes=this.paramNames.map(function(t){return r.hasOwnProperty(t)?r[t]:"Number"})}}else this.paramTypes=[];this.returnType||(this.returnType=i||"Number")}return _createClass(BaseFunctionNode,[{key:"isIdentifierConstant",value:function(t){return!!this.constants&&this.constants.hasOwnProperty(t)}},{key:"isInput",value:function(t){return"Input"===this.paramTypes[this.paramNames.indexOf(t)]}},{key:"setBuilder",value:function(t){return this.builder=t,this}},{key:"pushState",value:function(t){this.states.push(t)}},{key:"popState",value:function(t){if(this.state!==t)throw new Error("Cannot popState "+t+" when in "+this.state); -this.states.pop()}},{key:"isState",value:function(t){return this.state===t}},{key:"getJsFunction",value:function getJsFunction(){if(this.jsFunction)return this.jsFunction;if(this.jsFunctionString)return this.jsFunction=eval(this.jsFunctionString),this.jsFunction;throw"Missing jsFunction, and jsFunctionString parameter"}},{key:"astMemberExpressionUnroll",value:function(t){if("Identifier"===t.type)return t.name;if("ThisExpression"===t.type)return"this";if("MemberExpression"===t.type&&t.object&&t.property)return t.object.hasOwnProperty("name")&&"_"===t.object.name[0]?this.astMemberExpressionUnroll(t.property):this.astMemberExpressionUnroll(t.object)+"."+this.astMemberExpressionUnroll(t.property);if(t.hasOwnProperty("expressions")){var e=t.expressions[0];if("Literal"===e.type&&0===e.value&&2===t.expressions.length)return this.astMemberExpressionUnroll(t.expressions[1])}throw this.astErrorOutput("Unknown CallExpression_unroll",t)}},{key:"getJsAST",value:function(t){if(this.jsFunctionAST)return this.jsFunctionAST;if(t=t||acorn,null===t)throw"Missing JS to AST parser";var e=t.parse("var "+this.functionName+" = "+this.jsFunctionString+";",{locations:!0});if(null===e)throw"Failed to parse JS code";var n=e.body[0].declarations[0].init;return this.jsFunctionAST=n,n}},{key:"getFunctionString",value:function(){return this.generate(),this.functionString}},{key:"setFunctionString",value:function(t){this.functionString=t}},{key:"getParamType",value:function(t){var e=this.paramNames.indexOf(t);if(e===-1)return this.declarations.hasOwnProperty(t)?this.declarations[t]:"Number";if(this.parent){if(this.paramTypes[e])return this.paramTypes[e];for(var n=this.parent.calledFunctionsArguments[this.functionName],r=0;r0&&e.push(", "),e.push(this.paramTypes[i]),e.push(" "),e.push("user_"),e.push(this.paramNames[i]);return e.push(");\n"),e}},{key:"astFunctionExpression",value:function(t,e){if(this.isRootKernel)e.push("void");else{var n=this.returnType,r=g[n];if(!r)throw new Error("unknown type "+n);e.push(r)}if(e.push(" "),e.push(this.functionName),e.push("("),!this.isRootKernel)for(var i=0;i0&&e.push(", ");var a=this.getParamType(s),o=g[a];if(!o)throw new Error("unknown type "+a);e.push(o),e.push(" "),e.push("user_"),e.push(s)}e.push(") {\n");for(var u=0;u1){for(var s=null,a=0;a0&&e.push(",");var i=[];this.astGeneric(r,i);var s="Number";if(0===n){var a=r.init;if(a)if(a.object){if("MemberExpression"===a.object.type&&a.object.object)if("ThisExpression"!==a.object.object.type||!a.object.property||"thread"!==a.object.property.name&&"output"!==a.object.property.name){if("Identifier"===a.object.object.type){var o=this.getParamType(a.object.object.name);s=y[o]}else if(a.object.object.object&&"Identifier"===a.object.object.object.type){var u=this.getParamType(a.object.object.object.name);s=y[u]}else if(a.object.object.object&&a.object.object.object.object&&"ThisExpression"===a.object.object.object.object.type&&"constants"===a.object.object.object.property.name){var h=this.getConstantType(a.object.object.property.name);s=y[h]}else if(a.object.object.object&&a.object.object.object.object&&a.object.object.object.object.object&&"ThisExpression"===a.object.object.object.object.object.type&&"constants"===a.object.object.object.object.property.name){var c=this.getConstantType(a.object.object.object.property.name);s=y[c]}}else s="Integer";if(!s)throw new Error("unknown lookup type "+y)}else if(a.name&&this.declarations[a.name])s=this.declarations[a.name];else if("ArrayExpression"===a.type)s="Array("+a.elements.length+")";else if("CallExpression"===a.type){var l=this.builder.nodeMap[a.callee.name];l&&l.returnType&&(s=l.returnType)}var p=g[s];if(!p)throw new Error("type "+s+" not handled");e.push(p+" ")}this.declarations[r.id.name]=s,e.push.apply(e,i)}return e.push(";"),e}},{key:"astVariableDeclarator",value:function(t,e){return this.astGeneric(t.id,e),null!==t.init&&(e.push("="),this.astGeneric(t.init,e)),e}},{key:"astIfStatement",value:function(t,e){return e.push("if ("),this.astGeneric(t.test,e),e.push(")"),"BlockStatement"===t.consequent.type?this.astGeneric(t.consequent,e):(e.push(" {\n"),this.astGeneric(t.consequent,e),e.push("\n}\n")),t.alternate&&(e.push("else "),"BlockStatement"===t.alternate.type?this.astGeneric(t.alternate,e):(e.push(" {\n"),this.astGeneric(t.alternate,e),e.push("\n}\n"))),e}},{key:"astBreakStatement",value:function(t,e){return e.push("break;\n"),e}},{key:"astContinueStatement",value:function(t,e){return e.push("continue;\n"),e}},{key:"astLogicalExpression",value:function(t,e){return e.push("("),this.astGeneric(t.left,e),e.push(t.operator),this.astGeneric(t.right,e),e.push(")"),e}},{key:"astUpdateExpression",value:function(t,e){return t.prefix?(e.push(t.operator),this.astGeneric(t.argument,e)):(this.astGeneric(t.argument,e),e.push(t.operator)),e}},{key:"astUnaryExpression",value:function(t,e){return t.prefix?(e.push(t.operator),this.astGeneric(t.argument,e)):(this.astGeneric(t.argument,e),e.push(t.operator)),e}},{key:"astThisExpression",value:function(t,e){return e.push("this"),e}},{key:"astMemberExpression",value:function(t,e){if(m("[in] astMemberExpression "+t.object.type),t.computed)if("Identifier"===t.object.type||"MemberExpression"===t.object.type&&t.object.object.object&&"ThisExpression"===t.object.object.object.type&&"constants"===t.object.object.property.name){var n=t.object.name,r=this.functionName||"kernel",i=!1;if(this.paramNames){var s=this.paramNames.indexOf(n);s>=0&&"Number"===this.paramTypes[s]&&(i=!0)}if(m("- astMemberExpression "+n+" "+r),i)this.astGeneric(t.object,e),e.push("[int("),this.astGeneric(t.property,e),e.push(")]");else{var a=this.isState("in-get-call-parameters"),o=this.isState("multi-member-expression");o&&this.popState("multi-member-expression"),this.pushState("not-in-get-call-parameters");var u=null;switch(t.object.name?u=this.declarations[t.object.name]?this.declarations[t.object.name]:this.getParamType(t.object.name):t.object&&t.object.object&&t.object.object.object&&"ThisExpression"===t.object.object.object.type&&(u=this.getConstantType(t.object.property.name)),u){case"Array(2)":case"Array(3)":case"Array(4)":this.astGeneric(t.object,e),e.push("["),e.push(t.property.raw),e.push("]"),o&&this.popState("not-in-get-call-parameters");break;case"HTMLImageArray":e.push("getImage3D("),this.astGeneric(t.object,e),e.push(", ivec2("),this.astGeneric(t.object,e),e.push("Size[0],"),this.astGeneric(t.object,e),e.push("Size[1]), ivec3("),this.astGeneric(t.object,e),e.push("Dim[0],"),this.astGeneric(t.object,e),e.push("Dim[1],"),this.astGeneric(t.object,e),e.push("Dim[2]"),e.push("), "),this.popState("not-in-get-call-parameters"),this.pushState("in-get-call-parameters"),this.astGeneric(t.property,e),o||this.popState("in-get-call-parameters"),e.push(")");break;case"ArrayTexture(4)":case"HTMLImage":e.push("getImage2D("),this.astGeneric(t.object,e),e.push(", ivec2("),this.astGeneric(t.object,e),e.push("Size[0],"),this.astGeneric(t.object,e),e.push("Size[1]), ivec3("),this.astGeneric(t.object,e),e.push("Dim[0],"),this.astGeneric(t.object,e),e.push("Dim[1],"),this.astGeneric(t.object,e),e.push("Dim[2]"),e.push("), "),this.popState("not-in-get-call-parameters"),this.pushState("in-get-call-parameters"),this.astGeneric(t.property,e),o||this.popState("in-get-call-parameters"),e.push(")");break;default:a&&e.push("int("),e.push("get("),this.astGeneric(t.object,e),e.push(", ivec2("),this.astGeneric(t.object,e),e.push("Size[0],"),this.astGeneric(t.object,e),e.push("Size[1]), ivec3("),this.astGeneric(t.object,e),e.push("Dim[0],"),this.astGeneric(t.object,e),e.push("Dim[1],"),this.astGeneric(t.object,e),e.push("Dim[2]"),e.push("), "),this.astGeneric(t.object,e),e.push("BitRatio"),e.push(", "),this.popState("not-in-get-call-parameters"),this.pushState("in-get-call-parameters"),this.astGeneric(t.property,e),o||this.popState("in-get-call-parameters"),e.push(")"),a&&e.push(")")}}}else{m("- astMemberExpression obj:",t.object);var h=(this.states.length,this.isState("in-get-call-parameters"));h||this.pushState("multi-member-expression"),this.astGeneric(t.object,e),this.isState("multi-member-expression")&&this.popState("multi-member-expression");var c=!h&&this.isState("in-get-call-parameters"),l=e.pop();e.push(","),m("- astMemberExpression prop:",t.property);var f=this.isState("should-pop-in-get-call-parameters");f&&this.popState("should-pop-in-get-call-parameters"),this.astGeneric(t.property,e),e.push(l),c?this.pushState("should-pop-in-get-call-parameters"):f&&this.popState("in-get-call-parameters")}else{var d=this.astMemberExpressionUnroll(t),g=d.toLowerCase();m("- astMemberExpression unrolled:",d),0===d.indexOf(p)&&(d="constants_"+d.slice(p.length));var y=!this.isState("in-get-call-parameters");switch(g){case"this.thread.x":y&&e.push("float("),e.push("threadId.x"),y&&e.push(")");break;case"this.thread.y":y&&e.push("float("),e.push("threadId.y"),y&&e.push(")");break;case"this.thread.z":y&&e.push("float("),e.push("threadId.z"),y&&e.push(")");break;case"this.output.x":e.push(this.output[0]+".0");break;case"this.output.y":e.push(this.output[1]+".0");break;case"this.output.z":e.push(this.output[2]+".0");break;default:t.object&&t.object.name&&this.declarations[t.object.name]&&e.push("user_"),e.push(d)}}return m("[out] astMemberExpression "+t.object.type),e}},{key:"astSequenceExpression",value:function(t,e){for(var n=0;n0&&e.push(","),this.astGeneric(t.expressions,e);return e}},{key:"astCallExpression",value:function(t,e){if(t.callee){var n=this.astMemberExpressionUnroll(t.callee);0===n.indexOf(c)&&(n=n.slice(c.length)),0===n.indexOf(l)&&(n=n.slice(l.length)),"atan2"===n&&(n="atan"),this.calledFunctions.indexOf(n)<0&&this.calledFunctions.push(n),this.hasOwnProperty("funcName")||(this.calledFunctionsArguments[n]=[]);var r=[];this.calledFunctionsArguments[n].push(r),e.push(n),e.push("(");for(var i=0;i0&&e.push(", "),this.astGeneric(s,e),"Identifier"===s.type){var a=this.paramNames.indexOf(s.name);a===-1?r.push(null):r.push({name:s.name,type:this.paramTypes[a]||"Number"})}else r.push(null)}return e.push(")"),e}throw this.astErrorOutput("Unknown CallExpression",t)}},{key:"astArrayExpression",value:function(t,e){var n=t.elements.length;e.push("vec"+n+"(");for(var r=0;r0&&e.push(", ");var i=t.elements[r];this.astGeneric(i,e)}return e.push(")"),e}},{key:"getFunctionPrototypeString",value:function(){return this.webGlFunctionPrototypeString?this.webGlFunctionPrototypeString:this.webGlFunctionPrototypeString=this.generate()}},{key:"build",value:function(){return this.getFunctionPrototypeString().length>0}}]),e}(u);var g={Array:"sampler2D","Array(2)":"vec2","Array(3)":"vec3","Array(4)":"vec4",Array2D:"sampler2D",Array3D:"sampler2D",Float:"float",Input:"sampler2D",Integer:"float",Number:"float",NumberTexture:"sampler2D","ArrayTexture(4)":"sampler2D"},y={Array:"Number",Array2D:"Number",Array3D:"Number",HTMLImage:"Array(4)",HTMLImageArray:"Array(4)",NumberTexture:"Number","ArrayTexture(4)":"Array(4)"}},{"../../core/utils":32,"../function-node-base":7}],13:[function(t,e,n){function r(t){return/^function /.test(t)&&(t=t.substring(9)),t.replace(/[_]typeof/g,"typeof")}function i(t){return t.replace(/[_]typeof/g,"typeof")}var s=t("../../core/utils"),a=t("../kernel-run-shortcut");t("../../core/input"),t("../../core/texture");e.exports=function(t,e){return"() => {\n "+a.toString()+";\n const utils = {\n allPropertiesOf: "+i(s.allPropertiesOf.toString())+",\n clone: "+i(s.clone.toString())+",\n splitArray: "+i(s.splitArray.toString())+",\n getArgumentType: "+i(s.getArgumentType.toString())+",\n getDimensions: "+i(s.getDimensions.toString())+",\n dimToTexSize: "+i(s.dimToTexSize.toString())+",\n flattenTo: "+i(s.flattenTo.toString())+",\n flatten2dArrayTo: "+i(s.flatten2dArrayTo.toString())+",\n flatten3dArrayTo: "+i(s.flatten3dArrayTo.toString())+",\n systemEndianness: '"+i(s.systemEndianness())+"',\n initWebGl: "+i(s.initWebGl.toString())+",\n isArray: "+i(s.isArray.toString())+",\n checkOutput: "+i(s.checkOutput.toString())+"\n };\n const Utils = utils;\n const canvases = [];\n const maxTexSizes = {};\n let Texture = function() {};\n let Input = function() {}; \n class "+(e||"Kernel")+" {\n constructor() {\n this.maxTexSize = null;\n this.argumentsLength = 0;\n this.constantsLength = 0;\n this._canvas = null;\n this._webGl = null;\n this.program = null;\n this.outputToTexture = "+(t.outputToTexture?"true":"false")+";\n this.paramNames = "+JSON.stringify(t.paramNames)+";\n this.paramTypes = "+JSON.stringify(t.paramTypes)+";\n this.texSize = "+JSON.stringify(t.texSize)+";\n this.output = "+JSON.stringify(t.output)+";\n this.compiledFragShaderString = `"+t.compiledFragShaderString+"`;\n\t\t this.compiledVertShaderString = `"+t.compiledVertShaderString+"`;\n\t\t this.programUniformLocationCache = {};\n\t\t this.textureCache = {};\n\t\t this.subKernelOutputTextures = null;\n\t\t this.subKernelOutputVariableNames = null;\n\t\t this.uniform1fCache = {};\n\t\t this.uniform1iCache = {};\n\t\t this.uniform2fCache = {};\n\t\t this.uniform2fvCache = {};\n\t\t this.uniform2ivCache = {};\n\t\t this.uniform3fvCache = {};\n\t\t this.uniform3ivCache = {};\n }\n _getFragShaderString() { return this.compiledFragShaderString; }\n _getVertShaderString() { return this.compiledVertShaderString; }\n validateOptions() {}\n setupParams() {}\n setupConstants() {}\n setCanvas(canvas) { this._canvas = canvas; return this; }\n setWebGl(webGl) { this._webGl = webGl; return this; }\n setTexture(Type) { Texture = Type; }\n setInput(Type) { Input = Type; }\n "+r(t.getUniformLocation.toString())+"\n "+r(t.build.toString())+"\n\t\t "+r(t.run.toString())+"\n\t\t "+r(t._addArgument.toString())+"\n\t\t "+r(t._formatArrayTransfer.toString())+"\n\t\t "+r(t.getArgumentTexture.toString())+"\n\t\t "+r(t.getTextureCache.toString())+"\n\t\t "+r(t.getOutputTexture.toString())+"\n\t\t "+r(t.renderOutput.toString())+"\n\t\t "+r(t.updateMaxTexSize.toString())+"\n\t\t "+r(t._setupOutputTexture.toString())+"\n\t\t "+r(t.detachTextureCache.toString())+"\n\t\t "+r(t.setUniform1f.toString())+"\n\t\t "+r(t.setUniform1i.toString())+"\n\t\t "+r(t.setUniform2f.toString())+"\n\t\t "+r(t.setUniform2fv.toString())+"\n\t\t "+r(t.setUniform2iv.toString())+"\n\t\t "+r(t.setUniform3fv.toString())+"\n\t\t "+r(t.setUniform3iv.toString())+"\n };\n return kernelRunShortcut(new Kernel());\n };"; +"use strict";!function(){function t(e,n,r){function i(a,o){if(!n[a]){if(!e[a]){var u="function"==typeof require&&require;if(!o&&u)return u(a,!0);if(s)return s(a,!0);var h=new Error("Cannot find module '"+a+"'");throw h.code="MODULE_NOT_FOUND",h}var c=n[a]={exports:{}};e[a][0].call(c.exports,function(t){var n=e[a][1][t];return i(n||t)},c,c.exports,t,e,n,r)}return n[a].exports}for(var s="function"==typeof require&&require,a=0;a0&&e.push(", "),e.push("user_"),e.push(this.paramNames[n]);return e.push(");\n"),e}},{key:"astFunctionExpression",value:function(t,e){if(!this.isRootKernel){e.push("function"),e.push(" "),e.push(this.functionName),e.push("(");for(var n=0;n0&&e.push(", "),e.push("user_"),e.push(r)}e.push(") {\n")}for(var i=0;i1){for(var s=null,a=0;a0&&e.push(","),this.astGeneric(t.declarations[n],e);return e.push(";"),e}},{key:"astVariableDeclarator",value:function(t,e){return this.astGeneric(t.id,e),null!==t.init&&(e.push("="),this.astGeneric(t.init,e)),e}},{key:"astIfStatement",value:function(t,e){return e.push("if ("),this.astGeneric(t.test,e),e.push(")"),"BlockStatement"===t.consequent.type?this.astGeneric(t.consequent,e):(e.push(" {\n"),this.astGeneric(t.consequent,e),e.push("\n}\n")),t.alternate&&(e.push("else "),"BlockStatement"===t.alternate.type?this.astGeneric(t.alternate,e):(e.push(" {\n"),this.astGeneric(t.alternate,e),e.push("\n}\n"))),e}},{key:"astBreakStatement",value:function(t,e){return e.push("break;\n"),e}},{key:"astContinueStatement",value:function(t,e){return e.push("continue;\n"),e}},{key:"astLogicalExpression",value:function(t,e){return e.push("("),this.astGeneric(t.left,e),e.push(t.operator),this.astGeneric(t.right,e),e.push(")"),e}},{key:"astUpdateExpression",value:function(t,e){return t.prefix?(e.push(t.operator),this.astGeneric(t.argument,e)):(this.astGeneric(t.argument,e),e.push(t.operator)),e}},{key:"astUnaryExpression",value:function(t,e){return t.prefix?(e.push(t.operator),this.astGeneric(t.argument,e)):(this.astGeneric(t.argument,e),e.push(t.operator)),e}},{key:"astThisExpression",value:function(t,e){return e.push("_this"),e}},{key:"astMemberExpression",value:function(t,e){if(t.computed)if("Identifier"===t.object.type||"MemberExpression"===t.object.type&&t.object.object.object&&"ThisExpression"===t.object.object.object.type&&"constants"===t.object.object.property.name)this.pushState("identifier"),this.astGeneric(t.object,e),this.popState("identifier"),e.push("["),this.isInput(t.object.name)?this.astGeneric(t.property,e):this.astGeneric(t.property,e),e.push("]");else if(t.object.object)if(t.object.object.object&&this.isInput(t.object.object.object.name)){this.pushMemberState(t.object.object.object.name),this.pushState("input-index-z"),this.astGeneric(t.object,e);var n=e.pop();e.push(" + "),this.popState("input-index-z"),this.pushState("input-index"),this.astGeneric(t.property,e),this.popState("input-index"),e.push(n),this.popMemberState(t.object.object.object.name)}else if(this.isInput(t.object.object.name)){this.pushMemberState(t.object.object.name),this.isState("input-index-z")||this.pushState("input-index-y"),this.astGeneric(t.object,e);var r=e.pop();e.push(" + "),this.isState("input-index-z")||this.popState("input-index-y");var i=this.isState("input-index-z");i?this.pushState("input-index-y"):this.pushState("input-index"),this.astGeneric(t.property,e),i?this.popState("input-index-y"):this.popState("input-index"),e.push(r),this.popMemberState(t.object.object.name)}else{this.astGeneric(t.object,e);var s=e.pop();e.push("]["),this.astGeneric(t.property,e),e.push(s)}else{this.astGeneric(t.object,e);var a=e.pop();e.push("]["),this.astGeneric(t.property,e),e.push(a)}else{var o=this.astMemberExpressionUnroll(t);switch("Identifier"===t.property.type&&t.computed&&(o="user_"+o),0===o.indexOf("this.constants")?o="constants_"+o.substring(15):0===o.indexOf("this")&&(o="_"+o),this.state){case"input-index-y":case"input-index-z":e.push("(")}switch(o){case"_this.output.x":e.push(this.output[0]);break;case"_this.output.y":e.push(this.output[1]);break;case"_this.output.z":e.push(this.output[2]);break;default:t.object&&t.object.name&&this.declarations[t.object.name]&&e.push("user_"),e.push(o)}switch(this.state){case"input-index-y":var u=this.paramSizes[this.paramNames.indexOf(this.memberState)];e.push(" * "+u[0]+")");break;case"input-index-z":var h=this.paramSizes[this.paramNames.indexOf(this.memberState)];e.push(" * "+h[0]*h[1]+")")}}return e}},{key:"astSequenceExpression",value:function(t,e){for(var n=0;n0&&e.push(","),this.astGeneric(t.expressions,e);return e}},{key:"astCallExpression",value:function(t,e){if(t.callee){var n=this.astMemberExpressionUnroll(t.callee);this.calledFunctions.indexOf(n)<0&&this.calledFunctions.push(n),this.hasOwnProperty("funcName")||(this.calledFunctionsArguments[n]=[]);var r=[];this.calledFunctionsArguments[n].push(r),e.push(n),e.push("(");for(var i=0;i0&&e.push(", "),this.astGeneric(s,e),"Identifier"===s.type){var a=this.paramNames.indexOf(s.name);a===-1?r.push(null):r.push({name:s.name,type:this.paramTypes[a]})}else r.push(null)}return e.push(")"),e}throw this.astErrorOutput("Unknown CallExpression",t)}},{key:"astArrayExpression",value:function(t,e){var n=t.elements.length;e.push("[");for(var r=0;r0&&e.push(", ");var i=t.elements[r];this.astGeneric(i,e)}return e.push("]"),e}},{key:"astDebuggerStatement",value:function(t,e){return e.push("debugger;"),e}},{key:"memberState",get:function(){return this.memberStates[this.memberStates.length-1]}}]),e}(o)},{"../../core/utils":32,"../function-node-base":7}],3:[function(t,e,n){function r(t){return/^function /.test(t)&&(t=t.substring(9)),t.replace(/[_]typeof/g,"typeof")}function i(t){return t.replace(/[_]typeof/g,"typeof")}var s=t("../../core/utils"),a=t("../kernel-run-shortcut");e.exports=function(t,e){return"() => {\n "+a.toString()+";\n const utils = {\n allPropertiesOf: "+i(s.allPropertiesOf.toString())+",\n clone: "+i(s.clone.toString())+",\n checkOutput: "+i(s.checkOutput.toString())+"\n };\n const Utils = utils;\n let Input = function() {};\n class "+(e||"Kernel")+" {\n constructor() { \n this.argumentsLength = 0;\n this._canvas = null;\n this._webGl = null;\n this.built = false;\n this.program = null;\n this.paramNames = "+JSON.stringify(t.paramNames)+";\n this.paramTypes = "+JSON.stringify(t.paramTypes)+";\n this.texSize = "+JSON.stringify(t.texSize)+";\n this.output = "+JSON.stringify(t.output)+";\n this._kernelString = `"+t._kernelString+"`;\n this.output = "+JSON.stringify(t.output)+";\n\t\t this.run = function() {\n this.run = null;\n this.build();\n return this.run.apply(this, arguments);\n }.bind(this);\n this.thread = {\n x: 0,\n y: 0,\n z: 0\n };\n }\n setCanvas(canvas) { this._canvas = canvas; return this; }\n setWebGl(webGl) { this._webGl = webGl; return this; }\n setInput(Type) { Input = Type; }\n "+r(t.build.toString())+"\n "+r(t.setupParams.toString())+"\n "+r(t.setupConstants.toString())+"\n run () { "+t.kernelString+" }\n getKernelString() { return this._kernelString; }\n "+r(t.validateOptions.toString())+"\n };\n return kernelRunShortcut(new Kernel());\n };"}},{"../../core/utils":32,"../kernel-run-shortcut":9}],4:[function(t,e,n){function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var a=function(){function t(t,e){for(var n=0;n1?o=o.filter(function(t){return/^function/.test(t)?t:(h=t,!1)}):h=o.shift();var c=this._kernelString="\n\t\tvar LOOP_MAX = "+this._getLoopMaxString()+"\n\t\tvar constants = this.constants;\n\t\tvar _this = this;\n return function ("+this.paramNames.map(function(t){return"user_"+t}).join(", ")+") {\n "+this._processConstants()+"\n "+this._processParams()+"\n "+this._kernelLoop(h)+"\n if (this.graphical) {\n this._imageData.data.set(this._colorData);\n this._canvasCtx.putImageData(this._imageData, 0, 0);\n return;\n }\n "+this._kernelOutput()+"\n "+(o.length>0?o.join("\n"):"")+"\n }.bind(this);";return c}},{key:"toString",value:function(){return h(this)}},{key:"_getLoopMaxString",value:function(){return this.loopMaxIterations?" "+parseInt(this.loopMaxIterations)+";\n":" 1000;\n"}},{key:"_processConstants",value:function(){if(!this.constants)return"";var t=[];for(var e in this.constants){var n=this.constantTypes[e];switch(n){case"HTMLImage":t.push(" var constants_"+e+" = this._imageTo2DArray(this.constants."+e+")");break;case"HTMLImageArray":t.push(" var constants_"+e+" = this._imageTo3DArray(this.constants."+e+")");break;case"Input":t.push(" var constants_"+e+" = this.constants."+e+".value");break;default:t.push(" var constants_"+e+" = this.constants."+e)}}return t.join("\n")}},{key:"_processParams",value:function(){for(var t=[],e=0;e=0;a--){i[a]=new Array(t.width);for(var o=0;o=0||e.push(t)),e}},{key:"addKernel",value:function(t,e){var n=new this.Node("kernel",t,e);return n.setBuilder(this),n.isRootKernel=!0,this.addFunctionNode(n),n}},{key:"addSubKernel",value:function(t,e){var n=new this.Node(null,t,e);return n.setBuilder(this),n.isSubKernel=!0,this.addFunctionNode(n),n}},{key:"getPrototypeString",value:function(t){return this.getPrototypes(t).join("\n")}},{key:"getPrototypes",value:function(t){return this.rootKernel.generate(),t?this.getPrototypesFromFunctionNames(this.traceFunctionCalls(t,[]).reverse()):this.getPrototypesFromFunctionNames(Object.keys(this.nodeMap))}},{key:"getStringFromFunctionNames",value:function(t){for(var e=[],n=0;n ("+r.length+","+this.paramNames.length+")";this.paramTypes=r}else if("object"===("undefined"==typeof r?"undefined":_typeof(r))){var s=Object.keys(r);if(r.hasOwnProperty("returns")&&(this.returnType=r.returns,s.splice(s.indexOf("returns"),1)),s.length>0&&s.length!==this.paramNames.length)throw"Invalid argument type array length, against function length -> ("+s.length+","+this.paramNames.length+")";this.paramTypes=this.paramNames.map(function(t){return r.hasOwnProperty(t)?r[t]:"Number"})}}else this.paramTypes=[];this.returnType||(this.returnType=i||"Number")}return _createClass(BaseFunctionNode,[{key:"isIdentifierConstant",value:function(t){return!!this.constants&&this.constants.hasOwnProperty(t)}},{key:"isInput",value:function(t){return"Input"===this.paramTypes[this.paramNames.indexOf(t)]}},{key:"setBuilder",value:function(t){return this.builder=t,this; +}},{key:"pushState",value:function(t){this.states.push(t)}},{key:"popState",value:function(t){if(this.state!==t)throw new Error("Cannot popState "+t+" when in "+this.state);this.states.pop()}},{key:"isState",value:function(t){return this.state===t}},{key:"getJsFunction",value:function getJsFunction(){if(this.jsFunction)return this.jsFunction;if(this.jsFunctionString)return this.jsFunction=eval(this.jsFunctionString),this.jsFunction;throw"Missing jsFunction, and jsFunctionString parameter"}},{key:"astMemberExpressionUnroll",value:function(t){if("Identifier"===t.type)return t.name;if("ThisExpression"===t.type)return"this";if("MemberExpression"===t.type&&t.object&&t.property)return t.object.hasOwnProperty("name")&&"_"===t.object.name[0]?this.astMemberExpressionUnroll(t.property):this.astMemberExpressionUnroll(t.object)+"."+this.astMemberExpressionUnroll(t.property);if(t.hasOwnProperty("expressions")){var e=t.expressions[0];if("Literal"===e.type&&0===e.value&&2===t.expressions.length)return this.astMemberExpressionUnroll(t.expressions[1])}throw this.astErrorOutput("Unknown CallExpression_unroll",t)}},{key:"getJsAST",value:function(t){if(this.jsFunctionAST)return this.jsFunctionAST;if(t=t||acorn,null===t)throw"Missing JS to AST parser";var e=t.parse("var "+this.functionName+" = "+this.jsFunctionString+";",{locations:!0});if(null===e)throw"Failed to parse JS code";var n=e.body[0].declarations[0].init;return this.jsFunctionAST=n,n}},{key:"getFunctionString",value:function(){return this.generate(),this.functionString}},{key:"setFunctionString",value:function(t){this.functionString=t}},{key:"getParamType",value:function(t){var e=this.paramNames.indexOf(t);if(e===-1)return this.declarations.hasOwnProperty(t)?this.declarations[t]:"Number";if(this.parent){if(this.paramTypes[e])return this.paramTypes[e];for(var n=this.parent.calledFunctionsArguments[this.functionName],r=0;r0&&e.push(", "),e.push(this.paramTypes[i]),e.push(" "),e.push("user_"),e.push(this.paramNames[i]);return e.push(");\n"),e}},{key:"astFunctionExpression",value:function(t,e){if(this.isRootKernel)e.push("void");else{var n=this.returnType,r=g[n];if(!r)throw new Error("unknown type "+n);e.push(r)}if(e.push(" "),e.push(this.functionName),e.push("("),!this.isRootKernel)for(var i=0;i0&&e.push(", ");var a=this.getParamType(s),o=g[a];if(!o)throw new Error("unknown type "+a);e.push(o),e.push(" "),e.push("user_"),e.push(s)}e.push(") {\n");for(var u=0;u1){for(var s=null,a=0;a0&&e.push(",");var i=[];this.astGeneric(r,i);var s="Number";if(0===n){var a=r.init;if(a)if(a.object){if("MemberExpression"===a.object.type&&a.object.object)if("ThisExpression"!==a.object.object.type||!a.object.property||"thread"!==a.object.property.name&&"output"!==a.object.property.name){if("Identifier"===a.object.object.type){var o=this.getParamType(a.object.object.name);s=y[o]}else if(a.object.object.object&&"Identifier"===a.object.object.object.type){var u=this.getParamType(a.object.object.object.name);s=y[u]}else if(a.object.object.object&&a.object.object.object.object&&"ThisExpression"===a.object.object.object.object.type&&"constants"===a.object.object.object.property.name){var h=this.getConstantType(a.object.object.property.name);s=y[h]}else if(a.object.object.object&&a.object.object.object.object&&a.object.object.object.object.object&&"ThisExpression"===a.object.object.object.object.object.type&&"constants"===a.object.object.object.object.property.name){var c=this.getConstantType(a.object.object.object.property.name);s=y[c]}}else s="Integer";if(!s)throw new Error("unknown lookup type "+y)}else if(a.name&&this.declarations[a.name])s=this.declarations[a.name];else if("ArrayExpression"===a.type)s="Array("+a.elements.length+")";else if("CallExpression"===a.type){var l=this.builder.nodeMap[a.callee.name];l&&l.returnType&&(s=l.returnType)}var p=g[s];if(!p)throw new Error("type "+s+" not handled");e.push(p+" ")}this.declarations[r.id.name]=s,e.push.apply(e,i)}return e.push(";"),e}},{key:"astVariableDeclarator",value:function(t,e){return this.astGeneric(t.id,e),null!==t.init&&(e.push("="),this.astGeneric(t.init,e)),e}},{key:"astIfStatement",value:function(t,e){return e.push("if ("),this.astGeneric(t.test,e),e.push(")"),"BlockStatement"===t.consequent.type?this.astGeneric(t.consequent,e):(e.push(" {\n"),this.astGeneric(t.consequent,e),e.push("\n}\n")),t.alternate&&(e.push("else "),"BlockStatement"===t.alternate.type?this.astGeneric(t.alternate,e):(e.push(" {\n"),this.astGeneric(t.alternate,e),e.push("\n}\n"))),e}},{key:"astBreakStatement",value:function(t,e){return e.push("break;\n"),e}},{key:"astContinueStatement",value:function(t,e){return e.push("continue;\n"),e}},{key:"astLogicalExpression",value:function(t,e){return e.push("("),this.astGeneric(t.left,e),e.push(t.operator),this.astGeneric(t.right,e),e.push(")"),e}},{key:"astUpdateExpression",value:function(t,e){return t.prefix?(e.push(t.operator),this.astGeneric(t.argument,e)):(this.astGeneric(t.argument,e),e.push(t.operator)),e}},{key:"astUnaryExpression",value:function(t,e){return t.prefix?(e.push(t.operator),this.astGeneric(t.argument,e)):(this.astGeneric(t.argument,e),e.push(t.operator)),e}},{key:"astThisExpression",value:function(t,e){return e.push("this"),e}},{key:"astMemberExpression",value:function(t,e){if(m("[in] astMemberExpression "+t.object.type),t.computed)if("Identifier"===t.object.type||"MemberExpression"===t.object.type&&t.object.object.object&&"ThisExpression"===t.object.object.object.type&&"constants"===t.object.object.property.name){var n=t.object.name,r=this.functionName||"kernel",i=!1;if(this.paramNames){var s=this.paramNames.indexOf(n);s>=0&&"Number"===this.paramTypes[s]&&(i=!0)}if(m("- astMemberExpression "+n+" "+r),i)this.astGeneric(t.object,e),e.push("[int("),this.astGeneric(t.property,e),e.push(")]");else{var a=this.isState("in-get-call-parameters"),o=this.isState("multi-member-expression");o&&this.popState("multi-member-expression"),this.pushState("not-in-get-call-parameters");var u=null;switch(t.object.name?u=this.declarations[t.object.name]?this.declarations[t.object.name]:this.getParamType(t.object.name):t.object&&t.object.object&&t.object.object.object&&"ThisExpression"===t.object.object.object.type&&(u=this.getConstantType(t.object.property.name)),u){case"Array(2)":case"Array(3)":case"Array(4)":this.astGeneric(t.object,e),e.push("["),e.push(t.property.raw),e.push("]"),o&&this.popState("not-in-get-call-parameters");break;case"HTMLImageArray":e.push("getImage3D("),this.astGeneric(t.object,e),e.push(", ivec2("),this.astGeneric(t.object,e),e.push("Size[0],"),this.astGeneric(t.object,e),e.push("Size[1]), ivec3("),this.astGeneric(t.object,e),e.push("Dim[0],"),this.astGeneric(t.object,e),e.push("Dim[1],"),this.astGeneric(t.object,e),e.push("Dim[2]"),e.push("), "),this.popState("not-in-get-call-parameters"),this.pushState("in-get-call-parameters"),this.astGeneric(t.property,e),o||this.popState("in-get-call-parameters"),e.push(")");break;case"ArrayTexture(4)":case"HTMLImage":e.push("getImage2D("),this.astGeneric(t.object,e),e.push(", ivec2("),this.astGeneric(t.object,e),e.push("Size[0],"),this.astGeneric(t.object,e),e.push("Size[1]), ivec3("),this.astGeneric(t.object,e),e.push("Dim[0],"),this.astGeneric(t.object,e),e.push("Dim[1],"),this.astGeneric(t.object,e),e.push("Dim[2]"),e.push("), "),this.popState("not-in-get-call-parameters"),this.pushState("in-get-call-parameters"),this.astGeneric(t.property,e),o||this.popState("in-get-call-parameters"),e.push(")");break;default:a&&e.push("int("),e.push("get("),this.astGeneric(t.object,e),e.push(", ivec2("),this.astGeneric(t.object,e),e.push("Size[0],"),this.astGeneric(t.object,e),e.push("Size[1]), ivec3("),this.astGeneric(t.object,e),e.push("Dim[0],"),this.astGeneric(t.object,e),e.push("Dim[1],"),this.astGeneric(t.object,e),e.push("Dim[2]"),e.push("), "),this.astGeneric(t.object,e),e.push("BitRatio"),e.push(", "),this.popState("not-in-get-call-parameters"),this.pushState("in-get-call-parameters"),this.astGeneric(t.property,e),o||this.popState("in-get-call-parameters"),e.push(")"),a&&e.push(")")}}}else{m("- astMemberExpression obj:",t.object);var h=(this.states.length,this.isState("in-get-call-parameters"));h||this.pushState("multi-member-expression"),this.astGeneric(t.object,e),this.isState("multi-member-expression")&&this.popState("multi-member-expression");var c=!h&&this.isState("in-get-call-parameters"),l=e.pop();e.push(","),m("- astMemberExpression prop:",t.property);var f=this.isState("should-pop-in-get-call-parameters");f&&this.popState("should-pop-in-get-call-parameters"),this.astGeneric(t.property,e),e.push(l),c?this.pushState("should-pop-in-get-call-parameters"):f&&this.popState("in-get-call-parameters")}else{var d=this.astMemberExpressionUnroll(t),g=d.toLowerCase();m("- astMemberExpression unrolled:",d),0===d.indexOf(p)&&(d="constants_"+d.slice(p.length));var y=!this.isState("in-get-call-parameters");switch(g){case"this.thread.x":y&&e.push("float("),e.push("threadId.x"),y&&e.push(")");break;case"this.thread.y":y&&e.push("float("),e.push("threadId.y"),y&&e.push(")");break;case"this.thread.z":y&&e.push("float("),e.push("threadId.z"),y&&e.push(")");break;case"this.output.x":e.push(this.output[0]+".0");break;case"this.output.y":e.push(this.output[1]+".0");break;case"this.output.z":e.push(this.output[2]+".0");break;default:t.object&&t.object.name&&this.declarations[t.object.name]&&e.push("user_"),e.push(d)}}return m("[out] astMemberExpression "+t.object.type),e}},{key:"astSequenceExpression",value:function(t,e){for(var n=0;n0&&e.push(","),this.astGeneric(t.expressions,e);return e}},{key:"astCallExpression",value:function(t,e){if(t.callee){var n=this.astMemberExpressionUnroll(t.callee);0===n.indexOf(c)&&(n=n.slice(c.length)),0===n.indexOf(l)&&(n=n.slice(l.length)),"atan2"===n&&(n="atan"),this.calledFunctions.indexOf(n)<0&&this.calledFunctions.push(n),this.hasOwnProperty("funcName")||(this.calledFunctionsArguments[n]=[]);var r=[];this.calledFunctionsArguments[n].push(r),e.push(n),e.push("(");for(var i=0;i0&&e.push(", "),this.astGeneric(s,e),"Identifier"===s.type){var a=this.paramNames.indexOf(s.name);a===-1?r.push(null):r.push({name:s.name,type:this.paramTypes[a]||"Number"})}else r.push(null)}return e.push(")"),e}throw this.astErrorOutput("Unknown CallExpression",t)}},{key:"astArrayExpression",value:function(t,e){var n=t.elements.length;e.push("vec"+n+"(");for(var r=0;r0&&e.push(", ");var i=t.elements[r];this.astGeneric(i,e)}return e.push(")"),e}},{key:"getFunctionPrototypeString",value:function(){return this.webGlFunctionPrototypeString?this.webGlFunctionPrototypeString:this.webGlFunctionPrototypeString=this.generate()}},{key:"build",value:function(){return this.getFunctionPrototypeString().length>0}}]),e}(u);var g={Array:"sampler2D","Array(2)":"vec2","Array(3)":"vec3","Array(4)":"vec4",Array2D:"sampler2D",Array3D:"sampler2D",Float:"float",Input:"sampler2D",Integer:"float",Number:"float",NumberTexture:"sampler2D","ArrayTexture(4)":"sampler2D"},y={Array:"Number",Array2D:"Number",Array3D:"Number",HTMLImage:"Array(4)",HTMLImageArray:"Array(4)",NumberTexture:"Number","ArrayTexture(4)":"Array(4)"}},{"../../core/utils":32,"../function-node-base":7}],13:[function(t,e,n){function r(t){return/^function /.test(t)&&(t=t.substring(9)),t.replace(/[_]typeof/g,"typeof")}function i(t){return t.replace(/[_]typeof/g,"typeof")}var s=t("../../core/utils"),a=t("../kernel-run-shortcut");t("../../core/input"),t("../../core/texture");e.exports=function(t,e){return"() => {\n "+a.toString()+";\n const utils = {\n allPropertiesOf: "+i(s.allPropertiesOf.toString())+",\n clone: "+i(s.clone.toString())+",\n splitArray: "+i(s.splitArray.toString())+",\n getArgumentType: "+i(s.getArgumentType.toString())+",\n getDimensions: "+i(s.getDimensions.toString())+",\n dimToTexSize: "+i(s.dimToTexSize.toString())+",\n flattenTo: "+i(s.flattenTo.toString())+",\n flatten2dArrayTo: "+i(s.flatten2dArrayTo.toString())+",\n flatten3dArrayTo: "+i(s.flatten3dArrayTo.toString())+",\n systemEndianness: '"+i(s.systemEndianness())+"',\n initWebGl: "+i(s.initWebGl.toString())+",\n isArray: "+i(s.isArray.toString())+",\n checkOutput: "+i(s.checkOutput.toString())+"\n };\n const Utils = utils;\n const canvases = [];\n const maxTexSizes = {};\n let Texture = function() {};\n let Input = function() {}; \n class "+(e||"Kernel")+" {\n constructor() {\n this.maxTexSize = null;\n this.argumentsLength = 0;\n this.constantsLength = 0;\n this._canvas = null;\n this._webGl = null;\n this.program = null;\n this.outputToTexture = "+(t.outputToTexture?"true":"false")+";\n this.paramNames = "+JSON.stringify(t.paramNames)+";\n this.paramTypes = "+JSON.stringify(t.paramTypes)+";\n this.texSize = "+JSON.stringify(t.texSize)+";\n this.output = "+JSON.stringify(t.output)+";\n this.compiledFragShaderString = `"+t.compiledFragShaderString+"`;\n\t\t this.compiledVertShaderString = `"+t.compiledVertShaderString+"`;\n\t\t this.programUniformLocationCache = {};\n\t\t this.textureCache = {};\n\t\t this.subKernelOutputTextures = null;\n\t\t this.subKernelOutputVariableNames = null;\n\t\t this.uniform1fCache = {};\n\t\t this.uniform1iCache = {};\n\t\t this.uniform2fCache = {};\n\t\t this.uniform2fvCache = {};\n\t\t this.uniform2ivCache = {};\n\t\t this.uniform3fvCache = {};\n\t\t this.uniform3ivCache = {};\n }\n _getFragShaderString() { return this.compiledFragShaderString; }\n _getVertShaderString() { return this.compiledVertShaderString; }\n validateOptions() {}\n setupParams() {}\n setupConstants() {}\n setCanvas(canvas) { this._canvas = canvas; return this; }\n setWebGl(webGl) { this._webGl = webGl; return this; }\n setTexture(Type) { Texture = Type; }\n setInput(Type) { Input = Type; }\n "+r(t.getUniformLocation.toString())+"\n "+r(t.build.toString())+"\n\t\t "+r(t.run.toString())+"\n\t\t "+r(t._addArgument.toString())+"\n\t\t "+r(t._formatArrayTransfer.toString())+"\n\t\t "+r(t.getArgumentTexture.toString())+"\n\t\t "+r(t.getTextureCache.toString())+"\n\t\t "+r(t.getOutputTexture.toString())+"\n\t\t "+r(t.renderOutput.toString())+"\n\t\t "+r(t.updateMaxTexSize.toString())+"\n\t\t "+r(t._setupOutputTexture.toString())+"\n\t\t "+r(t.detachTextureCache.toString())+"\n\t\t "+r(t.setUniform1f.toString())+"\n\t\t "+r(t.setUniform1i.toString())+"\n\t\t "+r(t.setUniform2f.toString())+"\n\t\t "+r(t.setUniform2fv.toString())+"\n\t\t "+r(t.setUniform2iv.toString())+"\n\t\t "+r(t.setUniform3fv.toString())+"\n\t\t "+r(t.setUniform3iv.toString())+"\n };\n return kernelRunShortcut(new Kernel());\n };"; }},{"../../core/input":29,"../../core/texture":30,"../../core/utils":32,"../kernel-run-shortcut":9}],14:[function(t,e,n){function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var a=function g(t,e,n){null===t&&(t=Function.prototype);var r=Object.getOwnPropertyDescriptor(t,e);if(void 0===r){var i=Object.getPrototypeOf(t);return null===i?void 0:g(i,e,n)}if("value"in r)return r.value;var s=r.get;if(void 0!==s)return s.call(n)},o=function(){function t(t,e){for(var n=0;n0&&this._setupSubOutputTextures(this.subKernelOutputVariableNames.length))}},{key:"run",value:function(){null===this.program&&this.build.apply(this,arguments);var t=this.paramNames,e=this.paramTypes,n=this.texSize,r=this._webGl;r.useProgram(this.program),r.scissor(0,0,n[0],n[1]),this.hardcodeConstants||(this.setUniform3iv("uOutputDim",this.threadDim),this.setUniform2iv("uTexSize",n)),this.setUniform2f("ratio",n[0]/this.maxTexSize[0],n[1]/this.maxTexSize[1]),this.argumentsLength=0;for(var i=0;i0?t.join(";\n")+";\n":"\n"}},{key:"_replaceArtifacts",value:function(t,e){return t.replace(/[ ]*__([A-Z]+[0-9]*([_]?[A-Z])*)__;\n/g,function(t,n){if(e.hasOwnProperty(n))return e[n];throw"unhandled artifact "+n})}},{key:"_addKernels",value:function(){var t=this,e=this.functionBuilder,n=this._webGl;if(e.addFunctions(this.functions,{constants:this.constants,output:this.output}),e.addNativeFunctions(this.nativeFunctions),e.addKernel(this.fnString,{prototypeOnly:!1,constants:this.constants,output:this.output,debug:this.debug,loopMaxIterations:this.loopMaxIterations,paramNames:this.paramNames,paramTypes:this.paramTypes,constantTypes:this.constantTypes,fixIntegerDivisionAccuracy:this.fixIntegerDivisionAccuracy}),null!==this.subKernels){var r=this.drawBuffers=n.getExtension("WEBGL_draw_buffers");if(!r)throw new Error("could not instantiate draw buffers extension");this.subKernelOutputVariableNames=[],this.subKernels.forEach(function(e){return t._addSubKernel(e)})}else if(null!==this.subKernelProperties){var i=this.drawBuffers=n.getExtension("WEBGL_draw_buffers");if(!i)throw new Error("could not instantiate draw buffers extension");this.subKernelOutputVariableNames=[],Object.keys(this.subKernelProperties).forEach(function(e){return t._addSubKernel(t.subKernelProperties[e])})}}},{key:"_addSubKernel",value:function(t){this.functionBuilder.addSubKernel(t,{prototypeOnly:!1,constants:this.constants,output:this.output,debug:this.debug,loopMaxIterations:this.loopMaxIterations,fixIntegerDivisionAccuracy:this.fixIntegerDivisionAccuracy}),this.subKernelOutputVariableNames.push(t.name+"Result")}},{key:"_getFragShaderString",value:function(t){return null!==this.compiledFragShaderString?this.compiledFragShaderString:this.compiledFragShaderString=this._replaceArtifacts(this.constructor.fragShaderString,this._getFragShaderArtifactMap(t))}},{key:"_getVertShaderString",value:function(t){return null!==this.compiledVertShaderString?this.compiledVertShaderString:this.compiledVertShaderString=this.constructor.vertShaderString}},{key:"toString",value:function(){return f(this)}},{key:"addFunction",value:function(t){this.functionBuilder.addFunction(null,t)}},{key:"destroy",value:function(t){a(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"destroy",this).call(this),this.outputTexture&&this._webGl.deleteTexture(this.outputTexture),this.buffer&&this._webGl.deleteBuffer(this.buffer),this.framebuffer&&this._webGl.deleteFramebuffer(this.framebuffer),this.vertShader&&this._webGl.deleteShader(this.vertShader),this.fragShader&&this._webGl.deleteShader(this.fragShader),this.program&&this._webGl.deleteProgram(this.program);for(var n=Object.keys(this.textureCache),r=0;r=0&&(d[o]=null,m[o]=null)}delete this._webGl}}]),e}(u)},{"../../core/texture":30,"../../core/utils":32,"../kernel-base":8,"./kernel-string":13,"./shader-frag":16,"./shader-vert":17}],15:[function(t,e,n){function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var a=function(){function t(t,e){for(var n=0;n5&&void 0!==arguments[5]?arguments[5]:"NumberTexture";r(this,t),this.texture=e,this.size=n,this.dimensions=i,this.output=s,this.webGl=a,this.kernel=null,this.type=o}return i(t,[{key:"toArray",value:function(t){if(!t)throw new Error("You need to pass the GPU object for toArray to work.");return this.kernel?this.kernel(this):(this.kernel=t.createKernel(function(t){return t[this.thread.z][this.thread.y][this.thread.x]}).setOutput(this.output),this.kernel(this))}},{key:"delete",value:function(){return this.webGl.deleteTexture(this.texture)}}]),t}()},{}],31:[function(t,e,n){function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i=function(){function t(t,e){for(var n=0;n1&&i*s===r)return[i,s];for(var o=Math.sqrt(r),u=Math.ceil(o),h=Math.floor(o);u*h>r;)u--,h=Math.ceil(r/u);return i=h,s=Math.ceil(r/i),[i,s]}},{key:"getDimensions",value:function(t,e){var r=void 0;if(n.isArray(t)){for(var i=[],s=t;n.isArray(s);)i.push(s.length),s=s[0];r=i.reverse()}else if(t instanceof c)r=t.output;else{if(!(t instanceof h))throw"Unknown dimensions of "+t;r=t.size}if(e)for(r=n.clone(r);r.length<3;)r.push(1);return new Int32Array(r)}},{key:"pad",value:function(t,e){function n(t){return Array.apply(null,new Array(t)).map(Number.prototype.valueOf,0)}for(var r=t.length+2*e,i=t.map(function(t){return[].concat(n(e),t,n(e))}),s=0;st)return!1;if(n+=e[r+1],n>=t)return!0}}function n(t,n){return t<65?36===t:t<91||(t<97?95===t:t<123||(t<=65535?t>=170&&F.test(String.fromCharCode(t)):n!==!1&&e(t,j)))}function r(t,n){return t<48?36===t:t<58||!(t<65)&&(t<91||(t<97?95===t:t<123||(t<=65535?t>=170&&M.test(String.fromCharCode(t)):n!==!1&&(e(t,j)||e(t,B)))))}function i(t,e){return new V(t,{beforeExpr:!0,binop:e})}function s(t,e){return void 0===e&&(e={}),e.keyword=t,K[t]=new V(t,e)}function a(t,e){return 10===t||13===t||!e&&(8232===t||8233===t)}function o(t,e){return Z.call(t,e)}function u(t,e){for(var n=1,r=0;;){Y.lastIndex=r;var i=Y.exec(t);if(!(i&&i.index=2015&&(e.ecmaVersion-=2009),null==e.allowReserved&&(e.allowReserved=e.ecmaVersion<5),tt(e.onToken)){var r=e.onToken;e.onToken=function(t){return r.push(t)}}return tt(e.onComment)&&(e.onComment=c(e,e.onComment)),e}function c(t,e){return function(n,r,i,s,a,o){var u={type:n?"Block":"Line",value:r,start:i,end:s};t.locations&&(u.loc=new nt(this,a,o)),t.ranges&&(u.range=[i,s]),e.push(u)}}function l(t){return new RegExp("^(?:"+t.replace(/ /g,"|")+")$")}function p(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1}function f(t,e,n,r){return t.type=e,t.end=n,this.options.locations&&(t.loc.end=r),this.options.ranges&&(t.range[1]=n),t}function d(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode((t>>10)+55296,(1023&t)+56320))}function m(t){return 36===t||t>=40&&t<=43||46===t||63===t||t>=91&&t<=94||t>=123&&t<=125}function g(t){return n(t,!0)||36===t||95===t}function y(t){return r(t,!0)||36===t||95===t||8204===t||8205===t}function x(t){return t>=65&&t<=90||t>=97&&t<=122}function v(t){return t>=0&&t<=1114111}function b(t){return 100===t||68===t||115===t||83===t||119===t||87===t}function _(t){return x(t)||95===t}function T(t){return _(t)||E(t)}function E(t){return t>=48&&t<=57}function S(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function k(t){return t>=65&&t<=70?10+(t-65):t>=97&&t<=102?10+(t-97):t-48}function w(t){return t>=48&&t<=55}function A(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode((t>>10)+55296,(1023&t)+56320))}function R(t,e){return new st(e,t).parse()}function O(t,e,n){var r=new st(n,t,e);return r.nextToken(),r.parseExpression()}function C(t,e){return new st(e,t)}function D(e,n,r){t.parse_dammit=e,t.LooseParser=n,t.pluginsLoose=r}var I={3:"abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",5:"class enum extends super const export import",6:"enum",strict:"implements interface let package private protected public static yield",strictBind:"eval arguments"},P="break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this",N={5:P,6:P+" const class extends export import super"},L=/^in(stanceof)?$/,U="ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙՠ-ֈא-תׯ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࡠ-ࡪࢠ-ࢴࢶ-ࢽऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱৼਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡૹଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘ-ౚౠౡಀಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൔ-ൖൟ-ൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡸᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᲀ-ᲈᲐ-ᲺᲽ-Ჿᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄯㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿯ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞹꟷ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꣽꣾꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭥꭰ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ",G="‌‍·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߽߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛࣓-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯৾ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ૺ-૿ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఄా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ഀ-ഃ഻഼ാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ංඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ູົຼ່-ໍ໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠐-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭ᳲ-᳴᳷-᳹᷀-᷹᷻-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-ꣅ꣐-꣙꣠-꣱ꣿ-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍-﹏0-9_",F=new RegExp("["+U+"]"),M=new RegExp("["+U+G+"]");U=G=null;var j=[0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,190,52,76,44,33,24,27,35,30,0,12,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,26,230,43,117,63,32,0,257,0,11,39,8,0,22,0,12,39,3,3,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,68,12,0,67,12,65,1,31,6129,15,754,9486,286,82,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541],B=[509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,280,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239],V=function(t,e){void 0===e&&(e={}),this.label=t,this.keyword=e.keyword,this.beforeExpr=!!e.beforeExpr,this.startsExpr=!!e.startsExpr,this.isLoop=!!e.isLoop,this.isAssign=!!e.isAssign,this.prefix=!!e.prefix,this.postfix=!!e.postfix,this.binop=e.binop||null,this.updateContext=null},X={beforeExpr:!0},z={startsExpr:!0},K={},W={num:new V("num",z),regexp:new V("regexp",z),string:new V("string",z),name:new V("name",z),eof:new V("eof"),bracketL:new V("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new V("]"),braceL:new V("{",{beforeExpr:!0,startsExpr:!0}),braceR:new V("}"),parenL:new V("(",{beforeExpr:!0,startsExpr:!0}),parenR:new V(")"),comma:new V(",",X),semi:new V(";",X),colon:new V(":",X),dot:new V("."),question:new V("?",X),arrow:new V("=>",X),template:new V("template"),invalidTemplate:new V("invalidTemplate"),ellipsis:new V("...",X),backQuote:new V("`",z),dollarBraceL:new V("${",{beforeExpr:!0,startsExpr:!0}),eq:new V("=",{beforeExpr:!0,isAssign:!0}),assign:new V("_=",{beforeExpr:!0,isAssign:!0}),incDec:new V("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new V("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:i("||",1),logicalAND:i("&&",2),bitwiseOR:i("|",3),bitwiseXOR:i("^",4),bitwiseAND:i("&",5),equality:i("==/!=/===/!==",6),relational:i("/<=/>=",7),bitShift:i("<>/>>>",8),plusMin:new V("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:i("%",10),star:i("*",10),slash:i("/",10),starstar:new V("**",{beforeExpr:!0}),_break:s("break"),_case:s("case",X),_catch:s("catch"),_continue:s("continue"),_debugger:s("debugger"),_default:s("default",X),_do:s("do",{isLoop:!0,beforeExpr:!0}),_else:s("else",X),_finally:s("finally"),_for:s("for",{isLoop:!0}),_function:s("function",z),_if:s("if"),_return:s("return",X),_switch:s("switch"),_throw:s("throw",X),_try:s("try"),_var:s("var"),_const:s("const"),_while:s("while",{isLoop:!0}),_with:s("with"),_new:s("new",{beforeExpr:!0,startsExpr:!0}),_this:s("this",z),_super:s("super",z),_class:s("class",z),_extends:s("extends",X),_export:s("export"),_import:s("import"),_null:s("null",z),_true:s("true",z),_false:s("false",z),_in:s("in",{beforeExpr:!0,binop:7}),_instanceof:s("instanceof",{beforeExpr:!0,binop:7}),_typeof:s("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:s("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:s("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},H=/\r\n?|\n|\u2028|\u2029/,Y=new RegExp(H.source,"g"),q=/[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/,J=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,Q=Object.prototype,Z=Q.hasOwnProperty,$=Q.toString,tt=Array.isArray||function(t){return"[object Array]"===$.call(t)},et=function(t,e){this.line=t,this.column=e};et.prototype.offset=function(t){return new et(this.line,this.column+t)};var nt=function(t,e,n){this.start=e,this.end=n,null!==t.sourceFile&&(this.source=t.sourceFile)},rt={ecmaVersion:7,sourceType:"script",onInsertedSemicolon:null,onTrailingComma:null,allowReserved:null,allowReturnOutsideFunction:!1,allowImportExportEverywhere:!1,allowAwaitOutsideFunction:!1,allowHashBang:!1,locations:!1,onToken:null,onComment:null,ranges:!1,program:null,sourceFile:null,directSourceFile:null,preserveParens:!1,plugins:{}},it={},st=function(t,e,n){this.options=t=h(t),this.sourceFile=t.sourceFile,this.keywords=l(N[t.ecmaVersion>=6?6:5]);var r="";if(!t.allowReserved){for(var i=t.ecmaVersion;!(r=I[i]);i--);"module"===t.sourceType&&(r+=" await")}this.reservedWords=l(r);var s=(r?r+" ":"")+I.strict;this.reservedWordsStrict=l(s),this.reservedWordsStrictBind=l(s+" "+I.strictBind),this.input=String(e),this.containsEsc=!1,this.loadPlugins(t.plugins),n?(this.pos=n,this.lineStart=this.input.lastIndexOf("\n",n-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(H).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=W.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule="module"===t.sourceType,this.strict=this.inModule||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.inFunction=this.inGenerator=this.inAsync=!1,this.yieldPos=this.awaitPos=0,this.labels=[],0===this.pos&&t.allowHashBang&&"#!"===this.input.slice(0,2)&&this.skipLineComment(2),this.scopeStack=[],this.enterFunctionScope(),this.regexpState=null};st.prototype.isKeyword=function(t){return this.keywords.test(t)},st.prototype.isReservedWord=function(t){return this.reservedWords.test(t)},st.prototype.extend=function(t,e){this[t]=e(this[t])},st.prototype.loadPlugins=function(t){var e=this;for(var n in t){var r=it[n];if(!r)throw new Error("Plugin '"+n+"' not found");r(e,t[n])}},st.prototype.parse=function(){var t=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(t)};var at=st.prototype,ot=/^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;at.strictDirective=function(t){for(var e=this;;){J.lastIndex=t,t+=J.exec(e.input)[0].length;var n=ot.exec(e.input.slice(t));if(!n)return!1;if("use strict"===(n[1]||n[2]))return!0;t+=n[0].length}},at.eat=function(t){return this.type===t&&(this.next(),!0)},at.isContextual=function(t){return this.type===W.name&&this.value===t&&!this.containsEsc},at.eatContextual=function(t){return!!this.isContextual(t)&&(this.next(),!0)},at.expectContextual=function(t){this.eatContextual(t)||this.unexpected()},at.canInsertSemicolon=function(){return this.type===W.eof||this.type===W.braceR||H.test(this.input.slice(this.lastTokEnd,this.start))},at.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0},at.semicolon=function(){this.eat(W.semi)||this.insertSemicolon()||this.unexpected()},at.afterTrailingComma=function(t,e){if(this.type===t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0},at.expect=function(t){this.eat(t)||this.unexpected()},at.unexpected=function(t){this.raise(null!=t?t:this.start,"Unexpected token")},at.checkPatternErrors=function(t,e){if(t){t.trailingComma>-1&&this.raiseRecoverable(t.trailingComma,"Comma is not permitted after the rest element");var n=e?t.parenthesizedAssign:t.parenthesizedBind;n>-1&&this.raiseRecoverable(n,"Parenthesized pattern")}},at.checkExpressionErrors=function(t,e){if(!t)return!1;var n=t.shorthandAssign,r=t.doubleProto;return e?(n>=0&&this.raise(n,"Shorthand property assignments are valid only in destructuring patterns"),void(r>=0&&this.raiseRecoverable(r,"Redefinition of __proto__ property"))):n>=0||r>=0},at.checkYieldAwaitInDefaultParams=function(){this.yieldPos&&(!this.awaitPos||this.yieldPos=6&&(t.sourceType=this.options.sourceType),this.finishNode(t,"Program")};var ht={kind:"loop"},ct={kind:"switch"};ut.isLet=function(){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;J.lastIndex=this.pos;var t=J.exec(this.input),e=this.pos+t[0].length,i=this.input.charCodeAt(e);if(91===i||123===i)return!0;if(n(i,!0)){for(var s=e+1;r(this.input.charCodeAt(s),!0);)++s;var a=this.input.slice(e,s);if(!L.test(a))return!0}return!1},ut.isAsyncFunction=function(){ diff --git a/dist/backend/cpu/kernel.js b/dist/backend/cpu/kernel.js index ff6b17c8..cf9d6b0d 100644 --- a/dist/backend/cpu/kernel.js +++ b/dist/backend/cpu/kernel.js @@ -19,7 +19,7 @@ module.exports = function (_KernelBase) { * @constructor CPUKernel * * @desc Kernel Implementation for CPU. - * + * *

Instantiates properties to the CPU Kernel.

* * @extends KernelBase @@ -60,7 +60,7 @@ module.exports = function (_KernelBase) { * @function * @name validateOptions * - * @desc Validate options related to CPU Kernel, such as + * @desc Validate options related to CPU Kernel, such as * dimensions size, and auto dimension support. * */ @@ -92,8 +92,8 @@ module.exports = function (_KernelBase) { * @function * @name build * - * @desc Builds the Kernel, by generating the kernel - * string using thread dimensions, and arguments + * @desc Builds the Kernel, by generating the kernel + * string using thread dimensions, and arguments * supplied to the kernel. * *

If the graphical flag is enabled, canvas is used.

@@ -107,7 +107,10 @@ module.exports = function (_KernelBase) { this.setupParams(arguments); this.validateOptions(); var canvas = this._canvas; - this._canvasCtx = canvas.getContext('2d'); + if (canvas) { + // if node or canvas is not found, don't die + this._canvasCtx = canvas.getContext('2d'); + } var threadDim = this.threadDim = utils.clone(this.output); while (threadDim.length < 3) { @@ -115,8 +118,12 @@ module.exports = function (_KernelBase) { } if (this.graphical) { - canvas.width = threadDim[0]; - canvas.height = threadDim[1]; + var _canvas = this._canvas; + if (!_canvas) { + throw new Error('no canvas available for using graphical output'); + } + _canvas.width = threadDim[0]; + _canvas.height = threadDim[1]; this._imageData = this._canvasCtx.createImageData(threadDim[0], threadDim[1]); this._colorData = new Uint8ClampedArray(threadDim[0] * threadDim[1] * 4); } @@ -165,7 +172,7 @@ module.exports = function (_KernelBase) { * @name getKernelString * * @desc Generates kernel string for this kernel program. - * + * *

If sub-kernels are supplied, they are also factored in. * This string can be saved by calling the `toString` method * and then can be reused later.

diff --git a/package.json b/package.json index 8c085bbb..5b868974 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gpu.js", - "version": "1.10.3", + "version": "1.10.4", "description": "GPU Accelerated JavaScript", "main": "./dist/index.js", "files": [ diff --git a/src/backend/cpu/kernel.js b/src/backend/cpu/kernel.js index 2a6bffca..2c0d3404 100644 --- a/src/backend/cpu/kernel.js +++ b/src/backend/cpu/kernel.js @@ -10,7 +10,7 @@ module.exports = class CPUKernel extends KernelBase { * @constructor CPUKernel * * @desc Kernel Implementation for CPU. - * + * *

Instantiates properties to the CPU Kernel.

* * @extends KernelBase @@ -47,7 +47,7 @@ module.exports = class CPUKernel extends KernelBase { * @function * @name validateOptions * - * @desc Validate options related to CPU Kernel, such as + * @desc Validate options related to CPU Kernel, such as * dimensions size, and auto dimension support. * */ @@ -75,8 +75,8 @@ module.exports = class CPUKernel extends KernelBase { * @function * @name build * - * @desc Builds the Kernel, by generating the kernel - * string using thread dimensions, and arguments + * @desc Builds the Kernel, by generating the kernel + * string using thread dimensions, and arguments * supplied to the kernel. * *

If the graphical flag is enabled, canvas is used.

@@ -87,7 +87,10 @@ module.exports = class CPUKernel extends KernelBase { this.setupParams(arguments); this.validateOptions(); const canvas = this._canvas; - this._canvasCtx = canvas.getContext('2d'); + if (canvas) { + // if node or canvas is not found, don't die + this._canvasCtx = canvas.getContext('2d'); + } const threadDim = this.threadDim = utils.clone(this.output); while (threadDim.length < 3) { @@ -95,6 +98,10 @@ module.exports = class CPUKernel extends KernelBase { } if (this.graphical) { + const canvas = this._canvas; + if (!canvas) { + throw new Error('no canvas available for using graphical output'); + } canvas.width = threadDim[0]; canvas.height = threadDim[1]; this._imageData = this._canvasCtx.createImageData(threadDim[0], threadDim[1]); @@ -144,7 +151,7 @@ module.exports = class CPUKernel extends KernelBase { * @name getKernelString * * @desc Generates kernel string for this kernel program. - * + * *

If sub-kernels are supplied, they are also factored in. * This string can be saved by calling the `toString` method * and then can be reused later.

diff --git a/test/all.html b/test/all.html index 00bbe94c..9936d06a 100644 --- a/test/all.html +++ b/test/all.html @@ -89,5 +89,6 @@ + diff --git a/test/issues/401-cpu-canvas-check.js b/test/issues/401-cpu-canvas-check.js new file mode 100644 index 00000000..e87e89ae --- /dev/null +++ b/test/issues/401-cpu-canvas-check.js @@ -0,0 +1,30 @@ +(function() { + QUnit.test('Issue #401 - cpu no canvas graphical', function(assert) { + assert.throws(function() { + GPU.CPUKernel.prototype.build.apply({ + setupConstants: function() {}, + setupParams: function() {}, + validateOptions: function() {}, + getKernelString: function() {}, + graphical: true, + output: [1], + _canvas: null + }, []); + }, + new Error('no canvas available for using graphical output'), + 'throws when canvas is not available and using graphical output'); + }); + + QUnit.test('Issue #401 - cpu no canvas', function(assert) { + GPU.CPUKernel.prototype.build.apply({ + setupConstants: function() {}, + setupParams: function() {}, + validateOptions: function() {}, + getKernelString: function() {}, + graphical: false, + output: [1], + _canvas: null + }, []); + assert.equal(true, true, 'ok when canvas is not available and not using graphical output'); + }); +})(); \ No newline at end of file