aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/test
diff options
context:
space:
mode:
authorEduardo Julian2017-10-12 18:14:19 -0400
committerEduardo Julian2017-10-12 18:14:19 -0400
commit4b672d27a1a1a79643c43cf06917072cc97c1289 (patch)
tree6136e952c0e87172921ad4bf5c0ee128a085a0ba /new-luxc/test
parent50c370878c0f9985a8b6d1003af9e9f6282b853e (diff)
- Compilation and tests for arrays.
Diffstat (limited to '')
-rw-r--r--new-luxc/test/test/luxc/generator/procedure/host.jvm.lux108
1 files changed, 108 insertions, 0 deletions
diff --git a/new-luxc/test/test/luxc/generator/procedure/host.jvm.lux b/new-luxc/test/test/luxc/generator/procedure/host.jvm.lux
index 67fbbceda..6371286a6 100644
--- a/new-luxc/test/test/luxc/generator/procedure/host.jvm.lux
+++ b/new-luxc/test/test/luxc/generator/procedure/host.jvm.lux
@@ -233,3 +233,111 @@
["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 macro;Monad<Lux>
+ [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))
+ (macro;run (init-compiler []))
+ (case> (#R;Success outputZ)
+ (<test> <value> (:! <type> outputZ))
+
+ (#R;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 macro;Monad<Lux>
+ [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))
+ (macro;run (init-compiler []))
+ (case> (#R;Success outputG)
+ (<test> <value> (:! <type> outputG))
+
+ (#R;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 macro;Monad<Lux>
+ [#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))
+ (macro;run (init-compiler []))
+ (case> (#R;Success outputG)
+ (f.= valueD (:! Frac outputG))
+
+ (#R;Error error)
+ false)))
+ (test "jvm array length"
+ (|> (do macro;Monad<Lux>
+ [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))
+ (macro;run (init-compiler []))
+ (case> (#R;Success outputG)
+ (n.= size (:! Nat outputG))
+
+ (#R;Error error)
+ false)))
+ )))