aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/generator/expr.jvm.lux
blob: 61120ef86d3deba3e615efd588344a96ce3a9317 (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
78
(;module:
  lux
  (lux (control monad
                ["ex" exception #+ exception:]
                ["p" parser])
       (data ["e" error]
             text/format)
       [meta]
       (meta ["s" syntax]))
  (luxc ["&" base]
        (lang ["ls" synthesis])
        ["&;" analyser]
        ["&;" synthesizer]
        (synthesizer [";S" function])
        (generator ["&;" common]
                   ["&;" primitive]
                   ["&;" structure]
                   ["&;" eval]
                   ["&;" procedure]
                   ["&;" function]
                   ["&;" reference]
                   [";G" case]
                   (host ["$" jvm]))))

(exception: #export Unrecognized-Synthesis)

(def: #export (generate synthesis)
  (-> ls;Synthesis (Meta $;Inst))
  (case synthesis
    (^code [])
    &primitive;generate-unit

    (^code [(~ singleton)])
    (generate singleton)

    (^template [<tag> <generator>]
      [_ (<tag> value)]
      (<generator> value))
    ([#;Bool &primitive;generate-bool]
     [#;Nat  &primitive;generate-nat]
     [#;Int  &primitive;generate-int]
     [#;Deg  &primitive;generate-deg]
     [#;Frac &primitive;generate-frac]
     [#;Text &primitive;generate-text])

    (^code ((~ [_ (#;Nat tag)]) (~ [_ (#;Bool last?)]) (~ valueS)))
    (&structure;generate-variant generate tag last? valueS)

    (^code [(~@ members)])
    (&structure;generate-tuple generate members)

    (^ [_ (#;Form (list [_ (#;Int var)]))])
    (if (functionS;captured? var)
      (&reference;generate-captured var)
      (&reference;generate-variable var))

    [_ (#;Symbol definition)]
    (&reference;generate-definition definition)

    (^code ("lux let" (~ [_ (#;Nat register)]) (~ inputS) (~ exprS)))
    (caseG;generate-let generate register inputS exprS)

    (^code ("lux case" (~ inputS) (~ pathPS)))
    (caseG;generate-case generate inputS pathPS)

    (^multi (^code ("lux function" (~ [_ (#;Nat arity)]) [(~@ environment)] (~ bodyS)))
            [(s;run environment (p;some s;int)) (#e;Success environment)])
    (&function;generate-function generate environment arity bodyS)

    (^code ("lux call" (~ functionS) (~@ argsS)))
    (&function;generate-call generate functionS argsS)

    (^code ((~ [_ (#;Text procedure)]) (~@ argsS)))
    (&procedure;generate-procedure generate procedure argsS)

    _
    (&;throw Unrecognized-Synthesis (%code synthesis))
    ))