1.1 --- a/transresults.py Tue May 21 19:04:20 2024 +0200
1.2 +++ b/transresults.py Fri May 24 00:11:20 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 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 @@ -285,11 +285,21 @@
1.13
1.14 "A translation result for an invocation."
1.15
1.16 + def __init__(self, instructions, args=None):
1.17 + InstructionSequence.__init__(self, instructions)
1.18 + self.args = args
1.19 +
1.20 + def yields_integer(self):
1.21 + return self.args and True or False
1.22 +
1.23 def __str__(self):
1.24 - return encode_instructions(self.instructions)
1.25 + if self.yields_integer():
1.26 + return ", ".join(self.args)
1.27 + else:
1.28 + return encode_instructions(self.instructions)
1.29
1.30 def __repr__(self):
1.31 - return "InvocationResult(%r)" % self.instructions
1.32 + return "InvocationResult(%r, %r)" % (self.instructions, self.args)
1.33
1.34 class InstantiationResult(InvocationResult, TrInstanceRef):
1.35
1.36 @@ -335,14 +345,7 @@
1.37
1.38 "A logical expression result."
1.39
1.40 - def _convert(self, expr):
1.41 -
1.42 - "Return 'expr' converted to a testable value."
1.43 -
1.44 - if isinstance(expr, LogicalResult):
1.45 - return expr.apply_test()
1.46 - else:
1.47 - return "__BOOL(%s)" % expr
1.48 + pass
1.49
1.50 class NegationResult(LogicalResult):
1.51
1.52 @@ -355,8 +358,7 @@
1.53
1.54 "Return the result in a form suitable for direct testing."
1.55
1.56 - expr = self._convert(self.expr)
1.57 - return "(!%s)" % expr
1.58 + return "(!%s)" % self.expr.apply_test()
1.59
1.60 def discards_temporary(self, test=True):
1.61
1.62 @@ -367,9 +369,12 @@
1.63
1.64 return None
1.65
1.66 + def yields_integer(self):
1.67 + return self.expr.yields_integer()
1.68 +
1.69 def __str__(self):
1.70 return "(%s ? %s : %s)" % (
1.71 - self._convert(self.expr),
1.72 + self.expr.apply_test(),
1.73 PredefinedConstantRef("False"),
1.74 PredefinedConstantRef("True"))
1.75
1.76 @@ -400,7 +405,7 @@
1.77
1.78 results = []
1.79 for expr in self.exprs:
1.80 - results.append(self._convert(expr))
1.81 + results.append(expr.apply_test())
1.82
1.83 if self.conjunction:
1.84 return "(%s)" % " && ".join(results)
1.85 @@ -426,6 +431,12 @@
1.86
1.87 return temps
1.88
1.89 + def yields_integer(self):
1.90 + for expr in self.exprs:
1.91 + if not expr.yields_integer():
1.92 + return False
1.93 + return True
1.94 +
1.95 def __str__(self):
1.96
1.97 """