Skip to content
← Back

src/ir/values/equality_comparison.ghul

1
namespace IR.Values is
2
use TypeTyped = Semantic.Types.Typed
3
use Semantic.Types.Type
4
5
// `a =~ b` where both operands are a bare type parameter: no member
6
// operator can resolve statically, so the comparison goes through
7
// `EqualityComparer[T].Default`. That reaches a user-written `=~`
8
// through the synthesized `Equals` bridge where the instantiation
9
// declares one, and the runtime's own comparers give every other
10
// instantiation its natural value equality.
11
class EQUALITY_COMPARISON: Value, TypeTyped is
12
left: Value
13
right: Value
14
comparer_type: Type
15
type: Type
16
17
init(left: Value, right: Value, comparer_type: Type, type: Type) is
18
super.init()
19
20
self.left = left
21
self.right = right
22
self.comparer_type = comparer_type
23
self.type = type
24
si
25
26
gen(context: IR.CONTEXT) is
27
let body = context.current_srm_body_emitter!
28
29
body.call(context.resolve_equality_comparer_default(comparer_type))
30
31
gen(left, context)
32
gen(right, context)
33
34
body.call_virtual(context.resolve_equality_comparer_equals(comparer_type))
35
si
36
37
to_string() -> string =>
38
"equality-comparison[{comparer_type}]({left}, {right})"
39
si
40
si