pushInput k = Eval $ \inh ->
unEval k inh{valueStack = ValueStackCons (input inh) (valueStack inh)}
instance Routinable Eval where
- call (Label n) k = Eval $ \inh ->
+ call (LetName n) k = Eval $ \inh ->
callWithContinuation
{-sub-}(Code (TH.unsafeTExpCoerce (return (TH.VarE n))))
{-ok-}(suspend k inh)
(input inh)
{-ko-}(failStack inh)
- jump (Label n) = Eval $ \inh ->
+ jump (LetName n) = Eval $ \inh ->
callWithContinuation
{-sub-}(Code (TH.unsafeTExpCoerce (return (TH.VarE n))))
{-ok-}(retCode inh)
(input inh)
{-ko-}(failStack inh)
ret = Eval $ \inh -> unEval (resume (retCode inh)) inh
- subroutine (Label n) sub k = Eval $ \inh -> Code $ TH.unsafeTExpCoerce $ do
+ subroutine (LetName n) sub k = Eval $ \inh -> Code $ TH.unsafeTExpCoerce $ do
val <- TH.unTypeQ $ TH.examineCode $ [|| -- buildRec in Parsley
\(!ok) (!inp) ko ->
$$(unEval sub inh
{-# LANGUAGE ConstraintKinds #-} -- For Executable
-{-# LANGUAGE DerivingStrategies #-} -- For Show (Label a)
+{-# LANGUAGE DerivingStrategies #-} -- For Show (LetName a)
{-# LANGUAGE PatternSynonyms #-} -- For Fmap, App, …
{-# LANGUAGE UndecidableInstances #-} -- For Cursorable (Cursor inp)
module Symantic.Parser.Automaton.Instructions where
[Instr inp vs es ret] ->
Instr inp vs es ret ->
Instr inp (v ': vs) es ret
- -- | @('Subroutine' n v k)@ binds the 'Label' @(n)@ to the 'Instr'uction's @(v)@,
+ -- | @('Subroutine' n v k)@ binds the 'LetName' @(n)@ to the 'Instr'uction's @(v)@,
-- 'Call's @(n)@ and
-- continues with the next 'Instr'uction @(k)@.
Subroutine ::
- Label v -> Instr inp '[] ('Succ 'Zero) v ->
+ LetName v -> Instr inp '[] ('Succ 'Zero) v ->
Instr inp vs ('Succ es) ret ->
Instr inp vs ('Succ es) ret
-- | @('Jump' n k)@ pass the control-flow to the 'Subroutine' named @(n)@.
Jump ::
- Label ret ->
+ LetName ret ->
Instr inp '[] ('Succ es) ret
-- | @('Call' n k)@ pass the control-flow to the 'Subroutine' named @(n)@,
-- and when it 'Ret'urns, continues with the next 'Instr'uction @(k)@.
Call ::
- Label v ->
+ LetName v ->
Instr inp (v ': vs) ('Succ es) ret ->
Instr inp vs ('Succ es) ret
-- | @('Ret')@ returns the value stored in a singleton 'valueStack'.
InstrPureHaskell x -> trans x
InstrPureSameOffset -> sameOffset
--- ** Type 'Label'
-newtype Label a = Label { unLabel :: TH.Name }
+-- ** Type 'LetName'
+newtype LetName a = LetName { unLetName :: TH.Name }
deriving (Eq)
deriving newtype Show
-- ** Class 'Routinable'
class Routinable (repr :: Type -> [Type] -> Peano -> Type -> Type) where
subroutine ::
- Label v -> repr inp '[] ('Succ 'Zero) v ->
+ LetName v -> repr inp '[] ('Succ 'Zero) v ->
repr inp vs ('Succ es) ret ->
repr inp vs ('Succ es) ret
call ::
- Label v -> repr inp (v ': vs) ('Succ es) ret ->
+ LetName v -> repr inp (v ': vs) ('Succ es) ret ->
repr inp vs ('Succ es) ret
ret ::
repr inp '[ret] es ret
jump ::
- Label ret ->
+ LetName ret ->
repr inp '[] ('Succ es) ret
-- ** Class 'Readable'
(LoadInput (Push (InstrPureHaskell H.unit) k))
instance Letable TH.Name (Automaton inp) where
def n v = Automaton $ \k ->
- Subroutine (Label n) (unAutomaton v Ret) (Call (Label n) k)
+ Subroutine (LetName n) (unAutomaton v Ret) (Call (LetName n) k)
ref _isRec n = Automaton $ \case
- Ret -> Jump (Label n)
- k -> Call (Label n) k
+ Ret -> Jump (LetName n)
+ k -> Call (LetName n) k
instance Cursorable (Cursor inp) => Foldable (Automaton inp) where
{-
chainPre op p = go <*> p