aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/function/field/variable/count.lux
blob: a370740d7ee3516e94e6771d8a0efa7fc8a25f5c (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
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" io]
    ["[0]" try (.use "[1]#[0]" functor)]
    ["[0]" function]]
   [data
    ["[0]" bit (.use "[1]#[0]" equivalence)]
    [collection
     ["[0]" list]]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["n" nat (.use "[1]#[0]" equivalence)]]]
   [meta
    ["[0]" location]
    [compiler
     [target
      [jvm
       ["!" bytecode]
       ["[0]" type]]]
     [meta
      ["[0]" archive]]]]
   [test
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" / (.only)
   [///
    [constant
     ["[0]" arity]]
    [//
     ["[0]" abstract]
     [///
      ["[0]" jvm (.only)
       ["[0]" host]
       ["[0]" runtime]
       ["[0]" value]
       ["[0]" complex
        ["[1]T" \\test]]
       [///
        ["[0]" extension]
        [//
         ["[0]" phase]
         ["[0]" synthesis]
         ["[0]" translation]]]]]]]]])

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [module (random.lower_cased 1)

         expected_bit random.bit
         expected_i64 random.i64

         .let [extender (is extension.Extender
                            (function (_ _)
                              (undefined)))
               next (jvm.translate extender complexT.lux)
               @ [module 0 0]]

         arity (of ! each (|>> (n.% arity.maximum) (n.max arity.minimum)) random.nat)
         partial_application (of ! each (n.% arity) random.nat)])
      (all _.and
           (_.coverage [/.field]
             (when /.field
               "" false
               _ true))
           (_.coverage [/.type]
             (same? arity.type /.type))
           (_.coverage [/.initial]
             (let [[_ host] (io.run! host.host)]
               (|> (all !.composite
                        /.initial
                        !.i2l
                        (value.boxed type.long))
                   [{.#None}]
                   (of host evaluate)
                   (try#each (|>> (as Nat) (n#= 0)))
                   (try.else false))))
           (_.coverage [/.value]
             (let [fresh_abstraction!
                   (|> (do try.monad
                         [[_ archive] (archive.reserve "" archive.empty)
                          [_ archive] (archive.reserve module archive)
                          .let [[_ host] (io.run! host.host)
                                state (is runtime.State
                                          (translation.state host module))]]
                         (<| (phase.result state)
                             (do phase.monad
                               [_ (translation.set_buffer translation.empty_buffer)
                                it (next archive (<| (synthesis.function/abstraction @)
                                                     [(list) arity (synthesis.i64 @ expected_i64)]))]
                               (in (|> (all !.composite
                                            it
                                            /.value
                                            !.i2l
                                            (value.boxed type.long))
                                       [{.#None}]
                                       (of host evaluate)
                                       (try#each (|>> (as Nat) (n#= 0)))
                                       (try.else false))))))
                       (try.else false))

                   partial_application!
                   (|> (do try.monad
                         [[_ archive] (archive.reserve "" archive.empty)
                          [_ archive] (archive.reserve module archive)
                          .let [[_ host] (io.run! host.host)
                                state (is runtime.State
                                          (translation.state host module))]]
                         (<| (phase.result state)
                             (do phase.monad
                               [_ (translation.set_buffer translation.empty_buffer)
                                it (next archive (<| (synthesis.function/apply @)
                                                     [(<| (synthesis.function/abstraction @)
                                                          [(list) arity (synthesis.i64 @ expected_i64)])
                                                      (list.repeated partial_application (synthesis.bit @ expected_bit))]))]
                               (in (|> (all !.composite
                                            it
                                            (!.checkcast abstract.class)
                                            /.value
                                            !.i2l
                                            (value.boxed type.long))
                                       [{.#None}]
                                       (of host evaluate)
                                       (try#each (|>> (as Nat) (n#= partial_application)))
                                       (try.else false))))))
                       (try.else false))]
               (and fresh_abstraction!
                    partial_application!)))
           )))