From 8ff61d829964e7da19c9485389bad5f612131184 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 6 Dec 2018 10:09:50 -0500 Subject: [PATCH 1/4] Simplify the ValueRoots instance for closures. --- src/Data/Abstract/Value/Concrete.hs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Data/Abstract/Value/Concrete.hs b/src/Data/Abstract/Value/Concrete.hs index c778cd68a..50dd74ae3 100644 --- a/src/Data/Abstract/Value/Concrete.hs +++ b/src/Data/Abstract/Value/Concrete.hs @@ -50,10 +50,8 @@ data Value term address deriving (Eq, Ord, Show, Generic, NFData) -instance Ord address => ValueRoots address (Value term address) where - valueRoots v - | Closure _ _ _ _ _ _ _ <- v = undefined -- Env.addresses env - | otherwise = mempty +instance ValueRoots address (Value term address) where + valueRoots _ = lowerBound instance ( FreeVariables term From 4913b252b848adeeebad5c8aeebef524317fd2cf Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 6 Dec 2018 10:19:22 -0500 Subject: [PATCH 2/4] Define a helper for declaring functions/methods. --- src/Data/Syntax/Declaration.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Data/Syntax/Declaration.hs b/src/Data/Syntax/Declaration.hs index 31b062cc0..27cc4b62e 100644 --- a/src/Data/Syntax/Declaration.hs +++ b/src/Data/Syntax/Declaration.hs @@ -46,6 +46,23 @@ instance Evaluatable Function where v <- function name params functionBody associatedScope v <$ (value v >>= assign addr) +declareFunction :: ( Carrier sig m + , Member (State (ScopeGraph address)) sig + , Member (Allocator address) sig + , Member (Reader (address, address)) sig + , Member Fresh sig + , Ord address + ) + => Name + -> Span + -> Evaluator term address value m address +declareFunction name span = do + currentScope' <- currentScope + let lexicalEdges = Map.singleton Lexical [ currentScope' ] + associatedScope <- newScope lexicalEdges + declare (Declaration name) span (Just associatedScope) + pure associatedScope + instance Tokenize Function where tokenize Function{..} = within' Scope.Function $ do functionName From e65da03e850039cfe27e17e2cd1eca98ef9b0aac Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 6 Dec 2018 10:20:05 -0500 Subject: [PATCH 3/4] No we should not. --- src/Data/Syntax/Declaration.hs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Data/Syntax/Declaration.hs b/src/Data/Syntax/Declaration.hs index 27cc4b62e..82f6d6af8 100644 --- a/src/Data/Syntax/Declaration.hs +++ b/src/Data/Syntax/Declaration.hs @@ -31,7 +31,6 @@ instance Show1 Function where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Function where eval _ Function{..} = do name <- maybeM (throwEvalError NoNameError) (declaredName functionName) - -- TODO: Should we declare the name of the function within `function`? span <- ask @Span currentScope' <- currentScope let lexicalEdges = Map.singleton Lexical [ currentScope' ] @@ -91,7 +90,6 @@ instance Diffable Method where instance Evaluatable Method where eval _ Method{..} = do name <- maybeM (throwEvalError NoNameError) (declaredName methodName) - -- TODO: Should we declare the name of the function within `function`? span <- ask @Span currentScope' <- currentScope let lexicalEdges = Map.singleton Lexical [ currentScope' ] From fc19fa67db875dd463e19a8c2c83a73716b355a9 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 6 Dec 2018 10:20:51 -0500 Subject: [PATCH 4/4] Use declareFunction to define both Function and Method evaluation. --- src/Data/Syntax/Declaration.hs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Data/Syntax/Declaration.hs b/src/Data/Syntax/Declaration.hs index 82f6d6af8..630e6af29 100644 --- a/src/Data/Syntax/Declaration.hs +++ b/src/Data/Syntax/Declaration.hs @@ -32,10 +32,7 @@ instance Evaluatable Function where eval _ Function{..} = do name <- maybeM (throwEvalError NoNameError) (declaredName functionName) span <- ask @Span - currentScope' <- currentScope - let lexicalEdges = Map.singleton Lexical [ currentScope' ] - associatedScope <- newScope lexicalEdges - declare (Declaration name) span (Just associatedScope) + associatedScope <- declareFunction name span params <- withScope associatedScope . for functionParameters $ \paramNode -> do param <- maybeM (throwEvalError NoNameError) (declaredName paramNode) @@ -91,10 +88,7 @@ instance Evaluatable Method where eval _ Method{..} = do name <- maybeM (throwEvalError NoNameError) (declaredName methodName) span <- ask @Span - currentScope' <- currentScope - let lexicalEdges = Map.singleton Lexical [ currentScope' ] - associatedScope <- newScope lexicalEdges - declare (Declaration name) span (Just associatedScope) + associatedScope <- declareFunction name span params <- withScope associatedScope $ do let self = Name.name "__self"