1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 05:41:54 +03:00
semantic/test/Control/Abstract/Evaluator/Spec.hs

75 lines
2.4 KiB
Haskell
Raw Normal View History

{-# 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
import Control.Abstract
import Data.Abstract.Address.Precise as Precise
2018-08-08 02:50:55 +03:00
import Data.Abstract.BaseError
import Data.Abstract.Module
import qualified Data.Abstract.Number as Number
import Data.Abstract.Package
import Data.Abstract.Value.Concrete as Value
import Data.Algebra
2018-05-07 23:56:40 +03:00
import Data.Bifunctor (first)
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))
expected `shouldBe` Right (Value.Integer (Number.Integer 123))
2018-05-07 23:06:21 +03:00
it "calls functions" $ do
2018-06-22 20:52:21 +03:00
(_, expected) <- evaluate $ do
2018-07-23 17:26:06 +03:00
identity <- function [name "x"] lowerBound (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)
call identity recv [addr]
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-08-09 23:13:03 +03:00
. runState (lowerBound @(Heap Precise Val))
2018-06-20 19:17:46 +03:00
. runFresh 0
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-08-13 17:06:12 +03:00
. Precise.runDeref @_ @Val
. Precise.runAllocator
2018-06-22 20:52:21 +03:00
. (>>= deref . snd)
2018-05-30 20:03:50 +03:00
. runEnv lowerBound
. runReturn
. runLoopControl
. Value.runFunction coerce coerce
2018-06-06 16:46:12 +03:00
reassociate :: Either (SomeExc exc1) (Either (SomeExc exc2) (Either (SomeExc exc3) result)) -> Either (SomeExc (Sum '[exc3, exc2, exc1])) result
reassociate = mergeExcs . mergeExcs . mergeExcs . Right
type Val = Value Precise SpecEff
newtype SpecEff a = SpecEff
{ runSpecEff :: Eff '[ Function Precise Val
, Exc (LoopControl Precise)
2018-06-26 19:00:25 +03:00
, Exc (Return Precise)
, Env Precise
, Allocator Precise
, Deref Val
2018-08-06 19:29:24 +03:00
, Resumable (BaseError (AddressError Precise Val))
, Resumable (BaseError (EnvironmentError Precise))
, Resumable (BaseError (ValueError Precise SpecEff))
, Reader Span
, Reader ModuleInfo
, Reader PackageInfo
, Fresh
2018-08-09 23:13:03 +03:00
, State (Heap Precise Val)
2018-06-22 20:52:21 +03:00
, Lift IO
] a
}