1.1 --- a/micropython/trans.py Wed Aug 24 01:01:24 2011 +0200
1.2 +++ b/micropython/trans.py Wed Aug 24 01:05:46 2011 +0200
1.3 @@ -562,7 +562,7 @@
1.4 # Adjust the invocation frame for unknown invocations.
1.5 # Test the first argument if appropriate.
1.6
1.7 - self._generateCallFuncContextTest(temp_target, target, temp_context, temp_first_argument, node)
1.8 + self._generateCallFuncContextTest(target, temp_context, temp_first_argument, node)
1.9
1.10 # Traverse the keyword arguments adding them at the appropriate frame
1.11 # positions.
1.12 @@ -735,13 +735,13 @@
1.13 self.new_op(LoadAddress(target.default_attrs[pos - nargs_min]))
1.14 self.new_op(StoreFrame(pos))
1.15
1.16 - def _generateCallFuncContextTest(self, temp_target, target, temp_context, temp_first_argument, node):
1.17 + def _generateCallFuncContextTest(self, target, temp_context, temp_first_argument, node):
1.18
1.19 """
1.20 - Generate code to test for 'temp_target', representing the given
1.21 - 'target', the context provided by 'temp_context' against
1.22 - 'temp_first_argument', and to signal an exception (using 'node') if the
1.23 - context is incompatible with the first frame argument.
1.24 + Generate code involved in a call to the given 'target' to test the
1.25 + context provided by 'temp_context' against 'temp_first_argument', and to
1.26 + signal an exception (using 'node') if the context is incompatible with
1.27 + the first frame argument.
1.28
1.29 In addition, the invocation frame will be shifted if 'temp_context'
1.30 indicates a function or a class.
1.31 @@ -770,23 +770,28 @@
1.32 self.new_op(CheckClass(target="status"))
1.33 self.new_op(JumpIfFalse(continue_block, working="status"))
1.34
1.35 + # Test any explicit first argument against the context.
1.36 +
1.37 if temp_first_argument is not None:
1.38 - self.new_op(temp_first_argument)
1.39
1.40 # Check the current value (the argument) against the known context
1.41 # (given as the source).
1.42
1.43 - self.new_op(CheckInstance(target="status"))
1.44 - self.set_working(temp_context)
1.45 + temp_context = temp_context.copy()
1.46 + temp_context.target = "source"
1.47 + self.new_op(temp_context)
1.48 + self.new_op(temp_first_argument)
1.49 + self.new_op(CheckInstance(source="source", target="status"))
1.50
1.51 - self.new_op(JumpIfTrue(adjust_block, working="status"))
1.52 + if target is None:
1.53 + self.new_op(JumpIfTrue(adjust_block, working="status"))
1.54 + else:
1.55 + self.new_op(JumpIfTrue(continue_block, working="status"))
1.56
1.57 # Where the context is inappropriate, drop the incomplete frame and
1.58 # raise an exception.
1.59
1.60 self.new_op(DropFrame())
1.61 - self.new_op(Transfer(source="result", target="working"))
1.62 - self.new_op(Transfer(source="result_context", target="working_context"))
1.63
1.64 self.make_exception("TypeError")
1.65 self.set_target("exception")
1.66 @@ -824,9 +829,6 @@
1.67 "Finish the invocation and tidy up afterwards."
1.68
1.69 self.new_op(DropFrame())
1.70 - if load_result:
1.71 - self.new_op(Transfer(source="result", target="working"))
1.72 - self.new_op(Transfer(source="result_context", target="working_context"))
1.73
1.74 # Discard any temporary storage instructions.
1.75
1.76 @@ -836,6 +838,10 @@
1.77 if temp_context is not None:
1.78 self.discard_temp(temp_context)
1.79
1.80 + # Reset the active values.
1.81 +
1.82 + self.optimiser.reset()
1.83 +
1.84 def _visitFunctionDeclaration(self, node):
1.85
1.86 """
1.87 @@ -933,7 +939,6 @@
1.88 if not fn.is_lambda():
1.89 self.dispatch(compiler.ast.Name("None"))
1.90
1.91 - self.set_target("result")
1.92 self.new_op(Return())
1.93
1.94 # Make sure that enough frame space is reserved from the start.