Skip to content
← Back

src/ir/values/runtime.ghul

1
namespace IR.Values is
2
use Semantic.Types.Type
3
4
use Ghul.Pipes
5
6
// An operation the runtime provides, applied to its operands.
7
class RUNTIME: Value is
8
operation: IR.RuntimeOperation
9
operands: Collections.List[Value]
10
type: Type?
11
12
// The type an operation over a generic member is instantiated
13
// with, for an operation that has one.
14
type_argument: Type?
15
16
// An operation on a string builder is marked once, before
17
// everything it lowers to, as a call is. Every other operation is
18
// marked after its operands, which mark their own positions, as
19
// an operator is.
20
is_marked_as_call: bool =>
21
case operation
22
when IR.RuntimeOperation.NEW_STRING_BUILDER then true
23
when IR.RuntimeOperation.APPEND_TEXT then true
24
when IR.RuntimeOperation.APPEND_VALUE then true
25
when IR.RuntimeOperation.APPEND_ALIGNED_VALUE then true
26
when IR.RuntimeOperation.APPEND_FORMATTED_VALUE then true
27
when IR.RuntimeOperation.APPEND_ALIGNED_FORMATTED_VALUE then true
28
when IR.RuntimeOperation.BUILD_STRING then true
29
else false
30
esac
31
32
has_location: bool => is_marked_as_call /\ super.has_location
33
34
init(operation: IR.RuntimeOperation, operands: Collections.List[Value], type: Type?, type_argument: Type?) is
35
super.init()
36
37
self.operation = operation
38
self.operands = operands
39
self.type = type
40
self.type_argument = type_argument
41
si
42
43
init(operation: IR.RuntimeOperation, operands: Collections.List[Value], type: Type?) is
44
self.init(operation, operands, type, null)
45
si
46
47
init(operation: IR.RuntimeOperation, type: Type?) is
48
self.init(operation, Collections.LIST[Value](), type, null)
49
si
50
51
init(operation: IR.RuntimeOperation, operand: Value, type: Type?) is
52
self.init(operation, [operand]:Value, type, null)
53
si
54
55
init(operation: IR.RuntimeOperation, left: Value, right: Value, type: Type?) is
56
self.init(operation, [left, right]:Value, type, null)
57
si
58
59
accept(visitor: Visitor) is
60
visitor.visit(self)
61
si
62
63
to_string() -> string => "runtime:{operation}({operands |> join(", ")})"
64
si
65
si