Skip to content
← Back

src/ir/values/constrained.ghul

1
namespace IR.Values is
2
use Semantic.Types.Type
3
4
class CONSTRAINED: Value is
5
value: Value
6
_type: Type
7
type: Type? pure => _type
8
is_value_type: bool => false
9
10
init(
11
value: Value,
12
type: Type
13
) is
14
super.init()
15
16
self._type = type
17
self.value = ADDRESS(value, type)
18
si
19
20
init(
21
value: Value
22
) is
23
init(value, value.type!)
24
si
25
26
// Only load the receiver address. The `constrained.` prefix
27
// must sit immediately before the `callvirt`, after the
28
// arguments have been loaded, so the enclosing instance call
29
// emits it via gen_prefix once the operand stack is set up.
30
gen(context: IR.CONTEXT) is
31
value.gen(context)
32
si
33
34
gen_prefix(context: IR.CONTEXT) is
35
let body = context.current_srm_body_emitter!
36
body.constrained(context.resolve_type_token(type!))
37
si
38
39
to_string() -> string =>
40
"constrained:[{type}]({value})"
41
si
42
si