aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js.lux
blob: 61119e4730fb98dd625add8d1423dbf2e76a0704 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
(.module:
  [library
   [lux #*
    [abstract
     [monad (#+ do)]]
    [control
     ["." exception (#+ exception:)]]
    [target
     ["_" js]]]]
  ["." / #_
   [runtime (#+ Phase Phase!)]
   ["#." primitive]
   ["#." structure]
   ["#." reference]
   ["#." case]
   ["#." loop]
   ["#." function]
   ["/#" // #_
    ["#." reference]
    ["/#" // #_
     ["#." extension]
     ["/#" // #_
      [analysis (#+)]
      ["." synthesis]
      ["//#" /// #_
       ["#." phase ("#\." monad)]
       [reference (#+)
        [variable (#+)]]]]]]])

(def: (statement expression archive synthesis)
  Phase!
  (case synthesis
    (^template [<tag>]
      [(^ (<tag> value))
       (//////phase\each _.return (expression archive synthesis))])
    ([synthesis.bit]
     [synthesis.i64]
     [synthesis.f64]
     [synthesis.text]
     [synthesis.variant]
     [synthesis.tuple]
     [#synthesis.Reference]
     [synthesis.branch/get]
     [synthesis.function/apply]
     [#synthesis.Extension])

    (^ (synthesis.branch/case case))
    (/case.case! statement expression archive case)

    (^ (synthesis.branch/let let))
    (/case.let! statement expression archive let)

    (^ (synthesis.branch/if if))
    (/case.if! statement expression archive if)

    (^ (synthesis.loop/scope scope))
    (/loop.scope! statement expression archive scope)

    (^ (synthesis.loop/recur updates))
    (/loop.recur! statement expression archive updates)

    (^ (synthesis.function/abstraction abstraction))
    (//////phase\each _.return (/function.function statement expression archive abstraction))
    ))

(exception: .public cannot_recur_as_an_expression)

(def: (expression archive synthesis)
  Phase
  (case synthesis
    (^template [<tag> <generator>]
      [(^ (<tag> value))
       (//////phase\in (<generator> value))])
    ([synthesis.bit  /primitive.bit]
     [synthesis.i64  /primitive.i64]
     [synthesis.f64  /primitive.f64]
     [synthesis.text /primitive.text])

    (^ (synthesis.variant variantS))
    (/structure.variant expression archive variantS)

    (^ (synthesis.tuple members))
    (/structure.tuple expression archive members)

    (#synthesis.Reference value)
    (//reference.reference /reference.system archive value)

    (^ (synthesis.branch/case case))
    (/case.case ..statement expression archive case)

    (^ (synthesis.branch/let let))
    (/case.let expression archive let)

    (^ (synthesis.branch/if if))
    (/case.if expression archive if)

    (^ (synthesis.branch/get get))
    (/case.get expression archive get)

    (^ (synthesis.loop/scope scope))
    (/loop.scope ..statement expression archive scope)

    (^ (synthesis.loop/recur updates))
    (//////phase.except ..cannot_recur_as_an_expression [])

    (^ (synthesis.function/abstraction abstraction))
    (/function.function ..statement expression archive abstraction)

    (^ (synthesis.function/apply application))
    (/function.apply expression archive application)

    (#synthesis.Extension extension)
    (///extension.apply archive expression extension)))

(def: .public generate
  Phase
  ..expression)