1.1 --- a/micropython/syspython.py Sun Jul 07 21:06:01 2013 +0200
1.2 +++ b/micropython/syspython.py Mon Jul 08 00:37:20 2013 +0200
1.3 @@ -731,9 +731,56 @@
1.4 self._visitBitBinary(node)
1.5
1.6 def visitCallFunc(self, node):
1.7 +
1.8 + # Determine whether the invocation target is known.
1.9 +
1.10 + n = node.node
1.11 + attr = n._attr
1.12 +
1.13 + args = [self.dispatch(node.node)] + [self.dispatch(arg) for arg in node.args]
1.14 +
1.15 + if not attr or isinstance(attr, Instance):
1.16 + op = "apply"
1.17 +
1.18 + # Invocations with some knowledge available.
1.19 +
1.20 + else:
1.21 + context = attr.get_context()
1.22 + value = attr.get_value()
1.23 +
1.24 + # Class invocations.
1.25 +
1.26 + if isinstance(value, Class):
1.27 + op = "applyclass"
1.28 + if value:
1.29 + args[0] = quoted_ref(value)
1.30 + else:
1.31 +
1.32 + # Function invocations.
1.33 +
1.34 + if context is ReplaceableContext:
1.35 + op = "applyfunction"
1.36 +
1.37 + # Method invocations via classes.
1.38 +
1.39 + elif isinstance(context, Class) and value:
1.40 + op = "applystaticmethod"
1.41 + args.insert(0, quoted_ref(context))
1.42 + args[1] = quoted_ref(value)
1.43 +
1.44 + # Plain method invocations.
1.45 +
1.46 + elif context:
1.47 + op = "applymethod"
1.48 +
1.49 + # Unknown invocations.
1.50 +
1.51 + else:
1.52 + op = "apply"
1.53 +
1.54 return compiler.ast.CallFunc(
1.55 - special_name("apply"),
1.56 - [self.dispatch(node.node)] + [self.dispatch(arg) for arg in node.args],
1.57 + special_name(op),
1.58 + args,
1.59 node.star_args and self.dispatch(node.star_args),
1.60 node.dstar_args and self.dispatch(node.dstar_args)
1.61 )