Copyright | (c) Henry J. Wylde, 2015 |
---|---|
License | BSD3 |
Maintainer | public@hjwylde.com |
Safe Haskell | Safe |
Language | Haskell2010 |
Functions for executing a program and retrieving the return result.
This module assumes the program is well-formed. That is, it must be well-typed (see Language.Qux.TypeChecker).
- type Execution = EitherT Value Evaluation
- type Evaluation = StateT Locals (Reader Context)
- runExecution :: (a -> Value) -> Execution a -> Evaluation Value
- data Context
- type Locals = Map Id Value
- context :: Program -> Context
- exec :: Program -> Id -> [Value] -> Value
- execStmt :: Stmt -> Execution ()
- evalExpr :: Expr -> Evaluation Value
Environment
type Execution = EitherT Value Evaluation Source
An environment that holds the global state (Reader Context
) and the local state
(Locals
).
It supports breaking out of execution (via 'EitherT Value').
type Evaluation = StateT Locals (Reader Context) Source
An environment that holds the global state (Reader Context
) and the local state
(Locals
).
Purely for evaluation of expressions---this environment does not support breaking out of
execution.
runExecution :: (a -> Value) -> Execution a -> Evaluation Value Source
Contexts
Global context that holds function definitions. The function name, parameter names and statements are held.
Interpreter
Program execution
exec :: Program -> Id -> [Value] -> Value Source
exec program entry arguments
executes entry
(passing it arguments
) in the context
of program
.
This function wraps execFunction
by building and evaluating the environment under
the hood.
Expression evaluation
evalExpr :: Expr -> Evaluation Value Source
Reduces the expression to a value (normal form).