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

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

(def: #export (generate-bool value)
  (-> Bool (Meta $;Inst))
  (Meta/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> (Meta $;Inst))
     (Meta/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]
  )