From ad480eb5fc2eaf2b2c8228b09fa2cc1a095d86ea Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 13 Feb 2018 16:28:03 -0800 Subject: [PATCH] Add envUnion and envAll functions --- src/Data/Abstract/Environment.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Data/Abstract/Environment.hs b/src/Data/Abstract/Environment.hs index a1f69b5e6..a07d8f7ae 100644 --- a/src/Data/Abstract/Environment.hs +++ b/src/Data/Abstract/Environment.hs @@ -6,6 +6,7 @@ import Data.Abstract.FreeVariables import Data.Abstract.Live import Data.Functor.Classes.Generic import qualified Data.Map as Map +import qualified Data.Set as Set import Data.Semigroup import GHC.Generics @@ -24,6 +25,8 @@ envLookup k = trace ("envLookup" <> show k) . Map.lookup k . unEnvironment envInsert :: Name -> Address l a -> Environment l a -> Environment l a envInsert name value (Environment m) = trace ("envInsert" <> show name) $ Environment (Map.insert name value m) +envUnion :: Environment l a -> Environment l a -> Environment l a +envUnion (Environment e1) (Environment e2) = Environment $ Map.union e1 e2 -- | Retrieve the 'Live' set of addresses to which the given free variable names are bound. -- @@ -31,6 +34,8 @@ envInsert name value (Environment m) = trace ("envInsert" <> show name) $ Enviro envRoots :: (Ord l, Foldable t) => Environment l a -> t Name -> Live l a envRoots env = foldr ((<>) . maybe mempty liveSingleton . flip envLookup env) mempty +envAll :: (Ord l) => Environment l a -> Live l a +envAll (Environment env) = Live $ Set.fromList (Map.elems env) -- Instances