@@ -8,6 +8,7 @@ import Data.List (List)
|
||||
import Gyehoek.CPS.Syntax (cps)
|
||||
import Gyehoek.GenSym (runGenSym)
|
||||
import Effectful
|
||||
import Test.Tasty.ExpectedFailure (expectFail)
|
||||
|
||||
|
||||
root :: IO TestTree
|
||||
@@ -15,6 +16,8 @@ root = pure . testGroup "stackify" $
|
||||
[ trivialReturn
|
||||
, tailCall
|
||||
, prim
|
||||
, condition
|
||||
, procedure
|
||||
]
|
||||
|
||||
evalsTo :: List Obj -> Sut.Exp -> Assertion
|
||||
@@ -52,3 +55,28 @@ prim = testGroup "prim"
|
||||
[cps|(prim (+ 4 5)
|
||||
(κ (x) (continue halt x)))|]
|
||||
]
|
||||
|
||||
condition = testCase "if" do
|
||||
evalsTo [ObjImm (ImmInt 123)]
|
||||
[cps|(if #t (continue halt 123) (continue halt 456))|]
|
||||
evalsTo [ObjImm (ImmInt 456)]
|
||||
[cps|(if #f (continue halt 123) (continue halt 456))|]
|
||||
|
||||
procedure = testGroup "procedure"
|
||||
[ expectFail $ testCase "factorial" do
|
||||
evalsTo [ObjImm (ImmInt 720)]
|
||||
[cps|(letrec ((fac (λ (n ktail)
|
||||
(prim (zero? n)
|
||||
(κ (x0)
|
||||
(if x0
|
||||
(continue ktail 1)
|
||||
(prim (- n 1)
|
||||
(κ (x1)
|
||||
(letrec ((fac-k0
|
||||
(κ (x2)
|
||||
(prim (* n x2)
|
||||
(κ (x3)
|
||||
(continue ktail x3))))))
|
||||
(fac x1 fac-k0))))))))))
|
||||
(fac 6 halt))|]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user