1.1 --- a/translator.py Sun Jan 22 01:13:31 2017 +0100
1.2 +++ b/translator.py Sun Jan 22 01:16:01 2017 +0100
1.3 @@ -214,6 +214,30 @@
1.4 def __repr__(self):
1.5 return "AttrResult(%r, %r, %r)" % (self.instructions, self.refs, self.accessor_kinds)
1.6
1.7 +class InvocationResult(Expression, TranslationResult, InstructionSequence):
1.8 +
1.9 + "A translation result for an invocation."
1.10 +
1.11 + def __init__(self, instructions):
1.12 + InstructionSequence.__init__(self, instructions)
1.13 +
1.14 + def __str__(self):
1.15 + return encode_instructions(self.instructions)
1.16 +
1.17 + def __repr__(self):
1.18 + return "InvocationResult(%r)" % self.instructions
1.19 +
1.20 +class InstantiationResult(InvocationResult, TrInstanceRef):
1.21 +
1.22 + "An instantiation result acting like an invocation result."
1.23 +
1.24 + def __init__(self, ref, instructions):
1.25 + results.InstanceRef.__init__(self, ref)
1.26 + InvocationResult.__init__(self, instructions)
1.27 +
1.28 + def __repr__(self):
1.29 + return "InstantiationResult(%r, %r)" % (self.ref, self.instructions)
1.30 +
1.31 class PredefinedConstantRef(Expression, TranslationResult):
1.32
1.33 "A predefined constant reference."
1.34 @@ -1295,24 +1319,23 @@
1.35 # and thereby participate in a guaranteed evaluation order.
1.36
1.37 if target or function:
1.38 - output = "(\n%s(%s))" % (",\n".join(stages), argstr)
1.39 + stages[-1] += "(%s)" % argstr
1.40 + if instantiation:
1.41 + return InstantiationResult(instantiation, stages)
1.42 + else:
1.43 + return InvocationResult(stages)
1.44
1.45 # With unknown targets, the generic invocation function is applied to
1.46 # the callable and argument collections.
1.47
1.48 else:
1.49 self.record_temp("__tmp_targets")
1.50 - output = "(%s, __invoke(\n__tmp_targets[%d],\n%d, %d, %s, %s,\n%d, %s\n))" % (
1.51 - ",\n".join(stages),
1.52 + stages.append("__invoke(\n__tmp_targets[%d],\n%d, %d, %s, %s,\n%d, %s\n)" % (
1.53 self.function_target,
1.54 self.always_callable and 1 or 0,
1.55 len(kwargs), kwcodestr, kwargstr,
1.56 - len(args), argstr)
1.57 -
1.58 - if instantiation:
1.59 - return TrInstanceRef(instantiation, output)
1.60 - else:
1.61 - return make_expression(output)
1.62 + len(args), argstr))
1.63 + return InvocationResult(stages)
1.64
1.65 def always_callable(self, refs):
1.66