diff --git a/src/Analysis/Abstract/Evaluating.hs b/src/Analysis/Abstract/Evaluating.hs index 23b77ff64..8ed44fb12 100644 --- a/src/Analysis/Abstract/Evaluating.hs +++ b/src/Analysis/Abstract/Evaluating.hs @@ -3,6 +3,7 @@ module Analysis.Abstract.Evaluating where import Control.Effect import Control.Monad.Effect hiding (run) +import Control.Monad.Effect.Env import Control.Monad.Effect.Address import Control.Monad.Effect.Linker import Control.Monad.Effect.Fail @@ -11,6 +12,7 @@ import Control.Monad.Effect.State import Data.Abstract.Address import Data.Abstract.Environment import Data.Abstract.Linker +import Data.Abstract.FreeVariables import Data.Abstract.Eval import Data.Abstract.Store import Data.Abstract.Value @@ -55,6 +57,8 @@ evaluates :: forall v term , AbstractValue v , MonadAddress (LocationFor v) (Eff (Evaluating v)) -- , MonadLinker v (Eff (Evaluating v)) + -- , MonadEnv v (Eff (Evaluating v)) + , FreeVariables term , Eval term v (Eff (Evaluating v)) (Base term) ) => [(FilePath, term)] @@ -62,8 +66,25 @@ evaluates :: forall v term evaluates = run @(Evaluating v) . fix go pure where go _ yield [] = yield unit - go recur yield [(f, a)] = trace ("[]:" <> show f) $ eval (\_ term -> recur pure [(f, term)]) yield (project a) + go recur yield [(f, a)] = trace (show f) $ eval (\ev term -> recur ev [(f, term)]) yield (project a) go recur yield ((f, a):as) = do - x <- trace ("[a:as] " <> show f) $ - eval (const (const (go recur pure as))) pure (project a) - localLinker (linkerInsert f x) (yield x) + env <- askEnv :: (Eff (Evaluating v)) (Environment (LocationFor v) v) + v <- trace (show f) $ eval (\ev term -> recur ev [(f, term)]) pure (project a) + extraRoots (envRoots env (freeVariables a)) $ + localLinker (linkerInsert f v) (go recur yield as) + + -- go recur yield [(f, a)] = trace ("[] " <> show f) $ eval (\ev term -> recur ev [(f, term)]) pure (project a) >>= yield + -- go recur yield [(f, a)] = trace ("[]:" <> show f) $ eval (\_ term -> recur pure [(f, term)]) yield (project a) + -- go recur yield [(f, a)] = do + -- x <- trace (show f) $ eval (\ev term -> recur ev [(f, term)]) pure (project a) + -- localLinker (linkerInsert f x) (yield x) + -- go recur yield ((f, a):as) = do + -- trace ("[a:as] " <> show f) $ + -- eval (const (const (go recur pure as))) yield (project a) + + -- linker <- askLinker :: (Eff (Evaluating v)) (Linker v) + -- todo: local linker and linkerInsert + -- go recur yield ((f, a):as) = do + -- x <- trace ("[a:as] " <> show f) $ + -- eval (const (const (go recur pure as))) pure (project a) + -- localLinker (linkerInsert f x) (yield x) diff --git a/src/Data/Abstract/Environment.hs b/src/Data/Abstract/Environment.hs index 20d0c4c5d..498ff24fd 100644 --- a/src/Data/Abstract/Environment.hs +++ b/src/Data/Abstract/Environment.hs @@ -9,6 +9,8 @@ import qualified Data.Map as Map import Data.Semigroup import GHC.Generics +import Debug.Trace + -- | A map of names to addresses that represents the evaluation environment. newtype Environment l a = Environment { unEnvironment :: Map.Map Name (Address l a) } @@ -16,7 +18,7 @@ newtype Environment l a = Environment { unEnvironment :: Map.Map Name (Address l -- | Lookup a 'Name' in the environment. envLookup :: Name -> Environment l a -> Maybe (Address l a) -envLookup = (. unEnvironment) . Map.lookup +envLookup k = trace ("envLookup" <> show k) . Map.lookup k . unEnvironment -- | Insert a 'Name' in the environment. envInsert :: Name -> Address l a -> Environment l a -> Environment l a