WOOHOO! GHCi interprets "Hello World":
_____ __ __ ____ _________________________________________________
(| || || (| |) GHC Interactive, version 5.00
|| __ ||___|| || () For Haskell 98.
|| |) ||---|| || || http://www.haskell.org/ghc
|| || || || || (| Bug reports to: glasgow-haskell-bugs@haskell.org
(|___|| || || (|__|) \\______________________________________________________
Loading package std ... resolving ... done.
Prelude> :l Main
cmLoadModule: downsweep begins
getSummary: Main
after tsort:
NONREC
ModSummary { ms_mod = Main, ms_imps = [] ms_srcimps = [] }
CHECKING OLD IFACE for hs = Just "./Main.hs", hspp = Just "/tmp/ghc25011.hspp"
COMPILATION IS REQUIRED
UPSWEEP COMPLETELY SUCCESSFUL
CmLink.link: linkables are ...
LinkableM Main [Trees [Main.main = letP stg_cIM = (@PP Native PrelShow.$fShow[] Native PrelShow.$fShowChar)
in
letP stg_cIL = (@IP Native PrelBase.unpackCString#
141613256#)
in
(@PP (@PP Native PrelIO.print stg_cIM) stg_cIL)]]
Main.main
CmLink.link: done
Prelude> Main.main
Run expression: Main.main
evalI:
141613256#
"Hello, world!"
done.
LinkResult(..),
link,
unload,
- PersistentLinkerState{-abstractly!-}, emptyPLS
+ PersistentLinkerState{-abstractly!-}, emptyPLS,
+ lookupClosure
) where
import DriverPipeline
import CmTypes
import CmStaticInfo ( GhciMode(..) )
-import Module ( ModuleName, PackageName )
import Outputable ( SDoc )
-import FiniteMap
import Digraph ( SCC(..), flattenSCC )
-import Outputable
-import Exception
import DriverUtil
+import Module ( ModuleName, PackageName )
+import RdrName
+import FiniteMap
+import Outputable
import Panic ( panic )
+import Exception
import IO
#include "HsVersions.h"
-- to be actually linked this time around (or unlinked and re-linked
-- if the module was recompiled).
-link Batch batch_attempt_linking linkables pls1
- | batch_attempt_linking
- = do hPutStrLn stderr "CmLink.link(batch): linkables are ..."
+link mode batch_attempt_linking linkables pls1
+ = do hPutStrLn stderr "CmLink.link: linkables are ..."
hPutStrLn stderr (showSDoc (vcat (map ppr linkables)))
- let o_files = concatMap getOfiles linkables
+ res <- link' mode batch_attempt_linking linkables pls1
+ hPutStrLn stderr "CmLink.link: done"
+ return res
+
+link' Batch batch_attempt_linking linkables pls1
+ | batch_attempt_linking
+ = do let o_files = concatMap getOfiles linkables
doLink o_files
-- doLink only returns if it succeeds
- hPutStrLn stderr "CmLink.link(batch): done"
return (LinkOK pls1)
| otherwise
= do hPutStrLn stderr "CmLink.link(batch): upsweep (partially?) failed OR main not exported;"
getOfiles (LP _) = panic "CmLink.link(getOfiles): shouldn't get package linkables"
getOfiles (LM _ us) = map nameOfObject (filter isObject us)
-link Interactive batch_attempt_linking linkables pls1
- = linkObjs linkables pls1
+link' Interactive batch_attempt_linking linkables pls1
+ = linkObjs linkables pls1
+
ppLinkableSCC :: SCC Linkable -> SDoc
ppLinkableSCC = ppr . flattenSCC
-- link all the interpreted code in one go. We first remove from the
-- various environments any previous versions of these modules.
linkFinish pls mods ul_trees = do
+ resolveObjs
let itbl_env' = filterRdrNameEnv mods (itbl_env pls)
closure_env' = filterRdrNameEnv mods (closure_env pls)
stuff = [ (trees,itbls) | Trees trees itbls <- ul_trees ]
closure_env = new_closure_env,
itbl_env = new_itbl_env
}
- resolveObjs
+ putStrLn (showSDoc (vcat (map ppr (keysFM new_closure_env))))
return (LinkOK new_pls)
-- purge the current "linked image"
unload :: PersistentLinkerState -> IO PersistentLinkerState
unload pls = return pls{ closure_env = emptyFM, itbl_env = emptyFM }
+lookupClosure :: RdrName -> PersistentLinkerState -> Maybe HValue
+lookupClosure nm PersistentLinkerState{ closure_env = cenv } =
+ case lookupFM cenv nm of
+ Nothing -> Nothing
+ Just hv -> Just hv
#endif
\end{code}
\begin{code}
module CompManager ( cmInit, cmLoadModule,
cmGetExpr, cmRunExpr,
- CmState, emptyCmState -- abstract
+ CmState, emptyCmState, -- abstract
+ cmLookupSymbol --tmp
)
where
import UniqFM ( emptyUFM, lookupUFM, addToUFM, delListFromUFM )
import Digraph ( SCC(..), stronglyConnComp, flattenSCC, flattenSCCs )
-import CmLink ( PersistentLinkerState, emptyPLS, Linkable(..),
- link, LinkResult(..),
- filterModuleLinkables, modname_of_linkable,
- is_package_linkable, findModuleLinkable )
+import CmLink
import CmTypes
import HscTypes
import Interpreter ( HValue )
import HscTypes ( HomeSymbolTable, HomeIfaceTable,
PersistentCompilerState, ModDetails(..) )
import Name ( lookupNameEnv )
+import RdrName
import Module
import PrelNames ( mainName )
import HscMain ( initPersistentCompilerState )
return (Just time))
`catch`
(\err -> return Nothing)
+
+cmLookupSymbol :: RdrName -> CmState -> Maybe HValue
+cmLookupSymbol nm CmState{ pls = pls } = lookupClosure nm pls
\end{code}
-----------------------------------------------------------------------------
--- $Id: InteractiveUI.hs,v 1.2 2000/11/16 11:39:37 simonmar Exp $
+-- $Id: InteractiveUI.hs,v 1.3 2000/11/16 16:54:36 simonmar Exp $
--
-- GHC Interactive User Interface
--
module InteractiveUI (interactiveUI) where
+#include "HsVersions.h"
+
import CompManager
import CmStaticInfo
import DriverUtil
import DriverState
import Linker
import Module
+import RdrName -- tmp
+import OccName -- tmp
import Panic
import Util
import IO
import Char
+import PrelGHC ( unsafeCoerce# )
+
-----------------------------------------------------------------------------
ghciWelcomeMsg = "\
uiLoop = do
st <- getGHCiState
#ifndef NO_READLINE
- l <- io (readline (moduleNameUserString (current_module st) ++ ">"))
+ l <- io (readline (moduleNameUserString (current_module st) ++ "> "))
#else
l <- io (hGetLine stdin)
#endif
runCommand l
uiLoop
-runCommand c = myCatch (doCommand c)
- (\e -> io (hPutStr stdout ("Error: " ++ show e)))
+runCommand c =
+ myCatchDyn (doCommand c)
+ (\dyn -> case dyn of
+ PhaseFailed phase code ->
+ io ( putStrLn ("Phase " ++ phase ++ " failed (code "
+ ++ show code ++ ")"))
+ Interrupted -> io (putStrLn "Interrupted.")
+ _ -> io (putStrLn (show (dyn :: BarfKind)))
+ )
doCommand (':' : command) = specialCommand command
doCommand expr = do
+ st <- getGHCiState
io (hPutStrLn stdout ("Run expression: " ++ expr))
+ let (mod,'.':str) = break (=='.') expr
+ case cmLookupSymbol (mkOrig varName (mkModuleName mod) (_PK_ str)) (cmstate st) of
+ Nothing -> io (putStrLn "nothing.")
+ Just e -> io (do unsafeCoerce# e :: IO ()
+ putStrLn "done.")
return ()
specialCommand str = do
case [ (s,f) | (s,f) <- commands, prefixMatch cmd s ] of
[] -> io $ hPutStr stdout ("uknown command `:" ++ cmd ++ "'\n"
++ shortHelpText)
- [(_,f)] -> f rest
+ [(_,f)] -> f (dropWhile isSpace rest)
cs -> io $ hPutStrLn stdout ("prefix " ++ cmd ++
" matches multiple commands (" ++
- foldr1 (\a b -> a ++ ',':b) (map fst cs) ++ ")")
+ foldr1 (\a b -> a ++ ',':b) (map fst cs)
+ ++ ")")
noArgs c = io (hPutStrLn stdout ("command `:" ++ c ++ "' takes no arguments"))
io m = GHCi $ \s -> m >>= \a -> return (s,a)
-myCatch (GHCi m) h = GHCi $ \s -> Exception.catch (m s) (\e -> unGHCi (h e) s)
+myCatch (GHCi m) h = GHCi $ \s ->
+ Exception.catch (m s) (\e -> unGHCi (h e) s)
+myCatchDyn (GHCi m) h = GHCi $ \s ->
+ Exception.catchDyn (m s) (\e -> unGHCi (h e) s)
-----------------------------------------------------------------------------
-- package loader