futhark
Safe HaskellNone
LanguageGHC2021

Language.Futhark.Interpreter

Contents

Description

An interpreter operating on type-checked source Futhark terms. Relatively slow.

Synopsis

Documentation

data Ctx Source #

The interpreter context. All evaluation takes place with respect to a context, and it can be extended with more definitions, which is how the REPL works.

Constructors

Ctx 

data Env Source #

The actual type- and value environment.

Instances

Instances details
Monoid Env Source # 
Instance details

Defined in Language.Futhark.Interpreter

Methods

mempty :: Env #

mappend :: Env -> Env -> Env #

mconcat :: [Env] -> Env #

Semigroup Env Source # 
Instance details

Defined in Language.Futhark.Interpreter

Methods

(<>) :: Env -> Env -> Env #

sconcat :: NonEmpty Env -> Env #

stimes :: Integral b => b -> Env -> Env #

Show Env Source # 
Instance details

Defined in Language.Futhark.Interpreter

Methods

showsPrec :: Int -> Env -> ShowS #

show :: Env -> String #

showList :: [Env] -> ShowS #

newtype InterpreterError Source #

An error occurred during interpretation due to an error in the user program. Actual interpreter errors will be signaled with an IO exception (error).

Constructors

InterpreterError Text 

Instances

Instances details
Show InterpreterError Source # 
Instance details

Defined in Language.Futhark.Interpreter

prettyInterpreterError :: InterpreterError -> Doc AnsiStyle Source #

Prettyprint the error for human consumption.

initialCtx :: Ctx Source #

The initial environment contains definitions of the various intrinsic functions.

interpretExp :: Ctx -> Exp -> F ExtOp Value Source #

Interpret a single expression.

interpretApply :: Ctx -> Value -> Value -> F ExtOp Value Source #

Interpret an application of a function value to an argument value. It better be well-typed!

interpretFunction :: Ctx -> VName -> [Value] -> Either Text (F ExtOp Value) Source #

Execute the named function on the given arguments; may fail horribly if these are ill-typed.

ctxWithImports :: [Env] -> Ctx -> Ctx Source #

Produce a context, based on the one passed in, where all of the provided imports have been openened in order.

data ExtOp a Source #

Instances

Instances details
Functor ExtOp Source # 
Instance details

Defined in Language.Futhark.Interpreter

Methods

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

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

data BreakReason Source #

What is the reason for this break point?

Constructors

BreakPoint

An explicit breakpoint in the program.

BreakNaN

An arithmetic operation produced a fresh NaN.

data StackFrame Source #

Constructors

StackFrame 

Instances

Instances details
Located StackFrame Source # 
Instance details

Defined in Language.Futhark.Interpreter

Values

type Value = Value EvalM Source #

fromTuple :: forall (m :: Type -> Type). Value m -> Maybe [Value m] Source #

isEmptyArray :: forall (m :: Type -> Type). Value m -> Bool Source #

Does the value correspond to an empty array?

asByteString :: forall (m :: Type -> Type). Value m -> Maybe ByteString Source #

If the value represents an array of type []u8, then return those bytes.

prettyEmptyArray :: forall (m :: Type -> Type). TypeBase () NoMode -> Value m -> Text Source #

String representation of an empty array with the provided element type. This is pretty ad-hoc - don't expect good results unless the element type is a primitive.

prettyValue :: forall (m :: Type -> Type) a. Value m -> Doc a Source #

Prettyprint value.

valueText :: forall (m :: Type -> Type). Value m -> Text Source #

The value in the textual format.

IO

data IOOp Source #

The IO operation to perform. The idea of splitting it out into a type like this is to enforce some kind of auditing.

determineIO :: Monad m => Text -> Maybe (m ValueType -> Value m -> m IOOp) Source #

Determine which IO operation this is.

If you want to add a new one, then remember to also add it as an intrinsic in the type checker, and probably also to the prelude.

doIOOp :: forall (m :: Type -> Type). Maybe Server -> IOOp -> IO (Either Text (Value m)) Source #

Run an IO operation. Arrays are put on the server, if one is given.

ioRelativeTo :: FilePath -> IOOp -> IOOp Source #

Resolve relative file paths in the operation relative to the given directory, rather than the current working directory.