module Symantic.Parser.Machine.Dump where

import Data.Function (($), (.), id)
import Data.Functor ((<$>))
import Data.Kind (Type)
import Data.Semigroup (Semigroup(..))
import Data.String (String, IsString(..))
import Text.Show (Show(..))
import qualified Data.Tree as Tree
import qualified Data.List as List

import Symantic.Parser.Machine.Instructions

-- * Type 'DumpInstr'
newtype DumpInstr inp (vs:: [Type]) (es::Peano) a
  =     DumpInstr { forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr ::
  Tree.Forest String -> Tree.Forest String }

dumpInstr :: DumpInstr inp vs es a -> DumpInstr inp vs es a
dumpInstr :: forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> DumpInstr inp vs es a
dumpInstr = DumpInstr inp vs es a -> DumpInstr inp vs es a
forall a. a -> a
id

-- | Helper to dump a command.
dumpInstrCmd :: String -> Tree.Forest String -> Tree.Tree String
dumpInstrCmd :: String -> Forest String -> Tree String
dumpInstrCmd String
n = String -> Forest String -> Tree String
forall a. a -> Forest a -> Tree a
Tree.Node String
n
-- | Helper to dump an argument.
dumpInstrArg :: String -> Tree.Forest String -> Tree.Tree String
dumpInstrArg :: String -> Forest String -> Tree String
dumpInstrArg String
n = String -> Forest String -> Tree String
forall a. a -> Forest a -> Tree a
Tree.Node (String
"<"String -> String -> String
forall a. Semigroup a => a -> a -> a
<>String
nString -> String -> String
forall a. Semigroup a => a -> a -> a
<>String
">")

instance Show (DumpInstr inp vs es a) where
  show :: DumpInstr inp vs es a -> String
show = Tree String -> String
drawTree (Tree String -> String)
-> (DumpInstr inp vs es a -> Tree String)
-> DumpInstr inp vs es a
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Forest String -> Tree String
forall a. a -> Forest a -> Tree a
Tree.Node String
"" (Forest String -> Tree String)
-> (DumpInstr inp vs es a -> Forest String)
-> DumpInstr inp vs es a
-> Tree String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Forest String -> Forest String) -> Forest String -> Forest String
forall a b. (a -> b) -> a -> b
$ []) ((Forest String -> Forest String) -> Forest String)
-> (DumpInstr inp vs es a -> Forest String -> Forest String)
-> DumpInstr inp vs es a
-> Forest String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DumpInstr inp vs es a -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr
    where
    drawTree :: Tree.Tree String -> String
    drawTree :: Tree String -> String
drawTree  = [String] -> String
List.unlines ([String] -> String)
-> (Tree String -> [String]) -> Tree String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tree String -> [String]
draw
    draw :: Tree.Tree String -> [String]
    draw :: Tree String -> [String]
draw (Tree.Node String
x Forest String
ts0) = String -> [String]
List.lines String
x [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> Forest String -> [String]
drawSubTrees Forest String
ts0
      where
      drawSubTrees :: Forest String -> [String]
drawSubTrees [] = []
      drawSubTrees [Tree String
t] = String -> String -> [String] -> [String]
forall {c}. Semigroup c => c -> c -> [c] -> [c]
shift String
"" String
"  " (Tree String -> [String]
draw Tree String
t)
      drawSubTrees (Tree String
t:Forest String
ts) = String -> String -> [String] -> [String]
forall {c}. Semigroup c => c -> c -> [c] -> [c]
shift String
"" String
"| " (Tree String -> [String]
draw Tree String
t) [String] -> [String] -> [String]
forall a. Semigroup a => a -> a -> a
<> Forest String -> [String]
drawSubTrees Forest String
ts
      shift :: c -> c -> [c] -> [c]
shift c
first c
other = (c -> c -> c) -> [c] -> [c] -> [c]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
List.zipWith c -> c -> c
forall a. Semigroup a => a -> a -> a
(<>) (c
first c -> [c] -> [c]
forall a. a -> [a] -> [a]
: c -> [c]
forall a. a -> [a]
List.repeat c
other)
instance IsString (DumpInstr inp vs es a) where
  fromString :: String -> DumpInstr inp vs es a
fromString String
s = (Forest String -> Forest String) -> DumpInstr inp vs es a
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String) -> DumpInstr inp vs es a)
-> (Forest String -> Forest String) -> DumpInstr inp vs es a
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
forall a. a -> Forest a -> Tree a
Tree.Node (String -> String
forall a. IsString a => String -> a
fromString String
s) [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: Forest String
is

instance Stackable DumpInstr where
  push :: forall v inp (vs :: [*]) (n :: Peano) ret.
InstrPure v
-> DumpInstr inp (v : vs) n ret -> DumpInstr inp vs n ret
push InstrPure v
a DumpInstr inp (v : vs) n ret
k = (Forest String -> Forest String) -> DumpInstr inp vs n ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String) -> DumpInstr inp vs n ret)
-> (Forest String -> Forest String) -> DumpInstr inp vs n ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd (String
"push "String -> String -> String
forall a. Semigroup a => a -> a -> a
<>Int -> InstrPure v -> String -> String
forall a. Show a => Int -> a -> String -> String
showsPrec Int
10 InstrPure v
a String
"") [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: DumpInstr inp (v : vs) n ret -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp (v : vs) n ret
k Forest String
is
  pop :: forall inp (vs :: [*]) (n :: Peano) ret v.
DumpInstr inp vs n ret -> DumpInstr inp (v : vs) n ret
pop DumpInstr inp vs n ret
k = (Forest String -> Forest String) -> DumpInstr inp (v : vs) n ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String) -> DumpInstr inp (v : vs) n ret)
-> (Forest String -> Forest String) -> DumpInstr inp (v : vs) n ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd String
"pop" [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: DumpInstr inp vs n ret -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp vs n ret
k Forest String
is
  liftI2 :: forall x y z inp (vs :: [*]) (es :: Peano) ret.
InstrPure (x -> y -> z)
-> DumpInstr inp (z : vs) es ret
-> DumpInstr inp (y : x : vs) es ret
liftI2 InstrPure (x -> y -> z)
f DumpInstr inp (z : vs) es ret
k = (Forest String -> Forest String)
-> DumpInstr inp (y : x : vs) es ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String)
 -> DumpInstr inp (y : x : vs) es ret)
-> (Forest String -> Forest String)
-> DumpInstr inp (y : x : vs) es ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd (String
"lift "String -> String -> String
forall a. Semigroup a => a -> a -> a
<>InstrPure (x -> y -> z) -> String
forall a. Show a => a -> String
show InstrPure (x -> y -> z)
f) [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: DumpInstr inp (z : vs) es ret -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp (z : vs) es ret
k Forest String
is
  swap :: forall inp x y (vs :: [*]) (n :: Peano) r.
DumpInstr inp (x : y : vs) n r -> DumpInstr inp (y : x : vs) n r
swap DumpInstr inp (x : y : vs) n r
k = (Forest String -> Forest String) -> DumpInstr inp (y : x : vs) n r
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String)
 -> DumpInstr inp (y : x : vs) n r)
-> (Forest String -> Forest String)
-> DumpInstr inp (y : x : vs) n r
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd String
"swap" [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: DumpInstr inp (x : y : vs) n r -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp (x : y : vs) n r
k Forest String
is
instance Branchable DumpInstr where
  case_ :: forall inp x (vs :: [*]) (n :: Peano) r y.
DumpInstr inp (x : vs) n r
-> DumpInstr inp (y : vs) n r
-> DumpInstr inp (Either x y : vs) n r
case_ DumpInstr inp (x : vs) n r
l DumpInstr inp (y : vs) n r
r = (Forest String -> Forest String)
-> DumpInstr inp (Either x y : vs) n r
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String)
 -> DumpInstr inp (Either x y : vs) n r)
-> (Forest String -> Forest String)
-> DumpInstr inp (Either x y : vs) n r
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd String
"case"
    [ String -> Forest String -> Tree String
dumpInstrArg String
"left" (DumpInstr inp (x : vs) n r -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp (x : vs) n r
l [])
    , String -> Forest String -> Tree String
dumpInstrArg String
"right" (DumpInstr inp (y : vs) n r -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp (y : vs) n r
r [])
    ] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: Forest String
is
  choices :: forall v inp (vs :: [*]) (es :: Peano) ret.
[InstrPure (v -> Bool)]
-> [DumpInstr inp vs es ret]
-> DumpInstr inp vs es ret
-> DumpInstr inp (v : vs) es ret
choices [InstrPure (v -> Bool)]
ps [DumpInstr inp vs es ret]
bs DumpInstr inp vs es ret
d = (Forest String -> Forest String) -> DumpInstr inp (v : vs) es ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String) -> DumpInstr inp (v : vs) es ret)
-> (Forest String -> Forest String)
-> DumpInstr inp (v : vs) es ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is ->
    String -> Forest String -> Tree String
dumpInstrCmd (String
"choices "String -> String -> String
forall a. Semigroup a => a -> a -> a
<>[InstrPure (v -> Bool)] -> String
forall a. Show a => a -> String
show [InstrPure (v -> Bool)]
ps) (
      (String -> Forest String -> Tree String
dumpInstrArg String
"branch" (Forest String -> Tree String)
-> (DumpInstr inp vs es ret -> Forest String)
-> DumpInstr inp vs es ret
-> Tree String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Forest String -> Forest String) -> Forest String -> Forest String
forall a b. (a -> b) -> a -> b
$ []) ((Forest String -> Forest String) -> Forest String)
-> (DumpInstr inp vs es ret -> Forest String -> Forest String)
-> DumpInstr inp vs es ret
-> Forest String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DumpInstr inp vs es ret -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr (DumpInstr inp vs es ret -> Tree String)
-> [DumpInstr inp vs es ret] -> Forest String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [DumpInstr inp vs es ret]
bs) Forest String -> Forest String -> Forest String
forall a. Semigroup a => a -> a -> a
<>
      [ String -> Forest String -> Tree String
dumpInstrArg String
"default" (DumpInstr inp vs es ret -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp vs es ret
d []) ]
    ) Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: Forest String
is
instance Failable DumpInstr where
  fail :: forall inp (vs :: [*]) (es :: Peano) ret.
[ErrorItem (InputToken inp)] -> DumpInstr inp vs ('Succ es) ret
fail [ErrorItem (InputToken inp)]
_err = (Forest String -> Forest String) -> DumpInstr inp vs ('Succ es) ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String)
 -> DumpInstr inp vs ('Succ es) ret)
-> (Forest String -> Forest String)
-> DumpInstr inp vs ('Succ es) ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd String
"fail" [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: Forest String
is
  popFail :: forall inp (vs :: [*]) (es :: Peano) ret.
DumpInstr inp vs es ret -> DumpInstr inp vs ('Succ es) ret
popFail DumpInstr inp vs es ret
k = (Forest String -> Forest String) -> DumpInstr inp vs ('Succ es) ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String)
 -> DumpInstr inp vs ('Succ es) ret)
-> (Forest String -> Forest String)
-> DumpInstr inp vs ('Succ es) ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd String
"popFail" [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: DumpInstr inp vs es ret -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp vs es ret
k Forest String
is
  catchFail :: forall inp (vs :: [*]) (es :: Peano) ret.
DumpInstr inp vs ('Succ es) ret
-> DumpInstr inp (Cursor inp : vs) es ret
-> DumpInstr inp vs es ret
catchFail DumpInstr inp vs ('Succ es) ret
t DumpInstr inp (Cursor inp : vs) es ret
h = (Forest String -> Forest String) -> DumpInstr inp vs es ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String) -> DumpInstr inp vs es ret)
-> (Forest String -> Forest String) -> DumpInstr inp vs es ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd String
"catchFail"
    [ String -> Forest String -> Tree String
dumpInstrArg String
"try" (DumpInstr inp vs ('Succ es) ret -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp vs ('Succ es) ret
t [])
    , String -> Forest String -> Tree String
dumpInstrArg String
"handler" (DumpInstr inp (Cursor inp : vs) es ret
-> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp (Cursor inp : vs) es ret
h [])
    ] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: Forest String
is
instance Inputable DumpInstr where
  loadInput :: forall inp (vs :: [*]) (es :: Peano) r.
DumpInstr inp vs es r -> DumpInstr inp (Cursor inp : vs) es r
loadInput DumpInstr inp vs es r
k = (Forest String -> Forest String)
-> DumpInstr inp (Cursor inp : vs) es r
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String)
 -> DumpInstr inp (Cursor inp : vs) es r)
-> (Forest String -> Forest String)
-> DumpInstr inp (Cursor inp : vs) es r
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd String
"loadInput" [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: DumpInstr inp vs es r -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp vs es r
k Forest String
is
  pushInput :: forall inp (vs :: [*]) (es :: Peano) ret.
DumpInstr inp (Cursor inp : vs) es ret -> DumpInstr inp vs es ret
pushInput DumpInstr inp (Cursor inp : vs) es ret
k = (Forest String -> Forest String) -> DumpInstr inp vs es ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String) -> DumpInstr inp vs es ret)
-> (Forest String -> Forest String) -> DumpInstr inp vs es ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd String
"pushInput" [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: DumpInstr inp (Cursor inp : vs) es ret
-> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp (Cursor inp : vs) es ret
k Forest String
is
instance Routinable DumpInstr where
  subroutine :: forall v inp (vs :: [*]) (es :: Peano) ret.
LetName v
-> DumpInstr inp '[] ('Succ 'Zero) v
-> DumpInstr inp vs ('Succ es) ret
-> DumpInstr inp vs ('Succ es) ret
subroutine LetName v
n DumpInstr inp '[] ('Succ 'Zero) v
sub DumpInstr inp vs ('Succ es) ret
k = (Forest String -> Forest String) -> DumpInstr inp vs ('Succ es) ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String)
 -> DumpInstr inp vs ('Succ es) ret)
-> (Forest String -> Forest String)
-> DumpInstr inp vs ('Succ es) ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is ->
    String -> Forest String -> Tree String
forall a. a -> Forest a -> Tree a
Tree.Node (LetName v -> String
forall a. Show a => a -> String
show LetName v
nString -> String -> String
forall a. Semigroup a => a -> a -> a
<>String
":") (DumpInstr inp '[] ('Succ 'Zero) v -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp '[] ('Succ 'Zero) v
sub [])
    Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: DumpInstr inp vs ('Succ es) ret -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp vs ('Succ es) ret
k Forest String
is
  jump :: forall ret inp (es :: Peano).
LetName ret -> DumpInstr inp '[] ('Succ es) ret
jump LetName ret
n = (Forest String -> Forest String)
-> DumpInstr inp '[] ('Succ es) ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String)
 -> DumpInstr inp '[] ('Succ es) ret)
-> (Forest String -> Forest String)
-> DumpInstr inp '[] ('Succ es) ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd (String
"jump "String -> String -> String
forall a. Semigroup a => a -> a -> a
<>LetName ret -> String
forall a. Show a => a -> String
show LetName ret
n) [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: Forest String
is
  call :: forall v inp (vs :: [*]) (es :: Peano) ret.
LetName v
-> DumpInstr inp (v : vs) ('Succ es) ret
-> DumpInstr inp vs ('Succ es) ret
call LetName v
n DumpInstr inp (v : vs) ('Succ es) ret
k = (Forest String -> Forest String) -> DumpInstr inp vs ('Succ es) ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String)
 -> DumpInstr inp vs ('Succ es) ret)
-> (Forest String -> Forest String)
-> DumpInstr inp vs ('Succ es) ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd (String
"call "String -> String -> String
forall a. Semigroup a => a -> a -> a
<>LetName v -> String
forall a. Show a => a -> String
show LetName v
n) [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: DumpInstr inp (v : vs) ('Succ es) ret
-> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp (v : vs) ('Succ es) ret
k Forest String
is
  ret :: forall inp ret (es :: Peano). DumpInstr inp '[ret] es ret
ret = (Forest String -> Forest String) -> DumpInstr inp '[ret] es ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String) -> DumpInstr inp '[ret] es ret)
-> (Forest String -> Forest String) -> DumpInstr inp '[ret] es ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd String
"ret" [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: Forest String
is
instance Joinable DumpInstr where
  defJoin :: forall v inp (vs :: [*]) (es :: Peano) ret.
LetName v
-> DumpInstr inp (v : vs) es ret
-> DumpInstr inp vs es ret
-> DumpInstr inp vs es ret
defJoin LetName v
n DumpInstr inp (v : vs) es ret
sub DumpInstr inp vs es ret
k = (Forest String -> Forest String) -> DumpInstr inp vs es ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String) -> DumpInstr inp vs es ret)
-> (Forest String -> Forest String) -> DumpInstr inp vs es ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is ->
    String -> Forest String -> Tree String
forall a. a -> Forest a -> Tree a
Tree.Node (LetName v -> String
forall a. Show a => a -> String
show LetName v
nString -> String -> String
forall a. Semigroup a => a -> a -> a
<>String
":") (DumpInstr inp (v : vs) es ret -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp (v : vs) es ret
sub [])
    Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: DumpInstr inp vs es ret -> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp vs es ret
k Forest String
is
  refJoin :: forall v inp (vs :: [*]) (es :: Peano) ret.
LetName v -> DumpInstr inp (v : vs) es ret
refJoin LetName v
n = (Forest String -> Forest String) -> DumpInstr inp (v : vs) es ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String) -> DumpInstr inp (v : vs) es ret)
-> (Forest String -> Forest String)
-> DumpInstr inp (v : vs) es ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd (String
"refJoin "String -> String -> String
forall a. Semigroup a => a -> a -> a
<>LetName v -> String
forall a. Show a => a -> String
show LetName v
n) [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: Forest String
is
instance Readable DumpInstr inp where
  read :: forall inp (vs :: [*]) (es :: Peano) ret.
(inp ~ InputToken inp) =>
[ErrorItem inp]
-> InstrPure (inp -> Bool)
-> DumpInstr inp (inp : vs) ('Succ es) ret
-> DumpInstr inp vs ('Succ es) ret
read [ErrorItem inp]
_es InstrPure (inp -> Bool)
_p DumpInstr inp (inp : vs) ('Succ es) ret
k = (Forest String -> Forest String) -> DumpInstr inp vs ('Succ es) ret
forall inp (vs :: [*]) (es :: Peano) a.
(Forest String -> Forest String) -> DumpInstr inp vs es a
DumpInstr ((Forest String -> Forest String)
 -> DumpInstr inp vs ('Succ es) ret)
-> (Forest String -> Forest String)
-> DumpInstr inp vs ('Succ es) ret
forall a b. (a -> b) -> a -> b
$ \Forest String
is -> String -> Forest String -> Tree String
dumpInstrCmd String
"read" [] Tree String -> Forest String -> Forest String
forall a. a -> [a] -> [a]
: DumpInstr inp (inp : vs) ('Succ es) ret
-> Forest String -> Forest String
forall inp (vs :: [*]) (es :: Peano) a.
DumpInstr inp vs es a -> Forest String -> Forest String
unDumpInstr DumpInstr inp (inp : vs) ('Succ es) ret
k Forest String
is