blob: ba90a00e3c674f77fbeccc9becc4cec9bfee3ddc (
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
|
(;module:
lux
(lux [io]
(control [monad #+ do]
pipe)
(data [maybe]
["e" error]
[bit]
[bool "bool/" Eq<Bool>]
[number "int/" Number<Int> Codec<Text,Int>]
[text "text/" Eq<Text>]
text/format
(coll [list]))
["r" math/random "r/" Monad<Random>]
[meta #+ Monad<Meta>]
[host]
test)
(luxc (lang ["ls" synthesis])
[analyser]
[synthesizer]
(generator ["@" expr]
["@;" eval]
["@;" runtime]
["@;" common]))
(test/luxc common))
(context: "Conversions [Part 1]"
[int-sample (|> r;int (:: @ map (i.% 128)))
#let [frac-sample (int-to-frac int-sample)]]
(with-expansions [<2step> (do-template [<step1> <step2> <tag> <sample> <cast> <test>]
[(test (format <step1> " / " <step2>)
(|> (do meta;Monad<Meta>
[sampleI (@;generate (|> (<tag> <sample>)
(list) (#ls;Procedure <step1>)
(list) (#ls;Procedure <step2>)))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success valueG)
(<test> <sample> (:! <cast> valueG))
(#e;Error error)
false)))]
["jvm convert double-to-float" "jvm convert float-to-double" #ls;Frac frac-sample Frac f.=]
["jvm convert double-to-int" "jvm convert int-to-double" #ls;Frac frac-sample Frac f.=]
["jvm convert double-to-long" "jvm convert long-to-double" #ls;Frac frac-sample Frac f.=]
["jvm convert long-to-float" "jvm convert float-to-long" #ls;Int int-sample Int i.=]
["jvm convert long-to-int" "jvm convert int-to-long" #ls;Int int-sample Int i.=]
["jvm convert long-to-short" "jvm convert short-to-long" #ls;Int int-sample Int i.=]
["jvm convert long-to-byte" "jvm convert byte-to-long" #ls;Int int-sample Int i.=]
)]
($_ seq
<2step>
)))
(context: "Conversions [Part 2]"
[int-sample (|> r;int (:: @ map (|>. (i.% 128) int/abs)))
#let [frac-sample (int-to-frac int-sample)]]
(with-expansions [<3step> (do-template [<step1> <step2> <step3> <tag> <sample> <cast> <test>]
[(test (format <step1> " / " <step2> " / " <step3>)
(|> (do meta;Monad<Meta>
[sampleI (@;generate (|> (<tag> <sample>)
(list) (#ls;Procedure <step1>)
(list) (#ls;Procedure <step2>)
(list) (#ls;Procedure <step3>)))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success valueG)
(<test> <sample> (:! <cast> valueG))
(#e;Error error)
false)))]
["jvm convert long-to-int" "jvm convert int-to-char" "jvm convert char-to-long" #ls;Int int-sample Int i.=]
["jvm convert long-to-int" "jvm convert int-to-byte" "jvm convert byte-to-long" #ls;Int int-sample Int i.=]
["jvm convert long-to-int" "jvm convert int-to-short" "jvm convert short-to-long" #ls;Int int-sample Int i.=]
["jvm convert long-to-float" "jvm convert float-to-int" "jvm convert int-to-long" #ls;Int int-sample Int i.=]
["jvm convert long-to-int" "jvm convert int-to-float" "jvm convert float-to-long" #ls;Int int-sample Int i.=]
)
<4step> (do-template [<step1> <step2> <step3> <step4> <tag> <sample> <cast> <test>]
[(test (format <step1> " / " <step2> " / " <step3>)
(|> (do meta;Monad<Meta>
[sampleI (@;generate (|> (<tag> <sample>)
(list) (#ls;Procedure <step1>)
(list) (#ls;Procedure <step2>)
(list) (#ls;Procedure <step3>)
(list) (#ls;Procedure <step4>)))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success valueG)
(<test> <sample> (:! <cast> valueG))
(#e;Error error)
false)))]
["jvm convert long-to-int" "jvm convert int-to-char" "jvm convert char-to-byte" "jvm convert byte-to-long" #ls;Int int-sample Int i.=]
["jvm convert long-to-int" "jvm convert int-to-char" "jvm convert char-to-short" "jvm convert short-to-long" #ls;Int int-sample Int i.=]
["jvm convert long-to-int" "jvm convert int-to-char" "jvm convert char-to-int" "jvm convert int-to-long" #ls;Int int-sample Int i.=]
)
]
($_ seq
<3step>
<4step>
)))
(def: gen-nat
(r;Random Nat)
(|> r;nat
(r/map (n.% +128))
(r;filter (|>. (n.= +0) not))))
(def: gen-int
(r;Random Int)
(|> gen-nat (r/map nat-to-int)))
(def: gen-frac
(r;Random Frac)
(|> gen-int (r/map int-to-frac)))
(do-template [<domain> <generator> <tag> <type> <test> <augmentation> <+> <-> <*> </> <%> <pre> <post>]
[(context: (format "Arithmetic [" <domain> "]")
[param <generator>
#let [subject (<augmentation> param)]]
(with-expansions [<tests> (do-template [<procedure> <reference>]
[(test <procedure>
(|> (do meta;Monad<Meta>
[sampleI (@;generate (<post> (#ls;Procedure <procedure> (list (<pre> (<tag> subject))
(<pre> (<tag> param))))))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success valueG)
(<test> (<reference> param subject)
(:! <type> valueG))
(#e;Error error)
false)))]
[(format "jvm " <domain> " +") <+>]
[(format "jvm " <domain> " -") <->]
[(format "jvm " <domain> " *") <*>]
[(format "jvm " <domain> " /") </>]
[(format "jvm " <domain> " %") <%>]
)]
($_ seq
<tests>
)))]
["int" gen-int #ls;Int Int i.= (i.* 10) i.+ i.- i.* i./ i.% (|>. (list) (#ls;Procedure "jvm convert long-to-int")) (|>. (list) (#ls;Procedure "jvm convert int-to-long"))]
["long" gen-int #ls;Int Int i.= (i.* 10) i.+ i.- i.* i./ i.% id id]
["float" gen-frac #ls;Frac Frac f.= (f.* 10.0) f.+ f.- f.* f./ f.% (|>. (list) (#ls;Procedure "jvm convert double-to-float")) (|>. (list) (#ls;Procedure "jvm convert float-to-double"))]
["double" gen-frac #ls;Frac Frac f.= (f.* 10.0) f.+ f.- f.* f./ f.% id id]
)
(do-template [<domain> <post> <convert>]
[(context: (format "Bit-wise [" <domain> "]")
[param gen-nat
subject gen-nat
#let [shift (n.% +10 param)]]
(with-expansions [<combiners> (do-template [<procedure> <reference>]
[(test <procedure>
(|> (do meta;Monad<Meta>
[sampleI (@;generate (<post> (#ls;Procedure <procedure> (list (<convert> (#ls;Nat subject))
(<convert> (#ls;Nat param))))))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success valueG)
(n.= (<reference> param subject)
(:! Nat valueG))
(#e;Error error)
false)))]
[(format "jvm " <domain> " and") bit;and]
[(format "jvm " <domain> " or") bit;or]
[(format "jvm " <domain> " xor") bit;xor]
)
<shifters> (do-template [<procedure> <reference> <type> <test> <pre-subject> <pre>]
[(test <procedure>
(|> (do meta;Monad<Meta>
[sampleI (@;generate (<post> (#ls;Procedure <procedure> (list (<convert> (<pre> subject))
(|> (#ls;Nat shift)
(list)
(#ls;Procedure "jvm convert long-to-int"))))))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success valueG)
(<test> (<reference> shift (<pre-subject> subject))
(:! <type> valueG))
(#e;Error error)
false)))]
[(format "jvm " <domain> " shl") bit;shift-left Nat n.= id #ls;Nat]
[(format "jvm " <domain> " shr") bit;signed-shift-right Int i.= nat-to-int (|>. nat-to-int #ls;Int)]
[(format "jvm " <domain> " ushr") bit;shift-right Nat n.= id #ls;Nat]
)]
($_ seq
<combiners>
<shifters>
)))]
["int" (|>. (list) (#ls;Procedure "jvm convert int-to-long")) (|>. (list) (#ls;Procedure "jvm convert long-to-int"))]
["long" id id]
)
(do-template [<domain> <generator> <tag> <=> <<> <pre>]
[(context: (format "Order [" <domain> "]")
[param <generator>
subject <generator>]
(with-expansions [<tests> (do-template [<procedure> <reference>]
[(test <procedure>
(|> (do meta;Monad<Meta>
[sampleI (@;generate (#ls;Procedure <procedure> (list (<pre> (<tag> subject))
(<pre> (<tag> param)))))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success valueG)
(bool/= (<reference> param subject)
(:! Bool valueG))
(#e;Error error)
false)))]
[(format "jvm " <domain> " =") <=>]
[(format "jvm " <domain> " <") <<>]
)]
($_ seq
<tests>
)))]
["int" gen-int #ls;Int i.= i.< (|>. (list) (#ls;Procedure "jvm convert long-to-int"))]
["long" gen-int #ls;Int i.= i.< id]
["float" gen-frac #ls;Frac f.= f.< (|>. (list) (#ls;Procedure "jvm convert double-to-float"))]
["double" gen-frac #ls;Frac f.= f.< id]
["char" gen-int #ls;Int i.= i.< (|>. (list) (#ls;Procedure "jvm convert long-to-int")
(list) (#ls;Procedure "jvm convert int-to-char"))]
)
(context: "Array [Part 1]"
[size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +1))))
idx (|> r;nat (:: @ map (n.% size)))
valueZ r;bool
valueB gen-int
valueS gen-int
valueI gen-int
valueL r;int
valueF gen-frac
valueD r;frac
valueC gen-int]
(with-expansions [<array> (do-template [<class> <type> <value> <test> <input> <post>]
[(test <class>
(|> (do meta;Monad<Meta>
[sampleI (@;generate (|> (#ls;Procedure "jvm array new" (list (#ls;Nat +0) (#ls;Text <class>) (#ls;Nat size)))
(list (#ls;Text <class>) (#ls;Nat idx) <input>) (#ls;Procedure "jvm array write")
(list (#ls;Text <class>) (#ls;Nat idx)) (#ls;Procedure "jvm array read")
<post>))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputZ)
(<test> <value> (:! <type> outputZ))
(#e;Error error)
false)))]
["boolean" Bool valueZ bool/= (#ls;Bool valueZ) id]
["byte" Int valueB i.= (|> (#ls;Int valueB)
(list) (#ls;Procedure "jvm convert long-to-byte"))
(<| (#ls;Procedure "jvm convert byte-to-long") (list))]
["short" Int valueS i.= (|> (#ls;Int valueS)
(list) (#ls;Procedure "jvm convert long-to-short"))
(<| (#ls;Procedure "jvm convert short-to-long") (list))]
["int" Int valueI i.= (|> (#ls;Int valueI)
(list) (#ls;Procedure "jvm convert long-to-int"))
(<| (#ls;Procedure "jvm convert int-to-long") (list))]
["long" Int valueL i.= (#ls;Int valueL) id]
["float" Frac valueF f.= (|> (#ls;Frac valueF)
(list) (#ls;Procedure "jvm convert double-to-float"))
(<| (#ls;Procedure "jvm convert float-to-double") (list))]
["double" Frac valueD f.= (#ls;Frac valueD) id]
)]
($_ seq
<array>
)))
(context: "Array [Part 2]"
[size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +1))))
idx (|> r;nat (:: @ map (n.% size)))
valueZ r;bool
valueB gen-int
valueS gen-int
valueI gen-int
valueL r;int
valueF gen-frac
valueD r;frac
valueC gen-int]
(with-expansions [<array> (do-template [<class> <type> <value> <test> <input> <post>]
[(test <class>
(|> (do meta;Monad<Meta>
[sampleI (@;generate (|> (#ls;Procedure "jvm array new" (list (#ls;Nat +0) (#ls;Text <class>) (#ls;Nat size)))
(list (#ls;Text <class>) (#ls;Nat idx) <input>) (#ls;Procedure "jvm array write")
(list (#ls;Text <class>) (#ls;Nat idx)) (#ls;Procedure "jvm array read")
<post>))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(<test> <value> (:! <type> outputG))
(#e;Error error)
false)))]
["char" Int valueC i.= (|> (#ls;Int valueC)
(list) (#ls;Procedure "jvm convert long-to-int")
(list) (#ls;Procedure "jvm convert int-to-char"))
(<| (#ls;Procedure "jvm convert char-to-long") (list))]
["java.lang.Long" Int valueL i.= (#ls;Int valueL) id]
)]
($_ seq
<array>
(test "java.lang.Double (level 1)"
(|> (do meta;Monad<Meta>
[#let [inner (|> (#ls;Procedure "jvm array new" (list (#ls;Nat +0) (#ls;Text "java.lang.Double") (#ls;Nat size)))
(list (#ls;Text "java.lang.Double") (#ls;Nat idx) (#ls;Frac valueD)) (#ls;Procedure "jvm array write"))]
sampleI (@;generate (|> (#ls;Procedure "jvm array new" (list (#ls;Nat +1) (#ls;Text "java.lang.Double") (#ls;Nat size)))
(list (#ls;Text "#Array") (#ls;Nat idx) inner) (#ls;Procedure "jvm array write")
(list (#ls;Text "#Array") (#ls;Nat idx)) (#ls;Procedure "jvm array read")
(list (#ls;Text "java.lang.Double") (#ls;Nat idx)) (#ls;Procedure "jvm array read")))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(f.= valueD (:! Frac outputG))
(#e;Error error)
false)))
(test "jvm array length"
(|> (do meta;Monad<Meta>
[sampleI (@;generate (|> (#ls;Procedure "jvm array new" (list (#ls;Nat +0) (#ls;Text "java.lang.Object") (#ls;Nat size)))
(list) (#ls;Procedure "jvm array length")))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(n.= size (:! Nat outputG))
(#e;Error error)
false)))
)))
(host;import java.lang.Class
(getName [] String))
(def: classes
(List Text)
(list "java.lang.Object" "java.lang.Class"
"java.lang.String" "java.lang.Number"))
(def: instances
(List [Text (r;Random ls;Synthesis)])
(let [gen-boolean (|> r;bool (:: r;Functor<Random> map (|>. #ls;Bool)))
gen-integer (|> r;int (:: r;Functor<Random> map (|>. #ls;Int)))
gen-double (|> r;frac (:: r;Functor<Random> map (|>. #ls;Frac)))
gen-string (|> (r;text +5) (:: r;Functor<Random> map (|>. #ls;Text)))]
(list ["java.lang.Boolean" gen-boolean]
["java.lang.Long" gen-integer]
["java.lang.Double" gen-double]
["java.lang.String" gen-string]
["java.lang.Object" (r;either (r;either gen-boolean
gen-integer)
(r;either gen-double
gen-string))])))
(context: "Object."
[#let [num-classes (list;size classes)]
#let [num-instances (list;size instances)]
class-idx (|> r;nat (:: @ map (n.% num-classes)))
instance-idx (|> r;nat (:: @ map (n.% num-instances)))
#let [class (maybe;assume (list;nth class-idx classes))
[instance-class instance-gen] (maybe;assume (list;nth instance-idx instances))]
sample r;int
monitor r;int
instance instance-gen]
($_ seq
(test "jvm object null"
(|> (do meta;Monad<Meta>
[sampleI (@;generate (|> (#ls;Procedure "jvm object null" (list))
(list) (#ls;Procedure "jvm object null?")))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(:! Bool outputG)
(#e;Error error)
false)))
(test "jvm object null?"
(|> (do meta;Monad<Meta>
[sampleI (@;generate (|> (#ls;Int sample)
(list) (#ls;Procedure "jvm object null?")))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(not (:! Bool outputG))
(#e;Error error)
false)))
(test "jvm object synchronized"
(|> (do meta;Monad<Meta>
[sampleI (@;generate (#ls;Procedure "jvm object synchronized"
(list (#ls;Int monitor)
(#ls;Int sample))))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(i.= sample (:! Int outputG))
(#e;Error error)
false)))
(test "jvm object throw"
false)
(test "jvm object class"
(|> (do meta;Monad<Meta>
[sampleI (@;generate (#ls;Procedure "jvm object class" (list (#ls;Text class))))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(|> outputG (:! Class) (Class.getName []) (text/= class))
(#e;Error error)
false)))
(test "jvm object instance?"
(|> (do meta;Monad<Meta>
[sampleI (@;generate (#ls;Procedure "jvm object instance?" (list (#ls;Text instance-class)
instance)))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(:! Bool outputG)
(#e;Error error)
false)))
))
(host;import java.util.GregorianCalendar
(#static AD int))
(context: "Member [Field]"
($_ seq
(test "jvm member static get"
(|> (do meta;Monad<Meta>
[sampleI (@;generate (|> (#ls;Procedure "jvm member static get" (list (#ls;Text "java.util.GregorianCalendar") (#ls;Text "AD") (#ls;Text "int")))
(list) (#ls;Procedure "jvm convert int-to-long")))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(i.= GregorianCalendar.AD (:! Int outputG))
(#e;Error error)
false)))
(test "jvm member static put"
(|> (do meta;Monad<Meta>
[sampleI (@;generate (#ls;Procedure "jvm member static put" (list (#ls;Text "java.awt.datatransfer.DataFlavor") (#ls;Text "allHtmlFlavor") (#ls;Text "java.awt.datatransfer.DataFlavor")
(#ls;Procedure "jvm member static get" (list (#ls;Text "java.awt.datatransfer.DataFlavor") (#ls;Text "allHtmlFlavor") (#ls;Text "java.awt.datatransfer.DataFlavor"))))))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(is @runtime;unit (:! Text outputG))
(#e;Error error)
false)))
(test "jvm member virtual get"
false)
(test "jvm member virtual put"
false)
))
(host;import java.lang.Object)
(host;import (java.util.ArrayList a))
(context: "Member [Method]"
[sample (|> r;int (:: @ map (|>. int/abs (i.% 100))))
#let [object-longS (|> (#ls;Int sample)
(list (#ls;Text "java.lang.Object")) #ls;Tuple)
intS (|> (#ls;Int sample)
(list) (#ls;Procedure "jvm convert long-to-int")
(list (#ls;Text "int")) #ls;Tuple)
coded-intS (|> (#ls;Text (int/encode sample))
(list (#ls;Text "java.lang.String")) #ls;Tuple)
array-listS (#ls;Procedure "jvm member invoke constructor" (list (#ls;Text "java.util.ArrayList") intS))]]
($_ seq
(test "jvm member invoke static"
(|> (do meta;Monad<Meta>
[sampleI (@;generate (#ls;Procedure "jvm member invoke static"
(list (#ls;Text "java.lang.Long")
(#ls;Text "decode")
(#ls;Text "java.lang.Long")
coded-intS)))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(i.= sample (:! Int outputG))
(#e;Error error)
false)))
(test "jvm member invoke virtual"
(|> (do meta;Monad<Meta>
[sampleI (@;generate (|> object-longS
(list (#ls;Text "java.lang.Object")
(#ls;Text "equals")
(#ls;Text "boolean")
(#ls;Int sample))
(#ls;Procedure "jvm member invoke virtual")))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(:! Bool outputG)
(#e;Error error)
false)))
(test "jvm member invoke interface"
(|> (do meta;Monad<Meta>
[sampleI (@;generate (#ls;Procedure "jvm member invoke interface"
(list (#ls;Text "java.util.Collection")
(#ls;Text "add")
(#ls;Text "boolean")
array-listS
object-longS)))]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(:! Bool outputG)
(#e;Error error)
false)))
(test "jvm member invoke constructor"
(|> (do meta;Monad<Meta>
[sampleI (@;generate array-listS)]
(@eval;eval sampleI))
(meta;run (init-compiler []))
(case> (#e;Success outputG)
(host;instance? ArrayList (:! Object outputG))
(#e;Error error)
false)))
))
|