1.1 --- a/translator.py Sat Jan 21 18:22:20 2017 +0100
1.2 +++ b/translator.py Sat Jan 21 22:11:04 2017 +0100
1.3 @@ -19,11 +19,13 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from common import CommonModule, CommonOutput, first, get_builtin_module, \
1.8 - get_builtin_type, init_item, predefined_constants
1.9 +from common import CommonModule, CommonOutput, InstructionSequence, \
1.10 + first, get_builtin_module, get_builtin_type, init_item, \
1.11 + predefined_constants
1.12 from encoders import encode_access_instruction, encode_bound_reference, \
1.13 encode_function_pointer, encode_literal_constant, \
1.14 encode_literal_instantiator, encode_instantiator_pointer, \
1.15 + encode_instructions, \
1.16 encode_path, encode_symbol, encode_type_attribute, \
1.17 is_type_attribute
1.18 from os.path import exists, join
1.19 @@ -183,12 +185,12 @@
1.20 def __repr__(self):
1.21 return "TrResolvedInstanceRef(%r, %r)" % (self.ref, self.expr)
1.22
1.23 -class AttrResult(Expression, TranslationResult):
1.24 +class AttrResult(Expression, TranslationResult, InstructionSequence):
1.25
1.26 "A translation result for an attribute access."
1.27
1.28 - def __init__(self, s, refs, accessor_kinds):
1.29 - Expression.__init__(self, s)
1.30 + def __init__(self, instructions, refs, accessor_kinds):
1.31 + InstructionSequence.__init__(self, instructions)
1.32 self.refs = refs
1.33 self.accessor_kinds = accessor_kinds
1.34
1.35 @@ -206,10 +208,13 @@
1.36 def get_accessor_kinds(self):
1.37 return self.accessor_kinds
1.38
1.39 + def __str__(self):
1.40 + return encode_instructions(self.instructions)
1.41 +
1.42 def __repr__(self):
1.43 - return "AttrResult(%r, %r, %r)" % (self.s, self.refs, self.accessor_kinds)
1.44 -
1.45 -class PredefinedConstantRef(AttrResult):
1.46 + return "AttrResult(%r, %r, %r)" % (self.instructions, self.refs, self.accessor_kinds)
1.47 +
1.48 +class PredefinedConstantRef(Expression, TranslationResult):
1.49
1.50 "A predefined constant reference."
1.51
1.52 @@ -701,8 +706,8 @@
1.53 # Generate access instructions.
1.54
1.55 subs = {
1.56 - "<expr>" : str(attr_expr),
1.57 - "<assexpr>" : str(self.in_assignment),
1.58 + "<expr>" : attr_expr,
1.59 + "<assexpr>" : self.in_assignment,
1.60 }
1.61
1.62 temp_subs = {
1.63 @@ -738,15 +743,8 @@
1.64 if temp_subs.has_key(sub):
1.65 self.record_temp(temp_subs[sub])
1.66
1.67 - # Format the output.
1.68 -
1.69 - if len(output) == 1:
1.70 - out = output[0]
1.71 - else:
1.72 - out = "(\n%s\n)" % ",\n".join(output)
1.73 -
1.74 del self.attrs[0]
1.75 - return AttrResult(out, refs, self.get_accessor_kinds(location))
1.76 + return AttrResult(output, refs, self.get_accessor_kinds(location))
1.77
1.78 def get_referenced_attributes(self, location):
1.79