Skip to content
← Back

src/ir/values/load/local_variable.ghul

1
namespace IR.Values.Load is
2
use TypeTyped = Semantic.Types.Typed;
3
use SymbolBase = Semantic.Symbols.Symbol;
4
5
class LOCAL_VARIABLE: SYMBOL, TypeTyped is
6
is_consumable: bool => true;
7
is_lightweight_pure: bool => true;
8
9
init(symbol: SymbolBase) is
10
super.init(null, symbol);
11
si
12
13
gen(context: IR.CONTEXT) is
14
// Generator-function locals: the CLR-local slot doesn't
15
// exist inside MoveNext, so the load is redirected to
16
// the field on the state-machine frame. See the matching
17
// Load.LOCAL_ARGUMENT for the rationale.
18
let field_reference = IR.Values.state_machine_field_reference(symbol);
19
20
if field_reference? then
21
context.write_line("ldarg.0");
22
context.write_line("ldfld {field_reference}");
23
return;
24
fi
25
26
context.write_line("ldloc {symbol.il_name}");
27
si
28
29
gen_address(context: IR.CONTEXT) is
30
let field_reference = IR.Values.state_machine_field_reference(symbol);
31
32
if field_reference? then
33
context.write_line("ldarg.0");
34
context.write_line("ldflda {field_reference}");
35
return;
36
fi
37
38
context.write_line("ldloca {symbol.il_name}");
39
si
40
41
to_string() -> string =>
42
"load:[{type}]({from},\"{symbol.name}\")";
43
si
44
si