mirror of
https://github.com/anoma/juvix.git
synced 2025-01-05 22:46:08 +03:00
More tests for the VampIR compilation pipeline (#2197)
This commit is contained in:
parent
82a6f8c891
commit
a3a2454733
@ -164,5 +164,17 @@ tests =
|
||||
"Test020: boolean target"
|
||||
$(mkRelDir ".")
|
||||
$(mkRelFile "test020.juvix")
|
||||
$(mkRelFile "data/test020.json")
|
||||
$(mkRelFile "data/test020.json"),
|
||||
posTest
|
||||
11
|
||||
"Test021: fast exponentiation (exponential unrolling)"
|
||||
$(mkRelDir ".")
|
||||
$(mkRelFile "test021.juvix")
|
||||
$(mkRelFile "data/test021.json"),
|
||||
posTest
|
||||
10
|
||||
"Test022: fast exponentiation"
|
||||
$(mkRelDir ".")
|
||||
$(mkRelFile "test022.juvix")
|
||||
$(mkRelFile "data/test022.json")
|
||||
]
|
||||
|
5
tests/VampIR/positive/Compilation/data/test021.json
Normal file
5
tests/VampIR/positive/Compilation/data/test021.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"in1": "5",
|
||||
"in2": "3",
|
||||
"out": "125"
|
||||
}
|
5
tests/VampIR/positive/Compilation/data/test022.json
Normal file
5
tests/VampIR/positive/Compilation/data/test022.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"in1": "5",
|
||||
"in2": "11",
|
||||
"out": "48828125"
|
||||
}
|
23
tests/VampIR/positive/Compilation/test021.juvix
Normal file
23
tests/VampIR/positive/Compilation/test021.juvix
Normal file
@ -0,0 +1,23 @@
|
||||
-- fast exponentiation (exponential unrolling blow-up)
|
||||
module test021;
|
||||
|
||||
import Stdlib.Prelude open;
|
||||
import Stdlib.Data.Nat.Ord open;
|
||||
|
||||
{-# unroll: 4 #-}
|
||||
terminating
|
||||
power' : Nat → Nat → Nat → Nat;
|
||||
power' acc a b :=
|
||||
if
|
||||
(b == 0)
|
||||
acc
|
||||
(if
|
||||
(mod b 2 == 0)
|
||||
(power' acc (a * a) (div b 2))
|
||||
(power' (acc * a) (a * a) (div b 2)));
|
||||
|
||||
power : Nat → Nat → Nat;
|
||||
power := power' 1;
|
||||
|
||||
main : Nat -> Nat -> Nat;
|
||||
main := power;
|
19
tests/VampIR/positive/Compilation/test022.juvix
Normal file
19
tests/VampIR/positive/Compilation/test022.juvix
Normal file
@ -0,0 +1,19 @@
|
||||
-- fast exponentiation
|
||||
module test022;
|
||||
|
||||
import Stdlib.Prelude open;
|
||||
import Stdlib.Data.Nat.Ord open;
|
||||
|
||||
{-# unroll: 10 #-}
|
||||
terminating
|
||||
power' : Nat → Nat → Nat → Nat;
|
||||
power' acc a b :=
|
||||
let
|
||||
acc' : Nat := if (mod b 2 == 0) acc (acc * a);
|
||||
in if (b == 0) acc (power' acc' (a * a) (div b 2));
|
||||
|
||||
power : Nat → Nat → Nat;
|
||||
power := power' 1;
|
||||
|
||||
main : Nat -> Nat -> Nat;
|
||||
main := power;
|
Loading…
Reference in New Issue
Block a user