Skip to content
← Back

src/ir/values/async_completion.ghul

1
namespace IR.Values is
2
use Semantic.Types.Type
3
use Semantic.Symbols.Field
4
5
// Completes an async state machine's task through its builder, after
6
// marking the machine finished. A failure stores the exception on
7
// the evaluation stack, as a catch handler starts with it, and sets
8
// it on the builder; a success sets the result held in
9
// `result_field`, or no result where that is null.
10
class ASYNC_COMPLETION: Value is
11
state_field: Field
12
builder_field: Field
13
result_field: Field?
14
exception_type: Type?
15
16
// Written by the MoveNext lowering, not by any statement, so it
17
// marks no position.
18
has_location: bool => false
19
20
init(state_field: Field, builder_field: Field, result_field: Field?, exception_type: Type?) is
21
super.init()
22
23
self.state_field = state_field
24
self.builder_field = builder_field
25
self.result_field = result_field
26
self.exception_type = exception_type
27
si
28
29
failure(state_field: Field, builder_field: Field, exception_type: Type) -> ASYNC_COMPLETION static =>
30
ASYNC_COMPLETION(state_field, builder_field, null, exception_type)
31
32
success(state_field: Field, builder_field: Field, result_field: Field?) -> ASYNC_COMPLETION static =>
33
ASYNC_COMPLETION(state_field, builder_field, result_field, null)
34
35
accept(visitor: Visitor) is
36
visitor.visit(self)
37
si
38
39
to_string() -> string =>
40
if exception_type? then "async-fail" else "async-succeed" fi
41
si
42
si