@@ -66,7 +66,7 @@ import qualified Language.PureScript.Declarations as D
6666data PSCiState = PSCiState
6767 { psciImportedFilenames :: [FilePath]
6868 , psciImportedModuleNames :: [P.ModuleName]
69− , psciLoadedModules :: [(FilePath, P.Module)]
69+ , psciLoadedModules :: [(Maybe FilePath, P.Module)]
7070 , psciLetBindings :: [P.Expr -> P.Expr]
7171 }
7272
@@ -87,7 +87,7 @@ updateImports name st = st { psciImportedModuleNames = name : psciImportedModule
8787-- |
8888-- Updates the state to have more loaded files.
8989--
90−updateModules :: [(FilePath, P.Module)] -> PSCiState -> PSCiState
90+updateModules :: [(Maybe FilePath, P.Module)] -> PSCiState -> PSCiState
9191updateModules modules st = st { psciLoadedModules = psciLoadedModules st ++ modules }
9292
9393-- |
@@ -127,6 +127,17 @@ getHistoryFilename = do
127127loadModule :: FilePath -> IO (Either String [P.Module])
128128loadModule filename = either (Left . show) Right . P.runIndentParser filename P.parseModules <$> U.readFile filename
129129
130+-- |
131+-- Load all modules, including the Prelude
132+--
133+loadAllModules :: [FilePath] -> IO (Either ParseError [(Maybe FilePath, P.Module)])
134+loadAllModules files = do
135+ filesAndContent <- forM files $ \filename -> do
136+ content <- U.readFile filename
137+ return (Just filename, content)
138+ return $ P.parseModulesFromFiles $ (Nothing, P.prelude) : filesAndContent
139+
140+
130141-- |
131142-- Expands tilde in path.
132143--
@@ -292,7 +303,7 @@ handleDeclaration :: P.Expr -> PSCI ()
292303handleDeclaration value = do
293304 st <- PSCI $ lift get
294305 let m = createTemporaryModule True st value
295− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)]) []
306+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
296307 case e of
297308 Left err -> PSCI $ outputStrLn err
298309 Right _ -> do
@@ -330,13 +341,13 @@ handleShowImportedModules = do
330341--
331342handleImport :: P.ModuleName -> PSCI ()
332343handleImport moduleName = do
333− s <- liftM (updateImports moduleName) $ PSCI $ lift get
334− let m = createTemporaryModuleForImports s
335− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules s ++ [("$PSCI.purs", m)]) []
344+ st <- updateImports moduleName <$> PSCI (lift get)
345+ let m = createTemporaryModuleForImports st
346+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
336347 case e of
337348 Left err -> PSCI $ outputStrLn err
338349 Right _ -> do
339− PSCI $ lift $ put s
350+ PSCI $ lift $ put st
340351 return ()
341352
342353-- |
@@ -346,7 +357,7 @@ handleTypeOf :: P.Expr -> PSCI ()
346357handleTypeOf value = do
347358 st <- PSCI $ lift get
348359 let m = createTemporaryModule False st value
349− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)]) []
360+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
350361 case e of
351362 Left err -> PSCI $ outputStrLn err
352363 Right env' ->
@@ -396,7 +407,7 @@ handleKindOf typ = do
396407 st <- PSCI $ lift get
397408 let m = createTemporaryModuleForKind st typ
398409 mName = P.ModuleName [P.ProperName "$PSCI"]
399− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("$PSCI.purs", m)]) []
410+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
400411 case e of
401412 Left err -> PSCI $ outputStrLn err
402413 Right env' ->
@@ -442,15 +453,14 @@ handleCommand (LoadFile filePath) = do
442453 m <- psciIO $ loadModule absPath
443454 case m of
444455 Left err -> PSCI $ outputStrLn err
445− Right mods -> PSCI . lift $ modify (updateModules (map ((,) absPath) mods))
456+ Right mods -> PSCI . lift $ modify (updateModules (map ((,) (Just absPath)) mods))
446457 else
447458 PSCI . outputStrLn $ "Couldn't locate: " ++ filePath
448459handleCommand Reset = do
449460 files <- psciImportedFilenames <$> PSCI (lift get)
450− filesAndModules <- mapM (\file -> fmap (fmap (map ((,) file))) . psciIO . loadModule $ file) files
451− let modulesOrFirstError = fmap concat $ sequence filesAndModules
461+ modulesOrFirstError <- psciIO $ loadAllModules files
452462 case modulesOrFirstError of
453− Left err -> psciIO $ putStrLn err >> exitFailure
463+ Left err -> psciIO $ putStrLn (show err) >> exitFailure
454464 Right modules -> PSCI . lift $ put (PSCiState files defaultImports modules [])
455465handleCommand (TypeOf val) = handleTypeOf val
456466handleCommand (KindOf typ) = handleKindOf typ
@@ -489,15 +499,13 @@ loadUserConfig = do
489499loop :: Bool -> [FilePath] -> IO ()
490500loop singleLineMode files = do
491501 config <- loadUserConfig
492− preludeFilename <- P.preludeFilename
493− filesAndModules <- mapM (\file -> fmap (fmap (map ((,) file))) . loadModule $ file) (preludeFilename : files)
494− let modulesOrFirstError = fmap concat $ sequence filesAndModules
502+ modulesOrFirstError <- loadAllModules files
495503 case modulesOrFirstError of
496− Left err -> putStrLn err >> exitFailure
504+ Left err -> putStrLn (show err) >> exitFailure
497505 Right modules -> do
498506 historyFilename <- getHistoryFilename
499− let settings = defaultSettings {historyFile = Just historyFilename}
500− flip evalStateT (PSCiState (preludeFilename : files) defaultImports modules []) . runInputT (setComplete completion settings) $ do
507+ let settings = defaultSettings { historyFile = Just historyFilename }
508+ flip evalStateT (PSCiState files defaultImports modules []) . runInputT (setComplete completion settings) $ do
501509 outputStrLn prologueMessage
502510 traverse_ (mapM_ (runPSCI . handleCommand)) config
503511 go