Copyright | (C) 2017 Google Inc. |
---|---|
License | BSD2 (see the file LICENSE) |
Maintainer | Christiaan Baaij <christiaan.baaij@gmail.com> |
Safe Haskell | None |
Language | Haskell2010 |
Call-by-need evaluator based on the evaluator described in:
Maximilian Bolingbroke, Simon Peyton Jones, "Supercompilation by evaluation", Haskell '10, Baltimore, Maryland, USA.
Synopsis
- data Heap = Heap GlobalHeap PureHeap Supply
- type PureHeap = Map TmOccName Term
- type GlobalHeap = (IntMap Term, Int)
- type Stack = [StackFrame]
- data StackFrame
- data Value
- type State = (Heap, Stack, Term)
- type PrimEvaluator = Bool -> BindingMap -> TyConMap -> Heap -> Stack -> Text -> Type -> [Type] -> [Value] -> Maybe State
- whnf' :: PrimEvaluator -> BindingMap -> TyConMap -> GlobalHeap -> Supply -> Bool -> Term -> (GlobalHeap, Term)
- whnf :: PrimEvaluator -> BindingMap -> TyConMap -> Bool -> State -> State
- isScrut :: Stack -> Bool
- unwindStack :: State -> Maybe State
- step :: PrimEvaluator -> BindingMap -> TyConMap -> State -> Maybe State
- newLetBinding :: TyConMap -> Heap -> Term -> (Heap, Id)
- newLetBindings' :: TyConMap -> Heap -> [Either Term Type] -> (Heap, [Either Term Type])
- mkAbstr :: (Heap, Term) -> [Either TyVar Type] -> (Heap, Term)
- force :: BindingMap -> Heap -> Stack -> Id -> Maybe State
- unwind :: PrimEvaluator -> BindingMap -> TyConMap -> Heap -> Stack -> Value -> Maybe State
- update :: Heap -> Stack -> Id -> Value -> State
- valToTerm :: Value -> Term
- toVar :: Id -> Term
- toType :: TyVar -> Type
- apply :: Heap -> Stack -> Value -> Id -> State
- instantiate :: Heap -> Stack -> Value -> Type -> State
- primop :: PrimEvaluator -> BindingMap -> TyConMap -> Heap -> Stack -> Text -> Type -> [Type] -> [Value] -> Value -> [Term] -> Maybe State
- scrutinise :: Heap -> Stack -> Value -> [Alt] -> State
- matchLit :: DataCon -> Literal -> Bool
- substAlt :: DataCon -> Rebind [TyVar] [Id] -> [Either Term Type] -> Term -> Term
- allocate :: Heap -> Stack -> Bind (Rec [LetBinding]) Term -> State
- letSubst :: PureHeap -> Supply -> Id -> (Supply, (TmOccName, (TmOccName, Term)))
- uniqueInHeap :: PureHeap -> Supply -> TmOccName -> (Supply, TmName)
Documentation
The heap
type Stack = [StackFrame] Source #
The stack
data StackFrame Source #
Instances
Show StackFrame Source # | |
showsPrec :: Int -> StackFrame -> ShowS # show :: StackFrame -> String # showList :: [StackFrame] -> ShowS # | |
Pretty StackFrame Source # | |
type PrimEvaluator = Bool -> BindingMap -> TyConMap -> Heap -> Stack -> Text -> Type -> [Type] -> [Value] -> Maybe State Source #
Function that can evaluator primitives, i.e., perform delta-reduction
whnf' :: PrimEvaluator -> BindingMap -> TyConMap -> GlobalHeap -> Supply -> Bool -> Term -> (GlobalHeap, Term) Source #
Evaluate to WHNF starting with an empty Heap and Stack
whnf :: PrimEvaluator -> BindingMap -> TyConMap -> Bool -> State -> State Source #
Evaluate to WHNF given an existing Heap and Stack
isScrut :: Stack -> Bool Source #
Are we in a context where special primitives must be forced.
See [Note: forcing special primitives]
unwindStack :: State -> Maybe State Source #
Completely unwind the stack to get back the complete term
step :: PrimEvaluator -> BindingMap -> TyConMap -> State -> Maybe State Source #
Small-step operational semantics.
force :: BindingMap -> Heap -> Stack -> Id -> Maybe State Source #
Force the evaluation of a variable.
unwind :: PrimEvaluator -> BindingMap -> TyConMap -> Heap -> Stack -> Value -> Maybe State Source #
Unwind the stack by 1
:: PrimEvaluator | |
-> BindingMap | |
-> TyConMap | |
-> Heap | |
-> Stack | |
-> Text | Name of the primitive |
-> Type | Type of the primitive |
-> [Type] | Applied types |
-> [Value] | Applied values |
-> Value | The current value |
-> [Term] | The remaining terms which must be evaluated to a value |
-> Maybe State |
Evaluation of primitive operations
allocate :: Heap -> Stack -> Bind (Rec [LetBinding]) Term -> State Source #
Allocate let-bindings on the heap