aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/js/primitive.jvm.lux
blob: 753f1ce45ded153a733ad1509d99765bb4e6db4a (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
(.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-int value)
  (-> Int (Meta Expression))
  (let [high (|> value (bit.logical-right-shift +32) %i)
        low (|> value (bit.and low-mask) %i)]
    (meta/wrap (format runtimeT.int//new "(" high "," low ")"))))

(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))