module GHCi.ResolvedBCO
( ResolvedBCO(..)
, ResolvedBCOPtr(..)
) where
import SizedSeq
import GHCi.RemoteTypes
import GHCi.BreakArray
import Control.Monad.ST
import Data.Array.Unboxed
import Data.Array.Base
import Data.Binary
import GHC.Generics
data ResolvedBCO
= ResolvedBCO {
resolvedBCOArity :: !Int,
resolvedBCOInstrs :: UArray Int Word,
resolvedBCOBitmap :: UArray Int Word,
resolvedBCOLits :: UArray Int Word,
resolvedBCOPtrs :: (SizedSeq ResolvedBCOPtr)
}
deriving (Generic, Show)
instance Binary ResolvedBCO where
put ResolvedBCO{..} = do
put resolvedBCOArity
putArray resolvedBCOInstrs
putArray resolvedBCOBitmap
putArray resolvedBCOLits
put resolvedBCOPtrs
get = ResolvedBCO <$> get <*> getArray <*> getArray <*> getArray <*> get
putArray :: UArray Int Word -> Put
putArray a@(UArray _ _ n _) = do
put n
mapM_ put (elems a)
getArray :: Get (UArray Int Word)
getArray = do
n <- get
xs <- gets n []
return $! mkArray n xs
where
gets 0 xs = return xs
gets n xs = do
x <- get
gets (n1) (x:xs)
mkArray :: Int -> [Word] -> UArray Int Word
mkArray n0 xs0 = runST $ do
!marr <- newArray (0,n01) 0
let go 0 _ = return ()
go _ [] = error "mkArray"
go n (x:xs) = do
let n' = n1
unsafeWrite marr n' x
go n' xs
go n0 xs0
unsafeFreezeSTUArray marr
data ResolvedBCOPtr
= ResolvedBCORef !Int
| ResolvedBCOPtr !(RemoteRef HValue)
| ResolvedBCOStaticPtr !(RemotePtr ())
| ResolvedBCOPtrBCO ResolvedBCO
| ResolvedBCOPtrBreakArray !(RemoteRef BreakArray)
deriving (Generic, Show)
instance Binary ResolvedBCOPtr