Skip to content
← Back

src/ir/values/compare_order_to_zero.ghul

1
namespace IR.Values is
2
use TypeTyped = Semantic.Types.Typed
3
use Semantic.Types.Type
4
5
class COMPARE_ORDER_TO_ZERO: Value, TypeTyped is
6
value: Value
7
actual_operation: string?
8
type: Type
9
10
is_value_type: bool => true
11
12
init(value: Value, actual_operation: string?, type: Type) is
13
super.init()
14
15
self.value = value
16
self.actual_operation = actual_operation
17
self.type = type
18
si
19
20
// The comparison against zero the operator makes. `==` reads
21
// an order value as an equality test - used by `case` when it
22
// falls back to a scrutinee's `<>` in place of a missing `=~`
23
// (see CASE_MATCH_OPERAND_RESOLVER).
24
comparison: IR.Comparison =>
25
if actual_operation =~ ">" then
26
IR.Comparison.GREATER
27
elif actual_operation =~ ">=" then
28
IR.Comparison.GREATER_OR_EQUAL
29
elif actual_operation =~ "<" then
30
IR.Comparison.LESS
31
elif actual_operation =~ "<=" then
32
IR.Comparison.LESS_OR_EQUAL
33
elif actual_operation =~ "==" then
34
IR.Comparison.EQUAL
35
else
36
throw System.Exception("unexpected compare order operation: {actual_operation}")
37
fi
38
39
accept(visitor: Visitor) is
40
visitor.visit(self)
41
si
42
43
to_string() -> string =>
44
"compare-order-to-zero[{actual_operation}]({value})"
45
si
46
si