Skip to content
← Back

src/ir/values/call/innate.ghul

1
namespace IR.Values.Call is
2
use TypeTyped = Semantic.Types.Typed
3
use Semantic.Types.Type
4
5
class INNATE: Value, TypeTyped is
6
function: Semantic.Symbols.InnateFunction
7
from: Value?
8
arguments: Collections.List[Value]
9
type: Type
10
is_lowered: bool
11
12
_lowering: Value?
13
14
/// The values `lower` produced, or null where it has not run.
15
lowering: Value? => _lowering
16
17
actual_operation: string? public
18
19
innate_name: string => function.innate_name
20
type_name: string => innate_name.substring(0, innate_name.index_of('.'))
21
op_name: string => innate_name.substring(innate_name.index_of('.') + 1)
22
23
init(
24
function: Semantic.Symbols.InnateFunction,
25
from: Value?,
26
arguments: Collections.List[Value],
27
type: Type?) is
28
super.init()
29
30
self.function = function
31
self.from = from
32
self.arguments = arguments
33
34
if type? then
35
self.type = type
36
else
37
self.type = function.return_type!
38
fi
39
si
40
41
lower() -> Value is
42
// A host operation has no CIL form: a backend that provides host
43
// imports calls the import itself.
44
if IR.WasmGC.WASMGC_IMPORTS.is_host(innate_name) then
45
return self
46
fi
47
48
assert !is_lowered else "innate operation is already lowered: {self}"
49
50
is_lowered = true
51
52
let result = IR.Values.BLOCK(type)
53
54
IoC.CONTAINER.instance.innate_operation_generator.lower(self, result)
55
56
_lowering = result
57
58
return result
59
si
60
61
accept(visitor: Visitor) is
62
visitor.visit(self)
63
si
64
65
to_string() -> string =>
66
"innate:[{type}](\"{function.name}\",{from},{arguments})"
67
si
68
si