# HG changeset patch # User Paul Boddie # Date 1716652978 -7200 # Node ID 23d55ac5643345a091a1d13271171c1791a83476 # Parent 4a078c610c577ab005c1938086a4b119db35fd39 Handle return types slightly more generally for invocation results. diff -r 4a078c610c57 -r 23d55ac56433 translator.py --- a/translator.py Sat May 25 17:55:37 2024 +0200 +++ b/translator.py Sat May 25 18:02:58 2024 +0200 @@ -1287,7 +1287,9 @@ # NOTE: Special case for optimisation. - yields_integer = target and objpath == "native.int.is_int" + int_type = "__builtins__.int.int" + result_type = target and objpath == "native.int.is_int" and int_type or None + yields_integer = result_type == int_type # Arguments are presented in a temporary frame array with any context # always being the first argument. Where it would be unused, it may be @@ -1500,8 +1502,8 @@ # Provide the parameter details for possible optimisation when # translating the result. - return InvocationResult(stages, - yields_integer and final_args or None) + return InvocationResult(stages, result_type, + result_type and final_args or None) # With unknown targets, the generic invocation function is applied to # the callable and argument collections. diff -r 4a078c610c57 -r 23d55ac56433 transresults.py --- a/transresults.py Sat May 25 17:55:37 2024 +0200 +++ b/transresults.py Sat May 25 18:02:58 2024 +0200 @@ -285,21 +285,23 @@ "A translation result for an invocation." - def __init__(self, instructions, args=None): + def __init__(self, instructions, result_type=None, args=None): InstructionSequence.__init__(self, instructions) + self.result_type = result_type self.args = args def yields_integer(self): - return self.args and True or False + return self.result_type == "__builtins__.int.int" def __str__(self): - if self.yields_integer(): + if self.yields_integer() and self.args is not None: return ", ".join(self.args) else: return encode_instructions(self.instructions) def __repr__(self): - return "InvocationResult(%r, %r)" % (self.instructions, self.args) + return "InvocationResult(%r, %r, %r)" % (self.instructions, + self.result_type, self.args) class InstantiationResult(InvocationResult, TrInstanceRef): @@ -309,6 +311,9 @@ InstanceRef.__init__(self, ref) InvocationResult.__init__(self, instructions) + def yields_integer(self): + return self.ref.get_origin() == "__builtins__.int.int" + def __repr__(self): return "InstantiationResult(%r, %r)" % (self.ref, self.instructions)