Skip to content
← Back

src/ir/values/load/instance_anonymous_function.ghul

1
namespace IR.Values.Load is
2
use TypeTyped = Semantic.Types.Typed
3
use Semantic.Types.Type
4
use SymbolBase = Semantic.Symbols.Symbol
5
6
// The cast to the symbol's expected kind is a checked construction
7
// invariant: the caller only ever builds this value with a symbol of
8
// that kind, so a throw here means the invariant broke elsewhere.
9
@suppress("cast-may-throw")
10
class INSTANCE_ANONYMOUS_FUNCTION: SYMBOL, TypeTyped is
11
is_consumable: bool => true
12
13
func_type: Type
14
15
// The constructed delegate is what this load yields, which is
16
// the target delegate type when the literal was compiled for
17
// one rather than the closure's own function type.
18
type: Type => func_type
19
20
has_address: bool => false
21
22
init(symbol: SymbolBase, func_type: Type) is
23
super.init(null, symbol)
24
25
26
self.func_type = func_type
27
si
28
29
gen(context: IR.CONTEXT) is
30
let body = context.current_srm_body_emitter!
31
body.ldarg(0)
32
body.load_function_pointer(
33
context.resolve_call_target(cast Semantic.Symbols.Function(symbol)))
34
body.new_object(context.resolve_delegate_constructor(func_type))
35
si
36
37
to_string() -> string =>
38
"load:[{type}]({from},\"{symbol.name}\")"
39
si
40
41
si