#ifdef GHCI
cmModuleIsInterpreted, -- :: CmState -> String -> IO Bool
- cmSetContext, -- :: CmState -> [String] -> [String] -> IO CmState
+ cmSetContext, -- :: CmState -> DynFlags -> [String] -> [String] -> IO CmState
cmGetContext, -- :: CmState -> IO ([String],[String])
cmInfoThing, -- :: CmState -> DynFlags -> String -> IO (Maybe TyThing)
cmTypeOfName, -- :: CmState -> Name -> IO (Maybe String)
+ HValue,
cmCompileExpr, -- :: CmState -> DynFlags -> String
- -- -> IO (CmState, Maybe HValue)#endif
+ -- -> IO (CmState, Maybe HValue)
#endif
)
where
data CmRunResult
= CmRunOk [Name] -- names bound by this evaluation
| CmRunFailed
- | CmRunDeadlocked -- statement deadlocked
| CmRunException Exception -- statement raised an exception
cmRunStmt :: CmState -> DynFlags -> String -> IO (CmState, CmRunResult)
either_hvals <- sandboxIO thing_to_run
case either_hvals of
Left err
- | err == dEADLOCKED
- -> return ( cmstate{ pcs=new_pcs, ic=new_ic },
- CmRunDeadlocked )
- | otherwise
-> do hPutStrLn stderr ("unknown failure, code " ++ show err)
return ( cmstate{ pcs=new_pcs, ic=new_ic }, CmRunFailed )
CmRunOk names)
-- We run the statement in a "sandbox", which amounts to calling into
--- the RTS to request a new main thread. The main benefit is that we
--- get to detect a deadlock this way, but also there's no danger that
--- exceptions raised by the expression can affect the interpreter.
+-- the RTS to request a new main thread. The main benefit is that
+-- there's no danger that exceptions raised by the expression can
+-- affect the interpreter.
sandboxIO :: IO a -> IO (Either Int (Either Exception a))
sandboxIO thing = do
else do
return (Left (fromIntegral stat))
--- ToDo: slurp this in from ghc/includes/RtsAPI.h somehow
-dEADLOCKED = 4 :: Int
-
foreign import "rts_evalStableIO" {- safe -}
rts_evalStableIO :: StablePtr (IO a) -> Ptr (StablePtr a) -> IO CInt
-- more informative than the C type!