aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/generator/reference.jvm.lux
blob: 9af5111670cdd1993dc8927d7d4f995860cf56b3 (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
(;module:
  lux
  (lux (control [monad #+ do])
       (data text/format)
       [meta "meta/" Monad<Meta>])
  (luxc ["&" base]
        (host ["$" jvm]
              (jvm ["$t" type]
                   ["$i" inst]))
        (lang ["ls" synthesis]
              [";L" variable #+ Variable])
        (generator [";G" common]
                   [";G" function])))

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

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

(def: #export (generate-definition [def-module def-name])
  (-> Ident (Meta $;Inst))
  (let [bytecode-name (format def-module "/" (&;normalize-name def-name))]
    (meta/wrap ($i;GETSTATIC bytecode-name commonG;value-field commonG;$Object))))