aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/generator/expr.jvm.lux
blob: 32f8bde31313de7c3dcd271304bfc9c6173335ce (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
(;module:
  lux
  (lux (control monad)
       [macro #+ Monad<Lux> "Lux/" Monad<Lux>])
  (luxc ["&" base]
        (lang ["ls" synthesis])
        ["&;" analyser]
        ["&;" synthesizer]
        (generator ["&;" common]
                   ["&;" primitive]
                   ["&;" structure]
                   ["&;" eval]
                   ["&;" procedure]
                   (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;Real &primitive;generate-real]
     [#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;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)))