1.1 --- a/micropython/opt.py Sun Sep 28 03:30:03 2008 +0200
1.2 +++ b/micropython/opt.py Sun Sep 28 19:59:32 2008 +0200
1.3 @@ -20,6 +20,7 @@
1.4 """
1.5
1.6 from micropython.common import *
1.7 +from micropython.data import *
1.8 from micropython.rsvp import *
1.9
1.10 class Optimiser:
1.11 @@ -27,9 +28,8 @@
1.12 "A code optimiser."
1.13
1.14 supported_optimisations = [
1.15 - "constant_storage", "known_target", "self_access",
1.16 - "temp_storage", "load_operations", "no_operations",
1.17 - "unused_results"
1.18 + "constant_storage", "constant_accessor", "known_target", "self_access",
1.19 + "temp_storage", "load_operations", "no_operations", "unused_results"
1.20 ]
1.21
1.22 def __init__(self, translation, optimisations=None):
1.23 @@ -115,6 +115,9 @@
1.24 def should_optimise_constant_storage(self):
1.25 return "constant_storage" in self.optimisations
1.26
1.27 + def should_optimise_constant_accessor(self):
1.28 + return "constant_accessor" in self.optimisations
1.29 +
1.30 def should_optimise_known_target(self):
1.31 return "known_target" in self.optimisations
1.32
1.33 @@ -284,6 +287,33 @@
1.34 else:
1.35 return 0
1.36
1.37 + def optimise_constant_accessor(self):
1.38 +
1.39 + """
1.40 + Where the object whose attribute is being accessed is constant, provide
1.41 + information about its full name.
1.42 + """
1.43 +
1.44 + if self.should_optimise_constant_accessor() and self.have_constant_input():
1.45 + value = self.active_value
1.46 +
1.47 + # Get the details of the access.
1.48 +
1.49 + if isinstance(value.attr, Const):
1.50 + target_name = value.attr.value_type_name()
1.51 + else:
1.52 + target = value.attr.value
1.53 +
1.54 + if isinstance(target, Const):
1.55 + return target.value_type_name()
1.56 + elif isinstance(target, Instance):
1.57 + return None # skip production of optimised code
1.58 + else:
1.59 + return target.full_name()
1.60 +
1.61 + else:
1.62 + return None
1.63 +
1.64 def optimise_known_target(self):
1.65
1.66 """