1.1 --- a/docs/syspython.txt Sun Jul 07 21:06:01 2013 +0200
1.2 +++ b/docs/syspython.txt Mon Jul 08 00:37:20 2013 +0200
1.3 @@ -23,6 +23,9 @@
1.4 or method. Note that the apply function resembles the Python function of the
1.5 same name but is not actually that particular function.
1.6
1.7 +A family of special functions for invocations exists, addressing optimisation
1.8 +situations identified by program analysis.
1.9 +
1.10 Low-Level Code
1.11 --------------
1.12
2.1 --- a/micropython/syspython.py Sun Jul 07 21:06:01 2013 +0200
2.2 +++ b/micropython/syspython.py Mon Jul 08 00:37:20 2013 +0200
2.3 @@ -731,9 +731,56 @@
2.4 self._visitBitBinary(node)
2.5
2.6 def visitCallFunc(self, node):
2.7 +
2.8 + # Determine whether the invocation target is known.
2.9 +
2.10 + n = node.node
2.11 + attr = n._attr
2.12 +
2.13 + args = [self.dispatch(node.node)] + [self.dispatch(arg) for arg in node.args]
2.14 +
2.15 + if not attr or isinstance(attr, Instance):
2.16 + op = "apply"
2.17 +
2.18 + # Invocations with some knowledge available.
2.19 +
2.20 + else:
2.21 + context = attr.get_context()
2.22 + value = attr.get_value()
2.23 +
2.24 + # Class invocations.
2.25 +
2.26 + if isinstance(value, Class):
2.27 + op = "applyclass"
2.28 + if value:
2.29 + args[0] = quoted_ref(value)
2.30 + else:
2.31 +
2.32 + # Function invocations.
2.33 +
2.34 + if context is ReplaceableContext:
2.35 + op = "applyfunction"
2.36 +
2.37 + # Method invocations via classes.
2.38 +
2.39 + elif isinstance(context, Class) and value:
2.40 + op = "applystaticmethod"
2.41 + args.insert(0, quoted_ref(context))
2.42 + args[1] = quoted_ref(value)
2.43 +
2.44 + # Plain method invocations.
2.45 +
2.46 + elif context:
2.47 + op = "applymethod"
2.48 +
2.49 + # Unknown invocations.
2.50 +
2.51 + else:
2.52 + op = "apply"
2.53 +
2.54 return compiler.ast.CallFunc(
2.55 - special_name("apply"),
2.56 - [self.dispatch(node.node)] + [self.dispatch(arg) for arg in node.args],
2.57 + special_name(op),
2.58 + args,
2.59 node.star_args and self.dispatch(node.star_args),
2.60 node.dstar_args and self.dispatch(node.dstar_args)
2.61 )