Skip to content
← Back

src/ir/values/call/instance.ghul

1
namespace IR.Values.Call is
2
use TypeTyped = Semantic.Types.Typed
3
use Semantic.Types.Type
4
5
class INSTANCE: Value, TypeTyped is
6
is_state_changing_call: bool => !function.is_store_free
7
is_receiver_interior_call: bool => function.writes_only_receiver_interior
8
from: Value
9
function: Semantic.Symbols.Function
10
arguments: Collections.List[Value]
11
type: Type
12
13
init(from: Value, function: Semantic.Symbols.Function, arguments: Collections.List[Value], type: Type?) is
14
super.init()
15
16
self.from = from
17
self.function = function
18
self.arguments = arguments
19
20
if type? then
21
self.type = type
22
else
23
self.type = function.return_type!
24
fi
25
26
si
27
28
// Decided when the call is lowered rather than when it is built:
29
// whether the function can be overridden is not settled until
30
// the inheritance passes have run.
31
dispatch: IR.Dispatch =>
32
if isa CONSTRAINED(from) then
33
IR.Dispatch.CONSTRAINED
34
elif from.is_super \/ !function.is_virtual then
35
IR.Dispatch.DIRECT
36
elif let owner: Semantic.Symbols.Classy = function.owner /\ owner.is_trait then
37
IR.Dispatch.INTERFACE
38
else
39
IR.Dispatch.VIRTUAL
40
fi
41
42
accept(visitor: Visitor) is
43
visitor.visit(self)
44
si
45
46
to_string() -> string =>
47
"instance-call:[{type}]({from},\"{function.name}\",{arguments})"
48
si
49
50
si