X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fghci%2FDebugger.hs;h=849106984ccd63fbc254001d949df74ff8c51fb7;hb=876db7eda26b37f988bda8f6da8616b03aa5f810;hp=f662217a69f4926c8a49447835d9f590c21e70ff;hpb=ece94e430901c3480e842dcdbbcbef2f1bc070f7;p=ghc-hetmet.git diff --git a/compiler/ghci/Debugger.hs b/compiler/ghci/Debugger.hs index f662217..8491069 100644 --- a/compiler/ghci/Debugger.hs +++ b/compiler/ghci/Debugger.hs @@ -63,12 +63,12 @@ pprintClosureCommand session bindThings force str = do -- Do the obtainTerm--bindSuspensions-computeSubstitution dance go :: Session -> Id -> IO (Maybe TvSubst) go cms id = do - term_ <- obtainTerm cms force id - term <- tidyTermTyVars cms term_ - term' <- if not bindThings then return term + term_ <- withSession cms $ \hsc_env -> obtainTerm hsc_env force id + term <- tidyTermTyVars cms term_ + term' <- if not bindThings then return term else bindSuspensions cms term - showterm <- printTerm cms term' - unqual <- GHC.getPrintUnqual cms + showterm <- printTerm cms term' + unqual <- GHC.getPrintUnqual cms let showSDocForUserOneLine unqual doc = showDocWith LeftMode (doc (mkErrStyle unqual)) (putStrLn . showSDocForUserOneLine unqual) @@ -182,20 +182,27 @@ printTerm cms@(Session ref) = cPprTerm cPpr GHC.setSessionDynFlags cms dflags{log_action=noop_log} mb_txt <- withExtendedLinkEnv [(bname, val)] (GHC.compileExpr cms expr) - let myprec = 9 -- TODO Infix constructors + let myprec = 10 -- application precedence. TODO Infix constructors case mb_txt of - Just txt -> return . Just . text . unsafeCoerce# - $ txt - Nothing -> return Nothing + Just txt_ | txt <- unsafeCoerce# txt_, not (null txt) + -> return $ Just$ cparen (prec >= myprec && + needsParens txt) + (text txt) + _ -> return Nothing `finally` do writeIORef ref hsc_env GHC.setSessionDynFlags cms dflags - + needsParens ('"':txt) = False -- some simple heuristics to see whether parens + -- are redundant in an arbitrary Show output + needsParens ('(':txt) = False + needsParens txt = ' ' `elem` txt + + bindToFreshName hsc_env ty userName = do name <- newGrimName cms userName let ictxt = hsc_IC hsc_env tmp_ids = ic_tmp_ids ictxt - id = mkGlobalId VanillaGlobal name ty vanillaIdInfo + id = mkGlobalId VanillaGlobal name (sigmaType ty) vanillaIdInfo new_ic = ictxt { ic_tmp_ids = id : tmp_ids } return (hsc_env {hsc_IC = new_ic }, name)