{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ViewPatterns #-}
module Dovetail.Core.Effect.Console where
import Control.Monad.IO.Class (MonadIO(..))
import Data.Foldable (fold)
import Data.Text (Text)
import Data.Text.IO qualified as Text.IO
import Data.Typeable (Typeable)
import Dovetail
import Dovetail.Core.Effect (Effect)
import Dovetail.Evaluate (builtIn)
env :: forall ctx. Typeable ctx => Env ctx
env :: Env ctx
env = do
let _ModuleName :: ModuleName
_ModuleName = Text -> ModuleName
ModuleName Text
"Effect.Console"
logImpl :: Text -> Effect ctx (Value ctx)
logImpl :: Text -> Effect ctx (Value ctx)
logImpl Text
s Value ctx
_ = do
IO () -> Eval ctx ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Text -> IO ()
Text.IO.putStrLn Text
s)
Effect ctx (Value ctx)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (HashMap Text (Value ctx) -> Value ctx
forall ctx. HashMap Text (Value ctx) -> Value ctx
Object HashMap Text (Value ctx)
forall a. Monoid a => a
mempty)
notImplemented :: Text -> Eval ctx a
notImplemented :: Text -> Eval ctx a
notImplemented Text
name = EvaluationErrorType ctx -> Eval ctx a
forall x (m :: * -> *) a.
(MonadError (EvaluationError x) m,
MonadReader (EvaluationContext x) m) =>
EvaluationErrorType x -> m a
throwErrorWithContext (Text -> EvaluationErrorType ctx
forall ctx. Text -> EvaluationErrorType ctx
OtherError (Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" is not implemented"))
[Env ctx] -> Env ctx
forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold
[
ModuleName -> Text -> (Text -> Effect ctx (Value ctx)) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Text -> Effect ctx (Value ctx))
ModuleName
_ModuleName Text
"log"
Text -> Effect ctx (Value ctx)
logImpl
, ModuleName -> Text -> (Text -> Effect ctx (Value ctx)) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Text -> Effect ctx (Value ctx))
ModuleName
_ModuleName Text
"warn"
Text -> Effect ctx (Value ctx)
logImpl
, ModuleName -> Text -> (Text -> Effect ctx (Value ctx)) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Text -> Effect ctx (Value ctx))
ModuleName
_ModuleName Text
"error"
Text -> Effect ctx (Value ctx)
logImpl
, ModuleName -> Text -> (Text -> Effect ctx (Value ctx)) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Text -> Effect ctx (Value ctx))
ModuleName
_ModuleName Text
"info"
Text -> Effect ctx (Value ctx)
logImpl
, ModuleName -> Text -> (Text -> Effect ctx (Value ctx)) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Text -> Effect ctx (Value ctx))
ModuleName
_ModuleName Text
"time"
\Text
_ Value ctx
_ -> Text -> Eval ctx (Value ctx)
forall a. Text -> Eval ctx a
notImplemented Text
"time"
, ModuleName -> Text -> (Text -> Effect ctx (Value ctx)) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Text -> Effect ctx (Value ctx))
ModuleName
_ModuleName Text
"timeLog"
\Text
_ Value ctx
_ -> Text -> Eval ctx (Value ctx)
forall a. Text -> Eval ctx a
notImplemented Text
"timeLog"
, ModuleName -> Text -> (Text -> Effect ctx (Value ctx)) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Text -> Effect ctx (Value ctx))
ModuleName
_ModuleName Text
"timeEnd"
\Text
_ Value ctx
_ -> Text -> Eval ctx (Value ctx)
forall a. Text -> Eval ctx a
notImplemented Text
"timeEnd"
, ModuleName -> Text -> (Text -> Effect ctx (Value ctx)) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Text -> Effect ctx (Value ctx))
ModuleName
_ModuleName Text
"clear"
\Text
_ Value ctx
_ -> Text -> Eval ctx (Value ctx)
forall a. Text -> Eval ctx a
notImplemented Text
"clear"
]