Permalink
Browse files

Allow foreign import declarations to the entered interactively in GHCi.

  • Loading branch information...
simonmar committed Sep 22, 2011
1 parent 25de0ab commit 90d70e44d58bc466a65259c6e371707dc86c3d06
Showing with 16 additions and 4 deletions.
  1. +14 −3 compiler/main/HscMain.lhs
  2. +2 −1 ghc/InteractiveUI.hs
View
@@ -83,6 +83,7 @@ import VarSet
import VarEnv ( emptyTidyEnv )
import Panic
import Class
+import Data.List
#endif
import Id
@@ -145,7 +146,7 @@ import Bag
import Exception
import Control.Monad
-import Data.Maybe ( catMaybes )
+import Data.Maybe
import Data.IORef
\end{code}
#include "HsVersions.h"
@@ -1364,16 +1365,26 @@ hscDeclsWithLocation hsc_env str source linenumber = runHsc hsc_env $ do
let
tcs = filter (not . isImplicitTyCon) $ mg_tcs simpl_mg
clss = mg_clss simpl_mg
- tythings = map ATyCon tcs ++ map (ATyCon . classTyCon) clss
- sys_vars = filter (isExternalName . idName) $
+
+ ext_vars = filter (isExternalName . idName) $
bindersOfBinds (cg_binds tidy_cg)
+
+ (sys_vars, user_vars) = partition is_sys_var ext_vars
+ is_sys_var id = isDFunId id
+ || isRecordSelector id
+ || isJust (isClassOpId_maybe id)
-- we only need to keep around the external bindings
-- (as decided by TidyPgm), since those are the only ones
-- that might be referenced elsewhere.
+ tythings = map AnId user_vars
+ ++ map ATyCon tcs
+ ++ map (ATyCon . classTyCon) clss
+
-- pprTrace "new tycons" (ppr tcs) $ return ()
-- pprTrace "new classes" (ppr clss) $ return ()
-- pprTrace "new sys Ids" (ppr sys_vars) $ return ()
+ -- pprTrace "new user Ids" (ppr user_vars) $ return ()
let ictxt1 = extendInteractiveContext icontext tythings
ictxt = ictxt1 {
View
@@ -728,7 +728,8 @@ enqueueCommands cmds = do
-- | If we one of these strings prefixes a command, then we treat it as a decl
-- rather than a stmt.
declPrefixes :: [String]
-declPrefixes = ["class ","data ","newtype ","type ","instance ", "deriving "]
+declPrefixes = ["class ","data ","newtype ","type ","instance ", "deriving ",
+ "foreign "]
runStmt :: String -> SingleStep -> GHCi Bool
runStmt stmt step

0 comments on commit 90d70e4

Please sign in to comment.