1.1 --- a/micropython/ast.py Mon Sep 22 01:32:54 2008 +0200
1.2 +++ b/micropython/ast.py Tue Sep 23 00:33:01 2008 +0200
1.3 @@ -308,8 +308,14 @@
1.4 if self.should_optimise_temp_storage() and \
1.5 self.have_temp_compatible_access():
1.6
1.7 + # Remove the active value contributor.
1.8 +
1.9 removed = self.translation.active
1.10 self.translation.remove_active_value()
1.11 +
1.12 + # Extend the lifetime of any temporary storage location.
1.13 +
1.14 + self.translation.ensure_temp(removed)
1.15 return removed
1.16 else:
1.17 return self.translation.get_temp()
1.18 @@ -621,8 +627,10 @@
1.19 self.new_op(StoreTemp(position_in_frame))
1.20 return LoadTemp(position_in_frame)
1.21
1.22 - def reserve_temp(self):
1.23 - if not self.temp_positions:
1.24 + def reserve_temp(self, temp_position=None):
1.25 + if temp_position is not None:
1.26 + pass
1.27 + elif not self.temp_positions:
1.28 temp_position = 0
1.29 else:
1.30 temp_position = max(self.temp_positions) + 1
1.31 @@ -630,6 +638,11 @@
1.32 self.max_temp_position = max(self.max_temp_position, temp_position)
1.33 return self.unit.all_local_usage + temp_position # position in frame
1.34
1.35 + def ensure_temp(self, instruction=None):
1.36 + if isinstance(instruction, LoadTemp):
1.37 + temp_position = instruction.attr - self.unit.all_local_usage
1.38 + self.reserve_temp(temp_position)
1.39 +
1.40 def discard_temp(self, instruction=None):
1.41 if isinstance(instruction, LoadTemp):
1.42 temp_position = instruction.attr - self.unit.all_local_usage
1.43 @@ -1286,6 +1299,10 @@
1.44 self.new_op(StoreException())
1.45 self.new_op(RaiseException())
1.46
1.47 + # Prevent incorrect optimisation.
1.48 +
1.49 + self.clear_active()
1.50 +
1.51 self.set_label(end_label)
1.52
1.53 # Produce the result.
1.54 @@ -1295,6 +1312,7 @@
1.55 # Compilation duties...
1.56
1.57 self.discard_temp(temp)
1.58 + self.discard_temp(temp_out)
1.59
1.60 def _visitBinary(self, node, left_method, right_method):
1.61
1.62 @@ -1334,6 +1352,7 @@
1.63
1.64 self.discard_temp(temp1)
1.65 self.discard_temp(temp2)
1.66 + self.discard_temp(temp_out)
1.67
1.68 def _generateBinary(self, node, temp1, temp2, left_method, right_method):
1.69
1.70 @@ -1365,6 +1384,10 @@
1.71 self.new_op(StoreException())
1.72 self.new_op(RaiseException())
1.73
1.74 + # Prevent incorrect optimisation.
1.75 +
1.76 + self.clear_active()
1.77 +
1.78 self.set_label(end_label)
1.79 return temp_out
1.80
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/op_add_call.py Tue Sep 23 00:33:01 2008 +0200
2.3 @@ -0,0 +1,11 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +def f(x, y):
2.7 + pass
2.8 +
2.9 +a = 1
2.10 +b = 2
2.11 +c = 3
2.12 +f(a + b, b + c)
2.13 +
2.14 +# vim: tabstop=4 expandtab shiftwidth=4