blob: 6b6c68fde8564f3a3bf953b6885d1813fcb9761f (
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
(;module:
lux
(lux (control monad)
(data text/format)
[macro #+ Monad<Lux> "Lux/" Monad<Lux>])
(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 (Lux $;Inst))
(case synthesis
#ls;Unit
&primitive;generate-unit
(^template [<tag> <generator>]
(<tag> value)
(<generator> 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)
_
(macro;fail "Unrecognized synthesis.")))
## (def: #export (eval type code)
## (-> Type Code (Lux Top))
## (do Monad<Lux>
## [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 (Lux Unit))
## (do Monad<Lux>
## [analysis (analyse input)
## #let [synthesis (&synthesizer;synthesize analysis)]]
## (generate-synthesis synthesis)))
|