aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/lua/primitive.jvm.lux
blob: c322e50058a2c795584ba551d12f3cfe37d3d723 (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
(.module:
  lux
  (lux (control pipe)
       (data [number]
             text/format)
       [macro "meta/" Monad<Meta>])
  (luxc (lang (host [lua #+ Lua Expression Statement]))))

(def: #export translate-bool
  (-> Bool (Meta Expression))
  (|>> %b meta/wrap))

(def: #export translate-int
  (-> Int (Meta Expression))
  (|>> %i meta/wrap))

(def: #export translate-nat
  (-> Nat (Meta Expression))
  (|>> (:! Int) %i meta/wrap))

(def: #export translate-deg
  (-> Deg (Meta Expression))
  (|>> (:! Int) %i meta/wrap))

(def: #export translate-frac
  (-> Frac (Meta Expression))
  (|>> (cond> [(f/= number.positive-infinity)]
              [(new> "math.huge")]
              
              [(f/= number.negative-infinity)]
              [(new> "(-1 * math.huge)")]
              
              [(f/= number.not-a-number)]
              [(new> "(0/0)")]
              
              ## else
              [%f])
       meta/wrap))

(def: #export translate-text
  (-> Text (Meta Expression))
  (|>> %t meta/wrap))