1.1 --- a/translator.py Tue May 21 19:20:32 2024 +0200
1.2 +++ b/translator.py Fri May 24 00:20:23 2024 +0200
1.3 @@ -1317,21 +1317,24 @@
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 # Employ result targets only in functions.
1.12
1.13 + result_target = None
1.14 +
1.15 if self.in_function:
1.16 if self.result_target_name:
1.17 result_target = self.result_target_name
1.18 self.result_target_name = None
1.19 - else:
1.20 +
1.21 + # Reserve a temporary result target only if it will be used.
1.22 +
1.23 + elif not literal_instantiation and not yields_integer:
1.24 result_target = "__tmp_results[%d]" % self.result_target
1.25 -
1.26 - # Reserve a temporary result target only if it will be used.
1.27 -
1.28 - if not literal_instantiation:
1.29 - self.next_temp("__tmp_results")
1.30 - else:
1.31 - result_target = None
1.32 + self.next_temp("__tmp_results")
1.33
1.34 # Arguments are presented in a temporary frame array with any context
1.35 # always being the first argument. Where it would be unused, it may be
1.36 @@ -1466,9 +1469,17 @@
1.37 # the number of values. The result target and context are excluded.
1.38
1.39 if literal_instantiation:
1.40 - argstr = "%d, %s" % (len(args) - reserved_args, ", ".join(args[reserved_args:]))
1.41 + final_args = args[reserved_args:]
1.42 + argstr = "%d, %s" % (len(final_args), ", ".join(final_args))
1.43 else:
1.44 - argstr = ", ".join(args)
1.45 + # NOTE: Special case for optimisation.
1.46 +
1.47 + if yields_integer:
1.48 + final_args = args[reserved_args:]
1.49 + else:
1.50 + final_args = args
1.51 +
1.52 + argstr = ", ".join(final_args)
1.53
1.54 kwargstr = kwargs and ("__ARGS(%s)" % ", ".join(kwargs)) or "0"
1.55 kwcodestr = kwcodes and ("__KWARGS(%s)" % ", ".join(kwcodes)) or "0"
1.56 @@ -1542,7 +1553,11 @@
1.57 if instantiation:
1.58 return InstantiationResult(instantiation, stages)
1.59 else:
1.60 - return InvocationResult(result_target, stages)
1.61 + # Provide the parameter details for possible optimisation when
1.62 + # translating the result.
1.63 +
1.64 + return InvocationResult(result_target, stages,
1.65 + yields_integer and final_args or None)
1.66
1.67 # With unknown targets, the generic invocation function is applied to
1.68 # the callable and argument collections.
1.69 @@ -2353,7 +2368,7 @@
1.70 if temps:
1.71 self.remove_temps(temps)
1.72 else:
1.73 - self.writeline("%s (__BOOL(%s))" % (statement, test_ref))
1.74 + self.writeline("%s (%s)" % (statement, test_ref.apply_test()))
1.75
1.76 self.writeline("{")
1.77 self.indent += 1