@@ -153,6 +153,7 @@ def __init__(self, source=None, module=None, module_path=None, dart=False, coffe
153153 self ._with_rpc = None
154154 self ._with_rpc_name = None
155155 self ._with_direct_keys = False
156+ self ._with_glsl = False
156157
157158 self ._source = source .splitlines ()
158159 self ._classes = dict () ## class name : [method names]
@@ -1134,7 +1135,9 @@ def visit_Return(self, node):
11341135 # writer.write('self["__dict__"]["%s"] = %s' %(self._cached_property, self.visit(node.value)) )
11351136 # writer.write('return self["__dict__"]["%s"]' %self._cached_property)
11361137 #else:
1137- if self ._inline :
1138+ if self ._with_glsl :
1139+ writer .write ('out_float = %s' % self .visit (node .value ))
1140+ elif self ._inline :
11381141 writer .write ('__returns__%s = %s' % (self ._inline [- 1 ], self .visit (node .value )) )
11391142 if self ._inline_breakout :
11401143 writer .write ('break' )
@@ -1160,7 +1163,10 @@ def visit_BinOp(self, node):
11601163 op = self .visit (node .op )
11611164 right = self .visit (node .right )
11621165
1163- if op == '|' :
1166+ if self ._with_glsl :
1167+ return '(%s %s %s)' % (left , op , right )
1168+
1169+ elif op == '|' :
11641170 if isinstance (node .right , Str ):
11651171 self ._custom_op_hack = (node .right .s , left )
11661172 return ''
@@ -1451,7 +1457,7 @@ def visit_Subscript(self, node):
14511457 #return '%s["$wrapped"]' %name
14521458 return '%s[...]' % name
14531459
1454- elif self ._with_ll :
1460+ elif self ._with_ll or self . _with_glsl :
14551461 return '%s[ %s ]' % (name , self .visit (node .slice ))
14561462
14571463 elif self ._with_js or self ._with_dart :
@@ -2392,7 +2398,7 @@ def visit_FunctionDef(self, node):
23922398 self ._cached_property = None
23932399 self ._func_typedefs = {}
23942400
2395- if writer .is_at_global_level () and not self ._with_webworker :
2401+ if writer .is_at_global_level () and not self ._with_webworker and not self . _with_glsl :
23962402 self ._global_functions [ node .name ] = node ## save ast-node
23972403
23982404 for decorator in reversed (node .decorator_list ):
@@ -2564,7 +2570,11 @@ def visit_FunctionDef(self, node):
25642570 writer .write ( 'def %s( %s ):' % (node .name , ',' .join (args )) )
25652571
25662572
2567- elif self ._with_js or javascript or self ._with_ll :# or self._with_coffee:
2573+ elif self ._with_js or javascript or self ._with_ll or self ._with_glsl :
2574+
2575+ if self ._with_glsl :
2576+ writer .write ('@__glsl__' )
2577+
25682578 if node .args .vararg :
25692579 #raise SyntaxError( 'pure javascript functions can not take variable arguments (*args)' )
25702580 writer .write ('#WARNING - NOT IMPLEMENTED: javascript-mode functions with (*args)' )
@@ -2994,6 +3004,13 @@ def visit_For(self, node):
29943004 c .constant = True
29953005 self ._call_ids += 1
29963006
3007+ if self ._with_glsl :
3008+ writer .write ( 'for %s in %s:' % (self .visit (node .target ), self .visit (node .iter )) )
3009+ writer .push ()
3010+ map (self .visit , node .body )
3011+ writer .pull ()
3012+ return None
3013+
29973014 if self ._with_rpc_name and isinstance (node .iter , ast .Attribute ) and isinstance (node .iter .value , ast .Name ) and node .iter .value .id == self ._with_rpc_name :
29983015 target = self .visit (node .target )
29993016 writer .write ('def __rpc_loop__():' )
@@ -3240,7 +3257,16 @@ def visit_While(self, node):
32403257 def visit_With (self , node ):
32413258 global writer
32423259
3243- if isinstance ( node .context_expr , ast .Call ) and isinstance (node .context_expr .func , ast .Name ) and node .context_expr .func .id == 'rpc' :
3260+ if isinstance ( node .context_expr , Name ) and node .context_expr .id == 'glsl' :
3261+ writer .inline_glsl = True
3262+ self ._with_glsl = True
3263+ for b in node .body :
3264+ a = self .visit (b )
3265+ if a : writer .write (a )
3266+ self ._with_glsl = False
3267+ writer .inline_glsl = False
3268+
3269+ elif isinstance ( node .context_expr , ast .Call ) and isinstance (node .context_expr .func , ast .Name ) and node .context_expr .func .id == 'rpc' :
32443270 self ._with_rpc = self .visit ( node .context_expr .args [0 ] )
32453271 if isinstance (node .optional_vars , ast .Name ):
32463272 self ._with_rpc_name = node .optional_vars .id
0 commit comments