Skip to content
← Back

src/ir/block_stack.ghul

1
namespace IR is
2
use Logging
3
4
class BLOCK_STACK: BlockContext is
5
_blocks: Collections.STACK[Values.BLOCK]
6
7
is_in_block: bool => _blocks.count > 0
8
9
init() is
10
_blocks = Collections.STACK[Values.BLOCK]()
11
si
12
13
mark() -> int => _blocks.count
14
15
release(mark: int) is
16
while _blocks.count > mark do
17
_blocks.pop()
18
od
19
si
20
21
current_block: Values.BLOCK =>
22
assert _blocks.count > 0 else "BS {get_hash_code()}: no block on stack" in
23
24
_blocks.peek()
25
26
enter_block(block: Values.BLOCK) -> Values.BLOCK is
27
_blocks.push(block)
28
29
return block
30
si
31
32
enter_block(type: Semantic.Types.Type) -> Values.BLOCK is
33
let result = Values.BLOCK(type)
34
enter_block(result)
35
return result
36
si
37
38
enter_block() -> Values.BLOCK is
39
let result = Values.BLOCK()
40
enter_block(result)
41
return result
42
si
43
44
leave_block() is
45
_blocks.pop()
46
si
47
48
add(value: Values.Value) is
49
current_block.add(value)
50
si
51
si
52
si