1.1 --- a/micropython/ast.py Sun Aug 17 20:46:49 2008 +0200
1.2 +++ b/micropython/ast.py Mon Aug 18 01:40:18 2008 +0200
1.3 @@ -67,6 +67,7 @@
1.4 self.importer = importer
1.5 self.objtable = self.importer.get_object_table()
1.6 self.paramtable = self.importer.get_parameter_table()
1.7 + self.clstable = self.importer.get_class_table()
1.8 self.builtins = self.importer.modules.get("__builtins__")
1.9
1.10 # Desired optimisations.
1.11 @@ -280,6 +281,13 @@
1.12 op = self.code.pop()
1.13 self.active = None
1.14
1.15 + def remove_active_value(self):
1.16 +
1.17 + "Remove the value-providing active instruction if appropriate."
1.18 +
1.19 + if self.active_value is self.active:
1.20 + self.remove_op()
1.21 +
1.22 def replace_op(self, op):
1.23
1.24 "Replace the last added instruction with 'op'."
1.25 @@ -349,7 +357,9 @@
1.26 StoreTemp, StoreFrame, StoreResult, StoreException, # as the value being stored
1.27 LoadAddressContext, LoadAttr, LoadAttrIndex, # as the object being referenced
1.28 StoreAttr, StoreAttrIndex, StoreCallable, # as the object being referenced
1.29 - TestIdentity, CheckSelf # as one of the operands
1.30 + TestIdentity, CheckSelf, # as one of the operands
1.31 + LoadContext, # as the object providing the result
1.32 + JumpWithFrame # as the target
1.33 ))
1.34
1.35 def _is_resultant_no_operation(self, instruction):
1.36 @@ -554,9 +564,8 @@
1.37 if self._should_optimise_temp_storage() and \
1.38 self._have_temp_compatible_access():
1.39
1.40 - last = self.last_op()
1.41 - self.remove_op()
1.42 - return last
1.43 + self.remove_active_value()
1.44 + return self.active
1.45 else:
1.46 return self.get_temp()
1.47
1.48 @@ -570,9 +579,7 @@
1.49 self._have_simple_input() and \
1.50 self._is_simple_input_user(instruction):
1.51
1.52 - if self.active_value is self.active:
1.53 - self.remove_op()
1.54 -
1.55 + self.remove_active_value()
1.56 instruction.input = self.active_value
1.57
1.58 def _optimise_away_no_operations(self, instruction):
1.59 @@ -593,8 +600,8 @@
1.60
1.61 "Discard results which will not be used."
1.62
1.63 - if self._have_input():
1.64 - self.remove_op()
1.65 + if self._have_simple_input():
1.66 + self.remove_active_value()
1.67
1.68 # Visitor methods.
1.69