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:09:50 +03:00
|
|
|
import Control.Abstract
|
2018-08-13 16:43:37 +03:00
|
|
|
import Data.Abstract.Address.Precise as Precise
|
2018-08-08 02:50:55 +03:00
|
|
|
import Data.Abstract.BaseError
|
2018-08-15 08:19:08 +03:00
|
|
|
import Data.Abstract.Environment
|
2018-09-25 22:41:57 +03:00
|
|
|
import Data.Abstract.FreeVariables
|
2018-05-07 22:09:50 +03:00
|
|
|
import Data.Abstract.Module
|
|
|
|
import qualified Data.Abstract.Number as Number
|
|
|
|
import Data.Abstract.Package
|
2018-07-03 21:22:26 +03:00
|
|
|
import Data.Abstract.Value.Concrete 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)
|
2018-07-26 22:31:49 +03:00
|
|
|
import Data.Coerce
|
2018-05-07 23:56:40 +03:00
|
|
|
import Data.Functor.Const
|
|
|
|
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-06-22 20:52:21 +03:00
|
|
|
(_, expected) <- evaluate (box (integer 123))
|
2018-06-02 00:28:19 +03:00
|
|
|
expected `shouldBe` Right (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
|
2018-06-22 20:52:21 +03:00
|
|
|
(_, expected) <- evaluate $ do
|
2018-09-25 22:41:57 +03:00
|
|
|
identity <- function Nothing [name "x"] (coerce (variable (name "x")))
|
2018-07-24 09:23:53 +03:00
|
|
|
recv <- box unit
|
2018-07-23 17:26:26 +03:00
|
|
|
addr <- box (integer 123)
|
2018-08-01 04:41:17 +03:00
|
|
|
call identity recv [addr]
|
2018-06-02 00:28:19 +03:00
|
|
|
expected `shouldBe` Right (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-10-24 16:47:24 +03:00
|
|
|
. runTraceByIgnoring
|
2018-08-09 23:13:03 +03:00
|
|
|
. runState (lowerBound @(Heap Precise Val))
|
2018-10-24 16:47:24 +03:00
|
|
|
. runFresh
|
2018-06-22 17:38:03 +03:00
|
|
|
. runReader (PackageInfo (name "test") mempty)
|
2018-05-07 22:10:11 +03:00
|
|
|
. runReader (ModuleInfo "test/Control/Abstract/Evaluator/Spec.hs")
|
2018-08-06 19:29:24 +03:00
|
|
|
. runReader (lowerBound @Span)
|
2018-06-06 16:46:12 +03:00
|
|
|
. fmap reassociate
|
2018-05-28 21:47:20 +03:00
|
|
|
. runValueError
|
2018-05-07 23:06:04 +03:00
|
|
|
. runEnvironmentError
|
2018-05-07 22:10:11 +03:00
|
|
|
. runAddressError
|
2018-10-24 17:01:55 +03:00
|
|
|
. runDeref @_ @_ @Val
|
|
|
|
. runAllocator
|
2018-06-22 20:52:21 +03:00
|
|
|
. (>>= deref . snd)
|
2018-05-30 20:03:50 +03:00
|
|
|
. runEnv lowerBound
|
2018-05-08 17:19:50 +03:00
|
|
|
. runReturn
|
|
|
|
. runLoopControl
|
2018-10-24 17:01:55 +03:00
|
|
|
. runBoolean
|
|
|
|
. runFunction coerce
|
2018-05-10 04:30:34 +03:00
|
|
|
|
2018-10-22 16:53:59 +03:00
|
|
|
reassociate :: Either (SomeError exc1) (Either (SomeError exc2) (Either (SomeError exc3) result)) -> Either (SomeError (Sum '[exc3, exc2, exc1])) result
|
|
|
|
reassociate = mergeErrors . mergeErrors . mergeErrors . Right
|
2018-06-13 23:35:17 +03:00
|
|
|
|
2018-09-26 00:38:05 +03:00
|
|
|
type Val = Value SpecEff Precise
|
2018-09-25 22:41:57 +03:00
|
|
|
newtype SpecEff = SpecEff
|
2018-10-24 16:47:24 +03:00
|
|
|
{ runSpecEff :: Eff (FunctionC SpecEff Precise Val
|
|
|
|
(Eff (BooleanC Val
|
|
|
|
(Eff (ErrorC (LoopControl Precise)
|
|
|
|
(Eff (ErrorC (Return Precise)
|
|
|
|
(Eff (EnvC Precise
|
|
|
|
(Eff (AllocatorC Precise
|
|
|
|
(Eff (DerefC Val
|
|
|
|
(Eff (ResumableC (BaseError (AddressError Precise Val))
|
|
|
|
(Eff (ResumableC (BaseError (EnvironmentError Precise))
|
|
|
|
(Eff (ResumableC (BaseError (ValueError SpecEff Precise))
|
|
|
|
(Eff (ReaderC Span
|
|
|
|
(Eff (ReaderC ModuleInfo
|
|
|
|
(Eff (ReaderC PackageInfo
|
|
|
|
(Eff (FreshC
|
|
|
|
(Eff (StateC (Heap Precise Val)
|
|
|
|
(Eff (TraceByIgnoringC
|
|
|
|
(Eff (LiftC IO)))))))))))))))))))))))))))))))))
|
|
|
|
Precise
|
2018-06-13 23:35:17 +03:00
|
|
|
}
|
2018-09-25 22:41:57 +03:00
|
|
|
|
|
|
|
instance Eq SpecEff where _ == _ = True
|
|
|
|
instance Show SpecEff where show _ = "_"
|
|
|
|
instance FreeVariables SpecEff where freeVariables _ = lowerBound
|