2018-05-08 17:19:50 +03:00
|
|
|
{-# LANGUAGE TypeOperators #-}
|
2018-05-09 19:36:40 +03:00
|
|
|
module Control.Abstract.Evaluator.Spec
|
|
|
|
( spec
|
|
|
|
) where
|
2018-05-07 21:21:05 +03:00
|
|
|
|
2018-05-07 22:10:11 +03:00
|
|
|
import Analysis.Abstract.Evaluating (evaluating)
|
2018-05-07 22:09:50 +03:00
|
|
|
import Control.Abstract
|
|
|
|
import Data.Abstract.Module
|
|
|
|
import qualified Data.Abstract.Number as Number
|
|
|
|
import Data.Abstract.Package
|
2018-05-09 19:39:22 +03:00
|
|
|
import Data.Abstract.Value as Value
|
2018-05-07 22:19:57 +03:00
|
|
|
import Data.Algebra
|
2018-05-07 23:56:40 +03:00
|
|
|
import Data.Bifunctor (first)
|
|
|
|
import Data.Functor.Const
|
2018-05-08 17:19:50 +03:00
|
|
|
import Data.Semilattice.Lower
|
2018-05-07 23:56:40 +03:00
|
|
|
import Data.Sum
|
2018-05-09 19:36:48 +03:00
|
|
|
import SpecHelpers hiding (reassociate)
|
2018-05-07 21:21:05 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
2018-05-07 22:10:41 +03:00
|
|
|
spec = parallel $ do
|
|
|
|
it "constructs integers" $ do
|
2018-05-07 22:13:01 +03:00
|
|
|
(expected, _) <- evaluate (integer 123)
|
2018-05-09 19:39:22 +03:00
|
|
|
expected `shouldBe` Right (injValue (Value.Integer (Number.Integer 123)))
|
2018-05-07 22:09:50 +03:00
|
|
|
|
2018-05-07 23:06:21 +03:00
|
|
|
it "calls functions" $ do
|
|
|
|
(expected, _) <- evaluate $ do
|
2018-05-08 17:54:32 +03:00
|
|
|
identity <- closure [name "x"] lowerBound (variable (name "x"))
|
2018-05-07 23:06:21 +03:00
|
|
|
call identity [integer 123]
|
2018-05-09 19:39:22 +03:00
|
|
|
expected `shouldBe` Right (injValue (Value.Integer (Number.Integer 123)))
|
2018-05-07 23:06:21 +03:00
|
|
|
|
2018-05-07 22:10:11 +03:00
|
|
|
evaluate
|
2018-05-07 22:13:01 +03:00
|
|
|
= runM
|
2018-05-07 23:56:40 +03:00
|
|
|
. fmap (first reassociate)
|
2018-05-07 22:10:11 +03:00
|
|
|
. evaluating
|
|
|
|
. runReader (PackageInfo (name "test") Nothing)
|
|
|
|
. runReader (ModuleInfo "test/Control/Abstract/Evaluator/Spec.hs")
|
|
|
|
. Value.runValueError
|
2018-05-07 23:06:04 +03:00
|
|
|
. runEnvironmentError
|
2018-05-07 22:10:11 +03:00
|
|
|
. runAddressError
|
2018-05-08 17:19:50 +03:00
|
|
|
. runReturn
|
|
|
|
. runLoopControl
|
2018-05-08 18:10:35 +03:00
|
|
|
. fmap fst
|
2018-05-10 04:30:34 +03:00
|
|
|
. runState (Gotos lowerBound)
|
|
|
|
. runGoto Gotos getGotos
|
2018-05-08 17:19:50 +03:00
|
|
|
. constraining
|
|
|
|
|
2018-05-10 04:30:34 +03:00
|
|
|
newtype Gotos effects = Gotos { getGotos :: GotoTable (State (Gotos effects) ': effects) (Value Precise) }
|
|
|
|
|
2018-05-09 19:39:22 +03:00
|
|
|
constraining :: Evaluator Precise (Value Precise) effects a -> Evaluator Precise (Value Precise) effects a
|
2018-05-08 17:19:50 +03:00
|
|
|
constraining = id
|
2018-05-07 22:10:11 +03:00
|
|
|
|
2018-05-09 19:39:22 +03:00
|
|
|
reassociate :: Either Prelude.String (Either (SomeExc exc1) (Either (SomeExc exc2) (Either (SomeExc exc3) result))) -> Either (SomeExc (Sum '[Const Prelude.String, exc1, exc2, exc3])) result
|
2018-05-07 23:56:40 +03:00
|
|
|
reassociate (Left s) = Left (SomeExc (injectSum (Const s)))
|
|
|
|
reassociate (Right (Right (Right (Right a)))) = Right a
|