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 GPureHeap PureHeap Supply InScopeSet
- type PureHeap = VarEnv Term
- newtype GPureHeap = GPureHeap {}
- type GlobalHeap = (IntMap Term, Int)
- type Stack = [StackFrame]
- data StackFrame
- mkTickish :: Stack -> [TickInfo] -> Stack
- data Value
- type State = (Heap, Stack, Term)
- type PrimEvaluator = Bool -> TyConMap -> Heap -> Stack -> Text -> PrimInfo -> [Type] -> [Value] -> Maybe State
- whnf' :: PrimEvaluator -> BindingMap -> TyConMap -> GlobalHeap -> Supply -> InScopeSet -> Bool -> Term -> (GlobalHeap, PureHeap, Term)
- whnf :: PrimEvaluator -> TyConMap -> Bool -> State -> State
- isScrut :: Stack -> Bool
- unwindStack :: State -> Maybe State
- step :: PrimEvaluator -> 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 :: Heap -> Stack -> Id -> Maybe State
- unwind :: PrimEvaluator -> TyConMap -> Heap -> Stack -> Value -> Maybe State
- update :: Heap -> Stack -> Id -> Value -> State
- gupdate :: 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
- naturalLiteral :: Value -> Maybe Integer
- integerLiteral :: Value -> Maybe Integer
- primop :: PrimEvaluator -> TyConMap -> Heap -> Stack -> Text -> PrimInfo -> [Type] -> [Value] -> Value -> [Term] -> Maybe State
- scrutinise :: Heap -> Stack -> Value -> [Alt] -> State
- substAlt :: DataCon -> [TyVar] -> [Id] -> [Either Term Type] -> Term -> Term
- allocate :: Heap -> Stack -> [LetBinding] -> Term -> State
- letSubst :: PureHeap -> Supply -> Id -> (Supply, (Id, (Id, Term)))
- uniqueInHeap :: PureHeap -> Supply -> Id -> (Supply, Id)
- wrapUnsigned :: Integer -> Integer -> Integer
- wrapSigned :: Integer -> Integer -> Integer
Documentation
type Stack = [StackFrame] Source #
The stack
data StackFrame Source #
Update Id | |
GUpdate Id | |
Apply Id | |
Instantiate Type | |
PrimApply Text PrimInfo [Type] [Value] [Term] | |
Scrutinise Type [Alt] | |
Tickish TickInfo |
Instances
Show StackFrame Source # | |
Defined in Clash.Core.Evaluator showsPrec :: Int -> StackFrame -> ShowS # show :: StackFrame -> String # showList :: [StackFrame] -> ShowS # | |
ClashPretty StackFrame Source # | |
Defined in Clash.Core.Evaluator clashPretty :: StackFrame -> Doc () Source # |
Lambda Id Term | Functions |
TyLambda TyVar Term | Type abstractions |
DC DataCon [Either Term Type] | Data constructors |
Lit Literal | Literals |
PrimVal Text PrimInfo [Type] [Value] | Clash's number types are represented by their "fromInteger#" primitive function. So some primitives are values. |
Suspend Term | Used by lazy primitives |
type PrimEvaluator = Bool -> TyConMap -> Heap -> Stack -> Text -> PrimInfo -> [Type] -> [Value] -> Maybe State Source #
Function that can evaluator primitives, i.e., perform delta-reduction
whnf' :: PrimEvaluator -> BindingMap -> TyConMap -> GlobalHeap -> Supply -> InScopeSet -> Bool -> Term -> (GlobalHeap, PureHeap, Term) Source #
Evaluate to WHNF starting with an empty Heap and Stack
whnf :: PrimEvaluator -> 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
unwind :: PrimEvaluator -> TyConMap -> Heap -> Stack -> Value -> Maybe State Source #
Unwind the stack by 1
:: PrimEvaluator | |
-> TyConMap | |
-> Heap | |
-> Stack | |
-> Text | Name of the primitive |
-> PrimInfo | 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 -> [LetBinding] -> Term -> State Source #
Allocate let-bindings on the heap
letSubst :: PureHeap -> Supply -> Id -> (Supply, (Id, (Id, Term))) Source #
Create a unique name and substitution for a let-binder