From 1acc9f4cdd7b7cff29351594fa603c3b6fa4c666 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 12 Oct 2017 15:22:25 -0400 Subject: - Compilation and tests for arithmetic, bit-wise operations and order. --- .../test/test/luxc/analyser/procedure/host.jvm.lux | 3 - .../test/luxc/generator/procedure/host.jvm.lux | 135 +++++++++++++++++++++ 2 files changed, 135 insertions(+), 3 deletions(-) (limited to 'new-luxc/test') diff --git a/new-luxc/test/test/luxc/analyser/procedure/host.jvm.lux b/new-luxc/test/test/luxc/analyser/procedure/host.jvm.lux index c45143d5b..49d51eb3c 100644 --- a/new-luxc/test/test/luxc/analyser/procedure/host.jvm.lux +++ b/new-luxc/test/test/luxc/analyser/procedure/host.jvm.lux @@ -148,7 +148,6 @@ [(format "jvm " " =") @host;Boolean] [(format "jvm " " <") @host;Boolean] - [(format "jvm " " >") @host;Boolean] )] ($_ seq @@ -207,7 +206,6 @@ [(format "jvm " " =") @host;Boolean] [(format "jvm " " <") @host;Boolean] - [(format "jvm " " >") @host;Boolean] )] ($_ seq @@ -229,7 +227,6 @@ [(format "jvm " " =") @host;Boolean] [(format "jvm " " <") @host;Boolean] - [(format "jvm " " >") @host;Boolean] )] ($_ seq 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 1dd60bc76..67fbbceda 100644 --- a/new-luxc/test/test/luxc/generator/procedure/host.jvm.lux +++ b/new-luxc/test/test/luxc/generator/procedure/host.jvm.lux @@ -4,6 +4,8 @@ (control [monad #+ do] pipe) (data ["R" result] + [bit] + [bool "bool/" Eq] [number "int/" Number] text/format) ["r" math/random "r/" Monad] @@ -98,3 +100,136 @@ <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 [ <+> <-> <*> <%>
 ]
+  [(context: (format "Arithmetic ["  "]")
+     [param 
+      #let [subject ( param)]]
+     (with-expansions [ (do-template [ ]
+                                 [(test 
+                                        (|> (do macro;Monad
+                                              [sampleI (@;generate ( (#ls;Procedure  (list (
 ( subject))
+                                                                                                            (
 ( param))))))]
+                                              (@eval;eval sampleI))
+                                            (macro;run (init-compiler []))
+                                            (case> (#R;Success valueG)
+                                                   ( ( param subject)
+                                                           (:!  valueG))
+
+                                                   (#R;Error error)
+                                                   false)))]
+
+                                 [(format "jvm "  " +") <+>]
+                                 [(format "jvm "  " -") <->]
+                                 [(format "jvm "  " *") <*>]
+                                 [(format "jvm "  " /") ]
+                                 [(format "jvm "  " %") <%>]
+                                 )]
+       ($_ seq
+           
+           )))]
+
+  ["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 [  ]
+  [(context: (format "Bit-wise ["  "]")
+     [param gen-nat
+      subject gen-nat
+      #let [shift (n.% +10 param)]]
+     (with-expansions [ (do-template [ ]
+                                     [(test 
+                                            (|> (do macro;Monad
+                                                  [sampleI (@;generate ( (#ls;Procedure  (list ( (#ls;Nat subject))
+                                                                                                                ( (#ls;Nat param))))))]
+                                                  (@eval;eval sampleI))
+                                                (macro;run (init-compiler []))
+                                                (case> (#R;Success valueG)
+                                                       (n.= ( param subject)
+                                                            (:! Nat valueG))
+
+                                                       (#R;Error error)
+                                                       false)))]
+
+                                     [(format "jvm "  " and") bit;and]
+                                     [(format "jvm "  " or") bit;or]
+                                     [(format "jvm "  " xor") bit;xor]
+                                     )
+                        (do-template [     
]
+                                    [(test 
+                                           (|> (do macro;Monad
+                                                 [sampleI (@;generate ( (#ls;Procedure  (list ( (
 subject))
+                                                                                                               (|> (#ls;Nat shift)
+                                                                                                                   (list)
+                                                                                                                   (#ls;Procedure "jvm convert long-to-int"))))))]
+                                                 (@eval;eval sampleI))
+                                               (macro;run (init-compiler []))
+                                               (case> (#R;Success valueG)
+                                                      ( ( shift ( subject))
+                                                              (:!  valueG))
+
+                                                      (#R;Error error)
+                                                      false)))]
+
+                                    [(format "jvm "  " shl") bit;shift-left Nat n.= id #ls;Nat]
+                                    [(format "jvm "  " shr") bit;signed-shift-right Int i.= nat-to-int (|>. nat-to-int #ls;Int)]
+                                    [(format "jvm "  " ushr") bit;shift-right Nat n.= id #ls;Nat]
+                                    )]
+       ($_ seq
+           
+           
+           )))]
+
+  ["int" (|>. (list) (#ls;Procedure "jvm convert int-to-long")) (|>. (list) (#ls;Procedure "jvm convert long-to-int"))]
+  ["long" id id]
+  )
+
+(do-template [   <=> <<> 
]
+  [(context: (format "Order ["  "]")
+     [param 
+      subject ]
+     (with-expansions [ (do-template [ ]
+                                 [(test 
+                                        (|> (do macro;Monad
+                                              [sampleI (@;generate (#ls;Procedure  (list (
 ( subject))
+                                                                                                    (
 ( param)))))]
+                                              (@eval;eval sampleI))
+                                            (macro;run (init-compiler []))
+                                            (case> (#R;Success valueG)
+                                                   (bool/= ( param subject)
+                                                           (:! Bool valueG))
+
+                                                   (#R;Error error)
+                                                   false)))]
+
+                                 [(format "jvm "  " =") <=>]
+                                 [(format "jvm "  " <") <<>]
+                                 )]
+       ($_ seq
+           
+           )))]
+
+  ["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"))]
+  )
-- 
cgit v1.2.3