Skip to content
← Back

src/ir/values/literal/bigint.ghul

1
namespace IR.Values.Literal is
2
use TypeTyped = Semantic.Types.Typed
3
use Semantic.Types.Type
4
5
// System.Numerics.BigInteger has no load instruction, so a `bigint`
6
// literal is built at run time from its value, the way a decimal
7
// literal is built from its decomposition. A magnitude that fits in
8
// a long goes through the `BigInteger(int64)` constructor; anything
9
// wider goes through `BigInteger.Parse` on the digits, which are
10
// written out in decimal whatever radix the source used.
11
class BIGINT: Value, TypeTyped is
12
// The magnitude in decimal digits. A sign comes from a wrapping
13
// unary `-`, so this is never negative.
14
value: string
15
type: Type
16
as_long: long
17
fits_long: bool
18
19
is_lightweight_pure: bool => true
20
21
init(value: string, type: Type, as_long: long, fits_long: bool) is
22
super.init()
23
24
self.value = value
25
self.type = type
26
self.as_long = as_long
27
self.fits_long = fits_long
28
si
29
30
accept(visitor: Visitor) is
31
visitor.visit(self)
32
si
33
34
to_string() -> string =>
35
"literal:[{type}]({value}n)"
36
si
37
si