@@ -17,7 +17,7 @@ const localPrefix = 'this.';
1717const constantsPrefix = 'this.constants.' ;
1818
1919function isIdentifierKernelParam ( paramName , ast , funcParam ) {
20- return funcParam . paramNames . indexOf ( paramName ) != - 1 ;
20+ return funcParam . paramNames . indexOf ( paramName ) !== - 1 ;
2121}
2222
2323function ensureIndentifierType ( paramName , expectedType , ast , funcParam ) {
@@ -27,7 +27,7 @@ function ensureIndentifierType(paramName, expectedType, ast, funcParam) {
2727 throw 'Error unexpected identifier ' + paramName + ' on line ' + start . line ;
2828 } else {
2929 const actualType = funcParam . paramType [ funcParam . paramNames . indexOf ( paramName ) ] ;
30- if ( actualType != expectedType ) {
30+ if ( actualType !== expectedType ) {
3131 throw 'Error unexpected identifier ' + paramName + ' on line ' + start . line ;
3232 }
3333 }
@@ -69,31 +69,27 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
6969 super ( functionName , jsFunction , paramTypeArray , returnType ) ;
7070 this . gpu = null ;
7171 this . opt = null ;
72- this . jsFunctionString = null ;
73- this . webGlFunctionPrototypeString = null ;
7472 }
7573
76- generate ( inNode , _opt ) {
77- this . gpu = inNode . gpu ;
74+ generate ( _opt ) {
7875 const opt = this . opt = _opt || { } ;
7976 if ( opt . debug ) {
80- console . log ( inNode ) ;
77+ console . log ( this ) ;
8178 }
82- this . jsFunctionString = inNode . jsFunctionString ;
8379 if ( opt . prototypeOnly ) {
84- return GPUFunctionNode . astFunctionPrototype ( inNode . getJsAST ( ) , [ ] , inNode ) . join ( '' ) . trim ( ) ;
80+ return GPUFunctionNode . astFunctionPrototype ( this . getJsAST ( ) , [ ] , this ) . join ( '' ) . trim ( ) ;
8581 } else {
86- inNode . functionStringArray = this . astGeneric ( inNode . getJsAST ( ) , [ ] , inNode ) ;
82+ this . functionStringArray = this . astGeneric ( this . getJsAST ( ) , [ ] , this ) ;
8783 }
88- inNode . functionString = webGlRegexOptimize (
89- inNode . functionStringArray . join ( '' ) . trim ( )
90- ) ;
91- return inNode . functionString ;
84+ this . functionString = webGlRegexOptimize (
85+ this . functionStringArray . join ( '' ) . trim ( )
86+ ) ;
87+ return this . functionString ;
9288 }
9389
9490 isIdentifierConstant ( paramName ) {
9591 if ( ! this . opt . constants ) return false ;
96- return this . opt . constants . indexOf ( paramName ) != - 1 ;
92+ return this . opt . constants . indexOf ( paramName ) !== - 1 ;
9793 }
9894
9995 /// Prases the abstract syntax tree, genericially to its respective function
@@ -347,17 +343,17 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
347343 astBinaryExpression ( ast , retArr , funcParam ) {
348344 retArr . push ( '(' ) ;
349345
350- if ( ast . operator == '%' ) {
346+ if ( ast . operator === '%' ) {
351347 retArr . push ( 'mod(' ) ;
352348 this . astGeneric ( ast . left , retArr , funcParam ) ;
353349 retArr . push ( ',' ) ;
354350 this . astGeneric ( ast . right , retArr , funcParam ) ;
355351 retArr . push ( ')' ) ;
356- } else if ( ast . operator == '===' ) {
352+ } else if ( ast . operator === '===' ) {
357353 this . astGeneric ( ast . left , retArr , funcParam ) ;
358354 retArr . push ( '==' ) ;
359355 this . astGeneric ( ast . right , retArr , funcParam ) ;
360- } else if ( ast . operator == '!==' ) {
356+ } else if ( ast . operator === '!==' ) {
361357 this . astGeneric ( ast . left , retArr , funcParam ) ;
362358 retArr . push ( '!=' ) ;
363359 this . astGeneric ( ast . right , retArr , funcParam ) ;
@@ -380,24 +376,24 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
380376 ///
381377 /// @returns the append retArr
382378 astIdentifierExpression ( idtNode , retArr , funcParam ) {
383- if ( idtNode . type != 'Identifier' ) {
379+ if ( idtNode . type !== 'Identifier' ) {
384380 throw astErrorOutput (
385381 'IdentifierExpression - not an Identifier' ,
386382 ast , funcParam
387383 ) ;
388384 }
389385
390- if ( idtNode . name == 'gpu_threadX' ) {
386+ if ( idtNode . name === 'gpu_threadX' ) {
391387 retArr . push ( 'threadId.x' ) ;
392- } else if ( idtNode . name == 'gpu_threadY' ) {
388+ } else if ( idtNode . name === 'gpu_threadY' ) {
393389 retArr . push ( 'threadId.y' ) ;
394- } else if ( idtNode . name == 'gpu_threadZ' ) {
390+ } else if ( idtNode . name === 'gpu_threadZ' ) {
395391 retArr . push ( 'threadId.z' ) ;
396- } else if ( idtNode . name == 'gpu_dimensionsX' ) {
392+ } else if ( idtNode . name === 'gpu_dimensionsX' ) {
397393 retArr . push ( 'uOutputDim.x' ) ;
398- } else if ( idtNode . name == 'gpu_dimensionsY' ) {
394+ } else if ( idtNode . name === 'gpu_dimensionsY' ) {
399395 retArr . push ( 'uOutputDim.y' ) ;
400- } else if ( idtNode . name == 'gpu_dimensionsZ' ) {
396+ } else if ( idtNode . name === 'gpu_dimensionsZ' ) {
401397 retArr . push ( 'uOutputDim.z' ) ;
402398 } else {
403399 retArr . push ( 'user_' + idtNode . name ) ;
@@ -412,16 +408,16 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
412408 ///
413409 /// @returns the prased openclgl string
414410 astForStatement ( forNode , retArr , funcParam ) {
415- if ( forNode . type != 'ForStatement' ) {
411+ if ( forNode . type !== 'ForStatement' ) {
416412 throw astErrorOutput (
417413 'Invalid for statment' ,
418414 ast , funcParam
419415 ) ;
420416 }
421417
422- if ( forNode . test && forNode . test . type == 'BinaryExpression' ) {
423- if ( forNode . test . right . type == 'Identifier'
424- && forNode . test . operator == '<'
418+ if ( forNode . test && forNode . test . type === 'BinaryExpression' ) {
419+ if ( forNode . test . right . type === 'Identifier'
420+ && forNode . test . operator === '<'
425421 && this . isIdentifierConstant ( forNode . test . right . name ) == false ) {
426422
427423 if ( this . opt . loopMaxIterations === undefined ) {
@@ -445,8 +441,8 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
445441 retArr . push ( forNode . test . operator ) ;
446442 this . astGeneric ( forNode . test . right , retArr , funcParam ) ;
447443 retArr . push ( ') {\n' ) ;
448- if ( forNode . body . type == 'BlockStatement' ) {
449- for ( var i = 0 ; i < forNode . body . body . length ; i ++ ) {
444+ if ( forNode . body . type === 'BlockStatement' ) {
445+ for ( let i = 0 ; i < forNode . body . body . length ; i ++ ) {
450446 this . astGeneric ( forNode . body . body [ i ] , retArr , funcParam ) ;
451447 }
452448 } else {
@@ -483,7 +479,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
483479 ///
484480 /// @returns the prased openclgl string
485481 astWhileStatement ( whileNode , retArr , funcParam ) {
486- if ( whileNode . type != 'WhileStatement' ) {
482+ if ( whileNode . type !== 'WhileStatement' ) {
487483 throw astErrorOutput (
488484 'Invalid while statment' ,
489485 ast , funcParam
@@ -504,7 +500,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
504500 }
505501
506502 astAssignmentExpression ( assNode , retArr , funcParam ) {
507- if ( assNode . operator == '%=' ) {
503+ if ( assNode . operator === '%=' ) {
508504 this . astGeneric ( assNode . left , retArr , funcParam ) ;
509505 retArr . push ( '=' ) ;
510506 retArr . push ( 'mod(' ) ;
@@ -566,7 +562,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
566562 retArr . push ( 'if (' ) ;
567563 this . astGeneric ( ifNode . test , retArr , funcParam ) ;
568564 retArr . push ( ')' ) ;
569- if ( ifNode . consequent . type == 'BlockStatement' ) {
565+ if ( ifNode . consequent . type === 'BlockStatement' ) {
570566 this . astGeneric ( ifNode . consequent , retArr , funcParam ) ;
571567 } else {
572568 retArr . push ( ' {\n' ) ;
@@ -576,7 +572,7 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
576572
577573 if ( ifNode . alternate ) {
578574 retArr . push ( 'else ' ) ;
579- if ( ifNode . alternate . type == 'BlockStatement' ) {
575+ if ( ifNode . alternate . type === 'BlockStatement' ) {
580576 this . astGeneric ( ifNode . alternate , retArr , funcParam ) ;
581577 } else {
582578 retArr . push ( ' {\n' ) ;
@@ -639,16 +635,16 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
639635
640636 astMemberExpression ( mNode , retArr , funcParam ) {
641637 if ( mNode . computed ) {
642- if ( mNode . object . type == 'Identifier' ) {
638+ if ( mNode . object . type === 'Identifier' ) {
643639 // Working logger
644640 const reqName = mNode . object . name ;
645641 const funcName = funcParam . funcName || 'kernel' ;
646642 let assumeNotTexture = false ;
647643
648644 // Possibly an array request - handle it as such
649- if ( funcParam != 'kernel' && funcParam . paramNames ) {
645+ if ( funcParam !== 'kernel' && funcParam . paramNames ) {
650646 var idx = funcParam . paramNames . indexOf ( reqName ) ;
651- if ( idx >= 0 && funcParam . paramType [ idx ] == 'float' ) {
647+ if ( idx >= 0 && funcParam . paramType [ idx ] === 'float' ) {
652648 assumeNotTexture = true ;
653649 }
654650 }
@@ -701,17 +697,17 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
701697 unrolled = 'constants_' + unrolled . slice ( constantsPrefix . length ) ;
702698 }
703699
704- if ( unrolled_lc == 'this.thread.x' ) {
700+ if ( unrolled_lc === 'this.thread.x' ) {
705701 retArr . push ( 'threadId.x' ) ;
706- } else if ( unrolled_lc == 'this.thread.y' ) {
702+ } else if ( unrolled_lc === 'this.thread.y' ) {
707703 retArr . push ( 'threadId.y' ) ;
708- } else if ( unrolled_lc == 'this.thread.z' ) {
704+ } else if ( unrolled_lc === 'this.thread.z' ) {
709705 retArr . push ( 'threadId.z' ) ;
710- } else if ( unrolled_lc == 'this.dimensions.x' ) {
706+ } else if ( unrolled_lc === 'this.dimensions.x' ) {
711707 retArr . push ( 'uOutputDim.x' ) ;
712- } else if ( unrolled_lc == 'this.dimensions.y' ) {
708+ } else if ( unrolled_lc === 'this.dimensions.y' ) {
713709 retArr . push ( 'uOutputDim.y' ) ;
714- } else if ( unrolled_lc == 'this.dimensions.z' ) {
710+ } else if ( unrolled_lc === 'this.dimensions.z' ) {
715711 retArr . push ( 'uOutputDim.z' ) ;
716712 } else {
717713 retArr . push ( unrolled ) ;
@@ -738,13 +734,13 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
738734 ///
739735 /// @returns {String } the function namespace call, unrolled
740736 astMemberExpressionUnroll ( ast , funcParam ) {
741- if ( ast . type == 'Identifier' ) {
737+ if ( ast . type === 'Identifier' ) {
742738 return ast . name ;
743- } else if ( ast . type == 'ThisExpression' ) {
739+ } else if ( ast . type === 'ThisExpression' ) {
744740 return 'this' ;
745741 }
746742
747- if ( ast . type == 'MemberExpression' ) {
743+ if ( ast . type === 'MemberExpression' ) {
748744 if ( ast . object && ast . property ) {
749745 return (
750746 this . astMemberExpressionUnroll ( ast . object , funcParam ) +
@@ -855,14 +851,10 @@ module.exports = class GPUFunctionNode extends BaseFunctionNode {
855851 /// Returns:
856852 /// {String} webgl function string, result is cached under this.getFunctionPrototypeString
857853 ///
858- getFunctionPrototypeString ( opt ) {
859- opt = opt || { } ;
854+ getFunctionPrototypeString ( isRootKernel , options ) {
860855 if ( this . webGlFunctionPrototypeString ) {
861856 return this . webGlFunctionPrototypeString ;
862857 }
863- return this . functionPrototypeString = new FunctionNodeWebGl ( this , {
864- prototypeOnly : true ,
865- isRootKernel : opt . isRootKernel
866- } ) ;
858+ return this . functionPrototypeString = this . generate ( options ) ;
867859 }
868- }
860+ } ;
0 commit comments