git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #635 from Bogdanp/master
54c1d90Phil Freeman
psci/Main.hs+26−2
@@ -266,6 +266,17 @@ createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
266 in
266 in
267 P.Module moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
267 P.Module moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
268
268
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+
269modulesDir :: FilePath
280modulesDir :: FilePath
270modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
281modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
271
282
@@ -291,6 +302,20 @@ handleDeclaration value = do
291 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
302 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
292 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
303 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
293
304
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+
294-- |
319-- |
295-- Takes a value and prints its type
320-- Takes a value and prints its type
296--
321--
@@ -350,7 +375,7 @@ getCommand singleLineMode = do
350handleCommand :: Command -> PSCI ()
375handleCommand :: Command -> PSCI ()
351handleCommand (Expression val) = handleDeclaration val
376handleCommand (Expression val) = handleDeclaration val
352handleCommand Help = PSCI $ outputStrLn helpMessage
377handleCommand Help = PSCI $ outputStrLn helpMessage
353−handleCommand (Import moduleName) = PSCI $ lift $ modify (updateImports moduleName)
378+handleCommand (Import moduleName) = handleImport moduleName
354handleCommand (Let l) = PSCI $ lift $ modify (updateLets l)
379handleCommand (Let l) = PSCI $ lift $ modify (updateLets l)
355handleCommand (LoadFile filePath) = do
380handleCommand (LoadFile filePath) = do
356 absPath <- psciIO $ expandTilde filePath
381 absPath <- psciIO $ expandTilde filePath
@@ -438,4 +463,3 @@ termInfo = Cmd.defTI
438
463
439main :: IO ()
464main :: IO ()
440main = Cmd.run (term, termInfo)
465main = Cmd.run (term, termInfo)
441−