aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/extension.lux
blob: cdcf0879dafbcf8752e3a5d188cabb7aedd86ab6 (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
(.`` (.`` (.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]" 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]" generation]
                 ["[0]" declaration]
                 ["[0]" analysis (.only)
                  ["[0]" type]
                  ["<[1]>" \\parser]]
                 ["[0]" synthesis (.only)
                  ["<[1]>" \\parser]]
                 [phase
                  [generation
                   (.,, (.for "JVM" (.,, (.these ["[0]" jvm
                                                  ["[1]/[0]" runtime]]))
                              (.,, (.these))))]]]]]]
             [test
              ["_" property (.only Test)]]]]
           [\\library
            ["[0]" / (.only analysis synthesis generation declaration)]])))

... Generation
(for @.old
     (these)
     
     (these
      (for @.python
           ... TODO: Remove this hack once Jython is no longer being used as the Python interpreter.
           (analysis ("dummy dum dum" phase archive [])
             (undefined))

           (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 (|>> {analysis.#Extension (symbol ..my_synthesis|synthesis)}))))))

      ... Generation
      (def my_generation|generation
        Generation
        (generation (_ phase archive [pass_through <synthesis>.any])
          (phase archive pass_through)))

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

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

      (def dummy_generation|generation
        Generation
        (generation (_ phase archive [])
          (let [[_ self] (symbol ..dummy_generation)]
            (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_generation|synthesis
        Synthesis
        (synthesis (_ phase archive [])
          (at phase.monad in {synthesis.#Extension (symbol ..dummy_generation|generation) (list)})))

      (def dummy_generation
        Analysis
        (analysis (_ phase archive [])
          (at phase.monad in {analysis.#Extension (symbol ..dummy_generation|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.lifted_analysis
                             (type.expecting .Any)
                             (analysis_phase archive expression))

             lux (declaration.lifted_analysis meta.compiler_state)

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

             generation_phase declaration.generation
             expressionG (declaration.lifted_generation
                          (generation_phase lux archive expressionS))
             
             _ (declaration.lifted_generation
                (generation.with_new_context archive unit.none
                  (do !
                    [[module_id artifact_id] (generation.context archive)
                     .let [commentary (format "Successfully installed declaration " (%.text self) "!")]
                     _ (generation.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)
                                                            sequence.empty)))
                                              @.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)))))]
                    (generation.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 [/.generation]
                   (for @.old false
                        (and (n.= expected
                                  (..my_generation expected))
                             (let [[_ expected] (symbol ..dummy_generation)]
                               (text#= expected
                                       (..dummy_generation))))))
                 (_.coverage [/.declaration]
                   true)
                 )))))