X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fghci%2FInteractiveUI.hs;h=e0c49ceed6928e3489e84d667370306085d995cb;hb=831a35dd00faff195cf938659c2dd736192b865f;hp=70a602f16e27c61817c6304bd90c650835e9e8d2;hpb=7f1db085b2256e3372feca52d493ca7577413cbe;p=ghc-hetmet.git diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs index 70a602f..e0c49ce 100644 --- a/compiler/ghci/InteractiveUI.hs +++ b/compiler/ghci/InteractiveUI.hs @@ -335,7 +335,7 @@ interactiveUI srcs maybe_exprs = withTerminalReset $ do #endif -- initial context is just the Prelude - prel_mod <- GHC.findModule (GHC.mkModuleName "Prelude") Nothing + prel_mod <- GHC.lookupModule (GHC.mkModuleName "Prelude") Nothing GHC.setContext [] [prel_mod] default_editor <- liftIO $ findEditor @@ -730,23 +730,19 @@ afterRunStmt step_here run_result = do GHC.RunOk names -> do show_types <- isOptionSet ShowType when show_types $ printTypeOfNames names - GHC.RunBreak _ names mb_info - | isNothing mb_info || + GHC.RunBreak _ names mb_info + | isNothing mb_info || step_here (GHC.resumeSpan $ head resumes) -> do - printForUser $ ptext (sLit "Stopped at") <+> - ppr (GHC.resumeSpan $ head resumes) --- printTypeOfNames session names - let namesSorted = sortBy compareNames names - tythings <- catMaybes `liftM` - mapM GHC.lookupName namesSorted - docs <- pprTypeAndContents [id | AnId id <- tythings] - printForUserPartWay docs - maybe (return ()) runBreakCmd mb_info + mb_id_loc <- toBreakIdAndLocation mb_info + let breakCmd = maybe "" ( \(_,l) -> onBreakCmd l ) mb_id_loc + if (null breakCmd) + then printStoppedAtBreakInfo (head resumes) names + else enqueueCommands [breakCmd] -- run the command set with ":set stop " st <- getGHCiState enqueueCommands [stop st] return () - | otherwise -> resume GHC.SingleStep >>= + | otherwise -> resume step_here GHC.SingleStep >>= afterRunStmt step_here >> return () _ -> return () @@ -757,17 +753,26 @@ afterRunStmt step_here run_result = do return (case run_result of GHC.RunOk _ -> True; _ -> False) -runBreakCmd :: GHC.BreakInfo -> GHCi () -runBreakCmd info = do +toBreakIdAndLocation :: + Maybe GHC.BreakInfo -> GHCi (Maybe (Int, BreakLocation)) +toBreakIdAndLocation Nothing = return Nothing +toBreakIdAndLocation (Just info) = do let mod = GHC.breakInfo_module info nm = GHC.breakInfo_number info st <- getGHCiState - case [ loc | (_,loc) <- breaks st, - breakModule loc == mod, breakTick loc == nm ] of - [] -> return () - loc:_ | null cmd -> return () - | otherwise -> do enqueueCommands [cmd]; return () - where cmd = onBreakCmd loc + return $ listToMaybe [ id_loc | id_loc@(_,loc) <- breaks st, + breakModule loc == mod, + breakTick loc == nm ] + +printStoppedAtBreakInfo :: Resume -> [Name] -> GHCi () +printStoppedAtBreakInfo resume names = do + printForUser $ ptext (sLit "Stopped at") <+> + ppr (GHC.resumeSpan resume) + -- printTypeOfNames session names + let namesSorted = sortBy compareNames names + tythings <- catMaybes `liftM` mapM GHC.lookupName namesSorted + docs <- pprTypeAndContents [id | AnId id <- tythings] + printForUserPartWay docs printTypeOfNames :: [Name] -> GHCi () printTypeOfNames names @@ -1030,6 +1035,9 @@ defineMacro overwrite s = do runMacro :: GHC.HValue{-String -> IO String-} -> String -> GHCi Bool runMacro fun s = do str <- io ((unsafeCoerce# fun :: String -> IO String) s) + -- make sure we force any exceptions in the result, while we are still + -- inside the exception handler for commands: + seqList str (return ()) enqueueCommands (lines str) return False @@ -1207,14 +1215,20 @@ typeOfExpr str ty <- GHC.exprType str dflags <- getDynFlags let pefas = dopt Opt_PrintExplicitForalls dflags - printForUser $ sep [text str, nest 2 (dcolon <+> pprTypeForUser pefas ty)] + printForUser $ sep [utext str, nest 2 (dcolon <+> pprTypeForUser pefas ty)] kindOfType :: String -> GHCi () kindOfType str = handleSourceError (\e -> GHC.printExceptionAndWarnings e) $ do ty <- GHC.typeKind str - printForUser $ text str <+> dcolon <+> ppr ty + printForUser $ utext str <+> dcolon <+> ppr ty +-- HACK for printing unicode text. We assume the output device +-- understands UTF-8, and go via FastString which converts to UTF-8. +-- ToDo: fix properly when we have encoding support in Handles. +utext :: String -> SDoc +utext str = ftext (mkFastString str) + quit :: String -> GHCi Bool quit _ = return True @@ -1970,7 +1984,7 @@ continueCmd = noArgs $ doContinue (const True) GHC.RunToCompletion -- doContinue :: SingleStep -> GHCi () doContinue :: (SrcSpan -> Bool) -> SingleStep -> GHCi () doContinue pred step = do - runResult <- resume step + runResult <- resume pred step afterRunStmt pred runResult return () @@ -2342,7 +2356,7 @@ mkTickArray ticks lookupModule :: String -> GHCi Module lookupModule modName - = GHC.findModule (GHC.mkModuleName modName) Nothing + = GHC.lookupModule (GHC.mkModuleName modName) Nothing -- don't reset the counter back to zero? discardActiveBreakPoints :: GHCi ()