{-# language BangPatterns #-}
{-# language DataKinds #-}
{-# language MagicHash #-}
{-# language UnboxedTuples #-}

module Basics.Int8
  ( -- Types
    T
  , T#
  , R
    -- Lifting
  , lift
  , unlift
    -- Compare
  , gt#
  , lt#
  , gte#
  , lte#
  , eq#
  , neq#
  , gt
  , lt
  , gte
  , lte
  , eq
  , neq
    -- Array
  , read#
  , write#
  , index#
  , set#
  , uninitialized#
  , initialized#
  , uninitialized
  , initialized
  , copy#
  , copyMutable#
  , shrink#
    -- Constants
  , zero
  , def
    -- Metadata
  , signed
  , size
    -- Encoding
  , shows
  ) where

import Prelude hiding (shows)

import Data.Primitive (MutableByteArray(..))
import GHC.Exts hiding (setByteArray#)
import GHC.Int
import GHC.ST (ST(ST))

import qualified Prelude
import qualified GHC.Exts as Exts

type T = Int8
type T# = Int#
type R = 'IntRep

def :: T
{-# inline def #-}
def :: T
def = T
0

zero :: T
{-# inline zero #-}
zero :: T
zero = T
0

signed :: Bool
{-# inline signed #-}
signed :: Bool
signed = Bool
False

size :: Int
{-# inline size #-}
size :: Int
size = Int
1

lift :: T# -> T
{-# inline lift #-}
lift :: T# -> T
lift T#
i = Int8# -> T
I8# (T# -> Int8#
Exts.intToInt8# T#
i)

unlift :: T -> T#
{-# inline unlift #-}
unlift :: T -> T#
unlift (I8# Int8#
i) = Int8# -> T#
Exts.int8ToInt# Int8#
i

gt# :: T# -> T# -> Int#
{-# inline gt# #-}
gt# :: T# -> T# -> T#
gt# = T# -> T# -> T#
(>#)

lt# :: T# -> T# -> Int#
{-# inline lt# #-}
lt# :: T# -> T# -> T#
lt# = T# -> T# -> T#
(<#)

gte# :: T# -> T# -> Int#
{-# inline gte# #-}
gte# :: T# -> T# -> T#
gte# = T# -> T# -> T#
(>=#)

lte# :: T# -> T# -> Int#
{-# inline lte# #-}
lte# :: T# -> T# -> T#
lte# = T# -> T# -> T#
(<=#)

eq# :: T# -> T# -> Int#
{-# inline eq# #-}
eq# :: T# -> T# -> T#
eq# = T# -> T# -> T#
(==#)

neq# :: T# -> T# -> Int#
{-# inline neq# #-}
neq# :: T# -> T# -> T#
neq# = T# -> T# -> T#
(/=#)

gt :: T -> T -> Bool
{-# inline gt #-}
gt :: T -> T -> Bool
gt = forall a. Ord a => a -> a -> Bool
(>)

lt :: T -> T -> Bool
{-# inline lt #-}
lt :: T -> T -> Bool
lt = forall a. Ord a => a -> a -> Bool
(<)

gte :: T -> T -> Bool
{-# inline gte #-}
gte :: T -> T -> Bool
gte = forall a. Ord a => a -> a -> Bool
(>=)

lte :: T -> T -> Bool
{-# inline lte #-}
lte :: T -> T -> Bool
lte = forall a. Ord a => a -> a -> Bool
(<=)

eq :: T -> T -> Bool
{-# inline eq #-}
eq :: T -> T -> Bool
eq = forall a. Eq a => a -> a -> Bool
(==)

neq :: T -> T -> Bool
{-# inline neq #-}
neq :: T -> T -> Bool
neq = forall a. Eq a => a -> a -> Bool
(/=)

index# :: ByteArray# -> Int# -> T#
{-# inline index# #-}
index# :: ByteArray# -> T# -> T#
index# ByteArray#
arr T#
i = Int8# -> T#
Exts.int8ToInt# (ByteArray# -> T# -> Int8#
indexInt8Array# ByteArray#
arr T#
i)

read# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, T# #)
{-# inline read# #-}
read# :: forall s.
MutableByteArray# s -> T# -> State# s -> (# State# s, T# #)
read# MutableByteArray# s
arr T#
i State# s
st =
  let !(# State# s
st', Int8#
v #) = forall d.
MutableByteArray# d -> T# -> State# d -> (# State# d, Int8# #)
readInt8Array# MutableByteArray# s
arr T#
i State# s
st
   in (# State# s
st', Int8# -> T#
Exts.int8ToInt# Int8#
v #)

write# :: MutableByteArray# s -> Int# -> T# -> State# s -> State# s
{-# inline write# #-}
write# :: forall s. MutableByteArray# s -> T# -> T# -> State# s -> State# s
write# MutableByteArray# s
arr T#
i T#
v State# s
st = forall d.
MutableByteArray# d -> T# -> Int8# -> State# d -> State# d
writeInt8Array# MutableByteArray# s
arr T#
i (T# -> Int8#
Exts.intToInt8# T#
v) State# s
st

set# :: MutableByteArray# s -> Int# -> Int# -> T# -> State# s -> State# s
{-# inline set# #-}
set# :: forall s.
MutableByteArray# s -> T# -> T# -> T# -> State# s -> State# s
set# MutableByteArray# s
marr T#
off T#
len T#
x State# s
s = forall s.
MutableByteArray# s -> T# -> T# -> T# -> State# s -> State# s
Exts.setByteArray# MutableByteArray# s
marr T#
off T#
len T#
x State# s
s

shrink# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, MutableByteArray# s #)
{-# inline shrink# #-}
shrink# :: forall s.
MutableByteArray# s
-> T# -> State# s -> (# State# s, MutableByteArray# s #)
shrink# MutableByteArray# s
m T#
i State# s
s = (# forall d. MutableByteArray# d -> T# -> State# d -> State# d
Exts.shrinkMutableByteArray# MutableByteArray# s
m T#
i State# s
s, MutableByteArray# s
m #)

uninitialized# :: Int# -> State# s -> (# State# s, MutableByteArray# s #)
{-# inline uninitialized# #-}
uninitialized# :: forall s. T# -> State# s -> (# State# s, MutableByteArray# s #)
uninitialized# = forall s. T# -> State# s -> (# State# s, MutableByteArray# s #)
Exts.newByteArray#

uninitialized :: Int -> ST s (MutableByteArray s)
{-# inline uninitialized #-}
uninitialized :: forall s. Int -> ST s (MutableByteArray s)
uninitialized (I# T#
sz) = forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s0 -> case forall s. T# -> State# s -> (# State# s, MutableByteArray# s #)
uninitialized# T#
sz State# s
s0 of
  (# State# s
s1, MutableByteArray# s
a #) -> (# State# s
s1, forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray MutableByteArray# s
a #)

initialized :: Int -> T -> ST s (MutableByteArray s)
{-# inline initialized #-}
initialized :: forall s. Int -> T -> ST s (MutableByteArray s)
initialized (I# T#
sz) T
e = forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s0 -> case forall s.
T# -> T# -> State# s -> (# State# s, MutableByteArray# s #)
initialized# T#
sz (T -> T#
unlift T
e) State# s
s0 of
  (# State# s
s1, MutableByteArray# s
a #) -> (# State# s
s1, forall s. MutableByteArray# s -> MutableByteArray s
MutableByteArray MutableByteArray# s
a #)

copy# :: MutableByteArray# s -> Int# -> ByteArray# -> Int# -> Int# -> State# s -> State# s
{-# inline copy# #-}
copy# :: forall s.
MutableByteArray# s
-> T# -> ByteArray# -> T# -> T# -> State# s -> State# s
copy# MutableByteArray# s
dst T#
doff ByteArray#
src T#
soff T#
len =
  forall d.
ByteArray#
-> T# -> MutableByteArray# d -> T# -> T# -> State# d -> State# d
Exts.copyByteArray# ByteArray#
src T#
soff MutableByteArray# s
dst T#
doff T#
len

copyMutable# :: MutableByteArray# s -> Int# -> MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
{-# inline copyMutable# #-}
copyMutable# :: forall s.
MutableByteArray# s
-> T# -> MutableByteArray# s -> T# -> T# -> State# s -> State# s
copyMutable# MutableByteArray# s
dst T#
doff MutableByteArray# s
src T#
soff T#
len =
  forall s.
MutableByteArray# s
-> T# -> MutableByteArray# s -> T# -> T# -> State# s -> State# s
Exts.copyMutableByteArray# MutableByteArray# s
src T#
soff MutableByteArray# s
dst T#
doff T#
len

initialized# :: Int# -> T# -> State# s -> (# State# s, MutableByteArray# s #)
{-# inline initialized# #-}
initialized# :: forall s.
T# -> T# -> State# s -> (# State# s, MutableByteArray# s #)
initialized# T#
n T#
e State# s
s0 = case forall s. T# -> State# s -> (# State# s, MutableByteArray# s #)
Exts.newByteArray# T#
n State# s
s0 of
  (# State# s
s1, MutableByteArray# s
a #) -> case forall s.
MutableByteArray# s -> T# -> T# -> T# -> State# s -> State# s
set# MutableByteArray# s
a T#
0# T#
n T#
e State# s
s1 of
    State# s
s2 -> (# State# s
s2, MutableByteArray# s
a #)

shows :: T -> String -> String
shows :: T -> String -> String
shows = forall a. Show a => a -> String -> String
Prelude.shows