1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 07:25:44 +03:00

Move resolve & listModulesInDir into the module table effect module.

This commit is contained in:
Rob Rix 2018-05-07 12:23:51 -04:00
parent 6557859772
commit b69a9d275d
2 changed files with 17 additions and 16 deletions

View File

@ -6,12 +6,14 @@ module Control.Abstract.ModuleTable
, askModuleTable
, askLoadStack
, localLoadStack
, resolve
, listModulesInDir
) where
import Control.Abstract.Evaluator
import Data.Abstract.Environment
import Data.Abstract.Module
import Data.Abstract.ModuleTable
import Data.Abstract.ModuleTable as ModuleTable
import Prologue
-- | Retrieve the table of evaluated modules.
@ -40,3 +42,17 @@ askLoadStack = raise ask
-- | Locally update the module load stack.
localLoadStack :: Member (Reader LoadStack) effects => (LoadStack -> LoadStack) -> Evaluator location term value effects a -> Evaluator location term value effects a
localLoadStack = raiseHandler . local
-- Resolve a list of module paths to a possible module table entry.
resolve :: Member (Reader (ModuleTable [Module term])) effects
=> [FilePath]
-> Evaluator location term value effects (Maybe ModulePath)
resolve names = do
tbl <- askModuleTable
pure $ find (`ModuleTable.member` tbl) names
listModulesInDir :: Member (Reader (ModuleTable [Module term])) effects
=> FilePath
-> Evaluator location term value effects [ModulePath]
listModulesInDir dir = modulePathsInDir dir <$> askModuleTable

View File

@ -19,9 +19,7 @@ module Data.Abstract.Evaluatable
, evaluatePackageWith
, evaluatePackageBodyWith
, throwEvalError
, resolve
, traceResolve
, listModulesInDir
, require
, load
, LoadStack
@ -231,22 +229,9 @@ instance Evaluatable [] where
eval = maybe unit (runApp . foldMap1 (App . subtermValue)) . nonEmpty
-- Resolve a list of module paths to a possible module table entry.
resolve :: Member (Reader (ModuleTable [Module term])) effects
=> [FilePath]
-> Evaluator location term value effects (Maybe ModulePath)
resolve names = do
tbl <- askModuleTable
pure $ find (`ModuleTable.member` tbl) names
traceResolve :: (Show a, Show b) => a -> b -> c -> c
traceResolve name path = trace ("resolved " <> show name <> " -> " <> show path)
listModulesInDir :: Member (Reader (ModuleTable [Module term])) effects
=> FilePath
-> Evaluator location term value effects [ModulePath]
listModulesInDir dir = ModuleTable.modulePathsInDir dir <$> askModuleTable
-- | Require/import another module by name and return it's environment and value.
--
-- Looks up the term's name in the cache of evaluated modules first, returns if found, otherwise loads/evaluates the module.