summaryrefslogtreecommitdiff
path: root/prototypes
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-04-10 22:35:30 +0200
committerPéter Diviánszky <divipp@gmail.com>2016-04-10 22:35:30 +0200
commit1b6d0c364d2f1e204c4dbeb61ee5e6ab3d316275 (patch)
tree6a655dcf3d64c779fb91efc667ca6381ab3f5908 /prototypes
parent7e13b27715de9c05054c03b19e385d93811b06e5 (diff)
more test
Diffstat (limited to 'prototypes')
-rw-r--r--prototypes/ShiftReducer.hs19
1 files changed, 16 insertions, 3 deletions
diff --git a/prototypes/ShiftReducer.hs b/prototypes/ShiftReducer.hs
index fc29286e..178cbc6c 100644
--- a/prototypes/ShiftReducer.hs
+++ b/prototypes/ShiftReducer.hs
@@ -516,10 +516,11 @@ pushLet' (Shift u l) = case l of
516hnf :: SLExp -> SLExp 516hnf :: SLExp -> SLExp
517hnf exp@(Shift u (NoLet e)) = case e of 517hnf exp@(Shift u (NoLet e)) = case e of
518 EApp f x -> up u $ apl (NoLet <$> f) (NoLet <$> x) 518 EApp f x -> up u $ apl (NoLet <$> f) (NoLet <$> x)
519 ELam{} -> exp
520 ELit{} -> exp
521 Delta "add" [Int i, Int j] -> Int $ j + i 519 Delta "add" [Int i, Int j] -> Int $ j + i
520 Delta "whenLE" [Int x, f, Int y] -> if y < x then hnf $ f `app` Int y else Int y
522 Delta{} -> exp 521 Delta{} -> exp
522 ELam{} -> exp
523 ELit{} -> exp
523 x -> error $ "hnf: " ++ show x 524 x -> error $ "hnf: " ++ show x
524hnf exp@(Shift u (HasLet (Let m e'@(Shift u' e)))) = case NoLet <$> e' of 525hnf exp@(Shift u (HasLet (Let m e'@(Shift u' e)))) = case NoLet <$> e' of
525 Var i -> case Map.lookup i m of 526 Var i -> case Map.lookup i m of
@@ -534,6 +535,7 @@ apl f x = case hnf f of
534 x -> error $ "apl: " ++ show x 535 x -> error $ "apl: " ++ show x
535 where 536 where
536 arity "add" = 2 537 arity "add" = 2
538 arity "whenLE" = 3
537 539
538 540
539{- 541{-
@@ -563,9 +565,14 @@ idE = lam $ Var 0
563add :: SLExp 565add :: SLExp
564add = NoLet <$> mkShift (Delta "add" []) 566add = NoLet <$> mkShift (Delta "add" [])
565 567
568whenLE = NoLet <$> mkShift (Delta "whenLE" [])
569
566suc :: SLExp 570suc :: SLExp
567suc = lam $ add `app` Int 1 `app` Var 0 571suc = lam $ add `app` Int 1 `app` Var 0
568 572
573double :: SLExp
574double = lam $ add `app` Var 0 `app` Var 0
575
569-------- 576--------
570 577
571id_test = hnf (idE `app` Int 10) == Int 10 578id_test = hnf (idE `app` Int 10) == Int 10
@@ -574,11 +581,17 @@ add_test = hnf (add `app` Int 10 `app` Int 20) == Int 30
574 581
575succ_test = hnf (suc `app` Int 10) == Int 11 582succ_test = hnf (suc `app` Int 10) == Int 11
576 583
584double_test = hnf (iterateN 5 (double `app`) $ Int 1) == Int 32
585
586mutual_test = hnf $ lets_ (Map.fromList [ (0, lam $ Var 2 `app` Var 0)
587 , (1, lam $ whenLE `app` Int 100 `app` Var 1 `app` Var 0)
588 ])
589 $ Var 0 `app` Int 0
577 590
578----------------------------------------------------------------- run all tests 591----------------------------------------------------------------- run all tests
579 592
580return [] 593return []
581runTests | mkLet_test1 && id_test && add_test && succ_test = $quickCheckAll 594runTests | mkLet_test1 && id_test && add_test && succ_test && double_test = $quickCheckAll
582 595
583{- 596{-
584TODO 597TODO