@@ -266,6 +266,17 @@ createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
266266 in
267267 P.Module moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
268268
269+-- |
270+-- Makes a volatile module to execute the current imports.
271+--
272+createTemporaryModuleForImports :: PSCiState -> P.Module
273+createTemporaryModuleForImports PSCiState{psciImportedModuleNames = imports} =
274+ let
275+ moduleName = P.ModuleName [P.ProperName "$PSCI"]
276+ importDecl m = P.ImportDeclaration m P.Unqualified Nothing
277+ in
278+ P.Module moduleName (importDecl `map` imports) Nothing
279+
269280modulesDir :: FilePath
270281modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
271282
@@ -291,6 +302,20 @@ handleDeclaration value = do
291302 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
292303 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
293304
305+-- |
306+-- Imports a module, preserving the initial state on failure.
307+--
308+handleImport :: P.ModuleName -> PSCI ()
309+handleImport moduleName = do
310+ s <- liftM (updateImports moduleName) $ PSCI $ lift get
311+ let m = createTemporaryModuleForImports s
312+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules s ++ [("$PSCI.purs", m)]) []
313+ case e of
314+ Left err -> PSCI $ outputStrLn err
315+ Right _ -> do
316+ PSCI $ lift $ put s
317+ return ()
318+
294319-- |
295320-- Takes a value and prints its type
296321--
@@ -350,7 +375,7 @@ getCommand singleLineMode = do
350375handleCommand :: Command -> PSCI ()
351376handleCommand (Expression val) = handleDeclaration val
352377handleCommand Help = PSCI $ outputStrLn helpMessage
353−handleCommand (Import moduleName) = PSCI $ lift $ modify (updateImports moduleName)
378+handleCommand (Import moduleName) = handleImport moduleName
354379handleCommand (Let l) = PSCI $ lift $ modify (updateLets l)
355380handleCommand (LoadFile filePath) = do
356381 absPath <- psciIO $ expandTilde filePath
@@ -438,4 +463,3 @@ termInfo = Cmd.defTI
438463
439464main :: IO ()
440465main = Cmd.run (term, termInfo)
441−