1.1 --- a/translator.py Tue May 21 19:04:32 2024 +0200
1.2 +++ b/translator.py Fri May 24 00:14:24 2024 +0200
1.3 @@ -1285,6 +1285,10 @@
1.4 if stores_accessor:
1.5 self.record_temp("__tmp_values")
1.6
1.7 + # NOTE: Special case for optimisation.
1.8 +
1.9 + yields_integer = target and objpath == "native.int.is_int"
1.10 +
1.11 # Arguments are presented in a temporary frame array with any context
1.12 # always being the first argument. Where it would be unused, it may be
1.13 # set to null.
1.14 @@ -1409,9 +1413,17 @@
1.15 # the number of values. The context is excluded.
1.16
1.17 if literal_instantiation:
1.18 - argstr = "%d, %s" % (len(args) - reserved_args, ", ".join(args[reserved_args:]))
1.19 + final_args = args[reserved_args:]
1.20 + argstr = "%d, %s" % (len(final_args), ", ".join(final_args))
1.21 else:
1.22 - argstr = ", ".join(args)
1.23 + # NOTE: Special case for optimisation.
1.24 +
1.25 + if yields_integer:
1.26 + final_args = args[reserved_args:]
1.27 + else:
1.28 + final_args = args
1.29 +
1.30 + argstr = ", ".join(final_args)
1.31
1.32 kwargstr = kwargs and ("__ARGS(%s)" % ", ".join(kwargs)) or "0"
1.33 kwcodestr = kwcodes and ("__KWARGS(%s)" % ", ".join(kwcodes)) or "0"
1.34 @@ -1485,7 +1497,11 @@
1.35 if instantiation:
1.36 return InstantiationResult(instantiation, stages)
1.37 else:
1.38 - return InvocationResult(stages)
1.39 + # Provide the parameter details for possible optimisation when
1.40 + # translating the result.
1.41 +
1.42 + return InvocationResult(stages,
1.43 + yields_integer and final_args or None)
1.44
1.45 # With unknown targets, the generic invocation function is applied to
1.46 # the callable and argument collections.
1.47 @@ -2227,7 +2243,7 @@
1.48 if temps:
1.49 self.remove_temps(temps)
1.50 else:
1.51 - self.writeline("%s (__BOOL(%s))" % (statement, test_ref))
1.52 + self.writeline("%s (%s)" % (statement, test_ref.apply_test()))
1.53
1.54 self.writeline("{")
1.55 self.indent += 1