blob: 305f46adf107c776c356bb16bed5d4592ef0fe22 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
(.module:
lux
(lux (control pipe)
(data [bit]
[number]
text/format)
[macro "meta/" Monad<Meta>])
[//]
(// [".T" runtime])
(luxc (lang (host [js #+ JS Expression Statement]))))
(def: #export translate-bool
(-> Bool (Meta Expression))
(|>> %b meta/wrap))
(def: low-mask Nat (dec (bit.left-shift +32 +1)))
(def: #export (translate-nat value)
(-> Nat (Meta Expression))
(let [high (|> value
(bit.logical-right-shift +32)
.int %i)
low (|> value
(bit.and low-mask)
.int %i)]
(meta/wrap (format runtimeT.int//new "(" high "," low ")"))))
(def: #export translate-int
(-> Int (Meta Expression))
(|>> .nat translate-nat))
(def: deg-to-nat
(-> Deg Nat)
(|>> (:! Nat)))
(def: #export translate-deg
(-> Deg (Meta Expression))
(|>> deg-to-nat translate-nat))
(def: #export translate-frac
(-> Frac (Meta Expression))
(|>> (cond> [(f/= number.positive-infinity)]
[(new> "Infinity")]
[(f/= number.negative-infinity)]
[(new> "-Infinity")]
[(f/= number.not-a-number)]
[(new> "NaN")]
## else
[%f])
meta/wrap))
(def: #export translate-text
(-> Text (Meta Expression))
(|>> %t meta/wrap))
|