# HG changeset patch # User Paul Boddie # Date 1222631643 -7200 # Node ID 98862cdebb1ec166f86edf318c8f7d5c2f0356fa # Parent 585f1b4330e009f763f1d2e913608043ad54ef4e Tidied up the optimiser by removing unnecessary translator/translation references. diff -r 585f1b4330e0 -r 98862cdebb1e micropython/ast.py --- a/micropython/ast.py Sun Sep 28 21:42:03 2008 +0200 +++ b/micropython/ast.py Sun Sep 28 21:54:03 2008 +0200 @@ -728,7 +728,7 @@ # Drop any test if the target and the context are known. - if not self.optimiser.have_correct_self_for_target(context): + if not self.optimiser.have_correct_self_for_target(context, self.unit): continue_label = self.new_label() self.new_op(CheckSelf()) diff -r 585f1b4330e0 -r 98862cdebb1e micropython/opt.py --- a/micropython/opt.py Sun Sep 28 21:42:03 2008 +0200 +++ b/micropython/opt.py Sun Sep 28 21:54:03 2008 +0200 @@ -238,12 +238,15 @@ return self.is_input(self.active_value) - def have_self_input(self): + def have_self_input(self, unit): - "Return whether the active instruction is a reference to self." + """ + Return whether the active instruction is a reference to self in the + given 'unit'. + """ - return isinstance(self.translation.unit, Function) and \ - self.translation.unit.is_method() and isinstance(self.active_value, LoadName) and \ + return isinstance(unit, Function) and \ + unit.is_method() and isinstance(self.active_value, LoadName) and \ self.active_value.attr.name == "self" def have_temp_compatible_access(self): @@ -260,13 +263,13 @@ isinstance(self.active_value, LoadResult) and self.active_value is self.active or \ isinstance(self.active_value, LoadException) and self.active_value is self.active - def have_correct_self_for_target(self, context): + def have_correct_self_for_target(self, context, unit): - "Return whether the 'context' is compatible with the current value." + "Return whether the 'context' is compatible with the given 'unit'." - if context is not None and self.have_self_input(): + if context is not None and self.have_self_input(unit): - parent = self.translation.unit.parent + parent = unit.parent if parent is context or parent.has_subclass(context) or context.has_subclass(parent): return 1 @@ -338,7 +341,7 @@ """ return self.should_optimise_self_access() and \ - self.have_self_input() and not unit.is_relocated(attrname) + self.have_self_input(unit) and not unit.is_relocated(attrname) def optimise_temp_storage(self):