{-# LANGUAGE PatternSynonyms #-}

module Unison.Runtime.Serialize where

import Control.Monad (replicateM)
import Data.Bits (Bits)
import Data.ByteString qualified as B
import Data.Bytes.Get hiding (getBytes)
import Data.Bytes.Get qualified as Ser
import Data.Bytes.Put
import Data.Bytes.Serial
import Data.Bytes.Signed (Unsigned)
import Data.Bytes.VarInt
import Data.Foldable (traverse_)
import Data.Int (Int64)
import Data.Map.Strict as Map (Map, fromList, toList)
import Data.Text (Text)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import Data.Vector.Primitive qualified as BA
import Data.Word (Word64, Word8)
import GHC.Exts as IL (IsList (..))
import Unison.ConstructorReference (ConstructorReference, GConstructorReference (..))
import Unison.ConstructorType qualified as CT
import Unison.Hash (Hash)
import Unison.Hash qualified as Hash
import Unison.Reference (Id' (..), Reference, Reference' (Builtin, DerivedId), pattern Derived)
import Unison.Referent (Referent, pattern Con, pattern Ref)
import Unison.Runtime.Array qualified as PA
import Unison.Runtime.Exception
import Unison.Runtime.MCode
  ( Prim1 (..),
    Prim2 (..),
  )
import Unison.Util.Bytes qualified as Bytes
import Unison.Util.EnumContainers as EC

unknownTag :: (MonadGet m) => String -> Word8 -> m a
unknownTag :: forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
t Word8
w =
  m (Remaining m)
forall (m :: * -> *). MonadGet m => m (Remaining m)
remaining m (Remaining m) -> (Remaining m -> m a) -> m a
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Remaining m
r ->
    String -> m a
forall a. HasCallStack => String -> a
exn (String -> m a) -> String -> m a
forall a b. (a -> b) -> a -> b
$
      String
"unknown "
        String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
t
        String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" word: "
        String -> String -> String
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
w
        String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" ("
        String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (forall a b. (Integral a, Num b) => a -> b
fromIntegral @_ @Int Remaining m
r)
        String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" bytes remaining)"

class Tag t where
  tag2word :: t -> Word8
  word2tag :: (MonadGet m) => Word8 -> m t

putTag :: (MonadPut m) => (Tag t) => t -> m ()
putTag :: forall (m :: * -> *) t. (MonadPut m, Tag t) => t -> m ()
putTag = Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 (Word8 -> m ()) -> (t -> Word8) -> t -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Word8
forall t. Tag t => t -> Word8
tag2word

getTag :: (MonadGet m) => (Tag t) => m t
getTag :: forall (m :: * -> *) t. (MonadGet m, Tag t) => m t
getTag = Word8 -> m t
forall t (m :: * -> *). (Tag t, MonadGet m) => Word8 -> m t
forall (m :: * -> *). MonadGet m => Word8 -> m t
word2tag (Word8 -> m t) -> m Word8 -> m t
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m Word8
forall (m :: * -> *). MonadGet m => m Word8
getWord8

-- Some basics, moved over from V1 serialization
putChar :: (MonadPut m) => Char -> m ()
putChar :: forall (m :: * -> *). MonadPut m => Char -> m ()
putChar = VarInt Int -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => VarInt Int -> m ()
serialize (VarInt Int -> m ()) -> (Char -> VarInt Int) -> Char -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> VarInt Int
forall n. n -> VarInt n
VarInt (Int -> VarInt Int) -> (Char -> Int) -> Char -> VarInt Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
forall a. Enum a => a -> Int
fromEnum

getChar :: (MonadGet m) => m Char
getChar :: forall (m :: * -> *). MonadGet m => m Char
getChar = Int -> Char
forall a. Enum a => Int -> a
toEnum (Int -> Char) -> (VarInt Int -> Int) -> VarInt Int -> Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VarInt Int -> Int
forall n. VarInt n -> n
unVarInt (VarInt Int -> Char) -> m (VarInt Int) -> m Char
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

putFloat :: (MonadPut m) => Double -> m ()
putFloat :: forall (m :: * -> *). MonadPut m => Double -> m ()
putFloat = Double -> m ()
forall a (m :: * -> *). (SerialEndian a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Double -> m ()
serializeBE

getFloat :: (MonadGet m) => m Double
getFloat :: forall (m :: * -> *). MonadGet m => m Double
getFloat = m Double
forall a (m :: * -> *). (SerialEndian a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m Double
deserializeBE

putBool :: (MonadPut m) => Bool -> m ()
putBool :: forall (m :: * -> *). MonadPut m => Bool -> m ()
putBool Bool
b = Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 (if Bool
b then Word8
1 else Word8
0)

getBool :: (MonadGet m) => m Bool
getBool :: forall (m :: * -> *). MonadGet m => m Bool
getBool = Word8 -> m Bool
forall {a} {f :: * -> *}.
(Eq a, Num a, Applicative f, Show a) =>
a -> f Bool
d (Word8 -> m Bool) -> m Word8 -> m Bool
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m Word8
forall (m :: * -> *). MonadGet m => m Word8
getWord8
  where
    d :: a -> f Bool
d a
0 = Bool -> f Bool
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
    d a
1 = Bool -> f Bool
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
    d a
n = String -> f Bool
forall a. HasCallStack => String -> a
exn (String -> f Bool) -> String -> f Bool
forall a b. (a -> b) -> a -> b
$ String
"getBool: bad tag: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
n

putNat :: (MonadPut m) => Word64 -> m ()
putNat :: forall (m :: * -> *). MonadPut m => Word64 -> m ()
putNat = Word64 -> m ()
forall (m :: * -> *). MonadPut m => Word64 -> m ()
putWord64be

getNat :: (MonadGet m) => m Word64
getNat :: forall (m :: * -> *). MonadGet m => m Word64
getNat = m Word64
forall (m :: * -> *). MonadGet m => m Word64
getWord64be

putInt :: (MonadPut m) => Int64 -> m ()
putInt :: forall (m :: * -> *). MonadPut m => Int64 -> m ()
putInt = Int64 -> m ()
forall a (m :: * -> *). (SerialEndian a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => Int64 -> m ()
serializeBE

getInt :: (MonadGet m) => m Int64
getInt :: forall (m :: * -> *). MonadGet m => m Int64
getInt = m Int64
forall a (m :: * -> *). (SerialEndian a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m Int64
deserializeBE

putLength ::
  ( MonadPut m,
    Integral n,
    Integral (Unsigned n),
    Bits n,
    Bits (Unsigned n)
  ) =>
  n ->
  m ()
putLength :: forall (m :: * -> *) n.
(MonadPut m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
n -> m ()
putLength = VarInt n -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => VarInt n -> m ()
serialize (VarInt n -> m ()) -> (n -> VarInt n) -> n -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. n -> VarInt n
forall n. n -> VarInt n
VarInt

getLength ::
  ( MonadGet m,
    Integral n,
    Integral (Unsigned n),
    Bits n,
    Bits (Unsigned n)
  ) =>
  m n
getLength :: forall (m :: * -> *) n.
(MonadGet m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
m n
getLength = VarInt n -> n
forall n. VarInt n -> n
unVarInt (VarInt n -> n) -> m (VarInt n) -> m n
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (VarInt n)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (VarInt n)
deserialize

-- Checks for negatives, in case you put an Integer, which does not
-- behave properly for negative numbers.
putPositive ::
  (MonadPut m, Bits n, Bits (Unsigned n), Integral n, Integral (Unsigned n)) =>
  n ->
  m ()
putPositive :: forall (m :: * -> *) n.
(MonadPut m, Bits n, Bits (Unsigned n), Integral n,
 Integral (Unsigned n)) =>
n -> m ()
putPositive n
n
  | n
n n -> n -> Bool
forall a. Ord a => a -> a -> Bool
< n
0 = String -> m ()
forall a. HasCallStack => String -> a
exn (String -> m ()) -> String -> m ()
forall a b. (a -> b) -> a -> b
$ String
"putPositive: negative number: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show (n -> Integer
forall a. Integral a => a -> Integer
toInteger n
n)
  | Bool
otherwise = VarInt n -> m ()
forall a (m :: * -> *). (Serial a, MonadPut m) => a -> m ()
forall (m :: * -> *). MonadPut m => VarInt n -> m ()
serialize (n -> VarInt n
forall n. n -> VarInt n
VarInt n
n)

-- Reads as an Integer, then checks that the result will fit in the
-- result type.
getPositive :: forall m n. (Bounded n, Integral n, MonadGet m) => m n
getPositive :: forall (m :: * -> *) n. (Bounded n, Integral n, MonadGet m) => m n
getPositive = Integer -> m n
validate (Integer -> m n)
-> (VarInt Integer -> Integer) -> VarInt Integer -> m n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VarInt Integer -> Integer
forall n. VarInt n -> n
unVarInt (VarInt Integer -> m n) -> m (VarInt Integer) -> m n
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m (VarInt Integer)
forall a (m :: * -> *). (Serial a, MonadGet m) => m a
forall (m :: * -> *). MonadGet m => m (VarInt Integer)
deserialize
  where
    mx0 :: n
    mx0 :: n
mx0 = n
forall a. Bounded a => a
maxBound
    mx :: Integer
    mx :: Integer
mx = n -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral n
mx0

    validate :: Integer -> m n
    validate :: Integer -> m n
validate Integer
n
      | Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
mx = n -> m n
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (n -> m n) -> n -> m n
forall a b. (a -> b) -> a -> b
$ Integer -> n
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n
      | Bool
otherwise = String -> m n
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m n) -> String -> m n
forall a b. (a -> b) -> a -> b
$ String
"getPositive: overflow: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
n

putFoldable ::
  (Foldable f, MonadPut m) => (a -> m ()) -> f a -> m ()
putFoldable :: forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, MonadPut m) =>
(a -> m ()) -> f a -> m ()
putFoldable a -> m ()
putA f a
as = do
  Int -> m ()
forall (m :: * -> *) n.
(MonadPut m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
n -> m ()
putLength (f a -> Int
forall a. f a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length f a
as)
  (a -> m ()) -> f a -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ a -> m ()
putA f a
as

putMap :: (MonadPut m) => (a -> m ()) -> (b -> m ()) -> Map a b -> m ()
putMap :: forall (m :: * -> *) a b.
MonadPut m =>
(a -> m ()) -> (b -> m ()) -> Map a b -> m ()
putMap a -> m ()
putA b -> m ()
putB Map a b
m = ((a, b) -> m ()) -> [(a, b)] -> m ()
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, MonadPut m) =>
(a -> m ()) -> f a -> m ()
putFoldable ((a -> m ()) -> (b -> m ()) -> (a, b) -> m ()
forall (m :: * -> *) a b.
MonadPut m =>
(a -> m ()) -> (b -> m ()) -> (a, b) -> m ()
putPair a -> m ()
putA b -> m ()
putB) (Map a b -> [(a, b)]
forall k a. Map k a -> [(k, a)]
Map.toList Map a b
m)

getList :: (MonadGet m) => m a -> m [a]
getList :: forall (m :: * -> *) a. MonadGet m => m a -> m [a]
getList m a
a = m Int
forall (m :: * -> *) n.
(MonadGet m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
m n
getLength m Int -> (Int -> m [a]) -> m [a]
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Int -> m a -> m [a]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
`replicateM` m a
a)

getMap :: (MonadGet m, Ord a) => m a -> m b -> m (Map a b)
getMap :: forall (m :: * -> *) a b.
(MonadGet m, Ord a) =>
m a -> m b -> m (Map a b)
getMap m a
getA m b
getB = [(a, b)] -> Map a b
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(a, b)] -> Map a b) -> m [(a, b)] -> m (Map a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (a, b) -> m [(a, b)]
forall (m :: * -> *) a. MonadGet m => m a -> m [a]
getList (m a -> m b -> m (a, b)
forall (m :: * -> *) a b. MonadGet m => m a -> m b -> m (a, b)
getPair m a
getA m b
getB)

putEnumMap ::
  (MonadPut m) =>
  (EnumKey k) =>
  (k -> m ()) ->
  (v -> m ()) ->
  EnumMap k v ->
  m ()
putEnumMap :: forall (m :: * -> *) k v.
(MonadPut m, EnumKey k) =>
(k -> m ()) -> (v -> m ()) -> EnumMap k v -> m ()
putEnumMap k -> m ()
pk v -> m ()
pv EnumMap k v
m = ((k, v) -> m ()) -> [(k, v)] -> m ()
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, MonadPut m) =>
(a -> m ()) -> f a -> m ()
putFoldable ((k -> m ()) -> (v -> m ()) -> (k, v) -> m ()
forall (m :: * -> *) a b.
MonadPut m =>
(a -> m ()) -> (b -> m ()) -> (a, b) -> m ()
putPair k -> m ()
pk v -> m ()
pv) (EnumMap k v -> [(k, v)]
forall k a. EnumKey k => EnumMap k a -> [(k, a)]
mapToList EnumMap k v
m)

getEnumMap :: (MonadGet m) => (EnumKey k) => m k -> m v -> m (EnumMap k v)
getEnumMap :: forall (m :: * -> *) k v.
(MonadGet m, EnumKey k) =>
m k -> m v -> m (EnumMap k v)
getEnumMap m k
gk m v
gv = [(k, v)] -> EnumMap k v
forall k a. EnumKey k => [(k, a)] -> EnumMap k a
mapFromList ([(k, v)] -> EnumMap k v) -> m [(k, v)] -> m (EnumMap k v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (k, v) -> m [(k, v)]
forall (m :: * -> *) a. MonadGet m => m a -> m [a]
getList (m k -> m v -> m (k, v)
forall (m :: * -> *) a b. MonadGet m => m a -> m b -> m (a, b)
getPair m k
gk m v
gv)

putEnumSet :: (MonadPut m) => (EnumKey k) => (k -> m ()) -> EnumSet k -> m ()
putEnumSet :: forall (m :: * -> *) k.
(MonadPut m, EnumKey k) =>
(k -> m ()) -> EnumSet k -> m ()
putEnumSet k -> m ()
pk EnumSet k
s = Int -> m ()
forall (m :: * -> *) n.
(MonadPut m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
n -> m ()
putLength (EnumSet k -> Int
forall k. EnumSet k -> Int
setSize EnumSet k
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
*> (k -> m ()) -> EnumSet k -> m ()
forall (f :: * -> *) k.
(Applicative f, EnumKey k) =>
(k -> f ()) -> EnumSet k -> f ()
traverseSet_ k -> m ()
pk EnumSet k
s

getEnumSet :: (MonadGet m) => (EnumKey k) => m k -> m (EnumSet k)
getEnumSet :: forall (m :: * -> *) k.
(MonadGet m, EnumKey k) =>
m k -> m (EnumSet k)
getEnumSet m k
gk = [k] -> EnumSet k
forall k. EnumKey k => [k] -> EnumSet k
setFromList ([k] -> EnumSet k) -> m [k] -> m (EnumSet k)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m k -> m [k]
forall (m :: * -> *) a. MonadGet m => m a -> m [a]
getList m k
gk

putMaybe :: (MonadPut m) => Maybe a -> (a -> m ()) -> m ()
putMaybe :: forall (m :: * -> *) a.
MonadPut m =>
Maybe a -> (a -> m ()) -> m ()
putMaybe Maybe a
Nothing a -> m ()
_ = Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
0
putMaybe (Just a
a) a -> m ()
putA = Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
1 m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> a -> m ()
putA a
a

getMaybe :: (MonadGet m) => m a -> m (Maybe a)
getMaybe :: forall (m :: * -> *) a. MonadGet m => m a -> m (Maybe a)
getMaybe m a
getA =
  m Word8
forall (m :: * -> *). MonadGet m => m Word8
getWord8 m Word8 -> (Word8 -> m (Maybe a)) -> m (Maybe a)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Word8
tag -> case Word8
tag of
    Word8
0 -> Maybe a -> m (Maybe a)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing
    Word8
1 -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> m a -> m (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
getA
    Word8
_ -> String -> Word8 -> m (Maybe a)
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"Maybe" Word8
tag

putPair :: (MonadPut m) => (a -> m ()) -> (b -> m ()) -> (a, b) -> m ()
putPair :: forall (m :: * -> *) a b.
MonadPut m =>
(a -> m ()) -> (b -> m ()) -> (a, b) -> m ()
putPair a -> m ()
putA b -> m ()
putB (a
a, b
b) = a -> m ()
putA a
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
*> b -> m ()
putB b
b

getPair :: (MonadGet m) => m a -> m b -> m (a, b)
getPair :: forall (m :: * -> *) a b. MonadGet m => m a -> m b -> m (a, b)
getPair = (a -> b -> (a, b)) -> m a -> m b -> m (a, b)
forall a b c. (a -> b -> c) -> m a -> m b -> m c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,)

getBytes :: (MonadGet m) => m Bytes.Bytes
getBytes :: forall (m :: * -> *). MonadGet m => m Bytes
getBytes = [Chunk] -> Bytes
Bytes.fromChunks ([Chunk] -> Bytes) -> m [Chunk] -> m Bytes
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Chunk -> m [Chunk]
forall (m :: * -> *) a. MonadGet m => m a -> m [a]
getList m Chunk
forall (m :: * -> *). MonadGet m => m Chunk
getBlock

putBytes :: (MonadPut m) => Bytes.Bytes -> m ()
putBytes :: forall (m :: * -> *). MonadPut m => Bytes -> m ()
putBytes = (Chunk -> m ()) -> [Chunk] -> m ()
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, MonadPut m) =>
(a -> m ()) -> f a -> m ()
putFoldable Chunk -> m ()
forall (m :: * -> *). MonadPut m => Chunk -> m ()
putBlock ([Chunk] -> m ()) -> (Bytes -> [Chunk]) -> Bytes -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bytes -> [Chunk]
Bytes.chunks

getByteArray :: (MonadGet m) => m PA.ByteArray
getByteArray :: forall (m :: * -> *). MonadGet m => m ByteArray
getByteArray = [Word8] -> ByteArray
forall a. Prim a => [a] -> ByteArray
PA.byteArrayFromList ([Word8] -> ByteArray) -> m [Word8] -> m ByteArray
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Word8 -> m [Word8]
forall (m :: * -> *) a. MonadGet m => m a -> m [a]
getList m Word8
forall (m :: * -> *). MonadGet m => m Word8
getWord8

putByteArray :: (MonadPut m) => PA.ByteArray -> m ()
putByteArray :: forall (m :: * -> *). MonadPut m => ByteArray -> m ()
putByteArray ByteArray
a = (Word8 -> m ()) -> [Word8] -> m ()
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, MonadPut m) =>
(a -> m ()) -> f a -> m ()
putFoldable Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 (ByteArray -> [Item ByteArray]
forall l. IsList l => l -> [Item l]
IL.toList ByteArray
a)

getArray :: (MonadGet m) => m a -> m (PA.Array a)
getArray :: forall (m :: * -> *) a. MonadGet m => m a -> m (Array a)
getArray m a
getThing = [a] -> Array a
forall a. [a] -> Array a
PA.arrayFromList ([a] -> Array a) -> m [a] -> m (Array a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a -> m [a]
forall (m :: * -> *) a. MonadGet m => m a -> m [a]
getList m a
getThing

putArray :: (MonadPut m) => (a -> m ()) -> PA.Array a -> m ()
putArray :: forall (m :: * -> *) a.
MonadPut m =>
(a -> m ()) -> Array a -> m ()
putArray a -> m ()
putThing Array a
a = (a -> m ()) -> [a] -> m ()
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, MonadPut m) =>
(a -> m ()) -> f a -> m ()
putFoldable a -> m ()
putThing (Array a -> [Item (Array a)]
forall l. IsList l => l -> [Item l]
IL.toList Array a
a)

getBlock :: (MonadGet m) => m Bytes.Chunk
getBlock :: forall (m :: * -> *). MonadGet m => m Chunk
getBlock = m Int
forall (m :: * -> *) n.
(MonadGet m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
m n
getLength m Int -> (Int -> m Chunk) -> m Chunk
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ByteString -> Chunk) -> m ByteString -> m Chunk
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Chunk
Bytes.byteStringToChunk (m ByteString -> m Chunk)
-> (Int -> m ByteString) -> Int -> m Chunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> m ByteString
forall (m :: * -> *). MonadGet m => Int -> m ByteString
getByteString

putBlock :: (MonadPut m) => Bytes.Chunk -> m ()
putBlock :: forall (m :: * -> *). MonadPut m => Chunk -> m ()
putBlock Chunk
b = Int -> m ()
forall (m :: * -> *) n.
(MonadPut m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
n -> m ()
putLength (Chunk -> Int
forall a. Prim a => Vector a -> Int
BA.length Chunk
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
*> ByteString -> m ()
forall (m :: * -> *). MonadPut m => ByteString -> m ()
putByteString (Chunk -> ByteString
Bytes.chunkToByteString Chunk
b)

putHash :: (MonadPut m) => Hash -> m ()
putHash :: forall (m :: * -> *). MonadPut m => Hash -> m ()
putHash Hash
h = do
  let bs :: ByteString
bs = Hash -> ByteString
Hash.toByteString Hash
h
  Int -> m ()
forall (m :: * -> *) n.
(MonadPut m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
n -> m ()
putLength (ByteString -> Int
B.length ByteString
bs)
  ByteString -> m ()
forall (m :: * -> *). MonadPut m => ByteString -> m ()
putByteString ByteString
bs

getHash :: (MonadGet m) => m Hash
getHash :: forall (m :: * -> *). MonadGet m => m Hash
getHash = do
  Int
len <- m Int
forall (m :: * -> *) n.
(MonadGet m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
m n
getLength
  ByteString
bs <- ByteString -> ByteString
B.copy (ByteString -> ByteString) -> m ByteString -> m ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> m ByteString
forall (m :: * -> *). MonadGet m => Int -> m ByteString
Ser.getBytes Int
len
  pure $ ByteString -> Hash
Hash.fromByteString ByteString
bs

putReferent :: (MonadPut m) => Referent -> m ()
putReferent :: forall (m :: * -> *). MonadPut m => Referent -> m ()
putReferent = \case
  Ref TermReference
r -> do
    Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
0
    TermReference -> m ()
forall (m :: * -> *). MonadPut m => TermReference -> m ()
putReference TermReference
r
  Con ConstructorReference
r ConstructorType
ct -> do
    Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
1
    ConstructorReference -> m ()
forall (m :: * -> *). MonadPut m => ConstructorReference -> m ()
putConstructorReference ConstructorReference
r
    ConstructorType -> m ()
forall (m :: * -> *). MonadPut m => ConstructorType -> m ()
putConstructorType ConstructorType
ct

getReferent :: (MonadGet m) => m Referent
getReferent :: forall (m :: * -> *). MonadGet m => m Referent
getReferent = do
  Word8
tag <- m Word8
forall (m :: * -> *). MonadGet m => m Word8
getWord8
  case Word8
tag of
    Word8
0 -> TermReference -> Referent
Ref (TermReference -> Referent) -> m TermReference -> m Referent
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m TermReference
forall (m :: * -> *). MonadGet m => m TermReference
getReference
    Word8
1 -> ConstructorReference -> ConstructorType -> Referent
Con (ConstructorReference -> ConstructorType -> Referent)
-> m ConstructorReference -> m (ConstructorType -> Referent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m ConstructorReference
forall (m :: * -> *). MonadGet m => m ConstructorReference
getConstructorReference m (ConstructorType -> Referent) -> m ConstructorType -> m Referent
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m ConstructorType
forall (m :: * -> *). MonadGet m => m ConstructorType
getConstructorType
    Word8
_ -> String -> Word8 -> m Referent
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"getReferent" Word8
tag

getConstructorType :: (MonadGet m) => m CT.ConstructorType
getConstructorType :: forall (m :: * -> *). MonadGet m => m ConstructorType
getConstructorType =
  m Word8
forall (m :: * -> *). MonadGet m => m Word8
getWord8 m Word8 -> (Word8 -> m ConstructorType) -> m ConstructorType
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
    Word8
0 -> ConstructorType -> m ConstructorType
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ConstructorType
CT.Data
    Word8
1 -> ConstructorType -> m ConstructorType
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ConstructorType
CT.Effect
    Word8
t -> String -> Word8 -> m ConstructorType
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"getConstructorType" Word8
t

putConstructorType :: (MonadPut m) => CT.ConstructorType -> m ()
putConstructorType :: forall (m :: * -> *). MonadPut m => ConstructorType -> m ()
putConstructorType = \case
  ConstructorType
CT.Data -> Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
0
  ConstructorType
CT.Effect -> Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
1

putText :: (MonadPut m) => Text -> m ()
putText :: forall (m :: * -> *). MonadPut m => Text -> m ()
putText Text
text = do
  let bs :: ByteString
bs = Text -> ByteString
encodeUtf8 Text
text
  Int -> m ()
forall (m :: * -> *) n.
(MonadPut m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
n -> m ()
putLength (Int -> m ()) -> Int -> m ()
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
bs
  ByteString -> m ()
forall (m :: * -> *). MonadPut m => ByteString -> m ()
putByteString ByteString
bs

getText :: (MonadGet m) => m Text
getText :: forall (m :: * -> *). MonadGet m => m Text
getText = do
  Int
len <- m Int
forall (m :: * -> *) n.
(MonadGet m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
m n
getLength
  ByteString
bs <- ByteString -> ByteString
B.copy (ByteString -> ByteString) -> m ByteString -> m ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> m ByteString
forall (m :: * -> *). MonadGet m => Int -> m ByteString
Ser.getBytes Int
len
  pure $ ByteString -> Text
decodeUtf8 ByteString
bs

putReference :: (MonadPut m) => Reference -> m ()
putReference :: forall (m :: * -> *). MonadPut m => TermReference -> m ()
putReference TermReference
r = case TermReference
r of
  Builtin Text
name -> do
    Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
0
    Text -> m ()
forall (m :: * -> *). MonadPut m => Text -> m ()
putText Text
name
  Derived Hash
hash Word64
i -> do
    Word8 -> m ()
forall (m :: * -> *). MonadPut m => Word8 -> m ()
putWord8 Word8
1
    Hash -> m ()
forall (m :: * -> *). MonadPut m => Hash -> m ()
putHash Hash
hash
    Word64 -> m ()
forall (m :: * -> *) n.
(MonadPut m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
n -> m ()
putLength Word64
i

getReference :: (MonadGet m) => m Reference
getReference :: forall (m :: * -> *). MonadGet m => m TermReference
getReference = do
  Word8
tag <- m Word8
forall (m :: * -> *). MonadGet m => m Word8
getWord8
  case Word8
tag of
    Word8
0 -> Text -> TermReference
forall t h. t -> Reference' t h
Builtin (Text -> TermReference) -> m Text -> m TermReference
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Text
forall (m :: * -> *). MonadGet m => m Text
getText
    Word8
1 -> Id' Hash -> TermReference
forall h t. Id' h -> Reference' t h
DerivedId (Id' Hash -> TermReference) -> m (Id' Hash) -> m TermReference
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Hash -> Word64 -> Id' Hash
forall h. h -> Word64 -> Id' h
Id (Hash -> Word64 -> Id' Hash) -> m Hash -> m (Word64 -> Id' Hash)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Hash
forall (m :: * -> *). MonadGet m => m Hash
getHash m (Word64 -> Id' Hash) -> m Word64 -> m (Id' Hash)
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 :: * -> *) n.
(MonadGet m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
m n
getLength)
    Word8
_ -> String -> Word8 -> m TermReference
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"Reference" Word8
tag

putConstructorReference :: (MonadPut m) => ConstructorReference -> m ()
putConstructorReference :: forall (m :: * -> *). MonadPut m => ConstructorReference -> m ()
putConstructorReference (ConstructorReference TermReference
r Word64
i) = do
  TermReference -> m ()
forall (m :: * -> *). MonadPut m => TermReference -> m ()
putReference TermReference
r
  Word64 -> m ()
forall (m :: * -> *) n.
(MonadPut m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
n -> m ()
putLength Word64
i

getConstructorReference :: (MonadGet m) => m ConstructorReference
getConstructorReference :: forall (m :: * -> *). MonadGet m => m ConstructorReference
getConstructorReference =
  TermReference -> Word64 -> ConstructorReference
forall r. r -> Word64 -> GConstructorReference r
ConstructorReference (TermReference -> Word64 -> ConstructorReference)
-> m TermReference -> m (Word64 -> ConstructorReference)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m TermReference
forall (m :: * -> *). MonadGet m => m TermReference
getReference m (Word64 -> ConstructorReference)
-> m Word64 -> m ConstructorReference
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 :: * -> *) n.
(MonadGet m, Integral n, Integral (Unsigned n), Bits n,
 Bits (Unsigned n)) =>
m n
getLength

instance Tag Prim1 where
  tag2word :: Prim1 -> Word8
tag2word Prim1
DECI = Word8
0
  tag2word Prim1
DECN = Word8
1
  tag2word Prim1
INCI = Word8
2
  tag2word Prim1
INCN = Word8
3
  tag2word Prim1
NEGI = Word8
4
  tag2word Prim1
SGNI = Word8
5
  tag2word Prim1
LZRO = Word8
6
  tag2word Prim1
TZRO = Word8
7
  tag2word Prim1
COMN = Word8
8
  tag2word Prim1
COMI = Word8
9
  tag2word Prim1
POPC = Word8
10
  tag2word Prim1
ABSF = Word8
11
  tag2word Prim1
EXPF = Word8
12
  tag2word Prim1
LOGF = Word8
13
  tag2word Prim1
SQRT = Word8
14
  tag2word Prim1
COSF = Word8
15
  tag2word Prim1
ACOS = Word8
16
  tag2word Prim1
COSH = Word8
17
  tag2word Prim1
ACSH = Word8
18
  tag2word Prim1
SINF = Word8
19
  tag2word Prim1
ASIN = Word8
20
  tag2word Prim1
SINH = Word8
21
  tag2word Prim1
ASNH = Word8
22
  tag2word Prim1
TANF = Word8
23
  tag2word Prim1
ATAN = Word8
24
  tag2word Prim1
TANH = Word8
25
  tag2word Prim1
ATNH = Word8
26
  tag2word Prim1
ITOF = Word8
27
  tag2word Prim1
NTOF = Word8
28
  tag2word Prim1
CEIL = Word8
29
  tag2word Prim1
FLOR = Word8
30
  tag2word Prim1
TRNF = Word8
31
  tag2word Prim1
RNDF = Word8
32
  tag2word Prim1
TRNC = Word8
33
  tag2word Prim1
NOTB = Word8
34

  tag2word Prim1
SIZT = Word8
35
  tag2word Prim1
USNC = Word8
36
  tag2word Prim1
UCNS = Word8
37
  tag2word Prim1
ITOT = Word8
38
  tag2word Prim1
NTOT = Word8
39
  tag2word Prim1
FTOT = Word8
40
  tag2word Prim1
TTOI = Word8
41
  tag2word Prim1
TTON = Word8
42
  tag2word Prim1
TTOF = Word8
43
  tag2word Prim1
PAKT = Word8
44
  tag2word Prim1
UPKT = Word8
45
  tag2word Prim1
VWLS = Word8
46
  tag2word Prim1
VWRS = Word8
47
  tag2word Prim1
SIZS = Word8
48
  tag2word Prim1
PAKB = Word8
49
  tag2word Prim1
UPKB = Word8
50
  tag2word Prim1
SIZB = Word8
51
  tag2word Prim1
FLTB = Word8
52
  tag2word Prim1
MISS = Word8
53
  tag2word Prim1
CACH = Word8
54
  tag2word Prim1
LKUP = Word8
55
  tag2word Prim1
LOAD = Word8
56
  tag2word Prim1
CVLD = Word8
57
  tag2word Prim1
VALU = Word8
58
  tag2word Prim1
TLTT = Word8
59
  tag2word Prim1
DBTX = Word8
60
  tag2word Prim1
SDBL = Word8
61
  tag2word Prim1
REFN = Word8
62
  tag2word Prim1
REFR = Word8
63
  tag2word Prim1
RRFC = Word8
64
  tag2word Prim1
TIKR = Word8
65

  word2tag :: forall (m :: * -> *). MonadGet m => Word8 -> m Prim1
word2tag Word8
0 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
DECI
  word2tag Word8
1 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
DECN
  word2tag Word8
2 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
INCI
  word2tag Word8
3 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
INCN
  word2tag Word8
4 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
NEGI
  word2tag Word8
5 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
SGNI
  word2tag Word8
6 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
LZRO
  word2tag Word8
7 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
TZRO
  word2tag Word8
8 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
COMN
  word2tag Word8
9 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
COMI
  word2tag Word8
10 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
POPC
  word2tag Word8
11 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
ABSF
  word2tag Word8
12 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
EXPF
  word2tag Word8
13 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
LOGF
  word2tag Word8
14 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
SQRT
  word2tag Word8
15 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
COSF
  word2tag Word8
16 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
ACOS
  word2tag Word8
17 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
COSH
  word2tag Word8
18 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
ACSH
  word2tag Word8
19 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
SINF
  word2tag Word8
20 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
ASIN
  word2tag Word8
21 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
SINH
  word2tag Word8
22 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
ASNH
  word2tag Word8
23 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
TANF
  word2tag Word8
24 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
ATAN
  word2tag Word8
25 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
TANH
  word2tag Word8
26 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
ATNH
  word2tag Word8
27 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
ITOF
  word2tag Word8
28 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
NTOF
  word2tag Word8
29 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
CEIL
  word2tag Word8
30 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
FLOR
  word2tag Word8
31 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
TRNF
  word2tag Word8
32 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
RNDF
  word2tag Word8
33 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
TRNC
  word2tag Word8
34 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
NOTB

  word2tag Word8
35 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
SIZT
  word2tag Word8
36 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
USNC
  word2tag Word8
37 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
UCNS
  word2tag Word8
38 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
ITOT
  word2tag Word8
39 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
NTOT
  word2tag Word8
40 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
FTOT
  word2tag Word8
41 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
TTOI
  word2tag Word8
42 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
TTON
  word2tag Word8
43 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
TTOF
  word2tag Word8
44 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
PAKT
  word2tag Word8
45 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
UPKT
  word2tag Word8
46 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
VWLS
  word2tag Word8
47 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
VWRS
  word2tag Word8
48 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
SIZS
  word2tag Word8
49 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
PAKB
  word2tag Word8
50 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
UPKB
  word2tag Word8
51 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
SIZB
  word2tag Word8
52 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
FLTB
  word2tag Word8
53 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
MISS
  word2tag Word8
54 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
CACH
  word2tag Word8
55 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
LKUP
  word2tag Word8
56 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
LOAD
  word2tag Word8
57 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
CVLD
  word2tag Word8
58 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
VALU
  word2tag Word8
59 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
TLTT
  word2tag Word8
60 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
DBTX
  word2tag Word8
61 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
SDBL
  word2tag Word8
62 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
REFN
  word2tag Word8
63 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
REFR
  word2tag Word8
64 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
RRFC
  word2tag Word8
65 = Prim1 -> m Prim1
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim1
TIKR
  word2tag Word8
n = String -> Word8 -> m Prim1
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"Prim1" Word8
n

instance Tag Prim2 where
  tag2word :: Prim2 -> Word8
tag2word Prim2
ADDI = Word8
0
  tag2word Prim2
ADDN = Word8
1
  tag2word Prim2
SUBI = Word8
2
  tag2word Prim2
SUBN = Word8
3
  tag2word Prim2
MULI = Word8
4
  tag2word Prim2
MULN = Word8
5
  tag2word Prim2
DIVI = Word8
6
  tag2word Prim2
MODI = Word8
7
  tag2word Prim2
DIVN = Word8
8
  tag2word Prim2
MODN = Word8
9
  tag2word Prim2
SHLI = Word8
10
  tag2word Prim2
SHLN = Word8
11
  tag2word Prim2
SHRI = Word8
12
  tag2word Prim2
SHRN = Word8
13
  tag2word Prim2
POWI = Word8
14
  tag2word Prim2
POWN = Word8
15
  tag2word Prim2
EQLI = Word8
16
  tag2word Prim2
NEQI = Word8
17
  tag2word Prim2
EQLN = Word8
18
  tag2word Prim2
NEQN = Word8
19
  tag2word Prim2
LEQI = Word8
20
  tag2word Prim2
LEQN = Word8
21
  tag2word Prim2
LESI = Word8
22
  tag2word Prim2
LESN = Word8
23
  tag2word Prim2
ANDN = Word8
24
  tag2word Prim2
ANDI = Word8
25
  tag2word Prim2
IORN = Word8
26
  tag2word Prim2
IORI = Word8
27
  tag2word Prim2
XORN = Word8
28
  tag2word Prim2
XORI = Word8
29
  tag2word Prim2
EQLF = Word8
30
  tag2word Prim2
NEQF = Word8
31
  tag2word Prim2
LEQF = Word8
32
  tag2word Prim2
LESF = Word8
33
  tag2word Prim2
ADDF = Word8
34
  tag2word Prim2
SUBF = Word8
35
  tag2word Prim2
MULF = Word8
36
  tag2word Prim2
DIVF = Word8
37
  tag2word Prim2
ATN2 = Word8
38
  tag2word Prim2
POWF = Word8
39
  tag2word Prim2
LOGB = Word8
40
  tag2word Prim2
MAXF = Word8
41
  tag2word Prim2
MINF = Word8
42
  tag2word Prim2
CAST = Word8
43
  tag2word Prim2
DRPN = Word8
44
  tag2word Prim2
ANDB = Word8
45
  tag2word Prim2
IORB = Word8
46
  tag2word Prim2
EQLU = Word8
47
  tag2word Prim2
LEQU = Word8
48
  tag2word Prim2
LESU = Word8
49
  tag2word Prim2
CMPU = Word8
50
  tag2word Prim2
DRPT = Word8
51
  tag2word Prim2
CATT = Word8
52
  tag2word Prim2
TAKT = Word8
53
  tag2word Prim2
EQLT = Word8
54
  tag2word Prim2
LEQT = Word8
55
  tag2word Prim2
LEST = Word8
56
  tag2word Prim2
DRPS = Word8
57
  tag2word Prim2
CATS = Word8
58
  tag2word Prim2
TAKS = Word8
59
  tag2word Prim2
CONS = Word8
60
  tag2word Prim2
SNOC = Word8
61
  tag2word Prim2
IDXS = Word8
62
  tag2word Prim2
SPLL = Word8
63
  tag2word Prim2
SPLR = Word8
64
  tag2word Prim2
TAKB = Word8
65
  tag2word Prim2
DRPB = Word8
66
  tag2word Prim2
IDXB = Word8
67
  tag2word Prim2
CATB = Word8
68
  tag2word Prim2
THRO = Word8
69
  tag2word Prim2
TRCE = Word8
70
  tag2word Prim2
SDBX = Word8
71
  tag2word Prim2
IXOT = Word8
72
  tag2word Prim2
IXOB = Word8
73
  tag2word Prim2
SDBV = Word8
74
  tag2word Prim2
REFW = Word8
75

  word2tag :: forall (m :: * -> *). MonadGet m => Word8 -> m Prim2
word2tag Word8
0 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
ADDI
  word2tag Word8
1 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
ADDN
  word2tag Word8
2 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SUBI
  word2tag Word8
3 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SUBN
  word2tag Word8
4 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
MULI
  word2tag Word8
5 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
MULN
  word2tag Word8
6 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
DIVI
  word2tag Word8
7 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
MODI
  word2tag Word8
8 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
DIVN
  word2tag Word8
9 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
MODN
  word2tag Word8
10 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SHLI
  word2tag Word8
11 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SHLN
  word2tag Word8
12 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SHRI
  word2tag Word8
13 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SHRN
  word2tag Word8
14 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
POWI
  word2tag Word8
15 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
POWN
  word2tag Word8
16 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
EQLI
  word2tag Word8
17 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
NEQI
  word2tag Word8
18 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
EQLN
  word2tag Word8
19 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
NEQN
  word2tag Word8
20 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
LEQI
  word2tag Word8
21 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
LEQN
  word2tag Word8
22 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
LESI
  word2tag Word8
23 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
LESN
  word2tag Word8
24 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
ANDN
  word2tag Word8
25 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
ANDI
  word2tag Word8
26 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
IORN
  word2tag Word8
27 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
IORI
  word2tag Word8
28 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
XORN
  word2tag Word8
29 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
XORI
  word2tag Word8
30 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
EQLF
  word2tag Word8
31 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
NEQF
  word2tag Word8
32 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
LEQF
  word2tag Word8
33 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
LESF
  word2tag Word8
34 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
ADDF
  word2tag Word8
35 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SUBF
  word2tag Word8
36 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
MULF
  word2tag Word8
37 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
DIVF
  word2tag Word8
38 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
ATN2
  word2tag Word8
39 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
POWF
  word2tag Word8
40 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
LOGB
  word2tag Word8
41 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
MAXF
  word2tag Word8
42 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
MINF
  word2tag Word8
43 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
CAST
  word2tag Word8
44 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
DRPN
  word2tag Word8
45 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
ANDB
  word2tag Word8
46 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
IORB

  word2tag Word8
47 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
EQLU
  word2tag Word8
48 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
LEQU
  word2tag Word8
49 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
LESU
  word2tag Word8
50 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
CMPU
  word2tag Word8
51 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
DRPT
  word2tag Word8
52 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
CATT
  word2tag Word8
53 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
TAKT
  word2tag Word8
54 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
EQLT
  word2tag Word8
55 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
LEQT
  word2tag Word8
56 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
LEST
  word2tag Word8
57 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
DRPS
  word2tag Word8
58 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
CATS
  word2tag Word8
59 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
TAKS
  word2tag Word8
60 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
CONS
  word2tag Word8
61 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SNOC
  word2tag Word8
62 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
IDXS
  word2tag Word8
63 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SPLL
  word2tag Word8
64 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SPLR
  word2tag Word8
65 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
TAKB
  word2tag Word8
66 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
DRPB
  word2tag Word8
67 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
IDXB
  word2tag Word8
68 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
CATB
  word2tag Word8
69 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
THRO
  word2tag Word8
70 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
TRCE
  word2tag Word8
71 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SDBX
  word2tag Word8
72 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
IXOT
  word2tag Word8
73 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
IXOB
  word2tag Word8
74 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
SDBV
  word2tag Word8
75 = Prim2 -> m Prim2
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Prim2
REFW
  word2tag Word8
n = String -> Word8 -> m Prim2
forall (m :: * -> *) a. MonadGet m => String -> Word8 -> m a
unknownTag String
"Prim2" Word8
n