# HG changeset patch # User Paul Boddie # Date 1313955536 -7200 # Node ID e6bd9da8269264481d10d5f3108e746a715ab0ac # Parent 5382a26943ca0496e8a69fc625bff12046d0073f Renamed set_source to assign_value. Added instruction copying when setting the working register on an existing program instruction and inserting a new instruction. Added some methods to allow instructions to be used in sets. Added a test of the return statement and logical control flow. diff -r 5382a26943ca -r e6bd9da82692 micropython/ast.py --- a/micropython/ast.py Sun Aug 21 14:24:28 2011 +0200 +++ b/micropython/ast.py Sun Aug 21 21:38:56 2011 +0200 @@ -212,7 +212,7 @@ self.set_block(end_block) # Make a separate instruction to prevent previous temp accesses from - # being altered by set_source. + # being altered by assign_value. temp = LoadTemp(temp_pos) self.new_op(temp) @@ -245,7 +245,7 @@ self.set_block(end_block) # Make a separate instruction to prevent previous temp accesses from - # being altered by set_source. + # being altered by assign_value. temp = LoadTemp(temp_pos) self.new_op(temp) @@ -302,7 +302,7 @@ self.record_value() self.new_op(temp2) self.new_op(TestIdentity(target="status")) - self.set_source() + self.assign_value() self.discard_value() elif op_name.endswith("in"): @@ -454,7 +454,7 @@ "Assign the assignment expression to the recipient 'node'." self._visitAttr(node, self.optimiser.get_attribute_store_instructions()) - self.set_source() + self.assign_value() def visitAssList(self, node): @@ -493,7 +493,7 @@ raise TranslationNotImplementedError("AssName(OP_DELETE)") self._visitName(node, self.name_store_instructions) - self.set_source() + self.assign_value() # Add any attribute usage guards. @@ -531,7 +531,7 @@ self.new_op(LoadClass(node.unit)) self.record_value() self._visitName(node, self.name_store_instructions) - self.set_source() + self.assign_value() self.discard_value() # Visit the code. @@ -559,7 +559,7 @@ self.record_value() self._visitName(node, self.name_store_instructions) # AssName equivalent - self.set_source() + self.assign_value() self.discard_value() # Visiting of the code occurs when get_code is invoked on this node. diff -r 5382a26943ca -r e6bd9da82692 micropython/code.py --- a/micropython/code.py Sun Aug 21 14:24:28 2011 +0200 +++ b/micropython/code.py Sun Aug 21 21:38:56 2011 +0200 @@ -135,7 +135,7 @@ self.discard_temp(self.expr_temp.pop()) - def set_source(self, expr=None): + def assign_value(self, expr=None): """ Set the source of an assignment using 'expr' or the current assignment @@ -161,6 +161,7 @@ def set_working(self, expr): if expr is not None: + expr = expr.copy() expr.target = "working" self.insert_op(-1, expr) self.last_op().source = "working" diff -r 5382a26943ca -r e6bd9da82692 micropython/rsvp.py --- a/micropython/rsvp.py Sun Aug 21 14:24:28 2011 +0200 +++ b/micropython/rsvp.py Sun Aug 21 21:38:56 2011 +0200 @@ -306,6 +306,9 @@ self.target = target self.source = source + def get_details(self): + return self.__class__, self.attr, self.working, self.target, self.source + def copy(self): return self.__class__(self.attr, self.working, self.target, self.source) @@ -316,6 +319,15 @@ self.format_source(), self.format_target()) + def __hash__(self): + return hash(self.get_details()) + + def __eq__(self, other): + return self.get_details() == other.get_details() + + def __ne__(self, other): + return not self.__eq__(other) + def format_operand(self): operand = self.get_operand() return repr(operand) diff -r 5382a26943ca -r e6bd9da82692 micropython/trans.py --- a/micropython/trans.py Sun Aug 21 14:24:28 2011 +0200 +++ b/micropython/trans.py Sun Aug 21 21:38:56 2011 +0200 @@ -638,7 +638,7 @@ self.new_op(temp_target) self.new_op(StoreFrameIndex(paramindex)) - self.set_source() + self.assign_value() self.discard_value() # Record the highest possible frame position for this argument. @@ -982,7 +982,7 @@ else: self.record_value() self.new_op(StoreName(fn[parameter])) - self.set_source() + self.assign_value() self.discard_value() if parameters is not None: @@ -1018,7 +1018,7 @@ self.new_op(StoreAttr(attr)) else: self.new_op(StoreAddress(attr)) - self.set_source() + self.assign_value() self.discard_value() if dynamic: @@ -1243,7 +1243,7 @@ list_temp = self.get_temp() self.new_op(list_temp) self.new_op(StoreAttr(Attr(0, None, None))) # _elements is at position 0 - self.set_source() + self.assign_value() self.discard_value() self.new_op(list_temp.copy()) @@ -1271,7 +1271,7 @@ self.new_op(temp) self.new_op(StoreAttr(Attr(i + offset, None, None))) - self.set_source() + self.assign_value() def _generateTestBoolean(self, node, temp): diff -r 5382a26943ca -r e6bd9da82692 tests/return_choice.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/return_choice.py Sun Aug 21 21:38:56 2011 +0200 @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +def choice(x, y): + return x and y + +result_0 = choice(0, 1) +result_3 = choice(2, 3) + +# vim: tabstop=4 expandtab shiftwidth=4