Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains the core of Indigo language:
IndigoState
, a datatype that represents its state.
It also includes some convenient functions to work with it,
to provide rebindable syntax.
IndigoState
implements the functionality of a symbolic interpreter.
During its execution Lorentz code is being generated.
Functionally, it's the same as having Lorentz instruction that can access and
modify a StackVars
, referring to values on the stack with a RefId
.
Synopsis
- newtype IndigoState inp out = IndigoState {
- runIndigoState :: MetaData inp -> GenCode inp out
- usingIndigoState :: MetaData inp -> IndigoState inp out -> GenCode inp out
- (>>) :: IndigoState inp out -> IndigoState out out1 -> IndigoState inp out1
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- iput :: GenCode inp out -> IndigoState inp out
- nopState :: IndigoState inp inp
- assignTopVar :: KnownValue x => Var x -> IndigoState (x ': inp) (x ': inp)
- withObject :: forall a r. KnownValue a => DecomposedObjects -> Var a -> (Object a -> r) -> r
- withObjectState :: forall a inp out. KnownValue a => Var a -> (Object a -> IndigoState inp out) -> IndigoState inp out
- withStackVars :: (StackVars inp -> IndigoState inp out) -> IndigoState inp out
- type DecomposedObjects = Map RefId SomeObject
- data GenCodeHooks = GenCodeHooks {
- gchStmtHook :: forall inp out. Text -> (inp :-> out) -> inp :-> out
- gchAuxiliaryHook :: forall inp out. Text -> (inp :-> out) -> inp :-> out
- gchExprHook :: forall inp out. Text -> (inp :-> out) -> inp :-> out
- emptyGenCodeHooks :: GenCodeHooks
- data MetaData inp = MetaData {
- mdStack :: StackVars inp
- mdObjects :: DecomposedObjects
- mdHooks :: GenCodeHooks
- stmtHook :: forall inp out any. MetaData any -> Text -> (inp :-> out) -> inp :-> out
- stmtHookState :: Text -> IndigoState inp out -> IndigoState inp out
- auxiliaryHook :: forall inp out any. MetaData any -> Text -> (inp :-> out) -> inp :-> out
- auxiliaryHookState :: Text -> IndigoState inp out -> IndigoState inp out
- exprHook :: forall inp out any. MetaData any -> Text -> (inp :-> out) -> inp :-> out
- exprHookState :: Text -> IndigoState inp out -> IndigoState inp out
- replStkMd :: MetaData inp -> StackVars inp1 -> MetaData inp1
- alterStkMd :: MetaData inp -> (StackVars inp -> StackVars inp1) -> MetaData inp1
- pushRefMd :: KnownValue a => Var a -> MetaData inp -> MetaData (a ': inp)
- pushNoRefMd :: KnownValue a => MetaData inp -> MetaData (a ': inp)
- popNoRefMd :: MetaData (a ': inp) -> MetaData inp
- data GenCode inp out = GenCode {}
- cleanGenCode :: GenCode inp out -> inp :-> inp
- (##) :: (a :-> b) -> (b :-> c) -> a :-> c
Indigo State
newtype IndigoState inp out Source #
IndigoState data type.
It takes as input a StackVars
(for the initial state) and returns a
GenCode
(for the resulting state and the generated Lorentz code).
IndigoState has to be used to write backend typed Lorentz code from the corresponding frontend constructions.
It has no return type, IndigoState instruction may take one or more "return variables", that they assign to values produced during their execution.
IndigoState | |
|
usingIndigoState :: MetaData inp -> IndigoState inp out -> GenCode inp out Source #
Inverse of runIndigoState
for utility.
(>>) :: IndigoState inp out -> IndigoState out out1 -> IndigoState inp out1 Source #
Then for rebindable syntax.
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap
.
The name of this operator is an allusion to $
.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $
is function application, <$>
is function
application lifted over a Functor
.
Examples
Convert from a
to a Maybe
Int
using Maybe
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an
Either
Int
Int
Either
Int
String
using show
:
>>>
show <$> Left 17
Left 17>>>
show <$> Right 17
Right "17"
Double each element of a list:
>>>
(*2) <$> [1,2,3]
[2,4,6]
Apply even
to the second element of a pair:
>>>
even <$> (2,2)
(2,True)
nopState :: IndigoState inp inp Source #
The simplest IndigoState
, it does not modify the stack, nor the produced
code.
assignTopVar :: KnownValue x => Var x -> IndigoState (x ': inp) (x ': inp) Source #
Assigns a variable to reference the element on top of the stack.
withObject :: forall a r. KnownValue a => DecomposedObjects -> Var a -> (Object a -> r) -> r Source #
withObjectState :: forall a inp out. KnownValue a => Var a -> (Object a -> IndigoState inp out) -> IndigoState inp out Source #
withStackVars :: (StackVars inp -> IndigoState inp out) -> IndigoState inp out Source #
Utility function to create IndigoState
that need access to the current StackVars
.
type DecomposedObjects = Map RefId SomeObject Source #
data GenCodeHooks Source #
GenCodeHooks | |
|
Instances
Semigroup GenCodeHooks Source # | |
Defined in Indigo.Internal.State (<>) :: GenCodeHooks -> GenCodeHooks -> GenCodeHooks # sconcat :: NonEmpty GenCodeHooks -> GenCodeHooks # stimes :: Integral b => b -> GenCodeHooks -> GenCodeHooks # | |
Monoid GenCodeHooks Source # | |
Defined in Indigo.Internal.State mempty :: GenCodeHooks # mappend :: GenCodeHooks -> GenCodeHooks -> GenCodeHooks # mconcat :: [GenCodeHooks] -> GenCodeHooks # |
MetaData | |
|
stmtHookState :: Text -> IndigoState inp out -> IndigoState inp out Source #
auxiliaryHookState :: Text -> IndigoState inp out -> IndigoState inp out Source #
exprHookState :: Text -> IndigoState inp out -> IndigoState inp out Source #
pushNoRefMd :: KnownValue a => MetaData inp -> MetaData (a ': inp) Source #
Resulting state of IndigoM.
cleanGenCode :: GenCode inp out -> inp :-> inp Source #
Produces the generated Lorentz code that cleans after itself, leaving the same stack as the input one