aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/test/test/luxc/lang/translation/jvm/structure.lux
diff options
context:
space:
mode:
Diffstat (limited to 'new-luxc/test/test/luxc/lang/translation/jvm/structure.lux')
-rw-r--r--new-luxc/test/test/luxc/lang/translation/jvm/structure.lux113
1 files changed, 0 insertions, 113 deletions
diff --git a/new-luxc/test/test/luxc/lang/translation/jvm/structure.lux b/new-luxc/test/test/luxc/lang/translation/jvm/structure.lux
deleted file mode 100644
index 2fc377bd6..000000000
--- a/new-luxc/test/test/luxc/lang/translation/jvm/structure.lux
+++ /dev/null
@@ -1,113 +0,0 @@
-(.module:
- lux
- (lux [io]
- (control [monad #+ do]
- pipe)
- (data ["e" error]
- [maybe]
- [bool "bool/" Eq<Bool>]
- [text "text/" Eq<Text>]
- text/format
- (coll [array]
- [list]))
- ["r" math/random "r/" Monad<Random>]
- [macro]
- (macro [code])
- [host]
- test)
- (luxc [lang]
- (lang [".L" host]
- ["ls" synthesis]
- (translation (jvm [".T" expression]
- ["@." eval]
- ["@." runtime]
- ["@." common]))))
- (test/luxc common))
-
-(host.import java/lang/Integer)
-
-(def: gen-primitive
- (r.Random ls.Synthesis)
- (r.either (r.either (r.either (r/wrap (' []))
- (r/map code.bool r.bool))
- (r.either (r/map code.nat r.nat)
- (r/map code.int r.int)))
- (r.either (r.either (r/map code.deg r.deg)
- (r/map code.frac r.frac))
- (r/map code.text (r.text +5)))))
-
-(def: (corresponds? [prediction sample])
- (-> [ls.Synthesis Top] Bool)
- (case prediction
- [_ (#.Tuple #.Nil)]
- (is hostL.unit (:! Text sample))
-
- (^template [<tag> <type> <test>]
- [_ (<tag> prediction')]
- (case (host.try (<test> prediction' (:! <type> sample)))
- (#e.Success result)
- result
-
- (#e.Error error)
- false))
- ([#.Bool Bool bool/=]
- [#.Nat Nat n/=]
- [#.Int Int i/=]
- [#.Deg Deg d/=]
- [#.Frac Frac f/=]
- [#.Text Text text/=])
-
- _
- false
- ))
-
-(context: "Tuples."
- (<| (times +100)
- (do @
- [size (|> r.nat (:: @ map (|>> (n/% +10) (n/max +2))))
- members (r.list size gen-primitive)]
- (test "Can translate tuple."
- (|> (do macro.Monad<Meta>
- [sampleI (expressionT.translate (code.tuple members))]
- (@eval.eval sampleI))
- (lang.with-current-module "")
- (macro.run (init-compiler []))
- (case> (#e.Success valueT)
- (let [valueT (:! (Array Top) valueT)]
- (and (n/= size (array.size valueT))
- (list.every? corresponds? (list.zip2 members (array.to-list valueT)))))
-
- _
- false))))))
-
-(context: "Variants."
- (<| (times +100)
- (do @
- [num-tags (|> r.nat (:: @ map (|>> (n/% +10) (n/max +2))))
- tag (|> r.nat (:: @ map (n/% num-tags)))
- #let [last? (n/= (n/dec num-tags) tag)]
- member gen-primitive]
- (test "Can translate variant."
- (|> (do macro.Monad<Meta>
- [runtime-bytecode @runtime.translate
- sampleI (expressionT.translate (` ((~ (code.nat tag)) (~ (code.bool last?)) (~ member))))]
- (@eval.eval sampleI))
- (lang.with-current-module "")
- (macro.run (init-compiler []))
- (case> (#e.Success valueT)
- (let [valueT (:! (Array Top) valueT)]
- (and (n/= +3 (array.size valueT))
- (let [_tag (:! Integer (maybe.assume (array.read +0 valueT)))
- _last? (array.read +1 valueT)
- _value (:! Top (maybe.assume (array.read +2 valueT)))]
- (and (n/= tag (|> _tag host.int-to-long int-to-nat))
- (case _last?
- (#.Some _last?')
- (and last? (text/= "" (:! Text _last?')))
-
- #.None
- (not last?))
- (corresponds? [member _value])))))
-
- _
- false))))))