@@ -9,69 +9,102 @@ import Idris.Error
9import Idris.Delaborate
9import Idris.Delaborate
10import Idris.Compiler
10import Idris.Compiler
11import Idris.Prover
11import Idris.Prover
13import Core.Evaluate
14import Core.Evaluate
14import Core.ProofShell
15import Core.ProofShell
15import Core.TT
16import Core.TT
17import System.Console.Readline
18import System.Console.Readline
19+import System.FilePath
20+import System.Environment
18import Control.Monad
22import Control.Monad
19import Control.Monad.State
23import Control.Monad.State
20import Data.List
24import Data.List
22−repl :: String -> Idris ()
27+repl :: IState -> [FilePath] -> Idris ()
23−repl prompt
28+repl orig mods
29+ = do let prompt = mkPrompt mods
24− = do x <- lift $ readline (prompt ++ "> ")
30+ x <- lift $ readline (prompt ++ "> ")
26− Nothing -> repl prompt
32+ Nothing -> repl orig mods
27 Just input -> do lift $ addHistory input
33 Just input -> do lift $ addHistory input
28− continue <- processInput input
34+ ms <- processInput input orig mods
29− when continue (repl prompt)
35+ case ms of
36+ Just mods -> repl orig mods
40+mkPrompt [x] = "*" ++ dropExtension x
41+mkPrompt (x:xs) = "*" ++ dropExtension x ++ " " ++ mkPrompt xs
31−processInput :: String -> Idris Bool
43+processInput :: String -> IState -> [FilePath] -> Idris (Maybe [FilePath])
32−processInput cmd
44+processInput cmd orig inputs
33 = do i <- get
45 = do i <- get
46+ let fn = case inputs of
34 case parseCmd i cmd of
49 case parseCmd i cmd of
35 Left err -> do lift $ print err
50 Left err -> do lift $ print err
36− return True
51+ return (Just inputs)
52+ Right Reload -> do put orig
54+ mods <- mapM loadModule inputs
37 Right Quit -> do iputStrLn "Bye bye"
56 Right Quit -> do iputStrLn "Bye bye"
38− return False
57+ return Nothing
39− Right cmd -> do idrisCatch (process cmd)
58+ Right cmd -> do idrisCatch (process fn cmd)
40 (\e -> iputStrLn (report e))
59 (\e -> iputStrLn (report e))
41− return True
60+ return (Just inputs)
43−process :: Command -> Idris ()
62+process :: FilePath -> Command -> Idris ()
44−process Help
63+process _ Help
45 = iputStrLn "At some point I'll write some help text. Thanks for asking though."
64 = iputStrLn "At some point I'll write some help text. Thanks for asking though."
65+process "" Edit = iputStrLn "Nothing to edit"
68+ env <- lift $ getEnvironment
69+ let editor = getEditor env
70+ let line = case errLine i of
71+ Just l -> " +" ++ show l ++ " "
73+ let cmd = editor ++ line ++ f
76+ where getEditor env | Just ed <- lookup "EDITOR" env = ed
77+ | Just ed <- lookup "VISUAL" env = ed
46−process (Eval t) = do (tm, ty) <- elabVal toplevel t
79+process _ (Eval t) = do (tm, ty) <- elabVal toplevel t
47− ctxt <- getContext
80+ ctxt <- getContext
48− ist <- get
81+ ist <- get
49− let tm' = normaliseC ctxt [] tm
82+ let tm' = normaliseC ctxt [] tm
50− let ty' = normaliseC ctxt [] ty
83+ let ty' = normaliseC ctxt [] ty
51− logLvl 3 $ "Raw: " ++ show (tm', ty')
84+ logLvl 3 $ "Raw: " ++ show (tm', ty')
52− iputStrLn (show (delab ist tm') ++ " : " ++
85+ iputStrLn (show (delab ist tm') ++ " : " ++
53− show (delab ist ty'))
86+ show (delab ist ty'))
54−process (Spec t) = do (tm, ty) <- elabVal toplevel t
87+process _ (Spec t) = do (tm, ty) <- elabVal toplevel t
55− ctxt <- getContext
88+ ctxt <- getContext
56− ist <- get
89+ ist <- get
57− let tm' = specialise ctxt (idris_statics ist) tm
90+ let tm' = specialise ctxt (idris_statics ist) tm
58− iputStrLn (show (delab ist tm'))
91+ iputStrLn (show (delab ist tm'))
59−process (Prove n) = prover n
92+process _ (Prove n) = prover n
60−process (HNF t) = do (tm, ty) <- elabVal toplevel t
93+process _ (HNF t) = do (tm, ty) <- elabVal toplevel t
61− ctxt <- getContext
94+ ctxt <- getContext
62− ist <- get
95+ ist <- get
63− let tm' = hnf ctxt [] tm
96+ let tm' = hnf ctxt [] tm
64− iputStrLn (show (delab ist tm'))
97+ iputStrLn (show (delab ist tm'))
65−process TTShell = do ist <- get
98+process _ TTShell = do ist <- get
66− let shst = initState (tt_ctxt ist)
99+ let shst = initState (tt_ctxt ist)
67− shst' <- lift $ runShell shst
100+ shst' <- lift $ runShell shst
68− return ()
101+ return ()
69−process (Compile f) = do compile f
102+process _ (Compile f) = do compile f
70−process (LogLvl i) = setLogLevel i
103+process _ (LogLvl i) = setLogLevel i
71−process Metavars = do ist <- get
104+process _ Metavars = do ist <- get
72− let mvs = idris_metavars ist \\ primDefs
105+ let mvs = idris_metavars ist \\ primDefs
73− case mvs of
106+ case mvs of
74− [] -> iputStrLn "No global metavariables to solve"
107+ [] -> iputStrLn "No global metavariables to solve"
75− _ -> iputStrLn $ "Global metavariables:\n\t" ++ show mvs
108+ _ -> iputStrLn $ "Global metavariables:\n\t" ++ show mvs
76−process NOP = return ()
109+process _ NOP = return ()