+ -- Prepare for codegen
+ ; prepd_expr <- corePrepExpr dflags tidy_expr
+
+ -- Convert to BCOs
+ ; bcos <- coreExprToBCOs dflags prepd_expr
+
+ ; let
+ -- Make all the bound ids "global" ids, now that
+ -- they're notionally top-level bindings. This is
+ -- important: otherwise when we come to compile an expression
+ -- using these ids later, the byte code generator will consider
+ -- the occurrences to be free rather than global.
+ global_bound_ids = map globaliseId bound_ids;
+ globaliseId id = setGlobalIdDetails id VanillaGlobal
+
+ ; return (pcs2, Just (global_bound_ids, ty, bcos))
+
+ }}}}}
+
+hscParseStmt :: DynFlags -> String -> IO (Maybe RdrNameStmt)
+hscParseStmt dflags str
+ = do -------------------------- Parser ----------------
+ showPass dflags "Parser"
+ _scc_ "Parser" do
+
+ buf <- stringToStringBuffer str
+
+ let glaexts | dopt Opt_GlasgowExts dflags = 1#
+ | otherwise = 0#
+
+ case parseStmt buf PState{ bol = 0#, atbol = 1#,
+ context = [], glasgow_exts = glaexts,
+ loc = mkSrcLoc SLIT("<interactive>") 1 } of {
+
+ PFailed err -> do { hPutStrLn stderr (showSDoc err);
+-- Not yet implemented in <4.11 freeStringBuffer buf;
+ return Nothing };
+
+ -- no stmt: the line consisted of just space or comments
+ POk _ Nothing -> return Nothing;
+
+ POk _ (Just rdr_stmt) -> do {
+
+ --ToDo: can't free the string buffer until we've finished this
+ -- compilation sweep and all the identifiers have gone away.
+ --freeStringBuffer buf;
+ dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr rdr_stmt);
+ return (Just rdr_stmt)
+ }}
+#endif
+\end{code}
+
+%************************************************************************
+%* *
+\subsection{Getting information about an identifer}
+%* *
+%************************************************************************
+
+\begin{code}
+#ifdef GHCI
+hscThing -- like hscStmt, but deals with a single identifier
+ :: DynFlags
+ -> HomeSymbolTable
+ -> HomeIfaceTable
+ -> PersistentCompilerState -- IN: persistent compiler state
+ -> InteractiveContext -- Context for compiling
+ -> String -- The identifier
+ -> IO ( PersistentCompilerState,
+ [TyThing] )
+
+hscThing dflags hst hit pcs0 ic str
+ = do maybe_rdr_name <- myParseIdentifier dflags str
+ case maybe_rdr_name of {
+ Nothing -> return (pcs0, []);
+ Just rdr_name -> do
+
+ -- if the identifier is a constructor (begins with an
+ -- upper-case letter), then we need to consider both
+ -- constructor and type class identifiers.
+ let rdr_names
+ | occNameSpace occ == dataName = [ rdr_name, tccls_name ]
+ | otherwise = [ rdr_name ]
+ where
+ occ = rdrNameOcc rdr_name
+ tccls_occ = setOccNameSpace occ tcClsName
+ tccls_name = setRdrNameOcc rdr_name tccls_occ
+
+ (pcs, unqual, maybe_rn_result) <-
+ renameRdrName dflags hit hst pcs0 ic rdr_names
+
+ case maybe_rn_result of {
+ Nothing -> return (pcs, []);
+ Just (names, decls) -> do {
+
+ maybe_pcs <- typecheckExtraDecls dflags pcs hst unqual
+ iNTERACTIVE decls;
+
+ case maybe_pcs of {
+ Nothing -> return (pcs, []);
+ Just pcs ->
+ let do_lookup n
+ | isLocalName n = lookupNameEnv (ic_type_env ic) n
+ | otherwise = lookupType hst (pcs_PTE pcs) n
+
+ maybe_ty_things = map do_lookup names
+ in
+ return (pcs, catMaybes maybe_ty_things) }
+ }}}
+
+myParseIdentifier dflags str
+ = do buf <- stringToStringBuffer str
+
+ let glaexts | dopt Opt_GlasgowExts dflags = 1#
+ | otherwise = 0#
+
+ case parseIdentifier buf
+ PState{ bol = 0#, atbol = 1#,
+ context = [], glasgow_exts = glaexts,
+ loc = mkSrcLoc SLIT("<interactive>") 1 } of
+
+ PFailed err -> do { hPutStrLn stderr (showSDoc err);
+ freeStringBuffer buf;
+ return Nothing }
+
+ POk _ rdr_name -> do { --should, but can't: freeStringBuffer buf;
+ return (Just rdr_name) }
+#endif
+\end{code}
+
+%************************************************************************
+%* *
+\subsection{Find all the things defined in a module}
+%* *
+%************************************************************************