Skip to content
← Back

src/ir/values/decimal_convert.ghul

1
namespace IR.Values is
2
use Semantic.Types.Type
3
4
// A call to one of `System.Decimal`'s static methods, with its
5
// arguments already on the stack. Decimal has no IL opcodes of its
6
// own, so its arithmetic and its comparisons are all calls.
7
class DECIMAL_CALL: Value is
8
type: Type
9
method_name: string
10
parameter_types: Collections.List[Type]
11
12
init(type: Type, method_name: string, parameter_types: Collections.List[Type]) is
13
super.init()
14
15
self.type = type
16
self.method_name = method_name
17
self.parameter_types = parameter_types
18
si
19
20
gen(context: IR.CONTEXT) is
21
let body = context.current_srm_body_emitter!
22
body.call(
23
context.resolve_decimal_method(method_name, parameter_types, type))
24
si
25
26
to_string() -> string => "decimal-call:[{type}]({method_name})"
27
si
28
29
// A conversion between decimal and another scalar: the operand,
30
// then the call that converts it.
31
class DECIMAL_CONVERT: Value is
32
type: Type
33
value: Value
34
method_name: string
35
parameter_type: Type
36
37
init(
38
type: Type,
39
value: Value,
40
method_name: string,
41
parameter_type: Type
42
) is
43
super.init()
44
45
self.type = type
46
self.value = value
47
self.method_name = method_name
48
self.parameter_type = parameter_type
49
si
50
51
gen(context: IR.CONTEXT) is
52
gen(value, context)
53
54
let parameter_types = Collections.LIST[Type]()
55
56
parameter_types.add(parameter_type)
57
58
gen(DECIMAL_CALL(type, method_name, parameter_types), context)
59
si
60
61
to_string() -> string =>
62
"decimal-convert:[{type}]({value})"
63
si
64
si