1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 04:51:57 +03:00

Split a package body type out of Package.

This commit is contained in:
Rob Rix 2018-04-02 17:27:31 -04:00
parent 056a23a949
commit 9266439e7f
2 changed files with 11 additions and 7 deletions

View File

@ -186,8 +186,8 @@ evaluatePackage :: ( Effectful m
)
=> Package term
-> m effects [value]
evaluatePackage p = pushOrigin (packageOrigin p) (localModuleTable (<> packageModules p)
(traverse evaluateEntryPoint (ModuleTable.toPairs (packageEntryPoints p))))
evaluatePackage p = pushOrigin (packageOrigin p) (localModuleTable (<> packageModules (packageBody p))
(traverse evaluateEntryPoint (ModuleTable.toPairs (packageEntryPoints (packageBody p)))))
where evaluateEntryPoint (m, sym) = do
(_, v) <- require m
maybe (pure v) ((`call` []) <=< variable) sym

View File

@ -18,14 +18,18 @@ newtype Version = Version { versionString :: String }
-- | A package represents the unit of dependency, i.e. something which can depend upon, or be depended upon by, other packages. Packages have modules and may have entry points from which evaluation can proceed.
data Package term = Package
{ packageInfo :: PackageInfo
, packageModules :: ModuleTable [Module term]
{ packageInfo :: PackageInfo
, packageBody :: PackageBody term
}
deriving (Eq, Functor, Ord, Show)
data PackageBody term = PackageBody
{ packageModules :: ModuleTable [Module term]
, packageEntryPoints :: ModuleTable (Maybe Name)
}
deriving (Eq, Functor, Ord, Show)
fromModules :: [Module term] -> Package term
fromModules [] = Package (PackageInfo Nothing Nothing) mempty mempty
fromModules (m:ms) = Package (PackageInfo Nothing Nothing) (ModuleTable.fromModules (m:ms)) entryPoints
fromModules [] = Package (PackageInfo Nothing Nothing) (PackageBody mempty mempty)
fromModules (m:ms) = Package (PackageInfo Nothing Nothing) (PackageBody (ModuleTable.fromModules (m:ms)) entryPoints)
where entryPoints = ModuleTable.singleton (moduleName (moduleInfo m)) Nothing