aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/extension.lux
blob: 64905a9f2f226db4dd0149441195cf66fbae3f15 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
(.`` (.`` (.require
           [library
            [lux (.except)
             ["[0]" debug]
             [abstract
              ["[0]" monad (.only do)]]
             [control
              ["<>" parser]
              ["[0]" try (.use "[1]#[0]" functor)]]
             [data
              ["[0]" product]
              ["[0]" binary (.only)
               ["[1]F" \\format]]
              ["[0]" text (.use "[1]#[0]" equivalence)
               ["%" \\format (.only format)]]
              [collection
               ["[0]" sequence]
               ["[0]" list (.use "[1]#[0]" functor)]]]
             [math
              ["[0]" random]
              [number
               ["n" nat]]]
             ["[0]" meta (.only)
              ["[0]" location]
              ["[0]" code
               ["<[1]>" \\parser]]
              ["@" target (.only)
               ["[0]" js]
               ["[0]" python]
               ["[0]" lua]
               ["[0]" ruby]
               ["[0]" php]
               ["[0]" scheme]
               (.,, (.for "JVM" (.,, (.these ["[0]" jvm
                                              ["[1]" bytecode]
                                              ["[0]" class]
                                              ["[0]" version]
                                              [encoding
                                               ["[0]" name]]]))
                          (.,, (.these))))]
              [compiler
               ["[0]" phase]
               [meta
                [archive
                 ["[0]" unit]]]
               [language
                [lux
                 ["[0]" translation]
                 ["[0]" declaration]
                 ["[0]" analysis (.only)
                  ["[0]" type]
                  ["<[1]>" \\parser]]
                 ["[0]" synthesis (.only)
                  ["<[1]>" \\parser]]
                 [phase
                  [translation
                   (.,, (.for "JVM" (.,, (.these ["[0]" jvm
                                                  ["[1]/[0]" runtime]]))
                              (.,, (.these))))]]]]]]
             [test
              ["_" property (.only Test)]]]]
           [\\library
            ["[0]" / (.only analysis synthesis translation declaration)]])))

... Translation
(for @.old
     (these)
     
     (these
      ... Analysis
      (def my_analysis
        Analysis
        (analysis (_ phase archive [pass_through <code>.any])
          (phase archive pass_through)))

      ... Synthesis
      (def my_synthesis|synthesis
        Synthesis
        (synthesis (_ phase archive [pass_through <analysis>.any])
          (phase archive pass_through)))

      (def my_synthesis
        Analysis
        (analysis (_ phase archive [parameters (<>.some <code>.any)])
          (let [! phase.monad]
            (|> parameters
                (monad.each ! (phase archive))
                (at ! each (|>> (is (List analysis.Analysis))
                                {analysis.#Extension (symbol ..my_synthesis|synthesis)}
                                [location.dummy]
                                (is analysis.Analysis)))))))

      ... Translation
      (def my_translation|translation
        Translation
        (translation (_ phase archive [pass_through <synthesis>.any])
          (phase archive pass_through)))

      (def my_translation|synthesis
        Synthesis
        (synthesis (_ phase archive [parameters (<>.some <analysis>.any)])
          (let [! phase.monad]
            (|> parameters
                (monad.each ! (phase archive))
                (at ! each (|>> {synthesis.#Extension (symbol ..my_translation|translation)}
                                [location.dummy]
                                (is synthesis.Synthesis)))))))

      (def my_translation
        Analysis
        (analysis (_ phase archive [parameters (<>.some <code>.any)])
          (let [! phase.monad]
            (|> parameters
                (monad.each ! (phase archive))
                (at ! each (|>> (is (List analysis.Analysis))
                                {analysis.#Extension (symbol ..my_translation|synthesis)}
                                [location.dummy]
                                (is analysis.Analysis)))))))

      (def dummy_translation|translation
        Translation
        (translation (_ phase archive [])
          (let [[_ self] (symbol ..dummy_translation)]
            (at phase.monad in
                (for @.jvm (jvm.string self)
                     @.js (js.string self)
                     @.python (python.unicode self)
                     @.lua (lua.string self)
                     @.ruby (ruby.string self)
                     @.php (php.string self)
                     @.scheme (scheme.string self))))))

      (def dummy_translation|synthesis
        Synthesis
        (synthesis (_ phase archive [])
          (at phase.monad in (is synthesis.Synthesis
                                 [location.dummy {synthesis.#Extension (symbol ..dummy_translation|translation) (list)}]))))

      (def dummy_translation
        Analysis
        (analysis (_ phase archive [])
          (at phase.monad in (is analysis.Analysis
                                 [location.dummy {analysis.#Extension (symbol ..dummy_translation|synthesis) (list)}]))))

      ... Declaration
      (def my_declaration
        Declaration
        (declaration (_ phase archive [expression <code>.any])
          (do [! phase.monad]
            [.let [[_ self] (symbol ..my_declaration)]
             analysis_phase declaration.analysis
             expressionA (<| declaration.of_analysis
                             (type.expecting .Any)
                             (analysis_phase archive expression))

             lux (declaration.of_analysis meta.compiler_state)

             synthesis_phase declaration.synthesis
             expressionS (declaration.of_synthesis
                          (synthesis_phase lux archive expressionA))

             translation_phase declaration.translation
             expressionG (declaration.of_translation
                          (translation_phase lux archive expressionS))
             
             _ (declaration.of_translation
                (translation.with_new_context archive unit.none
                  (do !
                    [[module_id artifact_id] (translation.context archive)
                     .let [commentary (format "Successfully installed declaration " (%.text self) "!")]
                     _ (translation.save! artifact_id {.#None}
                                          (for @.jvm (let [$class (jvm/runtime.class_name [module_id artifact_id])]
                                                       (<| [$class]
                                                           (try.else (binary.empty 0))
                                                           (try#each (binaryF.result class.format))
                                                           (class.class version.v6_0 class.public
                                                             (name.internal $class)
                                                             {.#None}
                                                             (name.internal "java.lang.Object")
                                                             (list)
                                                             (list)
                                                             (list)
                                                             (list))))
                                               @.js (js.comment commentary
                                                      (js.statement (js.string commentary)))
                                               @.python (python.comment commentary
                                                          (python.statement (python.string commentary)))
                                               @.lua (lua.comment commentary
                                                       (lua.statement expressionG))
                                               @.ruby (ruby.comment commentary
                                                        (ruby.statement (ruby.string commentary)))))]
                    (translation.log! commentary))))]
            (in declaration.no_requirements))))

      (..my_declaration (n.* 2 3))
      ))

(def .public test
  Test
  (<| (_.covering /._)
      (do random.monad
        [expected random.nat]
        (`` (all _.and
                 (,, (with_template [<macro> <extension>]
                       [(_.coverage [<macro>]
                          (for @.old false
                               (n.= expected
                                    (<extension> expected))))]

                       [/.analysis ..my_analysis]
                       [/.synthesis ..my_synthesis]))
                 (_.coverage [/.translation]
                   (for @.old false
                        (and (n.= expected
                                  (..my_translation expected))
                             (let [[_ expected] (symbol ..dummy_translation)]
                               (text#= expected
                                       (..dummy_translation))))))
                 (_.coverage [/.declaration]
                   true)
                 )))))