(;module:
lux
(lux (control [monad #+ do])
(data text/format
(coll [list]))
[meta #+ Monad "Meta/" Monad]
[host #+ do-to])
(luxc ["&" base]
(lang ["la" analysis]
["ls" synthesis])
["&;" analyser]
["&;" synthesizer]
(generator ["&;" common]
(host ["$" jvm]
(jvm ["$t" type]
["$d" def]
["$i" inst]))))
[../runtime])
(def: $Object $;Type ($t;class "java.lang.Object" (list)))
(def: #export (generate-tuple generate members)
(-> (-> ls;Synthesis (Meta $;Inst)) (List ls;Synthesis) (Meta $;Inst))
(do Monad
[#let [size (list;size members)]
_ (&;assert "Cannot generate tuples with less than 2 elements."
(n.>= +2 size))
membersI (|> members
list;enumerate
(monad;map @ (function [[idx member]]
(do @
[memberI (generate member)]
(wrap (|>. $i;DUP
($i;int (nat-to-int idx))
memberI
$i;AASTORE)))))
(:: @ map $i;fuse))]
(wrap (|>. ($i;int (nat-to-int size))
($i;array $Object)
membersI))))
(def: (flagI tail?)
(-> Bool $;Inst)
(if tail?
($i;string "")
$i;NULL))
(def: #export (generate-variant generate tag tail? member)
(-> (-> ls;Synthesis (Meta $;Inst)) Nat Bool ls;Synthesis (Meta $;Inst))
(do Monad
[memberI (generate member)]
(wrap (|>. ($i;int (nat-to-int tag))
(flagI tail?)
memberI
($i;INVOKESTATIC ../runtime;runtime-class
"variant_make"
($t;method (list $t;int $Object $Object)
(#;Some ($t;array +1 $Object))
(list))
false)))))