clash-lib-1.8.1: Clash: a functional hardware description language - As a library

Copyright | (C) 2020-2021 QBayLogic B.V.
License | BSD2 (see the file LICENSE)
Maintainer | QBayLogic B.V. <devops@qbaylogic.com>
Safe Haskell | Safe-Inferred
Language | Haskell2010

Clash.Core.PartialEval.Monad

Contents

- Partial Evaluation Monad
- Local and Global Environments
- Evaluation Context
- Local Type Bindings
- Local Term Bindings
- Global Term Bindings
- IO Heap Bindings
- Lifted Data Constructors
- Fuel
- Accessing Global State
- Fresh Variable Generation
- Work free check

Description

The monad for partial evaluation, and its API. This should contain all auxiliary functions needed to define new evaluator implementations. This module is only needed to define new evaluators, for calling an existing evaluator see Clash.Core.PartialEval.

Synopsis

- data Eval a
- runEval :: GlobalEnv -> LocalEnv -> Eval a -> IO (a, GlobalEnv)
- getLocalEnv :: Eval LocalEnv
- setLocalEnv :: LocalEnv -> Eval a -> Eval a
- modifyLocalEnv :: (LocalEnv -> LocalEnv) -> Eval a -> Eval a
- getGlobalEnv :: Eval GlobalEnv
- modifyGlobalEnv :: (GlobalEnv -> GlobalEnv) -> Eval ()
- getContext :: Eval Id
- withContext :: Id -> Eval a -> Eval a
- getTvSubst :: Eval Subst
- findTyVar :: TyVar -> Eval (Maybe Type)
- withTyVar :: TyVar -> Type -> Eval a -> Eval a
- withTyVars :: [(TyVar, Type)] -> Eval a -> Eval a
- findId :: Id -> Eval (Maybe Value)
- withId :: Id -> Value -> Eval a -> Eval a
- withIds :: [(Id, Value)] -> Eval a -> Eval a
- withoutId :: Id -> Eval a -> Eval a
- findBinding :: Id -> Eval (Maybe (Binding Value))
- replaceBinding :: Binding Value -> Eval ()
- getRef :: Int -> Eval Value
- setRef :: Int -> Value -> Eval ()
- isKeepingLifted :: Eval Bool
- keepLifted :: Eval a -> Eval a
- getFuel :: Eval Word
- withFuel :: Eval a -> Eval a
- preserveFuel :: Eval a -> Eval a
- getTyConMap :: Eval TyConMap
- getInScope :: Eval InScopeSet
- getUniqueId :: OccName -> Type -> Eval Id
- getUniqueTyVar :: OccName -> Kind -> Eval TyVar
- workFreeValue :: Value -> Eval Bool

# Partial Evaluation Monad

data Eval a Source #

The monad of partial evaluation. The inner monad is IO, as primitive evaluation can attempt to evaluate IO actions.

#### Instances

Instances details

MonadFail Eval Source # |
Instance details Defined in Clash.Core.PartialEval.Monad Methods fail :: String -> Eval a Source #
MonadIO Eval Source # |
Instance details Defined in Clash.Core.PartialEval.Monad Methods liftIO :: IO a -> Eval a Source #
Alternative Eval Source # |
Instance details Defined in Clash.Core.PartialEval.Monad Methods empty :: Eval a Source # (<|>) :: Eval a -> Eval a -> Eval a Source # some :: Eval a -> Eval [a] Source # many :: Eval a -> Eval [a] Source #
Applicative Eval Source # |
Instance details Defined in Clash.Core.PartialEval.Monad Methods pure :: a -> Eval a Source # (<*>) :: Eval (a -> b) -> Eval a -> Eval b Source # liftA2 :: (a -> b -> c) -> Eval a -> Eval b -> Eval c Source # (*>) :: Eval a -> Eval b -> Eval b Source # (<*) :: Eval a -> Eval b -> Eval a Source #
Functor Eval Source # |
Instance details Defined in Clash.Core.PartialEval.Monad Methods fmap :: (a -> b) -> Eval a -> Eval b Source # (<$) :: a -> Eval b -> Eval a Source #
Monad Eval Source # |
Instance details Defined in Clash.Core.PartialEval.Monad Methods (>>=) :: Eval a -> (a -> Eval b) -> Eval b Source # (>>) :: Eval a -> Eval b -> Eval b Source # return :: a -> Eval a Source #
MonadCatch Eval Source # |
Instance details Defined in Clash.Core.PartialEval.Monad Methods catch :: (HasCallStack, Exception e) => Eval a -> (e -> Eval a) -> Eval a Source #
MonadMask Eval Source # |
Instance details Defined in Clash.Core.PartialEval.Monad Methods mask :: HasCallStack => ((forall a. Eval a -> Eval a) -> Eval b) -> Eval b Source # uninterruptibleMask :: HasCallStack => ((forall a. Eval a -> Eval a) -> Eval b) -> Eval b Source # generalBracket :: HasCallStack => Eval a -> (a -> ExitCase b -> Eval c) -> (a -> Eval b) -> Eval (b, c) Source #
MonadThrow Eval Source # |
Instance details Defined in Clash.Core.PartialEval.Monad Methods throwM :: (HasCallStack, Exception e) => e -> Eval a Source #
MonadReader LocalEnv Eval Source # |
Instance details Defined in Clash.Core.PartialEval.Monad Methods ask :: Eval LocalEnv Source # local :: (LocalEnv -> LocalEnv) -> Eval a -> Eval a Source # reader :: (LocalEnv -> a) -> Eval a Source #
MonadState GlobalEnv Eval Source # |
Instance details Defined in Clash.Core.PartialEval.Monad Methods get :: Eval GlobalEnv Source # put :: GlobalEnv -> Eval () Source # state :: (GlobalEnv -> (a, GlobalEnv)) -> Eval a Source #

runEval :: GlobalEnv -> LocalEnv -> Eval a -> IO (a, GlobalEnv) Source #

Evaluate an action in the partial evaluator, returning the result, and the final state of the global environment.

# Local and Global Environments

getLocalEnv :: Eval LocalEnv Source #

setLocalEnv :: LocalEnv -> Eval a -> Eval a Source #

modifyLocalEnv :: (LocalEnv -> LocalEnv) -> Eval a -> Eval a Source #

getGlobalEnv :: Eval GlobalEnv Source #

modifyGlobalEnv :: (GlobalEnv -> GlobalEnv) -> Eval () Source #

# Evaluation Context

getContext :: Eval Id Source #

withContext :: Id -> Eval a -> Eval a Source #

# Local Type Bindings

getTvSubst :: Eval Subst Source #

findTyVar :: TyVar -> Eval (Maybe Type) Source #

withTyVar :: TyVar -> Type -> Eval a -> Eval a Source #

withTyVars :: [(TyVar, Type)] -> Eval a -> Eval a Source #

# Local Term Bindings

findId :: Id -> Eval (Maybe Value) Source #

withId :: Id -> Value -> Eval a -> Eval a Source #

withIds :: [(Id, Value)] -> Eval a -> Eval a Source #

withoutId :: Id -> Eval a -> Eval a Source #

# Global Term Bindings

findBinding :: Id -> Eval (Maybe (Binding Value)) Source #

replaceBinding :: Binding Value -> Eval () Source #

# IO Heap Bindings

getRef :: Int -> Eval Value Source #

setRef :: Int -> Value -> Eval () Source #

# Lifted Data Constructors

isKeepingLifted :: Eval Bool Source #

keepLifted :: Eval a -> Eval a Source #

# Fuel

getFuel :: Eval Word Source #

withFuel :: Eval a -> Eval a Source #

preserveFuel :: Eval a -> Eval a Source #

# Accessing Global State

getTyConMap :: Eval TyConMap Source #

getInScope :: Eval InScopeSet Source #

# Fresh Variable Generation

getUniqueId :: OccName -> Type -> Eval Id Source #

getUniqueTyVar :: OccName -> Kind -> Eval TyVar Source #

# Work free check

workFreeValue :: Value -> Eval Bool Source #