Skip to content
← Back

src/syntax/trees/iterator_carrier.ghul

1
namespace Syntax.Trees is
2
3
// A node that iterates a sequence: a `for` loop, or a `yield in`
4
// that hands every element of one on. Compile-expressions resolves
5
// the iterator surface (`$get_iterator`, `move_next`, `$get_current`)
6
// once, here, and the IL pass drives those members directly.
7
trait IteratorCarrier is
8
// The sequence being iterated. Null where the parse failed.
9
iterated: Expressions.Expression?
10
11
// Null when `iterated` is already an iterator, in which case
12
// move_next / read_current are driven on its value directly.
13
read_iterator: Semantic.Symbols.Function?,
14
= value
15
16
read_current: Semantic.Symbols.Function?,
17
= value
18
19
move_next: Semantic.Symbols.Function?,
20
= value
21
22
// Inside a generator or async function the iterator has to
23
// survive every suspension, so it lives in a frame field rather
24
// than a CLR local, which MoveNext would reset on re-entry.
25
// Allocated in compile-expressions rather than while emitting,
26
// because the emitted assembly's rows are numbered before any
27
// body is compiled and a field that appears after that has none.
28
// Null outside a state machine.
29
iterator_field: Semantic.Symbols.Field?,
30
= value
31
si
32
si