Skip to content
← Back

src/syntax/process/node_states.ghul

1
namespace Syntax.Process is
2
use Collections
3
4
// Per-build compile-expressions state for the node kinds that
5
// carry more than the common EXPRESSION_STATE / STATEMENT_STATE.
6
// Each struct is hosted as a field on its node class, which keeps
7
// forwarders for the members and no knowledge of the storage, so
8
// that what a walk writes is reset by Node.clear() and
9
// Node.clear_outputs() through the struct rather than field by
10
// field.
11
12
// Whether a `ref` argument is a write, decided from the resolved
13
// callee.
14
struct REFERENCE_STATE is
15
writes_target: bool public
16
17
init() is
18
si
19
20
clear() is
21
writes_target = false
22
si
23
si
24
25
// The operators a synthesized memberwise comparison calls, one per
26
// member, recorded as each resolves.
27
struct MEMBERWISE_STATE is
28
called_functions: LIST[Semantic.Symbols.Function]? public
29
30
init() is
31
si
32
33
functions() -> LIST[Semantic.Symbols.Function] is
34
let list = called_functions ?? LIST[Semantic.Symbols.Function]()
35
called_functions = list
36
37
return list
38
si
39
40
clear() is
41
called_functions = null
42
si
43
si
44
45
// What an `if` in value position yields when no branch runs.
46
struct IF_STATE is
47
yields_absence_on_fall_through: bool public
48
49
init() is
50
si
51
52
clear() is
53
yields_absence_on_fall_through = false
54
si
55
si
56
57
// The iterator surface a `for` or `yield in` drives, resolved once
58
// by compile-expressions and read by generate-il. The frame field a
59
// state machine keeps the iterator in is allocated once and retyped
60
// by later walks, so clear_outputs() keeps it.
61
struct ITERATOR_STATE is
62
read_iterator: Semantic.Symbols.Function? public
63
read_current: Semantic.Symbols.Function? public
64
move_next: Semantic.Symbols.Function? public
65
iterator_field: Semantic.Symbols.Field? public
66
fusion: PIPE_FUSION? public
67
68
init() is
69
si
70
71
clear() is
72
read_iterator = null
73
read_current = null
74
move_next = null
75
iterator_field = null
76
fusion = null
77
si
78
79
clear_outputs() is
80
read_iterator = null
81
read_current = null
82
move_next = null
83
fusion = null
84
si
85
si
86
87
// The awaiter pattern an `await` resolved on its operand's type, and
88
// the frame fields a state machine carries its awaiter and result
89
// in. The fields are allocated once and retyped by later walks, so
90
// clear_outputs() keeps them.
91
struct AWAIT_STATE is
92
awaitable: Semantic.AWAITABLE? public
93
result_field: Semantic.Symbols.Field? public
94
awaiter_field: Semantic.Symbols.Field? public
95
96
init() is
97
si
98
99
clear() is
100
awaitable = null
101
result_field = null
102
awaiter_field = null
103
si
104
105
clear_outputs() is
106
awaitable = null
107
si
108
si
109
110
// The local a `use` holds its value in until the enclosing statement
111
// list disposes it, declared once and kept across walks.
112
struct USE_STATE is
113
target: Semantic.Symbols.Variable? public
114
115
init() is
116
si
117
118
clear() is
119
target = null
120
si
121
si
122
123
// The frame field a spilled operand is held in across a suspend,
124
// allocated once and retyped by later walks.
125
struct SPILL_STATE is
126
spill_field: Semantic.Symbols.Field? public
127
128
init() is
129
si
130
131
clear() is
132
spill_field = null
133
si
134
135
clear_outputs() is
136
si
137
si
138
139
// What the wrapping context asked of a statement in expression
140
// position, and the temp the walk routed its value through.
141
struct STATEMENT_EXPRESSION_STATE is
142
temp: IR.TEMP? public
143
want_value: bool public
144
void_tolerated: bool public
145
146
init() is
147
si
148
149
clear() is
150
temp = null
151
want_value = true
152
void_tolerated = false
153
si
154
155
clear_outputs() is
156
temp = null
157
si
158
si
159
160
// A parenthesised block's inputs from its context and the outputs
161
// its walk collects from the returns that target it.
162
struct VAL_BLOCK_STATE is
163
want_value: bool public
164
void_tolerated: bool public
165
expected_type: Semantic.Types.Type? public
166
expected_type_error_message: string? public
167
return_types: LIST[Semantic.Types.Type]? public
168
has_targeted_return: bool public
169
end_label: IR.LABEL? public
170
171
init() is
172
si
173
174
returns() -> LIST[Semantic.Types.Type] is
175
let list = return_types ?? LIST[Semantic.Types.Type]()
176
return_types = list
177
178
return list
179
si
180
181
clear() is
182
want_value = true
183
void_tolerated = false
184
expected_type = null
185
expected_type_error_message = null
186
clear_outputs()
187
si
188
189
clear_outputs() is
190
return_types = null
191
has_targeted_return = false
192
end_label = null
193
si
194
si
195
196
// The block a `return` exits, when it exits a block rather than
197
// the function.
198
struct RETURN_STATE is
199
val_block_target: Syntax.Trees.Expressions.VAL_BLOCK? public
200
201
init() is
202
si
203
204
clear() is
205
val_block_target = null
206
si
207
si
208
209
// The loop a `break` or `continue` resolved to.
210
struct JUMP_STATE is
211
resolved_target: Syntax.Trees.Statements.Statement? public
212
213
init() is
214
si
215
216
clear() is
217
resolved_target = null
218
si
219
si
220
si
221
222
namespace Syntax.Process is
223
use Collections
224
225
// Whether a statement list is the tail of a function body, pushed by
226
// the literal or definition that owns it.
227
struct LIST_STATE is
228
function_tail: bool public
229
230
init() is
231
si
232
233
clear() is
234
function_tail = false
235
si
236
si
237
si