Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
The evaluation algorithm is presented as a small-step
transition relation
from a CESKM
to either
This machine is written to be, as much as possible, an executable semantics for psilo. Its code should be useful as a reference for writing evaluators in general and for clarifying the meaning of the language in a concrete way.
Hence there is a broad separation between the algorithm itself (principally
defined by step
and CESKM
); and the array of utilities and helpers
necessary to support that algorithm (starting with Runtime
) so that the
language semantics are not obscured by implementation details.
Synopsis
- evaluate :: CbpvExp -> Either String (Value, [String])
- type Runtime = StateT RuntimeState (WriterT [String] (Except String))
- newtype RuntimeState = RuntimeState {
- gensym_val :: Int
- runtime :: RuntimeState -> Runtime a -> Either String (a, [String])
- runtimeLog :: String -> Runtime ()
- gensym :: Runtime Address
- op :: Symbol -> [Value] -> Runtime Value
- data CESKM = CESKM {
- control :: CbpvExp
- environment :: Env
- store :: Store
- kontinuation :: Kont
- meta :: [Kont]
- data Kont
- data Value
- step :: CESKM -> Runtime (Either Value CESKM)
- drive :: Either Value CESKM -> Runtime Value
- inject :: CbpvExp -> CESKM
- type Address = Int
- data Env
- data Store
- emptyEnv :: Env
- emptyStore :: Store
- bindEnv :: Env -> Symbol -> Either Address CbpvExp -> Env
- bindEnv' :: Env -> [Symbol] -> [Either Address CbpvExp] -> Env
- bindStore :: Store -> Address -> Value -> Store
- bindStore' :: Store -> [Address] -> [Value] -> Store
- lookupEnv :: MonadError String m => Env -> Symbol -> m (Either Address CbpvExp)
- lookupStore :: MonadError String m => Store -> Address -> m Value
Documentation
Runtime Monad
type Runtime = StateT RuntimeState (WriterT [String] (Except String)) Source #
Runtime support for the CESK(M) algorithm.
Runtime
does the following:
- generates fresh, unique
Address
es on demand (viagensym
); - provides a mechanism for throwing exceptions (
throwError
); and - implements the operators (
op
) that are assumed to exist.
The actual evaluation algorithm begins with evaluate
.
See also: CESKM
.
TODO
RuntimeT, Runtime = RuntimeT Identity
newtype RuntimeState Source #
State managed by Runtime
.
RuntimeState | |
|
runtimeLog :: String -> Runtime () Source #
op :: Symbol -> [Value] -> Runtime Value Source #
This function provides implementations of the built-in operators. TODO After making Runtime = RuntimeT Identity, rename this to baseOps and for all monads m => RuntimeT m THEN create a typeclass ops and different monads
CESK(M) evaluation
CESKM
contains the state required for the operation of an abstract
Control-string Environment Store Kontinuation Meta machine
A continuation annihilates with a Value
during computation to either halt
or transition to the next state.
A value is data which the machine actually stores, manipulates, and evaluates expressions to.
step :: CESKM -> Runtime (Either Value CESKM) Source #
Represents a single step
of a virtual machine state transition.
The function is not recursive although several of its constituent parts are.
drive :: Either Value CESKM -> Runtime Value Source #
Drives each step
of the virtual machine until termination or error.
Environment & Store
emptyStore :: Store Source #
lookupStore :: MonadError String m => Store -> Address -> m Value Source #