# HG changeset patch # User Paul Boddie # Date 1222122781 -7200 # Node ID f4a3c0049b31fdf6db9144d51fc14bfa46618587 # Parent e267cf7cc9be2c85efc8f58580a4a1421acd7cc2 Attempt to remove excessive temporary storage usage for the results of operators, reintroducing the mechanism to ensure the availability of temporary storage locations when optimising temporary storage usage. diff -r e267cf7cc9be -r f4a3c0049b31 micropython/ast.py --- a/micropython/ast.py Mon Sep 22 01:32:54 2008 +0200 +++ b/micropython/ast.py Tue Sep 23 00:33:01 2008 +0200 @@ -308,8 +308,14 @@ if self.should_optimise_temp_storage() and \ self.have_temp_compatible_access(): + # Remove the active value contributor. + removed = self.translation.active self.translation.remove_active_value() + + # Extend the lifetime of any temporary storage location. + + self.translation.ensure_temp(removed) return removed else: return self.translation.get_temp() @@ -621,8 +627,10 @@ self.new_op(StoreTemp(position_in_frame)) return LoadTemp(position_in_frame) - def reserve_temp(self): - if not self.temp_positions: + def reserve_temp(self, temp_position=None): + if temp_position is not None: + pass + elif not self.temp_positions: temp_position = 0 else: temp_position = max(self.temp_positions) + 1 @@ -630,6 +638,11 @@ self.max_temp_position = max(self.max_temp_position, temp_position) return self.unit.all_local_usage + temp_position # position in frame + def ensure_temp(self, instruction=None): + if isinstance(instruction, LoadTemp): + temp_position = instruction.attr - self.unit.all_local_usage + self.reserve_temp(temp_position) + def discard_temp(self, instruction=None): if isinstance(instruction, LoadTemp): temp_position = instruction.attr - self.unit.all_local_usage @@ -1286,6 +1299,10 @@ self.new_op(StoreException()) self.new_op(RaiseException()) + # Prevent incorrect optimisation. + + self.clear_active() + self.set_label(end_label) # Produce the result. @@ -1295,6 +1312,7 @@ # Compilation duties... self.discard_temp(temp) + self.discard_temp(temp_out) def _visitBinary(self, node, left_method, right_method): @@ -1334,6 +1352,7 @@ self.discard_temp(temp1) self.discard_temp(temp2) + self.discard_temp(temp_out) def _generateBinary(self, node, temp1, temp2, left_method, right_method): @@ -1365,6 +1384,10 @@ self.new_op(StoreException()) self.new_op(RaiseException()) + # Prevent incorrect optimisation. + + self.clear_active() + self.set_label(end_label) return temp_out diff -r e267cf7cc9be -r f4a3c0049b31 tests/op_add_call.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/op_add_call.py Tue Sep 23 00:33:01 2008 +0200 @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +def f(x, y): + pass + +a = 1 +b = 2 +c = 3 +f(a + b, b + c) + +# vim: tabstop=4 expandtab shiftwidth=4