futhark-0.25.32: An optimising compiler for a functional, array-oriented language.

Safe Haskell | None
Language | GHC2021

Language.Futhark.Interpreter

Contents

- Values

Description

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

Synopsis

- data Ctx = Ctx {
  - ctxEnv :: Env
  - ctxImports :: Map ImportName Env
  }
- data Env
- data InterpreterError
- prettyInterpreterError :: InterpreterError -> Doc AnsiStyle
- initialCtx :: Ctx
- interpretExp :: Ctx -> Exp -> F ExtOp Value
- interpretDec :: Ctx -> Dec -> F ExtOp Ctx
- 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
- data BreakReason
  - = BreakPoint
  - | BreakNaN
- 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
- prettyEmptyArray :: forall (m :: Type -> Type). TypeBase () () -> Value m -> Text
- prettyValue :: forall (m :: Type -> Type) a. Value m -> Doc a
- valueText :: forall (m :: Type -> Type). Value m -> Text

# 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 |

Fields

- ctxEnv :: Env
- ctxImports :: Map ImportName Env

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 Source # mappend :: Env -> Env -> Env Source # mconcat :: [Env] -> Env Source #
Semigroup Env Source # |
Instance details Defined in Language.Futhark.Interpreter Methods (<>) :: Env -> Env -> Env Source # sconcat :: NonEmpty Env -> Env Source # stimes :: Integral b => b -> Env -> Env Source #
Show Env Source # |
Instance details Defined in Language.Futhark.Interpreter Methods showsPrec :: Int -> Env -> ShowS Source # show :: Env -> String Source # showList :: [Env] -> ShowS Source #

data 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`).

#### Instances

Instances details

Show InterpreterError Source # |
Instance details Defined in Language.Futhark.Interpreter Methods showsPrec :: Int -> InterpreterError -> ShowS Source # show :: InterpreterError -> String Source # showList :: [InterpreterError] -> ShowS Source #

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 #

interpretDec :: Ctx -> Dec -> F ExtOp Ctx Source #

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 `open`ened in order.

data ExtOp a Source #

Constructors

ExtOpTrace Text (Doc ()) a |
ExtOpBreak Loc BreakReason (NonEmpty StackFrame) a |
ExtOpError InterpreterError |

#### Instances

Instances details

Functor ExtOp Source # |
Instance details Defined in Language.Futhark.Interpreter Methods fmap :: (a -> b) -> ExtOp a -> ExtOp b Source # (<$) :: a -> ExtOp b -> ExtOp a Source #

data BreakReason Source #

What is the reason for this break point?

Constructors

BreakPoint | An explicit breakpoint in the program.
BreakNaN | A

data StackFrame Source #

Constructors

StackFrame |

Fields

- stackFrameLoc :: Loc
- stackFrameCtx :: Ctx

#### Instances

Instances details

Located StackFrame Source # |
Instance details Defined in Language.Futhark.Interpreter Methods locOf :: StackFrame -> Loc Source # locOfList :: [StackFrame] -> Loc Source #

typeCheckerEnv :: Env -> Env Source #

# 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?

prettyEmptyArray :: forall (m :: Type -> Type). TypeBase () () -> 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.