Skip to content
← Back

src/ir/values/load/self.ghul

1
namespace IR.Values.Load is
2
use TypeTyped = Semantic.Types.Typed
3
use Semantic.Types.Type
4
use SymbolBase = Semantic.Symbols.Symbol
5
6
class REFERENCE_SELF: Value, TypeTyped is
7
`self: SymbolBase
8
type: Type?
9
10
is_self: bool => true
11
has_address: bool => true
12
is_lightweight_pure: bool => true
13
14
init(`self: SymbolBase) is
15
init(`self, null)
16
si
17
18
init(`self: SymbolBase, type: Type?) is
19
super.init()
20
21
self.`self = `self
22
23
if type? then
24
self.type = type
25
elif isa TypeTyped(`self) then
26
self.type = cast TypeTyped(`self).type!
27
fi
28
si
29
30
accept(visitor: Visitor) is
31
visitor.visit(self)
32
si
33
34
accept_address(visitor: Visitor) is
35
visitor.visit_address(self)
36
si
37
38
to_string() -> string =>
39
"self:[{type}]"
40
si
41
42
// Self-load inside a generator's MoveNext: ldarg.0 is the
43
// state-machine frame, not the user's instance, so the body's
44
// `self` accesses go through the synthesised _outer_self
45
// frame field. INSTANCE_GENERATOR_METHOD.load_self constructs
46
// this variant; ordinary instance methods keep the plain
47
// REFERENCE_SELF (ldarg.0).
48
class OUTER_SELF: Value, TypeTyped is
49
`self: SymbolBase
50
outer_self_field: Semantic.Symbols.Field
51
type: Type?
52
53
is_self: bool => true
54
has_address: bool => true
55
is_lightweight_pure: bool => true
56
57
init(`self: SymbolBase, type: Type?, outer_self_field: Semantic.Symbols.Field) is
58
super.init()
59
60
self.`self = `self
61
self.outer_self_field = outer_self_field
62
63
if type? then
64
self.type = type
65
elif isa TypeTyped(`self) then
66
self.type = cast TypeTyped(`self).type!
67
fi
68
si
69
70
71
accept(visitor: Visitor) is
72
visitor.visit(self)
73
si
74
75
accept_address(visitor: Visitor) is
76
visitor.visit_address(self)
77
si
78
79
to_string() -> string =>
80
"outer_self:[{type}]"
81
si
82
83
// pretty much all the time we reference a struct's self
84
// we actually want the address, but for an explicit `self`
85
// we need the value:
86
class VALUE_SELF: Value, TypeTyped is
87
`self: SymbolBase
88
type: Type?
89
90
is_self: bool => true
91
has_address: bool => true
92
is_lightweight_pure: bool => true
93
94
init(`self: SymbolBase) is
95
init(`self, null)
96
si
97
98
init(`self: SymbolBase, type: Type?) is
99
super.init()
100
101
self.`self = `self
102
103
if type? then
104
self.type = type
105
elif isa TypeTyped(`self) then
106
self.type = cast TypeTyped(`self).type!
107
fi
108
si
109
110
// we do actually have an address, just default to the value
111
112
accept(visitor: Visitor) is
113
visitor.visit(self)
114
si
115
116
accept_address(visitor: Visitor) is
117
visitor.visit_address(self)
118
si
119
120
to_string() -> string =>
121
"self:[{type}]"
122
si
123
124
si