Skip to content
← Back

src/ir/values/call/closure.ghul

1
namespace IR.Values.Call is
2
use TypeTyped = Semantic.Types.Typed
3
use Semantic.Types.Type
4
5
class CLOSURE: Value, TypeTyped is
6
// Invoking a function value can run anything — except through
7
// a pure function type, whose slots only admit store-free
8
// values.
9
is_state_changing_call: bool => !(func_type? /\ func_type.is_pure_function)
10
from: Value
11
type: Type
12
13
is_action: bool
14
func_type: Type?
15
arguments: Collections.List[Value]
16
17
init(
18
from: Value,
19
type: Type,
20
is_action: bool,
21
func_type: Type,
22
arguments: Collections.List[Value]
23
) is
24
super.init()
25
26
self.from = from
27
self.type = type
28
self.is_action = is_action
29
self.func_type = func_type
30
self.arguments = arguments
31
si
32
33
gen(context: IR.CONTEXT) is
34
// Placeholder-invariant backstop: a function type still
35
// carrying an inference sentinel means inference never
36
// settled and no upstream diagnostic reported it. Encoding
37
// the signature would fail inside the emitter as an opaque
38
// internal error, so report a located diagnostic here and
39
// leave the body unemitted — the compile fails either way,
40
// but one of them tells the user what went wrong.
41
if context.contains_sentinel(func_type) then
42
context.report_unresolved_type(location, func_type!)
43
return
44
fi
45
46
gen(from, context)
47
48
let count mut = 0
49
for a in arguments do
50
gen(a, context)
51
52
count = count + 1
53
od
54
55
let body = context.current_srm_body_emitter!
56
body.call_virtual(
57
context.resolve_delegate_invoke(func_type!, count, is_action))
58
si
59
60
to_string() -> string =>
61
"closure-call:[{type}]({from}{arguments})"
62
si
63
si