aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/extension.lux
blob: 66bf59e0e3e58b664a326b109d04620bc72ea452 (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
(.`` (.`` (.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]]]
             [meta
              ["[0]" code
               ["<[1]>" \\parser]]
              [macro
               ["[0]" template]]
              ["@" 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)]])))

(def dummy_generation "dummy generation")

(with_template [<name>]
  [(def <name>
     Text
     (`` (%.symbol (symbol (,, (template.symbol [.._ <name>]))))))]

  [my_analysis]
  [my_synthesis]
  [my_generation]
  [my_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" self phase archive [])
             (undefined))

           (these))
      
      ... Analysis
      (analysis (..my_analysis self phase archive [pass_through <code>.any])
        (phase archive pass_through))

      ... Synthesis
      (analysis (..my_synthesis self phase archive [parameters (<>.some <code>.any)])
        (let [! phase.monad]
          (|> parameters
              (monad.each ! (phase archive))
              (at ! each (|>> {analysis.#Extension self})))))

      (synthesis (..my_synthesis self phase archive [pass_through <analysis>.any])
        (phase archive pass_through))

      ... Generation
      (analysis (..my_generation self phase archive [parameters (<>.some <code>.any)])
        (let [! phase.monad]
          (|> parameters
              (monad.each ! (phase archive))
              (at ! each (|>> {analysis.#Extension self})))))

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

      (generation (..my_generation self phase archive [pass_through <synthesis>.any])
        (phase archive pass_through))

      (analysis (..dummy_generation self phase archive [])
        (at phase.monad in {analysis.#Extension self (list)}))

      (synthesis (..dummy_generation self phase archive [])
        (at phase.monad in {synthesis.#Extension self (list)}))

      (generation (..dummy_generation self phase archive [])
        (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))))

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

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

           generation_phase declaration.generation
           expressionG (declaration.lifted_generation
                        (generation_phase 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)))

      (`` ((,, (static ..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
                                    (`` ((,, (static <extension>)) expected)))))]

                       [/.analysis ..my_analysis]
                       [/.synthesis ..my_synthesis]))
                 (_.coverage [/.generation]
                   (for @.old false
                        (and (n.= expected
                                  (`` ((,, (static ..my_generation)) expected)))
                             (text#= ..dummy_generation
                                     (`` ((,, (static ..dummy_generation))))))))
                 (_.coverage [/.declaration]
                   true)
                 )))))