1.1 --- a/translator.py Fri Feb 17 19:46:39 2017 +0100
1.2 +++ b/translator.py Sat Feb 18 18:52:04 2017 +0100
1.3 @@ -331,6 +331,10 @@
1.4
1.5 self.temp_usage = {}
1.6
1.7 + # Initialise some data used for attribute access generation.
1.8 +
1.9 + self.init_substitutions()
1.10 +
1.11 def __repr__(self):
1.12 return "TranslatedModule(%r, %r)" % (self.name, self.importer)
1.13
1.14 @@ -738,27 +742,8 @@
1.15 "<assexpr>" : self.in_assignment,
1.16 }
1.17
1.18 - temp_subs = {
1.19 - "<context>" : "__tmp_contexts",
1.20 - "<set_context>" : "__tmp_contexts",
1.21 - "<private_context>" : "__tmp_private_context",
1.22 - "<set_private_context>" : "__tmp_private_context",
1.23 - "<accessor>" : "__tmp_value",
1.24 - "<target_accessor>" : "__tmp_target_value",
1.25 - "<set_accessor>" : "__tmp_value",
1.26 - "<set_target_accessor>" : "__tmp_target_value",
1.27 - }
1.28 -
1.29 - op_subs = {
1.30 - "<context>" : "__get_context",
1.31 - "<set_context>" : "__set_context",
1.32 - "<set_private_context>" : "__set_private_context",
1.33 - "<set_accessor>" : "__set_accessor",
1.34 - "<set_target_accessor>" : "__set_target_accessor",
1.35 - }
1.36 -
1.37 - subs.update(temp_subs)
1.38 - subs.update(op_subs)
1.39 + subs.update(self.temp_subs)
1.40 + subs.update(self.op_subs)
1.41
1.42 output = []
1.43 substituted = set()
1.44 @@ -779,12 +764,45 @@
1.45 # Record temporary name usage.
1.46
1.47 for sub in substituted:
1.48 - if temp_subs.has_key(sub):
1.49 - self.record_temp(temp_subs[sub])
1.50 + if self.temp_subs.has_key(sub):
1.51 + self.record_temp(self.temp_subs[sub])
1.52
1.53 del self.attrs[0]
1.54 return AttrResult(output, refs, location)
1.55
1.56 + def init_substitutions(self):
1.57 +
1.58 + """
1.59 + Initialise substitutions, defining temporary variable mappings, some of
1.60 + which are also used as substitutions, together with operation mappings
1.61 + used as substitutions in instructions defined by the optimiser.
1.62 + """
1.63 +
1.64 + self.temp_subs = {
1.65 +
1.66 + # Substitutions used by instructions.
1.67 +
1.68 + "<private_context>" : "__tmp_private_context",
1.69 + "<accessor>" : "__tmp_value",
1.70 + "<target_accessor>" : "__tmp_target_value",
1.71 +
1.72 + # Mappings to be replaced by those given below.
1.73 +
1.74 + "<context>" : "__tmp_contexts",
1.75 + "<set_context>" : "__tmp_contexts",
1.76 + "<set_private_context>" : "__tmp_private_context",
1.77 + "<set_accessor>" : "__tmp_value",
1.78 + "<set_target_accessor>" : "__tmp_target_value",
1.79 + }
1.80 +
1.81 + self.op_subs = {
1.82 + "<context>" : "__get_context",
1.83 + "<set_context>" : "__set_context",
1.84 + "<set_private_context>" : "__set_private_context",
1.85 + "<set_accessor>" : "__set_accessor",
1.86 + "<set_target_accessor>" : "__set_target_accessor",
1.87 + }
1.88 +
1.89 def get_referenced_attributes(self, location):
1.90
1.91 """