Safe Haskell | None |
---|---|
Language | Haskell2010 |
GHCi
Description
Interacting with the interpreter, whether it is running on an external process or in the current process.
Synopsis
- evalStmt :: HscEnv -> Bool -> EvalExpr ForeignHValue -> IO (EvalStatus_ [ForeignHValue] [HValueRef])
- data EvalStatus_ a b
- = EvalComplete Word64 (EvalResult a)
- | EvalBreak Bool HValueRef Int Int (RemoteRef (ResumeContext b)) (RemotePtr CostCentreStack)
- type EvalStatus a = EvalStatus_ a a
- data EvalResult a
- data EvalExpr a
- resumeStmt :: HscEnv -> Bool -> ForeignRef (ResumeContext [HValueRef]) -> IO (EvalStatus_ [ForeignHValue] [HValueRef])
- abandonStmt :: HscEnv -> ForeignRef (ResumeContext [HValueRef]) -> IO ()
- evalIO :: HscEnv -> ForeignHValue -> IO ()
- evalString :: HscEnv -> ForeignHValue -> IO String
- evalStringToIOString :: HscEnv -> ForeignHValue -> String -> IO String
- mallocData :: HscEnv -> ByteString -> IO (RemotePtr ())
- createBCOs :: HscEnv -> [ResolvedBCO] -> IO [HValueRef]
- addSptEntry :: HscEnv -> Fingerprint -> ForeignHValue -> IO ()
- mkCostCentres :: HscEnv -> String -> [(String, String)] -> IO [RemotePtr CostCentre]
- costCentreStackInfo :: HscEnv -> RemotePtr CostCentreStack -> IO [String]
- newBreakArray :: HscEnv -> Int -> IO (ForeignRef BreakArray)
- enableBreakpoint :: HscEnv -> ForeignRef BreakArray -> Int -> Bool -> IO ()
- breakpointStatus :: HscEnv -> ForeignRef BreakArray -> Int -> IO Bool
- getBreakpointVar :: HscEnv -> ForeignHValue -> Int -> IO (Maybe ForeignHValue)
- initObjLinker :: HscEnv -> IO ()
- lookupSymbol :: HscEnv -> FastString -> IO (Maybe (Ptr ()))
- lookupClosure :: HscEnv -> String -> IO (Maybe HValueRef)
- loadDLL :: HscEnv -> String -> IO (Maybe String)
- loadArchive :: HscEnv -> String -> IO ()
- loadObj :: HscEnv -> String -> IO ()
- unloadObj :: HscEnv -> String -> IO ()
- addLibrarySearchPath :: HscEnv -> String -> IO (Ptr ())
- removeLibrarySearchPath :: HscEnv -> Ptr () -> IO Bool
- resolveObjs :: HscEnv -> IO SuccessFlag
- findSystemLibrary :: HscEnv -> String -> IO (Maybe String)
- iservCmd :: Binary a => HscEnv -> Message a -> IO a
- data Message a where
- Shutdown :: forall a. Message ()
- InitLinker :: forall a. Message ()
- LookupSymbol :: forall a. String -> Message (Maybe (RemotePtr ()))
- LookupClosure :: forall a. String -> Message (Maybe HValueRef)
- LoadDLL :: forall a. String -> Message (Maybe String)
- LoadArchive :: forall a. String -> Message ()
- LoadObj :: forall a. String -> Message ()
- UnloadObj :: forall a. String -> Message ()
- AddLibrarySearchPath :: forall a. String -> Message (RemotePtr ())
- RemoveLibrarySearchPath :: forall a. RemotePtr () -> Message Bool
- ResolveObjs :: forall a. Message Bool
- FindSystemLibrary :: forall a. String -> Message (Maybe String)
- CreateBCOs :: forall a. [ByteString] -> Message [HValueRef]
- FreeHValueRefs :: forall a. [HValueRef] -> Message ()
- AddSptEntry :: forall a. Fingerprint -> HValueRef -> Message ()
- MallocData :: forall a. ByteString -> Message (RemotePtr ())
- MallocStrings :: forall a. [ByteString] -> Message [RemotePtr ()]
- PrepFFI :: forall a. FFIConv -> [FFIType] -> FFIType -> Message (RemotePtr C_ffi_cif)
- FreeFFI :: forall a. RemotePtr C_ffi_cif -> Message ()
- MkConInfoTable :: forall a. Int -> Int -> Int -> Int -> [Word8] -> Message (RemotePtr StgInfoTable)
- EvalStmt :: forall a. EvalOpts -> EvalExpr HValueRef -> Message (EvalStatus_ [HValueRef] [HValueRef])
- ResumeStmt :: forall a. EvalOpts -> RemoteRef (ResumeContext [HValueRef]) -> Message (EvalStatus_ [HValueRef] [HValueRef])
- AbandonStmt :: forall a. RemoteRef (ResumeContext [HValueRef]) -> Message ()
- EvalString :: forall a. HValueRef -> Message (EvalResult String)
- EvalStringToString :: forall a. HValueRef -> String -> Message (EvalResult String)
- EvalIO :: forall a. HValueRef -> Message (EvalResult ())
- MkCostCentres :: forall a. String -> [(String, String)] -> Message [RemotePtr CostCentre]
- CostCentreStackInfo :: forall a. RemotePtr CostCentreStack -> Message [String]
- NewBreakArray :: forall a. Int -> Message (RemoteRef BreakArray)
- EnableBreakpoint :: forall a. RemoteRef BreakArray -> Int -> Bool -> Message ()
- BreakpointStatus :: forall a. RemoteRef BreakArray -> Int -> Message Bool
- GetBreakpointVar :: forall a. HValueRef -> Int -> Message (Maybe HValueRef)
- StartTH :: forall a. Message (RemoteRef (IORef QState))
- RunTH :: forall a. RemoteRef (IORef QState) -> HValueRef -> THResultType -> Maybe Loc -> Message (QResult ByteString)
- RunModFinalizers :: forall a. RemoteRef (IORef QState) -> [RemoteRef (Q ())] -> Message (QResult ())
- withIServ :: (MonadIO m, ExceptionMonad m) => HscEnv -> (IServ -> m a) -> m a
- stopIServ :: HscEnv -> IO ()
- iservCall :: Binary a => IServ -> Message a -> IO a
- readIServ :: IServ -> Get a -> IO a
- writeIServ :: IServ -> Put -> IO ()
- purgeLookupSymbolCache :: HscEnv -> IO ()
- freeHValueRefs :: HscEnv -> [HValueRef] -> IO ()
- mkFinalizedHValue :: HscEnv -> RemoteRef a -> IO (ForeignRef a)
- wormhole :: DynFlags -> ForeignRef a -> IO a
- wormholeRef :: DynFlags -> RemoteRef a -> IO a
- mkEvalOpts :: DynFlags -> Bool -> EvalOpts
- fromEvalResult :: EvalResult a -> IO a
High-level interface to the interpreter
evalStmt :: HscEnv -> Bool -> EvalExpr ForeignHValue -> IO (EvalStatus_ [ForeignHValue] [HValueRef]) Source #
Execute an action of type IO [a]
, returning ForeignHValue
s for
each of the results.
data EvalStatus_ a b Source #
Constructors
EvalComplete Word64 (EvalResult a) | |
EvalBreak Bool HValueRef Int Int (RemoteRef (ResumeContext b)) (RemotePtr CostCentreStack) |
Instances
type EvalStatus a = EvalStatus_ a a Source #
data EvalResult a Source #
Constructors
EvalException SerializableException | |
EvalSuccess a |
Instances
Show a => Show (EvalResult a) | |
Defined in GHCi.Message | |
Generic (EvalResult a) | |
Defined in GHCi.Message Methods from :: EvalResult a -> Rep (EvalResult a) x Source # to :: Rep (EvalResult a) x -> EvalResult a Source # | |
Binary a => Binary (EvalResult a) | |
Defined in GHCi.Message Methods put :: EvalResult a -> Put Source # get :: Get (EvalResult a) Source # putList :: [EvalResult a] -> Put Source # | |
type Rep (EvalResult a) | |
Defined in GHCi.Message type Rep (EvalResult a) = D1 (MetaData "EvalResult" "GHCi.Message" "ghci-8.6.2" False) (C1 (MetaCons "EvalException" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 SerializableException)) :+: C1 (MetaCons "EvalSuccess" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))) |
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.
Instances
Show a => Show (EvalExpr a) | |
Generic (EvalExpr a) | |
Binary a => Binary (EvalExpr a) | |
type Rep (EvalExpr a) | |
Defined in GHCi.Message type Rep (EvalExpr a) = D1 (MetaData "EvalExpr" "GHCi.Message" "ghci-8.6.2" False) (C1 (MetaCons "EvalThis" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)) :+: C1 (MetaCons "EvalApp" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (EvalExpr a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (EvalExpr a)))) |
resumeStmt :: HscEnv -> Bool -> ForeignRef (ResumeContext [HValueRef]) -> IO (EvalStatus_ [ForeignHValue] [HValueRef]) Source #
abandonStmt :: HscEnv -> ForeignRef (ResumeContext [HValueRef]) -> IO () Source #
evalString :: HscEnv -> ForeignHValue -> IO String Source #
Execute an action of type IO String
evalStringToIOString :: HscEnv -> ForeignHValue -> String -> IO String Source #
Execute an action of type String -> IO String
mallocData :: HscEnv -> ByteString -> IO (RemotePtr ()) Source #
Allocate and store the given bytes in memory, returning a pointer to the memory in the remote process.
createBCOs :: HscEnv -> [ResolvedBCO] -> IO [HValueRef] Source #
Create a set of BCOs that may be mutually recursive.
addSptEntry :: HscEnv -> Fingerprint -> ForeignHValue -> IO () Source #
mkCostCentres :: HscEnv -> String -> [(String, String)] -> IO [RemotePtr CostCentre] Source #
costCentreStackInfo :: HscEnv -> RemotePtr CostCentreStack -> IO [String] Source #
newBreakArray :: HscEnv -> Int -> IO (ForeignRef BreakArray) Source #
enableBreakpoint :: HscEnv -> ForeignRef BreakArray -> Int -> Bool -> IO () Source #
breakpointStatus :: HscEnv -> ForeignRef BreakArray -> Int -> IO Bool Source #
getBreakpointVar :: HscEnv -> ForeignHValue -> Int -> IO (Maybe ForeignHValue) Source #
The object-code linker
initObjLinker :: HscEnv -> IO () Source #
lookupSymbol :: HscEnv -> FastString -> IO (Maybe (Ptr ())) Source #
loadDLL :: HscEnv -> String -> IO (Maybe String) Source #
loadDLL loads a dynamic library using the OS's native linker (i.e. dlopen() on Unix, LoadLibrary() on Windows). It takes either an absolute pathname to the file, or a relative filename (e.g. "libfoo.so" or "foo.dll"). In the latter case, loadDLL searches the standard locations for the appropriate library.
Returns:
Nothing => success Just err_msg => failure
resolveObjs :: HscEnv -> IO SuccessFlag Source #
Lower-level API using messages
iservCmd :: Binary a => HscEnv -> Message a -> IO a Source #
Run a command in the interpreter's context. With
-fexternal-interpreter
, the command is serialized and sent to an
external iserv process, and the response is deserialized (hence the
Binary
constraint). With -fno-external-interpreter
we execute
the command directly here.
A Message a
is a message that returns a value of type a
.
These are requests sent from GHC to the server.
Constructors
Shutdown :: forall a. Message () | Exit the iserv process |
InitLinker :: forall a. Message () | |
LookupSymbol :: forall a. String -> Message (Maybe (RemotePtr ())) | |
LookupClosure :: forall a. String -> Message (Maybe HValueRef) | |
LoadDLL :: forall a. String -> Message (Maybe String) | |
LoadArchive :: forall a. String -> Message () | |
LoadObj :: forall a. String -> Message () | |
UnloadObj :: forall a. String -> Message () | |
AddLibrarySearchPath :: forall a. String -> Message (RemotePtr ()) | |
RemoveLibrarySearchPath :: forall a. RemotePtr () -> Message Bool | |
ResolveObjs :: forall a. Message Bool | |
FindSystemLibrary :: forall a. String -> Message (Maybe String) | |
CreateBCOs :: forall a. [ByteString] -> Message [HValueRef] | 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 |
FreeHValueRefs :: forall a. [HValueRef] -> Message () | Release |
AddSptEntry :: forall a. Fingerprint -> HValueRef -> Message () | Add entries to the Static Pointer Table |
MallocData :: forall a. ByteString -> Message (RemotePtr ()) | Malloc some data and return a |
MallocStrings :: forall a. [ByteString] -> Message [RemotePtr ()] | |
PrepFFI :: forall a. FFIConv -> [FFIType] -> FFIType -> Message (RemotePtr C_ffi_cif) | Calls |
FreeFFI :: forall a. RemotePtr C_ffi_cif -> Message () | Free data previously created by |
MkConInfoTable :: forall a. Int -> Int -> Int -> Int -> [Word8] -> Message (RemotePtr StgInfoTable) | Create an info table for a constructor |
EvalStmt :: forall a. EvalOpts -> EvalExpr HValueRef -> Message (EvalStatus_ [HValueRef] [HValueRef]) | Evaluate a statement |
ResumeStmt :: forall a. EvalOpts -> RemoteRef (ResumeContext [HValueRef]) -> Message (EvalStatus_ [HValueRef] [HValueRef]) | Resume evaluation of a statement after a breakpoint |
AbandonStmt :: forall a. RemoteRef (ResumeContext [HValueRef]) -> Message () | Abandon evaluation of a statement after a breakpoint |
EvalString :: forall a. HValueRef -> Message (EvalResult String) | Evaluate something of type |
EvalStringToString :: forall a. HValueRef -> String -> Message (EvalResult String) | Evaluate something of type |
EvalIO :: forall a. HValueRef -> Message (EvalResult ()) | Evaluate something of type |
MkCostCentres :: forall a. String -> [(String, String)] -> Message [RemotePtr CostCentre] | Create a set of CostCentres with the same module name |
CostCentreStackInfo :: forall a. RemotePtr CostCentreStack -> Message [String] | Show a |
NewBreakArray :: forall a. Int -> Message (RemoteRef BreakArray) | Create a new array of breakpoint flags |
EnableBreakpoint :: forall a. RemoteRef BreakArray -> Int -> Bool -> Message () | Enable a breakpoint |
BreakpointStatus :: forall a. RemoteRef BreakArray -> Int -> Message Bool | Query the status of a breakpoint (True = enabled) |
GetBreakpointVar :: forall a. HValueRef -> Int -> Message (Maybe HValueRef) | Get a reference to a free variable at a breakpoint |
StartTH :: forall a. Message (RemoteRef (IORef QState)) | Start a new TH module, return a state token that should be |
RunTH :: forall a. RemoteRef (IORef QState) -> HValueRef -> THResultType -> Maybe Loc -> Message (QResult ByteString) | 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. |
RunModFinalizers :: forall a. RemoteRef (IORef QState) -> [RemoteRef (Q ())] -> Message (QResult ()) | Run the given mod finalizers. |
withIServ :: (MonadIO m, ExceptionMonad m) => HscEnv -> (IServ -> m a) -> m a Source #
Grab a lock on the IServ
and do something with it.
Overloaded because this is used from TcM as well as IO.
iservCall :: Binary a => IServ -> Message a -> IO a Source #
Send a Message
and receive the response from the iserv process
purgeLookupSymbolCache :: HscEnv -> IO () Source #
mkFinalizedHValue :: HscEnv -> RemoteRef a -> IO (ForeignRef a) Source #
Creates a ForeignRef
that will automatically release the
RemoteRef
when it is no longer referenced.
wormhole :: DynFlags -> ForeignRef a -> IO a Source #
Convert a ForeignRef
to the value it references directly. This
only works when the interpreter is running in the same process as
the compiler, so it fails when -fexternal-interpreter
is on.
wormholeRef :: DynFlags -> RemoteRef a -> IO a Source #
Convert an RemoteRef
to the value it references directly. This
only works when the interpreter is running in the same process as
the compiler, so it fails when -fexternal-interpreter
is on.
fromEvalResult :: EvalResult a -> IO a Source #