From 658c9e98b8a1f7617f84bf42deafa4b0430d1a23 Mon Sep 17 00:00:00 2001 From: Lukasz Czajka Date: Wed, 8 Jan 2025 11:04:19 +0100 Subject: [PATCH] add test --- test/Main.hs | 4 +- test/Tree/Eval/Positive.hs | 7 +++- test/Tree/Transformation.hs | 2 + test/Tree/Transformation/Apply.hs | 3 +- test/Tree/Transformation/ConvertUnaryCalls.hs | 33 +++++++++++++++ tests/Tree/positive/out/test043.out | 1 + tests/Tree/positive/test043.jvt | 41 +++++++++++++++++++ 7 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 test/Tree/Transformation/ConvertUnaryCalls.hs create mode 100644 tests/Tree/positive/out/test043.out create mode 100644 tests/Tree/positive/test043.jvt diff --git a/test/Main.hs b/test/Main.hs index 6f7dd375ab..98ef785718 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -28,9 +28,9 @@ import Typecheck qualified slowTests :: IO TestTree slowTests = - sequentialTestGroup + testGroup "Juvix slow tests" - AllFinish + -- AllFinish <$> sequence [ return Runtime.allTests, return Reg.allTests, diff --git a/test/Tree/Eval/Positive.hs b/test/Tree/Eval/Positive.hs index 6026e3a577..e4bafd3e99 100644 --- a/test/Tree/Eval/Positive.hs +++ b/test/Tree/Eval/Positive.hs @@ -249,5 +249,10 @@ tests = "Test042: Uncurried function type unification" $(mkRelDir ".") $(mkRelFile "test042.jvt") - $(mkRelFile "out/test042.out") + $(mkRelFile "out/test042.out"), + PosTest + "Test043: Unary closure calls" + $(mkRelDir ".") + $(mkRelFile "test043.jvt") + $(mkRelFile "out/test043.out") ] diff --git a/test/Tree/Transformation.hs b/test/Tree/Transformation.hs index 2a360724ee..4b38fa5fc6 100644 --- a/test/Tree/Transformation.hs +++ b/test/Tree/Transformation.hs @@ -3,6 +3,7 @@ module Tree.Transformation where import Base import Tree.Transformation.Apply qualified as Apply import Tree.Transformation.CheckNoAnoma qualified as CheckNoAnoma +import Tree.Transformation.ConvertUnaryCalls qualified as ConvertUnaryCalls import Tree.Transformation.IdentityTrans qualified as IdentityTrans import Tree.Transformation.Reachability qualified as Reachability @@ -12,6 +13,7 @@ allTests = "JuvixTree transformations" [ IdentityTrans.allTests, Apply.allTests, + ConvertUnaryCalls.allTests, Reachability.allTests, CheckNoAnoma.allTests ] diff --git a/test/Tree/Transformation/Apply.hs b/test/Tree/Transformation/Apply.hs index 8aa9d16e53..26fb4ab833 100644 --- a/test/Tree/Transformation/Apply.hs +++ b/test/Tree/Transformation/Apply.hs @@ -15,7 +15,8 @@ allTests = [ "Test007: Higher-order functions", "Test022: Self-application", "Test025: Dynamic closure extension", - "Test032: Church numerals" + "Test032: Church numerals", + "Test043: Unary closure calls" ] Eval.tests ) diff --git a/test/Tree/Transformation/ConvertUnaryCalls.hs b/test/Tree/Transformation/ConvertUnaryCalls.hs new file mode 100644 index 0000000000..1e6e7c8b0c --- /dev/null +++ b/test/Tree/Transformation/ConvertUnaryCalls.hs @@ -0,0 +1,33 @@ +module Tree.Transformation.ConvertUnaryCalls (allTests) where + +import Base +import Juvix.Compiler.Tree.Transformation +import Tree.Eval.Positive qualified as Eval +import Tree.Transformation.Base + +allTests :: TestTree +allTests = + testGroup + "ConvertUnaryCalls" + ( map liftTest $ + Eval.filterTests + [ "Test007: Higher-order functions", + "Test022: Self-application", + "Test025: Dynamic closure extension", + "Test032: Church numerals", + "Test043: Unary closure calls" + ] + Eval.tests + ) + +pipe :: [TransformationId] +pipe = [ConvertUnaryCalls] + +liftTest :: Eval.PosTest -> TestTree +liftTest _testEval = + fromTest + Test + { _testTransformations = pipe, + _testAssertion = const (return ()), + _testEval + } diff --git a/tests/Tree/positive/out/test043.out b/tests/Tree/positive/out/test043.out new file mode 100644 index 0000000000..b4de394767 --- /dev/null +++ b/tests/Tree/positive/out/test043.out @@ -0,0 +1 @@ +11 diff --git a/tests/Tree/positive/test043.jvt b/tests/Tree/positive/test043.jvt new file mode 100644 index 0000000000..088ba408d1 --- /dev/null +++ b/tests/Tree/positive/test043.jvt @@ -0,0 +1,41 @@ + +type List { + nil : List; + cons : (*, List) -> List; +} + +function lambda_add(integer) : integer; +function lambda_add2(integer, integer) : integer; +function mapnat(integer -> integer, List) : List; +function main() : List; + +function lambda_add(_X' : integer) : integer { + add(1, _X') +} + +function lambda_add2(_X : integer, _Y : integer) : integer { + add(_X, _Y) +} + +function mapnat(f : integer -> integer, _X : List) : List { + case[List](_X) { + nil: alloc[nil]() + cons: save { + alloc[cons](ccall(f, tmp[0].cons[0]), call[mapnat](f, tmp[0].cons[1])) + } + } +} + +function mysum(f : (integer, integer) -> integer, _X : List) : integer { + case[List](_X) { + nil: 0 + cons: save { + ccall(f, tmp[0].cons[0], call[mysum](f, tmp[0].cons[1])) + } + } +} + +function main() : integer { + call[mysum](calloc[lambda_add2](), call[mapnat](calloc[lambda_add](), alloc[cons](1, alloc[cons](3, alloc[cons](4, alloc[nil]()))))) + -- result: 11 +}