AbstractTypedSemanticsSpec.hs 5.14 KB
Newer Older
Sven Keidel's avatar
Sven Keidel committed
1 2 3 4 5 6 7 8
{-# LANGUAGE FlexibleContexts #-}
module AbstractTypedSemanticsSpec where

-- import           AbstractTypedSemantics
-- import           Sort
-- import           Signature (Signature)
-- import qualified Signature as S
-- import           InterpreterArrow
Jente Hidskes's avatar
Jente Hidskes committed
9
-- import           Paths_sturdy_stratego
Sven Keidel's avatar
Sven Keidel committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
-- import           Syntax(parseModule,Strat(..))

-- import           Data.ATerm(parseATerm)
-- import           Data.PowersetResult
-- import           Data.Result
-- import qualified Data.Term as T
-- import           Data.TermEnv
-- import qualified Data.Text.IO as TIO
-- import           Data.Foldable
-- import           Data.List

import           Test.Hspec


main :: IO ()
main = hspec spec

spec :: Spec
spec = return ()
  -- do
  
  -- let sig = S.empty & S.insertSubtype "String" "Expr"
  --                   & S.insertSubtype "INT" "Expr"
  --                   & S.insertType "Add" (S.Fun ["Expr", "Expr"] "Expr")

  -- it "lists should belong to the correct sort" $ do
  --   term' S.empty (T.Cons "Nil" []) `shouldMatchList` [Success (nil (List Bottom))]

  --   term' S.empty (T.Cons "Cons" [StringLiteral "foo", StringLiteral "bar"])
  --     `shouldMatchList` []

  --   term' S.empty (T.Cons "Cons" [StringLiteral "foo", nil (List Bottom)])
  --     `shouldMatchList` [Success (cons (StringLiteral "foo") (nil (List "String")) (List "String"))]

  --   term' sig (T.Cons "Cons" [StringLiteral "foo", nil (List Bottom)])
  --     `shouldMatchList` [Success (cons (StringLiteral "foo") (nil (List "String")) (List "String"))]

  --   let t = List (Coproduct "INT" "String")
  --     in term' sig (T.Cons "Cons" [NumberLiteral 1, cons (StringLiteral "foo") (nil (List "String")) (List "String")]) `shouldBe`
  --          [Success (cons (NumberLiteral 1) (cons (StringLiteral "foo") (nil t) t) t)]

  --   term' sig (T.Cons "Cons" [Wildcard Top, Wildcard Top])
  --     `shouldMatchList` [Success (cons (Wildcard Top) (Wildcard (List Top)) (List Top))]

  --   term' sig (T.Cons "Cons" [Wildcard "String", Wildcard Top])
  --     `shouldMatchList` [Success (cons (Wildcard "String") (Wildcard (List "String")) (List "String"))]

  --   term' sig (T.Cons "Cons" [Wildcard Top, Wildcard (List "String")])
  --     `shouldMatchList` [Success (cons (Wildcard Top) (Wildcard (List Top)) (List Top))]

  --   term' sig (T.Cons "Cons" [Wildcard Top, nil (List Bottom)])
  --     `shouldMatchList` [Success (cons (Wildcard Top) (nil (List Top)) (List Top))]

  --   term' sig (T.Cons "Cons" [NumberLiteral 1, cons (Wildcard Top) (nil (List Top)) (List Top)])
  --     `shouldMatchList` [Success (cons (NumberLiteral 1) (cons (Wildcard Top) (nil (List Top)) (List Top)) (List Top))]

  --   term' sig (T.Cons "Cons" [some (Wildcard Top) (Option Top), nil (List Bottom)])
  --     `shouldMatchList` [Success (cons (some (Wildcard Top) (Option Top)) (nil (List (Option Top))) (List (Option Top)))]

  --   term' sig (T.Cons "Add" [Wildcard Top, Wildcard Top])
  --     `shouldMatchList` [Success (Cons "Add" [Wildcard "Expr", Wildcard "Expr"] "Expr")]

  --   term' sig (T.Cons "Add" [NumberLiteral 1, Wildcard Top])
  --     `shouldMatchList` [Success (Cons "Add" [NumberLiteral 1, Wildcard "Expr"] "Expr")]

  --   term' sig (T.Cons "Add" [StringLiteral "foo", Wildcard Top])
  --     `shouldMatchList` [Success (Cons "Add" [StringLiteral "foo", Wildcard "Expr"] "Expr")]


  -- it "should refine wildcards on matching" $ do
  --   matchTerm' sig (Wildcard (Tuple [List (Tuple ["String","Expr"]), "Expr"]))
  --     `shouldMatchList` [Success (T.Cons "" [Wildcard (List (Tuple ["String", "Expr"])), Wildcard "Expr"])]

  --   matchTerm' sig (Wildcard (List (Tuple ["String","Expr"])))
  --     `shouldMatchList` [Success (T.Cons "Nil" []),
  --                        Success (T.Cons "Cons" [Wildcard (Tuple ["String", "Expr"]),
  --                                                Wildcard (List (Tuple ["String", "Expr"]))])]

  --   nub (matchTerm' sig (Wildcard "Expr"))
  --     `shouldMatchList` [Success (T.Cons "Add" [Wildcard "Expr", Wildcard "Expr"]), Success T.Wildcard]

  -- describe "Case Studies" $ describe "PCF" $ beforeAll parsePCFCaseStudy $
  --   it "should execute well typed programs without a problem" $ \m ->
  --     evalPCF 3 m (Wildcard (Tuple [List (Tuple ["String","Exp"]), "Exp"]))
  --       `shouldSatisfy` not . null

  -- where 
  --   term' :: Signature -> T.TermF Term -> [Result Term]
  --   term' sig t = fmap fst <$> toList (unPowRes (runInterp T.term (sig,()) (t,())))

  --   matchTerm' :: Signature -> Term -> [Result (T.TermF Term)]
  --   matchTerm' sig t = fmap fst <$> toList (unPowRes (runInterp T.matchTerm (sig,()) (t,())))

  --   cons :: Term -> Term -> Sort -> Term
  --   cons x xs = Cons "Cons" [x,xs]

  --   some :: Term -> Sort -> Term
  --   some x = Cons "Some" [x]

  --   nil :: Sort -> Term
  --   nil = Cons "Nil" []

  --   (&) = flip ($)

  --   evalPCF n module_ t = toList $ unPowRes $ evalModule n module_ (Call "eval_0_0" [] []) (t,abstractTermEnv [])

  --   parsePCFCaseStudy = do
  --     file <- TIO.readFile =<< getDataFileName "case-studies/pcf/pcf.aterm"
  --     case parseModule =<< parseATerm file of
  --       Left e -> fail (show e)
  --       Right module_ -> return module_