X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fghci%2FDebugger.hs;h=849106984ccd63fbc254001d949df74ff8c51fb7;hp=b7c8e324d7a63d71da0d959207c360b54d2cca4c;hb=876db7eda26b37f988bda8f6da8616b03aa5f810;hpb=834fcf7de73aeb4a3fa4c88dc995ce1b55b78a93 diff --git a/compiler/ghci/Debugger.hs b/compiler/ghci/Debugger.hs index b7c8e32..8491069 100644 --- a/compiler/ghci/Debugger.hs +++ b/compiler/ghci/Debugger.hs @@ -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)