1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 13:51:44 +03:00

Streamline this code a bit, no functional changes

This commit is contained in:
Timothy Clem 2018-03-02 16:33:27 -08:00
parent 7b4b35cb5e
commit ab71814900
2 changed files with 8 additions and 11 deletions

View File

@ -29,6 +29,9 @@ class (MonadEvaluator t v m) => MonadValue t v m where
-- | Construct an abstract string value.
string :: ByteString -> m v
-- | Construct an abstract interface value.
interface :: v -> m v
-- | Eliminate boolean values. TODO: s/boolean/truthy
ifthenelse :: v -> m v -> m v -> m v
@ -40,8 +43,6 @@ class (MonadEvaluator t v m) => MonadValue t v m where
-- | Extract the environment from an interface value.
environment :: v -> m (EnvironmentFor v)
interface :: v -> m v
-- | Construct a 'Value' wrapping the value arguments (if any).
instance ( FreeVariables t
, MonadAddressable location (Value location t) m

View File

@ -232,20 +232,16 @@ instance Evaluatable Import2 where
env <- getGlobalEnv
putGlobalEnv mempty
importedEnv <- require name
env' <- Map.foldrWithKey (\k v rest -> do
if Map.null symbols
-- Copy over all symbols in the environment under their qualified names.
then envInsert (prefix <> k) v <$> rest
-- Only copy over specified symbols, possibly aliasing them.
else maybe rest (\symAlias -> envInsert symAlias v <$> rest) (Map.lookup k symbols)
) (pure env) (unEnvironment importedEnv)
env' <- Map.foldrWithKey copy (pure env) (unEnvironment importedEnv)
modifyGlobalEnv (const env')
unit
where
name = qualifiedName (subterm from)
symbols = Map.fromList xs
prefix = qualifiedName (subterm alias) <> "."
symbols = Map.fromList xs
copy = if Map.null symbols then qualifyInsert else directInsert
qualifyInsert k v rest = envInsert (prefix <> k) v <$> rest
directInsert k v rest = maybe rest (\symAlias -> envInsert symAlias v <$> rest) (Map.lookup k symbols)
-- | A wildcard import