diff options
author | Simon Marlow <marlowsd@gmail.com> | 2011-09-16 13:40:53 +0100 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2011-09-21 09:52:59 +0100 |
commit | 3db757241ce7fb99c096c30481aefa86bb9855a1 (patch) | |
tree | 003ea696a39cf558b975cc4d4b0e7bd88c0867ad /ghc/GhciMonad.hs | |
parent | 9de6f19e5de702967a9411b01c06734d3b67eea8 (diff) | |
download | haskell-3db757241ce7fb99c096c30481aefa86bb9855a1.tar.gz |
Add support for all top-level declarations to GHCi
This is work mostly done by Daniel Winograd-Cort during his
internship at MSR Cambridge, with some further refactoring by me.
This commit adds support to GHCi for most top-level declarations that
can be used in Haskell source files. Class, data, newtype, type,
instance are all supported, as are Type Family-related declarations.
The current set of declarations are shown by :show bindings. As with
variable bindings, entities bound by newer declarations shadow earlier
ones.
Tests are in testsuite/tests/ghci/scripts/ghci039--ghci054.
Documentation to follow.
Diffstat (limited to 'ghc/GhciMonad.hs')
-rw-r--r-- | ghc/GhciMonad.hs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/ghc/GhciMonad.hs b/ghc/GhciMonad.hs index ba58d8c21f..d7d5b447be 100644 --- a/ghc/GhciMonad.hs +++ b/ghc/GhciMonad.hs @@ -247,16 +247,27 @@ printForUserPartWay doc = do unqual <- GHC.getPrintUnqual liftIO $ Outputable.printForUserPartWay stdout opt_PprUserLength unqual doc -runStmt :: String -> GHC.SingleStep -> GHCi GHC.RunResult +runStmt :: String -> GHC.SingleStep -> GHCi (Maybe GHC.RunResult) runStmt expr step = do st <- getGHCiState reifyGHCi $ \x -> withProgName (progname st) $ withArgs (args st) $ reflectGHCi x $ do - GHC.handleSourceError (\e -> do GHC.printException e - return GHC.RunFailed) $ do - GHC.runStmtWithLocation (progname st) (line_number st) expr step + GHC.handleSourceError (\e -> do GHC.printException e; + return Nothing) $ do + r <- GHC.runStmtWithLocation (progname st) (line_number st) expr step + return (Just r) + +runDecls :: String -> GHCi [GHC.Name] +runDecls decls = do + st <- getGHCiState + reifyGHCi $ \x -> + withProgName (progname st) $ + withArgs (args st) $ + reflectGHCi x $ do + GHC.handleSourceError (\e -> do GHC.printException e; return []) $ do + GHC.runDeclsWithLocation (progname st) (line_number st) decls resume :: (SrcSpan -> Bool) -> GHC.SingleStep -> GHCi GHC.RunResult resume canLogSpan step = do |