2.1 --- a/encoders.py Sat Jan 21 18:22:20 2017 +0100
2.2 +++ b/encoders.py Sat Jan 21 22:11:04 2017 +0100
2.3 @@ -249,7 +249,7 @@
2.4 a[0] = "&%s" % a[0]
2.5 a[1] = "&%s" % a[1]
2.6
2.7 - argstr = "(%s)" % ", ".join(a)
2.8 + argstr = "(%s)" % ", ".join(map(str, a))
2.9
2.10 # Substitute the first element of the instruction, which may not be an
2.11 # operation at all.
2.12 @@ -319,6 +319,15 @@
2.13
2.14 return "__new_%s" % encode_path(path)
2.15
2.16 +def encode_instructions(instructions):
2.17 +
2.18 + "Encode 'instructions' as a sequence."
2.19 +
2.20 + if len(instructions) == 1:
2.21 + return instructions[0]
2.22 + else:
2.23 + return "(\n%s\n)" % ",\n".join(instructions)
2.24 +
2.25 def encode_literal_constant(n):
2.26
2.27 "Encode a name for the literal constant with the number 'n'."
3.1 --- a/translator.py Sat Jan 21 18:22:20 2017 +0100
3.2 +++ b/translator.py Sat Jan 21 22:11:04 2017 +0100
3.3 @@ -19,11 +19,13 @@
3.4 this program. If not, see <http://www.gnu.org/licenses/>.
3.5 """
3.6
3.7 -from common import CommonModule, CommonOutput, first, get_builtin_module, \
3.8 - get_builtin_type, init_item, predefined_constants
3.9 +from common import CommonModule, CommonOutput, InstructionSequence, \
3.10 + first, get_builtin_module, get_builtin_type, init_item, \
3.11 + predefined_constants
3.12 from encoders import encode_access_instruction, encode_bound_reference, \
3.13 encode_function_pointer, encode_literal_constant, \
3.14 encode_literal_instantiator, encode_instantiator_pointer, \
3.15 + encode_instructions, \
3.16 encode_path, encode_symbol, encode_type_attribute, \
3.17 is_type_attribute
3.18 from os.path import exists, join
3.19 @@ -183,12 +185,12 @@
3.20 def __repr__(self):
3.21 return "TrResolvedInstanceRef(%r, %r)" % (self.ref, self.expr)
3.22
3.23 -class AttrResult(Expression, TranslationResult):
3.24 +class AttrResult(Expression, TranslationResult, InstructionSequence):
3.25
3.26 "A translation result for an attribute access."
3.27
3.28 - def __init__(self, s, refs, accessor_kinds):
3.29 - Expression.__init__(self, s)
3.30 + def __init__(self, instructions, refs, accessor_kinds):
3.31 + InstructionSequence.__init__(self, instructions)
3.32 self.refs = refs
3.33 self.accessor_kinds = accessor_kinds
3.34
3.35 @@ -206,10 +208,13 @@
3.36 def get_accessor_kinds(self):
3.37 return self.accessor_kinds
3.38
3.39 + def __str__(self):
3.40 + return encode_instructions(self.instructions)
3.41 +
3.42 def __repr__(self):
3.43 - return "AttrResult(%r, %r, %r)" % (self.s, self.refs, self.accessor_kinds)
3.44 -
3.45 -class PredefinedConstantRef(AttrResult):
3.46 + return "AttrResult(%r, %r, %r)" % (self.instructions, self.refs, self.accessor_kinds)
3.47 +
3.48 +class PredefinedConstantRef(Expression, TranslationResult):
3.49
3.50 "A predefined constant reference."
3.51
3.52 @@ -701,8 +706,8 @@
3.53 # Generate access instructions.
3.54
3.55 subs = {
3.56 - "<expr>" : str(attr_expr),
3.57 - "<assexpr>" : str(self.in_assignment),
3.58 + "<expr>" : attr_expr,
3.59 + "<assexpr>" : self.in_assignment,
3.60 }
3.61
3.62 temp_subs = {
3.63 @@ -738,15 +743,8 @@
3.64 if temp_subs.has_key(sub):
3.65 self.record_temp(temp_subs[sub])
3.66
3.67 - # Format the output.
3.68 -
3.69 - if len(output) == 1:
3.70 - out = output[0]
3.71 - else:
3.72 - out = "(\n%s\n)" % ",\n".join(output)
3.73 -
3.74 del self.attrs[0]
3.75 - return AttrResult(out, refs, self.get_accessor_kinds(location))
3.76 + return AttrResult(output, refs, self.get_accessor_kinds(location))
3.77
3.78 def get_referenced_attributes(self, location):
3.79