(;module:
lux
(lux (control monad)
(data text/format)
[meta #+ Monad "Meta/" Monad])
(luxc ["&" base]
(lang ["ls" synthesis])
["&;" analyser]
["&;" synthesizer]
(synthesizer [";S" function])
(generator ["&;" common]
["&;" primitive]
["&;" structure]
["&;" eval]
["&;" procedure]
["&;" function]
["&;" reference]
(host ["$" jvm]))))
(def: #export (generate synthesis)
(-> ls;Synthesis (Meta $;Inst))
(case synthesis
#ls;Unit
&primitive;generate-unit
(^template [ ]
( value)
( value))
([#ls;Bool &primitive;generate-bool]
[#ls;Nat &primitive;generate-nat]
[#ls;Int &primitive;generate-int]
[#ls;Deg &primitive;generate-deg]
[#ls;Frac &primitive;generate-frac]
[#ls;Text &primitive;generate-text])
(#ls;Variant tag tail? member)
(&structure;generate-variant generate tag tail? member)
(#ls;Tuple members)
(&structure;generate-tuple generate members)
(#ls;Variable var)
(if (functionS;captured? var)
(&reference;generate-captured var)
(&reference;generate-variable var))
(#ls;Function arity env body)
(&function;generate-function generate env arity body)
(#ls;Call args function)
(&function;generate-call generate function args)
(#ls;Procedure name args)
(&procedure;generate-procedure generate name args)
_
(meta;fail "Unrecognized synthesis.")))
## (def: #export (eval type code)
## (-> Type Code (Meta Top))
## (do Monad
## [analysis (&;with-expected-type leftT
## (&analyser;analyser eval code))
## #let [synthesis (&synthesizer;synthesize analysis)]
## inst (generate synthesis)]
## (&eval;eval inst)))
## (def: analyse
## &;Analyser
## (&analyser;analyser eval))
## (def: #export (generate input)
## (-> Code (Meta Unit))
## (do Monad
## [analysis (analyse input)
## #let [synthesis (&synthesizer;synthesize analysis)]]
## (generate-synthesis synthesis)))