futhark
Safe HaskellNone
LanguageGHC2021

Futhark.Eval

Description

Facilities for evaluating Futhark code.

This most directly provides the building blocks for futhark eval, but this module also contains server interaction machinery used by futhark repl and other commands that make use of the Futhark interpreter.

Synopsis

Documentation

runExpr :: (Evaluation m, MonadIO m) => InterpreterState -> Text -> m (Doc AnsiStyle) Source #

Run an expression in the given interpreter state. The expression is parsed, type checked, and then run. Returns a prettyprinted result. Must be run in a monad that supports aborting and traces.

evalServerOptions :: [FunOptDescr EvalConfig] Source #

Command line options for configuring the use of an external server.

runFFI :: Maybe Server -> ServerM Value -> IO (Either InterpreterError Value) Source #

Perform an action on the server. A failure is reported as a Left. Calls error if no server is provided.

forceValue :: Maybe Server -> Value -> IO (Either InterpreterError Value) Source #

Fetch in full a value that may reside on a server, so that it can be printed or otherwise inspected.

externaliseLast :: Imports -> Imports Source #

Mark the entry points of the last import - which is the file the user actually asked us to load - as external, meaning that calls to them are dispatched to a server instead of being interpreted.

runInterpreterWith :: MonadIO m => (Doc AnsiStyle -> m ()) -> Maybe Server -> Maybe FilePath -> F ExtOp a -> m (Either InterpreterError a) Source #

Run an interpreter action non-interactively. Breakpoints are ignored, as there is no way to enter a debugging prompt. Traces, and the breakpoints that are ignored, are reported with the given function. External calls are dispatched to the given server (if any). Relative paths in IO operations are resolved relative to the given directory, if any, and otherwise relative to the working directory.

interpretImports :: Monad m => (F ExtOp Ctx -> m (Either InterpreterError Ctx)) -> Imports -> ExceptT (Doc AnsiStyle) m (Env, Ctx) Source #

Interpret the given imports in order with the provided interpreter runner, and produce the type and interpreter environment of the last one.

initialiseInterpreter :: (Evaluation m, MonadIO m) => EvalConfig -> Maybe FilePath -> Maybe Server -> Imports -> m (Either (Doc AnsiStyle) (Maybe Server, Env, Ctx)) Source #

Set up an interpreter context for the given program. If a server is provided, or a backend has been requested (in which case a server is started), then the entry points of the loaded file are marked external, such that calls to them are dispatched to the server instead of being interpreted. On failure, a server started here is shut down again, so a returned server is always one that the caller now owns (and must eventually stop). A server passed in by the caller is never shut down here.

newInterpreterState :: (MonadIO m, Evaluation m) => EvalConfig -> VFS -> m (Either (Doc AnsiStyle) InterpreterState) Source #

Type check and interpret the given program (if any), producing a state in which expressions can be evaluated with runExpr.

class Monad m => Evaluation (m :: Type -> Type) where Source #

The class of monads that can perform expression evaluation.

Methods

abort :: Doc AnsiStyle -> m b Source #

trace :: Doc AnsiStyle -> m () Source #

Instances

Instances details
Evaluation EvalRecordRef Source # 
Instance details

Defined in Futhark.Eval

Evaluation IO Source # 
Instance details

Defined in Futhark.Eval

Evaluation m => Evaluation (ExceptT (Doc AnsiStyle) m) Source # 
Instance details

Defined in Futhark.Eval

data EvalRecordRef a Source #

Instances

Instances details
Evaluation EvalRecordRef Source # 
Instance details

Defined in Futhark.Eval

Applicative EvalRecordRef Source # 
Instance details

Defined in Futhark.Eval

Functor EvalRecordRef Source # 
Instance details

Defined in Futhark.Eval

Methods

fmap :: (a -> b) -> EvalRecordRef a -> EvalRecordRef b #

(<$) :: a -> EvalRecordRef b -> EvalRecordRef a #

Monad EvalRecordRef Source # 
Instance details

Defined in Futhark.Eval

MonadIO EvalRecordRef Source # 
Instance details

Defined in Futhark.Eval

Methods

liftIO :: IO a -> EvalRecordRef a #