1.1 --- a/micropython/syspython.py Fri Nov 15 21:56:10 2013 +0100
1.2 +++ b/micropython/syspython.py Fri Nov 15 21:57:29 2013 +0100
1.3 @@ -747,12 +747,18 @@
1.4
1.5 # Determine whether the invocation target is known.
1.6
1.7 - n = node.node
1.8 - attr = n._attr
1.9 -
1.10 args = [self.dispatch(node.node)] + [self.dispatch(arg) for arg in node.args]
1.11
1.12 - if not attr or isinstance(attr, Instance):
1.13 + target = node.node
1.14 +
1.15 + # Attribute information is only known for specific accessors.
1.16 +
1.17 + if isinstance(target, compiler.ast.AttributeAccessor):
1.18 + attr = target._attr
1.19 + else:
1.20 + attr = None
1.21 +
1.22 + if not attr or isinstance(attr, (Instance, UnresolvedName)):
1.23 op = "apply"
1.24
1.25 # Invocations with some knowledge available.
1.26 @@ -835,6 +841,12 @@
1.27 def visitDiv(self, node):
1.28 return self._visitBinary(node)
1.29
1.30 + def visitExec(self, node):
1.31 +
1.32 + # NOTE: Return the statement for now.
1.33 +
1.34 + return node
1.35 +
1.36 def visitFloorDiv(self, node):
1.37 return self._visitBinary(node)
1.38
1.39 @@ -1140,6 +1152,32 @@
1.40 def visitUnarySub(self, node):
1.41 return self._visitUnary(node)
1.42
1.43 + def visitWith(self, node):
1.44 +
1.45 + """
1.46 + Convert from...
1.47 +
1.48 + with <expr> as <var>:
1.49 + ...
1.50 +
1.51 + ...to...
1.52 +
1.53 + _manager = <var> = <expr> # <var> may be absent
1.54 + _exit = _manager.__exit__
1.55 + _manager.__enter__()
1.56 + try:
1.57 + ...
1.58 + except Exception, exc:
1.59 + if not _exit(exc.type, exc.value, exc.tb):
1.60 + raise
1.61 + else:
1.62 + _exit(None, None, None)
1.63 + """
1.64 +
1.65 + # NOTE: For now, not adding this exuberance to the output.
1.66 +
1.67 + return node
1.68 +
1.69 # Convenience functions.
1.70
1.71 def convert(module, program, filename):