moduleHint.Context(ModuleName,loadModules,getLoadedModules,setTopLevelModules,setImports,reset)whereimportData.ListimportControl.Monad.ErrorimportHint.BaseimportHint.ConversionsimportqualifiedGHC-- | Tries to load all the requested modules from their source file.-- Modules my be indicated by their ModuleName (e.g. \"My.Module\") or-- by the full path to its source file.---- The interpreter is 'reset' both before loading the modules and in the event-- of an error.loadModules::[String]->Interpreter()loadModulesfs=doghc_session<-fromSessionStateghcSession---- first, unload everythingreset--letdoLoad=mayFail$dotargets<-mapM(\f->GHC.guessTargetfNothing)fs--GHC.setTargetsghc_sessiontargetsres<-GHC.loadghc_sessionGHC.LoadAllTargetsreturn$guard(isSucceededres)>>Just()--doLoad`catchError`(\e->reset>>throwErrore)--return()-- | Returns the list of modules loaded with 'loadModules'.getLoadedModules::Interpreter[ModuleName]getLoadedModules=liftM(mapmodNameFromSummary)getLoadedModSummariesmodNameFromSummary::GHC.ModSummary->ModuleNamemodNameFromSummary=fromGhcRep_.GHC.ms_modgetLoadedModSummaries::Interpreter[GHC.ModSummary]getLoadedModSummaries=doghc_session<-fromSessionStateghcSession--all_mod_summ<-liftIO$GHC.getModuleGraphghc_sessionfilterM(liftIO.GHC.isLoadedghc_session.GHC.ms_mod_name)all_mod_summ-- | Sets the modules whose context is used during evaluation. All bindings-- of these modules are in scope, not only those exported.---- Modules must be interpreted to use this function.setTopLevelModules::[ModuleName]->Interpreter()setTopLevelModulesms=doghc_session<-fromSessionStateghcSession--loaded_mods_ghc<-getLoadedModSummaries--letnot_loaded=ms\\mapmodNameFromSummaryloaded_mods_ghcwhen(not.null$not_loaded)$throwError$NotAllowed("These modules have not been loaded:\n"++unlinesnot_loaded)--ms_mods<-mapMfindModulems--letmod_is_interpr=GHC.moduleIsInterpretedghc_sessionnot_interpreted<-liftIO$filterM(liftMnot.mod_is_interpr)ms_modswhen(not.null$not_interpreted)$throwError$NotAllowed("These modules are not interpreted:\n"++unlines(mapfromGhcRep_not_interpreted))--liftIO$do(_,old_imports)<-GHC.getContextghc_sessionGHC.setContextghc_sessionms_modsold_imports-- | Sets the modules whose exports must be in context.setImports::[ModuleName]->Interpreter()setImportsms=doghc_session<-fromSessionStateghcSession--ms_mods<-mapMfindModulems--liftIO$do(old_top_level,_)<-GHC.getContextghc_sessionGHC.setContextghc_sessionold_top_levelms_mods-- | All imported modules are cleared from the context, and-- loaded modules are unloaded. It is similar to a @:load@ in-- GHCi, but observe that not even the Prelude will be in-- context after a reset.reset::Interpreter()reset=doghc_session<-fromSessionStateghcSession---- Remove all modules from contextliftIO$GHC.setContextghc_session[][]---- Unload all previously loaded modulesliftIO$GHC.setTargetsghc_session[]liftIO$GHC.loadghc_sessionGHC.LoadAllTargets---- At this point, GHCi would call rts_revertCAFs and-- reset the buffering of stdin, stdout and stderr.-- Should we do any of these?---- liftIO $ rts_revertCAFs--return()-- SHOULD WE CALL THIS WHEN MODULES ARE LOADED / UNLOADED?-- foreign import ccall "revertCAFs" rts_revertCAFs :: IO ()