aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/generator/primitive.jvm.lux
blob: a63aa859665e12fec56c34dc45a48dd9dd5a2b84 (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
(;module:
  lux
  (lux (control monad)
       (data text/format)
       [macro #+ Monad<Lux> "Lux/" Monad<Lux>])
  (luxc ["&" base]
        (lang ["la" analysis]
              ["ls" synthesis])
        ["&;" analyser]
        ["&;" synthesizer]
        (generator ["&;" common]
                   (host ["$" jvm]
                         (jvm ["$i" inst]
                              ["$t" type]))))
  [../runtime])

(def: #export generate-unit
  (Lux $;Inst)
  (Lux/wrap ($i;string ../runtime;unit)))

(def: #export (generate-bool value)
  (-> Bool (Lux $;Inst))
  (Lux/wrap ($i;GETSTATIC "java.lang.Boolean"
                          (if value "TRUE" "FALSE")
                          ($t;class "java.lang.Boolean" (list)))))

(do-template [<name> <type> <load> <wrap>]
  [(def: #export (<name> value)
     (-> <type> (Lux $;Inst))
     (Lux/wrap (|>. (<load> value) <wrap>)))]

  [generate-nat  Nat  (|>. (:! Int) $i;long) ($i;wrap #$;Long)]
  [generate-int  Int  $i;long ($i;wrap #$;Long)]
  [generate-deg  Deg  (|>. (:! Int) $i;long) ($i;wrap #$;Long)]
  [generate-frac Frac $i;double ($i;wrap #$;Double)]
  [generate-text Text $i;string id]
  )