{- |
Module      : Language.Egison
Licence     : MIT

This is the top module of Egison.
-}

module Language.Egison
       ( module Language.Egison.AST
       , module Language.Egison.Data
       , module Language.Egison.Eval
       , module Language.Egison.EvalState
       , module Language.Egison.Parser
       , module Language.Egison.Primitives
       -- * Modules needed to execute Egison
       , module Language.Egison.CmdOptions
       , module Language.Egison.RState
       -- * Environment
       , initialEnv
       , coreLibraries
       -- * Information
       , version
      ) where

import           Control.Monad.Reader       (asks, local)
import           Control.Monad.State

import           Data.Version
import qualified Paths_egison               as P

import           Language.Egison.AST
import           Language.Egison.CmdOptions
import           Language.Egison.Data
import           Language.Egison.Eval
import           Language.Egison.EvalState
import           Language.Egison.Parser
import           Language.Egison.Primitives
import           Language.Egison.RState

-- |Version number
version :: Version
version :: Version
version = Version
P.version

-- |Create initial environment with only primitive functions
-- Core libraries will be loaded separately to maintain consistent Env chain
-- Returns EvalM Env to preserve EvalState (type environment, class environment)
initialEnv :: EvalM Env
initialEnv :: EvalM Env
initialEnv = do
  Bool
isNoIO <- ExceptT EgisonError RuntimeM Bool
-> StateT EvalState (ExceptT EgisonError RuntimeM) Bool
forall (m :: * -> *) a. Monad m => m a -> StateT EvalState m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ExceptT EgisonError RuntimeM Bool
 -> StateT EvalState (ExceptT EgisonError RuntimeM) Bool)
-> ExceptT EgisonError RuntimeM Bool
-> StateT EvalState (ExceptT EgisonError RuntimeM) Bool
forall a b. (a -> b) -> a -> b
$ RuntimeM Bool -> ExceptT EgisonError RuntimeM Bool
forall (m :: * -> *) a. Monad m => m a -> ExceptT EgisonError m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (RuntimeM Bool -> ExceptT EgisonError RuntimeM Bool)
-> RuntimeM Bool -> ExceptT EgisonError RuntimeM Bool
forall a b. (a -> b) -> a -> b
$ (EgisonOpts -> Bool) -> RuntimeM Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks EgisonOpts -> Bool
optNoIO
  Env
env <- IO Env -> EvalM Env
forall a. IO a -> StateT EvalState (ExceptT EgisonError RuntimeM) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Env -> EvalM Env) -> IO Env -> EvalM Env
forall a b. (a -> b) -> a -> b
$ if Bool
isNoIO then IO Env
primitiveEnvNoIO else IO Env
primitiveEnv
  Env -> EvalM Env
forall a. a -> StateT EvalState (ExceptT EgisonError RuntimeM) a
forall (m :: * -> *) a. Monad m => a -> m a
return Env
env

coreLibraries :: [String]
coreLibraries :: [String]
coreLibraries =
  -- Libs that defines user-defined infixes comes first
  [
    String
"lib/core/base.egi"              -- Defines (&&) (||)
  , String
"lib/core/order.egi"
  , String
"lib/core/collection.egi"        -- Defines (++) for patterns
  , String
"lib/core/maybe.egi"
  , String
"lib/core/number.egi"
  , String
"lib/core/random.egi"
  , String
"lib/core/assoc.egi"
  , String
"lib/core/string.egi"
  , String
"lib/core/io.egi"

  , String
"lib/math/expression.egi"        -- Defines (+) (*) (/) (^) for patterns
  , String
"lib/math/common/arithmetic.egi" -- Defines (+) (-) (*) (/) (+') (-') (*') (/')
  , String
"lib/math/algebra/group.egi"

  , String
"lib/math/common/constants.egi"
  , String
"lib/math/common/functions.egi"
  , String
"lib/math/algebra/root.egi"
  , String
"lib/math/algebra/tensor.egi"    -- Defines (.) (.')
  , String
"lib/math/algebra/vector.egi"

  , String
"lib/math/algebra/equations.egi"
  , String
"lib/math/algebra/matrix.egi"
  , String
"lib/math/analysis/derivative.egi"

  , String
"lib/math/geometry/differential-form.egi"
--  , "lib/math/algebra/inverse.egi"
--  , "lib/math/analysis/integral.egi"
  ]