@@ -66,7 +66,7 @@ import qualified Language.PureScript.Declarations as D
66data PSCiState = PSCiState
66data PSCiState = PSCiState
67 { psciImportedFilenames :: [FilePath]
67 { psciImportedFilenames :: [FilePath]
68 , psciImportedModuleNames :: [P.ModuleName]
68 , psciImportedModuleNames :: [P.ModuleName]
69− , psciLoadedModules :: [(FilePath, P.Module)]
69+ , psciLoadedModules :: [(Maybe FilePath, P.Module)]
70 , psciLetBindings :: [P.Expr -> P.Expr]
70 , psciLetBindings :: [P.Expr -> P.Expr]
@@ -87,7 +87,7 @@ updateImports name st = st { psciImportedModuleNames = name : psciImportedModule
88-- Updates the state to have more loaded files.
88-- Updates the state to have more loaded files.
90−updateModules :: [(FilePath, P.Module)] -> PSCiState -> PSCiState
90+updateModules :: [(Maybe FilePath, P.Module)] -> PSCiState -> PSCiState
91updateModules modules st = st { psciLoadedModules = psciLoadedModules st ++ modules }
91updateModules modules st = st { psciLoadedModules = psciLoadedModules st ++ modules }
@@ -127,6 +127,17 @@ getHistoryFilename = do
127loadModule :: FilePath -> IO (Either String [P.Module])
127loadModule :: FilePath -> IO (Either String [P.Module])
128loadModule filename = either (Left . show) Right . P.runIndentParser filename P.parseModules <$> U.readFile filename
128loadModule filename = either (Left . show) Right . P.runIndentParser filename P.parseModules <$> U.readFile filename
131+-- Load all modules, including the Prelude
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
131-- Expands tilde in path.
142-- Expands tilde in path.
@@ -292,7 +303,7 @@ handleDeclaration :: P.Expr -> PSCI ()
292handleDeclaration value = do
303handleDeclaration value = do
293 st <- PSCI $ lift get
304 st <- PSCI $ lift get
294 let m = createTemporaryModule True st value
305 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)]) []
296 case e of
307 case e of
297 Left err -> PSCI $ outputStrLn err
308 Left err -> PSCI $ outputStrLn err
298 Right _ -> do
309 Right _ -> do
@@ -330,13 +341,13 @@ handleShowImportedModules = do
331handleImport :: P.ModuleName -> PSCI ()
342handleImport :: P.ModuleName -> PSCI ()
332handleImport moduleName = do
343handleImport moduleName = do
333− s <- liftM (updateImports moduleName) $ PSCI $ lift get
344+ st <- updateImports moduleName <$> PSCI (lift get)
334− let m = createTemporaryModuleForImports s
345+ let m = createTemporaryModuleForImports st
335− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules s ++ [("$PSCI.purs", m)]) []
346+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
336 case e of
347 case e of
337 Left err -> PSCI $ outputStrLn err
348 Left err -> PSCI $ outputStrLn err
338 Right _ -> do
349 Right _ -> do
339− PSCI $ lift $ put s
350+ PSCI $ lift $ put st
340 return ()
351 return ()
@@ -346,7 +357,7 @@ handleTypeOf :: P.Expr -> PSCI ()
346handleTypeOf value = do
357handleTypeOf value = do
347 st <- PSCI $ lift get
358 st <- PSCI $ lift get
348 let m = createTemporaryModule False st value
359 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)]) []
350 case e of
361 case e of
351 Left err -> PSCI $ outputStrLn err
362 Left err -> PSCI $ outputStrLn err
352 Right env' ->
363 Right env' ->
@@ -396,7 +407,7 @@ handleKindOf typ = do
396 st <- PSCI $ lift get
407 st <- PSCI $ lift get
397 let m = createTemporaryModuleForKind st typ
408 let m = createTemporaryModuleForKind st typ
398 mName = P.ModuleName [P.ProperName "$PSCI"]
409 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)]) []
400 case e of
411 case e of
401 Left err -> PSCI $ outputStrLn err
412 Left err -> PSCI $ outputStrLn err
402 Right env' ->
413 Right env' ->
@@ -442,15 +453,14 @@ handleCommand (LoadFile filePath) = do
442 m <- psciIO $ loadModule absPath
453 m <- psciIO $ loadModule absPath
443 case m of
454 case m of
444 Left err -> PSCI $ outputStrLn err
455 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))
447 PSCI . outputStrLn $ "Couldn't locate: " ++ filePath
458 PSCI . outputStrLn $ "Couldn't locate: " ++ filePath
448handleCommand Reset = do
459handleCommand Reset = do
449 files <- psciImportedFilenames <$> PSCI (lift get)
460 files <- psciImportedFilenames <$> PSCI (lift get)
450− filesAndModules <- mapM (\file -> fmap (fmap (map ((,) file))) . psciIO . loadModule $ file) files
461+ modulesOrFirstError <- psciIO $ loadAllModules files
451− let modulesOrFirstError = fmap concat $ sequence filesAndModules
452 case modulesOrFirstError of
462 case modulesOrFirstError of
453− Left err -> psciIO $ putStrLn err >> exitFailure
463+ Left err -> psciIO $ putStrLn (show err) >> exitFailure
454 Right modules -> PSCI . lift $ put (PSCiState files defaultImports modules [])
464 Right modules -> PSCI . lift $ put (PSCiState files defaultImports modules [])
455handleCommand (TypeOf val) = handleTypeOf val
465handleCommand (TypeOf val) = handleTypeOf val
456handleCommand (KindOf typ) = handleKindOf typ
466handleCommand (KindOf typ) = handleKindOf typ
@@ -489,15 +499,13 @@ loadUserConfig = do
489loop :: Bool -> [FilePath] -> IO ()
499loop :: Bool -> [FilePath] -> IO ()
490loop singleLineMode files = do
500loop singleLineMode files = do
491 config <- loadUserConfig
501 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
495 case modulesOrFirstError of
503 case modulesOrFirstError of
496− Left err -> putStrLn err >> exitFailure
504+ Left err -> putStrLn (show err) >> exitFailure
497 Right modules -> do
505 Right modules -> do
498 historyFilename <- getHistoryFilename
506 historyFilename <- getHistoryFilename
499− let settings = defaultSettings {historyFile = Just historyFilename}
507+ let settings = defaultSettings { historyFile = Just historyFilename }
500− flip evalStateT (PSCiState (preludeFilename : files) defaultImports modules []) . runInputT (setComplete completion settings) $ do
508+ flip evalStateT (PSCiState files defaultImports modules []) . runInputT (setComplete completion settings) $ do
501 outputStrLn prologueMessage
509 outputStrLn prologueMessage
502 traverse_ (mapM_ (runPSCI . handleCommand)) config
510 traverse_ (mapM_ (runPSCI . handleCommand)) config