From 5358e75a69fa0c70f48a7df2bd31ac53d14035b0 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 22 Jan 2020 16:37:23 -0500 Subject: [PATCH] Add withScope --- semantic-python/src/Language/Python/ScopeGraph.hs | 4 ++-- semantic-scope-graph/src/Control/Effect/Sketch.hs | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/semantic-python/src/Language/Python/ScopeGraph.hs b/semantic-python/src/Language/Python/ScopeGraph.hs index a6a873d84..5efc526ae 100644 --- a/semantic-python/src/Language/Python/ScopeGraph.hs +++ b/semantic-python/src/Language/Python/ScopeGraph.hs @@ -175,8 +175,8 @@ instance ToScopeGraph Py.FunctionDefinition where associatedScope <- newScope lexicalEdges let declProps = DeclProperties ScopeGraph.Function ScopeGraph.Default (Just associatedScope) name' <- declareMaybeName (Just $ Name.name name) declProps - -- withScope associatedScope $ - -- (for parameters $ declare parameter) <> scopeGraph body + withScope associatedScope $ pure () + -- (for parameters $ declare parameter) <> scopeGraph body complete instance ToScopeGraph Py.FutureImportStatement where scopeGraph = todo diff --git a/semantic-scope-graph/src/Control/Effect/Sketch.hs b/semantic-scope-graph/src/Control/Effect/Sketch.hs index 7313cd97d..8427d646f 100644 --- a/semantic-scope-graph/src/Control/Effect/Sketch.hs +++ b/semantic-scope-graph/src/Control/Effect/Sketch.hs @@ -18,8 +18,10 @@ module Control.Effect.Sketch , RefProperties (..) , FunProperties (..) , declare + -- Scope Manipulation , currentScope , newScope + , withScope , declareFunction , declareMaybeName , reference @@ -73,7 +75,7 @@ reference n decl props = send (Reference n decl props pure) newScope :: forall sig m . (Has Sketch sig m) => Map ScopeGraph.EdgeLabel [Name] -> m Name newScope edges = send (NewScope edges pure) -declareFunction :: forall sig m . (Has Sketch sig m, Has (Reader Name) sig m) => Maybe Name -> FunProperties -> m (Name, Name) +declareFunction :: forall sig m . (Has Sketch sig m) => Maybe Name -> FunProperties -> m (Name, Name) declareFunction name props = do currentScope' <- currentScope let lexicalEdges = Map.singleton ScopeGraph.Lexical [ currentScope' ] @@ -81,7 +83,7 @@ declareFunction name props = do name' <- declareMaybeName name (DeclProperties { relation = ScopeGraph.Default, kind = (getField @"kind" @FunProperties props), associatedScope = Just associatedScope }) pure (name', associatedScope) -declareMaybeName :: forall sig m . (Has Sketch sig m) +declareMaybeName :: Has Sketch sig m => Maybe Name -> DeclProperties -> m Name @@ -90,6 +92,11 @@ declareMaybeName maybeName props = do Just name -> declare name props >> pure name _ -> Name.gensym >>= \name -> declare name (props { relation = ScopeGraph.Gensym }) >> pure name -- TODO: Modify props and change Kind to Gensym +withScope :: Has Sketch sig m + => Name + -> m a + -> m a +withScope scope = local (const scope) -- declareFunction :: ( Has (State (ScopeGraph address)) sig m -- , Has (Allocator address) sig m -- , Has (Reader (CurrentScope address)) sig m