@@ -4,6 +4,7 @@ var functionNode_webgl = (function() {
44 var gpu , opt , jsFunctionString ;
55
66 function isIdentifierConstant ( paramName ) {
7+ if ( ! opt . constants ) return false ;
78 return opt . constants . indexOf ( paramName ) != - 1 ;
89 }
910
@@ -38,6 +39,9 @@ var functionNode_webgl = (function() {
3839 function functionNode_webgl ( inNode , _opt ) {
3940 gpu = inNode . gpu ;
4041 opt = _opt ;
42+ if ( opt . debug ) {
43+ console . log ( inNode ) ;
44+ }
4145 jsFunctionString = inNode . jsFunctionString ;
4246 inNode . webglFunctionString_array = ast_generic ( inNode . getJS_AST ( ) , [ ] , inNode ) ;
4347 inNode . webglFunctionString = webgl_regex_optimize (
@@ -289,6 +293,8 @@ var functionNode_webgl = (function() {
289293 ///
290294 /// @returns the appened retArr
291295 function ast_BinaryExpression ( ast , retArr , funcParam ) {
296+ retArr . push ( "(" ) ;
297+
292298 if ( ast . operator == "%" ) {
293299 retArr . push ( "mod(" ) ;
294300 ast_generic ( ast . left , retArr , funcParam ) ;
@@ -301,6 +307,8 @@ var functionNode_webgl = (function() {
301307 ast_generic ( ast . right , retArr , funcParam ) ;
302308 }
303309
310+ retArr . push ( ")" ) ;
311+
304312 return retArr ;
305313 }
306314
@@ -377,8 +385,12 @@ var functionNode_webgl = (function() {
377385 retArr . push ( forNode . test . operator ) ;
378386 ast_generic ( forNode . test . right , retArr , funcParam ) ;
379387 retArr . push ( ") {\n" ) ;
380- for ( var i = 0 ; i < forNode . body . body . length ; i ++ ) {
381- ast_generic ( forNode . body . body [ i ] , retArr , funcParam ) ;
388+ if ( forNode . body . type == "BlockStatement" ) {
389+ for ( var i = 0 ; i < forNode . body . body . length ; i ++ ) {
390+ ast_generic ( forNode . body . body [ i ] , retArr , funcParam ) ;
391+ }
392+ } else {
393+ ast_generic ( forNode . body , retArr , funcParam ) ;
382394 }
383395 retArr . push ( "} else {\n" ) ;
384396 retArr . push ( "break;\n" ) ;
@@ -494,11 +506,23 @@ var functionNode_webgl = (function() {
494506 retArr . push ( "if(" ) ;
495507 ast_generic ( ifNode . test , retArr , funcParam ) ;
496508 retArr . push ( ")" ) ;
497- ast_generic ( ifNode . consequent , retArr , funcParam ) ;
509+ if ( ifNode . consequent . type == "BlockStatement" ) {
510+ ast_generic ( ifNode . consequent , retArr , funcParam ) ;
511+ } else {
512+ retArr . push ( " {\n" ) ;
513+ ast_generic ( ifNode . consequent , retArr , funcParam ) ;
514+ retArr . push ( "\n}\n" ) ;
515+ }
498516
499517 if ( ifNode . alternate ) {
500518 retArr . push ( "else " ) ;
501- ast_generic ( ifNode . alternate , retArr , funcParam ) ;
519+ if ( ifNode . alternate . type == "BlockStatement" ) {
520+ ast_generic ( ifNode . alternate , retArr , funcParam ) ;
521+ } else {
522+ retArr . push ( " {\n" ) ;
523+ ast_generic ( ifNode . alternate , retArr , funcParam ) ;
524+ retArr . push ( "\n}\n" ) ;
525+ }
502526 }
503527 return retArr ;
504528
0 commit comments