1.1 --- a/transresults.py Tue May 21 19:20:32 2024 +0200
1.2 +++ b/transresults.py Fri May 24 00:20:23 2024 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Translation result abstractions.
1.6
1.7 -Copyright (C) 2016, 2017, 2018, 2021, 2023 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2016-2018, 2021, 2023, 2024 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -295,15 +295,23 @@
1.13
1.14 "A translation result for an invocation."
1.15
1.16 - def __init__(self, result_target, instructions):
1.17 + def __init__(self, result_target, instructions, args=None):
1.18 InstructionSequence.__init__(self, instructions)
1.19 self.result_target = result_target
1.20 + self.args = args
1.21 +
1.22 + def yields_integer(self):
1.23 + return self.args and True or False
1.24
1.25 def __str__(self):
1.26 - return encode_instructions(self.instructions)
1.27 + if self.yields_integer():
1.28 + return ", ".join(self.args)
1.29 + else:
1.30 + return encode_instructions(self.instructions)
1.31
1.32 def __repr__(self):
1.33 - return "InvocationResult(%r, %r)" % (self.result_target, self.instructions)
1.34 + return "InvocationResult(%r, %r, %r)" % (self.result_target,
1.35 + self.instructions, self.args)
1.36
1.37 class InstantiationResult(InvocationResult, TrInstanceRef):
1.38
1.39 @@ -349,14 +357,7 @@
1.40
1.41 "A logical expression result."
1.42
1.43 - def _convert(self, expr):
1.44 -
1.45 - "Return 'expr' converted to a testable value."
1.46 -
1.47 - if isinstance(expr, LogicalResult):
1.48 - return expr.apply_test()
1.49 - else:
1.50 - return "__BOOL(%s)" % expr
1.51 + pass
1.52
1.53 class NegationResult(LogicalResult):
1.54
1.55 @@ -369,8 +370,7 @@
1.56
1.57 "Return the result in a form suitable for direct testing."
1.58
1.59 - expr = self._convert(self.expr)
1.60 - return "(!%s)" % expr
1.61 + return "(!%s)" % self.expr.apply_test()
1.62
1.63 def discards_temporary(self, test=True):
1.64
1.65 @@ -381,9 +381,12 @@
1.66
1.67 return None
1.68
1.69 + def yields_integer(self):
1.70 + return self.expr.yields_integer()
1.71 +
1.72 def __str__(self):
1.73 return "(%s ? %s : %s)" % (
1.74 - self._convert(self.expr),
1.75 + self.expr.apply_test(),
1.76 PredefinedConstantRef("False"),
1.77 PredefinedConstantRef("True"))
1.78
1.79 @@ -414,7 +417,7 @@
1.80
1.81 results = []
1.82 for expr in self.exprs:
1.83 - results.append(self._convert(expr))
1.84 + results.append(expr.apply_test())
1.85
1.86 if self.conjunction:
1.87 return "(%s)" % " && ".join(results)
1.88 @@ -440,6 +443,12 @@
1.89
1.90 return temps
1.91
1.92 + def yields_integer(self):
1.93 + for expr in self.exprs:
1.94 + if not expr.yields_integer():
1.95 + return False
1.96 + return True
1.97 +
1.98 def __str__(self):
1.99
1.100 """