Skip to content
← Back

src/syntax/process/statement_states.ghul

1
namespace Syntax.Process is
2
use Collections
3
4
use Type = Semantic.Types.Type
5
use Value = IR.Values.Value
6
use Variable = Semantic.Symbols.Variable
7
8
// Per-build state the compile-expressions pass family records on
9
// statement nodes, read downstream by IL generation. Each struct is
10
// hosted as a field on its statement class and knows how to clear
11
// itself; the statement classes carry read-only forwarders and no
12
// knowledge of the contents. See NodeStateStore for the companion
13
// store-based pattern for sparse state.
14
struct STATEMENT_STATE is
15
value: Value? public
16
want_value: bool public
17
// Set alongside want_value where a value is wanted but a void
18
// one is acceptable: the body of a function literal whose
19
// return type is still being inferred. An `if` / `case` there
20
// whose arms only yield void produces no value at all and
21
// settles the return as void, rather than being reported for
22
// having no value to give.
23
void_tolerated: bool public
24
// Set by the statement-list visitor's function-tail judge when a
25
// demanded tail delivered a non-void value (well- or ill-typed):
26
// the implicit return consumed the body's return obligation. A
27
// tail that turned out void leaves it false, and the body falls
28
// through to the default-value return under the definite-return
29
// warning.
30
function_tail_delivered: bool public
31
// Locals declared by `let use ... in` expressions within this
32
// statement, disposed once the statement completes.
33
let_in_disposals: Collections.LIST[Variable]? public
34
35
init() is
36
si
37
38
add_let_in_disposal(v: Variable) is
39
let list = let_in_disposals ?? Collections.LIST[Variable]()
40
let_in_disposals = list
41
42
list.add(v)
43
si
44
45
clear() is
46
value = null
47
want_value = false
48
void_tolerated = false
49
function_tail_delivered = false
50
let_in_disposals = null
51
si
52
53
clear_outputs() is
54
value = null
55
function_tail_delivered = false
56
let_in_disposals = null
57
si
58
si
59
60
struct LIST_DISPOSAL_STATE is
61
variables_to_dispose: Collections.LIST[Variable]? public
62
want_dispose: bool public
63
64
init() is
65
si
66
67
add(v: Variable) is
68
want_dispose = true
69
70
let list = variables_to_dispose ?? Collections.LIST[Variable]()
71
variables_to_dispose = list
72
73
list.add(v)
74
si
75
76
clear() is
77
variables_to_dispose = null
78
want_dispose = false
79
si
80
si
81
82
struct EXPECTED_TYPE_STATE is
83
expected_type: Type? public
84
expected_type_error_message: string? public
85
86
init() is
87
si
88
89
set(expected_type: Type?, error_message: string?) is
90
self.expected_type = expected_type
91
self.expected_type_error_message = error_message
92
si
93
94
clear() is
95
expected_type = null
96
expected_type_error_message = null
97
si
98
si
99
100
struct CASE_STATE is
101
expected_type: Type? public
102
expected_type_error_message: string? public
103
is_exhaustive: bool public
104
requires_default_fallthrough: bool public
105
// The scrutinee evaluated once into a temp, shared across every
106
// `when` label test and pattern arm. `scrutinee_spill` is
107
// emitted at the start of the case; `scrutinee_load` reads the
108
// temp. Built in compile-expressions so every label's
109
// value-equality test - also built there - references the one
110
// evaluation, matching the single-evaluation semantics the
111
// case scrutinee has always had.
112
scrutinee_spill: Value? public
113
scrutinee_load: Value? public
114
115
init() is
116
si
117
118
set_expected_type(expected_type: Type?, error_message: string?) is
119
self.expected_type = expected_type
120
self.expected_type_error_message = error_message
121
si
122
123
set_scrutinee(scrutinee_spill: Value?, scrutinee_load: Value?) is
124
self.scrutinee_spill = scrutinee_spill
125
self.scrutinee_load = scrutinee_load
126
si
127
128
clear() is
129
expected_type = null
130
expected_type_error_message = null
131
is_exhaustive = false
132
requires_default_fallthrough = false
133
scrutinee_spill = null
134
scrutinee_load = null
135
si
136
si
137
138
// Per-arm state for a `case` `when` label list: the value-equality
139
// test Value built in compile-expressions for each label, parallel
140
// to the arm's label expressions. A null entry means no `=~`/`<>`
141
// resolved for that label (or it is a `null` label) - generate-il
142
// then falls back to a raw compare, or a presence test for `null`.
143
struct CASE_MATCH_STATE is
144
tests: Collections.LIST[Value?]? public
145
146
init() is
147
si
148
149
clear() is
150
tests = null
151
si
152
si
153
si