License | BSD-3-Clause |
---|---|
Maintainer | Jamie Willis |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
This contains the instructions and satelite datatypes for representing parsers at the lowest CPS-form level. These are indexed by multiple types, which are documented in the source (if not on Haddock!).
Since: 1.0.0.0
Synopsis
- data Instr (o :: Type) (k :: [Type] -> Nat -> Type -> Type -> Type) (xs :: [Type]) (n :: Nat) (r :: Type) (a :: Type) where
- Ret :: Instr o k '[x] n x a
- Push :: Defunc x -> k (x ': xs) n r a -> Instr o k xs n r a
- Pop :: k xs n r a -> Instr o k (x ': xs) n r a
- Lift2 :: Defunc (x -> y -> z) -> k (z ': xs) n r a -> Instr o k (y ': (x ': xs)) n r a
- Sat :: Defunc (Char -> Bool) -> k (Char ': xs) (Succ n) r a -> Instr o k xs (Succ n) r a
- Call :: MVar x -> k (x ': xs) (Succ n) r a -> Instr o k xs (Succ n) r a
- Jump :: MVar x -> Instr o k '[] (Succ n) x a
- Empt :: Instr o k xs (Succ n) r a
- Commit :: k xs n r a -> Instr o k xs (Succ n) r a
- Catch :: k xs (Succ n) r a -> Handler o k (o ': xs) n r a -> Instr o k xs n r a
- Tell :: k (o ': xs) n r a -> Instr o k xs n r a
- Seek :: k xs n r a -> Instr o k (o ': xs) n r a
- Case :: k (x ': xs) n r a -> k (y ': xs) n r a -> Instr o k (Either x y ': xs) n r a
- Choices :: [Defunc (x -> Bool)] -> [k xs n r a] -> k xs n r a -> Instr o k (x ': xs) n r a
- Iter :: MVar Void -> k '[] One Void a -> Handler o k (o ': xs) n r a -> Instr o k xs n r a
- Join :: ΦVar x -> Instr o k (x ': xs) n r a
- MkJoin :: ΦVar x -> k (x ': xs) n r a -> k xs n r a -> Instr o k xs n r a
- Swap :: k (x ': (y ': xs)) n r a -> Instr o k (y ': (x ': xs)) n r a
- Dup :: k (x ': (x ': xs)) n r a -> Instr o k (x ': xs) n r a
- Make :: ΣVar x -> Access -> k xs n r a -> Instr o k (x ': xs) n r a
- Get :: ΣVar x -> Access -> k (x ': xs) n r a -> Instr o k xs n r a
- Put :: ΣVar x -> Access -> k xs n r a -> Instr o k (x ': xs) n r a
- LogEnter :: String -> k xs (Succ (Succ n)) r a -> Instr o k xs (Succ n) r a
- LogExit :: String -> k xs n r a -> Instr o k xs n r a
- MetaInstr :: MetaInstr n -> k xs n r a -> Instr o k xs n r a
- data Handler (o :: Type) (k :: [Type] -> Nat -> Type -> Type -> Type) (xs :: [Type]) (n :: Nat) (r :: Type) (a :: Type) where
- data Access
- data MetaInstr (n :: Nat) where
- _App :: Fix4 (Instr o) (y ': xs) n r a -> Instr o (Fix4 (Instr o)) (x ': ((x -> y) ': xs)) n r a
- _Fmap :: Defunc (x -> y) -> Fix4 (Instr o) (y ': xs) n r a -> Instr o (Fix4 (Instr o)) (x ': xs) n r a
- _Modify :: ΣVar x -> Fix4 (Instr o) xs n r a -> Instr o (Fix4 (Instr o)) ((x -> x) ': xs) n r a
- _Make :: ΣVar x -> k xs n r a -> Instr o k (x ': xs) n r a
- _Put :: ΣVar x -> k xs n r a -> Instr o k (x ': xs) n r a
- _Get :: ΣVar x -> k (x ': xs) n r a -> Instr o k xs n r a
- addCoins :: Int -> Fix4 (Instr o) xs (Succ n) r a -> Fix4 (Instr o) xs (Succ n) r a
- refundCoins :: Int -> Fix4 (Instr o) xs n r a -> Fix4 (Instr o) xs n r a
- drainCoins :: Int -> Fix4 (Instr o) xs (Succ n) r a -> Fix4 (Instr o) xs (Succ n) r a
Main Instructions
data Instr (o :: Type) (k :: [Type] -> Nat -> Type -> Type -> Type) (xs :: [Type]) (n :: Nat) (r :: Type) (a :: Type) where Source #
This represents the instructions of the machine, in CPS form as an indexed functor.
When an instruction has a Succ
in the type, it indicates that it is capable of failing.
Since: 1.4.0.0
Ret | This instruction returns from either calls or the entire parser at the top-level. Since: 1.0.0.0 |
| |
Push | Pushes a value onto the stack, which is required by the continuation parameter. Since: 1.0.0.0 |
Pop | Removes a value from the stack, so it is the correct shape for the continuation parameter. Since: 1.0.0.0 |
| |
Lift2 | Applies a function to the top two elements of the stack, converting them to something else and pushing it back on. Since: 1.0.0.0 |
Sat | Reads a character so long as it matches a given predicate. If it does not, or no input is available, this instruction fails. Since: 1.0.0.0 |
Call | Calls another let-bound parser. Since: 1.0.0.0 |
Jump | Jumps to another let-bound parser tail-recursively. Since: 1.0.0.0 |
Empt | Fails unconditionally. Since: 1.0.0.0 |
Commit | Discards a failure handler, so that it is no longer in scope. Since: 1.0.0.0 |
Catch | Registers a handler to deal with possible failure in the given machine. Since: 1.4.0.0 |
Tell | Pushes the current input offset onto the stack. Since: 1.0.0.0 |
| |
Seek | Pops the input offset off of the stack and makes that the current input offset. Since: 1.0.0.0 |
| |
Case | Picks one of two continuations based on whether a Since: 1.0.0.0 |
Choices | Given a collection of predicates and machines, this instruction will execute the first machine for which the corresponding predicate returns true for the value on the top of the stack. Since: 1.0.0.0 |
Iter | Sets up an iteration, where the second argument is executed repeatedly until it fails, which is
handled by the given handler. The use of Since: 1.0.0.0 |
Join | Jumps to a given join point. Since: 1.0.0.0 |
MkJoin | Sets up a new join point binding. Since: 1.0.0.0 |
Swap | Swaps the top two elements on the stack Since: 1.0.0.0 |
| |
Dup | Duplicates the top value on the stack. May produce a let-binding. Since: 1.0.0.0 |
| |
Make | Initialises a new register for use within the continuation. Initial value is on the stack. Since: 1.0.0.0 |
Get | Pushes the value contained within a register onto the stack. Since: 1.0.0.0 |
Put | Places the value on the top of the stack into a given register. Since: 1.0.0.0 |
LogEnter | Begins a debugging scope, the inner scope requires two handlers, the first is the log handler itself, and then the second is the "real" fail handler for when the log handler is executed. Since: 1.0.0.0 |
LogExit | Ends the log scope after a succesful execution. Since: 1.0.0.0 |
MetaInstr | Executes a meta-instruction, which is interacting with implementation specific static information. Since: 1.0.0.0 |
Auxilliary Types
data Handler (o :: Type) (k :: [Type] -> Nat -> Type -> Type -> Type) (xs :: [Type]) (n :: Nat) (r :: Type) (a :: Type) where Source #
There are two types of organic handlers within parsley, which are
captured by this type, which is also an IFunctor and wraps around
Instr
.
Since: 1.4.0.0
Same | These handlers have two distinct behaviours depending on whether the captured offset matches the current offset or not. Since: 1.4.0.0 |
| |
Always :: k (o ': xs) n r a -> Handler o k (o ': xs) n r a | These handlers are unconditional on the input, and will always do the same thing regardless of the input provided. Since: 1.4.0.0 |
This determines whether or not an interaction with an register should be materialised in the generated code or not.
Since: 1.0.0.0
data MetaInstr (n :: Nat) where Source #
These are meta-instructions, which interact with static information to direct the code-generation process. They are not formally part of parsley's semantics and can be omitted from an implementation without consequence.
Since: 1.0.0.0
AddCoins :: Int -> MetaInstr (Succ n) | Adds coins to the piggy-bank system (see Parsley.Internal.Backend.Machine.Types.Context for more information). If there are coins already available, add a piggy-bank, otherwise generate a length check and add the coins. A handler is required, in case the length check fails. Since: 1.0.0.0 |
RefundCoins :: Int -> MetaInstr n | Refunds to the piggy-bank system (see Parsley.Internal.Backend.Machine.Types.Context for more information). This always happens for free, and is added straight to the coins. Since: 1.0.0.0 |
DrainCoins :: Int -> MetaInstr (Succ n) | Remove coins from piggy-bank system (see Parsley.Internal.Backend.Machine.Types.Context for more information) This is used to pay for more expensive calls to bindings with known required input. A handler is required, as there may not be enough coins to pay the cost and a length check causes a failure. Since: 1.0.0.0 |
Smart Instructions
_App :: Fix4 (Instr o) (y ': xs) n r a -> Instr o (Fix4 (Instr o)) (x ': ((x -> y) ': xs)) n r a Source #
Applies a value on the top of the stack to a function on the second-most top of the stack.
Since: 1.0.0.0
_Fmap :: Defunc (x -> y) -> Fix4 (Instr o) (y ': xs) n r a -> Instr o (Fix4 (Instr o)) (x ': xs) n r a Source #
Adjusts the value on the top of the stack with the given function.
Since: 1.0.0.0
_Modify :: ΣVar x -> Fix4 (Instr o) xs n r a -> Instr o (Fix4 (Instr o)) ((x -> x) ': xs) n r a Source #
Updates the value in a given register using the function on the top of the stack.
Since: 1.0.0.0
Smart Meta-Instructions
addCoins :: Int -> Fix4 (Instr o) xs (Succ n) r a -> Fix4 (Instr o) xs (Succ n) r a Source #
Smart-constuctor around AddCoins
.
Since: 1.0.0.0
refundCoins :: Int -> Fix4 (Instr o) xs n r a -> Fix4 (Instr o) xs n r a Source #
Smart-constuctor around RefundCoins
.
Since: 1.0.0.0