From 244109310ac55d4cd74ea9fd4c16e855ba581c0a Mon Sep 17 00:00:00 2001 From: joshvera Date: Fri, 9 Nov 2018 11:37:45 -0500 Subject: [PATCH] Add AbstractHole instances for Path, Scope, Address Co-Authored-By: Rick Winfrey --- src/Data/Abstract/ScopeGraph.hs | 14 ++++++++++++++ src/Semantic/Graph.hs | 13 ++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Data/Abstract/ScopeGraph.hs b/src/Data/Abstract/ScopeGraph.hs index b4e847840..e7dad3403 100644 --- a/src/Data/Abstract/ScopeGraph.hs +++ b/src/Data/Abstract/ScopeGraph.hs @@ -24,6 +24,7 @@ module Data.Abstract.ScopeGraph , scopeOfRef ) where +import Control.Abstract.Hole import Data.Abstract.Name import qualified Data.Map.Strict as Map import Data.Span @@ -41,6 +42,15 @@ data Scope scopeAddress = Scope { , declarations :: Seq (Declaration, (Span, Maybe scopeAddress)) } deriving (Eq, Show, Ord, Generic, NFData) +instance Lower (Scope scopeAddress) where + lowerBound = Scope mempty mempty mempty + +instance AbstractHole (Scope scopeAddress) where + hole = lowerBound + +instance AbstractHole address => AbstractHole (Address address) where + hole = Address hole (Position 0) + newtype Position = Position { unPosition :: Int } deriving (Eq, Show, Ord, Generic, NFData) @@ -57,10 +67,14 @@ deriving instance NFData scope => NFData (ScopeGraph scope) data Path scope where -- | Construct a direct path to a declaration. + Hole :: Path scope DPath :: Declaration -> Position -> Path scope -- | Construct an edge from a scope to another declaration path. EPath :: EdgeLabel -> scope -> Path scope -> Path scope +instance AbstractHole (Path scope) where + hole = Hole + deriving instance Eq scope => Eq (Path scope) deriving instance Show scope => Show (Path scope) deriving instance Ord scope => Ord (Path scope) diff --git a/src/Semantic/Graph.hs b/src/Semantic/Graph.hs index 67d7c41d5..030d605d4 100644 --- a/src/Semantic/Graph.hs +++ b/src/Semantic/Graph.hs @@ -422,17 +422,20 @@ resumingHeapError = runHeapErrorWith (\ baseError -> traceError "ScopeError" bas resumingScopeError :: ( Carrier sig m , Member Trace sig + , AbstractHole (Address address) + , AbstractHole (Scope address) + , AbstractHole (Path address) + , AbstractHole address , Show address , Ord address ) => Evaluator term address value (ResumableWithC (BaseError (ScopeError address)) (Eff m)) a -> Evaluator term address value m a resumingScopeError = runScopeErrorWith (\ baseError -> traceError "ScopeError" baseError *> case baseErrorException baseError of - ex -> undefined) - -- LookupError :: address -> HeapError address address - -- LookupLinksError :: address -> HeapError address (Map EdgeLabel (Map address address)) - -- LookupPathError :: Path address -> HeapError address address - + ScopeError decl span -> pure hole + LookupScopeError -> pure hole + LookupPathError decl -> pure hole + CurrentScopeError -> pure hole) resumingTypeError :: ( Carrier sig m , Member NonDet sig