1.1 --- a/micropython/code.py Sun Aug 07 23:01:35 2011 +0200
1.2 +++ b/micropython/code.py Sun Aug 21 14:24:28 2011 +0200
1.3 @@ -135,19 +135,41 @@
1.4
1.5 self.discard_temp(self.expr_temp.pop())
1.6
1.7 - def set_source(self):
1.8 + def set_source(self, expr=None):
1.9
1.10 """
1.11 - Set the source of an assignment using the current assignment value. This
1.12 - sets the source input for the current instruction.
1.13 + Set the source of an assignment using 'expr' or the current assignment
1.14 + value. This sets the source register of the current instruction.
1.15 """
1.16
1.17 - self.optimiser.set_source(self.expr_temp[-1])
1.18 + if expr is None:
1.19 + expr = self.expr_temp[-1]
1.20 +
1.21 + # Optimise away constant storage if appropriate.
1.22 +
1.23 + if self.optimiser.optimise_constant_storage(expr):
1.24 + self.remove_op()
1.25 + return
1.26 +
1.27 + # Otherwise, insert the assignment source.
1.28
1.29 - # Optimise away constant storage if appropriate.
1.30 + if expr is not None:
1.31 + expr = expr.copy()
1.32 + expr.target = "source"
1.33 + self.insert_op(-1, expr)
1.34 + self.last_op().source = "source"
1.35
1.36 - if self.optimiser.optimise_constant_storage():
1.37 - self.remove_op()
1.38 + def set_working(self, expr):
1.39 + if expr is not None:
1.40 + expr.target = "working"
1.41 + self.insert_op(-1, expr)
1.42 + self.last_op().source = "working"
1.43 +
1.44 + def set_target(self, target):
1.45 +
1.46 + "Reset the target of the active instruction to 'target'."
1.47 +
1.48 + self.optimiser.set_target(target)
1.49
1.50 def is_immediate_user(self, node):
1.51
1.52 @@ -253,7 +275,6 @@
1.53
1.54 # Optimise load operations employed by this instruction.
1.55
1.56 - self.optimiser.optimise_load_operations(op)
1.57 if self.optimiser.optimise_away_no_operations(op) or self.optimiser.optimise_unused_handlers(op):
1.58 return 0
1.59
1.60 @@ -263,6 +284,12 @@
1.61 self.optimiser.set_new(op)
1.62 return 1
1.63
1.64 + def insert_op(self, i, op):
1.65 +
1.66 + "Insert at index 'i' in the current block the instruction 'op'."
1.67 +
1.68 + self.blocks[-1].code.insert(i, op)
1.69 +
1.70 def remove_op(self):
1.71
1.72 "Remove the last instruction."