module Language.Egison
( module Language.Egison.Types
, module Language.Egison.Parser
, module Language.Egison.Primitives
, evalEgisonExpr
, evalEgisonTopExpr
, evalEgisonTopExprs
, runEgisonExpr
, runEgisonTopExpr
, runEgisonTopExprs
, loadEgisonLibrary
, loadEgisonFile
, initialEnv
, initialEnvNoIO
, version
) where
import Control.Applicative ((<$>), (<*>))
import Control.Monad.Error
import Data.IORef
import Data.Version
import qualified Paths_egison as P
import Language.Egison.Types
import Language.Egison.Parser
import Language.Egison.Primitives
import Language.Egison.Core
version :: Version
version = P.version
evalEgisonExpr :: Env -> EgisonExpr -> IO (Either EgisonError EgisonValue)
evalEgisonExpr env expr = fromEgisonM $ evalExprDeep env expr
evalEgisonTopExpr :: Env -> EgisonTopExpr -> IO (Either EgisonError Env)
evalEgisonTopExpr env exprs = fromEgisonM $ evalTopExpr env exprs
evalEgisonTopExprs :: Env -> [EgisonTopExpr] -> IO (Either EgisonError Env)
evalEgisonTopExprs env exprs = fromEgisonM $ evalTopExprs env exprs
runEgisonExpr :: Env -> String -> IO (Either EgisonError EgisonValue)
runEgisonExpr env input = fromEgisonM $ readExpr input >>= evalExprDeep env
runEgisonTopExpr :: Env -> String -> IO (Either EgisonError Env)
runEgisonTopExpr env input = fromEgisonM $ readTopExpr input >>= evalTopExpr env
runEgisonTopExprs :: Env -> String -> IO (Either EgisonError Env)
runEgisonTopExprs env input = fromEgisonM $ readTopExprs input >>= evalTopExprs env
loadEgisonFile :: Env -> FilePath -> IO (Either EgisonError Env)
loadEgisonFile env path = evalEgisonTopExpr env (LoadFile path)
loadEgisonLibrary :: Env -> FilePath -> IO (Either EgisonError Env)
loadEgisonLibrary env path = evalEgisonTopExpr env (Load path)
initialEnv :: IO Env
initialEnv = do
env <- primitiveEnv
ret <- evalEgisonTopExprs env $ map Load coreLibraries
case ret of
Left err -> do
print . show $ err
return env
Right env' -> return env'
initialEnvNoIO :: IO Env
initialEnvNoIO = do
env <- primitiveEnvNoIO
ret <- evalEgisonTopExprs env $ map Load coreLibraries
case ret of
Left err -> do
print . show $ err
return env
Right env' -> return env'
coreLibraries :: [String]
coreLibraries =
[ "lib/core/base.egi"
, "lib/core/collection.egi"
, "lib/core/order.egi"
, "lib/core/number.egi"
, "lib/core/natural-number.egi"
, "lib/core/string.egi"
, "lib/core/database.egi"
, "lib/core/io.egi"
]