aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/js/primitive.jvm.lux
blob: 270fa510d1cf3a6e15bdb20b34f02d57c0bea591 (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.left-shift +32 +1)))

(def: #export (translate-nat value)
  (-> Nat (Meta Expression))
  (let [high (|> value
                 (bit.logical-right-shift +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))