| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Language.Futhark.Interpreter
Description
An interpreter operating on type-checked source Futhark terms. Relatively slow.
Synopsis
- data Ctx = Ctx {
- ctxEnv :: Env
- ctxImports :: Map ImportName Env
- data Env
- newtype InterpreterError = InterpreterError Text
- prettyInterpreterError :: InterpreterError -> Doc AnsiStyle
- initialCtx :: Ctx
- interpretExp :: Ctx -> Exp -> F ExtOp Value
- interpretDec :: Ctx -> Dec -> F ExtOp Ctx
- interpretApply :: Ctx -> Value -> Value -> F ExtOp Value
- interpretImport :: Ctx -> (ImportName, Prog) -> F ExtOp Ctx
- interpretFunction :: Ctx -> VName -> [Value] -> Either Text (F ExtOp Value)
- ctxWithImports :: [Env] -> Ctx -> Ctx
- data ExtOp a
- = ExtOpTrace Text (Doc ()) a
- | ExtOpBreak Loc BreakReason (NonEmpty StackFrame) a
- | ExtOpError InterpreterError
- | ExtOpFFI (ServerM Value) (Value -> a)
- | ExtOpIO IOOp (Value -> a)
- data BreakReason
- data StackFrame = StackFrame {
- stackFrameLoc :: Loc
- stackFrameCtx :: Ctx
- typeCheckerEnv :: Env -> Env
- type Value = Value EvalM
- fromTuple :: forall (m :: Type -> Type). Value m -> Maybe [Value m]
- isEmptyArray :: forall (m :: Type -> Type). Value m -> Bool
- asByteString :: forall (m :: Type -> Type). Value m -> Maybe ByteString
- prettyEmptyArray :: forall (m :: Type -> Type). TypeBase () NoMode -> Value m -> Text
- prettyValue :: forall (m :: Type -> Type) a. Value m -> Doc a
- valueText :: forall (m :: Type -> Type). Value m -> Text
- data IOOp
- determineIO :: Monad m => Text -> Maybe (m ValueType -> Value m -> m IOOp)
- doIOOp :: forall (m :: Type -> Type). Maybe Server -> IOOp -> IO (Either Text (Value m))
- ioRelativeTo :: FilePath -> IOOp -> IOOp
Documentation
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 | |
Fields
| |
The actual type- and value environment.
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
| Show InterpreterError Source # | |
Defined in Language.Futhark.Interpreter Methods showsPrec :: Int -> InterpreterError -> ShowS # show :: InterpreterError -> String # showList :: [InterpreterError] -> ShowS # | |
prettyInterpreterError :: InterpreterError -> Doc AnsiStyle Source #
Prettyprint the error for human consumption.
initialCtx :: Ctx Source #
The initial environment contains definitions of the various intrinsic functions.
interpretApply :: Ctx -> Value -> Value -> F ExtOp Value Source #
Interpret an application of a function value to an argument value. It better be well-typed!
interpretImport :: Ctx -> (ImportName, Prog) -> F ExtOp Ctx Source #
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.
Constructors
| ExtOpTrace Text (Doc ()) a | |
| ExtOpBreak Loc BreakReason (NonEmpty StackFrame) a | |
| ExtOpError InterpreterError | |
| ExtOpFFI (ServerM Value) (Value -> a) | |
| ExtOpIO IOOp (Value -> a) | Perform an IO operation. |
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 | |
Fields
| |
Instances
| Located StackFrame Source # | |
Defined in Language.Futhark.Interpreter | |
typeCheckerEnv :: Env -> Env Source #
Values
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.
IO
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.