on master help sign in
Add --repl [package] command line option

Checks the package, then starts a REPL using the main module listed in the package description. If no main module is given, the REPL is not started. (This means library packages will need a main module listed --- it has no other effect that to be the 'home' file for the REPL).

commit63d2989d133f60af34faac7b25bff59fa60fbbf6 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSun 2 Feb 2014, 22:06 (13 years ago) parent93c06b5
4 files changed+38−9
main/Main.hs+5−2 src/Idris/AbsSyntaxTree.hs+1 src/Idris/REPL.hs+5 src/Pkg/Package.hs+27−7
main/Main.hs+5−2
@@ -55,14 +55,17 @@ runIdris opts = do
5555 when (ShowLibdir `elem` opts) $ runIO showLibdir
5656 case opt getPkgCheck opts of
5757 [] -> return ()
58− fs -> do runIO $ mapM_ (checkPkg (WarnOnly `elem` opts)) fs
58+ fs -> do runIO $ mapM_ (checkPkg (WarnOnly `elem` opts) True) fs
5959 runIO $ exitWith ExitSuccess
6060 case opt getPkgClean opts of
6161 [] -> return ()
6262 fs -> do runIO $ mapM_ cleanPkg fs
6363 runIO $ exitWith ExitSuccess
6464 case opt getPkg opts of
65− [] -> idrisMain opts -- in Idris.REPL
65+ [] -> case opt getPkgREPL opts of
66+ [] -> idrisMain opts
67+ [f] -> replPkg f
68+ _ -> ifail "Too many packages"
6669 fs -> runIO $ mapM_ (buildPkg (WarnOnly `elem` opts)) fs
6770
6871usage = do putStrLn usagemsg
src/Idris/AbsSyntaxTree.hs+1
@@ -315,6 +315,7 @@ data Opt = Filename String
315315 | PkgInstall String
316316 | PkgClean String
317317 | PkgCheck String
318+ | PkgREPL String
318319 | WarnOnly
319320 | Pkg String
320321 | BCAsm String
src/Idris/REPL.hs+5
@@ -1019,6 +1019,7 @@ parseArgs ("--package":n:ns) = Pkg n : (parseArgs ns)
10191019parseArgs ("-p":n:ns) = Pkg n : (parseArgs ns)
10201020parseArgs ("--build":n:ns) = PkgBuild n : (parseArgs ns)
10211021parseArgs ("--install":n:ns) = PkgInstall n : (parseArgs ns)
1022+parseArgs ("--repl":n:ns) = PkgREPL n : (parseArgs ns)
10221023parseArgs ("--clean":n:ns) = PkgClean n : (parseArgs ns)
10231024parseArgs ("--checkpkg":n:ns) = PkgCheck n : (parseArgs ns)
10241025-- Misc Options
@@ -1336,6 +1337,10 @@ getPkgClean :: Opt -> Maybe String
13361337getPkgClean (PkgClean str) = Just str
13371338getPkgClean _ = Nothing
13381339
1340+getPkgREPL :: Opt -> Maybe String
1341+getPkgREPL (PkgREPL str) = Just str
1342+getPkgREPL _ = Nothing
1343+
13391344getPkgCheck :: Opt -> Maybe String
13401345getPkgCheck (PkgCheck str) = Just str
13411346getPkgCheck _ = Nothing
src/Pkg/Package.hs+27−7
@@ -69,9 +69,10 @@ buildPkg warnonly (install, fp)
6969-- This differs from build in that executables are not built, if the
7070-- package contains an executable.
7171checkPkg :: Bool -- ^ Show Warnings
72+ -> Bool -- ^ quit on failure
7273 -> FilePath -- ^ Path to ipkg file.
7374 -> IO ()
74−checkPkg warnonly fpath
75+checkPkg warnonly quit fpath
7576 = do pkgdesc <-parseDesc fpath
7677 ok <- mapM (testLib warnonly (pkgname pkgdesc)) (libdeps pkgdesc)
7778 when (and ok) $
@@ -81,12 +82,31 @@ checkPkg warnonly fpath
8182 res <- buildMods (NoREPL : Verbose : idris_opts pkgdesc)
8283 (modules pkgdesc)
8384 setCurrentDirectory dir
84− case res of
85− Nothing -> exitWith (ExitFailure 1)
86− Just res' -> do
87− case errLine res' of
88− Just _ -> exitWith (ExitFailure 1)
89− _ -> return ()
85+ when quit $ case res of
86+ Nothing -> exitWith (ExitFailure 1)
87+ Just res' -> do
88+ case errLine res' of
89+ Just _ -> exitWith (ExitFailure 1)
90+ _ -> return ()
91+
92+-- | Check a package and start a REPL
93+replPkg :: FilePath -> Idris ()
94+replPkg fp = do orig <- getIState
95+ runIO $ checkPkg False False fp
96+ pkgdesc <- runIO $ parseDesc fp -- bzzt, repetition!
97+ let opts = idris_opts pkgdesc
98+ let mod = idris_main pkgdesc
99+ let f = toPath (showCG mod)
100+ putIState orig
101+ dir <- runIO $ getCurrentDirectory
102+ runIO $ setCurrentDirectory $ dir </> sourcedir pkgdesc
103+
104+ if (f /= "")
105+ then idrisMain ((Filename f) : opts)
106+ else iputStrLn "Can't start REPL: no main module given"
107+ runIO $ setCurrentDirectory dir
108+
109+ where toPath n = foldl1' (</>) $ splitOn "." n
90110
91111-- | Clean Package build files
92112cleanPkg :: FilePath -- ^ Path to ipkg file.