@@ -0,0 +1,54 @@
|
||||
module Gyehoek.Test.CPS.Stackify (root) where
|
||||
|
||||
import Test.Tasty (TestTree, testGroup)
|
||||
import Test.Tasty.HUnit
|
||||
import qualified Gyehoek.CPS.Stackify as Sut
|
||||
import Gyehoek.Stack.VM as Stk
|
||||
import Data.List (List)
|
||||
import Gyehoek.CPS.Syntax (cps)
|
||||
import Gyehoek.GenSym (runGenSym)
|
||||
import Effectful
|
||||
|
||||
|
||||
root :: IO TestTree
|
||||
root = pure . testGroup "stackify" $
|
||||
[ trivialReturn
|
||||
, tailCall
|
||||
, prim
|
||||
]
|
||||
|
||||
evalsTo :: List Obj -> Sut.Exp -> Assertion
|
||||
evalsTo rs e =
|
||||
Stk.eval e' @?= rs
|
||||
where e' = runPureEff . runGenSym $ Sut.stackifyExp "main" e
|
||||
|
||||
trivialReturn = testGroup "trivial return"
|
||||
[ testCase "return int" do
|
||||
evalsTo [ObjImm (ImmInt 4)]
|
||||
[cps|(continue halt 4)|]
|
||||
, testCase "return bool" do
|
||||
evalsTo [ObjImm (ImmBool True)]
|
||||
[cps|(continue halt #t)|]
|
||||
evalsTo [ObjImm (ImmBool False)]
|
||||
[cps|(continue halt #f)|]
|
||||
]
|
||||
|
||||
tailCall = testGroup "tail call"
|
||||
[ testCase "square" do
|
||||
evalsTo [ObjImm (ImmInt 16)]
|
||||
[cps|(letrec ((square (λ (x ktail)
|
||||
(prim (* x x)
|
||||
(κ (x0) (continue ktail x0))))))
|
||||
(square 4 halt))|]
|
||||
]
|
||||
|
||||
prim = testGroup "prim"
|
||||
[ testCase "multiply" do
|
||||
evalsTo [ObjImm (ImmInt 20)]
|
||||
[cps|(prim (* 4 5)
|
||||
(κ (x) (continue halt x)))|]
|
||||
, testCase "add" do
|
||||
evalsTo [ObjImm (ImmInt 9)]
|
||||
[cps|(prim (+ 4 5)
|
||||
(κ (x) (continue halt x)))|]
|
||||
]
|
||||
Reference in New Issue
Block a user