(;module:
lux
(lux (control [monad #+ do])
(data [text]
text/format)
[meta "meta/" Monad])
(luxc ["&" base]
[";L" host]
(host ["$" jvm]
(jvm ["$t" type]
["$i" inst]))
(lang ["ls" synthesis]
[";L" variable #+ Variable]
(translation [";T" common]))))
(do-template [ ]
[(def: #export ( idx)
(-> Nat Text)
(|> idx nat-to-int %i (format )))]
[captured "c"]
[partial "p"]
)
(def: #export (translate-captured variable)
(-> Variable (Meta $;Inst))
(do meta;Monad
[function-class hostL;context]
(wrap (|>. ($i;ALOAD +0)
($i;GETFIELD function-class
(|> variable i.inc (i.* -1) int-to-nat captured)
commonT;$Object)))))
(def: #export (translate-local variable)
(-> Variable (Meta $;Inst))
(meta/wrap ($i;ALOAD (int-to-nat variable))))
(def: #export (translate-variable variable)
(-> Variable (Meta $;Inst))
(if (variableL;captured? variable)
(translate-captured variable)
(translate-local variable)))
(def: #export (translate-definition [def-module def-name])
(-> Ident (Meta $;Inst))
(let [bytecode-name (format def-module "/" (&;normalize-name def-name))]
(meta/wrap ($i;GETSTATIC bytecode-name commonT;value-field commonT;$Object))))