@@ -71,9 +71,9 @@ supportModule =
71 code = unlines
71 code = unlines
72 [ "module S where"
72 [ "module S where"
74− , "import Console"
74+ , "import Prelude"
76 , "import Control.Monad.Eff"
75 , "import Control.Monad.Eff"
76+ , "import Control.Monad.Eff.Console"
77 , "import Control.Monad.Eff.Unsafe"
77 , "import Control.Monad.Eff.Unsafe"
79 , "class Eval a where"
79 , "class Eval a where"
@@ -431,17 +431,19 @@ handleCommand (Expression val) = handleDeclaration val
431handleCommand ShowHelp = PSCI $ outputStrLn helpMessage
431handleCommand ShowHelp = PSCI $ outputStrLn helpMessage
432handleCommand (Import im) = handleImport im
432handleCommand (Import im) = handleImport im
433handleCommand (Decls l) = handleDecls l
433handleCommand (Decls l) = handleDecls l
434−handleCommand (LoadFile filePath) = do
434+handleCommand (LoadFile filePath) = whenFileExists filePath $ \absPath -> do
435− absPath <- psciIO $ expandTilde filePath
436− exists <- psciIO $ doesFileExist absPath
438− PSCI . lift $ modify (updateImportedFiles absPath)
435+ PSCI . lift $ modify (updateImportedFiles absPath)
439− m <- psciIO $ loadModule absPath
436+ m <- psciIO $ loadModule absPath
440− case m of
437+ case m of
441− Left err -> PSCI $ outputStrLn err
438+ Left err -> PSCI $ outputStrLn err
442− Right mods -> PSCI . lift $ modify (updateModules (map ((,) (Right absPath)) mods))
439+ Right mods -> PSCI . lift $ modify (updateModules (map ((,) (Right absPath)) mods))
443− else
440+handleCommand (LoadForeign filePath) = whenFileExists filePath $ \absPath -> do
444− PSCI . outputStrLn $ "Couldn't locate: " ++ filePath
441+ foreignsOrError <- psciIO . runMake $ do
442+ foreignFile <- makeIO (const (P.SimpleErrorWrapper $ P.CannotReadFile absPath)) (readFile absPath)
443+ P.parseForeignModulesFromFiles [(absPath, foreignFile)]
444+ case foreignsOrError of
445+ Left err -> PSCI $ outputStrLn $ P.prettyPrintMultipleErrors False err
446+ Right foreigns -> PSCI . lift $ modify (updateForeignFiles foreigns)
445handleCommand ResetState = do
447handleCommand ResetState = do
446 files <- psciImportedFilenames <$> PSCI (lift get)
448 files <- psciImportedFilenames <$> PSCI (lift get)
447 PSCI . lift . modify $ \st -> st
449 PSCI . lift . modify $ \st -> st
@@ -457,6 +459,14 @@ handleCommand (ShowInfo QueryLoaded) = handleShowLoadedModules
457handleCommand (ShowInfo QueryImport) = handleShowImportedModules
459handleCommand (ShowInfo QueryImport) = handleShowImportedModules
458handleCommand QuitPSCi = error "`handleCommand QuitPSCi` was called. This is a bug."
460handleCommand QuitPSCi = error "`handleCommand QuitPSCi` was called. This is a bug."
462+whenFileExists :: FilePath -> (FilePath -> PSCI ()) -> PSCI ()
463+whenFileExists filePath f = do
464+ absPath <- psciIO $ expandTilde filePath
465+ exists <- psciIO $ doesFileExist absPath
468+ else PSCI . outputStrLn $ "Couldn't locate: " ++ filePath
460loadUserConfig :: IO (Maybe [Command])
470loadUserConfig :: IO (Maybe [Command])
461loadUserConfig = do
471loadUserConfig = do
462 configFile <- (</> ".psci") <$> getCurrentDirectory
472 configFile <- (</> ".psci") <$> getCurrentDirectory