{-# LANGUAGE GADTs, DeriveGeneric, StandaloneDeriving, ScopedTypeVariables,
    GeneralizedNewtypeDeriving, ExistentialQuantification, RecordWildCards,
    CPP #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-orphans #-}

-- |
-- Remote GHCi message types and serialization.
--
-- For details on Remote GHCi, see Note [Remote GHCi] in
-- compiler/GHC/Runtime/Interpreter.hs.
--
module GHCi.Message
  ( Message(..), Msg(..)
  , THMessage(..), THMsg(..)
  , QResult(..)
  , EvalStatus_(..), EvalStatus, EvalResult(..), EvalOpts(..), EvalExpr(..)
  , SerializableException(..)
  , toSerializableException, fromSerializableException
  , THResult(..), THResultType(..)
  , ResumeContext(..)
  , QState(..)
  , getMessage, putMessage, getTHMessage, putTHMessage
  , Pipe(..), remoteCall, remoteTHCall, readPipe, writePipe
  , LoadedDLL
  ) where

import Prelude -- See note [Why do we import Prelude here?]
import GHCi.RemoteTypes
import GHCi.FFI
import GHCi.TH.Binary () -- For Binary instances
import GHCi.BreakArray

import GHC.LanguageExtensions
import qualified GHC.Exts.Heap as Heap
import GHC.ForeignSrcLang
import GHC.Fingerprint
import Control.Concurrent
import Control.Exception
import Data.Binary
import Data.Binary.Get
import Data.Binary.Put
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as LB
import Data.Dynamic
import Data.Typeable (TypeRep)
import Data.IORef
import Data.Map (Map)
import Foreign
import GHC.Generics
import GHC.Stack.CCS
import qualified Language.Haskell.TH        as TH
import qualified Language.Haskell.TH.Syntax as TH
import System.Exit
import System.IO
import System.IO.Error

-- -----------------------------------------------------------------------------
-- The RPC protocol between GHC and the interactive server

-- | A @Message a@ is a message that returns a value of type @a@.
-- These are requests sent from GHC to the server.
data Message a where
  -- | Exit the iserv process
  Shutdown :: Message ()
  RtsRevertCAFs :: Message ()

  -- RTS Linker -------------------------------------------

  -- These all invoke the corresponding functions in the RTS Linker API.
  InitLinker :: Message ()
  LookupSymbol :: String -> Message (Maybe (RemotePtr ()))
  LookupSymbolInDLL :: RemotePtr LoadedDLL -> String -> Message (Maybe (RemotePtr ()))
  LookupClosure :: String -> Message (Maybe HValueRef)
  LoadDLL :: String -> Message (Either String (RemotePtr LoadedDLL))
  LoadArchive :: String -> Message () -- error?
  LoadObj :: String -> Message () -- error?
  UnloadObj :: String -> Message () -- error?
  AddLibrarySearchPath :: String -> Message (RemotePtr ())
  RemoveLibrarySearchPath :: RemotePtr () -> Message Bool
  ResolveObjs :: Message Bool
  FindSystemLibrary :: String -> Message (Maybe String)

  -- Interpreter -------------------------------------------

  -- | Create a set of BCO objects, and return HValueRefs to them
  -- Note: Each ByteString contains a Binary-encoded [ResolvedBCO], not
  -- a ResolvedBCO. The list is to allow us to serialise the ResolvedBCOs
  -- in parallel. See @createBCOs@ in compiler/GHC/Runtime/Interpreter.hs.
  CreateBCOs :: [LB.ByteString] -> Message [HValueRef]

  -- | Release 'HValueRef's
  FreeHValueRefs :: [HValueRef] -> Message ()

  -- | Add entries to the Static Pointer Table
  AddSptEntry :: Fingerprint -> HValueRef -> Message ()

  -- | Malloc some data and return a 'RemotePtr' to it
  MallocData :: ByteString -> Message (RemotePtr ())
  MallocStrings :: [ByteString] -> Message [RemotePtr ()]

  -- | Calls 'GHCi.FFI.prepareForeignCall'
  PrepFFI :: FFIConv -> [FFIType] -> FFIType -> Message (RemotePtr C_ffi_cif)

  -- | Free data previously created by 'PrepFFI'
  FreeFFI :: RemotePtr C_ffi_cif -> Message ()

  -- | Create an info table for a constructor
  MkConInfoTable
   :: Bool    -- TABLES_NEXT_TO_CODE
   -> Int     -- ptr words
   -> Int     -- non-ptr words
   -> Int     -- constr tag
   -> Int     -- pointer tag
   -> ByteString -- constructor desccription
   -> Message (RemotePtr Heap.StgInfoTable)

  -- | Evaluate a statement
  EvalStmt
    :: EvalOpts
    -> EvalExpr HValueRef {- IO [a] -}
    -> Message (EvalStatus [HValueRef]) {- [a] -}

  -- | Resume evaluation of a statement after a breakpoint
  ResumeStmt
   :: EvalOpts
   -> RemoteRef (ResumeContext [HValueRef])
   -> Message (EvalStatus [HValueRef])

  -- | Abandon evaluation of a statement after a breakpoint
  AbandonStmt
   :: RemoteRef (ResumeContext [HValueRef])
   -> Message ()

  -- | Evaluate something of type @IO String@
  EvalString
    :: HValueRef {- IO String -}
    -> Message (EvalResult String)

  -- | Evaluate something of type @String -> IO String@
  EvalStringToString
    :: HValueRef {- String -> IO String -}
    -> String
    -> Message (EvalResult String)

  -- | Evaluate something of type @IO ()@
  EvalIO
   :: HValueRef {- IO a -}
   -> Message (EvalResult ())

  -- | Create a set of CostCentres with the same module name
  MkCostCentres
   :: String     -- module, RemotePtr so it can be shared
   -> [(String,String)] -- (name, SrcSpan)
   -> Message [RemotePtr CostCentre]

  -- | Show a 'CostCentreStack' as a @[String]@
  CostCentreStackInfo
   :: RemotePtr CostCentreStack
   -> Message [String]

  -- | Create a new array of breakpoint flags
  NewBreakArray
   :: Int                               -- size
   -> Message (RemoteRef BreakArray)

  -- | Set how many times a breakpoint should be ignored
  --   also used for enable/disable
  SetupBreakpoint
   :: RemoteRef BreakArray
   -> Int                           -- breakpoint index
   -> Int                           -- ignore count to be stored in the BreakArray
                                    -- -1 disable; 0 enable; >= 1 enable, ignore count.
   -> Message ()

  -- | Query the status of a breakpoint (True <=> enabled)
  BreakpointStatus
   :: RemoteRef BreakArray
   -> Int                               -- index
   -> Message Bool                      -- True <=> enabled

  -- | Get a reference to a free variable at a breakpoint
  GetBreakpointVar
   :: HValueRef                         -- the AP_STACK from EvalBreak
   -> Int
   -> Message (Maybe HValueRef)

  -- Template Haskell -------------------------------------------
  -- For more details on how TH works with Remote GHCi, see
  -- Note [Remote Template Haskell] in libraries/ghci/GHCi/TH.hs.

  -- | Start a new TH module, return a state token that should be
  StartTH :: Message (RemoteRef (IORef QState))

  -- | Evaluate a TH computation.
  --
  -- Returns a ByteString, because we have to force the result
  -- before returning it to ensure there are no errors lurking
  -- in it.  The TH types don't have NFData instances, and even if
  -- they did, we have to serialize the value anyway, so we might
  -- as well serialize it to force it.
  RunTH
   :: RemoteRef (IORef QState)
   -> HValueRef {- e.g. TH.Q TH.Exp -}
   -> THResultType
   -> Maybe TH.Loc
   -> Message (QResult ByteString)

  -- | Run the given mod finalizers.
  RunModFinalizers :: RemoteRef (IORef QState)
                   -> [RemoteRef (TH.Q ())]
                   -> Message (QResult ())

  -- | Remote interface to GHC.Exts.Heap.getClosureData. This is used by
  -- the GHCi debugger to inspect values in the heap for :print and
  -- type reconstruction.
  GetClosure
    :: HValueRef
    -> Message (Heap.GenClosure HValueRef)

  -- | Evaluate something. This is used to support :force in GHCi.
  Seq
    :: HValueRef
    -> Message (EvalStatus ())

  -- | Resume forcing a free variable in a breakpoint (#2950)
  ResumeSeq
    :: RemoteRef (ResumeContext ())
    -> Message (EvalStatus ())

deriving instance Show (Message a)


-- | Template Haskell return values
data QResult a
  = QDone a
    -- ^ RunTH finished successfully; return value follows
  | QException String
    -- ^ RunTH threw an exception
  | QFail String
    -- ^ RunTH called 'fail'
  deriving ((forall x. QResult a -> Rep (QResult a) x)
-> (forall x. Rep (QResult a) x -> QResult a)
-> Generic (QResult a)
forall x. Rep (QResult a) x -> QResult a
forall x. QResult a -> Rep (QResult a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (QResult a) x -> QResult a
forall a x. QResult a -> Rep (QResult a) x
$cfrom :: forall a x. QResult a -> Rep (QResult a) x
from :: forall x. QResult a -> Rep (QResult a) x
$cto :: forall a x. Rep (QResult a) x -> QResult a
to :: forall x. Rep (QResult a) x -> QResult a
Generic, Int -> QResult a -> ShowS
[QResult a] -> ShowS
QResult a -> String
(Int -> QResult a -> ShowS)
-> (QResult a -> String)
-> ([QResult a] -> ShowS)
-> Show (QResult a)
forall a. Show a => Int -> QResult a -> ShowS
forall a. Show a => [QResult a] -> ShowS
forall a. Show a => QResult a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> QResult a -> ShowS
showsPrec :: Int -> QResult a -> ShowS
$cshow :: forall a. Show a => QResult a -> String
show :: QResult a -> String
$cshowList :: forall a. Show a => [QResult a] -> ShowS
showList :: [QResult a] -> ShowS
Show)

instance Binary a => Binary (QResult a)


-- | Messages sent back to GHC from GHCi.TH, to implement the methods
-- of 'Quasi'.  For an overview of how TH works with Remote GHCi, see
-- Note [Remote Template Haskell] in GHCi.TH.
data THMessage a where
  NewName :: String -> THMessage (THResult TH.Name)
  Report :: Bool -> String -> THMessage (THResult ())
  LookupName :: Bool -> String -> THMessage (THResult (Maybe TH.Name))
  Reify :: TH.Name -> THMessage (THResult TH.Info)
  ReifyFixity :: TH.Name -> THMessage (THResult (Maybe TH.Fixity))
  ReifyType :: TH.Name -> THMessage (THResult TH.Type)
  ReifyInstances :: TH.Name -> [TH.Type] -> THMessage (THResult [TH.Dec])
  ReifyRoles :: TH.Name -> THMessage (THResult [TH.Role])
  ReifyAnnotations :: TH.AnnLookup -> TypeRep
    -> THMessage (THResult [ByteString])
  ReifyModule :: TH.Module -> THMessage (THResult TH.ModuleInfo)
  ReifyConStrictness :: TH.Name -> THMessage (THResult [TH.DecidedStrictness])

  GetPackageRoot :: THMessage (THResult FilePath)
  AddDependentFile :: FilePath -> THMessage (THResult ())
  AddTempFile :: String -> THMessage (THResult FilePath)
  AddModFinalizer :: RemoteRef (TH.Q ()) -> THMessage (THResult ())
  AddCorePlugin :: String -> THMessage (THResult ())
  AddTopDecls :: [TH.Dec] -> THMessage (THResult ())
  AddForeignFilePath :: ForeignSrcLang -> FilePath -> THMessage (THResult ())
  IsExtEnabled :: Extension -> THMessage (THResult Bool)
  ExtsEnabled :: THMessage (THResult [Extension])
  PutDoc :: TH.DocLoc -> String -> THMessage (THResult ())
  GetDoc :: TH.DocLoc -> THMessage (THResult (Maybe String))

  StartRecover :: THMessage ()
  EndRecover :: Bool -> THMessage ()
  FailIfErrs :: THMessage (THResult ())

  -- | Indicates that this RunTH is finished, and the next message
  -- will be the result of RunTH (a QResult).
  RunTHDone :: THMessage ()

deriving instance Show (THMessage a)

data THMsg = forall a . (Binary a, Show a) => THMsg (THMessage a)

getTHMessage :: Get THMsg
getTHMessage :: Get THMsg
getTHMessage = do
  Word8
b <- Get Word8
getWord8
  case Word8
b of
    Word8
0  -> THMessage (THResult Name) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult Name) -> THMsg)
-> (String -> THMessage (THResult Name)) -> String -> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> THMessage (THResult Name)
NewName (String -> THMsg) -> Get String -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
    Word8
1  -> THMessage (THResult ()) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult ()) -> THMsg)
-> Get (THMessage (THResult ())) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Bool -> String -> THMessage (THResult ())
Report (Bool -> String -> THMessage (THResult ()))
-> Get Bool -> Get (String -> THMessage (THResult ()))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Bool
forall t. Binary t => Get t
get Get (String -> THMessage (THResult ()))
-> Get String -> Get (THMessage (THResult ()))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get String
forall t. Binary t => Get t
get)
    Word8
2  -> THMessage (THResult (Maybe Name)) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult (Maybe Name)) -> THMsg)
-> Get (THMessage (THResult (Maybe Name))) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Bool -> String -> THMessage (THResult (Maybe Name))
LookupName (Bool -> String -> THMessage (THResult (Maybe Name)))
-> Get Bool -> Get (String -> THMessage (THResult (Maybe Name)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Bool
forall t. Binary t => Get t
get Get (String -> THMessage (THResult (Maybe Name)))
-> Get String -> Get (THMessage (THResult (Maybe Name)))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get String
forall t. Binary t => Get t
get)
    Word8
3  -> THMessage (THResult Info) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult Info) -> THMsg)
-> (Name -> THMessage (THResult Info)) -> Name -> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> THMessage (THResult Info)
Reify (Name -> THMsg) -> Get Name -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Name
forall t. Binary t => Get t
get
    Word8
4  -> THMessage (THResult (Maybe Fixity)) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult (Maybe Fixity)) -> THMsg)
-> (Name -> THMessage (THResult (Maybe Fixity))) -> Name -> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> THMessage (THResult (Maybe Fixity))
ReifyFixity (Name -> THMsg) -> Get Name -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Name
forall t. Binary t => Get t
get
    Word8
5  -> THMessage (THResult [Dec]) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult [Dec]) -> THMsg)
-> Get (THMessage (THResult [Dec])) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Name -> [Type] -> THMessage (THResult [Dec])
ReifyInstances (Name -> [Type] -> THMessage (THResult [Dec]))
-> Get Name -> Get ([Type] -> THMessage (THResult [Dec]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Name
forall t. Binary t => Get t
get Get ([Type] -> THMessage (THResult [Dec]))
-> Get [Type] -> Get (THMessage (THResult [Dec]))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get [Type]
forall t. Binary t => Get t
get)
    Word8
6  -> THMessage (THResult [Role]) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult [Role]) -> THMsg)
-> (Name -> THMessage (THResult [Role])) -> Name -> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> THMessage (THResult [Role])
ReifyRoles (Name -> THMsg) -> Get Name -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Name
forall t. Binary t => Get t
get
    Word8
7  -> THMessage (THResult [ByteString]) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult [ByteString]) -> THMsg)
-> Get (THMessage (THResult [ByteString])) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (AnnLookup -> TypeRep -> THMessage (THResult [ByteString])
ReifyAnnotations (AnnLookup -> TypeRep -> THMessage (THResult [ByteString]))
-> Get AnnLookup
-> Get (TypeRep -> THMessage (THResult [ByteString]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get AnnLookup
forall t. Binary t => Get t
get Get (TypeRep -> THMessage (THResult [ByteString]))
-> Get TypeRep -> Get (THMessage (THResult [ByteString]))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get TypeRep
forall t. Binary t => Get t
get)
    Word8
8  -> THMessage (THResult ModuleInfo) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult ModuleInfo) -> THMsg)
-> (Module -> THMessage (THResult ModuleInfo)) -> Module -> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Module -> THMessage (THResult ModuleInfo)
ReifyModule (Module -> THMsg) -> Get Module -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Module
forall t. Binary t => Get t
get
    Word8
9  -> THMessage (THResult [DecidedStrictness]) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult [DecidedStrictness]) -> THMsg)
-> (Name -> THMessage (THResult [DecidedStrictness]))
-> Name
-> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> THMessage (THResult [DecidedStrictness])
ReifyConStrictness (Name -> THMsg) -> Get Name -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Name
forall t. Binary t => Get t
get
    Word8
10 -> THMessage (THResult ()) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult ()) -> THMsg)
-> (String -> THMessage (THResult ())) -> String -> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> THMessage (THResult ())
AddDependentFile (String -> THMsg) -> Get String -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
    Word8
11 -> THMessage (THResult String) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult String) -> THMsg)
-> (String -> THMessage (THResult String)) -> String -> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> THMessage (THResult String)
AddTempFile (String -> THMsg) -> Get String -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
    Word8
12 -> THMessage (THResult ()) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult ()) -> THMsg)
-> ([Dec] -> THMessage (THResult ())) -> [Dec] -> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Dec] -> THMessage (THResult ())
AddTopDecls ([Dec] -> THMsg) -> Get [Dec] -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get [Dec]
forall t. Binary t => Get t
get
    Word8
13 -> THMessage (THResult Bool) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult Bool) -> THMsg)
-> Get (THMessage (THResult Bool)) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Extension -> THMessage (THResult Bool)
IsExtEnabled (Extension -> THMessage (THResult Bool))
-> Get Extension -> Get (THMessage (THResult Bool))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Extension
forall t. Binary t => Get t
get)
    Word8
14 -> THMessage (THResult [Extension]) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult [Extension]) -> THMsg)
-> Get (THMessage (THResult [Extension])) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> THMessage (THResult [Extension])
-> Get (THMessage (THResult [Extension]))
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return THMessage (THResult [Extension])
ExtsEnabled
    Word8
15 -> THMessage () -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage () -> THMsg) -> Get (THMessage ()) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> THMessage () -> Get (THMessage ())
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return THMessage ()
StartRecover
    Word8
16 -> THMessage () -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage () -> THMsg) -> (Bool -> THMessage ()) -> Bool -> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> THMessage ()
EndRecover (Bool -> THMsg) -> Get Bool -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Bool
forall t. Binary t => Get t
get
    Word8
17 -> THMessage (THResult ()) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult ()) -> THMsg)
-> Get (THMessage (THResult ())) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> THMessage (THResult ()) -> Get (THMessage (THResult ()))
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return THMessage (THResult ())
FailIfErrs
    Word8
18 -> THMsg -> Get THMsg
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (THMessage () -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg THMessage ()
RunTHDone)
    Word8
19 -> THMessage (THResult ()) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult ()) -> THMsg)
-> (RemoteRef (Q ()) -> THMessage (THResult ()))
-> RemoteRef (Q ())
-> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RemoteRef (Q ()) -> THMessage (THResult ())
AddModFinalizer (RemoteRef (Q ()) -> THMsg) -> Get (RemoteRef (Q ())) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RemoteRef (Q ()))
forall t. Binary t => Get t
get
    Word8
20 -> THMessage (THResult ()) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult ()) -> THMsg)
-> Get (THMessage (THResult ())) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ForeignSrcLang -> String -> THMessage (THResult ())
AddForeignFilePath (ForeignSrcLang -> String -> THMessage (THResult ()))
-> Get ForeignSrcLang -> Get (String -> THMessage (THResult ()))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get ForeignSrcLang
forall t. Binary t => Get t
get Get (String -> THMessage (THResult ()))
-> Get String -> Get (THMessage (THResult ()))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get String
forall t. Binary t => Get t
get)
    Word8
21 -> THMessage (THResult ()) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult ()) -> THMsg)
-> (String -> THMessage (THResult ())) -> String -> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> THMessage (THResult ())
AddCorePlugin (String -> THMsg) -> Get String -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
    Word8
22 -> THMessage (THResult Type) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult Type) -> THMsg)
-> (Name -> THMessage (THResult Type)) -> Name -> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> THMessage (THResult Type)
ReifyType (Name -> THMsg) -> Get Name -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Name
forall t. Binary t => Get t
get
    Word8
23 -> THMessage (THResult ()) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult ()) -> THMsg)
-> Get (THMessage (THResult ())) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (DocLoc -> String -> THMessage (THResult ())
PutDoc (DocLoc -> String -> THMessage (THResult ()))
-> Get DocLoc -> Get (String -> THMessage (THResult ()))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get DocLoc
forall t. Binary t => Get t
get Get (String -> THMessage (THResult ()))
-> Get String -> Get (THMessage (THResult ()))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get String
forall t. Binary t => Get t
get)
    Word8
24 -> THMessage (THResult (Maybe String)) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult (Maybe String)) -> THMsg)
-> (DocLoc -> THMessage (THResult (Maybe String)))
-> DocLoc
-> THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DocLoc -> THMessage (THResult (Maybe String))
GetDoc (DocLoc -> THMsg) -> Get DocLoc -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get DocLoc
forall t. Binary t => Get t
get
    Word8
25 -> THMessage (THResult String) -> THMsg
forall a. (Binary a, Show a) => THMessage a -> THMsg
THMsg (THMessage (THResult String) -> THMsg)
-> Get (THMessage (THResult String)) -> Get THMsg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> THMessage (THResult String) -> Get (THMessage (THResult String))
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return THMessage (THResult String)
GetPackageRoot
    Word8
n -> String -> Get THMsg
forall a. HasCallStack => String -> a
error (String
"getTHMessage: unknown message " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
n)

putTHMessage :: THMessage a -> Put
putTHMessage :: forall a. THMessage a -> Put
putTHMessage THMessage a
m = case THMessage a
m of
  NewName String
a                   -> Word8 -> Put
putWord8 Word8
0  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
a
  Report Bool
a String
b                  -> Word8 -> Put
putWord8 Word8
1  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Put
forall t. Binary t => t -> Put
put Bool
a Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
b
  LookupName Bool
a String
b              -> Word8 -> Put
putWord8 Word8
2  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Put
forall t. Binary t => t -> Put
put Bool
a Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
b
  Reify Name
a                     -> Word8 -> Put
putWord8 Word8
3  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Name -> Put
forall t. Binary t => t -> Put
put Name
a
  ReifyFixity Name
a               -> Word8 -> Put
putWord8 Word8
4  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Name -> Put
forall t. Binary t => t -> Put
put Name
a
  ReifyInstances Name
a [Type]
b          -> Word8 -> Put
putWord8 Word8
5  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Name -> Put
forall t. Binary t => t -> Put
put Name
a Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Type] -> Put
forall t. Binary t => t -> Put
put [Type]
b
  ReifyRoles Name
a                -> Word8 -> Put
putWord8 Word8
6  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Name -> Put
forall t. Binary t => t -> Put
put Name
a
  ReifyAnnotations AnnLookup
a TypeRep
b        -> Word8 -> Put
putWord8 Word8
7  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> AnnLookup -> Put
forall t. Binary t => t -> Put
put AnnLookup
a Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TypeRep -> Put
forall t. Binary t => t -> Put
put TypeRep
b
  ReifyModule Module
a               -> Word8 -> Put
putWord8 Word8
8  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Module -> Put
forall t. Binary t => t -> Put
put Module
a
  ReifyConStrictness Name
a        -> Word8 -> Put
putWord8 Word8
9  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Name -> Put
forall t. Binary t => t -> Put
put Name
a
  AddDependentFile String
a          -> Word8 -> Put
putWord8 Word8
10 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
a
  AddTempFile String
a               -> Word8 -> Put
putWord8 Word8
11 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
a
  AddTopDecls [Dec]
a               -> Word8 -> Put
putWord8 Word8
12 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Dec] -> Put
forall t. Binary t => t -> Put
put [Dec]
a
  IsExtEnabled Extension
a              -> Word8 -> Put
putWord8 Word8
13 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Extension -> Put
forall t. Binary t => t -> Put
put Extension
a
  THMessage a
ExtsEnabled                 -> Word8 -> Put
putWord8 Word8
14
  THMessage a
StartRecover                -> Word8 -> Put
putWord8 Word8
15
  EndRecover Bool
a                -> Word8 -> Put
putWord8 Word8
16 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Put
forall t. Binary t => t -> Put
put Bool
a
  THMessage a
FailIfErrs                  -> Word8 -> Put
putWord8 Word8
17
  THMessage a
RunTHDone                   -> Word8 -> Put
putWord8 Word8
18
  AddModFinalizer RemoteRef (Q ())
a           -> Word8 -> Put
putWord8 Word8
19 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemoteRef (Q ()) -> Put
forall t. Binary t => t -> Put
put RemoteRef (Q ())
a
  AddForeignFilePath ForeignSrcLang
lang String
a   -> Word8 -> Put
putWord8 Word8
20 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ForeignSrcLang -> Put
forall t. Binary t => t -> Put
put ForeignSrcLang
lang Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
a
  AddCorePlugin String
a             -> Word8 -> Put
putWord8 Word8
21 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
a
  ReifyType Name
a                 -> Word8 -> Put
putWord8 Word8
22 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Name -> Put
forall t. Binary t => t -> Put
put Name
a
  PutDoc DocLoc
l String
s                  -> Word8 -> Put
putWord8 Word8
23 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> DocLoc -> Put
forall t. Binary t => t -> Put
put DocLoc
l Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
s
  GetDoc DocLoc
l                    -> Word8 -> Put
putWord8 Word8
24 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> DocLoc -> Put
forall t. Binary t => t -> Put
put DocLoc
l
  THMessage a
GetPackageRoot              -> Word8 -> Put
putWord8 Word8
25


data EvalOpts = EvalOpts
  { EvalOpts -> Bool
useSandboxThread :: Bool
  , EvalOpts -> Bool
singleStep :: Bool
  , EvalOpts -> Bool
breakOnException :: Bool
  , EvalOpts -> Bool
breakOnError :: Bool
  }
  deriving ((forall x. EvalOpts -> Rep EvalOpts x)
-> (forall x. Rep EvalOpts x -> EvalOpts) -> Generic EvalOpts
forall x. Rep EvalOpts x -> EvalOpts
forall x. EvalOpts -> Rep EvalOpts x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. EvalOpts -> Rep EvalOpts x
from :: forall x. EvalOpts -> Rep EvalOpts x
$cto :: forall x. Rep EvalOpts x -> EvalOpts
to :: forall x. Rep EvalOpts x -> EvalOpts
Generic, Int -> EvalOpts -> ShowS
[EvalOpts] -> ShowS
EvalOpts -> String
(Int -> EvalOpts -> ShowS)
-> (EvalOpts -> String) -> ([EvalOpts] -> ShowS) -> Show EvalOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EvalOpts -> ShowS
showsPrec :: Int -> EvalOpts -> ShowS
$cshow :: EvalOpts -> String
show :: EvalOpts -> String
$cshowList :: [EvalOpts] -> ShowS
showList :: [EvalOpts] -> ShowS
Show)

instance Binary EvalOpts

data ResumeContext a = ResumeContext
  { forall a. ResumeContext a -> MVar ()
resumeBreakMVar :: MVar ()
  , forall a. ResumeContext a -> MVar (EvalStatus a)
resumeStatusMVar :: MVar (EvalStatus a)
  , forall a. ResumeContext a -> ThreadId
resumeThreadId :: ThreadId
  }

-- | We can pass simple expressions to EvalStmt, consisting of values
-- and application.  This allows us to wrap the statement to be
-- executed in another function, which is used by GHCi to implement
-- :set args and :set prog.  It might be worthwhile to extend this
-- little language in the future.
data EvalExpr a
  = EvalThis a
  | EvalApp (EvalExpr a) (EvalExpr a)
  deriving ((forall x. EvalExpr a -> Rep (EvalExpr a) x)
-> (forall x. Rep (EvalExpr a) x -> EvalExpr a)
-> Generic (EvalExpr a)
forall x. Rep (EvalExpr a) x -> EvalExpr a
forall x. EvalExpr a -> Rep (EvalExpr a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (EvalExpr a) x -> EvalExpr a
forall a x. EvalExpr a -> Rep (EvalExpr a) x
$cfrom :: forall a x. EvalExpr a -> Rep (EvalExpr a) x
from :: forall x. EvalExpr a -> Rep (EvalExpr a) x
$cto :: forall a x. Rep (EvalExpr a) x -> EvalExpr a
to :: forall x. Rep (EvalExpr a) x -> EvalExpr a
Generic, Int -> EvalExpr a -> ShowS
[EvalExpr a] -> ShowS
EvalExpr a -> String
(Int -> EvalExpr a -> ShowS)
-> (EvalExpr a -> String)
-> ([EvalExpr a] -> ShowS)
-> Show (EvalExpr a)
forall a. Show a => Int -> EvalExpr a -> ShowS
forall a. Show a => [EvalExpr a] -> ShowS
forall a. Show a => EvalExpr a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> EvalExpr a -> ShowS
showsPrec :: Int -> EvalExpr a -> ShowS
$cshow :: forall a. Show a => EvalExpr a -> String
show :: EvalExpr a -> String
$cshowList :: forall a. Show a => [EvalExpr a] -> ShowS
showList :: [EvalExpr a] -> ShowS
Show)

instance Binary a => Binary (EvalExpr a)

type EvalStatus a = EvalStatus_ a a

data EvalStatus_ a b
  = EvalComplete Word64 (EvalResult a)
  | EvalBreak Bool
       HValueRef{- AP_STACK -}
       Int {- break index -}
       Int {- uniq of ModuleName -}
       (RemoteRef (ResumeContext b))
       (RemotePtr CostCentreStack) -- Cost centre stack
  deriving ((forall x. EvalStatus_ a b -> Rep (EvalStatus_ a b) x)
-> (forall x. Rep (EvalStatus_ a b) x -> EvalStatus_ a b)
-> Generic (EvalStatus_ a b)
forall x. Rep (EvalStatus_ a b) x -> EvalStatus_ a b
forall x. EvalStatus_ a b -> Rep (EvalStatus_ a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (EvalStatus_ a b) x -> EvalStatus_ a b
forall a b x. EvalStatus_ a b -> Rep (EvalStatus_ a b) x
$cfrom :: forall a b x. EvalStatus_ a b -> Rep (EvalStatus_ a b) x
from :: forall x. EvalStatus_ a b -> Rep (EvalStatus_ a b) x
$cto :: forall a b x. Rep (EvalStatus_ a b) x -> EvalStatus_ a b
to :: forall x. Rep (EvalStatus_ a b) x -> EvalStatus_ a b
Generic, Int -> EvalStatus_ a b -> ShowS
[EvalStatus_ a b] -> ShowS
EvalStatus_ a b -> String
(Int -> EvalStatus_ a b -> ShowS)
-> (EvalStatus_ a b -> String)
-> ([EvalStatus_ a b] -> ShowS)
-> Show (EvalStatus_ a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. Show a => Int -> EvalStatus_ a b -> ShowS
forall a b. Show a => [EvalStatus_ a b] -> ShowS
forall a b. Show a => EvalStatus_ a b -> String
$cshowsPrec :: forall a b. Show a => Int -> EvalStatus_ a b -> ShowS
showsPrec :: Int -> EvalStatus_ a b -> ShowS
$cshow :: forall a b. Show a => EvalStatus_ a b -> String
show :: EvalStatus_ a b -> String
$cshowList :: forall a b. Show a => [EvalStatus_ a b] -> ShowS
showList :: [EvalStatus_ a b] -> ShowS
Show)

instance Binary a => Binary (EvalStatus_ a b)

data EvalResult a
  = EvalException SerializableException
  | EvalSuccess a
  deriving ((forall x. EvalResult a -> Rep (EvalResult a) x)
-> (forall x. Rep (EvalResult a) x -> EvalResult a)
-> Generic (EvalResult a)
forall x. Rep (EvalResult a) x -> EvalResult a
forall x. EvalResult a -> Rep (EvalResult a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (EvalResult a) x -> EvalResult a
forall a x. EvalResult a -> Rep (EvalResult a) x
$cfrom :: forall a x. EvalResult a -> Rep (EvalResult a) x
from :: forall x. EvalResult a -> Rep (EvalResult a) x
$cto :: forall a x. Rep (EvalResult a) x -> EvalResult a
to :: forall x. Rep (EvalResult a) x -> EvalResult a
Generic, Int -> EvalResult a -> ShowS
[EvalResult a] -> ShowS
EvalResult a -> String
(Int -> EvalResult a -> ShowS)
-> (EvalResult a -> String)
-> ([EvalResult a] -> ShowS)
-> Show (EvalResult a)
forall a. Show a => Int -> EvalResult a -> ShowS
forall a. Show a => [EvalResult a] -> ShowS
forall a. Show a => EvalResult a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> EvalResult a -> ShowS
showsPrec :: Int -> EvalResult a -> ShowS
$cshow :: forall a. Show a => EvalResult a -> String
show :: EvalResult a -> String
$cshowList :: forall a. Show a => [EvalResult a] -> ShowS
showList :: [EvalResult a] -> ShowS
Show)

instance Binary a => Binary (EvalResult a)

-- | A dummy type that tags pointers returned by 'LoadDLL'.
data LoadedDLL

-- SomeException can't be serialized because it contains dynamic
-- types.  However, we do very limited things with the exceptions that
-- are thrown by interpreted computations:
--
-- * We print them, e.g. "*** Exception: <something>"
-- * UserInterrupt has a special meaning
-- * In ghc -e, exitWith should exit with the appropriate exit code
--
-- So all we need to do is distinguish UserInterrupt and ExitCode, and
-- all other exceptions can be represented by their 'show' string.
--
data SerializableException
  = EUserInterrupt
  | EExitCode ExitCode
  | EOtherException String
  deriving ((forall x. SerializableException -> Rep SerializableException x)
-> (forall x. Rep SerializableException x -> SerializableException)
-> Generic SerializableException
forall x. Rep SerializableException x -> SerializableException
forall x. SerializableException -> Rep SerializableException x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SerializableException -> Rep SerializableException x
from :: forall x. SerializableException -> Rep SerializableException x
$cto :: forall x. Rep SerializableException x -> SerializableException
to :: forall x. Rep SerializableException x -> SerializableException
Generic, Int -> SerializableException -> ShowS
[SerializableException] -> ShowS
SerializableException -> String
(Int -> SerializableException -> ShowS)
-> (SerializableException -> String)
-> ([SerializableException] -> ShowS)
-> Show SerializableException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SerializableException -> ShowS
showsPrec :: Int -> SerializableException -> ShowS
$cshow :: SerializableException -> String
show :: SerializableException -> String
$cshowList :: [SerializableException] -> ShowS
showList :: [SerializableException] -> ShowS
Show)

toSerializableException :: SomeException -> SerializableException
toSerializableException :: SomeException -> SerializableException
toSerializableException SomeException
ex
  | Just AsyncException
UserInterrupt <- SomeException -> Maybe AsyncException
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
ex  = SerializableException
EUserInterrupt
  | Just (ExitCode
ec::ExitCode) <- SomeException -> Maybe ExitCode
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
ex = (ExitCode -> SerializableException
EExitCode ExitCode
ec)
  | Bool
otherwise = String -> SerializableException
EOtherException (SomeException -> String
forall a. Show a => a -> String
show (SomeException
ex :: SomeException))

fromSerializableException :: SerializableException -> SomeException
fromSerializableException :: SerializableException -> SomeException
fromSerializableException SerializableException
EUserInterrupt = AsyncException -> SomeException
forall e. Exception e => e -> SomeException
toException AsyncException
UserInterrupt
fromSerializableException (EExitCode ExitCode
c) = ExitCode -> SomeException
forall e. Exception e => e -> SomeException
toException ExitCode
c
fromSerializableException (EOtherException String
str) = ErrorCall -> SomeException
forall e. Exception e => e -> SomeException
toException (String -> ErrorCall
ErrorCall String
str)

instance Binary ExitCode
instance Binary SerializableException

data THResult a
  = THException String
  | THComplete a
  deriving ((forall x. THResult a -> Rep (THResult a) x)
-> (forall x. Rep (THResult a) x -> THResult a)
-> Generic (THResult a)
forall x. Rep (THResult a) x -> THResult a
forall x. THResult a -> Rep (THResult a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (THResult a) x -> THResult a
forall a x. THResult a -> Rep (THResult a) x
$cfrom :: forall a x. THResult a -> Rep (THResult a) x
from :: forall x. THResult a -> Rep (THResult a) x
$cto :: forall a x. Rep (THResult a) x -> THResult a
to :: forall x. Rep (THResult a) x -> THResult a
Generic, Int -> THResult a -> ShowS
[THResult a] -> ShowS
THResult a -> String
(Int -> THResult a -> ShowS)
-> (THResult a -> String)
-> ([THResult a] -> ShowS)
-> Show (THResult a)
forall a. Show a => Int -> THResult a -> ShowS
forall a. Show a => [THResult a] -> ShowS
forall a. Show a => THResult a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> THResult a -> ShowS
showsPrec :: Int -> THResult a -> ShowS
$cshow :: forall a. Show a => THResult a -> String
show :: THResult a -> String
$cshowList :: forall a. Show a => [THResult a] -> ShowS
showList :: [THResult a] -> ShowS
Show)

instance Binary a => Binary (THResult a)

data THResultType = THExp | THPat | THType | THDec | THAnnWrapper
  deriving (Int -> THResultType
THResultType -> Int
THResultType -> [THResultType]
THResultType -> THResultType
THResultType -> THResultType -> [THResultType]
THResultType -> THResultType -> THResultType -> [THResultType]
(THResultType -> THResultType)
-> (THResultType -> THResultType)
-> (Int -> THResultType)
-> (THResultType -> Int)
-> (THResultType -> [THResultType])
-> (THResultType -> THResultType -> [THResultType])
-> (THResultType -> THResultType -> [THResultType])
-> (THResultType -> THResultType -> THResultType -> [THResultType])
-> Enum THResultType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: THResultType -> THResultType
succ :: THResultType -> THResultType
$cpred :: THResultType -> THResultType
pred :: THResultType -> THResultType
$ctoEnum :: Int -> THResultType
toEnum :: Int -> THResultType
$cfromEnum :: THResultType -> Int
fromEnum :: THResultType -> Int
$cenumFrom :: THResultType -> [THResultType]
enumFrom :: THResultType -> [THResultType]
$cenumFromThen :: THResultType -> THResultType -> [THResultType]
enumFromThen :: THResultType -> THResultType -> [THResultType]
$cenumFromTo :: THResultType -> THResultType -> [THResultType]
enumFromTo :: THResultType -> THResultType -> [THResultType]
$cenumFromThenTo :: THResultType -> THResultType -> THResultType -> [THResultType]
enumFromThenTo :: THResultType -> THResultType -> THResultType -> [THResultType]
Enum, Int -> THResultType -> ShowS
[THResultType] -> ShowS
THResultType -> String
(Int -> THResultType -> ShowS)
-> (THResultType -> String)
-> ([THResultType] -> ShowS)
-> Show THResultType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> THResultType -> ShowS
showsPrec :: Int -> THResultType -> ShowS
$cshow :: THResultType -> String
show :: THResultType -> String
$cshowList :: [THResultType] -> ShowS
showList :: [THResultType] -> ShowS
Show, (forall x. THResultType -> Rep THResultType x)
-> (forall x. Rep THResultType x -> THResultType)
-> Generic THResultType
forall x. Rep THResultType x -> THResultType
forall x. THResultType -> Rep THResultType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. THResultType -> Rep THResultType x
from :: forall x. THResultType -> Rep THResultType x
$cto :: forall x. Rep THResultType x -> THResultType
to :: forall x. Rep THResultType x -> THResultType
Generic)

instance Binary THResultType

-- | The server-side Template Haskell state.  This is created by the
-- StartTH message.  A new one is created per module that GHC
-- typechecks.
data QState = QState
  { QState -> Map TypeRep Dynamic
qsMap        :: Map TypeRep Dynamic
       -- ^ persistent data between splices in a module
  , QState -> Maybe Loc
qsLocation   :: Maybe TH.Loc
       -- ^ location for current splice, if any
  , QState -> Pipe
qsPipe :: Pipe
       -- ^ pipe to communicate with GHC
  }
instance Show QState where show :: QState -> String
show QState
_ = String
"<QState>"

-- Orphan instances of Binary for Ptr / FunPtr by conversion to Word64.
-- This is to support Binary StgInfoTable which includes these.
instance Binary (Ptr a) where
  put :: Ptr a -> Put
put Ptr a
p = Word64 -> Put
forall t. Binary t => t -> Put
put (WordPtr -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Ptr a -> WordPtr
forall a. Ptr a -> WordPtr
ptrToWordPtr Ptr a
p) :: Word64)
  get :: Get (Ptr a)
get = (WordPtr -> Ptr a
forall a. WordPtr -> Ptr a
wordPtrToPtr (WordPtr -> Ptr a) -> (Word64 -> WordPtr) -> Word64 -> Ptr a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> WordPtr
forall a b. (Integral a, Num b) => a -> b
fromIntegral) (Word64 -> Ptr a) -> Get Word64 -> Get (Ptr a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Get Word64
forall t. Binary t => Get t
get :: Get Word64)

instance Binary (FunPtr a) where
  put :: FunPtr a -> Put
put = Ptr Any -> Put
forall t. Binary t => t -> Put
put (Ptr Any -> Put) -> (FunPtr a -> Ptr Any) -> FunPtr a -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FunPtr a -> Ptr Any
forall a b. FunPtr a -> Ptr b
castFunPtrToPtr
  get :: Get (FunPtr a)
get = Ptr Any -> FunPtr a
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr (Ptr Any -> FunPtr a) -> Get (Ptr Any) -> Get (FunPtr a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (Ptr Any)
forall t. Binary t => Get t
get

-- Binary instances to support the GetClosure message
#if MIN_VERSION_ghc_heap(8,11,0)
instance Binary Heap.StgTSOProfInfo
instance Binary Heap.CostCentreStack
instance Binary Heap.CostCentre
instance Binary Heap.IndexTable
instance Binary Heap.WhatNext
instance Binary Heap.WhyBlocked
instance Binary Heap.TsoFlags
#endif

instance Binary Heap.StgInfoTable
instance Binary Heap.ClosureType
instance Binary Heap.PrimType
instance Binary a => Binary (Heap.GenClosure a)

data Msg = forall a . (Binary a, Show a) => Msg (Message a)

getMessage :: Get Msg
getMessage :: Get Msg
getMessage = do
    Word8
b <- Get Word8
getWord8
    case Word8
b of
      Word8
0  -> Message () -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message () -> Msg) -> Get (Message ()) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message () -> Get (Message ())
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return Message ()
Shutdown
      Word8
1  -> Message () -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message () -> Msg) -> Get (Message ()) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message () -> Get (Message ())
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return Message ()
InitLinker
      Word8
2  -> Message (Maybe (RemotePtr ())) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (Maybe (RemotePtr ())) -> Msg)
-> (String -> Message (Maybe (RemotePtr ()))) -> String -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Message (Maybe (RemotePtr ()))
LookupSymbol (String -> Msg) -> Get String -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
      Word8
3  -> Message (Maybe HValueRef) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (Maybe HValueRef) -> Msg)
-> (String -> Message (Maybe HValueRef)) -> String -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Message (Maybe HValueRef)
LookupClosure (String -> Msg) -> Get String -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
      Word8
4  -> Message (Either String (RemotePtr LoadedDLL)) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (Either String (RemotePtr LoadedDLL)) -> Msg)
-> (String -> Message (Either String (RemotePtr LoadedDLL)))
-> String
-> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Message (Either String (RemotePtr LoadedDLL))
LoadDLL (String -> Msg) -> Get String -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
      Word8
5  -> Message () -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message () -> Msg) -> (String -> Message ()) -> String -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Message ()
LoadArchive (String -> Msg) -> Get String -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
      Word8
6  -> Message () -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message () -> Msg) -> (String -> Message ()) -> String -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Message ()
LoadObj (String -> Msg) -> Get String -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
      Word8
7  -> Message () -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message () -> Msg) -> (String -> Message ()) -> String -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Message ()
UnloadObj (String -> Msg) -> Get String -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
      Word8
8  -> Message (RemotePtr ()) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (RemotePtr ()) -> Msg)
-> (String -> Message (RemotePtr ())) -> String -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Message (RemotePtr ())
AddLibrarySearchPath (String -> Msg) -> Get String -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
      Word8
9  -> Message Bool -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message Bool -> Msg)
-> (RemotePtr () -> Message Bool) -> RemotePtr () -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RemotePtr () -> Message Bool
RemoveLibrarySearchPath (RemotePtr () -> Msg) -> Get (RemotePtr ()) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RemotePtr ())
forall t. Binary t => Get t
get
      Word8
10 -> Message Bool -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message Bool -> Msg) -> Get (Message Bool) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message Bool -> Get (Message Bool)
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return Message Bool
ResolveObjs
      Word8
11 -> Message (Maybe String) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (Maybe String) -> Msg)
-> (String -> Message (Maybe String)) -> String -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Message (Maybe String)
FindSystemLibrary (String -> Msg) -> Get String -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get
      Word8
12 -> Message [HValueRef] -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message [HValueRef] -> Msg)
-> ([ByteString] -> Message [HValueRef]) -> [ByteString] -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ByteString] -> Message [HValueRef]
CreateBCOs ([ByteString] -> Msg) -> Get [ByteString] -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get [ByteString]
forall t. Binary t => Get t
get
      Word8
13 -> Message () -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message () -> Msg)
-> ([HValueRef] -> Message ()) -> [HValueRef] -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [HValueRef] -> Message ()
FreeHValueRefs ([HValueRef] -> Msg) -> Get [HValueRef] -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get [HValueRef]
forall t. Binary t => Get t
get
      Word8
14 -> Message (RemotePtr ()) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (RemotePtr ()) -> Msg)
-> (ByteString -> Message (RemotePtr ())) -> ByteString -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Message (RemotePtr ())
MallocData (ByteString -> Msg) -> Get ByteString -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get ByteString
forall t. Binary t => Get t
get
      Word8
15 -> Message [RemotePtr ()] -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message [RemotePtr ()] -> Msg)
-> ([ByteString] -> Message [RemotePtr ()]) -> [ByteString] -> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ByteString] -> Message [RemotePtr ()]
MallocStrings ([ByteString] -> Msg) -> Get [ByteString] -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get [ByteString]
forall t. Binary t => Get t
get
      Word8
16 -> Message (RemotePtr C_ffi_cif) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (RemotePtr C_ffi_cif) -> Msg)
-> Get (Message (RemotePtr C_ffi_cif)) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FFIConv -> [FFIType] -> FFIType -> Message (RemotePtr C_ffi_cif)
PrepFFI (FFIConv -> [FFIType] -> FFIType -> Message (RemotePtr C_ffi_cif))
-> Get FFIConv
-> Get ([FFIType] -> FFIType -> Message (RemotePtr C_ffi_cif))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get FFIConv
forall t. Binary t => Get t
get Get ([FFIType] -> FFIType -> Message (RemotePtr C_ffi_cif))
-> Get [FFIType] -> Get (FFIType -> Message (RemotePtr C_ffi_cif))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get [FFIType]
forall t. Binary t => Get t
get Get (FFIType -> Message (RemotePtr C_ffi_cif))
-> Get FFIType -> Get (Message (RemotePtr C_ffi_cif))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get FFIType
forall t. Binary t => Get t
get)
      Word8
17 -> Message () -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message () -> Msg)
-> (RemotePtr C_ffi_cif -> Message ())
-> RemotePtr C_ffi_cif
-> Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> RemotePtr C_ffi_cif -> Message ()
FreeFFI (RemotePtr C_ffi_cif -> Msg)
-> Get (RemotePtr C_ffi_cif) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RemotePtr C_ffi_cif)
forall t. Binary t => Get t
get
      Word8
18 -> Message (RemotePtr StgInfoTable) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (RemotePtr StgInfoTable) -> Msg)
-> Get (Message (RemotePtr StgInfoTable)) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Bool
-> Int
-> Int
-> Int
-> Int
-> ByteString
-> Message (RemotePtr StgInfoTable)
MkConInfoTable (Bool
 -> Int
 -> Int
 -> Int
 -> Int
 -> ByteString
 -> Message (RemotePtr StgInfoTable))
-> Get Bool
-> Get
     (Int
      -> Int
      -> Int
      -> Int
      -> ByteString
      -> Message (RemotePtr StgInfoTable))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Bool
forall t. Binary t => Get t
get Get
  (Int
   -> Int
   -> Int
   -> Int
   -> ByteString
   -> Message (RemotePtr StgInfoTable))
-> Get Int
-> Get
     (Int
      -> Int -> Int -> ByteString -> Message (RemotePtr StgInfoTable))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int
forall t. Binary t => Get t
get Get
  (Int
   -> Int -> Int -> ByteString -> Message (RemotePtr StgInfoTable))
-> Get Int
-> Get
     (Int -> Int -> ByteString -> Message (RemotePtr StgInfoTable))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int
forall t. Binary t => Get t
get Get (Int -> Int -> ByteString -> Message (RemotePtr StgInfoTable))
-> Get Int
-> Get (Int -> ByteString -> Message (RemotePtr StgInfoTable))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int
forall t. Binary t => Get t
get Get (Int -> ByteString -> Message (RemotePtr StgInfoTable))
-> Get Int -> Get (ByteString -> Message (RemotePtr StgInfoTable))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int
forall t. Binary t => Get t
get Get (ByteString -> Message (RemotePtr StgInfoTable))
-> Get ByteString -> Get (Message (RemotePtr StgInfoTable))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get ByteString
forall t. Binary t => Get t
get)
      Word8
19 -> Message (EvalStatus_ [HValueRef] [HValueRef]) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (EvalStatus_ [HValueRef] [HValueRef]) -> Msg)
-> Get (Message (EvalStatus_ [HValueRef] [HValueRef])) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (EvalOpts
-> EvalExpr HValueRef
-> Message (EvalStatus_ [HValueRef] [HValueRef])
EvalStmt (EvalOpts
 -> EvalExpr HValueRef
 -> Message (EvalStatus_ [HValueRef] [HValueRef]))
-> Get EvalOpts
-> Get
     (EvalExpr HValueRef
      -> Message (EvalStatus_ [HValueRef] [HValueRef]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get EvalOpts
forall t. Binary t => Get t
get Get
  (EvalExpr HValueRef
   -> Message (EvalStatus_ [HValueRef] [HValueRef]))
-> Get (EvalExpr HValueRef)
-> Get (Message (EvalStatus_ [HValueRef] [HValueRef]))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (EvalExpr HValueRef)
forall t. Binary t => Get t
get)
      Word8
20 -> Message (EvalStatus_ [HValueRef] [HValueRef]) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (EvalStatus_ [HValueRef] [HValueRef]) -> Msg)
-> Get (Message (EvalStatus_ [HValueRef] [HValueRef])) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (EvalOpts
-> RemoteRef (ResumeContext [HValueRef])
-> Message (EvalStatus_ [HValueRef] [HValueRef])
ResumeStmt (EvalOpts
 -> RemoteRef (ResumeContext [HValueRef])
 -> Message (EvalStatus_ [HValueRef] [HValueRef]))
-> Get EvalOpts
-> Get
     (RemoteRef (ResumeContext [HValueRef])
      -> Message (EvalStatus_ [HValueRef] [HValueRef]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get EvalOpts
forall t. Binary t => Get t
get Get
  (RemoteRef (ResumeContext [HValueRef])
   -> Message (EvalStatus_ [HValueRef] [HValueRef]))
-> Get (RemoteRef (ResumeContext [HValueRef]))
-> Get (Message (EvalStatus_ [HValueRef] [HValueRef]))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (RemoteRef (ResumeContext [HValueRef]))
forall t. Binary t => Get t
get)
      Word8
21 -> Message () -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message () -> Msg) -> Get (Message ()) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (RemoteRef (ResumeContext [HValueRef]) -> Message ()
AbandonStmt (RemoteRef (ResumeContext [HValueRef]) -> Message ())
-> Get (RemoteRef (ResumeContext [HValueRef])) -> Get (Message ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RemoteRef (ResumeContext [HValueRef]))
forall t. Binary t => Get t
get)
      Word8
22 -> Message (EvalResult String) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (EvalResult String) -> Msg)
-> Get (Message (EvalResult String)) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (HValueRef -> Message (EvalResult String)
EvalString (HValueRef -> Message (EvalResult String))
-> Get HValueRef -> Get (Message (EvalResult String))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get HValueRef
forall t. Binary t => Get t
get)
      Word8
23 -> Message (EvalResult String) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (EvalResult String) -> Msg)
-> Get (Message (EvalResult String)) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (HValueRef -> String -> Message (EvalResult String)
EvalStringToString (HValueRef -> String -> Message (EvalResult String))
-> Get HValueRef -> Get (String -> Message (EvalResult String))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get HValueRef
forall t. Binary t => Get t
get Get (String -> Message (EvalResult String))
-> Get String -> Get (Message (EvalResult String))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get String
forall t. Binary t => Get t
get)
      Word8
24 -> Message (EvalResult ()) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (EvalResult ()) -> Msg)
-> Get (Message (EvalResult ())) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (HValueRef -> Message (EvalResult ())
EvalIO (HValueRef -> Message (EvalResult ()))
-> Get HValueRef -> Get (Message (EvalResult ()))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get HValueRef
forall t. Binary t => Get t
get)
      Word8
25 -> Message [RemotePtr CostCentre] -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message [RemotePtr CostCentre] -> Msg)
-> Get (Message [RemotePtr CostCentre]) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> [(String, String)] -> Message [RemotePtr CostCentre]
MkCostCentres (String -> [(String, String)] -> Message [RemotePtr CostCentre])
-> Get String
-> Get ([(String, String)] -> Message [RemotePtr CostCentre])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get String
forall t. Binary t => Get t
get Get ([(String, String)] -> Message [RemotePtr CostCentre])
-> Get [(String, String)] -> Get (Message [RemotePtr CostCentre])
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get [(String, String)]
forall t. Binary t => Get t
get)
      Word8
26 -> Message [String] -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message [String] -> Msg) -> Get (Message [String]) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (RemotePtr CostCentreStack -> Message [String]
CostCentreStackInfo (RemotePtr CostCentreStack -> Message [String])
-> Get (RemotePtr CostCentreStack) -> Get (Message [String])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RemotePtr CostCentreStack)
forall t. Binary t => Get t
get)
      Word8
27 -> Message (RemoteRef BreakArray) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (RemoteRef BreakArray) -> Msg)
-> Get (Message (RemoteRef BreakArray)) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> Message (RemoteRef BreakArray)
NewBreakArray (Int -> Message (RemoteRef BreakArray))
-> Get Int -> Get (Message (RemoteRef BreakArray))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Int
forall t. Binary t => Get t
get)
      Word8
28 -> Message () -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message () -> Msg) -> Get (Message ()) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (RemoteRef BreakArray -> Int -> Int -> Message ()
SetupBreakpoint (RemoteRef BreakArray -> Int -> Int -> Message ())
-> Get (RemoteRef BreakArray) -> Get (Int -> Int -> Message ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RemoteRef BreakArray)
forall t. Binary t => Get t
get Get (Int -> Int -> Message ())
-> Get Int -> Get (Int -> Message ())
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int
forall t. Binary t => Get t
get Get (Int -> Message ()) -> Get Int -> Get (Message ())
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int
forall t. Binary t => Get t
get)
      Word8
29 -> Message Bool -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message Bool -> Msg) -> Get (Message Bool) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (RemoteRef BreakArray -> Int -> Message Bool
BreakpointStatus (RemoteRef BreakArray -> Int -> Message Bool)
-> Get (RemoteRef BreakArray) -> Get (Int -> Message Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RemoteRef BreakArray)
forall t. Binary t => Get t
get Get (Int -> Message Bool) -> Get Int -> Get (Message Bool)
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int
forall t. Binary t => Get t
get)
      Word8
30 -> Message (Maybe HValueRef) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (Maybe HValueRef) -> Msg)
-> Get (Message (Maybe HValueRef)) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (HValueRef -> Int -> Message (Maybe HValueRef)
GetBreakpointVar (HValueRef -> Int -> Message (Maybe HValueRef))
-> Get HValueRef -> Get (Int -> Message (Maybe HValueRef))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get HValueRef
forall t. Binary t => Get t
get Get (Int -> Message (Maybe HValueRef))
-> Get Int -> Get (Message (Maybe HValueRef))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Int
forall t. Binary t => Get t
get)
      Word8
31 -> Message (RemoteRef (IORef QState)) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (RemoteRef (IORef QState)) -> Msg)
-> Get (Message (RemoteRef (IORef QState))) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message (RemoteRef (IORef QState))
-> Get (Message (RemoteRef (IORef QState)))
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return Message (RemoteRef (IORef QState))
StartTH
      Word8
32 -> Message (QResult ()) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (QResult ()) -> Msg)
-> Get (Message (QResult ())) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (RemoteRef (IORef QState)
-> [RemoteRef (Q ())] -> Message (QResult ())
RunModFinalizers (RemoteRef (IORef QState)
 -> [RemoteRef (Q ())] -> Message (QResult ()))
-> Get (RemoteRef (IORef QState))
-> Get ([RemoteRef (Q ())] -> Message (QResult ()))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RemoteRef (IORef QState))
forall t. Binary t => Get t
get Get ([RemoteRef (Q ())] -> Message (QResult ()))
-> Get [RemoteRef (Q ())] -> Get (Message (QResult ()))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get [RemoteRef (Q ())]
forall t. Binary t => Get t
get)
      Word8
33 -> Message () -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message () -> Msg) -> Get (Message ()) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Fingerprint -> HValueRef -> Message ()
AddSptEntry (Fingerprint -> HValueRef -> Message ())
-> Get Fingerprint -> Get (HValueRef -> Message ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Fingerprint
forall t. Binary t => Get t
get Get (HValueRef -> Message ()) -> Get HValueRef -> Get (Message ())
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get HValueRef
forall t. Binary t => Get t
get)
      Word8
34 -> Message (QResult ByteString) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (QResult ByteString) -> Msg)
-> Get (Message (QResult ByteString)) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (RemoteRef (IORef QState)
-> HValueRef
-> THResultType
-> Maybe Loc
-> Message (QResult ByteString)
RunTH (RemoteRef (IORef QState)
 -> HValueRef
 -> THResultType
 -> Maybe Loc
 -> Message (QResult ByteString))
-> Get (RemoteRef (IORef QState))
-> Get
     (HValueRef
      -> THResultType -> Maybe Loc -> Message (QResult ByteString))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RemoteRef (IORef QState))
forall t. Binary t => Get t
get Get
  (HValueRef
   -> THResultType -> Maybe Loc -> Message (QResult ByteString))
-> Get HValueRef
-> Get (THResultType -> Maybe Loc -> Message (QResult ByteString))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get HValueRef
forall t. Binary t => Get t
get Get (THResultType -> Maybe Loc -> Message (QResult ByteString))
-> Get THResultType
-> Get (Maybe Loc -> Message (QResult ByteString))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get THResultType
forall t. Binary t => Get t
get Get (Maybe Loc -> Message (QResult ByteString))
-> Get (Maybe Loc) -> Get (Message (QResult ByteString))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get (Maybe Loc)
forall t. Binary t => Get t
get)
      Word8
35 -> Message (GenClosure HValueRef) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (GenClosure HValueRef) -> Msg)
-> Get (Message (GenClosure HValueRef)) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (HValueRef -> Message (GenClosure HValueRef)
GetClosure (HValueRef -> Message (GenClosure HValueRef))
-> Get HValueRef -> Get (Message (GenClosure HValueRef))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get HValueRef
forall t. Binary t => Get t
get)
      Word8
36 -> Message (EvalStatus_ () ()) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (EvalStatus_ () ()) -> Msg)
-> Get (Message (EvalStatus_ () ())) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (HValueRef -> Message (EvalStatus_ () ())
Seq (HValueRef -> Message (EvalStatus_ () ()))
-> Get HValueRef -> Get (Message (EvalStatus_ () ()))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get HValueRef
forall t. Binary t => Get t
get)
      Word8
37 -> Message () -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message () -> Msg) -> Get (Message ()) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Message () -> Get (Message ())
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return Message ()
RtsRevertCAFs
      Word8
38 -> Message (EvalStatus_ () ()) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (EvalStatus_ () ()) -> Msg)
-> Get (Message (EvalStatus_ () ())) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (RemoteRef (ResumeContext ()) -> Message (EvalStatus_ () ())
ResumeSeq (RemoteRef (ResumeContext ()) -> Message (EvalStatus_ () ()))
-> Get (RemoteRef (ResumeContext ()))
-> Get (Message (EvalStatus_ () ()))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RemoteRef (ResumeContext ()))
forall t. Binary t => Get t
get)
      Word8
40 -> Message (Maybe (RemotePtr ())) -> Msg
forall a. (Binary a, Show a) => Message a -> Msg
Msg (Message (Maybe (RemotePtr ())) -> Msg)
-> Get (Message (Maybe (RemotePtr ()))) -> Get Msg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (RemotePtr LoadedDLL -> String -> Message (Maybe (RemotePtr ()))
LookupSymbolInDLL (RemotePtr LoadedDLL -> String -> Message (Maybe (RemotePtr ())))
-> Get (RemotePtr LoadedDLL)
-> Get (String -> Message (Maybe (RemotePtr ())))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RemotePtr LoadedDLL)
forall t. Binary t => Get t
get Get (String -> Message (Maybe (RemotePtr ())))
-> Get String -> Get (Message (Maybe (RemotePtr ())))
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get String
forall t. Binary t => Get t
get)
      Word8
_  -> String -> Get Msg
forall a. HasCallStack => String -> a
error (String -> Get Msg) -> String -> Get Msg
forall a b. (a -> b) -> a -> b
$ String
"Unknown Message code " String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Word8 -> String
forall a. Show a => a -> String
show Word8
b)

putMessage :: Message a -> Put
putMessage :: forall a. Message a -> Put
putMessage Message a
m = case Message a
m of
  Message a
Shutdown                    -> Word8 -> Put
putWord8 Word8
0
  Message a
InitLinker                  -> Word8 -> Put
putWord8 Word8
1
  LookupSymbol String
str            -> Word8 -> Put
putWord8 Word8
2  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
str
  LookupClosure String
str           -> Word8 -> Put
putWord8 Word8
3  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
str
  LoadDLL String
str                 -> Word8 -> Put
putWord8 Word8
4  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
str
  LoadArchive String
str             -> Word8 -> Put
putWord8 Word8
5  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
str
  LoadObj String
str                 -> Word8 -> Put
putWord8 Word8
6  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
str
  UnloadObj String
str               -> Word8 -> Put
putWord8 Word8
7  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
str
  AddLibrarySearchPath String
str    -> Word8 -> Put
putWord8 Word8
8  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
str
  RemoveLibrarySearchPath RemotePtr ()
ptr -> Word8 -> Put
putWord8 Word8
9  Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemotePtr () -> Put
forall t. Binary t => t -> Put
put RemotePtr ()
ptr
  Message a
ResolveObjs                 -> Word8 -> Put
putWord8 Word8
10
  FindSystemLibrary String
str       -> Word8 -> Put
putWord8 Word8
11 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
str
  CreateBCOs [ByteString]
bco              -> Word8 -> Put
putWord8 Word8
12 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [ByteString] -> Put
forall t. Binary t => t -> Put
put [ByteString]
bco
  FreeHValueRefs [HValueRef]
val          -> Word8 -> Put
putWord8 Word8
13 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [HValueRef] -> Put
forall t. Binary t => t -> Put
put [HValueRef]
val
  MallocData ByteString
bs               -> Word8 -> Put
putWord8 Word8
14 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ByteString -> Put
forall t. Binary t => t -> Put
put ByteString
bs
  MallocStrings [ByteString]
bss           -> Word8 -> Put
putWord8 Word8
15 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [ByteString] -> Put
forall t. Binary t => t -> Put
put [ByteString]
bss
  PrepFFI FFIConv
conv [FFIType]
args FFIType
res       -> Word8 -> Put
putWord8 Word8
16 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FFIConv -> Put
forall t. Binary t => t -> Put
put FFIConv
conv Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [FFIType] -> Put
forall t. Binary t => t -> Put
put [FFIType]
args Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FFIType -> Put
forall t. Binary t => t -> Put
put FFIType
res
  FreeFFI RemotePtr C_ffi_cif
p                   -> Word8 -> Put
putWord8 Word8
17 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemotePtr C_ffi_cif -> Put
forall t. Binary t => t -> Put
put RemotePtr C_ffi_cif
p
  MkConInfoTable Bool
tc Int
p Int
n Int
t Int
pt ByteString
d -> Word8 -> Put
putWord8 Word8
18 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> Put
forall t. Binary t => t -> Put
put Bool
tc Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
p Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
n Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
t Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
pt Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ByteString -> Put
forall t. Binary t => t -> Put
put ByteString
d
  EvalStmt EvalOpts
opts EvalExpr HValueRef
val           -> Word8 -> Put
putWord8 Word8
19 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> EvalOpts -> Put
forall t. Binary t => t -> Put
put EvalOpts
opts Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> EvalExpr HValueRef -> Put
forall t. Binary t => t -> Put
put EvalExpr HValueRef
val
  ResumeStmt EvalOpts
opts RemoteRef (ResumeContext [HValueRef])
val         -> Word8 -> Put
putWord8 Word8
20 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> EvalOpts -> Put
forall t. Binary t => t -> Put
put EvalOpts
opts Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemoteRef (ResumeContext [HValueRef]) -> Put
forall t. Binary t => t -> Put
put RemoteRef (ResumeContext [HValueRef])
val
  AbandonStmt RemoteRef (ResumeContext [HValueRef])
val             -> Word8 -> Put
putWord8 Word8
21 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemoteRef (ResumeContext [HValueRef]) -> Put
forall t. Binary t => t -> Put
put RemoteRef (ResumeContext [HValueRef])
val
  EvalString HValueRef
val              -> Word8 -> Put
putWord8 Word8
22 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> HValueRef -> Put
forall t. Binary t => t -> Put
put HValueRef
val
  EvalStringToString HValueRef
str String
val  -> Word8 -> Put
putWord8 Word8
23 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> HValueRef -> Put
forall t. Binary t => t -> Put
put HValueRef
str Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
val
  EvalIO HValueRef
val                  -> Word8 -> Put
putWord8 Word8
24 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> HValueRef -> Put
forall t. Binary t => t -> Put
put HValueRef
val
  MkCostCentres String
mod [(String, String)]
ccs       -> Word8 -> Put
putWord8 Word8
25 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
mod Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [(String, String)] -> Put
forall t. Binary t => t -> Put
put [(String, String)]
ccs
  CostCentreStackInfo RemotePtr CostCentreStack
ptr     -> Word8 -> Put
putWord8 Word8
26 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemotePtr CostCentreStack -> Put
forall t. Binary t => t -> Put
put RemotePtr CostCentreStack
ptr
  NewBreakArray Int
sz            -> Word8 -> Put
putWord8 Word8
27 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
sz
  SetupBreakpoint RemoteRef BreakArray
arr Int
ix Int
cnt    -> Word8 -> Put
putWord8 Word8
28 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemoteRef BreakArray -> Put
forall t. Binary t => t -> Put
put RemoteRef BreakArray
arr Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
ix Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
cnt
  BreakpointStatus RemoteRef BreakArray
arr Int
ix     -> Word8 -> Put
putWord8 Word8
29 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemoteRef BreakArray -> Put
forall t. Binary t => t -> Put
put RemoteRef BreakArray
arr Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
ix
  GetBreakpointVar HValueRef
a Int
b        -> Word8 -> Put
putWord8 Word8
30 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> HValueRef -> Put
forall t. Binary t => t -> Put
put HValueRef
a Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Put
forall t. Binary t => t -> Put
put Int
b
  Message a
StartTH                     -> Word8 -> Put
putWord8 Word8
31
  RunModFinalizers RemoteRef (IORef QState)
a [RemoteRef (Q ())]
b        -> Word8 -> Put
putWord8 Word8
32 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemoteRef (IORef QState) -> Put
forall t. Binary t => t -> Put
put RemoteRef (IORef QState)
a Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [RemoteRef (Q ())] -> Put
forall t. Binary t => t -> Put
put [RemoteRef (Q ())]
b
  AddSptEntry Fingerprint
a HValueRef
b             -> Word8 -> Put
putWord8 Word8
33 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Fingerprint -> Put
forall t. Binary t => t -> Put
put Fingerprint
a Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> HValueRef -> Put
forall t. Binary t => t -> Put
put HValueRef
b
  RunTH RemoteRef (IORef QState)
st HValueRef
q THResultType
loc Maybe Loc
ty           -> Word8 -> Put
putWord8 Word8
34 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemoteRef (IORef QState) -> Put
forall t. Binary t => t -> Put
put RemoteRef (IORef QState)
st Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> HValueRef -> Put
forall t. Binary t => t -> Put
put HValueRef
q Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> THResultType -> Put
forall t. Binary t => t -> Put
put THResultType
loc Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe Loc -> Put
forall t. Binary t => t -> Put
put Maybe Loc
ty
  GetClosure HValueRef
a                -> Word8 -> Put
putWord8 Word8
35 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> HValueRef -> Put
forall t. Binary t => t -> Put
put HValueRef
a
  Seq HValueRef
a                       -> Word8 -> Put
putWord8 Word8
36 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> HValueRef -> Put
forall t. Binary t => t -> Put
put HValueRef
a
  Message a
RtsRevertCAFs               -> Word8 -> Put
putWord8 Word8
37
  ResumeSeq RemoteRef (ResumeContext ())
a                 -> Word8 -> Put
putWord8 Word8
38 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemoteRef (ResumeContext ()) -> Put
forall t. Binary t => t -> Put
put RemoteRef (ResumeContext ())
a
  LookupSymbolInDLL RemotePtr LoadedDLL
dll String
str   -> Word8 -> Put
putWord8 Word8
40 Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> RemotePtr LoadedDLL -> Put
forall t. Binary t => t -> Put
put RemotePtr LoadedDLL
dll Put -> Put -> Put
forall a b. PutM a -> PutM b -> PutM b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Put
forall t. Binary t => t -> Put
put String
str

-- -----------------------------------------------------------------------------
-- Reading/writing messages

data Pipe = Pipe
  { Pipe -> Handle
pipeRead :: Handle
  , Pipe -> Handle
pipeWrite ::  Handle
  , Pipe -> IORef (Maybe ByteString)
pipeLeftovers :: IORef (Maybe ByteString)
  }

remoteCall :: Binary a => Pipe -> Message a -> IO a
remoteCall :: forall a. Binary a => Pipe -> Message a -> IO a
remoteCall Pipe
pipe Message a
msg = do
  Pipe -> Put -> IO ()
writePipe Pipe
pipe (Message a -> Put
forall a. Message a -> Put
putMessage Message a
msg)
  Pipe -> Get a -> IO a
forall a. Pipe -> Get a -> IO a
readPipe Pipe
pipe Get a
forall t. Binary t => Get t
get

remoteTHCall :: Binary a => Pipe -> THMessage a -> IO a
remoteTHCall :: forall a. Binary a => Pipe -> THMessage a -> IO a
remoteTHCall Pipe
pipe THMessage a
msg = do
  Pipe -> Put -> IO ()
writePipe Pipe
pipe (THMessage a -> Put
forall a. THMessage a -> Put
putTHMessage THMessage a
msg)
  Pipe -> Get a -> IO a
forall a. Pipe -> Get a -> IO a
readPipe Pipe
pipe Get a
forall t. Binary t => Get t
get

writePipe :: Pipe -> Put -> IO ()
writePipe :: Pipe -> Put -> IO ()
writePipe Pipe{Handle
IORef (Maybe ByteString)
pipeRead :: Pipe -> Handle
pipeWrite :: Pipe -> Handle
pipeLeftovers :: Pipe -> IORef (Maybe ByteString)
pipeRead :: Handle
pipeWrite :: Handle
pipeLeftovers :: IORef (Maybe ByteString)
..} Put
put
  | ByteString -> Bool
LB.null ByteString
bs = () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
  | Bool
otherwise  = do
    Handle -> ByteString -> IO ()
LB.hPut Handle
pipeWrite ByteString
bs
    Handle -> IO ()
hFlush Handle
pipeWrite
 where
  bs :: ByteString
bs = Put -> ByteString
runPut Put
put

readPipe :: Pipe -> Get a -> IO a
readPipe :: forall a. Pipe -> Get a -> IO a
readPipe Pipe{Handle
IORef (Maybe ByteString)
pipeRead :: Pipe -> Handle
pipeWrite :: Pipe -> Handle
pipeLeftovers :: Pipe -> IORef (Maybe ByteString)
pipeRead :: Handle
pipeWrite :: Handle
pipeLeftovers :: IORef (Maybe ByteString)
..} Get a
get = do
  Maybe ByteString
leftovers <- IORef (Maybe ByteString) -> IO (Maybe ByteString)
forall a. IORef a -> IO a
readIORef IORef (Maybe ByteString)
pipeLeftovers
  Maybe (a, Maybe ByteString)
m <- Handle
-> Get a -> Maybe ByteString -> IO (Maybe (a, Maybe ByteString))
forall a.
Handle
-> Get a -> Maybe ByteString -> IO (Maybe (a, Maybe ByteString))
getBin Handle
pipeRead Get a
get Maybe ByteString
leftovers
  case Maybe (a, Maybe ByteString)
m of
    Maybe (a, Maybe ByteString)
Nothing -> IOError -> IO a
forall a e. Exception e => e -> a
throw (IOError -> IO a) -> IOError -> IO a
forall a b. (a -> b) -> a -> b
$
      IOErrorType -> String -> Maybe Handle -> Maybe String -> IOError
mkIOError IOErrorType
eofErrorType String
"GHCi.Message.remoteCall" (Handle -> Maybe Handle
forall a. a -> Maybe a
Just Handle
pipeRead) Maybe String
forall a. Maybe a
Nothing
    Just (a
result, Maybe ByteString
new_leftovers) -> do
      IORef (Maybe ByteString) -> Maybe ByteString -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef (Maybe ByteString)
pipeLeftovers Maybe ByteString
new_leftovers
      a -> IO a
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
result

getBin
  :: Handle -> Get a -> Maybe ByteString
  -> IO (Maybe (a, Maybe ByteString))

getBin :: forall a.
Handle
-> Get a -> Maybe ByteString -> IO (Maybe (a, Maybe ByteString))
getBin Handle
h Get a
get Maybe ByteString
leftover = Maybe ByteString -> Decoder a -> IO (Maybe (a, Maybe ByteString))
go Maybe ByteString
leftover (Get a -> Decoder a
forall a. Get a -> Decoder a
runGetIncremental Get a
get)
 where
   go :: Maybe ByteString -> Decoder a -> IO (Maybe (a, Maybe ByteString))
go Maybe ByteString
Nothing (Done ByteString
leftover Int64
_ a
msg) =
     Maybe (a, Maybe ByteString) -> IO (Maybe (a, Maybe ByteString))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ((a, Maybe ByteString) -> Maybe (a, Maybe ByteString)
forall a. a -> Maybe a
Just (a
msg, if ByteString -> Bool
B.null ByteString
leftover then Maybe ByteString
forall a. Maybe a
Nothing else ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
leftover))
   go Maybe ByteString
_ Done{} = ErrorCall -> IO (Maybe (a, Maybe ByteString))
forall e a. Exception e => e -> IO a
throwIO (String -> ErrorCall
ErrorCall String
"getBin: Done with leftovers")
   go (Just ByteString
leftover) (Partial Maybe ByteString -> Decoder a
fun) = do
     Maybe ByteString -> Decoder a -> IO (Maybe (a, Maybe ByteString))
go Maybe ByteString
forall a. Maybe a
Nothing (Maybe ByteString -> Decoder a
fun (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
leftover))
   go Maybe ByteString
Nothing (Partial Maybe ByteString -> Decoder a
fun) = do
     -- putStrLn "before hGetSome"
     ByteString
b <- Handle -> Int -> IO ByteString
B.hGetSome Handle
h (Int
32Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
1024)
     -- putStrLn $ "hGetSome: " ++ show (B.length b)
     if ByteString -> Bool
B.null ByteString
b
        then Maybe (a, Maybe ByteString) -> IO (Maybe (a, Maybe ByteString))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (a, Maybe ByteString)
forall a. Maybe a
Nothing
        else Maybe ByteString -> Decoder a -> IO (Maybe (a, Maybe ByteString))
go Maybe ByteString
forall a. Maybe a
Nothing (Maybe ByteString -> Decoder a
fun (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
b))
   go Maybe ByteString
_lft (Fail ByteString
_rest Int64
_off String
str) =
     ErrorCall -> IO (Maybe (a, Maybe ByteString))
forall e a. Exception e => e -> IO a
throwIO (String -> ErrorCall
ErrorCall (String
"getBin: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
str))