aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/extension.lux
blob: 3421ba12ec2832ecd0a5d650d798f66a155f6378 (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
(.module:
  [library
   [lux "*"
    ["." debug]
    ["@" target
     ["." jvm]
     ["." js]
     ["." python]
     ["." lua]
     ["." ruby]
     ["." php]
     ["." scheme]]
    [abstract
     ["." monad {"+" [do]}]]
    [control
     ["." try]
     ["<>" parser
      ["<.>" code]
      ["<.>" analysis]
      ["<.>" synthesis]]]
    [data
     ["." product]
     ["." text ("#\." equivalence)
      ["%" format {"+" [format]}]]
     [collection
      ["." row]
      ["." list ("#\." functor)]]]
    [math
     ["." random]
     [number
      ["n" nat]]]
    [tool
     [compiler
      ["." phase]
      [language
       [lux
        ["." analysis]
        ["." synthesis]
        ["." directive]
        [phase
         [analysis
          ["." type]]]]]]]
    ["_" test {"+" [Test]}]]]
  [\\library
   ["." / {"+" [analysis: synthesis: generation: directive:]}]])

(def: my_analysis "my analysis")
(def: my_synthesis "my synthesis")
(def: my_generation "my generation")
(def: dummy_generation "dummy generation")
(def: my_directive "my directive")

... Generation
(for {@.old
      (as_is)}
     
     (as_is
      ... 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))
              (\ ! 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))
              (\ ! each (|>> (#analysis.Extension self))))))

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

      (generation: (..my_generation self phase archive [pass_through <synthesis>.any])
        (for {@.jvm
              (\ phase.monad each (|>> #jvm.Embedded row.row)
                 (phase archive pass_through))}
             (phase archive pass_through)))

      (analysis: (..dummy_generation self phase archive [])
        (\ phase.monad in (#analysis.Extension self (list))))

      (synthesis: (..dummy_generation self phase archive [])
        (\ phase.monad in (#synthesis.Extension self (list))))

      (generation: (..dummy_generation self phase archive [])
        (\ phase.monad in
           (for {@.jvm
                 (row.row (#jvm.Constant (#jvm.LDC (#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)})))

      ... Directive
      (directive: (..my_directive self phase archive [parameters (<>.some <code>.any)])
        (do phase.monad
          [.let [_ (debug.log! (format "Successfully installed directive " (%.text self) "!"))]]
          (in directive.no_requirements)))

      (`` ((~~ (static ..my_directive))))
      ))

(def: .public test
  Test
  (<| (_.covering /._)
      (do random.monad
        [expected random.nat]
        (`` ($_ _.and
                (~~ (template [<macro> <extension>]
                      [(_.cover [<macro>]
                                (for {@.old
                                      false}
                                     (n.= expected
                                          (`` ((~~ (static <extension>)) expected)))))]

                      [/.analysis: ..my_analysis]
                      [/.synthesis: ..my_synthesis]))
                (_.cover [/.generation:]
                         (for {@.old
                               false}
                              (and (n.= expected
                                        (`` ((~~ (static ..my_generation)) expected)))
                                   (text\= ..dummy_generation
                                           (`` ((~~ (static ..dummy_generation))))))))
                (_.cover [/.directive:]
                         true)
                )))))