aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/generator/reference.jvm.lux
blob: 28c9360367353a3cd285e7646cafa26ffab36429 (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
(;module:
  lux
  (lux (control [monad #+ do])
       (data text/format)
       [macro "lux/" Monad<Lux>])
  (luxc (lang ["ls" synthesis])
        (generator [";G" common]
                   [";G" function]
                   (host ["$" jvm]
                         (jvm ["$t" type]
                              ["$i" inst])))))

(def: $Object $;Type ($t;class "java.lang.Object" (list)))

(def: #export (generate-captured variable)
  (-> ls;Variable (Lux $;Inst))
  (do macro;Monad<Lux>
    [function-class commonG;function]
    (wrap (|>. ($i;ALOAD +0)
               ($i;GETFIELD function-class
                            (|> variable i.inc (i.* -1) int-to-nat functionG;captured)
                            $Object)))))

(def: #export (generate-variable variable)
  (-> ls;Variable (Lux $;Inst))
  (lux/wrap ($i;ALOAD (int-to-nat variable))))