1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 06:11:49 +03:00

Removing holding onto val in Interface

This commit is contained in:
Timothy Clem 2018-02-26 15:49:13 -08:00
parent ca21d42399
commit 16a4341505
3 changed files with 9 additions and 10 deletions

View File

@ -40,7 +40,7 @@ instance (Ord location) => Ord1 (Closure location) where liftCompare = genericLi
instance (Show location) => Show1 (Closure location) where liftShowsPrec = genericLiftShowsPrec
-- | A program value consisting of the value of the program and it's enviornment of bindings.
data Interface location term = Interface (Value location term) (Environment location (Value location term))
newtype Interface location term = Interface (Environment location (Value location term))
deriving (Eq, Generic1, Ord, Show)
instance (Eq location) => Eq1 (Interface location) where liftEq = genericLiftEq
@ -116,7 +116,7 @@ class AbstractValue v where
instance (FreeVariables term, Ord location) => ValueRoots location (Value location term) where
valueRoots v
| Just (Closure names body env) <- prj v = envRoots env (foldr Set.delete (freeVariables body) names)
| Just (Interface _ env) <- prj v = envAll env
| Just (Interface env) <- prj v = envAll env
| otherwise = mempty
-- | Construct a 'Value' wrapping the value arguments (if any).

View File

@ -160,10 +160,10 @@ instance ( Ord (LocationFor (Value l t))
=> Evaluatable es t (Value l t) Program where
eval (Program xs) = eval' xs
where
interface val = inj . Value.Interface val <$> ask @(EnvironmentFor (Value l t))
interface = inj . Value.Interface <$> ask @(EnvironmentFor (Value l t))
eval' [] = interface unit
eval' [x] = step x >>= interface
eval' [] = interface
eval' [x] = step @(Value l t) x >> interface
eval' (x:xs) = do
_ <- step @(Value l t) x
env <- get @(EnvironmentFor (Value l t))

View File

@ -288,11 +288,10 @@ instance ( Show l
=> Evaluatable es t (Value l t) Import where
eval (Import from _ _) = do
interface <- require @(Value l t) @t from
-- TODO: Consider returning the value instead of the interface.
Interface _ env <- maybe
(fail ("expected an interface, but got: " <> show interface))
pure
(prj interface :: Maybe (Value.Interface l t))
Interface env <- maybe
(fail ("expected an interface, but got: " <> show interface))
pure
(prj interface :: Maybe (Value.Interface l t))
modify (envUnion env)
pure interface