blob: 2e1bf83895bccf3ace772fddd5ec015184493c51 (
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 (n/dec (bit.shift-left +32 +1)))
(def: #export (translate-nat value)
(-> Nat (Meta Expression))
(let [high (|> value
(bit.shift-right +32)
nat-to-int %i)
low (|> value
(bit.and low-mask)
nat-to-int %i)]
(meta/wrap (format runtimeT.int//new "(" high "," low ")"))))
(def: #export translate-int
(-> Int (Meta Expression))
(|>> int-to-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))
|