1.1 --- a/micropython/ast.py Mon Feb 18 01:22:25 2008 +0100
1.2 +++ b/micropython/ast.py Tue Feb 19 00:05:22 2008 +0100
1.3 @@ -278,18 +278,18 @@
1.4 the correct location, then invoke the function.
1.5 """
1.6
1.7 - # Record the location of the invocation.
1.8 + # Mark the frame, evaluate the target, generate the call.
1.9 +
1.10 + self._startCallFunc()
1.11 + self.dispatch(node.node)
1.12 + self._generateCallFunc(node.args, node)
1.13 +
1.14 + def _startCallFunc(self):
1.15 +
1.16 + "Record the location of the invocation."
1.17
1.18 self.new_op(MakeFrame()) # records the start of the frame
1.19
1.20 - # Evaluate the target.
1.21 -
1.22 - self.dispatch(node.node)
1.23 -
1.24 - # Generate the call.
1.25 -
1.26 - self._generateCallFunc(node.args, node)
1.27 -
1.28 def _generateCallFunc(self, args, node):
1.29
1.30 # NOTE: Only simple cases are used for optimisations.
1.31 @@ -297,8 +297,24 @@
1.32 last = self.last_op()
1.33 if isinstance(last, (LoadName, LoadAttr)) and last.attr.assignments == 1:
1.34 target = last.attr.value
1.35 + context = last.attr.parent
1.36 else:
1.37 target = None
1.38 + context = None
1.39 +
1.40 + # Where a target is known and has a known context, avoid generating any
1.41 + # first argument.
1.42 +
1.43 + if context is not None:
1.44 + pass # NOTE: Class methods should be supported.
1.45 + else:
1.46 + continue_label = self.new_label()
1.47 + self.new_op(LoadContext())
1.48 + self.new_op(CheckContext())
1.49 + self.new_op(JumpIfTrue(continue_label))
1.50 + self.new_op(LoadConst("TypeError")) # NOTE: Do this properly!
1.51 + self.new_op(RaiseException())
1.52 + self.set_label(continue_label)
1.53
1.54 # Evaluate the arguments.
1.55
1.56 @@ -418,6 +434,7 @@
1.57
1.58 # Get the "list" to be iterated over, obtain its iterator.
1.59
1.60 + self._startCallFunc()
1.61 self.dispatch(node.list)
1.62 self._generateAttr("__iter__", (LoadAttr, LoadAttrIndex))
1.63 self._generateCallFunc([], node)
1.64 @@ -429,6 +446,7 @@
1.65
1.66 # Use the iterator to get the next value.
1.67
1.68 + self._startCallFunc()
1.69 self.new_op(Duplicate())
1.70 self._generateAttr("next", (LoadAttr, LoadAttrIndex))
1.71 self._generateCallFunc([], node)