diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-04-10 22:35:30 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-04-10 22:35:30 +0200 |
commit | 1b6d0c364d2f1e204c4dbeb61ee5e6ab3d316275 (patch) | |
tree | 6a655dcf3d64c779fb91efc667ca6381ab3f5908 /prototypes | |
parent | 7e13b27715de9c05054c03b19e385d93811b06e5 (diff) |
more test
Diffstat (limited to 'prototypes')
-rw-r--r-- | prototypes/ShiftReducer.hs | 19 |
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 | |||
516 | hnf :: SLExp -> SLExp | 516 | hnf :: SLExp -> SLExp |
517 | hnf exp@(Shift u (NoLet e)) = case e of | 517 | hnf 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 |
524 | hnf exp@(Shift u (HasLet (Let m e'@(Shift u' e)))) = case NoLet <$> e' of | 525 | hnf 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 | |||
563 | add :: SLExp | 565 | add :: SLExp |
564 | add = NoLet <$> mkShift (Delta "add" []) | 566 | add = NoLet <$> mkShift (Delta "add" []) |
565 | 567 | ||
568 | whenLE = NoLet <$> mkShift (Delta "whenLE" []) | ||
569 | |||
566 | suc :: SLExp | 570 | suc :: SLExp |
567 | suc = lam $ add `app` Int 1 `app` Var 0 | 571 | suc = lam $ add `app` Int 1 `app` Var 0 |
568 | 572 | ||
573 | double :: SLExp | ||
574 | double = lam $ add `app` Var 0 `app` Var 0 | ||
575 | |||
569 | -------- | 576 | -------- |
570 | 577 | ||
571 | id_test = hnf (idE `app` Int 10) == Int 10 | 578 | id_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 | ||
575 | succ_test = hnf (suc `app` Int 10) == Int 11 | 582 | succ_test = hnf (suc `app` Int 10) == Int 11 |
576 | 583 | ||
584 | double_test = hnf (iterateN 5 (double `app`) $ Int 1) == Int 32 | ||
585 | |||
586 | mutual_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 | ||
580 | return [] | 593 | return [] |
581 | runTests | mkLet_test1 && id_test && add_test && succ_test = $quickCheckAll | 594 | runTests | mkLet_test1 && id_test && add_test && succ_test && double_test = $quickCheckAll |
582 | 595 | ||
583 | {- | 596 | {- |
584 | TODO | 597 | TODO |