X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fghci%2FInteractiveUI.hs;h=3a76f92f42710152a59a50bc577d1af53dca100a;hb=d5c0de4518422315f0179121b222b0e3c7d82d86;hp=9b0bdf956465f3a8de4444447fdac8a989781dde;hpb=10406dfbd1a90e0ca813cc2809719263642d9a97;p=ghc-hetmet.git diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs index 9b0bdf9..3a76f92 100644 --- a/compiler/ghci/InteractiveUI.hs +++ b/compiler/ghci/InteractiveUI.hs @@ -74,6 +74,7 @@ import Data.Char import Data.Dynamic import Data.Array import Control.Monad as Monad +import Text.Printf import Foreign.StablePtr ( newStablePtr ) import GHC.Exts ( unsafeCoerce# ) @@ -539,7 +540,7 @@ runStmt stmt step result <- io $ withProgName (progname st) $ withArgs (args st) $ GHC.runStmt session stmt step afterRunStmt result - return False + return (isRunResultOk result) afterRunStmt :: GHC.RunResult -> GHCi (Maybe (Bool,[Name])) @@ -583,6 +584,11 @@ switchOnRunResult (GHC.RunBreak threadId names info) = do return (Just (True,names)) +isRunResultOk :: GHC.RunResult -> Bool +isRunResultOk (GHC.RunOk _) = True +isRunResultOk _ = False + + showTypeOfName :: Session -> Name -> GHCi () showTypeOfName session n = do maybe_tything <- io (GHC.lookupName session n) @@ -1148,14 +1154,20 @@ optToStr RevertCAFs = "r" -- --------------------------------------------------------------------------- -- code for `:show' -showCmd str = +showCmd str = do + st <- getGHCiState case words str of + ["args"] -> io $ putStrLn (show (args st)) + ["prog"] -> io $ putStrLn (show (progname st)) + ["prompt"] -> io $ putStrLn (show (prompt st)) + ["editor"] -> io $ putStrLn (show (editor st)) + ["stop"] -> io $ putStrLn (show (stop st)) ["modules" ] -> showModules ["bindings"] -> showBindings ["linker"] -> io showLinkerState - ["breaks"] -> showBkptTable - ["context"] -> showContext - _ -> throwDyn (CmdLineError "syntax: :show [modules|bindings|breaks]") + ["breaks"] -> showBkptTable + ["context"] -> showContext + _ -> throwDyn (CmdLineError "syntax: :show [args|prog|prompt|editor|stop|modules|bindings|breaks|context]") showModules = do session <- getSession @@ -1479,15 +1491,23 @@ deleteCmd argLine = do | otherwise = return () historyCmd :: String -> GHCi () -historyCmd = noArgs $ do - s <- getSession - resumes <- io $ GHC.getResumeContext s - case resumes of - [] -> io $ putStrLn "Not stopped at a breakpoint" - (r:rs) -> do - let hist = GHC.resumeHistory r - spans <- mapM (io . GHC.getHistorySpan s) hist - printForUser (vcat (map ppr spans)) +historyCmd arg + | null arg = history 20 + | all isDigit arg = history (read arg) + | otherwise = io $ putStrLn "Syntax: :history [num]" + where + history num = do + s <- getSession + resumes <- io $ GHC.getResumeContext s + case resumes of + [] -> io $ putStrLn "Not stopped at a breakpoint" + (r:rs) -> do + let hist = GHC.resumeHistory r + (took,rest) = splitAt num hist + spans <- mapM (io . GHC.getHistorySpan s) took + let nums = map (printf "-%-3d:") [(1::Int)..] + printForUser (vcat (zipWith (<+>) (map text nums) (map ppr spans))) + io $ putStrLn $ if null rest then "" else "..." backCmd :: String -> GHCi () backCmd = noArgs $ do