| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Howl.Eval.Context
Description
Core evaluation context types and operations.
This module defines the evaluator context, rules, declarations, attributes, and lower-level operations for running and extending Howl evaluation.
Synopsis
- data Rule
- data Context = MkContext {
- symbolRecordTable :: !(HashTable Symbol SymbolRecord)
- moduleNumberRef :: !(IORef Int)
- lineNumberRef :: !(IORef Int)
- errorLineHandlerRef :: !(IORef (Text -> IO ()))
- outputLineHandlerRef :: !(IORef (Text -> IO ()))
- addToEvalCacheHandler :: Expr -> Eval ()
- returnIfInCacheHandler :: Expr -> Eval Expr -> Eval Expr
- data Attributes = MkAttributes {}
- data HoldType
- emptyAttributes :: Attributes
- data SymbolRecord = MkSymbolRecord {
- ownValue :: !(Maybe Expr)
- downValues :: !DownValues
- upValues :: !(Seq Rule)
- attributes :: !Attributes
- data DownValues = MkDownValues {
- sequentialRules :: !(Seq Rule)
- uniqueMatches :: !(Map Expr Expr)
- newtype Eval a = Eval (ReaderT Context IO a)
- runEvalWithContext :: Context -> Eval a -> IO a
- runEvalNewContext :: Eval a -> IO a
- getContext :: Eval Context
- returnIfInCache :: Expr -> Eval Expr -> Eval Expr
- addToEvalCache :: Expr -> Eval ()
- emitErrorLine :: Text -> Eval ()
- emitOutputLine :: Text -> Eval ()
- data Decl
- newContext :: IO Context
- getLineNumber :: Eval Int
- incrLineNumber :: Eval ()
- setErrorLineHandler :: Context -> (Text -> IO ()) -> IO ()
- setOutputLineHandler :: Context -> (Text -> IO ()) -> IO ()
- lookupSymbolRecord :: Symbol -> Eval (Maybe SymbolRecord)
- lookupAttributes :: Symbol -> Eval Attributes
- addDownValue :: Symbol -> Rule -> Eval ()
- addUpValue :: Symbol -> Rule -> Eval ()
- addDecl :: Decl -> Eval ()
- modifyAttributes :: Symbol -> (Attributes -> Attributes) -> Eval ()
- setAttributes :: Symbol -> Attributes -> Eval ()
- setFlat :: Attributes -> Attributes
- setOrderless :: Attributes -> Attributes
- setNumericFunction :: Attributes -> Attributes
- setHoldType :: HoldType -> Attributes -> Attributes
- clear :: Symbol -> Eval ()
- clearAll :: Symbol -> Eval ()
- newModuleSymbol :: Symbol -> Eval Symbol
- getDefinedSymbols :: Eval [Symbol]
- compilePat :: Expr -> Eval Pat
- dummyAddToEvalCache :: EvalCache -> Expr -> Eval ()
- dummyReturnIfInCache :: EvalCache -> Expr -> Eval Expr -> Eval Expr
Documentation
A rewrite rule used by the evaluator.
The mutable state used when evaluating expressions.
Constructors
| MkContext | |
Fields
| |
data Attributes #
TODO: Add Protected, NumericFunction, OneIdentity | The attributes associated with a symbol.
Constructors
| MkAttributes | |
Instances
| Show Attributes # | |
Defined in Howl.Eval.Context Methods showsPrec :: Int -> Attributes -> ShowS # show :: Attributes -> String # showList :: [Attributes] -> ShowS # | |
| Eq Attributes # | |
Defined in Howl.Eval.Context | |
| Ord Attributes # | |
Defined in Howl.Eval.Context Methods compare :: Attributes -> Attributes -> Ordering # (<) :: Attributes -> Attributes -> Bool # (<=) :: Attributes -> Attributes -> Bool # (>) :: Attributes -> Attributes -> Bool # (>=) :: Attributes -> Attributes -> Bool # max :: Attributes -> Attributes -> Attributes # min :: Attributes -> Attributes -> Attributes # | |
The hold behavior of a symbol during evaluation.
emptyAttributes :: Attributes #
The default empty set of symbol attributes.
data SymbolRecord #
Information associated with a symbol in the evaluation context.
Constructors
| MkSymbolRecord | |
Fields
| |
Instances
| Show SymbolRecord # | |
Defined in Howl.Eval.Context Methods showsPrec :: Int -> SymbolRecord -> ShowS # show :: SymbolRecord -> String # showList :: [SymbolRecord] -> ShowS # | |
data DownValues #
For cases when a pattern matches a unique expression, we store that expression in the uniqueMatches Map for fast lookup. In the evaluator, we try these lookups first before moving through the sequentialRules. | The down-values associated with a symbol.
Constructors
| MkDownValues | |
Fields
| |
Instances
| Show DownValues # | |
Defined in Howl.Eval.Context Methods showsPrec :: Int -> DownValues -> ShowS # show :: DownValues -> String # showList :: [DownValues] -> ShowS # | |
The monad in which Howl evaluation runs.
An Eval computation has access to the current evaluation context,
including symbol definitions, attributes, line-number state, and
output/error handlers.
Instances
| MonadIO Eval # | |
Defined in Howl.Eval.Context | |
| MonadCatch Eval # | |
Defined in Howl.Eval.Context | |
| MonadMask Eval # | |
Defined in Howl.Eval.Context Methods mask :: HasCallStack => ((forall a. Eval a -> Eval a) -> Eval b) -> Eval b # uninterruptibleMask :: HasCallStack => ((forall a. Eval a -> Eval a) -> Eval b) -> Eval b # generalBracket :: HasCallStack => Eval a -> (a -> ExitCase b -> Eval c) -> (a -> Eval b) -> Eval (b, c) # | |
| MonadThrow Eval # | |
Defined in Howl.Eval.Context Methods throwM :: (HasCallStack, Exception e) => e -> Eval a # | |
| Applicative Eval # | |
| Functor Eval # | |
| Monad Eval # | |
| MonadFail Eval # | |
Defined in Howl.Eval.Context | |
| MonadReader Context Eval # | |
| ToExpr a => ToBuiltin (Eval (Maybe a)) # | A monadic builtin that may fail to match its arguments, signified
by |
| ToExpr a => ToBuiltin (Eval a) # | A monadic builtin that always matches its arguments. |
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a (Eval (Maybe b))) # | A variadic monadic builtin that may fail to match its arguments,
signified by |
| (FromExpr a, ToExpr b) => ToBuiltin (Variadic a (Eval b)) # | A variadic monadic builtin that always matches its arguments. |
runEvalWithContext :: Context -> Eval a -> IO a #
Run an Eval computation in the given context.
runEvalNewContext :: Eval a -> IO a #
Create a new context and run an Eval computation in it.
getContext :: Eval Context #
Get the current context.
returnIfInCache :: Expr -> Eval Expr -> Eval Expr #
Return the cached value of an expression when available, otherwise run the given computation.
addToEvalCache :: Expr -> Eval () #
Add an expression to the evaluation cache.
emitErrorLine :: Text -> Eval () #
Emit a line of error output using the current error handler.
emitOutputLine :: Text -> Eval () #
Emit a line of standard output using the current output handler.
A declaration that can be added to the evaluation context.
newContext :: IO Context #
Create a new empty evaluation context.
getLineNumber :: Eval Int #
Get the current input line number.
incrLineNumber :: Eval () #
Increment the current input line number.
setErrorLineHandler :: Context -> (Text -> IO ()) -> IO () #
Set the error output handler for a Context.
setOutputLineHandler :: Context -> (Text -> IO ()) -> IO () #
Set the standard output handler for a Context.
lookupSymbolRecord :: Symbol -> Eval (Maybe SymbolRecord) #
Look up the record associated with a symbol in the current context.
lookupAttributes :: Symbol -> Eval Attributes #
Look up the attributes of a symbol in the current context.
addDownValue :: Symbol -> Rule -> Eval () #
Add a down-value rule for the given symbol.
addUpValue :: Symbol -> Rule -> Eval () #
Add an up-value rule for the given symbol.
modifyAttributes :: Symbol -> (Attributes -> Attributes) -> Eval () #
Modify the attributes of a symbol in the current context.
setAttributes :: Symbol -> Attributes -> Eval () #
Set the attributes of a symbol in the current context.
setFlat :: Attributes -> Attributes #
Set the Flat attribute.
setOrderless :: Attributes -> Attributes #
Set the Orderless attribute.
setNumericFunction :: Attributes -> Attributes #
Set the NumericFunction attribute.
setHoldType :: HoldType -> Attributes -> Attributes #
Set the hold behavior of a symbol.
newModuleSymbol :: Symbol -> Eval Symbol #
Create a fresh module-local symbol derived from the given base symbol.
getDefinedSymbols :: Eval [Symbol] #
Get the symbols that currently have records in the context.
compilePat :: Expr -> Eval Pat #
Compile an expression into a pattern, using the current context to determine attributes such as associativity and commutativity.
dummyAddToEvalCache :: EvalCache -> Expr -> Eval () #
A no-op cache insertion hook.