Skip to content
← Back

src/ir/values/address.ghul

1
namespace IR.Values is
2
use Semantic.Types.Type
3
4
class ADDRESS: Value is
5
_next_id: int static
6
7
is_lightweight_pure: bool => value.is_lightweight_pure
8
has_address: bool => value.has_address
9
type: Type
10
value: Value
11
12
name: string?
13
14
next_name: string static is
15
let result = ".address.{_next_id}"
16
17
_next_id = _next_id + 1
18
19
return result
20
si
21
22
init(
23
value: Value,
24
type: Type
25
) is
26
super.init()
27
28
self.value = value
29
self.type = type
30
si
31
32
init(
33
value: Value
34
) is
35
init(value, value.type!)
36
si
37
38
reset_id() static is
39
_next_id = 0
40
si
41
42
gen_address(context: IR.CONTEXT) is
43
gen(context)
44
si
45
46
gen(context: IR.CONTEXT) is
47
if value.has_address then
48
value.gen_address(context)
49
else
50
if !name? then
51
name = next_name
52
fi
53
54
let body = context.current_srm_body_emitter!
55
body.declare_local(name!, type)
56
57
value.gen(context)
58
59
body.stloc(name!)
60
body.ldloca(name!)
61
fi
62
si
63
64
to_string() -> string =>
65
"address:[{type}]({value})"
66
si
67
si