1.1 --- a/micropython/ast.py Sat Aug 02 02:02:04 2008 +0200
1.2 +++ b/micropython/ast.py Sun Aug 03 00:19:51 2008 +0200
1.3 @@ -89,6 +89,7 @@
1.4
1.5 self.code = None
1.6 self.temp_positions = set()
1.7 + self.max_temp_position = -1
1.8
1.9 def __repr__(self):
1.10 return "Translation(%r)" % self.module
1.11 @@ -104,6 +105,7 @@
1.12 if self.module.module is not None:
1.13 self.dispatch(self.module.module)
1.14
1.15 + self.unit.temp_usage = self.max_temp_position + 1
1.16 return self.code
1.17
1.18 def get_code(self, unit):
1.19 @@ -117,6 +119,7 @@
1.20 if unit.astnode is not None:
1.21 self.dispatch(unit.astnode)
1.22
1.23 + self.unit.temp_usage = self.max_temp_position + 1
1.24 return self.code
1.25
1.26 # Name-related methods.
1.27 @@ -222,16 +225,13 @@
1.28 self.new_op(StoreTemp(temp_position))
1.29 return LoadTemp(temp_position)
1.30
1.31 - def ensure_temp(self):
1.32 - if isinstance(self.active, LoadTemp):
1.33 - self.temp_positions.add(self.active.attr)
1.34 -
1.35 def reserve_temp(self):
1.36 if not self.temp_positions:
1.37 temp_position = 0
1.38 else:
1.39 temp_position = max(self.temp_positions) + 1
1.40 self.temp_positions.add(temp_position)
1.41 + self.max_temp_position = max(self.max_temp_position, temp_position)
1.42 return temp_position
1.43
1.44 def discard_temp(self, instruction=None):
1.45 @@ -352,7 +352,7 @@
1.46
1.47 "Return whether 'instruction' provides an input."
1.48
1.49 - return isinstance(instruction, (LoadConst, LoadName, LoadTemp, LoadResult) + self.attribute_load_instructions)
1.50 + return isinstance(instruction, (LoadConst, LoadName, LoadTemp, LoadResult, LoadBoolean) + self.attribute_load_instructions)
1.51
1.52 # Convenience tests.
1.53
1.54 @@ -509,11 +509,6 @@
1.55 if self._should_optimise_temp_storage() and \
1.56 self._have_temp_compatible_access():
1.57
1.58 - # Where an existing temporary storage reference will be retained,
1.59 - # keep it active.
1.60 -
1.61 - self.ensure_temp()
1.62 -
1.63 last = self.last_op()
1.64 self.remove_op()
1.65 return last
1.66 @@ -842,7 +837,6 @@
1.67 # raise an exception.
1.68
1.69 self.new_op(DropFrame())
1.70 -
1.71 self.new_op(LoadResult())
1.72
1.73 self.load_builtin("TypeError", node)
1.74 @@ -1109,10 +1103,6 @@
1.75
1.76 self._generateBinary(node, temp1, temp2, left_method, right_method)
1.77
1.78 - # Yield the result.
1.79 -
1.80 - self.new_op(LoadResult())
1.81 -
1.82 # Compilation duties...
1.83
1.84 self.discard_temp(temp1)
1.85 @@ -1340,7 +1330,6 @@
1.86 """
1.87
1.88 end_label = self.new_label()
1.89 - temp_result_pos = self.reserve_temp()
1.90
1.91 self.dispatch(node.expr)
1.92 temp2 = self._optimise_temp_storage()
1.93 @@ -1355,13 +1344,16 @@
1.94 self.dispatch(next_node)
1.95 temp2 = self._optimise_temp_storage()
1.96
1.97 + # Use the appropriate mechanism, setting the boolean status for the
1.98 + # comparison.
1.99 +
1.100 if methods is not None:
1.101 left_method, right_method = methods
1.102
1.103 # Generate method call using evaluated argument and next node.
1.104
1.105 self._generateBinary(node, temp1, temp2, left_method, right_method)
1.106 - self.new_op(LoadResult())
1.107 + self.new_op(TestBoolean())
1.108
1.109 else:
1.110 # Deal with the special operators.
1.111 @@ -1394,19 +1386,14 @@
1.112 self.new_op(StoreFrame(1))
1.113 self._doCallFunc(temp_method)
1.114 self._endCallFunc(temp_method)
1.115 - self.new_op(LoadResult())
1.116 + self.new_op(TestBoolean())
1.117
1.118 if op_name.find("not") != -1:
1.119 self.new_op(InvertBoolean())
1.120
1.121 - # Record the result in temporary storage.
1.122 -
1.123 - self.new_op(StoreTemp(temp_result_pos))
1.124 -
1.125 # Test the result and jump to the end label if false.
1.126
1.127 if op is not last_op:
1.128 - self.new_op(TestBoolean())
1.129 self.new_op(JumpIfFalse(end_label))
1.130
1.131 # Compilation duties...
1.132 @@ -1416,8 +1403,9 @@
1.133 self.discard_temp(temp2)
1.134 self.set_label(end_label)
1.135
1.136 - self.new_op(LoadTemp(temp_result_pos))
1.137 - self.cancel_temp(temp_result_pos)
1.138 + # Yield the appropriate value.
1.139 +
1.140 + self.new_op(LoadBoolean())
1.141
1.142 def visitConst(self, node):
1.143 const = self.module.constant_values[node.value]
1.144 @@ -1614,7 +1602,7 @@
1.145 self.discard_value()
1.146
1.147 self.new_op(temp)
1.148 - self.discard_temp(temp)
1.149 + #self.discard_temp(temp)
1.150
1.151 # Visiting of the code occurs when get_code is invoked on this node.
1.152
1.153 @@ -1657,13 +1645,18 @@
1.154
1.155 self.dispatch(node.expr)
1.156 self.new_op(TestBoolean())
1.157 - self.new_op(JumpIfTrue(true_label))
1.158 - self.load_builtin("True", node)
1.159 - self.new_op(Jump(next_label))
1.160 -
1.161 - self.set_label(true_label)
1.162 - self.load_builtin("False", node)
1.163 - self.set_label(next_label)
1.164 + self.new_op(InvertBoolean())
1.165 + self.new_op(LoadBoolean())
1.166 +
1.167 + # The equivalent of InvertBoolean/LoadBoolean.
1.168 +
1.169 + #self.new_op(JumpIfTrue(true_label))
1.170 + #self.load_builtin("True", node)
1.171 + #self.new_op(Jump(next_label))
1.172 +
1.173 + #self.set_label(true_label)
1.174 + #self.load_builtin("False", node)
1.175 + #self.set_label(next_label)
1.176
1.177 # Prevent incorrect optimisation.
1.178
2.1 --- a/micropython/data.py Sat Aug 02 02:02:04 2008 +0200
2.2 +++ b/micropython/data.py Sun Aug 03 00:19:51 2008 +0200
2.3 @@ -358,9 +358,8 @@
2.4
2.5 # Program-related details.
2.6
2.7 - self.stack_usage = 0
2.8 - self.stack_temp_usage = 0
2.9 - self.stack_local_usage = 0
2.10 + self.temp_usage = 0
2.11 + self.local_usage = 0
2.12
2.13 def __repr__(self):
2.14 if self.location is not None:
2.15 @@ -685,9 +684,8 @@
2.16
2.17 # Program-related details.
2.18
2.19 - self.stack_usage = 0
2.20 - self.stack_temp_usage = 0
2.21 - self.stack_local_usage = 0
2.22 + self.temp_usage = 0
2.23 + self.local_usage = 0
2.24
2.25 def _add_parameters(self, argnames):
2.26 for name in argnames:
2.27 @@ -793,7 +791,7 @@
2.28 for i, attr in enumerate(self.locals().values()):
2.29 attr.position = i + j
2.30
2.31 - self.stack_local_usage = i
2.32 + self.local_usage = i
2.33 self.finalised = 1
2.34
2.35 def function_from_method(self):
2.36 @@ -860,9 +858,8 @@
2.37
2.38 # Program-related details.
2.39
2.40 - self.stack_usage = 0
2.41 - self.stack_temp_usage = 0
2.42 - self.stack_local_usage = 0
2.43 + self.temp_usage = 0
2.44 + self.local_usage = 0
2.45
2.46 def full_name(self):
2.47 return self.name
3.1 --- a/micropython/rsvp.py Sat Aug 02 02:02:04 2008 +0200
3.2 +++ b/micropython/rsvp.py Sun Aug 03 00:19:51 2008 +0200
3.3 @@ -205,11 +205,12 @@
3.4 class PopHandler(Instruction): "Pop an exception handler from the handler stack."
3.5 class CheckException(Instruction): "Check the raised exception against another."
3.6
3.7 -# General instructions.
3.8 +# Test instructions, operating on the boolean status register.
3.9
3.10 -class InvertBoolean(Instruction): "Invert the current value."
3.11 -class TestBoolean(Instruction): "Test whether the current value is a true value."
3.12 -class TestIdentity(Instruction): "Test whether the current value is identical to the source value."
3.13 -class TestIdentityAddress(Address): "Test whether the current value is identical to the given address."
3.14 +class TestBoolean(Instruction): "Test whether the current value is a true value, setting the boolean status."
3.15 +class TestIdentity(Instruction): "Test whether the current value is identical to the source value, setting the boolean status."
3.16 +class TestIdentityAddress(Address): "Test whether the current value is identical to the given address, setting the boolean status."
3.17 +class InvertBoolean(Instruction): "Invert the boolean status."
3.18 +class LoadBoolean(Instruction): "Load the appropriate value into the current value for the boolean status."
3.19
3.20 # vim: tabstop=4 expandtab shiftwidth=4