Skip to content
← Back

src/ir/program/exit_numbering.ghul

1
namespace IR.Program is
2
use Collections.LIST
3
4
/// The exits that leave the protected body of a try with a finally,
5
/// numbered so the finally can be run once and the exit taken
6
/// afterwards from its number. Exits that go to the same place share a
7
/// number.
8
class EXIT_NUMBERING is
9
_exits: LIST[Values.Exit]
10
11
/// One of each kind of exit numbered so far, the exit numbered
12
/// `n` at `n - 1`.
13
exits: Collections.List[Values.Exit] => _exits
14
15
init() is
16
_exits = LIST[Values.Exit]()
17
si
18
19
/// The number of `exit`, from 1. Exits that go to the same place
20
/// share a number.
21
number(exit: Values.Exit) -> int is
22
let is_continue = isa Values.CONTINUE(exit)
23
24
for i in 0.._exits.count do
25
let numbered = _exits[i]
26
27
if numbered.target == exit.target /\ isa Values.CONTINUE(numbered) == is_continue then
28
return i + 1
29
fi
30
od
31
32
_exits.add(exit)
33
34
return _exits.count
35
si
36
si
37
si