1.1 --- a/transresults.py Sun Nov 14 00:37:32 2021 +0100
1.2 +++ b/transresults.py Sun Nov 14 00:42:49 2021 +0100
1.3 @@ -59,6 +59,12 @@
1.4 def __repr__(self):
1.5 return "Expression(%r)" % self.s
1.6
1.7 + def as_arg(self):
1.8 +
1.9 + "Return the expression without any mutable tag."
1.10 +
1.11 + return self.s
1.12 +
1.13 class TrResolvedNameRef(ResolvedNameRef):
1.14
1.15 "A reference to a name in the translation."
1.16 @@ -132,6 +138,21 @@
1.17 else:
1.18 return "(%s)" % self.attrname
1.19
1.20 + def as_arg(self):
1.21 +
1.22 + "Return the expression without any mutable tag."
1.23 +
1.24 + s = self.__str__()
1.25 +
1.26 + # NOTE: This is a superficial test for internal attributes that relies
1.27 + # NOTE: on such attributes being used directly and passed to native
1.28 + # NOTE: code.
1.29 +
1.30 + if self.attrname in ("__data__", "__size__"):
1.31 + return s
1.32 + else:
1.33 + return "__TO_IMMUTABLE(%s)" % s
1.34 +
1.35 class TrConstantValueRef(ConstantValueRef):
1.36
1.37 "A constant value reference in the translation."
1.38 @@ -139,6 +160,9 @@
1.39 def __str__(self):
1.40 return encode_literal_constant(self.number)
1.41
1.42 + def as_arg(self):
1.43 + return self.__str__()
1.44 +
1.45 class TrLiteralSequenceRef(LiteralSequenceRef):
1.46
1.47 "A reference representing a sequence of values."
1.48 @@ -146,6 +170,9 @@
1.49 def __str__(self):
1.50 return str(self.node)
1.51
1.52 + def as_arg(self):
1.53 + return self.__str__()
1.54 +
1.55 class TrInstanceRef(InstanceRef):
1.56
1.57 "A reference representing instantiation of a class."
1.58 @@ -166,6 +193,9 @@
1.59 def __repr__(self):
1.60 return "TrResolvedInstanceRef(%r, %r)" % (self.ref, self.expr)
1.61
1.62 + def as_arg(self):
1.63 + return self.__str__()
1.64 +
1.65 class AttrResult(Result, InstructionSequence):
1.66
1.67 "A translation result for an attribute access."
1.68 @@ -222,6 +252,9 @@
1.69 self.context_identity, self.context_identity_verified,
1.70 self.accessor_test, self.accessor_stored)
1.71
1.72 + def as_arg(self):
1.73 + return self.__str__()
1.74 +
1.75 class AliasResult(NameRef, Result):
1.76
1.77 "An alias for other values."
1.78 @@ -275,6 +308,9 @@
1.79 def __repr__(self):
1.80 return "AliasResult(%r, %r)" % (self.name_ref, self.refs)
1.81
1.82 + def as_arg(self):
1.83 + return self.__str__()
1.84 +
1.85 class InvocationResult(Result, InstructionSequence):
1.86
1.87 "A translation result for an invocation."
1.88 @@ -285,6 +321,9 @@
1.89 def __repr__(self):
1.90 return "InvocationResult(%r)" % self.instructions
1.91
1.92 + def as_arg(self):
1.93 + return self.__str__()
1.94 +
1.95 class InstantiationResult(InvocationResult, TrInstanceRef):
1.96
1.97 "An instantiation result acting like an invocation result."
1.98 @@ -325,6 +364,9 @@
1.99 def __repr__(self):
1.100 return "PredefinedConstantRef(%r)" % self.value
1.101
1.102 + def as_arg(self):
1.103 + return self.__str__()
1.104 +
1.105 class LogicalResult(Result):
1.106
1.107 "A logical expression result."
1.108 @@ -370,6 +412,9 @@
1.109 def __repr__(self):
1.110 return "NegationResult(%r)" % self.expr
1.111
1.112 + def as_arg(self):
1.113 + return self.__str__()
1.114 +
1.115 class LogicalOperationResult(LogicalResult):
1.116
1.117 "A logical operation result."
1.118 @@ -442,4 +487,7 @@
1.119 def __repr__(self):
1.120 return "LogicalOperationResult(%r, %r)" % (self.exprs, self.conjunction)
1.121
1.122 + def as_arg(self):
1.123 + return self.__str__()
1.124 +
1.125 # vim: tabstop=4 expandtab shiftwidth=4