Skip to content
← Back

src/ir/local_id_generator.ghul

1
namespace IR is
2
use IO.Std;
3
4
5
class LOCAL_ID_GENERATOR is
6
_next_id_stack: Collections.STACK[int];
7
8
next_id: int is
9
let result = _next_id_stack.pop();
10
11
_next_id_stack.push(result + 1);
12
13
return result;
14
si
15
16
// FIXME: could keep a set of local variable names seen in the current function and
17
// only add a suffix if the name is actually not unique
18
get_unique_il_name_for(name: string) -> string => "'{name}.{next_id}'";
19
20
init() is
21
_next_id_stack = Collections.STACK[int]();
22
si
23
24
enter_function() is
25
_next_id_stack.push(0);
26
si
27
28
leave_function() is
29
_next_id_stack.pop();
30
si
31
si
32
si