Skip to content
← Back

src/ir/values/load/local_argument.ghul

1
namespace IR.Values.Load is
2
use TypeTyped = Semantic.Types.Typed;
3
use SymbolBase = Semantic.Symbols.Symbol;
4
5
class LOCAL_ARGUMENT: 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 arguments: the CLR parameter
15
// doesn't exist inside MoveNext, so the load is
16
// redirected to the field on the state-machine frame
17
// populated by the .ctor. Plain functions take the
18
// ldarg path.
19
let field_reference = IR.Values.state_machine_field_reference(symbol);
20
21
if field_reference? then
22
context.write_line("ldarg.0");
23
context.write_line("ldfld {field_reference}");
24
return;
25
fi
26
27
context.write_line("ldarg {symbol.il_name}");
28
si
29
30
gen_address(context: IR.CONTEXT) is
31
let field_reference = IR.Values.state_machine_field_reference(symbol);
32
33
if field_reference? then
34
context.write_line("ldarg.0");
35
context.write_line("ldflda {field_reference}");
36
return;
37
fi
38
39
context.write_line("ldarga {symbol.il_name}");
40
si
41
42
to_string() -> string =>
43
"load:[{type}]({from},\"{symbol.name}\")";
44
si
45
si