mirror of
https://github.com/github/semantic.git
synced 2024-12-24 15:35:14 +03:00
Move resolve & listModulesInDir into the module table effect module.
This commit is contained in:
parent
6557859772
commit
b69a9d275d
@ -6,12 +6,14 @@ module Control.Abstract.ModuleTable
|
|||||||
, askModuleTable
|
, askModuleTable
|
||||||
, askLoadStack
|
, askLoadStack
|
||||||
, localLoadStack
|
, localLoadStack
|
||||||
|
, resolve
|
||||||
|
, listModulesInDir
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Abstract.Evaluator
|
import Control.Abstract.Evaluator
|
||||||
import Data.Abstract.Environment
|
import Data.Abstract.Environment
|
||||||
import Data.Abstract.Module
|
import Data.Abstract.Module
|
||||||
import Data.Abstract.ModuleTable
|
import Data.Abstract.ModuleTable as ModuleTable
|
||||||
import Prologue
|
import Prologue
|
||||||
|
|
||||||
-- | Retrieve the table of evaluated modules.
|
-- | Retrieve the table of evaluated modules.
|
||||||
@ -40,3 +42,17 @@ askLoadStack = raise ask
|
|||||||
-- | Locally update the module load stack.
|
-- | 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 :: Member (Reader LoadStack) effects => (LoadStack -> LoadStack) -> Evaluator location term value effects a -> Evaluator location term value effects a
|
||||||
localLoadStack = raiseHandler . local
|
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
|
||||||
|
@ -19,9 +19,7 @@ module Data.Abstract.Evaluatable
|
|||||||
, evaluatePackageWith
|
, evaluatePackageWith
|
||||||
, evaluatePackageBodyWith
|
, evaluatePackageBodyWith
|
||||||
, throwEvalError
|
, throwEvalError
|
||||||
, resolve
|
|
||||||
, traceResolve
|
, traceResolve
|
||||||
, listModulesInDir
|
|
||||||
, require
|
, require
|
||||||
, load
|
, load
|
||||||
, LoadStack
|
, LoadStack
|
||||||
@ -231,22 +229,9 @@ instance Evaluatable [] where
|
|||||||
eval = maybe unit (runApp . foldMap1 (App . subtermValue)) . nonEmpty
|
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 :: (Show a, Show b) => a -> b -> c -> c
|
||||||
traceResolve name path = trace ("resolved " <> show name <> " -> " <> show path)
|
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.
|
-- | 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.
|
-- Looks up the term's name in the cache of evaluated modules first, returns if found, otherwise loads/evaluates the module.
|
||||||
|
Loading…
Reference in New Issue
Block a user