# HG changeset patch # User Paul Boddie # Date 1487440324 -3600 # Node ID 3e5b14c95a551054e7298186c5257c465b2268fb # Parent 0b24363cbf9c19781f7242d7ee115a97e133314e Tidied up the substitutions for attribute access instructions. diff -r 0b24363cbf9c -r 3e5b14c95a55 translator.py --- a/translator.py Fri Feb 17 19:46:39 2017 +0100 +++ b/translator.py Sat Feb 18 18:52:04 2017 +0100 @@ -331,6 +331,10 @@ self.temp_usage = {} + # Initialise some data used for attribute access generation. + + self.init_substitutions() + def __repr__(self): return "TranslatedModule(%r, %r)" % (self.name, self.importer) @@ -738,27 +742,8 @@ "" : self.in_assignment, } - temp_subs = { - "" : "__tmp_contexts", - "" : "__tmp_contexts", - "" : "__tmp_private_context", - "" : "__tmp_private_context", - "" : "__tmp_value", - "" : "__tmp_target_value", - "" : "__tmp_value", - "" : "__tmp_target_value", - } - - op_subs = { - "" : "__get_context", - "" : "__set_context", - "" : "__set_private_context", - "" : "__set_accessor", - "" : "__set_target_accessor", - } - - subs.update(temp_subs) - subs.update(op_subs) + subs.update(self.temp_subs) + subs.update(self.op_subs) output = [] substituted = set() @@ -779,12 +764,45 @@ # Record temporary name usage. for sub in substituted: - if temp_subs.has_key(sub): - self.record_temp(temp_subs[sub]) + if self.temp_subs.has_key(sub): + self.record_temp(self.temp_subs[sub]) del self.attrs[0] return AttrResult(output, refs, location) + def init_substitutions(self): + + """ + Initialise substitutions, defining temporary variable mappings, some of + which are also used as substitutions, together with operation mappings + used as substitutions in instructions defined by the optimiser. + """ + + self.temp_subs = { + + # Substitutions used by instructions. + + "" : "__tmp_private_context", + "" : "__tmp_value", + "" : "__tmp_target_value", + + # Mappings to be replaced by those given below. + + "" : "__tmp_contexts", + "" : "__tmp_contexts", + "" : "__tmp_private_context", + "" : "__tmp_value", + "" : "__tmp_target_value", + } + + self.op_subs = { + "" : "__get_context", + "" : "__set_context", + "" : "__set_private_context", + "" : "__set_accessor", + "" : "__set_target_accessor", + } + def get_referenced_attributes(self, location): """