{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PatternSynonyms #-}

module Unison.Runtime.MCode.Serialize
  ( putComb,
    getComb,
    putCombIx,
    getCombIx,
  )
where

import Data.Bytes.Get
import Data.Bytes.Put
import Data.Bytes.Serial
import Data.Bytes.VarInt
import Data.Primitive.PrimArray
import Data.Word (Word64)
import GHC.Exts (IsList (..))
import Unison.Runtime.MCode hiding (MatchT)
import Unison.Runtime.Serialize
import Unison.Util.Text qualified as Util.Text

putComb :: (MonadPut m) => (cix -> m ()) -> GComb cix -> m ()
putComb :: forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GComb cix -> m ()
putComb cix -> m ()
putCix (Lam Int
ua Int
ba Int
uf Int
bf GSection cix
body) =
  Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
ua m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
ba m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
uf m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
bf m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
putCix GSection cix
body

getComb :: (MonadGet m) => m cix -> m (GComb cix)
getComb :: forall (m :: * -> *) cix. MonadGet m => m cix -> m (GComb cix)
getComb m cix
gCix = Int -> Int -> Int -> Int -> GSection cix -> GComb cix
forall comb.
Int -> Int -> Int -> Int -> GSection comb -> GComb comb
Lam (Int -> Int -> Int -> Int -> GSection cix -> GComb cix)
-> m Int -> m (Int -> Int -> Int -> GSection cix -> GComb cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> Int -> Int -> GSection cix -> GComb cix)
-> m Int -> m (Int -> Int -> GSection cix -> GComb cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> Int -> GSection cix -> GComb cix)
-> m Int -> m (Int -> GSection cix -> GComb cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> GSection cix -> GComb cix)
-> m Int -> m (GSection cix -> GComb cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (GSection cix -> GComb cix) -> m (GSection cix) -> m (GComb cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix)

data SectionT
  = AppT
  | CallT
  | JumpT
  | MatchT
  | YieldT
  | InsT
  | LetT
  | DieT
  | ExitT
  | DMatchT
  | NMatchT
  | RMatchT

instance Tag SectionT where
  tag2word :: SectionT -> Word8
tag2word SectionT
AppT = Word8
0
  tag2word SectionT
CallT = Word8
1
  tag2word SectionT
JumpT = Word8
2
  tag2word SectionT
MatchT = Word8
3
  tag2word SectionT
YieldT = Word8
4
  tag2word SectionT
InsT = Word8
5
  tag2word SectionT
LetT = Word8
6
  tag2word SectionT
DieT = Word8
7
  tag2word SectionT
ExitT = Word8
8
  tag2word SectionT
DMatchT = Word8
9
  tag2word SectionT
NMatchT = Word8
10
  tag2word SectionT
RMatchT = Word8
11

  word2tag :: forall (m :: * -> *). MonadGet m => Word8 -> m SectionT
word2tag Word8
0 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
AppT
  word2tag Word8
1 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
CallT
  word2tag Word8
2 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
JumpT
  word2tag Word8
3 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
MatchT
  word2tag Word8
4 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
YieldT
  word2tag Word8
5 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
InsT
  word2tag Word8
6 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
LetT
  word2tag Word8
7 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
DieT
  word2tag Word8
8 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
ExitT
  word2tag Word8
9 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
DMatchT
  word2tag Word8
10 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
NMatchT
  word2tag Word8
11 = SectionT -> m SectionT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SectionT
RMatchT
  word2tag Word8
i = String -> Word8 -> m SectionT
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"SectionT" Word8
i

putSection :: (MonadPut m) => (cix -> m ()) -> GSection cix -> m ()
putSection :: forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix = \case
  App Bool
b GRef cix
r Args
a -> SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
AppT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Bool -> m ()
serialize Bool
b m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GRef cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GRef cix -> m ()
putRef cix -> m ()
pCix GRef cix
r m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Args -> m ()
forall (m :: * -> *). MonadPut m => Args -> m ()
putArgs Args
a
  Call Bool
b cix
cix Args
a -> SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
CallT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Bool -> m ()
serialize Bool
b m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> cix -> m ()
pCix cix
cix m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Args -> m ()
forall (m :: * -> *). MonadPut m => Args -> m ()
putArgs Args
a
  Jump Int
i Args
a -> SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
JumpT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Args -> m ()
forall (m :: * -> *). MonadPut m => Args -> m ()
putArgs Args
a
  Match Int
i GBranch cix
b -> SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
MatchT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GBranch cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GBranch cix -> m ()
putBranch cix -> m ()
pCix GBranch cix
b
  Yield Args
a -> SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
YieldT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Args -> m ()
forall (m :: * -> *). MonadPut m => Args -> m ()
putArgs Args
a
  Ins GInstr cix
i GSection cix
s -> SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
InsT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GInstr cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GInstr cix -> m ()
putInstr cix -> m ()
pCix GInstr cix
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix GSection cix
s
  Let GSection cix
s cix
ci -> SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
LetT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix GSection cix
s m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> cix -> m ()
pCix cix
ci
  Die String
s -> SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
DieT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> String -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => String -> m ()
serialize String
s
  GSection cix
Exit -> SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
ExitT
  DMatch Maybe Reference
mr Int
i GBranch cix
b -> SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
DMatchT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Maybe Reference -> (Reference -> m ()) -> m ()
forall (m :: * -> *) a.
MonadPut m =>
Maybe a -> (a -> m ()) -> m ()
putMaybe Maybe Reference
mr Reference -> m ()
forall (m :: * -> *). MonadPut m => Reference -> m ()
putReference m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GBranch cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GBranch cix -> m ()
putBranch cix -> m ()
pCix GBranch cix
b
  NMatch Maybe Reference
mr Int
i GBranch cix
b -> SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
NMatchT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Maybe Reference -> (Reference -> m ()) -> m ()
forall (m :: * -> *) a.
MonadPut m =>
Maybe a -> (a -> m ()) -> m ()
putMaybe Maybe Reference
mr Reference -> m ()
forall (m :: * -> *). MonadPut m => Reference -> m ()
putReference m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GBranch cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GBranch cix -> m ()
putBranch cix -> m ()
pCix GBranch cix
b
  RMatch Int
i GSection cix
pu EnumMap Word64 (GBranch cix)
bs ->
    SectionT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag SectionT
RMatchT
      m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
      m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix GSection cix
pu
      m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Word64 -> m ())
-> (GBranch cix -> m ()) -> EnumMap Word64 (GBranch cix) -> m ()
forall (m :: * -> *) k v.
(MonadPut m, EnumKey k) =>
(k -> m ()) -> (v -> m ()) -> EnumMap k v -> m ()
putEnumMap Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord ((cix -> m ()) -> GBranch cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GBranch cix -> m ()
putBranch cix -> m ()
pCix) EnumMap Word64 (GBranch cix)
bs

getSection :: (MonadGet m) => m cix -> m (GSection cix)
getSection :: forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix =
  m SectionT
forall (m :: * -> *) t. (MonadGet m, Tag t) => m t
getTag m SectionT -> (SectionT -> m (GSection cix)) -> m (GSection cix)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    SectionT
AppT -> Bool -> GRef cix -> Args -> GSection cix
forall comb. Bool -> GRef comb -> Args -> GSection comb
App (Bool -> GRef cix -> Args -> GSection cix)
-> m Bool -> m (GRef cix -> Args -> GSection cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Bool
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m Bool
deserialize m (GRef cix -> Args -> GSection cix)
-> m (GRef cix) -> m (Args -> GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix -> m (GRef cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GRef cix)
getRef m cix
gCix m (Args -> GSection cix) -> m Args -> m (GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Args
forall (m :: * -> *). MonadGet m => m Args
getArgs
    SectionT
CallT -> Bool -> cix -> Args -> GSection cix
forall comb. Bool -> comb -> Args -> GSection comb
Call (Bool -> cix -> Args -> GSection cix)
-> m Bool -> m (cix -> Args -> GSection cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Bool
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m Bool
deserialize m (cix -> Args -> GSection cix)
-> m cix -> m (Args -> GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix
gCix m (Args -> GSection cix) -> m Args -> m (GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Args
forall (m :: * -> *). MonadGet m => m Args
getArgs
    SectionT
JumpT -> Int -> Args -> GSection cix
forall comb. Int -> Args -> GSection comb
Jump (Int -> Args -> GSection cix) -> m Int -> m (Args -> GSection cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Args -> GSection cix) -> m Args -> m (GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Args
forall (m :: * -> *). MonadGet m => m Args
getArgs
    SectionT
MatchT -> Int -> GBranch cix -> GSection cix
forall comb. Int -> GBranch comb -> GSection comb
Match (Int -> GBranch cix -> GSection cix)
-> m Int -> m (GBranch cix -> GSection cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (GBranch cix -> GSection cix)
-> m (GBranch cix) -> m (GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix -> m (GBranch cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GBranch cix)
getBranch m cix
gCix
    SectionT
YieldT -> Args -> GSection cix
forall comb. Args -> GSection comb
Yield (Args -> GSection cix) -> m Args -> m (GSection cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Args
forall (m :: * -> *). MonadGet m => m Args
getArgs
    SectionT
InsT -> GInstr cix -> GSection cix -> GSection cix
forall comb. GInstr comb -> GSection comb -> GSection comb
Ins (GInstr cix -> GSection cix -> GSection cix)
-> m (GInstr cix) -> m (GSection cix -> GSection cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m cix -> m (GInstr cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GInstr cix)
getInstr m cix
gCix m (GSection cix -> GSection cix)
-> m (GSection cix) -> m (GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix
    SectionT
LetT -> GSection cix -> cix -> GSection cix
forall comb. GSection comb -> comb -> GSection comb
Let (GSection cix -> cix -> GSection cix)
-> m (GSection cix) -> m (cix -> GSection cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix m (cix -> GSection cix) -> m cix -> m (GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix
gCix
    SectionT
DieT -> String -> GSection cix
forall comb. String -> GSection comb
Die (String -> GSection cix) -> m String -> m (GSection cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m String
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m String
deserialize
    SectionT
ExitT -> GSection cix -> m (GSection cix)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure GSection cix
forall comb. GSection comb
Exit
    SectionT
DMatchT -> Maybe Reference -> Int -> GBranch cix -> GSection cix
forall comb.
Maybe Reference -> Int -> GBranch comb -> GSection comb
DMatch (Maybe Reference -> Int -> GBranch cix -> GSection cix)
-> m (Maybe Reference) -> m (Int -> GBranch cix -> GSection cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Reference -> m (Maybe Reference)
forall (m :: * -> *) a. MonadGet m => m a -> m (Maybe a)
getMaybe m Reference
forall (m :: * -> *). MonadGet m => m Reference
getReference m (Int -> GBranch cix -> GSection cix)
-> m Int -> m (GBranch cix -> GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (GBranch cix -> GSection cix)
-> m (GBranch cix) -> m (GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix -> m (GBranch cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GBranch cix)
getBranch m cix
gCix
    SectionT
NMatchT -> Maybe Reference -> Int -> GBranch cix -> GSection cix
forall comb.
Maybe Reference -> Int -> GBranch comb -> GSection comb
NMatch (Maybe Reference -> Int -> GBranch cix -> GSection cix)
-> m (Maybe Reference) -> m (Int -> GBranch cix -> GSection cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Reference -> m (Maybe Reference)
forall (m :: * -> *) a. MonadGet m => m a -> m (Maybe a)
getMaybe m Reference
forall (m :: * -> *). MonadGet m => m Reference
getReference m (Int -> GBranch cix -> GSection cix)
-> m Int -> m (GBranch cix -> GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (GBranch cix -> GSection cix)
-> m (GBranch cix) -> m (GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix -> m (GBranch cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GBranch cix)
getBranch m cix
gCix
    SectionT
RMatchT ->
      Int -> GSection cix -> EnumMap Word64 (GBranch cix) -> GSection cix
forall comb.
Int
-> GSection comb -> EnumMap Word64 (GBranch comb) -> GSection comb
RMatch (Int
 -> GSection cix -> EnumMap Word64 (GBranch cix) -> GSection cix)
-> m Int
-> m (GSection cix -> EnumMap Word64 (GBranch cix) -> GSection cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (GSection cix -> EnumMap Word64 (GBranch cix) -> GSection cix)
-> m (GSection cix)
-> m (EnumMap Word64 (GBranch cix) -> GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix m (EnumMap Word64 (GBranch cix) -> GSection cix)
-> m (EnumMap Word64 (GBranch cix)) -> m (GSection cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Word64 -> m (GBranch cix) -> m (EnumMap Word64 (GBranch cix))
forall (m :: * -> *) k v.
(MonadGet m, EnumKey k) =>
m k -> m v -> m (EnumMap k v)
getEnumMap m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord (m cix -> m (GBranch cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GBranch cix)
getBranch m cix
gCix)

data InstrT
  = UPrim1T
  | UPrim2T
  | BPrim1T
  | BPrim2T
  | ForeignCallT
  | SetDynT
  | CaptureT
  | NameT
  | InfoT
  | PackT
  | UnpackT
  | LitT
  | PrintT
  | ResetT
  | ForkT
  | AtomicallyT
  | SeqT
  | TryForceT
  | BLitT

instance Tag InstrT where
  tag2word :: InstrT -> Word8
tag2word InstrT
UPrim1T = Word8
0
  tag2word InstrT
UPrim2T = Word8
1
  tag2word InstrT
BPrim1T = Word8
2
  tag2word InstrT
BPrim2T = Word8
3
  tag2word InstrT
ForeignCallT = Word8
4
  tag2word InstrT
SetDynT = Word8
5
  tag2word InstrT
CaptureT = Word8
6
  tag2word InstrT
NameT = Word8
7
  tag2word InstrT
InfoT = Word8
8
  tag2word InstrT
PackT = Word8
9
  tag2word InstrT
UnpackT = Word8
10
  tag2word InstrT
LitT = Word8
11
  tag2word InstrT
PrintT = Word8
12
  tag2word InstrT
ResetT = Word8
13
  tag2word InstrT
ForkT = Word8
14
  tag2word InstrT
AtomicallyT = Word8
15
  tag2word InstrT
SeqT = Word8
16
  tag2word InstrT
TryForceT = Word8
17
  tag2word InstrT
BLitT = Word8
18

  word2tag :: forall (m :: * -> *). MonadGet m => Word8 -> m InstrT
word2tag Word8
0 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
UPrim1T
  word2tag Word8
1 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
UPrim2T
  word2tag Word8
2 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
BPrim1T
  word2tag Word8
3 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
BPrim2T
  word2tag Word8
4 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
ForeignCallT
  word2tag Word8
5 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
SetDynT
  word2tag Word8
6 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
CaptureT
  word2tag Word8
7 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
NameT
  word2tag Word8
8 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
InfoT
  word2tag Word8
9 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
PackT
  word2tag Word8
10 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
UnpackT
  word2tag Word8
11 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
LitT
  word2tag Word8
12 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
PrintT
  word2tag Word8
13 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
ResetT
  word2tag Word8
14 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
ForkT
  word2tag Word8
15 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
AtomicallyT
  word2tag Word8
16 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
SeqT
  word2tag Word8
17 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
TryForceT
  word2tag Word8
18 = InstrT -> m InstrT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InstrT
BLitT
  word2tag Word8
n = String -> Word8 -> m InstrT
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"InstrT" Word8
n

putInstr :: (MonadPut m) => (cix -> m ()) -> GInstr cix -> m ()
putInstr :: forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GInstr cix -> m ()
putInstr cix -> m ()
pCix = \case
  (UPrim1 UPrim1
up Int
i) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
UPrim1T m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> UPrim1 -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag UPrim1
up m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
  (UPrim2 UPrim2
up Int
i Int
j) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
UPrim2T m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> UPrim2 -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag UPrim2
up m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
j
  (BPrim1 BPrim1
bp Int
i) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
BPrim1T m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> BPrim1 -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag BPrim1
bp m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
  (BPrim2 BPrim2
bp Int
i Int
j) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
BPrim2T m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> BPrim2 -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag BPrim2
bp m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
j
  (ForeignCall Bool
b Word64
w Args
a) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
ForeignCallT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Bool -> m ()
serialize Bool
b m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord Word64
w m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Args -> m ()
forall (m :: * -> *). MonadPut m => Args -> m ()
putArgs Args
a
  (SetDyn Word64
w Int
i) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
SetDynT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord Word64
w m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
  (Capture Word64
w) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
CaptureT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord Word64
w
  (Name GRef cix
r Args
a) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
NameT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GRef cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GRef cix -> m ()
putRef cix -> m ()
pCix GRef cix
r m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Args -> m ()
forall (m :: * -> *). MonadPut m => Args -> m ()
putArgs Args
a
  (Info String
s) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
InfoT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> String -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => String -> m ()
serialize String
s
  (Pack Reference
r Word64
w Args
a) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
PackT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Reference -> m ()
forall (m :: * -> *). MonadPut m => Reference -> m ()
putReference Reference
r m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord Word64
w m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Args -> m ()
forall (m :: * -> *). MonadPut m => Args -> m ()
putArgs Args
a
  (Unpack Maybe Reference
mr Int
i) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
UnpackT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Maybe Reference -> (Reference -> m ()) -> m ()
forall (m :: * -> *) a.
MonadPut m =>
Maybe a -> (a -> m ()) -> m ()
putMaybe Maybe Reference
mr Reference -> m ()
forall (m :: * -> *). MonadPut m => Reference -> m ()
putReference m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
  (Lit MLit
l) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
LitT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> MLit -> m ()
forall (m :: * -> *). MonadPut m => MLit -> m ()
putLit MLit
l
  (BLit Reference
r Word64
tt MLit
l) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
BLitT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Reference -> m ()
forall (m :: * -> *). MonadPut m => Reference -> m ()
putReference Reference
r m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
putNat Word64
tt m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> MLit -> m ()
forall (m :: * -> *). MonadPut m => MLit -> m ()
putLit MLit
l
  (Print Int
i) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
PrintT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
  (Reset EnumSet Word64
s) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
ResetT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Word64 -> m ()) -> EnumSet Word64 -> m ()
forall (m :: * -> *) k.
(MonadPut m, EnumKey k) =>
(k -> m ()) -> EnumSet k -> m ()
putEnumSet Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord EnumSet Word64
s
  (Fork Int
i) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
ForkT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
  (Atomically Int
i) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
AtomicallyT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
  (Seq Args
a) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
SeqT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Args -> m ()
forall (m :: * -> *). MonadPut m => Args -> m ()
putArgs Args
a
  (TryForce Int
i) -> InstrT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag InstrT
TryForceT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i

getInstr :: (MonadGet m) => m cix -> m (GInstr cix)
getInstr :: forall (m :: * -> *) cix. MonadGet m => m cix -> m (GInstr cix)
getInstr m cix
gCix =
  m InstrT
forall (m :: * -> *) t. (MonadGet m, Tag t) => m t
getTag m InstrT -> (InstrT -> m (GInstr cix)) -> m (GInstr cix)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    InstrT
UPrim1T -> UPrim1 -> Int -> GInstr cix
forall comb. UPrim1 -> Int -> GInstr comb
UPrim1 (UPrim1 -> Int -> GInstr cix) -> m UPrim1 -> m (Int -> GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m UPrim1
forall (m :: * -> *) t. (MonadGet m, Tag t) => m t
getTag m (Int -> GInstr cix) -> m Int -> m (GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    InstrT
UPrim2T -> UPrim2 -> Int -> Int -> GInstr cix
forall comb. UPrim2 -> Int -> Int -> GInstr comb
UPrim2 (UPrim2 -> Int -> Int -> GInstr cix)
-> m UPrim2 -> m (Int -> Int -> GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m UPrim2
forall (m :: * -> *) t. (MonadGet m, Tag t) => m t
getTag m (Int -> Int -> GInstr cix) -> m Int -> m (Int -> GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> GInstr cix) -> m Int -> m (GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    InstrT
BPrim1T -> BPrim1 -> Int -> GInstr cix
forall comb. BPrim1 -> Int -> GInstr comb
BPrim1 (BPrim1 -> Int -> GInstr cix) -> m BPrim1 -> m (Int -> GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m BPrim1
forall (m :: * -> *) t. (MonadGet m, Tag t) => m t
getTag m (Int -> GInstr cix) -> m Int -> m (GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    InstrT
BPrim2T -> BPrim2 -> Int -> Int -> GInstr cix
forall comb. BPrim2 -> Int -> Int -> GInstr comb
BPrim2 (BPrim2 -> Int -> Int -> GInstr cix)
-> m BPrim2 -> m (Int -> Int -> GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m BPrim2
forall (m :: * -> *) t. (MonadGet m, Tag t) => m t
getTag m (Int -> Int -> GInstr cix) -> m Int -> m (Int -> GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> GInstr cix) -> m Int -> m (GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    InstrT
ForeignCallT -> Bool -> Word64 -> Args -> GInstr cix
forall comb. Bool -> Word64 -> Args -> GInstr comb
ForeignCall (Bool -> Word64 -> Args -> GInstr cix)
-> m Bool -> m (Word64 -> Args -> GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Bool
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m Bool
deserialize m (Word64 -> Args -> GInstr cix)
-> m Word64 -> m (Args -> GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord m (Args -> GInstr cix) -> m Args -> m (GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Args
forall (m :: * -> *). MonadGet m => m Args
getArgs
    InstrT
SetDynT -> Word64 -> Int -> GInstr cix
forall comb. Word64 -> Int -> GInstr comb
SetDyn (Word64 -> Int -> GInstr cix) -> m Word64 -> m (Int -> GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord m (Int -> GInstr cix) -> m Int -> m (GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    InstrT
CaptureT -> Word64 -> GInstr cix
forall comb. Word64 -> GInstr comb
Capture (Word64 -> GInstr cix) -> m Word64 -> m (GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord
    InstrT
NameT -> GRef cix -> Args -> GInstr cix
forall comb. GRef comb -> Args -> GInstr comb
Name (GRef cix -> Args -> GInstr cix)
-> m (GRef cix) -> m (Args -> GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m cix -> m (GRef cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GRef cix)
getRef m cix
gCix m (Args -> GInstr cix) -> m Args -> m (GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Args
forall (m :: * -> *). MonadGet m => m Args
getArgs
    InstrT
InfoT -> String -> GInstr cix
forall comb. String -> GInstr comb
Info (String -> GInstr cix) -> m String -> m (GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m String
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m String
deserialize
    InstrT
PackT -> Reference -> Word64 -> Args -> GInstr cix
forall comb. Reference -> Word64 -> Args -> GInstr comb
Pack (Reference -> Word64 -> Args -> GInstr cix)
-> m Reference -> m (Word64 -> Args -> GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Reference
forall (m :: * -> *). MonadGet m => m Reference
getReference m (Word64 -> Args -> GInstr cix)
-> m Word64 -> m (Args -> GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord m (Args -> GInstr cix) -> m Args -> m (GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Args
forall (m :: * -> *). MonadGet m => m Args
getArgs
    InstrT
UnpackT -> Maybe Reference -> Int -> GInstr cix
forall comb. Maybe Reference -> Int -> GInstr comb
Unpack (Maybe Reference -> Int -> GInstr cix)
-> m (Maybe Reference) -> m (Int -> GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Reference -> m (Maybe Reference)
forall (m :: * -> *) a. MonadGet m => m a -> m (Maybe a)
getMaybe m Reference
forall (m :: * -> *). MonadGet m => m Reference
getReference m (Int -> GInstr cix) -> m Int -> m (GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    InstrT
LitT -> MLit -> GInstr cix
forall comb. MLit -> GInstr comb
Lit (MLit -> GInstr cix) -> m MLit -> m (GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m MLit
forall (m :: * -> *). MonadGet m => m MLit
getLit
    InstrT
BLitT -> Reference -> Word64 -> MLit -> GInstr cix
forall comb. Reference -> Word64 -> MLit -> GInstr comb
BLit (Reference -> Word64 -> MLit -> GInstr cix)
-> m Reference -> m (Word64 -> MLit -> GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Reference
forall (m :: * -> *). MonadGet m => m Reference
getReference m (Word64 -> MLit -> GInstr cix)
-> m Word64 -> m (MLit -> GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Word64
forall (m :: * -> *). MonadGet m => m Word64
getNat m (MLit -> GInstr cix) -> m MLit -> m (GInstr cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m MLit
forall (m :: * -> *). MonadGet m => m MLit
getLit
    InstrT
PrintT -> Int -> GInstr cix
forall comb. Int -> GInstr comb
Print (Int -> GInstr cix) -> m Int -> m (GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    InstrT
ResetT -> EnumSet Word64 -> GInstr cix
forall comb. EnumSet Word64 -> GInstr comb
Reset (EnumSet Word64 -> GInstr cix)
-> m (EnumSet Word64) -> m (GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Word64 -> m (EnumSet Word64)
forall (m :: * -> *) k.
(MonadGet m, EnumKey k) =>
m k -> m (EnumSet k)
getEnumSet m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord
    InstrT
ForkT -> Int -> GInstr cix
forall comb. Int -> GInstr comb
Fork (Int -> GInstr cix) -> m Int -> m (GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    InstrT
AtomicallyT -> Int -> GInstr cix
forall comb. Int -> GInstr comb
Atomically (Int -> GInstr cix) -> m Int -> m (GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    InstrT
SeqT -> Args -> GInstr cix
forall comb. Args -> GInstr comb
Seq (Args -> GInstr cix) -> m Args -> m (GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Args
forall (m :: * -> *). MonadGet m => m Args
getArgs
    InstrT
TryForceT -> Int -> GInstr cix
forall comb. Int -> GInstr comb
TryForce (Int -> GInstr cix) -> m Int -> m (GInstr cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt

data ArgsT
  = ZArgsT
  | UArg1T
  | UArg2T
  | BArg1T
  | BArg2T
  | DArg2T
  | UArgRT
  | BArgRT
  | DArgRT
  | BArgNT
  | UArgNT
  | DArgNT
  | DArgVT

instance Tag ArgsT where
  tag2word :: ArgsT -> Word8
tag2word ArgsT
ZArgsT = Word8
0
  tag2word ArgsT
UArg1T = Word8
1
  tag2word ArgsT
UArg2T = Word8
2
  tag2word ArgsT
BArg1T = Word8
3
  tag2word ArgsT
BArg2T = Word8
4
  tag2word ArgsT
DArg2T = Word8
5
  tag2word ArgsT
UArgRT = Word8
6
  tag2word ArgsT
BArgRT = Word8
7
  tag2word ArgsT
DArgRT = Word8
8
  tag2word ArgsT
BArgNT = Word8
9
  tag2word ArgsT
UArgNT = Word8
10
  tag2word ArgsT
DArgNT = Word8
11
  tag2word ArgsT
DArgVT = Word8
12

  word2tag :: forall (m :: * -> *). MonadGet m => Word8 -> m ArgsT
word2tag Word8
0 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
ZArgsT
  word2tag Word8
1 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
UArg1T
  word2tag Word8
2 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
UArg2T
  word2tag Word8
3 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
BArg1T
  word2tag Word8
4 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
BArg2T
  word2tag Word8
5 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
DArg2T
  word2tag Word8
6 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
UArgRT
  word2tag Word8
7 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
BArgRT
  word2tag Word8
8 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
DArgRT
  word2tag Word8
9 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
BArgNT
  word2tag Word8
10 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
UArgNT
  word2tag Word8
11 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
DArgNT
  word2tag Word8
12 = ArgsT -> m ArgsT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgsT
DArgVT
  word2tag Word8
n = String -> Word8 -> m ArgsT
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"ArgsT" Word8
n

putArgs :: (MonadPut m) => Args -> m ()
putArgs :: forall (m :: * -> *). MonadPut m => Args -> m ()
putArgs Args
ZArgs = ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
ZArgsT
putArgs (UArg1 Int
i) = ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
UArg1T m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
putArgs (UArg2 Int
i Int
j) = ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
UArg1T m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
j
putArgs (BArg1 Int
i) = ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
BArg1T m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
putArgs (BArg2 Int
i Int
j) = ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
BArg2T m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
j
putArgs (DArg2 Int
i Int
j) = ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
DArg2T m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
j
putArgs (UArgR Int
i Int
j) = ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
UArgRT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
j
putArgs (BArgR Int
i Int
j) = ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
BArgRT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
j
putArgs (DArgR Int
i Int
j Int
k Int
l) =
  ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
DArgRT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
j m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
k m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
l
putArgs (BArgN PrimArray Int
pa) = ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
BArgNT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> PrimArray Int -> m ()
forall (m :: * -> *). MonadPut m => PrimArray Int -> m ()
putIntArr PrimArray Int
pa
putArgs (UArgN PrimArray Int
pa) = ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
UArgNT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> PrimArray Int -> m ()
forall (m :: * -> *). MonadPut m => PrimArray Int -> m ()
putIntArr PrimArray Int
pa
putArgs (DArgN PrimArray Int
ua PrimArray Int
ba) =
  ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
DArgNT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> PrimArray Int -> m ()
forall (m :: * -> *). MonadPut m => PrimArray Int -> m ()
putIntArr PrimArray Int
ua m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> PrimArray Int -> m ()
forall (m :: * -> *). MonadPut m => PrimArray Int -> m ()
putIntArr PrimArray Int
ba
putArgs (DArgV Int
i Int
j) = ArgsT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag ArgsT
DArgVT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
j

getArgs :: (MonadGet m) => m Args
getArgs :: forall (m :: * -> *). MonadGet m => m Args
getArgs =
  m ArgsT
forall (m :: * -> *) t. (MonadGet m, Tag t) => m t
getTag m ArgsT -> (ArgsT -> m Args) -> m Args
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    ArgsT
ZArgsT -> Args -> m Args
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Args
ZArgs
    ArgsT
UArg1T -> Int -> Args
UArg1 (Int -> Args) -> m Int -> m Args
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    ArgsT
UArg2T -> Int -> Int -> Args
UArg2 (Int -> Int -> Args) -> m Int -> m (Int -> Args)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> Args) -> m Int -> m Args
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    ArgsT
BArg1T -> Int -> Args
BArg1 (Int -> Args) -> m Int -> m Args
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    ArgsT
BArg2T -> Int -> Int -> Args
BArg2 (Int -> Int -> Args) -> m Int -> m (Int -> Args)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> Args) -> m Int -> m Args
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    ArgsT
DArg2T -> Int -> Int -> Args
DArg2 (Int -> Int -> Args) -> m Int -> m (Int -> Args)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> Args) -> m Int -> m Args
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    ArgsT
UArgRT -> Int -> Int -> Args
UArgR (Int -> Int -> Args) -> m Int -> m (Int -> Args)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> Args) -> m Int -> m Args
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    ArgsT
BArgRT -> Int -> Int -> Args
BArgR (Int -> Int -> Args) -> m Int -> m (Int -> Args)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> Args) -> m Int -> m Args
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    ArgsT
DArgRT -> Int -> Int -> Int -> Int -> Args
DArgR (Int -> Int -> Int -> Int -> Args)
-> m Int -> m (Int -> Int -> Int -> Args)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> Int -> Int -> Args) -> m Int -> m (Int -> Int -> Args)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> Int -> Args) -> m Int -> m (Int -> Args)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> Args) -> m Int -> m Args
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    ArgsT
BArgNT -> PrimArray Int -> Args
BArgN (PrimArray Int -> Args) -> m (PrimArray Int) -> m Args
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (PrimArray Int)
forall (m :: * -> *). MonadGet m => m (PrimArray Int)
getIntArr
    ArgsT
UArgNT -> PrimArray Int -> Args
UArgN (PrimArray Int -> Args) -> m (PrimArray Int) -> m Args
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (PrimArray Int)
forall (m :: * -> *). MonadGet m => m (PrimArray Int)
getIntArr
    ArgsT
DArgNT -> PrimArray Int -> PrimArray Int -> Args
DArgN (PrimArray Int -> PrimArray Int -> Args)
-> m (PrimArray Int) -> m (PrimArray Int -> Args)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (PrimArray Int)
forall (m :: * -> *). MonadGet m => m (PrimArray Int)
getIntArr m (PrimArray Int -> Args) -> m (PrimArray Int) -> m Args
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m (PrimArray Int)
forall (m :: * -> *). MonadGet m => m (PrimArray Int)
getIntArr
    ArgsT
DArgVT -> Int -> Int -> Args
DArgV (Int -> Int -> Args) -> m Int -> m (Int -> Args)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt m (Int -> Args) -> m Int -> m Args
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt

data RefT = StkT | EnvT | DynT

instance Tag RefT where
  tag2word :: RefT -> Word8
tag2word RefT
StkT = Word8
0
  tag2word RefT
EnvT = Word8
1
  tag2word RefT
DynT = Word8
2

  word2tag :: forall (m :: * -> *). MonadGet m => Word8 -> m RefT
word2tag Word8
0 = RefT -> m RefT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure RefT
StkT
  word2tag Word8
1 = RefT -> m RefT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure RefT
EnvT
  word2tag Word8
2 = RefT -> m RefT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure RefT
DynT
  word2tag Word8
n = String -> Word8 -> m RefT
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"RefT" Word8
n

putRef :: (MonadPut m) => (cix -> m ()) -> GRef cix -> m ()
putRef :: forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GRef cix -> m ()
putRef cix -> m ()
_pCix (Stk Int
i) = RefT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag RefT
StkT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
putRef cix -> m ()
pCix (Env cix
cix) = RefT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag RefT
EnvT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> cix -> m ()
pCix cix
cix
putRef cix -> m ()
_pCix (Dyn Word64
i) = RefT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag RefT
DynT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord Word64
i

getRef :: (MonadGet m) => m cix -> m (GRef cix)
getRef :: forall (m :: * -> *) cix. MonadGet m => m cix -> m (GRef cix)
getRef m cix
gCix =
  m RefT
forall (m :: * -> *) t. (MonadGet m, Tag t) => m t
getTag m RefT -> (RefT -> m (GRef cix)) -> m (GRef cix)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    RefT
StkT -> Int -> GRef cix
forall comb. Int -> GRef comb
Stk (Int -> GRef cix) -> m Int -> m (GRef cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    RefT
EnvT -> cix -> GRef cix
forall comb. comb -> GRef comb
Env (cix -> GRef cix) -> m cix -> m (GRef cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m cix
gCix
    RefT
DynT -> Word64 -> GRef cix
forall comb. Word64 -> GRef comb
Dyn (Word64 -> GRef cix) -> m Word64 -> m (GRef cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord

putCombIx :: (MonadPut m) => CombIx -> m ()
putCombIx :: forall (m :: * -> *). MonadPut m => CombIx -> m ()
putCombIx (CIx Reference
r Word64
n Word64
i) = Reference -> m ()
forall (m :: * -> *). MonadPut m => Reference -> m ()
putReference Reference
r m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord Word64
n m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord Word64
i

getCombIx :: (MonadGet m) => m CombIx
getCombIx :: forall (m :: * -> *). MonadGet m => m CombIx
getCombIx = Reference -> Word64 -> Word64 -> CombIx
CIx (Reference -> Word64 -> Word64 -> CombIx)
-> m Reference -> m (Word64 -> Word64 -> CombIx)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Reference
forall (m :: * -> *). MonadGet m => m Reference
getReference m (Word64 -> Word64 -> CombIx) -> m Word64 -> m (Word64 -> CombIx)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord m (Word64 -> CombIx) -> m Word64 -> m CombIx
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord

data MLitT = MIT | MDT | MTT | MMT | MYT

instance Tag MLitT where
  tag2word :: MLitT -> Word8
tag2word MLitT
MIT = Word8
0
  tag2word MLitT
MDT = Word8
1
  tag2word MLitT
MTT = Word8
2
  tag2word MLitT
MMT = Word8
3
  tag2word MLitT
MYT = Word8
4

  word2tag :: forall (m :: * -> *). MonadGet m => Word8 -> m MLitT
word2tag Word8
0 = MLitT -> m MLitT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MLitT
MIT
  word2tag Word8
1 = MLitT -> m MLitT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MLitT
MDT
  word2tag Word8
2 = MLitT -> m MLitT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MLitT
MTT
  word2tag Word8
3 = MLitT -> m MLitT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MLitT
MMT
  word2tag Word8
4 = MLitT -> m MLitT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MLitT
MYT
  word2tag Word8
n = String -> Word8 -> m MLitT
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"MLitT" Word8
n

putLit :: (MonadPut m) => MLit -> m ()
putLit :: forall (m :: * -> *). MonadPut m => MLit -> m ()
putLit (MI Int
i) = MLitT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag MLitT
MIT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i
putLit (MD Double
d) = MLitT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag MLitT
MDT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Double -> m ()
forall (m :: * -> *). MonadPut m => Double -> m ()
putFloat Double
d
putLit (MT Text
t) = MLitT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag MLitT
MTT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Text -> m ()
forall (m :: * -> *). MonadPut m => Text -> m ()
putText (Text -> Text
Util.Text.toText Text
t)
putLit (MM Referent
r) = MLitT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag MLitT
MMT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Referent -> m ()
forall (m :: * -> *). MonadPut m => Referent -> m ()
putReferent Referent
r
putLit (MY Reference
r) = MLitT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag MLitT
MYT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Reference -> m ()
forall (m :: * -> *). MonadPut m => Reference -> m ()
putReference Reference
r

getLit :: (MonadGet m) => m MLit
getLit :: forall (m :: * -> *). MonadGet m => m MLit
getLit =
  m MLitT
forall (m :: * -> *) t. (MonadGet m, Tag t) => m t
getTag m MLitT -> (MLitT -> m MLit) -> m MLit
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    MLitT
MIT -> Int -> MLit
MI (Int -> MLit) -> m Int -> m MLit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int
forall (m :: * -> *). MonadGet m => m Int
gInt
    MLitT
MDT -> Double -> MLit
MD (Double -> MLit) -> m Double -> m MLit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Double
forall (m :: * -> *). MonadGet m => m Double
getFloat
    MLitT
MTT -> Text -> MLit
MT (Text -> MLit) -> (Text -> Text) -> Text -> MLit
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
Util.Text.fromText (Text -> MLit) -> m Text -> m MLit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Text
forall (m :: * -> *). MonadGet m => m Text
getText
    MLitT
MMT -> Referent -> MLit
MM (Referent -> MLit) -> m Referent -> m MLit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Referent
forall (m :: * -> *). MonadGet m => m Referent
getReferent
    MLitT
MYT -> Reference -> MLit
MY (Reference -> MLit) -> m Reference -> m MLit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Reference
forall (m :: * -> *). MonadGet m => m Reference
getReference

data BranchT = Test1T | Test2T | TestWT | TestTT

instance Tag BranchT where
  tag2word :: BranchT -> Word8
tag2word BranchT
Test1T = Word8
0
  tag2word BranchT
Test2T = Word8
1
  tag2word BranchT
TestWT = Word8
2
  tag2word BranchT
TestTT = Word8
3

  word2tag :: forall (m :: * -> *). MonadGet m => Word8 -> m BranchT
word2tag Word8
0 = BranchT -> m BranchT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BranchT
Test1T
  word2tag Word8
1 = BranchT -> m BranchT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BranchT
Test2T
  word2tag Word8
2 = BranchT -> m BranchT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BranchT
TestWT
  word2tag Word8
3 = BranchT -> m BranchT
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BranchT
TestTT
  word2tag Word8
n = String -> Word8 -> m BranchT
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"BranchT" Word8
n

putBranch :: (MonadPut m) => (cix -> m ()) -> GBranch cix -> m ()
putBranch :: forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GBranch cix -> m ()
putBranch cix -> m ()
pCix (Test1 Word64
w GSection cix
s GSection cix
d) =
  BranchT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag BranchT
Test1T m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord Word64
w m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix GSection cix
s m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix GSection cix
d
putBranch cix -> m ()
pCix (Test2 Word64
a GSection cix
sa Word64
b GSection cix
sb GSection cix
d) =
  BranchT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag BranchT
Test2T
    m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord Word64
a
    m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix GSection cix
sa
    m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord Word64
b
    m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix GSection cix
sb
    m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix GSection cix
d
putBranch cix -> m ()
pCix (TestW GSection cix
d EnumMap Word64 (GSection cix)
m) =
  BranchT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag BranchT
TestWT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix GSection cix
d m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Word64 -> m ())
-> (GSection cix -> m ()) -> EnumMap Word64 (GSection cix) -> m ()
forall (m :: * -> *) k v.
(MonadPut m, EnumKey k) =>
(k -> m ()) -> (v -> m ()) -> EnumMap k v -> m ()
putEnumMap Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord ((cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix) EnumMap Word64 (GSection cix)
m
putBranch cix -> m ()
pCix (TestT GSection cix
d Map Text (GSection cix)
m) =
  BranchT -> m ()
forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag BranchT
TestTT m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix GSection cix
d m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Text -> m ())
-> (GSection cix -> m ()) -> Map Text (GSection cix) -> m ()
forall (m :: * -> *) a b.
MonadPut m =>
(a -> m ()) -> (b -> m ()) -> Map a b -> m ()
putMap (Text -> m ()
forall (m :: * -> *). MonadPut m => Text -> m ()
putText (Text -> m ()) -> (Text -> Text) -> Text -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
Util.Text.toText) ((cix -> m ()) -> GSection cix -> m ()
forall (m :: * -> *) cix.
MonadPut m =>
(cix -> m ()) -> GSection cix -> m ()
putSection cix -> m ()
pCix) Map Text (GSection cix)
m

getBranch :: (MonadGet m) => m cix -> m (GBranch cix)
getBranch :: forall (m :: * -> *) cix. MonadGet m => m cix -> m (GBranch cix)
getBranch m cix
gCix =
  m BranchT
forall (m :: * -> *) t. (MonadGet m, Tag t) => m t
getTag m BranchT -> (BranchT -> m (GBranch cix)) -> m (GBranch cix)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    BranchT
Test1T -> Word64 -> GSection cix -> GSection cix -> GBranch cix
forall comb.
Word64 -> GSection comb -> GSection comb -> GBranch comb
Test1 (Word64 -> GSection cix -> GSection cix -> GBranch cix)
-> m Word64 -> m (GSection cix -> GSection cix -> GBranch cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord m (GSection cix -> GSection cix -> GBranch cix)
-> m (GSection cix) -> m (GSection cix -> GBranch cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix m (GSection cix -> GBranch cix)
-> m (GSection cix) -> m (GBranch cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix
    BranchT
Test2T ->
      Word64
-> GSection cix
-> Word64
-> GSection cix
-> GSection cix
-> GBranch cix
forall comb.
Word64
-> GSection comb
-> Word64
-> GSection comb
-> GSection comb
-> GBranch comb
Test2
        (Word64
 -> GSection cix
 -> Word64
 -> GSection cix
 -> GSection cix
 -> GBranch cix)
-> m Word64
-> m (GSection cix
      -> Word64 -> GSection cix -> GSection cix -> GBranch cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord
        m (GSection cix
   -> Word64 -> GSection cix -> GSection cix -> GBranch cix)
-> m (GSection cix)
-> m (Word64 -> GSection cix -> GSection cix -> GBranch cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix
        m (Word64 -> GSection cix -> GSection cix -> GBranch cix)
-> m Word64 -> m (GSection cix -> GSection cix -> GBranch cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord
        m (GSection cix -> GSection cix -> GBranch cix)
-> m (GSection cix) -> m (GSection cix -> GBranch cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix
        m (GSection cix -> GBranch cix)
-> m (GSection cix) -> m (GBranch cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix
    BranchT
TestWT -> GSection cix -> EnumMap Word64 (GSection cix) -> GBranch cix
forall comb.
GSection comb -> EnumMap Word64 (GSection comb) -> GBranch comb
TestW (GSection cix -> EnumMap Word64 (GSection cix) -> GBranch cix)
-> m (GSection cix)
-> m (EnumMap Word64 (GSection cix) -> GBranch cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix m (EnumMap Word64 (GSection cix) -> GBranch cix)
-> m (EnumMap Word64 (GSection cix)) -> m (GBranch cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Word64 -> m (GSection cix) -> m (EnumMap Word64 (GSection cix))
forall (m :: * -> *) k v.
(MonadGet m, EnumKey k) =>
m k -> m v -> m (EnumMap k v)
getEnumMap m Word64
forall (m :: * -> *). MonadGet m => m Word64
gWord (m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix)
    BranchT
TestTT -> GSection cix -> Map Text (GSection cix) -> GBranch cix
forall comb.
GSection comb -> Map Text (GSection comb) -> GBranch comb
TestT (GSection cix -> Map Text (GSection cix) -> GBranch cix)
-> m (GSection cix) -> m (Map Text (GSection cix) -> GBranch cix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix m (Map Text (GSection cix) -> GBranch cix)
-> m (Map Text (GSection cix)) -> m (GBranch cix)
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m Text -> m (GSection cix) -> m (Map Text (GSection cix))
forall (m :: * -> *) a b.
(MonadGet m, Ord a) =>
m a -> m b -> m (Map a b)
getMap (Text -> Text
Util.Text.fromText (Text -> Text) -> m Text -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Text
forall (m :: * -> *). MonadGet m => m Text
getText) (m cix -> m (GSection cix)
forall (m :: * -> *) cix. MonadGet m => m cix -> m (GSection cix)
getSection m cix
gCix)

gInt :: (MonadGet m) => m Int
gInt :: forall (m :: * -> *). MonadGet m => m Int
gInt = VarInt Int -> Int
forall n. VarInt n -> n
unVarInt (VarInt Int -> Int) -> m (VarInt Int) -> m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (VarInt Int)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (VarInt Int)
deserialize

pInt :: (MonadPut m) => Int -> m ()
pInt :: forall (m :: * -> *). MonadPut m => Int -> m ()
pInt Int
i = VarInt Int -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => VarInt Int -> m ()
serialize (Int -> VarInt Int
forall n. n -> VarInt n
VarInt Int
i)

gWord :: (MonadGet m) => m Word64
gWord :: forall (m :: * -> *). MonadGet m => m Word64
gWord = VarInt Word64 -> Word64
forall n. VarInt n -> n
unVarInt (VarInt Word64 -> Word64) -> m (VarInt Word64) -> m Word64
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (VarInt Word64)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (VarInt Word64)
deserialize

pWord :: (MonadPut m) => Word64 -> m ()
pWord :: forall (m :: * -> *). MonadPut m => Word64 -> m ()
pWord Word64
w = VarInt Word64 -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => VarInt Word64 -> m ()
serialize (Word64 -> VarInt Word64
forall n. n -> VarInt n
VarInt Word64
w)

putIntArr :: (MonadPut m) => PrimArray Int -> m ()
putIntArr :: forall (m :: * -> *). MonadPut m => PrimArray Int -> m ()
putIntArr PrimArray Int
pa = (Int -> m ()) -> [Int] -> m ()
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, MonadPut m) =>
(a -> m ()) -> f a -> m ()
putFoldable Int -> m ()
forall (m :: * -> *). MonadPut m => Int -> m ()
pInt ([Int] -> m ()) -> [Int] -> m ()
forall a b. (a -> b) -> a -> b
$ PrimArray Int -> [Item (PrimArray Int)]
forall l. IsList l => l -> [Item l]
toList PrimArray Int
pa

getIntArr :: (MonadGet m) => m (PrimArray Int)
getIntArr :: forall (m :: * -> *). MonadGet m => m (PrimArray Int)
getIntArr = [Int] -> PrimArray Int
[Item (PrimArray Int)] -> PrimArray Int
forall l. IsList l => [Item l] -> l
fromList ([Int] -> PrimArray Int) -> m [Int] -> m (PrimArray Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Int -> m [Int]
forall (m :: * -> *) a. MonadGet m => m a -> m [a]
getList m Int
forall (m :: * -> *). MonadGet m => m Int
gInt