@@ -22,7 +22,7 @@
2222module PSCi where
2323
2424import Data.Foldable (traverse_)
25−import Data.List (intercalate, nub, sort)
25+import Data.List (intercalate, nub, sort, isPrefixOf)
2626import Data.Traversable (traverse)
2727import Data.Version (showVersion)
2828import qualified Data.Map as M
@@ -59,6 +59,35 @@ import Parser (parseCommand)
5959import Completion (completion)
6060import Types
6161
62+-- | The name of the PSCI support module
63+supportModuleName :: P.ModuleName
64+supportModuleName = P.ModuleName [P.ProperName "$PSCI", P.ProperName "Support"]
65+
66+-- | Support module, contains code to evaluate terms
67+supportModule :: P.Module
68+supportModule =
69+ case P.parseModulesFromFiles id [("", code)] of
70+ Right [(_, P.Module cs _ ds exps)] -> P.Module cs supportModuleName ds exps
71+ _ -> error "Support module could not be parsed"
72+ where
73+ code :: String
74+ code = unlines
75+ [ "module S where"
76+ , ""
77+ , "import Console"
78+ , ""
79+ , "import Control.Monad.Eff"
80+ , "import Control.Monad.Eff.Unsafe"
81+ , ""
82+ , "class Eval a where"
83+ , " eval :: a -> Eff (console :: CONSOLE) Unit"
84+ , ""
85+ , "instance evalShow :: (Show a) => Eval a where"
86+ , " eval = print"
87+ , ""
88+ , "instance evalEff :: (Eval a) => Eval (Eff eff a) where"
89+ , " eval x = unsafeInterleaveEff x >>= eval"
90+ ]
6291
6392-- File helpers
6493-- |
@@ -202,7 +231,7 @@ instance P.MonadMake Make where
202231 writeTextFile path text = makeIO (const (P.CannotWriteFile path)) $ do
203232 mkdirp path
204233 writeFile path text
205− progress s = unless (s == "Compiling $PSCI") $ liftIO . putStrLn $ s
234+ progress s = unless ("Compiling $PSCI" `isPrefixOf` s) $ liftIO . putStrLn $ s
206235
207236mkdirp :: FilePath -> IO ()
208237mkdirp = createDirectoryIfMissing True . takeDirectory
@@ -214,8 +243,7 @@ createTemporaryModule :: Bool -> PSCiState -> P.Expr -> P.Module
214243createTemporaryModule exec PSCiState{psciImportedModules = imports, psciLetBindings = lets} val =
215244 let
216245 moduleName = P.ModuleName [P.ProperName "$PSCI"]
217− traceModule = P.ModuleName [P.ProperName "Debug", P.ProperName "Trace"]
218− trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
246+ trace = P.Var (P.Qualified (Just supportModuleName) (P.Ident "eval"))
219247 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
220248 itDecl = P.ValueDeclaration (P.Ident "it") P.Value [] $ Right val
221249 mainDecl = P.ValueDeclaration (P.Ident "main") P.Value [] $ Right mainValue
@@ -262,7 +290,7 @@ handleDeclaration val = do
262290 st <- PSCI $ lift get
263291 let m = createTemporaryModule True st val
264292 let nodeArgs = psciNodeFlags st ++ [indexFile]
265− e <- psciIO . runMake $ P.make modulesDir (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
293+ e <- psciIO . runMake $ P.make modulesDir (psciLoadedModules st ++ [(Left P.RebuildAlways, supportModule), (Left P.RebuildAlways, m)]) []
266294 case e of
267295 Left errs -> printErrors errs
268296 Right _ -> do
@@ -481,6 +509,10 @@ loadUserConfig = do
481509 else
482510 return Nothing
483511
512+-- | Checks if the Console module is defined
513+consoleIsDefined :: [P.Module] -> Bool
514+consoleIsDefined = any ((== P.ModuleName [P.ProperName "Console"]) . P.getModuleName)
515+
484516-- |
485517-- The PSCI main loop.
486518--
@@ -496,6 +528,10 @@ loop PSCiOptions{..} = do
496528 flip evalStateT (PSCiState psciInputFile defaultImports modules [] psciInputNodeFlags) . runInputT (setComplete completion settings) $ do
497529 outputStrLn prologueMessage
498530 traverse_ (mapM_ (runPSCI . handleCommand)) config
531+ unless (consoleIsDefined (map snd modules)) . outputStrLn $ unlines
532+ [ "PSCi requires the purescript-console module to be installed."
533+ , "For help getting started, visit http://wiki.purescript.org/PSCi"
534+ ]
499535 go
500536 where
501537 go :: InputT (StateT PSCiState IO) ()