@@ -42,7 +42,7 @@ import Idris.Elab.Value
42import Version_idris (gitHash)
42import Version_idris (gitHash)
43import Util.System
43import Util.System
44import Util.DynamicLinker
44import Util.DynamicLinker
45−import Util.Net (listenOnLocalhost)
45+import Util.Net (listenOnLocalhost, listenOnLocalhostAnyPort)
46import Util.Pretty hiding ((</>))
46import Util.Pretty hiding ((</>))
48import Idris.Core.Evaluate
48import Idris.Core.Evaluate
@@ -93,6 +93,8 @@ import Data.Word (Word)
93import Data.Either (partitionEithers)
93import Data.Either (partitionEithers)
94import Control.DeepSeq
94import Control.DeepSeq
96+import Numeric ( readHex )
96import Debug.Trace
98import Debug.Trace
98-- | Run the REPL
100-- | Run the REPL
@@ -151,7 +153,7 @@ startServer orig fn_in = do tid <- runIO $ forkOS serverLoop
151 -- TODO: option for port number
153 -- TODO: option for port number
152 serverLoop = withSocketsDo $
154 serverLoop = withSocketsDo $
153 do sock <- listenOnLocalhost $ PortNumber 4294
155 do sock <- listenOnLocalhost $ PortNumber 4294
154− loop fn orig sock
156+ loop fn orig { idris_colourRepl = False } sock
156 fn = case fn_in of
158 fn = case fn_in of
157 (f:_) -> f
159 (f:_) -> f
@@ -161,7 +163,10 @@ startServer orig fn_in = do tid <- runIO $ forkOS serverLoop
161 = do (h,_,_) <- accept sock
163 = do (h,_,_) <- accept sock
162 hSetEncoding h utf8
164 hSetEncoding h utf8
163 cmd <- hGetLine h
165 cmd <- hGetLine h
166+ let isth = case idris_outputmode ist of
167+ RawOutput _ -> ist {idris_outputmode = RawOutput h}
168+ IdeSlave n _ -> ist {idris_outputmode = IdeSlave n h}
164− (ist', fn) <- processNetCmd orig ist h fn cmd
169+ (ist', fn) <- processNetCmd orig isth h fn cmd
166 loop fn ist' sock
171 loop fn ist' sock
@@ -187,12 +192,18 @@ processNetCmd orig i h fn cmd
187 setOutH h
192 setOutH h
188 setQuiet True
193 setQuiet True
189 setVerbose False
194 setVerbose False
190− mods <- loadInputs h [f] toline
195+ mods <- loadInputs [f] toline
191 ist <- getIState
196 ist <- getIState
192 return (ist, f)
197 return (ist, f)
193− processNet fn c = do process h fn c
198+ processNet fn c = do process fn c
194 ist <- getIState
199 ist <- getIState
195 return (ist, fn)
200 return (ist, fn)
201+ setOutH :: Handle -> Idris ()
204+ putIState $ case idris_outputmode ist of
205+ RawOutput _ -> ist {idris_outputmode = RawOutput h}
206+ IdeSlave n _ -> ist {idris_outputmode = IdeSlave n h}
197-- | Run a command on the server on localhost
208-- | Run a command on the server on localhost
198runClient :: String -> IO ()
209runClient :: String -> IO ()
@@ -208,55 +219,73 @@ runClient str = withSocketsDo $ do
208 else do l <- hGetLine h
219 else do l <- hGetLine h
209 hGetResp (acc ++ l ++ "\n") h
220 hGetResp (acc ++ l ++ "\n") h
222+initIdeslaveSocket :: IO Handle
223+initIdeslaveSocket = do
224+ (sock, port) <- listenOnLocalhostAnyPort
225+ putStrLn $ show port
226+ (h, _, _) <- accept sock
211-- | Run the IdeSlave
230-- | Run the IdeSlave
212−ideslaveStart :: IState -> [FilePath] -> Idris ()
231+ideslaveStart :: Bool -> IState -> [FilePath] -> Idris ()
213−ideslaveStart orig mods
232+ideslaveStart s orig mods
233+ = do h <- runIO $ if s then initIdeslaveSocket else return stdout
214− = do i <- getIState
235+ i <- getIState
215 case idris_outputmode i of
236 case idris_outputmode i of
216− IdeSlave n ->
237+ IdeSlave n h ->
217− when (mods /= []) (do isetPrompt (mkPrompt mods))
238+ do runIO $ hPutStrLn h $ IdeSlave.convSExp "protocol-version" IdeSlave.ideSlaveEpoch n
240+ a:_ -> runIdeSlaveCommand h n i "" [] (IdeSlave.LoadFile a Nothing)
218− ideslave orig mods
242+ ideslave h orig mods
221−ideslave :: IState -> [FilePath] -> Idris ()
244+ideslave :: Handle -> IState -> [FilePath] -> Idris ()
222−ideslave orig mods
245+ideslave h orig mods
223 = do idrisCatch
246 = do idrisCatch
224− (do l <- runIO $ getLine
247+ (do let inh = if h == stdout then stdin else h
248+ len' <- runIO $ IdeSlave.getLen inh
250+ Left err -> ierror err
252+ l <- runIO $ IdeSlave.getNChar inh len ""
225 (sexp, id) <- case IdeSlave.parseMessage l of
253 (sexp, id) <- case IdeSlave.parseMessage l of
226 Left err -> ierror err
254 Left err -> ierror err
227 Right (sexp, id) -> return (sexp, id)
255 Right (sexp, id) -> return (sexp, id)
228 i <- getIState
256 i <- getIState
229− putIState $ i { idris_outputmode = (IdeSlave id) }
257+ putIState $ i { idris_outputmode = (IdeSlave id h) }
230 idrisCatch -- to report correct id back!
258 idrisCatch -- to report correct id back!
231 (do let fn = case mods of
259 (do let fn = case mods of
232 (f:_) -> f
260 (f:_) -> f
234 case IdeSlave.sexpToCommand sexp of
262 case IdeSlave.sexpToCommand sexp of
235− Just cmd -> runIdeSlaveCommand id orig fn mods cmd
263+ Just cmd -> runIdeSlaveCommand h id orig fn mods cmd
236 Nothing -> iPrintError "did not understand" )
264 Nothing -> iPrintError "did not understand" )
237 (\e -> do iPrintError $ show e))
265 (\e -> do iPrintError $ show e))
238 (\e -> do iPrintError $ show e)
266 (\e -> do iPrintError $ show e)
239− ideslave orig mods
267+ ideslave h orig mods
241-- | Run IDESlave commands
269-- | Run IDESlave commands
270+runIdeSlaveCommand :: Handle -- ^^ The handle for communication
242−runIdeSlaveCommand :: Integer -- ^^ The continuation ID for the client
271+ -> Integer -- ^^ The continuation ID for the client
243 -> IState -- ^^ The original IState
272 -> IState -- ^^ The original IState
244 -> FilePath -- ^^ The current open file
273 -> FilePath -- ^^ The current open file
245 -> [FilePath] -- ^^ The currently loaded modules
274 -> [FilePath] -- ^^ The currently loaded modules
246 -> IdeSlave.IdeSlaveCommand -- ^^ The command to process
275 -> IdeSlave.IdeSlaveCommand -- ^^ The command to process
247 -> Idris ()
276 -> Idris ()
248−runIdeSlaveCommand id orig fn mods (IdeSlave.Interpret cmd) =
277+runIdeSlaveCommand h id orig fn mods (IdeSlave.Interpret cmd) =
249 do c <- colourise
278 do c <- colourise
250 i <- getIState
279 i <- getIState
251 case parseCmd i "(input)" cmd of
280 case parseCmd i "(input)" cmd of
252− Failure err -> iPrintError $ show (fixColour c err)
281+ Failure err -> iPrintError $ show (fixColour False err)
253 Success (Prove n') ->
282 Success (Prove n') ->
254 idrisCatch
283 idrisCatch
255− (do process stdout fn (Prove n')
284+ (do process fn (Prove n')
256 isetPrompt (mkPrompt mods)
285 isetPrompt (mkPrompt mods)
257 case idris_outputmode i of
286 case idris_outputmode i of
258− IdeSlave n -> -- signal completion of proof to ide
287+ IdeSlave n h -> -- signal completion of proof to ide
259− runIO . hPutStrLn stdout $
288+ runIO . hPutStrLn h $
260 IdeSlave.convSExp "return"
289 IdeSlave.convSExp "return"
261 (IdeSlave.SymbolAtom "ok", "")
290 (IdeSlave.SymbolAtom "ok", "")
@@ -264,26 +293,26 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.Interpret cmd) =
264 (\e -> do ist <- getIState
293 (\e -> do ist <- getIState
265 isetPrompt (mkPrompt mods)
294 isetPrompt (mkPrompt mods)
266 case idris_outputmode i of
295 case idris_outputmode i of
267− IdeSlave n ->
296+ IdeSlave n h ->
268− runIO . hPutStrLn stdout $
297+ runIO . hPutStrLn h $
269 IdeSlave.convSExp "abandon-proof" "Abandoned" n
298 IdeSlave.convSExp "abandon-proof" "Abandoned" n
270 _ -> return ()
299 _ -> return ()
271− ihRenderError stdout $ pprintErr ist e)
300+ iRenderError $ pprintErr ist e)
272 Success cmd -> idrisCatch
301 Success cmd -> idrisCatch
273 (ideslaveProcess fn cmd)
302 (ideslaveProcess fn cmd)
274− (\e -> getIState >>= ihRenderError stdout . flip pprintErr e)
303+ (\e -> getIState >>= iRenderError . flip pprintErr e)
275−runIdeSlaveCommand id orig fn mods (IdeSlave.REPLCompletions str) =
304+runIdeSlaveCommand h id orig fn mods (IdeSlave.REPLCompletions str) =
276 do (unused, compls) <- replCompletion (reverse str, "")
305 do (unused, compls) <- replCompletion (reverse str, "")
277 let good = IdeSlave.SexpList [IdeSlave.SymbolAtom "ok",
306 let good = IdeSlave.SexpList [IdeSlave.SymbolAtom "ok",
278 IdeSlave.toSExp (map replacement compls,
307 IdeSlave.toSExp (map replacement compls,
279 reverse unused)]
308 reverse unused)]
280− runIO $ putStrLn $ IdeSlave.convSExp "return" good id
309+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" good id
281−runIdeSlaveCommand id orig fn mods (IdeSlave.LoadFile filename toline) =
310+runIdeSlaveCommand h id orig fn mods (IdeSlave.LoadFile filename toline) =
282 do i <- getIState
311 do i <- getIState
284 putIState (orig { idris_options = idris_options i,
313 putIState (orig { idris_options = idris_options i,
285− idris_outputmode = (IdeSlave id) })
314+ idris_outputmode = (IdeSlave id h) })
286− loadInputs stdout [filename] toline
315+ loadInputs [filename] toline
287 isetPrompt (mkPrompt [filename])
316 isetPrompt (mkPrompt [filename])
288 -- Report either success or failure
317 -- Report either success or failure
289 i <- getIState
318 i <- getIState
@@ -293,45 +322,45 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.LoadFile filename toline) =
293 (\fc -> IdeSlave.SexpList [IdeSlave.SymbolAtom "ok",
322 (\fc -> IdeSlave.SexpList [IdeSlave.SymbolAtom "ok",
294 IdeSlave.toSExp fc])
323 IdeSlave.toSExp fc])
295 (idris_parsedSpan i)
324 (idris_parsedSpan i)
296− in runIO . putStrLn $ IdeSlave.convSExp "return" msg id
325+ in runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
297 Just x -> iPrintError $ "didn't load " ++ filename
326 Just x -> iPrintError $ "didn't load " ++ filename
298− ideslave orig [filename]
327+ ideslave h orig [filename]
299−runIdeSlaveCommand id orig fn mods (IdeSlave.TypeOf name) =
328+runIdeSlaveCommand h id orig fn mods (IdeSlave.TypeOf name) =
300 case splitName name of
329 case splitName name of
301 Left err -> iPrintError err
330 Left err -> iPrintError err
302− Right n -> process stdout "(ideslave)"
331+ Right n -> process "(ideslave)"
303 (Check (PRef (FC "(ideslave)" (0,0) (0,0)) n))
332 (Check (PRef (FC "(ideslave)" (0,0) (0,0)) n))
304 where splitName :: String -> Either String Name
333 where splitName :: String -> Either String Name
305 splitName s = case reverse $ splitOn "." s of
334 splitName s = case reverse $ splitOn "." s of
306 [] -> Left ("Didn't understand name '" ++ s ++ "'")
335 [] -> Left ("Didn't understand name '" ++ s ++ "'")
307 [n] -> Right $ sUN n
336 [n] -> Right $ sUN n
308 (n:ns) -> Right $ sNS (sUN n) ns
337 (n:ns) -> Right $ sNS (sUN n) ns
309−runIdeSlaveCommand id orig fn mods (IdeSlave.DocsFor name) =
338+runIdeSlaveCommand h id orig fn mods (IdeSlave.DocsFor name) =
310 case parseConst orig name of
339 case parseConst orig name of
311− Success c -> process stdout "(ideslave)" (DocStr (Right c))
340+ Success c -> process "(ideslave)" (DocStr (Right c))
312 Failure _ ->
341 Failure _ ->
313 case splitName name of
342 case splitName name of
314 Left err -> iPrintError err
343 Left err -> iPrintError err
315− Right n -> process stdout "(ideslave)" (DocStr (Left n))
344+ Right n -> process "(ideslave)" (DocStr (Left n))
316−runIdeSlaveCommand id orig fn mods (IdeSlave.CaseSplit line name) =
345+runIdeSlaveCommand h id orig fn mods (IdeSlave.CaseSplit line name) =
317− process stdout fn (CaseSplitAt False line (sUN name))
346+ process fn (CaseSplitAt False line (sUN name))
318−runIdeSlaveCommand id orig fn mods (IdeSlave.AddClause line name) =
347+runIdeSlaveCommand h id orig fn mods (IdeSlave.AddClause line name) =
319− process stdout fn (AddClauseFrom False line (sUN name))
348+ process fn (AddClauseFrom False line (sUN name))
320−runIdeSlaveCommand id orig fn mods (IdeSlave.AddProofClause line name) =
349+runIdeSlaveCommand h id orig fn mods (IdeSlave.AddProofClause line name) =
321− process stdout fn (AddProofClauseFrom False line (sUN name))
350+ process fn (AddProofClauseFrom False line (sUN name))
322−runIdeSlaveCommand id orig fn mods (IdeSlave.AddMissing line name) =
351+runIdeSlaveCommand h id orig fn mods (IdeSlave.AddMissing line name) =
323− process stdout fn (AddMissing False line (sUN name))
352+ process fn (AddMissing False line (sUN name))
324−runIdeSlaveCommand id orig fn mods (IdeSlave.MakeWithBlock line name) =
353+runIdeSlaveCommand h id orig fn mods (IdeSlave.MakeWithBlock line name) =
325− process stdout fn (MakeWith False line (sUN name))
354+ process fn (MakeWith False line (sUN name))
326−runIdeSlaveCommand id orig fn mods (IdeSlave.ProofSearch r line name hints depth) =
355+runIdeSlaveCommand h id orig fn mods (IdeSlave.ProofSearch r line name hints depth) =
327− doProofSearch stdout fn False r line (sUN name) (map sUN hints) depth
356+ doProofSearch fn False r line (sUN name) (map sUN hints) depth
328−runIdeSlaveCommand id orig fn mods (IdeSlave.MakeLemma line name) =
357+runIdeSlaveCommand h id orig fn mods (IdeSlave.MakeLemma line name) =
329 case splitName name of
358 case splitName name of
330 Left err -> iPrintError err
359 Left err -> iPrintError err
331− Right n -> process stdout fn (MakeLemma False line n)
360+ Right n -> process fn (MakeLemma False line n)
332−runIdeSlaveCommand id orig fn mods (IdeSlave.Apropos a) =
361+runIdeSlaveCommand h id orig fn mods (IdeSlave.Apropos a) =
333− process stdout fn (Apropos a)
362+ process fn (Apropos a)
334−runIdeSlaveCommand id orig fn mods (IdeSlave.GetOpts) =
363+runIdeSlaveCommand h id orig fn mods (IdeSlave.GetOpts) =
335 do ist <- getIState
364 do ist <- getIState
336 let opts = idris_options ist
365 let opts = idris_options ist
337 let impshow = opt_showimp opts
366 let impshow = opt_showimp opts
@@ -339,16 +368,16 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.GetOpts) =
339 let options = (IdeSlave.SymbolAtom "ok",
368 let options = (IdeSlave.SymbolAtom "ok",
340 [(IdeSlave.SymbolAtom "show-implicits", impshow),
369 [(IdeSlave.SymbolAtom "show-implicits", impshow),
341 (IdeSlave.SymbolAtom "error-context", errCtxt)])
370 (IdeSlave.SymbolAtom "error-context", errCtxt)])
342− runIO . putStrLn $ IdeSlave.convSExp "return" options id
371+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" options id
343−runIdeSlaveCommand id orig fn mods (IdeSlave.SetOpt IdeSlave.ShowImpl b) =
372+runIdeSlaveCommand h id orig fn mods (IdeSlave.SetOpt IdeSlave.ShowImpl b) =
344 do setImpShow b
373 do setImpShow b
345 let msg = (IdeSlave.SymbolAtom "ok", b)
374 let msg = (IdeSlave.SymbolAtom "ok", b)
346− runIO . putStrLn $ IdeSlave.convSExp "return" msg id
375+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
347−runIdeSlaveCommand id orig fn mods (IdeSlave.SetOpt IdeSlave.ErrContext b) =
376+runIdeSlaveCommand h id orig fn mods (IdeSlave.SetOpt IdeSlave.ErrContext b) =
348 do setErrContext b
377 do setErrContext b
349 let msg = (IdeSlave.SymbolAtom "ok", b)
378 let msg = (IdeSlave.SymbolAtom "ok", b)
350− runIO . putStrLn $ IdeSlave.convSExp "return" msg id
379+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
351−runIdeSlaveCommand id orig fn mods (IdeSlave.Metavariables cols) =
380+runIdeSlaveCommand h id orig fn mods (IdeSlave.Metavariables cols) =
352 do ist <- getIState
381 do ist <- getIState
353 let mvs = reverse $ map fst (idris_metavars ist) \\ primDefs
382 let mvs = reverse $ map fst (idris_metavars ist) \\ primDefs
354 let ppo = ppOptionIst ist
383 let ppo = ppOptionIst ist
@@ -364,7 +393,7 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.Metavariables cols) =
364 (zip bnds hs),
393 (zip bnds hs),
365 render ist bnd c pc))
394 render ist bnd c pc))
367− runIO . putStrLn $
396+ runIO . hPutStrLn h $
368 IdeSlave.convSExp "return" (IdeSlave.SymbolAtom "ok", mvOutput) id
397 IdeSlave.convSExp "return" (IdeSlave.SymbolAtom "ok", mvOutput) id
369 where mapPair f g xs = zip (map (f . fst) xs) (map (g . snd) xs)
398 where mapPair f g xs = zip (map (f . fst) xs) (map (g . snd) xs)
370 mapSnd f xs = zip (map fst xs) (map (f . snd) xs)
399 mapSnd f xs = zip (map fst xs) (map (f . snd) xs)
@@ -409,32 +438,32 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.Metavariables cols) =
409 let (out, spans) = render ist bnd t pt in
438 let (out, spans) = render ist bnd t pt in
410 (show n , out, spans)
439 (show n , out, spans)
412−runIdeSlaveCommand id orig fn mods (IdeSlave.WhoCalls n) =
441+runIdeSlaveCommand h id orig fn mods (IdeSlave.WhoCalls n) =
413 case splitName n of
442 case splitName n of
414 Left err -> iPrintError err
443 Left err -> iPrintError err
415 Right n -> do calls <- whoCalls n
444 Right n -> do calls <- whoCalls n
416 ist <- getIState
445 ist <- getIState
417 let msg = (IdeSlave.SymbolAtom "ok",
446 let msg = (IdeSlave.SymbolAtom "ok",
418 map (\ (n,ns) -> (pn ist n, map (pn ist) ns)) calls)
447 map (\ (n,ns) -> (pn ist n, map (pn ist) ns)) calls)
419− runIO . putStrLn $ IdeSlave.convSExp "return" msg id
448+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
420 where pn ist = displaySpans .
449 where pn ist = displaySpans .
421 renderPretty 0.9 1000 .
450 renderPretty 0.9 1000 .
422 fmap (fancifyAnnots ist) .
451 fmap (fancifyAnnots ist) .
423 prettyName True True []
452 prettyName True True []
424−runIdeSlaveCommand id orig fn mods (IdeSlave.CallsWho n) =
453+runIdeSlaveCommand h id orig fn mods (IdeSlave.CallsWho n) =
425 case splitName n of
454 case splitName n of
426 Left err -> iPrintError err
455 Left err -> iPrintError err
427 Right n -> do calls <- callsWho n
456 Right n -> do calls <- callsWho n
428 ist <- getIState
457 ist <- getIState
429 let msg = (IdeSlave.SymbolAtom "ok",
458 let msg = (IdeSlave.SymbolAtom "ok",
430 map (\ (n,ns) -> (pn ist n, map (pn ist) ns)) calls)
459 map (\ (n,ns) -> (pn ist n, map (pn ist) ns)) calls)
431− runIO . putStrLn $ IdeSlave.convSExp "return" msg id
460+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
432 where pn ist = displaySpans .
461 where pn ist = displaySpans .
433 renderPretty 0.9 1000 .
462 renderPretty 0.9 1000 .
434 fmap (fancifyAnnots ist) .
463 fmap (fancifyAnnots ist) .
435 prettyName True True []
464 prettyName True True []
437−runIdeSlaveCommand id orig fn modes (IdeSlave.TermNormalise bnd tm) =
466+runIdeSlaveCommand h id orig fn modes (IdeSlave.TermNormalise bnd tm) =
438 do ctxt <- getContext
467 do ctxt <- getContext
439 ist <- getIState
468 ist <- getIState
440 let tm' = force (normaliseAll ctxt [] tm)
469 let tm' = force (normaliseAll ctxt [] tm)
@@ -448,15 +477,15 @@ runIdeSlaveCommand id orig fn modes (IdeSlave.TermNormalise bnd tm) =
448 displaySpans .
477 displaySpans .
449 renderPretty 0.9 80 .
478 renderPretty 0.9 80 .
450 fmap (fancifyAnnots ist) $ ptm)
479 fmap (fancifyAnnots ist) $ ptm)
451− runIO . putStrLn $ IdeSlave.convSExp "return" msg id
480+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
452−runIdeSlaveCommand id orig fn modes (IdeSlave.TermShowImplicits bnd tm) =
481+runIdeSlaveCommand h id orig fn modes (IdeSlave.TermShowImplicits bnd tm) =
453− ideSlaveForceTermImplicits id bnd True tm
482+ ideSlaveForceTermImplicits h id bnd True tm
454−runIdeSlaveCommand id orig fn modes (IdeSlave.TermNoImplicits bnd tm) =
483+runIdeSlaveCommand h id orig fn modes (IdeSlave.TermNoImplicits bnd tm) =
455− ideSlaveForceTermImplicits id bnd False tm
484+ ideSlaveForceTermImplicits h id bnd False tm
457-- | Show a term for IDESlave with the specified implicitness
486-- | Show a term for IDESlave with the specified implicitness
458−ideSlaveForceTermImplicits :: Integer -> [(Name, Bool)] -> Bool -> Term -> Idris ()
487+ideSlaveForceTermImplicits :: Handle -> Integer -> [(Name, Bool)] -> Bool -> Term -> Idris ()
459−ideSlaveForceTermImplicits id bnd impl tm =
488+ideSlaveForceTermImplicits h id bnd impl tm =
460 do ist <- getIState
489 do ist <- getIState
461 let expl = annotate (AnnTerm bnd tm)
490 let expl = annotate (AnnTerm bnd tm)
462 (pprintPTerm ((ppOptionIst ist) { ppopt_impl = impl })
491 (pprintPTerm ((ppOptionIst ist) { ppopt_impl = impl })
@@ -466,7 +495,7 @@ ideSlaveForceTermImplicits id bnd impl tm =
466 displaySpans .
495 displaySpans .
467 renderPretty 0.9 80 .
496 renderPretty 0.9 80 .
468 fmap (fancifyAnnots ist) $ expl)
497 fmap (fancifyAnnots ist) $ expl)
469− runIO . putStrLn $ IdeSlave.convSExp "return" msg id
498+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
471splitName :: String -> Either String Name
500splitName :: String -> Either String Name
472splitName s = case reverse $ splitOn "." s of
501splitName s = case reverse $ splitOn "." s of
@@ -475,70 +504,70 @@ splitName s = case reverse $ splitOn "." s of
475 (n:ns) -> Right $ sNS (sUN n) ns
504 (n:ns) -> Right $ sNS (sUN n) ns
477ideslaveProcess :: FilePath -> Command -> Idris ()
506ideslaveProcess :: FilePath -> Command -> Idris ()
478−ideslaveProcess fn Warranty = process stdout fn Warranty
507+ideslaveProcess fn Warranty = process fn Warranty
479−ideslaveProcess fn Help = process stdout fn Help
508+ideslaveProcess fn Help = process fn Help
480−ideslaveProcess fn (ChangeDirectory f) = do process stdout fn (ChangeDirectory f)
509+ideslaveProcess fn (ChangeDirectory f) = do process fn (ChangeDirectory f)
481 iPrintResult "changed directory to"
510 iPrintResult "changed directory to"
482−ideslaveProcess fn (Eval t) = process stdout fn (Eval t)
511+ideslaveProcess fn (Eval t) = process fn (Eval t)
483−ideslaveProcess fn (NewDefn decls) = do process stdout fn (NewDefn decls)
512+ideslaveProcess fn (NewDefn decls) = do process fn (NewDefn decls)
484 iPrintResult "defined"
513 iPrintResult "defined"
485−ideslaveProcess fn (ExecVal t) = process stdout fn (ExecVal t)
514+ideslaveProcess fn (ExecVal t) = process fn (ExecVal t)
486−ideslaveProcess fn (Check (PRef x n)) = process stdout fn (Check (PRef x n))
515+ideslaveProcess fn (Check (PRef x n)) = process fn (Check (PRef x n))
487−ideslaveProcess fn (Check t) = process stdout fn (Check t)
516+ideslaveProcess fn (Check t) = process fn (Check t)
488−ideslaveProcess fn (DocStr n) = process stdout fn (DocStr n)
517+ideslaveProcess fn (DocStr n) = process fn (DocStr n)
489−ideslaveProcess fn Universes = process stdout fn Universes
518+ideslaveProcess fn Universes = process fn Universes
490−ideslaveProcess fn (Defn n) = do process stdout fn (Defn n)
519+ideslaveProcess fn (Defn n) = do process fn (Defn n)
491 iPrintResult ""
520 iPrintResult ""
492−ideslaveProcess fn (TotCheck n) = process stdout fn (TotCheck n)
521+ideslaveProcess fn (TotCheck n) = process fn (TotCheck n)
493−ideslaveProcess fn (DebugInfo n) = do process stdout fn (DebugInfo n)
522+ideslaveProcess fn (DebugInfo n) = do process fn (DebugInfo n)
494 iPrintResult ""
523 iPrintResult ""
495−ideslaveProcess fn (Search t) = process stdout fn (Search t)
524+ideslaveProcess fn (Search t) = process fn (Search t)
496−ideslaveProcess fn (Spec t) = process stdout fn (Spec t)
525+ideslaveProcess fn (Spec t) = process fn (Spec t)
497-- RmProof and AddProof not supported!
526-- RmProof and AddProof not supported!
498−ideslaveProcess fn (ShowProof n') = process stdout fn (ShowProof n')
527+ideslaveProcess fn (ShowProof n') = process fn (ShowProof n')
499−ideslaveProcess fn (HNF t) = process stdout fn (HNF t)
528+ideslaveProcess fn (HNF t) = process fn (HNF t)
500−--ideslaveProcess fn TTShell = process stdout fn TTShell -- need some prove mode!
529+--ideslaveProcess fn TTShell = process fn TTShell -- need some prove mode!
501−ideslaveProcess fn (TestInline t) = process stdout fn (TestInline t)
530+ideslaveProcess fn (TestInline t) = process fn (TestInline t)
503−ideslaveProcess fn Execute = do process stdout fn Execute
532+ideslaveProcess fn Execute = do process fn Execute
504 iPrintResult ""
533 iPrintResult ""
505−ideslaveProcess fn (Compile codegen f) = do process stdout fn (Compile codegen f)
534+ideslaveProcess fn (Compile codegen f) = do process fn (Compile codegen f)
506 iPrintResult ""
535 iPrintResult ""
507−ideslaveProcess fn (LogLvl i) = do process stdout fn (LogLvl i)
536+ideslaveProcess fn (LogLvl i) = do process fn (LogLvl i)
508 iPrintResult ""
537 iPrintResult ""
509−ideslaveProcess fn (Pattelab t) = process stdout fn (Pattelab t)
538+ideslaveProcess fn (Pattelab t) = process fn (Pattelab t)
510−ideslaveProcess fn (Missing n) = process stdout fn (Missing n)
539+ideslaveProcess fn (Missing n) = process fn (Missing n)
511−ideslaveProcess fn (DynamicLink l) = do process stdout fn (DynamicLink l)
540+ideslaveProcess fn (DynamicLink l) = do process fn (DynamicLink l)
512 iPrintResult ""
541 iPrintResult ""
513−ideslaveProcess fn ListDynamic = do process stdout fn ListDynamic
542+ideslaveProcess fn ListDynamic = do process fn ListDynamic
514 iPrintResult ""
543 iPrintResult ""
515−ideslaveProcess fn Metavars = process stdout fn Metavars
544+ideslaveProcess fn Metavars = process fn Metavars
516−ideslaveProcess fn (SetOpt ErrContext) = do process stdout fn (SetOpt ErrContext)
545+ideslaveProcess fn (SetOpt ErrContext) = do process fn (SetOpt ErrContext)
517 iPrintResult ""
546 iPrintResult ""
518−ideslaveProcess fn (UnsetOpt ErrContext) = do process stdout fn (UnsetOpt ErrContext)
547+ideslaveProcess fn (UnsetOpt ErrContext) = do process fn (UnsetOpt ErrContext)
519 iPrintResult ""
548 iPrintResult ""
520−ideslaveProcess fn (SetOpt ShowImpl) = do process stdout fn (SetOpt ShowImpl)
549+ideslaveProcess fn (SetOpt ShowImpl) = do process fn (SetOpt ShowImpl)
521 iPrintResult ""
550 iPrintResult ""
522−ideslaveProcess fn (UnsetOpt ShowImpl) = do process stdout fn (UnsetOpt ShowImpl)
551+ideslaveProcess fn (UnsetOpt ShowImpl) = do process fn (UnsetOpt ShowImpl)
523 iPrintResult ""
552 iPrintResult ""
524−ideslaveProcess fn (SetOpt ShowOrigErr) = do process stdout fn (SetOpt ShowOrigErr)
553+ideslaveProcess fn (SetOpt ShowOrigErr) = do process fn (SetOpt ShowOrigErr)
525 iPrintResult ""
554 iPrintResult ""
526−ideslaveProcess fn (UnsetOpt ShowOrigErr) = do process stdout fn (UnsetOpt ShowOrigErr)
555+ideslaveProcess fn (UnsetOpt ShowOrigErr) = do process fn (UnsetOpt ShowOrigErr)
527 iPrintResult ""
556 iPrintResult ""
528−ideslaveProcess fn (SetOpt x) = process stdout fn (SetOpt x)
557+ideslaveProcess fn (SetOpt x) = process fn (SetOpt x)
529−ideslaveProcess fn (UnsetOpt x) = process stdout fn (UnsetOpt x)
558+ideslaveProcess fn (UnsetOpt x) = process fn (UnsetOpt x)
530−ideslaveProcess fn (CaseSplitAt False pos str) = process stdout fn (CaseSplitAt False pos str)
559+ideslaveProcess fn (CaseSplitAt False pos str) = process fn (CaseSplitAt False pos str)
531−ideslaveProcess fn (AddProofClauseFrom False pos str) = process stdout fn (AddProofClauseFrom False pos str)
560+ideslaveProcess fn (AddProofClauseFrom False pos str) = process fn (AddProofClauseFrom False pos str)
532−ideslaveProcess fn (AddClauseFrom False pos str) = process stdout fn (AddClauseFrom False pos str)
561+ideslaveProcess fn (AddClauseFrom False pos str) = process fn (AddClauseFrom False pos str)
533−ideslaveProcess fn (AddMissing False pos str) = process stdout fn (AddMissing False pos str)
562+ideslaveProcess fn (AddMissing False pos str) = process fn (AddMissing False pos str)
534−ideslaveProcess fn (MakeWith False pos str) = process stdout fn (MakeWith False pos str)
563+ideslaveProcess fn (MakeWith False pos str) = process fn (MakeWith False pos str)
535−ideslaveProcess fn (DoProofSearch False r pos str xs) = process stdout fn (DoProofSearch False r pos str xs)
564+ideslaveProcess fn (DoProofSearch False r pos str xs) = process fn (DoProofSearch False r pos str xs)
536−ideslaveProcess fn (SetConsoleWidth w) = do process stdout fn (SetConsoleWidth w)
565+ideslaveProcess fn (SetConsoleWidth w) = do process fn (SetConsoleWidth w)
537 iPrintResult ""
566 iPrintResult ""
538−ideslaveProcess fn (Apropos a) = do process stdout fn (Apropos a)
567+ideslaveProcess fn (Apropos a) = do process fn (Apropos a)
539 iPrintResult ""
568 iPrintResult ""
540−ideslaveProcess fn (WhoCalls n) = process stdout fn (WhoCalls n)
569+ideslaveProcess fn (WhoCalls n) = process fn (WhoCalls n)
541−ideslaveProcess fn (CallsWho n) = process stdout fn (CallsWho n)
570+ideslaveProcess fn (CallsWho n) = process fn (CallsWho n)
542ideslaveProcess fn _ = iPrintError "command not recognized or not supported"
571ideslaveProcess fn _ = iPrintError "command not recognized or not supported"
@@ -570,18 +599,18 @@ processInput cmd orig inputs
570 , idris_colourTheme = idris_colourTheme i
599 , idris_colourTheme = idris_colourTheme i
573− mods <- loadInputs stdout inputs Nothing
602+ mods <- loadInputs inputs Nothing
574 return (Just inputs)
603 return (Just inputs)
575 Success (Load f toline) ->
604 Success (Load f toline) ->
576 do putIState orig { idris_options = idris_options i
605 do putIState orig { idris_options = idris_options i
577 , idris_colourTheme = idris_colourTheme i
606 , idris_colourTheme = idris_colourTheme i
580− mod <- loadInputs stdout [f] toline
609+ mod <- loadInputs [f] toline
581 return (Just [f])
610 return (Just [f])
582 Success (ModImport f) ->
611 Success (ModImport f) ->
583 do clearErr
612 do clearErr
584− fmod <- loadModule stdout f
613+ fmod <- loadModule f
585 return (Just (inputs ++ [fmod]))
614 return (Just (inputs ++ [fmod]))
586 Success Edit -> do -- takeMVar stvar
615 Success Edit -> do -- takeMVar stvar
587 edit fn orig
616 edit fn orig
@@ -590,7 +619,7 @@ processInput cmd orig inputs
590 return (Just inputs)
619 return (Just inputs)
591 Success Quit -> do when (not quiet) (iputStrLn "Bye bye")
620 Success Quit -> do when (not quiet) (iputStrLn "Bye bye")
592 return Nothing
621 return Nothing
593− Success cmd -> do idrisCatch (process stdout fn cmd)
622+ Success cmd -> do idrisCatch (process fn cmd)
594 (\e -> do msg <- showErr e ; iputStrLn msg)
623 (\e -> do msg <- showErr e ; iputStrLn msg)
595 return (Just inputs)
624 return (Just inputs)
@@ -626,7 +655,7 @@ edit f orig
626 putIState $ orig { idris_options = idris_options i
655 putIState $ orig { idris_options = idris_options i
627 , idris_colourTheme = idris_colourTheme i
656 , idris_colourTheme = idris_colourTheme i
629− loadInputs stdout [f] Nothing
658+ loadInputs [f] Nothing
630-- clearOrigPats
659-- clearOrigPats
632 return ()
661 return ()
@@ -652,13 +681,13 @@ insertScript prf (p@"---------- Proofs ----------" : "" : xs)
652 = p : "" : prf : xs
681 = p : "" : prf : xs
653insertScript prf (x : xs) = x : insertScript prf xs
682insertScript prf (x : xs) = x : insertScript prf xs
655−process :: Handle -> FilePath -> Command -> Idris ()
684+process :: FilePath -> Command -> Idris ()
656−process h fn Help = iPrintResult displayHelp
685+process fn Help = iPrintResult displayHelp
657−process h fn Warranty = iPrintResult warranty
686+process fn Warranty = iPrintResult warranty
658−process h fn (ChangeDirectory f)
687+process fn (ChangeDirectory f)
659 = do runIO $ setCurrentDirectory f
688 = do runIO $ setCurrentDirectory f
660 return ()
689 return ()
661−process h fn (Eval t)
690+process fn (Eval t)
662 = withErrorReflection $ do logLvl 5 $ show t
691 = withErrorReflection $ do logLvl 5 $ show t
663 (tm, ty) <- elabVal recinfo ERHS t
692 (tm, ty) <- elabVal recinfo ERHS t
664 ctxt <- getContext
693 ctxt <- getContext
@@ -671,10 +700,10 @@ process h fn (Eval t)
671 logLvl 10 $ "Debug: " ++ showEnvDbg [] tm'
700 logLvl 10 $ "Debug: " ++ showEnvDbg [] tm'
672 let tmDoc = pprintDelab ist tm'
701 let tmDoc = pprintDelab ist tm'
673 tyDoc = pprintDelab ist ty'
702 tyDoc = pprintDelab ist ty'
674− ihPrintTermWithType h tmDoc tyDoc
703+ iPrintTermWithType tmDoc tyDoc
677−process h fn (NewDefn decls) = do
706+process fn (NewDefn decls) = do
678 logLvl 3 ("Defining names using these decls: " ++ show (showDecls verbosePPOption decls))
707 logLvl 3 ("Defining names using these decls: " ++ show (showDecls verbosePPOption decls))
679 mapM_ defineName namedGroups where
708 mapM_ defineName namedGroups where
680 namedGroups = groupBy (\d1 d2 -> getName d1 == getName d2) decls
709 namedGroups = groupBy (\d1 d2 -> getName d1 == getName d2) decls
@@ -732,7 +761,7 @@ process h fn (NewDefn decls) = do
732 PInstance syn fc constraints cls parms ty instName (map fixClauses decls)
761 PInstance syn fc constraints cls parms ty instName (map fixClauses decls)
733 fixClauses decl = decl
762 fixClauses decl = decl
735−process h fn (Undefine names) = undefine names
764+process fn (Undefine names) = undefine names
737 undefine :: [Name] -> Idris ()
766 undefine :: [Name] -> Idris ()
738 undefine [] = do
767 undefine [] = do
@@ -741,7 +770,7 @@ process h fn (Undefine names) = undefine names
741 -- Keep track of which names you've removed so you can
770 -- Keep track of which names you've removed so you can
742 -- print them out to the user afterward
771 -- print them out to the user afterward
743 undefine names = undefine' names []
772 undefine names = undefine' names []
744− undefine' [] list = do ihputStrLn h (show list)
773+ undefine' [] list = do iputStrLn (show list)
745 return ()
774 return ()
746 undefine' (n:names) already = do
775 undefine' (n:names) already = do
747 allDefined <- idris_repl_defs `fmap` get
776 allDefined <- idris_repl_defs `fmap` get
@@ -764,7 +793,7 @@ process h fn (Undefine names) = undefine names
767−process h fn (ExecVal t)
796+process fn (ExecVal t)
768 = do ctxt <- getContext
797 = do ctxt <- getContext
769 ist <- getIState
798 ist <- getIState
770 (tm, ty) <- elabVal recinfo ERHS t
799 (tm, ty) <- elabVal recinfo ERHS t
@@ -773,19 +802,19 @@ process h fn (ExecVal t)
773 res <- execute tm
802 res <- execute tm
774 let (resOut, tyOut) = (prettyIst ist (delab ist res),
803 let (resOut, tyOut) = (prettyIst ist (delab ist res),
775 prettyIst ist (delab ist ty'))
804 prettyIst ist (delab ist ty'))
776− ihPrintTermWithType h resOut tyOut
805+ iPrintTermWithType resOut tyOut
778−process h fn (Check (PRef _ n))
807+process fn (Check (PRef _ n))
779 = do ctxt <- getContext
808 = do ctxt <- getContext
780 ist <- getIState
809 ist <- getIState
781 let ppo = ppOptionIst ist
810 let ppo = ppOptionIst ist
782 case lookupNames n ctxt of
811 case lookupNames n ctxt of
783 ts@(t:_) ->
812 ts@(t:_) ->
784 case lookup t (idris_metavars ist) of
813 case lookup t (idris_metavars ist) of
785− Just (_, i, _) -> ihRenderResult h . fmap (fancifyAnnots ist) $
814+ Just (_, i, _) -> iRenderResult . fmap (fancifyAnnots ist) $
786 showMetavarInfo ppo ist n i
815 showMetavarInfo ppo ist n i
787− Nothing -> ihPrintFunTypes h [] n (map (\n -> (n, delabTy ist n)) ts)
816+ Nothing -> iPrintFunTypes [] n (map (\n -> (n, delabTy ist n)) ts)
788− [] -> ihPrintError h $ "No such variable " ++ show n
817+ [] -> iPrintError $ "No such variable " ++ show n
790 showMetavarInfo ppo ist n i
819 showMetavarInfo ppo ist n i
791 = case lookupTy n (tt_ctxt ist) of
820 = case lookupTy n (tt_ctxt ist) of
@@ -810,7 +839,7 @@ process h fn (Check (PRef _ n))
810 tPretty bnd ist t = pprintPTerm (ppOptionIst ist) bnd [] (idris_infixes ist) t
839 tPretty bnd ist t = pprintPTerm (ppOptionIst ist) bnd [] (idris_infixes ist) t
813−process h fn (Check t)
842+process fn (Check t)
814 = do (tm, ty) <- elabVal recinfo ERHS t
843 = do (tm, ty) <- elabVal recinfo ERHS t
815 ctxt <- getContext
844 ctxt <- getContext
816 ist <- getIState
845 ist <- getIState
@@ -818,24 +847,24 @@ process h fn (Check t)
818 ty' = normaliseC ctxt [] ty
847 ty' = normaliseC ctxt [] ty
819 case tm of
848 case tm of
820 TType _ ->
849 TType _ ->
821− ihPrintTermWithType h (prettyIst ist PType) type1Doc
850+ iPrintTermWithType (prettyIst ist PType) type1Doc
822− _ -> ihPrintTermWithType h (pprintDelab ist tm)
851+ _ -> iPrintTermWithType (pprintDelab ist tm)
823− (pprintDelab ist ty)
852+ (pprintDelab ist ty)
825−process h fn (DocStr (Left n))
854+process fn (DocStr (Left n))
826 = do ist <- getIState
855 = do ist <- getIState
827 case lookupCtxtName n (idris_docstrings ist) of
856 case lookupCtxtName n (idris_docstrings ist) of
828 [] -> iPrintError $ "No documentation for " ++ show n
857 [] -> iPrintError $ "No documentation for " ++ show n
829 ns -> do toShow <- mapM (showDoc ist) ns
858 ns -> do toShow <- mapM (showDoc ist) ns
830− ihRenderResult h (vsep toShow)
859+ iRenderResult (vsep toShow)
831 where showDoc ist (n, d) = do doc <- getDocs n
860 where showDoc ist (n, d) = do doc <- getDocs n
832 return $ pprintDocs ist doc
861 return $ pprintDocs ist doc
834−process h fn (DocStr (Right c))
863+process fn (DocStr (Right c))
835 = do ist <- getIState
864 = do ist <- getIState
836− ihRenderResult h $ pprintConstDocs ist c (constDocs c)
865+ iRenderResult $ pprintConstDocs ist c (constDocs c)
838−process h fn Universes
867+process fn Universes
839 = do i <- getIState
868 = do i <- getIState
840 let cs = idris_constraints i
869 let cs = idris_constraints i
841-- iputStrLn $ showSep "\n" (map show cs)
870-- iputStrLn $ showSep "\n" (map show cs)
@@ -845,7 +874,7 @@ process h fn Universes
845 case ucheck cs of
874 case ucheck cs of
846 Error e -> iPrintError $ pshow i e
875 Error e -> iPrintError $ pshow i e
847 OK _ -> iPrintResult "Universes OK"
876 OK _ -> iPrintResult "Universes OK"
848−process h fn (Defn n)
877+process fn (Defn n)
849 = do i <- getIState
878 = do i <- getIState
850 iputStrLn "Compiled patterns:\n"
879 iputStrLn "Compiled patterns:\n"
851 iputStrLn $ show (lookupDef n (tt_ctxt i))
880 iputStrLn $ show (lookupDef n (tt_ctxt i))
@@ -860,20 +889,20 @@ process h fn (Defn n)
860 = let i' = i { idris_options = (idris_options i) { opt_showimp = True } }
889 = let i' = i { idris_options = (idris_options i) { opt_showimp = True } }
861 in iputStrLn (showTm i' (delab i lhs) ++ " = " ++
890 in iputStrLn (showTm i' (delab i lhs) ++ " = " ++
862 showTm i' (delab i rhs))
891 showTm i' (delab i rhs))
863−process h fn (TotCheck n)
892+process fn (TotCheck n)
864 = do i <- getIState
893 = do i <- getIState
865 case lookupNameTotal n (tt_ctxt i) of
894 case lookupNameTotal n (tt_ctxt i) of
866− [] -> ihPrintError h $ "Unknown operator " ++ show n
895+ [] -> iPrintError $ "Unknown operator " ++ show n
867 ts -> do ist <- getIState
896 ts -> do ist <- getIState
868 c <- colourise
897 c <- colourise
869 let ppo = ppOptionIst ist
898 let ppo = ppOptionIst ist
870 let showN = showName (Just ist) [] ppo c
899 let showN = showName (Just ist) [] ppo c
871− ihPrintResult h . concat . intersperse "\n" .
900+ iPrintResult . concat . intersperse "\n" .
872 map (\(n, t) -> showN n ++ " is " ++ showTotal t i) $
901 map (\(n, t) -> showN n ++ " is " ++ showTotal t i) $
876−process h fn (DebugInfo n)
905+process fn (DebugInfo n)
877 = do i <- getIState
906 = do i <- getIState
878 let oi = lookupCtxtName n (idris_optimisation i)
907 let oi = lookupCtxtName n (idris_optimisation i)
879 when (not (null oi)) $ iputStrLn (show oi)
908 when (not (null oi)) $ iputStrLn (show oi)
@@ -890,29 +919,29 @@ process h fn (DebugInfo n)
890 iputStrLn $ "Size change: " ++ show sc
919 iputStrLn $ "Size change: " ++ show sc
891 when (not (null cg')) $ do iputStrLn "Call graph:\n"
920 when (not (null cg')) $ do iputStrLn "Call graph:\n"
892 iputStrLn (show cg')
921 iputStrLn (show cg')
893−process h fn (Search t) = searchByType h t
922+process fn (Search t) = searchByType t
894−process h fn (CaseSplitAt updatefile l n)
923+process fn (CaseSplitAt updatefile l n)
895− = caseSplitAt h fn updatefile l n
924+ = caseSplitAt fn updatefile l n
896−process h fn (AddClauseFrom updatefile l n)
925+process fn (AddClauseFrom updatefile l n)
897− = addClauseFrom h fn updatefile l n
926+ = addClauseFrom fn updatefile l n
898−process h fn (AddProofClauseFrom updatefile l n)
927+process fn (AddProofClauseFrom updatefile l n)
899− = addProofClauseFrom h fn updatefile l n
928+ = addProofClauseFrom fn updatefile l n
900−process h fn (AddMissing updatefile l n)
929+process fn (AddMissing updatefile l n)
901− = addMissing h fn updatefile l n
930+ = addMissing fn updatefile l n
902−process h fn (MakeWith updatefile l n)
931+process fn (MakeWith updatefile l n)
903− = makeWith h fn updatefile l n
932+ = makeWith fn updatefile l n
904−process h fn (MakeLemma updatefile l n)
933+process fn (MakeLemma updatefile l n)
905− = makeLemma h fn updatefile l n
934+ = makeLemma fn updatefile l n
906−process h fn (DoProofSearch updatefile rec l n hints)
935+process fn (DoProofSearch updatefile rec l n hints)
907− = doProofSearch h fn updatefile rec l n hints Nothing
936+ = doProofSearch fn updatefile rec l n hints Nothing
908−process h fn (Spec t)
937+process fn (Spec t)
909 = do (tm, ty) <- elabVal recinfo ERHS t
938 = do (tm, ty) <- elabVal recinfo ERHS t
910 ctxt <- getContext
939 ctxt <- getContext
911 ist <- getIState
940 ist <- getIState
912 let tm' = simplify ctxt [] {- (idris_statics ist) -} tm
941 let tm' = simplify ctxt [] {- (idris_statics ist) -} tm
913 iPrintResult (show (delab ist tm'))
942 iPrintResult (show (delab ist tm'))
915−process h fn (RmProof n')
944+process fn (RmProof n')
916 = do i <- getIState
945 = do i <- getIState
917 n <- resolveProof n'
946 n <- resolveProof n'
918 let proofs = proof_list i
947 let proofs = proof_list i
@@ -928,7 +957,7 @@ process h fn (RmProof n')
928 let ms = idris_metavars i
957 let ms = idris_metavars i
929 putIState $ i { idris_metavars = (n, (Nothing, 0, False)) : ms }
958 putIState $ i { idris_metavars = (n, (Nothing, 0, False)) : ms }
931−process h fn' (AddProof prf)
960+process fn' (AddProof prf)
932 = do fn <- do
961 = do fn <- do
933 let fn'' = takeWhile (/= ' ') fn'
962 let fn'' = takeWhile (/= ' ') fn'
934 ex <- runIO $ doesFileExist fn''
963 ex <- runIO $ doesFileExist fn''
@@ -958,7 +987,7 @@ process h fn' (AddProof prf)
958 iputStrLn $ "Added proof " ++ show n
987 iputStrLn $ "Added proof " ++ show n
959 where ls = (lines prog)
988 where ls = (lines prog)
961−process h fn (ShowProof n')
990+process fn (ShowProof n')
962 = do i <- getIState
991 = do i <- getIState
963 n <- resolveProof n'
992 n <- resolveProof n'
964 let proofs = proof_list i
993 let proofs = proof_list i
@@ -966,7 +995,7 @@ process h fn (ShowProof n')
966 Nothing -> iPrintError "No proof to show"
995 Nothing -> iPrintError "No proof to show"
967 Just p -> iPrintResult $ showProof False n p
996 Just p -> iPrintResult $ showProof False n p
969−process h fn (Prove n')
998+process fn (Prove n')
970 = do ctxt <- getContext
999 = do ctxt <- getContext
971 ist <- getIState
1000 ist <- getIState
972 let ns = lookupNames n' ctxt
1001 let ns = lookupNames n' ctxt
@@ -984,20 +1013,20 @@ process h fn (Prove n')
984 mapM_ checkDeclTotality (idris_totcheck i)
1013 mapM_ checkDeclTotality (idris_totcheck i)
985 warnTotality
1014 warnTotality
987−process h fn (HNF t)
1016+process fn (HNF t)
988 = do (tm, ty) <- elabVal recinfo ERHS t
1017 = do (tm, ty) <- elabVal recinfo ERHS t
989 ctxt <- getContext
1018 ctxt <- getContext
990 ist <- getIState
1019 ist <- getIState
991 let tm' = hnf ctxt [] tm
1020 let tm' = hnf ctxt [] tm
992 iPrintResult (show (delab ist tm'))
1021 iPrintResult (show (delab ist tm'))
993−process h fn (TestInline t)
1022+process fn (TestInline t)
994 = do (tm, ty) <- elabVal recinfo ERHS t
1023 = do (tm, ty) <- elabVal recinfo ERHS t
995 ctxt <- getContext
1024 ctxt <- getContext
996 ist <- getIState
1025 ist <- getIState
997 let tm' = inlineTerm ist tm
1026 let tm' = inlineTerm ist tm
998 c <- colourise
1027 c <- colourise
999 iPrintResult (showTm ist (delab ist tm'))
1028 iPrintResult (showTm ist (delab ist tm'))
1000−process h fn Execute
1029+process fn Execute
1001 = idrisCatch
1030 = idrisCatch
1002 (do ist <- getIState
1031 (do ist <- getIState
1003 (m, _) <- elabVal recinfo ERHS
1032 (m, _) <- elabVal recinfo ERHS
@@ -1009,33 +1038,33 @@ process h fn Execute
1009 t <- codegen
1038 t <- codegen
1010 compile t tmpn m
1039 compile t tmpn m
1011 case idris_outputmode ist of
1040 case idris_outputmode ist of
1012− RawOutput -> do runIO $ system tmpn
1041+ RawOutput h -> do runIO $ system tmpn
1013− return ()
1042+ return ()
1014− IdeSlave n -> runIO . hPutStrLn h $
1043+ IdeSlave n h -> runIO . hPutStrLn h $
1015− IdeSlave.convSExp "run-program" tmpn n)
1044+ IdeSlave.convSExp "run-program" tmpn n)
1016− (\e -> getIState >>= ihRenderError stdout . flip pprintErr e)
1045+ (\e -> getIState >>= iRenderError . flip pprintErr e)
1017 where fc = fileFC "main"
1046 where fc = fileFC "main"
1018−process h fn (Compile codegen f)
1047+process fn (Compile codegen f)
1019 = do (m, _) <- elabVal recinfo ERHS
1048 = do (m, _) <- elabVal recinfo ERHS
1020 (PApp fc (PRef fc (sUN "run__IO"))
1049 (PApp fc (PRef fc (sUN "run__IO"))
1021 [pexp $ PRef fc (sNS (sUN "main") ["Main"])])
1050 [pexp $ PRef fc (sNS (sUN "main") ["Main"])])
1022 compile codegen f m
1051 compile codegen f m
1023 where fc = fileFC "main"
1052 where fc = fileFC "main"
1024−process h fn (LogLvl i) = setLogLevel i
1053+process fn (LogLvl i) = setLogLevel i
1025-- Elaborate as if LHS of a pattern (debug command)
1054-- Elaborate as if LHS of a pattern (debug command)
1026−process h fn (Pattelab t)
1055+process fn (Pattelab t)
1027 = do (tm, ty) <- elabVal recinfo ELHS t
1056 = do (tm, ty) <- elabVal recinfo ELHS t
1028 iPrintResult $ show tm ++ "\n\n : " ++ show ty
1057 iPrintResult $ show tm ++ "\n\n : " ++ show ty
1030−process h fn (Missing n)
1059+process fn (Missing n)
1031 = do i <- getIState
1060 = do i <- getIState
1032 let i' = i { idris_options = (idris_options i) { opt_showimp = True } }
1061 let i' = i { idris_options = (idris_options i) { opt_showimp = True } }
1033 case lookupCtxt n (idris_patdefs i) of
1062 case lookupCtxt n (idris_patdefs i) of
1034− [] -> ihPrintError h $ "Unknown operator " ++ show n
1063+ [] -> iPrintError $ "Unknown operator " ++ show n
1035 [(_, tms)] ->
1064 [(_, tms)] ->
1036 iPrintResult (showSep "\n" (map (showTm i') tms))
1065 iPrintResult (showSep "\n" (map (showTm i') tms))
1037 _ -> iPrintError $ "Ambiguous name"
1066 _ -> iPrintError $ "Ambiguous name"
1038−process h fn (DynamicLink l)
1067+process fn (DynamicLink l)
1039 = do i <- getIState
1068 = do i <- getIState
1040 let importdirs = opt_importdirs (idris_options i)
1069 let importdirs = opt_importdirs (idris_options i)
1041 lib = trim l
1070 lib = trim l
@@ -1048,80 +1077,80 @@ process h fn (DynamicLink l)
1048 return ()
1077 return ()
1049 else putIState $ i { idris_dynamic_libs = x:libs }
1078 else putIState $ i { idris_dynamic_libs = x:libs }
1050 where trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace
1079 where trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace
1051−process h fn ListDynamic
1080+process fn ListDynamic
1052 = do i <- getIState
1081 = do i <- getIState
1053 iputStrLn "Dynamic libraries:"
1082 iputStrLn "Dynamic libraries:"
1054 showLibs $ idris_dynamic_libs i
1083 showLibs $ idris_dynamic_libs i
1055 where showLibs [] = return ()
1084 where showLibs [] = return ()
1056 showLibs ((Lib name _):ls) = do iputStrLn $ "\t" ++ name; showLibs ls
1085 showLibs ((Lib name _):ls) = do iputStrLn $ "\t" ++ name; showLibs ls
1057−process h fn Metavars
1086+process fn Metavars
1058 = do ist <- getIState
1087 = do ist <- getIState
1059 let mvs = map fst (idris_metavars ist) \\ primDefs
1088 let mvs = map fst (idris_metavars ist) \\ primDefs
1060 case mvs of
1089 case mvs of
1061 [] -> iPrintError "No global metavariables to solve"
1090 [] -> iPrintError "No global metavariables to solve"
1062 _ -> iPrintResult $ "Global metavariables:\n\t" ++ show mvs
1091 _ -> iPrintResult $ "Global metavariables:\n\t" ++ show mvs
1063−process h fn NOP = return ()
1092+process fn NOP = return ()
1065−process h fn (SetOpt ErrContext) = setErrContext True
1094+process fn (SetOpt ErrContext) = setErrContext True
1066−process h fn (UnsetOpt ErrContext) = setErrContext False
1095+process fn (UnsetOpt ErrContext) = setErrContext False
1067−process h fn (SetOpt ShowImpl) = setImpShow True
1096+process fn (SetOpt ShowImpl) = setImpShow True
1068−process h fn (UnsetOpt ShowImpl) = setImpShow False
1097+process fn (UnsetOpt ShowImpl) = setImpShow False
1069−process h fn (SetOpt ShowOrigErr) = setShowOrigErr True
1098+process fn (SetOpt ShowOrigErr) = setShowOrigErr True
1070−process h fn (UnsetOpt ShowOrigErr) = setShowOrigErr False
1099+process fn (UnsetOpt ShowOrigErr) = setShowOrigErr False
1071−process h fn (SetOpt AutoSolve) = setAutoSolve True
1100+process fn (SetOpt AutoSolve) = setAutoSolve True
1072−process h fn (UnsetOpt AutoSolve) = setAutoSolve False
1101+process fn (UnsetOpt AutoSolve) = setAutoSolve False
1073−process h fn (SetOpt NoBanner) = setNoBanner True
1102+process fn (SetOpt NoBanner) = setNoBanner True
1074−process h fn (UnsetOpt NoBanner) = setNoBanner False
1103+process fn (UnsetOpt NoBanner) = setNoBanner False
1075−process h fn (SetOpt WarnReach) = fmodifyState opts_idrisCmdline $ nub . (WarnReach:)
1104+process fn (SetOpt WarnReach) = fmodifyState opts_idrisCmdline $ nub . (WarnReach:)
1076−process h fn (UnsetOpt WarnReach) = fmodifyState opts_idrisCmdline $ delete WarnReach
1105+process fn (UnsetOpt WarnReach) = fmodifyState opts_idrisCmdline $ delete WarnReach
1078−process h fn (SetOpt _) = iPrintError "Not a valid option"
1107+process fn (SetOpt _) = iPrintError "Not a valid option"
1079−process h fn (UnsetOpt _) = iPrintError "Not a valid option"
1108+process fn (UnsetOpt _) = iPrintError "Not a valid option"
1080−process h fn (SetColour ty c) = setColour ty c
1109+process fn (SetColour ty c) = setColour ty c
1081−process h fn ColourOn
1110+process fn ColourOn
1082 = do ist <- getIState
1111 = do ist <- getIState
1083 putIState $ ist { idris_colourRepl = True }
1112 putIState $ ist { idris_colourRepl = True }
1084−process h fn ColourOff
1113+process fn ColourOff
1085 = do ist <- getIState
1114 = do ist <- getIState
1086 putIState $ ist { idris_colourRepl = False }
1115 putIState $ ist { idris_colourRepl = False }
1087−process h fn ListErrorHandlers =
1116+process fn ListErrorHandlers =
1088 do ist <- getIState
1117 do ist <- getIState
1089 iPrintResult $ case idris_errorhandlers ist of
1118 iPrintResult $ case idris_errorhandlers ist of
1090 [] -> "No registered error handlers"
1119 [] -> "No registered error handlers"
1091 handlers -> "Registered error handlers: " ++ (concat . intersperse ", " . map show) handlers
1120 handlers -> "Registered error handlers: " ++ (concat . intersperse ", " . map show) handlers
1092−process h fn (SetConsoleWidth w) = setWidth w
1121+process fn (SetConsoleWidth w) = setWidth w
1094−process h fn (Apropos a) =
1123+process fn (Apropos a) =
1095 do ist <- getIState
1124 do ist <- getIState
1096 let names = apropos ist (T.pack a)
1125 let names = apropos ist (T.pack a)
1097 let aproposInfo = [ (n,
1126 let aproposInfo = [ (n,
1098 delabTy ist n,
1127 delabTy ist n,
1099 fmap (overview . fst) (lookupCtxtExact n (idris_docstrings ist)))
1128 fmap (overview . fst) (lookupCtxtExact n (idris_docstrings ist)))
1100 | n <- sort names, isUN n ]
1129 | n <- sort names, isUN n ]
1101− ihRenderResult h $ vsep (map (prettyDocumentedIst ist) aproposInfo)
1130+ iRenderResult $ vsep (map (prettyDocumentedIst ist) aproposInfo)
1102 where isUN (UN _) = True
1131 where isUN (UN _) = True
1103 isUN (NS n _) = isUN n
1132 isUN (NS n _) = isUN n
1104 isUN _ = False
1133 isUN _ = False
1106−process h fn (WhoCalls n) =
1135+process fn (WhoCalls n) =
1107 do calls <- whoCalls n
1136 do calls <- whoCalls n
1108 ist <- getIState
1137 ist <- getIState
1109− ihRenderResult h . vsep $
1138+ iRenderResult . vsep $
1110 map (\(n, ns) ->
1139 map (\(n, ns) ->
1111 text "Callers of" <+> prettyName True True [] n <$>
1140 text "Callers of" <+> prettyName True True [] n <$>
1112 indent 1 (vsep (map ((text "*" <+>) . align . prettyName True True []) ns)))
1141 indent 1 (vsep (map ((text "*" <+>) . align . prettyName True True []) ns)))
1115−process h fn (CallsWho n) =
1144+process fn (CallsWho n) =
1116 do calls <- callsWho n
1145 do calls <- callsWho n
1117 ist <- getIState
1146 ist <- getIState
1118− ihRenderResult h . vsep $
1147+ iRenderResult . vsep $
1119 map (\(n, ns) ->
1148 map (\(n, ns) ->
1120 prettyName True True [] n <+> text "calls:" <$>
1149 prettyName True True [] n <+> text "calls:" <$>
1121 indent 1 (vsep (map ((text "*" <+>) . align . prettyName True True []) ns)))
1150 indent 1 (vsep (map ((text "*" <+>) . align . prettyName True True []) ns)))
1123-- IdrisDoc
1152-- IdrisDoc
1124−process h fn (MakeDoc s) =
1153+process fn (MakeDoc s) =
1125 do istate <- getIState
1154 do istate <- getIState
1126 let names = words s
1155 let names = words s
1127 parse n | Success x <- runparser name istate fn n = Right x
1156 parse n | Success x <- runparser name istate fn n = Right x
@@ -1178,8 +1207,8 @@ idris opts = do res <- runErrorT $ execStateT totalMain idrisInit
1178 [] -> return ()
1207 [] -> return ()
1181−loadInputs :: Handle -> [FilePath] -> Maybe Int -> Idris ()
1210+loadInputs :: [FilePath] -> Maybe Int -> Idris ()
1182−loadInputs h inputs toline -- furthest line to read in input source files
1211+loadInputs inputs toline -- furthest line to read in input source files
1183 = idrisCatch
1212 = idrisCatch
1184 (do ist <- getIState
1213 (do ist <- getIState
1185 -- if we're in --check and not outputting anything, don't bother
1214 -- if we're in --check and not outputting anything, don't bother
@@ -1231,10 +1260,10 @@ loadInputs h inputs toline -- furthest line to read in input source files
1231 (\e -> do i <- getIState
1260 (\e -> do i <- getIState
1232 case e of
1261 case e of
1233 At f e' -> do setErrSpan f
1262 At f e' -> do setErrSpan f
1234− ihWarn stdout f $ pprintErr i e'
1263+ iWarn f $ pprintErr i e'
1235 ProgramLineComment -> return () -- fail elsewhere
1264 ProgramLineComment -> return () -- fail elsewhere
1236 _ -> do setErrSpan emptyFC -- FIXME! Propagate it
1265 _ -> do setErrSpan emptyFC -- FIXME! Propagate it
1237− ihWarn stdout emptyFC $ pprintErr i e)
1266+ iWarn emptyFC $ pprintErr i e)
1238 where -- load all files, stop if any fail
1267 where -- load all files, stop if any fail
1239 tryLoad :: Bool -> [IFileType] -> Idris ()
1268 tryLoad :: Bool -> [IFileType] -> Idris ()
1240 tryLoad keepstate [] = warnTotality >> return ()
1269 tryLoad keepstate [] = warnTotality >> return ()
@@ -1251,7 +1280,7 @@ loadInputs h inputs toline -- furthest line to read in input source files
1251 then Just l
1280 then Just l
1252 else Nothing
1281 else Nothing
1253 _ -> Nothing
1282 _ -> Nothing
1254− loadFromIFile h f maxline
1283+ loadFromIFile f maxline
1255 inew <- getIState
1284 inew <- getIState
1256 -- FIXME: Save these in IBC to avoid this hack! Need to
1285 -- FIXME: Save these in IBC to avoid this hack! Need to
1257 -- preserve it all from source inputs
1286 -- preserve it all from source inputs
@@ -1299,7 +1328,7 @@ idrisMain opts =
1299 do let inputs = opt getFile opts
1328 do let inputs = opt getFile opts
1300 let quiet = Quiet `elem` opts
1329 let quiet = Quiet `elem` opts
1301 let nobanner = NoBanner `elem` opts
1330 let nobanner = NoBanner `elem` opts
1302− let idesl = Ideslave `elem` opts
1331+ let idesl = Ideslave `elem` opts || IdeslaveSocket `elem` opts
1303 let runrepl = not (NoREPL `elem` opts)
1332 let runrepl = not (NoREPL `elem` opts)
1304 let verbose = runrepl || Verbose `elem` opts
1333 let verbose = runrepl || Verbose `elem` opts
1305 let output = opt getOutput opts
1334 let output = opt getOutput opts
@@ -1336,7 +1365,6 @@ idrisMain opts =
1336 mapM_ addLangExt (opt getLanguageExt opts)
1365 mapM_ addLangExt (opt getLanguageExt opts)
1337 setREPL runrepl
1366 setREPL runrepl
1338 setQuiet (quiet || isJust script || not (null immediate))
1367 setQuiet (quiet || isJust script || not (null immediate))
1340 setVerbose verbose
1368 setVerbose verbose
1341 setCmdLine opts
1369 setCmdLine opts
1342 setOutputTy outty
1370 setOutputTy outty
@@ -1362,9 +1390,9 @@ idrisMain opts =
1362 addPkgDir "base"
1390 addPkgDir "base"
1363 mapM_ addPkgDir pkgdirs
1391 mapM_ addPkgDir pkgdirs
1364 elabPrims
1392 elabPrims
1365− when (not (NoBuiltins `elem` opts)) $ do x <- loadModule stdout "Builtins"
1393+ when (not (NoBuiltins `elem` opts)) $ do x <- loadModule "Builtins"
1366 return ()
1394 return ()
1367− when (not (NoPrelude `elem` opts)) $ do x <- loadModule stdout "Prelude"
1395+ when (not (NoPrelude `elem` opts)) $ do x <- loadModule "Prelude"
1368 return ()
1396 return ()
1370 when (runrepl && not idesl) initScript
1398 when (runrepl && not idesl) initScript
@@ -1380,14 +1408,14 @@ idrisMain opts =
1380 iputStrLn banner
1408 iputStrLn banner
1382 orig <- getIState
1410 orig <- getIState
1383− loadInputs stdout inputs Nothing
1411+ when (not idesl) $ loadInputs inputs Nothing
1385 runIO $ hSetBuffering stdout LineBuffering
1413 runIO $ hSetBuffering stdout LineBuffering
1387 ok <- noErrors
1415 ok <- noErrors
1388 when ok $ case output of
1416 when ok $ case output of
1389 [] -> return ()
1417 [] -> return ()
1390− (o:_) -> idrisCatch (process stdout "" (Compile cgn o))
1418+ (o:_) -> idrisCatch (process "" (Compile cgn o))
1391 (\e -> do ist <- getIState ; iputStrLn $ pshow ist e)
1419 (\e -> do ist <- getIState ; iputStrLn $ pshow ist e)
1393 case immediate of
1421 case immediate of
@@ -1398,7 +1426,7 @@ idrisMain opts =
1398 case parseExpr ist str of
1426 case parseExpr ist str of
1399 Failure err -> do iputStrLn $ show (fixColour c err)
1427 Failure err -> do iputStrLn $ show (fixColour c err)
1400 runIO $ exitWith (ExitFailure 1)
1428 runIO $ exitWith (ExitFailure 1)
1401− Success e -> process stdout "" (Eval e))
1429+ Success e -> process "" (Eval e))
1403 runIO $ exitWith ExitSuccess
1431 runIO $ exitWith ExitSuccess
@@ -1420,7 +1448,8 @@ idrisMain opts =
1420-- clearOrigPats
1448-- clearOrigPats
1421 startServer orig inputs
1449 startServer orig inputs
1422 runInputT (replSettings (Just historyFile)) $ repl orig inputs
1450 runInputT (replSettings (Just historyFile)) $ repl orig inputs
1451+ let idesock = IdeslaveSocket `elem` opts
1423− when (idesl) $ ideslaveStart orig inputs
1452+ when (idesl) $ ideslaveStart idesock orig inputs
1424 ok <- noErrors
1453 ok <- noErrors
1425 when (not ok) $ runIO (exitWith (ExitFailure 1))
1454 when (not ok) $ runIO (exitWith (ExitFailure 1))
@@ -1482,7 +1511,7 @@ initScript = do script <- getInitScript
1482 Success Edit -> iPrintError "Init scripts cannot invoke the editor"
1511 Success Edit -> iPrintError "Init scripts cannot invoke the editor"
1483 Success Proofs -> proofs i
1512 Success Proofs -> proofs i
1484 Success Quit -> iPrintError "Init scripts cannot quit Idris"
1513 Success Quit -> iPrintError "Init scripts cannot quit Idris"
1485− Success cmd -> process stdout [] cmd
1514+ Success cmd -> process [] cmd
1487getFile :: Opt -> Maybe String
1516getFile :: Opt -> Maybe String
1488getFile (Filename str) = Just str
1517getFile (Filename str) = Just str