1.1 --- a/micropython/syspython.py Thu Jul 04 22:53:22 2013 +0200
1.2 +++ b/micropython/syspython.py Thu Jul 04 23:46:09 2013 +0200
1.3 @@ -132,8 +132,9 @@
1.4 op_name = operator_functions[node.op]
1.5
1.6 return self.dispatch(node.node, compiler.ast.CallFunc(
1.7 - module_attribute("operator", op_name),
1.8 - [self.dispatch(node.node), self.dispatch(node.expr)]
1.9 + special_name("apply"),
1.10 + [module_attribute("operator", op_name),
1.11 + self.dispatch(node.node), self.dispatch(node.expr)]
1.12 ))
1.13
1.14 visitBreak = NOP
1.15 @@ -251,8 +252,8 @@
1.16 compiler.ast.CallFunc(special_name("storetemp"), [
1.17 temp,
1.18 compiler.ast.CallFunc(
1.19 - module_attribute("__builtins__", "iter"),
1.20 - [self.dispatch(node.list)]
1.21 + special_name("apply"),
1.22 + [module_attribute("__builtins__", "iter"), self.dispatch(node.list)]
1.23 )
1.24 ]),
1.25 # while True: ...
1.26 @@ -403,15 +404,19 @@
1.27 return compiler.ast.Stmt([])
1.28
1.29 def visitPrint(self, node):
1.30 - return compiler.ast.Print(
1.31 - [self.dispatch(n) for n in node.nodes],
1.32 - node.dest and self.dispatch(node.dest)
1.33 + return compiler.ast.CallFunc(
1.34 + special_name("apply"),
1.35 + [module_attribute("__builtins__", "_print"),
1.36 + node.dest and self.dispatch(node.dest) or special_name("None")]
1.37 + + [self.dispatch(n) for n in node.nodes]
1.38 )
1.39
1.40 def visitPrintnl(self, node):
1.41 - return compiler.ast.Print(
1.42 - [self.dispatch(n) for n in node.nodes],
1.43 - node.dest and self.dispatch(node.dest)
1.44 + return compiler.ast.CallFunc(
1.45 + special_name("apply"),
1.46 + [module_attribute("__builtins__", "_println"),
1.47 + node.dest and self.dispatch(node.dest) or special_name("None")]
1.48 + + [self.dispatch(n) for n in node.nodes]
1.49 )
1.50
1.51 def visitRaise(self, node):
1.52 @@ -460,8 +465,8 @@
1.53
1.54 for n in node.nodes[1:]:
1.55 last = compiler.ast.CallFunc(
1.56 - module_attribute("operator", op_name),
1.57 - [last, self.dispatch(n)]
1.58 + special_name("apply"),
1.59 + [module_attribute("operator", op_name), last, self.dispatch(n)]
1.60 )
1.61
1.62 return last
1.63 @@ -470,16 +475,17 @@
1.64 op_name = operator_functions[node.__class__.__name__]
1.65
1.66 return compiler.ast.CallFunc(
1.67 - module_attribute("operator", op_name),
1.68 - [self.dispatch(node.left), self.dispatch(node.right)]
1.69 + special_name("apply"),
1.70 + [module_attribute("operator", op_name),
1.71 + self.dispatch(node.left), self.dispatch(node.right)]
1.72 )
1.73
1.74 def _visitUnary(self, node):
1.75 op_name = operator_functions[node.__class__.__name__]
1.76
1.77 return compiler.ast.CallFunc(
1.78 - module_attribute("operator", op_name),
1.79 - [self.dispatch(node.expr)]
1.80 + special_name("apply"),
1.81 + [module_attribute("operator", op_name), self.dispatch(node.expr)]
1.82 )
1.83
1.84 def _generateValue(self, value):
1.85 @@ -614,8 +620,8 @@
1.86
1.87 return compiler.ast.Stmt([
1.88 self.dispatch(n, compiler.ast.CallFunc(
1.89 - module_attribute("operator", "getitem"),
1.90 - [expr, i]
1.91 + special_name("apply"),
1.92 + [module_attribute("operator", "getitem"), expr, i]
1.93 ))
1.94 for (i, n) in enumerate(node.nodes)
1.95 ])
1.96 @@ -731,8 +737,9 @@
1.97 else:
1.98 nodes.append(
1.99 compiler.ast.CallFunc(
1.100 - module_attribute("operator", operator_functions.get(op_name)),
1.101 - [self.dispatch(left), self.dispatch(right)]
1.102 + special_name("apply"),
1.103 + [module_attribute("operator", operator_functions.get(op_name)),
1.104 + self.dispatch(left), self.dispatch(right)]
1.105 )
1.106 )
1.107 left = right
1.108 @@ -831,8 +838,8 @@
1.109 compiler.ast.CallFunc(special_name("storetemp"), [
1.110 temp,
1.111 compiler.ast.CallFunc(
1.112 - module_attribute("__builtins__", "list"),
1.113 - []
1.114 + special_name("apply"),
1.115 + [module_attribute("__builtins__", "list")]
1.116 )
1.117 ]),
1.118 # ...
1.119 @@ -881,8 +888,8 @@
1.120 compiler.ast.CallFunc(special_name("storetemp"), [
1.121 temp,
1.122 compiler.ast.CallFunc(
1.123 - module_attribute("__builtins__", "iter"),
1.124 - [self.dispatch(node.list)]
1.125 + special_name("apply"),
1.126 + [module_attribute("__builtins__", "iter"), self.dispatch(node.list)]
1.127 )
1.128 ]),
1.129 # while True: ...
1.130 @@ -1010,9 +1017,12 @@
1.131
1.132 def visitSlice(self, node, expr=None):
1.133 return compiler.ast.CallFunc(
1.134 - module_attribute("operator", expr and "setslice" or "getslice"),
1.135 - [self.dispatch(node.expr), node.lower and self.dispatch(node.lower), node.upper and self.dispatch(node.upper)]
1.136 - + (expr and [expr] or [])
1.137 + special_name("apply"),
1.138 + [module_attribute("operator", expr and "setslice" or "getslice"),
1.139 + self.dispatch(node.expr),
1.140 + node.lower and self.dispatch(node.lower),
1.141 + node.upper and self.dispatch(node.upper)]
1.142 + + (expr and [expr] or [])
1.143 )
1.144
1.145 def visitSliceobj(self, node):
1.146 @@ -1023,9 +1033,11 @@
1.147
1.148 def visitSubscript(self, node, expr=None):
1.149 return compiler.ast.CallFunc(
1.150 - module_attribute("operator", expr and "setitem" or "getitem"),
1.151 - [self.dispatch(node.expr), compiler.ast.Tuple([self.dispatch(sub) for sub in node.subs])]
1.152 - + (expr and [expr] or [])
1.153 + special_name("apply"),
1.154 + [module_attribute("operator", expr and "setitem" or "getitem"),
1.155 + self.dispatch(node.expr),
1.156 + compiler.ast.Tuple([self.dispatch(sub) for sub in node.subs])]
1.157 + + (expr and [expr] or [])
1.158 )
1.159
1.160 def visitTuple(self, node, expr=None):