1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 22:01:46 +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. -- | Construct an abstract string value.
string :: ByteString -> m v string :: ByteString -> m v
-- | Construct an abstract interface value.
interface :: v -> m v
-- | Eliminate boolean values. TODO: s/boolean/truthy -- | Eliminate boolean values. TODO: s/boolean/truthy
ifthenelse :: v -> m v -> m v -> m v 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. -- | Extract the environment from an interface value.
environment :: v -> m (EnvironmentFor v) environment :: v -> m (EnvironmentFor v)
interface :: v -> m v
-- | Construct a 'Value' wrapping the value arguments (if any). -- | Construct a 'Value' wrapping the value arguments (if any).
instance ( FreeVariables t instance ( FreeVariables t
, MonadAddressable location (Value location t) m , MonadAddressable location (Value location t) m

View File

@ -232,20 +232,16 @@ instance Evaluatable Import2 where
env <- getGlobalEnv env <- getGlobalEnv
putGlobalEnv mempty putGlobalEnv mempty
importedEnv <- require name importedEnv <- require name
env' <- Map.foldrWithKey (\k v rest -> do env' <- Map.foldrWithKey copy (pure env) (unEnvironment importedEnv)
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)
modifyGlobalEnv (const env') modifyGlobalEnv (const env')
unit unit
where where
name = qualifiedName (subterm from) name = qualifiedName (subterm from)
symbols = Map.fromList xs
prefix = qualifiedName (subterm alias) <> "." 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 -- | A wildcard import