@@ -42,7 +42,7 @@ import Idris.Elab.Value
4242import Version_idris (gitHash)
4343import Util.System
4444import Util.DynamicLinker
45−import Util.Net (listenOnLocalhost)
45+import Util.Net (listenOnLocalhost, listenOnLocalhostAnyPort)
4646import Util.Pretty hiding ((</>))
4747
4848import Idris.Core.Evaluate
@@ -93,6 +93,8 @@ import Data.Word (Word)
9393import Data.Either (partitionEithers)
9494import Control.DeepSeq
9595
96+import Numeric ( readHex )
97+
9698import Debug.Trace
9799
98100-- | Run the REPL
@@ -151,7 +153,7 @@ startServer orig fn_in = do tid <- runIO $ forkOS serverLoop
151153 -- TODO: option for port number
152154 serverLoop = withSocketsDo $
153155 do sock <- listenOnLocalhost $ PortNumber 4294
154− loop fn orig sock
156+ loop fn orig { idris_colourRepl = False } sock
155157
156158 fn = case fn_in of
157159 (f:_) -> f
@@ -161,7 +163,10 @@ startServer orig fn_in = do tid <- runIO $ forkOS serverLoop
161163 = do (h,_,_) <- accept sock
162164 hSetEncoding h utf8
163165 cmd <- hGetLine h
164− (ist', fn) <- processNetCmd orig ist h fn cmd
166+ let isth = case idris_outputmode ist of
167+ RawOutput _ -> ist {idris_outputmode = RawOutput h}
168+ IdeSlave n _ -> ist {idris_outputmode = IdeSlave n h}
169+ (ist', fn) <- processNetCmd orig isth h fn cmd
165170 hClose h
166171 loop fn ist' sock
167172
@@ -187,12 +192,18 @@ processNetCmd orig i h fn cmd
187192 setOutH h
188193 setQuiet True
189194 setVerbose False
190− mods <- loadInputs h [f] toline
195+ mods <- loadInputs [f] toline
191196 ist <- getIState
192197 return (ist, f)
193− processNet fn c = do process h fn c
198+ processNet fn c = do process fn c
194199 ist <- getIState
195200 return (ist, fn)
201+ setOutH :: Handle -> Idris ()
202+ setOutH h =
203+ do ist <- getIState
204+ putIState $ case idris_outputmode ist of
205+ RawOutput _ -> ist {idris_outputmode = RawOutput h}
206+ IdeSlave n _ -> ist {idris_outputmode = IdeSlave n h}
196207
197208-- | Run a command on the server on localhost
198209runClient :: String -> IO ()
@@ -208,55 +219,73 @@ runClient str = withSocketsDo $ do
208219 else do l <- hGetLine h
209220 hGetResp (acc ++ l ++ "\n") h
210221
222+initIdeslaveSocket :: IO Handle
223+initIdeslaveSocket = do
224+ (sock, port) <- listenOnLocalhostAnyPort
225+ putStrLn $ show port
226+ (h, _, _) <- accept sock
227+ hSetEncoding h utf8
228+ return h
229+
211230-- | Run the IdeSlave
212−ideslaveStart :: IState -> [FilePath] -> Idris ()
213−ideslaveStart orig mods
214− = do i <- getIState
231+ideslaveStart :: Bool -> IState -> [FilePath] -> Idris ()
232+ideslaveStart s orig mods
233+ = do h <- runIO $ if s then initIdeslaveSocket else return stdout
234+ setIdeSlave True h
235+ i <- getIState
215236 case idris_outputmode i of
216− IdeSlave n ->
217− when (mods /= []) (do isetPrompt (mkPrompt mods))
218− ideslave orig mods
219−
220−
221−ideslave :: IState -> [FilePath] -> Idris ()
222−ideslave orig mods
237+ IdeSlave n h ->
238+ do runIO $ hPutStrLn h $ IdeSlave.convSExp "protocol-version" IdeSlave.ideSlaveEpoch n
239+ case mods of
240+ a:_ -> runIdeSlaveCommand h n i "" [] (IdeSlave.LoadFile a Nothing)
241+ _ -> return ()
242+ ideslave h orig mods
243+
244+ideslave :: Handle -> IState -> [FilePath] -> Idris ()
245+ideslave h orig mods
223246 = do idrisCatch
224− (do l <- runIO $ getLine
247+ (do let inh = if h == stdout then stdin else h
248+ len' <- runIO $ IdeSlave.getLen inh
249+ len <- case len' of
250+ Left err -> ierror err
251+ Right n -> return n
252+ l <- runIO $ IdeSlave.getNChar inh len ""
225253 (sexp, id) <- case IdeSlave.parseMessage l of
226254 Left err -> ierror err
227255 Right (sexp, id) -> return (sexp, id)
228256 i <- getIState
229− putIState $ i { idris_outputmode = (IdeSlave id) }
257+ putIState $ i { idris_outputmode = (IdeSlave id h) }
230258 idrisCatch -- to report correct id back!
231259 (do let fn = case mods of
232260 (f:_) -> f
233− _ -> ""
261+ _ -> ""
234262 case IdeSlave.sexpToCommand sexp of
235− Just cmd -> runIdeSlaveCommand id orig fn mods cmd
263+ Just cmd -> runIdeSlaveCommand h id orig fn mods cmd
236264 Nothing -> iPrintError "did not understand" )
237265 (\e -> do iPrintError $ show e))
238266 (\e -> do iPrintError $ show e)
239− ideslave orig mods
267+ ideslave h orig mods
240268
241269-- | Run IDESlave commands
242−runIdeSlaveCommand :: Integer -- ^^ The continuation ID for the client
270+runIdeSlaveCommand :: Handle -- ^^ The handle for communication
271+ -> Integer -- ^^ The continuation ID for the client
243272 -> IState -- ^^ The original IState
244273 -> FilePath -- ^^ The current open file
245274 -> [FilePath] -- ^^ The currently loaded modules
246275 -> IdeSlave.IdeSlaveCommand -- ^^ The command to process
247276 -> Idris ()
248−runIdeSlaveCommand id orig fn mods (IdeSlave.Interpret cmd) =
277+runIdeSlaveCommand h id orig fn mods (IdeSlave.Interpret cmd) =
249278 do c <- colourise
250279 i <- getIState
251280 case parseCmd i "(input)" cmd of
252− Failure err -> iPrintError $ show (fixColour c err)
281+ Failure err -> iPrintError $ show (fixColour False err)
253282 Success (Prove n') ->
254283 idrisCatch
255− (do process stdout fn (Prove n')
284+ (do process fn (Prove n')
256285 isetPrompt (mkPrompt mods)
257286 case idris_outputmode i of
258− IdeSlave n -> -- signal completion of proof to ide
259− runIO . hPutStrLn stdout $
287+ IdeSlave n h -> -- signal completion of proof to ide
288+ runIO . hPutStrLn h $
260289 IdeSlave.convSExp "return"
261290 (IdeSlave.SymbolAtom "ok", "")
262291 n
@@ -264,26 +293,26 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.Interpret cmd) =
264293 (\e -> do ist <- getIState
265294 isetPrompt (mkPrompt mods)
266295 case idris_outputmode i of
267− IdeSlave n ->
268− runIO . hPutStrLn stdout $
296+ IdeSlave n h ->
297+ runIO . hPutStrLn h $
269298 IdeSlave.convSExp "abandon-proof" "Abandoned" n
270299 _ -> return ()
271− ihRenderError stdout $ pprintErr ist e)
300+ iRenderError $ pprintErr ist e)
272301 Success cmd -> idrisCatch
273302 (ideslaveProcess fn cmd)
274− (\e -> getIState >>= ihRenderError stdout . flip pprintErr e)
275−runIdeSlaveCommand id orig fn mods (IdeSlave.REPLCompletions str) =
303+ (\e -> getIState >>= iRenderError . flip pprintErr e)
304+runIdeSlaveCommand h id orig fn mods (IdeSlave.REPLCompletions str) =
276305 do (unused, compls) <- replCompletion (reverse str, "")
277306 let good = IdeSlave.SexpList [IdeSlave.SymbolAtom "ok",
278307 IdeSlave.toSExp (map replacement compls,
279308 reverse unused)]
280− runIO $ putStrLn $ IdeSlave.convSExp "return" good id
281−runIdeSlaveCommand id orig fn mods (IdeSlave.LoadFile filename toline) =
309+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" good id
310+runIdeSlaveCommand h id orig fn mods (IdeSlave.LoadFile filename toline) =
282311 do i <- getIState
283312 clearErr
284313 putIState (orig { idris_options = idris_options i,
285− idris_outputmode = (IdeSlave id) })
286− loadInputs stdout [filename] toline
314+ idris_outputmode = (IdeSlave id h) })
315+ loadInputs [filename] toline
287316 isetPrompt (mkPrompt [filename])
288317 -- Report either success or failure
289318 i <- getIState
@@ -293,45 +322,45 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.LoadFile filename toline) =
293322 (\fc -> IdeSlave.SexpList [IdeSlave.SymbolAtom "ok",
294323 IdeSlave.toSExp fc])
295324 (idris_parsedSpan i)
296− in runIO . putStrLn $ IdeSlave.convSExp "return" msg id
325+ in runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
297326 Just x -> iPrintError $ "didn't load " ++ filename
298− ideslave orig [filename]
299−runIdeSlaveCommand id orig fn mods (IdeSlave.TypeOf name) =
327+ ideslave h orig [filename]
328+runIdeSlaveCommand h id orig fn mods (IdeSlave.TypeOf name) =
300329 case splitName name of
301330 Left err -> iPrintError err
302− Right n -> process stdout "(ideslave)"
331+ Right n -> process "(ideslave)"
303332 (Check (PRef (FC "(ideslave)" (0,0) (0,0)) n))
304333 where splitName :: String -> Either String Name
305334 splitName s = case reverse $ splitOn "." s of
306335 [] -> Left ("Didn't understand name '" ++ s ++ "'")
307336 [n] -> Right $ sUN n
308337 (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) =
310339 case parseConst orig name of
311− Success c -> process stdout "(ideslave)" (DocStr (Right c))
340+ Success c -> process "(ideslave)" (DocStr (Right c))
312341 Failure _ ->
313342 case splitName name of
314343 Left err -> iPrintError err
315− Right n -> process stdout "(ideslave)" (DocStr (Left n))
316−runIdeSlaveCommand id orig fn mods (IdeSlave.CaseSplit line name) =
317− process stdout fn (CaseSplitAt False line (sUN name))
318−runIdeSlaveCommand id orig fn mods (IdeSlave.AddClause line name) =
319− process stdout fn (AddClauseFrom False line (sUN name))
320−runIdeSlaveCommand id orig fn mods (IdeSlave.AddProofClause line name) =
321− process stdout fn (AddProofClauseFrom False line (sUN name))
322−runIdeSlaveCommand id orig fn mods (IdeSlave.AddMissing line name) =
323− process stdout fn (AddMissing False line (sUN name))
324−runIdeSlaveCommand id orig fn mods (IdeSlave.MakeWithBlock line name) =
325− process stdout fn (MakeWith False line (sUN name))
326−runIdeSlaveCommand id orig fn mods (IdeSlave.ProofSearch r line name hints depth) =
327− doProofSearch stdout fn False r line (sUN name) (map sUN hints) depth
328−runIdeSlaveCommand id orig fn mods (IdeSlave.MakeLemma line name) =
344+ Right n -> process "(ideslave)" (DocStr (Left n))
345+runIdeSlaveCommand h id orig fn mods (IdeSlave.CaseSplit line name) =
346+ process fn (CaseSplitAt False line (sUN name))
347+runIdeSlaveCommand h id orig fn mods (IdeSlave.AddClause line name) =
348+ process fn (AddClauseFrom False line (sUN name))
349+runIdeSlaveCommand h id orig fn mods (IdeSlave.AddProofClause line name) =
350+ process fn (AddProofClauseFrom False line (sUN name))
351+runIdeSlaveCommand h id orig fn mods (IdeSlave.AddMissing line name) =
352+ process fn (AddMissing False line (sUN name))
353+runIdeSlaveCommand h id orig fn mods (IdeSlave.MakeWithBlock line name) =
354+ process fn (MakeWith False line (sUN name))
355+runIdeSlaveCommand h id orig fn mods (IdeSlave.ProofSearch r line name hints depth) =
356+ doProofSearch fn False r line (sUN name) (map sUN hints) depth
357+runIdeSlaveCommand h id orig fn mods (IdeSlave.MakeLemma line name) =
329358 case splitName name of
330359 Left err -> iPrintError err
331− Right n -> process stdout fn (MakeLemma False line n)
332−runIdeSlaveCommand id orig fn mods (IdeSlave.Apropos a) =
333− process stdout fn (Apropos a)
334−runIdeSlaveCommand id orig fn mods (IdeSlave.GetOpts) =
360+ Right n -> process fn (MakeLemma False line n)
361+runIdeSlaveCommand h id orig fn mods (IdeSlave.Apropos a) =
362+ process fn (Apropos a)
363+runIdeSlaveCommand h id orig fn mods (IdeSlave.GetOpts) =
335364 do ist <- getIState
336365 let opts = idris_options ist
337366 let impshow = opt_showimp opts
@@ -339,16 +368,16 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.GetOpts) =
339368 let options = (IdeSlave.SymbolAtom "ok",
340369 [(IdeSlave.SymbolAtom "show-implicits", impshow),
341370 (IdeSlave.SymbolAtom "error-context", errCtxt)])
342− runIO . putStrLn $ IdeSlave.convSExp "return" options id
343−runIdeSlaveCommand id orig fn mods (IdeSlave.SetOpt IdeSlave.ShowImpl b) =
371+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" options id
372+runIdeSlaveCommand h id orig fn mods (IdeSlave.SetOpt IdeSlave.ShowImpl b) =
344373 do setImpShow b
345374 let msg = (IdeSlave.SymbolAtom "ok", b)
346− runIO . putStrLn $ IdeSlave.convSExp "return" msg id
347−runIdeSlaveCommand id orig fn mods (IdeSlave.SetOpt IdeSlave.ErrContext b) =
375+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
376+runIdeSlaveCommand h id orig fn mods (IdeSlave.SetOpt IdeSlave.ErrContext b) =
348377 do setErrContext b
349378 let msg = (IdeSlave.SymbolAtom "ok", b)
350− runIO . putStrLn $ IdeSlave.convSExp "return" msg id
351−runIdeSlaveCommand id orig fn mods (IdeSlave.Metavariables cols) =
379+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
380+runIdeSlaveCommand h id orig fn mods (IdeSlave.Metavariables cols) =
352381 do ist <- getIState
353382 let mvs = reverse $ map fst (idris_metavars ist) \\ primDefs
354383 let ppo = ppOptionIst ist
@@ -364,7 +393,7 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.Metavariables cols) =
364393 (zip bnds hs),
365394 render ist bnd c pc))
366395 splitMvs
367− runIO . putStrLn $
396+ runIO . hPutStrLn h $
368397 IdeSlave.convSExp "return" (IdeSlave.SymbolAtom "ok", mvOutput) id
369398 where mapPair f g xs = zip (map (f . fst) xs) (map (g . snd) xs)
370399 mapSnd f xs = zip (map fst xs) (map (f . snd) xs)
@@ -409,32 +438,32 @@ runIdeSlaveCommand id orig fn mods (IdeSlave.Metavariables cols) =
409438 let (out, spans) = render ist bnd t pt in
410439 (show n , out, spans)
411440
412−runIdeSlaveCommand id orig fn mods (IdeSlave.WhoCalls n) =
441+runIdeSlaveCommand h id orig fn mods (IdeSlave.WhoCalls n) =
413442 case splitName n of
414443 Left err -> iPrintError err
415444 Right n -> do calls <- whoCalls n
416445 ist <- getIState
417446 let msg = (IdeSlave.SymbolAtom "ok",
418447 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
420449 where pn ist = displaySpans .
421450 renderPretty 0.9 1000 .
422451 fmap (fancifyAnnots ist) .
423452 prettyName True True []
424−runIdeSlaveCommand id orig fn mods (IdeSlave.CallsWho n) =
453+runIdeSlaveCommand h id orig fn mods (IdeSlave.CallsWho n) =
425454 case splitName n of
426455 Left err -> iPrintError err
427456 Right n -> do calls <- callsWho n
428457 ist <- getIState
429458 let msg = (IdeSlave.SymbolAtom "ok",
430459 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
432461 where pn ist = displaySpans .
433462 renderPretty 0.9 1000 .
434463 fmap (fancifyAnnots ist) .
435464 prettyName True True []
436465
437−runIdeSlaveCommand id orig fn modes (IdeSlave.TermNormalise bnd tm) =
466+runIdeSlaveCommand h id orig fn modes (IdeSlave.TermNormalise bnd tm) =
438467 do ctxt <- getContext
439468 ist <- getIState
440469 let tm' = force (normaliseAll ctxt [] tm)
@@ -448,15 +477,15 @@ runIdeSlaveCommand id orig fn modes (IdeSlave.TermNormalise bnd tm) =
448477 displaySpans .
449478 renderPretty 0.9 80 .
450479 fmap (fancifyAnnots ist) $ ptm)
451− runIO . putStrLn $ IdeSlave.convSExp "return" msg id
452−runIdeSlaveCommand id orig fn modes (IdeSlave.TermShowImplicits bnd tm) =
453− ideSlaveForceTermImplicits id bnd True tm
454−runIdeSlaveCommand id orig fn modes (IdeSlave.TermNoImplicits bnd tm) =
455− ideSlaveForceTermImplicits id bnd False tm
480+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
481+runIdeSlaveCommand h id orig fn modes (IdeSlave.TermShowImplicits bnd tm) =
482+ ideSlaveForceTermImplicits h id bnd True tm
483+runIdeSlaveCommand h id orig fn modes (IdeSlave.TermNoImplicits bnd tm) =
484+ ideSlaveForceTermImplicits h id bnd False tm
456485
457486-- | Show a term for IDESlave with the specified implicitness
458−ideSlaveForceTermImplicits :: Integer -> [(Name, Bool)] -> Bool -> Term -> Idris ()
459−ideSlaveForceTermImplicits id bnd impl tm =
487+ideSlaveForceTermImplicits :: Handle -> Integer -> [(Name, Bool)] -> Bool -> Term -> Idris ()
488+ideSlaveForceTermImplicits h id bnd impl tm =
460489 do ist <- getIState
461490 let expl = annotate (AnnTerm bnd tm)
462491 (pprintPTerm ((ppOptionIst ist) { ppopt_impl = impl })
@@ -466,7 +495,7 @@ ideSlaveForceTermImplicits id bnd impl tm =
466495 displaySpans .
467496 renderPretty 0.9 80 .
468497 fmap (fancifyAnnots ist) $ expl)
469− runIO . putStrLn $ IdeSlave.convSExp "return" msg id
498+ runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
470499
471500splitName :: String -> Either String Name
472501splitName s = case reverse $ splitOn "." s of
@@ -475,70 +504,70 @@ splitName s = case reverse $ splitOn "." s of
475504 (n:ns) -> Right $ sNS (sUN n) ns
476505
477506ideslaveProcess :: FilePath -> Command -> Idris ()
478−ideslaveProcess fn Warranty = process stdout fn Warranty
479−ideslaveProcess fn Help = process stdout fn Help
480−ideslaveProcess fn (ChangeDirectory f) = do process stdout fn (ChangeDirectory f)
507+ideslaveProcess fn Warranty = process fn Warranty
508+ideslaveProcess fn Help = process fn Help
509+ideslaveProcess fn (ChangeDirectory f) = do process fn (ChangeDirectory f)
481510 iPrintResult "changed directory to"
482−ideslaveProcess fn (Eval t) = process stdout fn (Eval t)
483−ideslaveProcess fn (NewDefn decls) = do process stdout fn (NewDefn decls)
511+ideslaveProcess fn (Eval t) = process fn (Eval t)
512+ideslaveProcess fn (NewDefn decls) = do process fn (NewDefn decls)
484513 iPrintResult "defined"
485−ideslaveProcess fn (ExecVal t) = process stdout fn (ExecVal t)
486−ideslaveProcess fn (Check (PRef x n)) = process stdout fn (Check (PRef x n))
487−ideslaveProcess fn (Check t) = process stdout fn (Check t)
488−ideslaveProcess fn (DocStr n) = process stdout fn (DocStr n)
489−ideslaveProcess fn Universes = process stdout fn Universes
490−ideslaveProcess fn (Defn n) = do process stdout fn (Defn n)
514+ideslaveProcess fn (ExecVal t) = process fn (ExecVal t)
515+ideslaveProcess fn (Check (PRef x n)) = process fn (Check (PRef x n))
516+ideslaveProcess fn (Check t) = process fn (Check t)
517+ideslaveProcess fn (DocStr n) = process fn (DocStr n)
518+ideslaveProcess fn Universes = process fn Universes
519+ideslaveProcess fn (Defn n) = do process fn (Defn n)
491520 iPrintResult ""
492−ideslaveProcess fn (TotCheck n) = process stdout fn (TotCheck n)
493−ideslaveProcess fn (DebugInfo n) = do process stdout fn (DebugInfo n)
521+ideslaveProcess fn (TotCheck n) = process fn (TotCheck n)
522+ideslaveProcess fn (DebugInfo n) = do process fn (DebugInfo n)
494523 iPrintResult ""
495−ideslaveProcess fn (Search t) = process stdout fn (Search t)
496−ideslaveProcess fn (Spec t) = process stdout fn (Spec t)
524+ideslaveProcess fn (Search t) = process fn (Search t)
525+ideslaveProcess fn (Spec t) = process fn (Spec t)
497526-- RmProof and AddProof not supported!
498−ideslaveProcess fn (ShowProof n') = process stdout fn (ShowProof n')
499−ideslaveProcess fn (HNF t) = process stdout fn (HNF t)
500−--ideslaveProcess fn TTShell = process stdout fn TTShell -- need some prove mode!
501−ideslaveProcess fn (TestInline t) = process stdout fn (TestInline t)
527+ideslaveProcess fn (ShowProof n') = process fn (ShowProof n')
528+ideslaveProcess fn (HNF t) = process fn (HNF t)
529+--ideslaveProcess fn TTShell = process fn TTShell -- need some prove mode!
530+ideslaveProcess fn (TestInline t) = process fn (TestInline t)
502531
503−ideslaveProcess fn Execute = do process stdout fn Execute
532+ideslaveProcess fn Execute = do process fn Execute
504533 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)
506535 iPrintResult ""
507−ideslaveProcess fn (LogLvl i) = do process stdout fn (LogLvl i)
536+ideslaveProcess fn (LogLvl i) = do process fn (LogLvl i)
508537 iPrintResult ""
509−ideslaveProcess fn (Pattelab t) = process stdout fn (Pattelab t)
510−ideslaveProcess fn (Missing n) = process stdout fn (Missing n)
511−ideslaveProcess fn (DynamicLink l) = do process stdout fn (DynamicLink l)
538+ideslaveProcess fn (Pattelab t) = process fn (Pattelab t)
539+ideslaveProcess fn (Missing n) = process fn (Missing n)
540+ideslaveProcess fn (DynamicLink l) = do process fn (DynamicLink l)
512541 iPrintResult ""
513−ideslaveProcess fn ListDynamic = do process stdout fn ListDynamic
542+ideslaveProcess fn ListDynamic = do process fn ListDynamic
514543 iPrintResult ""
515−ideslaveProcess fn Metavars = process stdout fn Metavars
516−ideslaveProcess fn (SetOpt ErrContext) = do process stdout fn (SetOpt ErrContext)
544+ideslaveProcess fn Metavars = process fn Metavars
545+ideslaveProcess fn (SetOpt ErrContext) = do process fn (SetOpt ErrContext)
517546 iPrintResult ""
518−ideslaveProcess fn (UnsetOpt ErrContext) = do process stdout fn (UnsetOpt ErrContext)
547+ideslaveProcess fn (UnsetOpt ErrContext) = do process fn (UnsetOpt ErrContext)
519548 iPrintResult ""
520−ideslaveProcess fn (SetOpt ShowImpl) = do process stdout fn (SetOpt ShowImpl)
549+ideslaveProcess fn (SetOpt ShowImpl) = do process fn (SetOpt ShowImpl)
521550 iPrintResult ""
522−ideslaveProcess fn (UnsetOpt ShowImpl) = do process stdout fn (UnsetOpt ShowImpl)
551+ideslaveProcess fn (UnsetOpt ShowImpl) = do process fn (UnsetOpt ShowImpl)
523552 iPrintResult ""
524−ideslaveProcess fn (SetOpt ShowOrigErr) = do process stdout fn (SetOpt ShowOrigErr)
553+ideslaveProcess fn (SetOpt ShowOrigErr) = do process fn (SetOpt ShowOrigErr)
525554 iPrintResult ""
526−ideslaveProcess fn (UnsetOpt ShowOrigErr) = do process stdout fn (UnsetOpt ShowOrigErr)
555+ideslaveProcess fn (UnsetOpt ShowOrigErr) = do process fn (UnsetOpt ShowOrigErr)
527556 iPrintResult ""
528−ideslaveProcess fn (SetOpt x) = process stdout fn (SetOpt x)
529−ideslaveProcess fn (UnsetOpt x) = process stdout fn (UnsetOpt x)
530−ideslaveProcess fn (CaseSplitAt False pos str) = process stdout fn (CaseSplitAt False pos str)
531−ideslaveProcess fn (AddProofClauseFrom False pos str) = process stdout fn (AddProofClauseFrom False pos str)
532−ideslaveProcess fn (AddClauseFrom False pos str) = process stdout fn (AddClauseFrom False pos str)
533−ideslaveProcess fn (AddMissing False pos str) = process stdout fn (AddMissing False pos str)
534−ideslaveProcess fn (MakeWith False pos str) = process stdout fn (MakeWith False pos str)
535−ideslaveProcess fn (DoProofSearch False r pos str xs) = process stdout fn (DoProofSearch False r pos str xs)
536−ideslaveProcess fn (SetConsoleWidth w) = do process stdout fn (SetConsoleWidth w)
557+ideslaveProcess fn (SetOpt x) = process fn (SetOpt x)
558+ideslaveProcess fn (UnsetOpt x) = process fn (UnsetOpt x)
559+ideslaveProcess fn (CaseSplitAt False pos str) = process fn (CaseSplitAt False pos str)
560+ideslaveProcess fn (AddProofClauseFrom False pos str) = process fn (AddProofClauseFrom False pos str)
561+ideslaveProcess fn (AddClauseFrom False pos str) = process fn (AddClauseFrom False pos str)
562+ideslaveProcess fn (AddMissing False pos str) = process fn (AddMissing False pos str)
563+ideslaveProcess fn (MakeWith False pos str) = process fn (MakeWith False pos str)
564+ideslaveProcess fn (DoProofSearch False r pos str xs) = process fn (DoProofSearch False r pos str xs)
565+ideslaveProcess fn (SetConsoleWidth w) = do process fn (SetConsoleWidth w)
537566 iPrintResult ""
538−ideslaveProcess fn (Apropos a) = do process stdout fn (Apropos a)
567+ideslaveProcess fn (Apropos a) = do process fn (Apropos a)
539568 iPrintResult ""
540−ideslaveProcess fn (WhoCalls n) = process stdout fn (WhoCalls n)
541−ideslaveProcess fn (CallsWho n) = process stdout fn (CallsWho n)
569+ideslaveProcess fn (WhoCalls n) = process fn (WhoCalls n)
570+ideslaveProcess fn (CallsWho n) = process fn (CallsWho n)
542571ideslaveProcess fn _ = iPrintError "command not recognized or not supported"
543572
544573
@@ -570,18 +599,18 @@ processInput cmd orig inputs
570599 , idris_colourTheme = idris_colourTheme i
571600 }
572601 clearErr
573− mods <- loadInputs stdout inputs Nothing
602+ mods <- loadInputs inputs Nothing
574603 return (Just inputs)
575604 Success (Load f toline) ->
576605 do putIState orig { idris_options = idris_options i
577606 , idris_colourTheme = idris_colourTheme i
578607 }
579608 clearErr
580− mod <- loadInputs stdout [f] toline
609+ mod <- loadInputs [f] toline
581610 return (Just [f])
582611 Success (ModImport f) ->
583612 do clearErr
584− fmod <- loadModule stdout f
613+ fmod <- loadModule f
585614 return (Just (inputs ++ [fmod]))
586615 Success Edit -> do -- takeMVar stvar
587616 edit fn orig
@@ -590,7 +619,7 @@ processInput cmd orig inputs
590619 return (Just inputs)
591620 Success Quit -> do when (not quiet) (iputStrLn "Bye bye")
592621 return Nothing
593− Success cmd -> do idrisCatch (process stdout fn cmd)
622+ Success cmd -> do idrisCatch (process fn cmd)
594623 (\e -> do msg <- showErr e ; iputStrLn msg)
595624 return (Just inputs)
596625
@@ -626,7 +655,7 @@ edit f orig
626655 putIState $ orig { idris_options = idris_options i
627656 , idris_colourTheme = idris_colourTheme i
628657 }
629− loadInputs stdout [f] Nothing
658+ loadInputs [f] Nothing
630659-- clearOrigPats
631660 iucheck
632661 return ()
@@ -652,13 +681,13 @@ insertScript prf (p@"---------- Proofs ----------" : "" : xs)
652681 = p : "" : prf : xs
653682insertScript prf (x : xs) = x : insertScript prf xs
654683
655−process :: Handle -> FilePath -> Command -> Idris ()
656−process h fn Help = iPrintResult displayHelp
657−process h fn Warranty = iPrintResult warranty
658−process h fn (ChangeDirectory f)
684+process :: FilePath -> Command -> Idris ()
685+process fn Help = iPrintResult displayHelp
686+process fn Warranty = iPrintResult warranty
687+process fn (ChangeDirectory f)
659688 = do runIO $ setCurrentDirectory f
660689 return ()
661−process h fn (Eval t)
690+process fn (Eval t)
662691 = withErrorReflection $ do logLvl 5 $ show t
663692 (tm, ty) <- elabVal recinfo ERHS t
664693 ctxt <- getContext
@@ -671,10 +700,10 @@ process h fn (Eval t)
671700 logLvl 10 $ "Debug: " ++ showEnvDbg [] tm'
672701 let tmDoc = pprintDelab ist tm'
673702 tyDoc = pprintDelab ist ty'
674− ihPrintTermWithType h tmDoc tyDoc
703+ iPrintTermWithType tmDoc tyDoc
675704
676705
677−process h fn (NewDefn decls) = do
706+process fn (NewDefn decls) = do
678707 logLvl 3 ("Defining names using these decls: " ++ show (showDecls verbosePPOption decls))
679708 mapM_ defineName namedGroups where
680709 namedGroups = groupBy (\d1 d2 -> getName d1 == getName d2) decls
@@ -732,7 +761,7 @@ process h fn (NewDefn decls) = do
732761 PInstance syn fc constraints cls parms ty instName (map fixClauses decls)
733762 fixClauses decl = decl
734763
735−process h fn (Undefine names) = undefine names
764+process fn (Undefine names) = undefine names
736765 where
737766 undefine :: [Name] -> Idris ()
738767 undefine [] = do
@@ -741,7 +770,7 @@ process h fn (Undefine names) = undefine names
741770 -- Keep track of which names you've removed so you can
742771 -- print them out to the user afterward
743772 undefine names = undefine' names []
744− undefine' [] list = do ihputStrLn h (show list)
773+ undefine' [] list = do iputStrLn (show list)
745774 return ()
746775 undefine' (n:names) already = do
747776 allDefined <- idris_repl_defs `fmap` get
@@ -764,7 +793,7 @@ process h fn (Undefine names) = undefine names
764793
765794
766795
767−process h fn (ExecVal t)
796+process fn (ExecVal t)
768797 = do ctxt <- getContext
769798 ist <- getIState
770799 (tm, ty) <- elabVal recinfo ERHS t
@@ -773,19 +802,19 @@ process h fn (ExecVal t)
773802 res <- execute tm
774803 let (resOut, tyOut) = (prettyIst ist (delab ist res),
775804 prettyIst ist (delab ist ty'))
776− ihPrintTermWithType h resOut tyOut
805+ iPrintTermWithType resOut tyOut
777806
778−process h fn (Check (PRef _ n))
807+process fn (Check (PRef _ n))
779808 = do ctxt <- getContext
780809 ist <- getIState
781810 let ppo = ppOptionIst ist
782811 case lookupNames n ctxt of
783812 ts@(t:_) ->
784813 case lookup t (idris_metavars ist) of
785− Just (_, i, _) -> ihRenderResult h . fmap (fancifyAnnots ist) $
814+ Just (_, i, _) -> iRenderResult . fmap (fancifyAnnots ist) $
786815 showMetavarInfo ppo ist n i
787− Nothing -> ihPrintFunTypes h [] n (map (\n -> (n, delabTy ist n)) ts)
788− [] -> ihPrintError h $ "No such variable " ++ show n
816+ Nothing -> iPrintFunTypes [] n (map (\n -> (n, delabTy ist n)) ts)
817+ [] -> iPrintError $ "No such variable " ++ show n
789818 where
790819 showMetavarInfo ppo ist n i
791820 = case lookupTy n (tt_ctxt ist) of
@@ -810,7 +839,7 @@ process h fn (Check (PRef _ n))
810839 tPretty bnd ist t = pprintPTerm (ppOptionIst ist) bnd [] (idris_infixes ist) t
811840
812841
813−process h fn (Check t)
842+process fn (Check t)
814843 = do (tm, ty) <- elabVal recinfo ERHS t
815844 ctxt <- getContext
816845 ist <- getIState
@@ -818,24 +847,24 @@ process h fn (Check t)
818847 ty' = normaliseC ctxt [] ty
819848 case tm of
820849 TType _ ->
821− ihPrintTermWithType h (prettyIst ist PType) type1Doc
822− _ -> ihPrintTermWithType h (pprintDelab ist tm)
823− (pprintDelab ist ty)
850+ iPrintTermWithType (prettyIst ist PType) type1Doc
851+ _ -> iPrintTermWithType (pprintDelab ist tm)
852+ (pprintDelab ist ty)
824853
825−process h fn (DocStr (Left n))
854+process fn (DocStr (Left n))
826855 = do ist <- getIState
827856 case lookupCtxtName n (idris_docstrings ist) of
828857 [] -> iPrintError $ "No documentation for " ++ show n
829858 ns -> do toShow <- mapM (showDoc ist) ns
830− ihRenderResult h (vsep toShow)
859+ iRenderResult (vsep toShow)
831860 where showDoc ist (n, d) = do doc <- getDocs n
832861 return $ pprintDocs ist doc
833862
834−process h fn (DocStr (Right c))
863+process fn (DocStr (Right c))
835864 = do ist <- getIState
836− ihRenderResult h $ pprintConstDocs ist c (constDocs c)
865+ iRenderResult $ pprintConstDocs ist c (constDocs c)
837866
838−process h fn Universes
867+process fn Universes
839868 = do i <- getIState
840869 let cs = idris_constraints i
841870-- iputStrLn $ showSep "\n" (map show cs)
@@ -845,7 +874,7 @@ process h fn Universes
845874 case ucheck cs of
846875 Error e -> iPrintError $ pshow i e
847876 OK _ -> iPrintResult "Universes OK"
848−process h fn (Defn n)
877+process fn (Defn n)
849878 = do i <- getIState
850879 iputStrLn "Compiled patterns:\n"
851880 iputStrLn $ show (lookupDef n (tt_ctxt i))
@@ -860,20 +889,20 @@ process h fn (Defn n)
860889 = let i' = i { idris_options = (idris_options i) { opt_showimp = True } }
861890 in iputStrLn (showTm i' (delab i lhs) ++ " = " ++
862891 showTm i' (delab i rhs))
863−process h fn (TotCheck n)
892+process fn (TotCheck n)
864893 = do i <- getIState
865894 case lookupNameTotal n (tt_ctxt i) of
866− [] -> ihPrintError h $ "Unknown operator " ++ show n
895+ [] -> iPrintError $ "Unknown operator " ++ show n
867896 ts -> do ist <- getIState
868897 c <- colourise
869898 let ppo = ppOptionIst ist
870899 let showN = showName (Just ist) [] ppo c
871− ihPrintResult h . concat . intersperse "\n" .
900+ iPrintResult . concat . intersperse "\n" .
872901 map (\(n, t) -> showN n ++ " is " ++ showTotal t i) $
873902 ts
874903
875904
876−process h fn (DebugInfo n)
905+process fn (DebugInfo n)
877906 = do i <- getIState
878907 let oi = lookupCtxtName n (idris_optimisation i)
879908 when (not (null oi)) $ iputStrLn (show oi)
@@ -890,29 +919,29 @@ process h fn (DebugInfo n)
890919 iputStrLn $ "Size change: " ++ show sc
891920 when (not (null cg')) $ do iputStrLn "Call graph:\n"
892921 iputStrLn (show cg')
893−process h fn (Search t) = searchByType h t
894−process h fn (CaseSplitAt updatefile l n)
895− = caseSplitAt h fn updatefile l n
896−process h fn (AddClauseFrom updatefile l n)
897− = addClauseFrom h fn updatefile l n
898−process h fn (AddProofClauseFrom updatefile l n)
899− = addProofClauseFrom h fn updatefile l n
900−process h fn (AddMissing updatefile l n)
901− = addMissing h fn updatefile l n
902−process h fn (MakeWith updatefile l n)
903− = makeWith h fn updatefile l n
904−process h fn (MakeLemma updatefile l n)
905− = makeLemma h fn updatefile l n
906−process h fn (DoProofSearch updatefile rec l n hints)
907− = doProofSearch h fn updatefile rec l n hints Nothing
908−process h fn (Spec t)
922+process fn (Search t) = searchByType t
923+process fn (CaseSplitAt updatefile l n)
924+ = caseSplitAt fn updatefile l n
925+process fn (AddClauseFrom updatefile l n)
926+ = addClauseFrom fn updatefile l n
927+process fn (AddProofClauseFrom updatefile l n)
928+ = addProofClauseFrom fn updatefile l n
929+process fn (AddMissing updatefile l n)
930+ = addMissing fn updatefile l n
931+process fn (MakeWith updatefile l n)
932+ = makeWith fn updatefile l n
933+process fn (MakeLemma updatefile l n)
934+ = makeLemma fn updatefile l n
935+process fn (DoProofSearch updatefile rec l n hints)
936+ = doProofSearch fn updatefile rec l n hints Nothing
937+process fn (Spec t)
909938 = do (tm, ty) <- elabVal recinfo ERHS t
910939 ctxt <- getContext
911940 ist <- getIState
912941 let tm' = simplify ctxt [] {- (idris_statics ist) -} tm
913942 iPrintResult (show (delab ist tm'))
914943
915−process h fn (RmProof n')
944+process fn (RmProof n')
916945 = do i <- getIState
917946 n <- resolveProof n'
918947 let proofs = proof_list i
@@ -928,7 +957,7 @@ process h fn (RmProof n')
928957 let ms = idris_metavars i
929958 putIState $ i { idris_metavars = (n, (Nothing, 0, False)) : ms }
930959
931−process h fn' (AddProof prf)
960+process fn' (AddProof prf)
932961 = do fn <- do
933962 let fn'' = takeWhile (/= ' ') fn'
934963 ex <- runIO $ doesFileExist fn''
@@ -958,7 +987,7 @@ process h fn' (AddProof prf)
958987 iputStrLn $ "Added proof " ++ show n
959988 where ls = (lines prog)
960989
961−process h fn (ShowProof n')
990+process fn (ShowProof n')
962991 = do i <- getIState
963992 n <- resolveProof n'
964993 let proofs = proof_list i
@@ -966,7 +995,7 @@ process h fn (ShowProof n')
966995 Nothing -> iPrintError "No proof to show"
967996 Just p -> iPrintResult $ showProof False n p
968997
969−process h fn (Prove n')
998+process fn (Prove n')
970999 = do ctxt <- getContext
9711000 ist <- getIState
9721001 let ns = lookupNames n' ctxt
@@ -984,20 +1013,20 @@ process h fn (Prove n')
9841013 mapM_ checkDeclTotality (idris_totcheck i)
9851014 warnTotality
9861015
987−process h fn (HNF t)
1016+process fn (HNF t)
9881017 = do (tm, ty) <- elabVal recinfo ERHS t
9891018 ctxt <- getContext
9901019 ist <- getIState
9911020 let tm' = hnf ctxt [] tm
9921021 iPrintResult (show (delab ist tm'))
993−process h fn (TestInline t)
1022+process fn (TestInline t)
9941023 = do (tm, ty) <- elabVal recinfo ERHS t
9951024 ctxt <- getContext
9961025 ist <- getIState
9971026 let tm' = inlineTerm ist tm
9981027 c <- colourise
9991028 iPrintResult (showTm ist (delab ist tm'))
1000−process h fn Execute
1029+process fn Execute
10011030 = idrisCatch
10021031 (do ist <- getIState
10031032 (m, _) <- elabVal recinfo ERHS
@@ -1009,33 +1038,33 @@ process h fn Execute
10091038 t <- codegen
10101039 compile t tmpn m
10111040 case idris_outputmode ist of
1012− RawOutput -> do runIO $ system tmpn
1013− return ()
1014− IdeSlave n -> runIO . hPutStrLn h $
1015− IdeSlave.convSExp "run-program" tmpn n)
1016− (\e -> getIState >>= ihRenderError stdout . flip pprintErr e)
1041+ RawOutput h -> do runIO $ system tmpn
1042+ return ()
1043+ IdeSlave n h -> runIO . hPutStrLn h $
1044+ IdeSlave.convSExp "run-program" tmpn n)
1045+ (\e -> getIState >>= iRenderError . flip pprintErr e)
10171046 where fc = fileFC "main"
1018−process h fn (Compile codegen f)
1047+process fn (Compile codegen f)
10191048 = do (m, _) <- elabVal recinfo ERHS
10201049 (PApp fc (PRef fc (sUN "run__IO"))
10211050 [pexp $ PRef fc (sNS (sUN "main") ["Main"])])
10221051 compile codegen f m
10231052 where fc = fileFC "main"
1024−process h fn (LogLvl i) = setLogLevel i
1053+process fn (LogLvl i) = setLogLevel i
10251054-- Elaborate as if LHS of a pattern (debug command)
1026−process h fn (Pattelab t)
1055+process fn (Pattelab t)
10271056 = do (tm, ty) <- elabVal recinfo ELHS t
10281057 iPrintResult $ show tm ++ "\n\n : " ++ show ty
10291058
1030−process h fn (Missing n)
1059+process fn (Missing n)
10311060 = do i <- getIState
10321061 let i' = i { idris_options = (idris_options i) { opt_showimp = True } }
10331062 case lookupCtxt n (idris_patdefs i) of
1034− [] -> ihPrintError h $ "Unknown operator " ++ show n
1063+ [] -> iPrintError $ "Unknown operator " ++ show n
10351064 [(_, tms)] ->
10361065 iPrintResult (showSep "\n" (map (showTm i') tms))
10371066 _ -> iPrintError $ "Ambiguous name"
1038−process h fn (DynamicLink l)
1067+process fn (DynamicLink l)
10391068 = do i <- getIState
10401069 let importdirs = opt_importdirs (idris_options i)
10411070 lib = trim l
@@ -1048,80 +1077,80 @@ process h fn (DynamicLink l)
10481077 return ()
10491078 else putIState $ i { idris_dynamic_libs = x:libs }
10501079 where trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace
1051−process h fn ListDynamic
1080+process fn ListDynamic
10521081 = do i <- getIState
10531082 iputStrLn "Dynamic libraries:"
10541083 showLibs $ idris_dynamic_libs i
10551084 where showLibs [] = return ()
10561085 showLibs ((Lib name _):ls) = do iputStrLn $ "\t" ++ name; showLibs ls
1057−process h fn Metavars
1086+process fn Metavars
10581087 = do ist <- getIState
10591088 let mvs = map fst (idris_metavars ist) \\ primDefs
10601089 case mvs of
10611090 [] -> iPrintError "No global metavariables to solve"
10621091 _ -> iPrintResult $ "Global metavariables:\n\t" ++ show mvs
1063−process h fn NOP = return ()
1064−
1065−process h fn (SetOpt ErrContext) = setErrContext True
1066−process h fn (UnsetOpt ErrContext) = setErrContext False
1067−process h fn (SetOpt ShowImpl) = setImpShow True
1068−process h fn (UnsetOpt ShowImpl) = setImpShow False
1069−process h fn (SetOpt ShowOrigErr) = setShowOrigErr True
1070−process h fn (UnsetOpt ShowOrigErr) = setShowOrigErr False
1071−process h fn (SetOpt AutoSolve) = setAutoSolve True
1072−process h fn (UnsetOpt AutoSolve) = setAutoSolve False
1073−process h fn (SetOpt NoBanner) = setNoBanner True
1074−process h fn (UnsetOpt NoBanner) = setNoBanner False
1075−process h fn (SetOpt WarnReach) = fmodifyState opts_idrisCmdline $ nub . (WarnReach:)
1076−process h fn (UnsetOpt WarnReach) = fmodifyState opts_idrisCmdline $ delete WarnReach
1077−
1078−process h fn (SetOpt _) = iPrintError "Not a valid option"
1079−process h fn (UnsetOpt _) = iPrintError "Not a valid option"
1080−process h fn (SetColour ty c) = setColour ty c
1081−process h fn ColourOn
1092+process fn NOP = return ()
1093+
1094+process fn (SetOpt ErrContext) = setErrContext True
1095+process fn (UnsetOpt ErrContext) = setErrContext False
1096+process fn (SetOpt ShowImpl) = setImpShow True
1097+process fn (UnsetOpt ShowImpl) = setImpShow False
1098+process fn (SetOpt ShowOrigErr) = setShowOrigErr True
1099+process fn (UnsetOpt ShowOrigErr) = setShowOrigErr False
1100+process fn (SetOpt AutoSolve) = setAutoSolve True
1101+process fn (UnsetOpt AutoSolve) = setAutoSolve False
1102+process fn (SetOpt NoBanner) = setNoBanner True
1103+process fn (UnsetOpt NoBanner) = setNoBanner False
1104+process fn (SetOpt WarnReach) = fmodifyState opts_idrisCmdline $ nub . (WarnReach:)
1105+process fn (UnsetOpt WarnReach) = fmodifyState opts_idrisCmdline $ delete WarnReach
1106+
1107+process fn (SetOpt _) = iPrintError "Not a valid option"
1108+process fn (UnsetOpt _) = iPrintError "Not a valid option"
1109+process fn (SetColour ty c) = setColour ty c
1110+process fn ColourOn
10821111 = do ist <- getIState
10831112 putIState $ ist { idris_colourRepl = True }
1084−process h fn ColourOff
1113+process fn ColourOff
10851114 = do ist <- getIState
10861115 putIState $ ist { idris_colourRepl = False }
1087−process h fn ListErrorHandlers =
1116+process fn ListErrorHandlers =
10881117 do ist <- getIState
10891118 iPrintResult $ case idris_errorhandlers ist of
10901119 [] -> "No registered error handlers"
10911120 handlers -> "Registered error handlers: " ++ (concat . intersperse ", " . map show) handlers
1092−process h fn (SetConsoleWidth w) = setWidth w
1121+process fn (SetConsoleWidth w) = setWidth w
10931122
1094−process h fn (Apropos a) =
1123+process fn (Apropos a) =
10951124 do ist <- getIState
10961125 let names = apropos ist (T.pack a)
10971126 let aproposInfo = [ (n,
10981127 delabTy ist n,
10991128 fmap (overview . fst) (lookupCtxtExact n (idris_docstrings ist)))
11001129 | n <- sort names, isUN n ]
1101− ihRenderResult h $ vsep (map (prettyDocumentedIst ist) aproposInfo)
1130+ iRenderResult $ vsep (map (prettyDocumentedIst ist) aproposInfo)
11021131 where isUN (UN _) = True
11031132 isUN (NS n _) = isUN n
11041133 isUN _ = False
11051134
1106−process h fn (WhoCalls n) =
1135+process fn (WhoCalls n) =
11071136 do calls <- whoCalls n
11081137 ist <- getIState
1109− ihRenderResult h . vsep $
1138+ iRenderResult . vsep $
11101139 map (\(n, ns) ->
11111140 text "Callers of" <+> prettyName True True [] n <$>
11121141 indent 1 (vsep (map ((text "*" <+>) . align . prettyName True True []) ns)))
11131142 calls
11141143
1115−process h fn (CallsWho n) =
1144+process fn (CallsWho n) =
11161145 do calls <- callsWho n
11171146 ist <- getIState
1118− ihRenderResult h . vsep $
1147+ iRenderResult . vsep $
11191148 map (\(n, ns) ->
11201149 prettyName True True [] n <+> text "calls:" <$>
11211150 indent 1 (vsep (map ((text "*" <+>) . align . prettyName True True []) ns)))
11221151 calls
11231152-- IdrisDoc
1124−process h fn (MakeDoc s) =
1153+process fn (MakeDoc s) =
11251154 do istate <- getIState
11261155 let names = words s
11271156 parse n | Success x <- runparser name istate fn n = Right x
@@ -1178,8 +1207,8 @@ idris opts = do res <- runErrorT $ execStateT totalMain idrisInit
11781207 [] -> return ()
11791208
11801209
1181−loadInputs :: Handle -> [FilePath] -> Maybe Int -> Idris ()
1182−loadInputs h inputs toline -- furthest line to read in input source files
1210+loadInputs :: [FilePath] -> Maybe Int -> Idris ()
1211+loadInputs inputs toline -- furthest line to read in input source files
11831212 = idrisCatch
11841213 (do ist <- getIState
11851214 -- 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
12311260 (\e -> do i <- getIState
12321261 case e of
12331262 At f e' -> do setErrSpan f
1234− ihWarn stdout f $ pprintErr i e'
1263+ iWarn f $ pprintErr i e'
12351264 ProgramLineComment -> return () -- fail elsewhere
12361265 _ -> do setErrSpan emptyFC -- FIXME! Propagate it
1237− ihWarn stdout emptyFC $ pprintErr i e)
1266+ iWarn emptyFC $ pprintErr i e)
12381267 where -- load all files, stop if any fail
12391268 tryLoad :: Bool -> [IFileType] -> Idris ()
12401269 tryLoad keepstate [] = warnTotality >> return ()
@@ -1251,7 +1280,7 @@ loadInputs h inputs toline -- furthest line to read in input source files
12511280 then Just l
12521281 else Nothing
12531282 _ -> Nothing
1254− loadFromIFile h f maxline
1283+ loadFromIFile f maxline
12551284 inew <- getIState
12561285 -- FIXME: Save these in IBC to avoid this hack! Need to
12571286 -- preserve it all from source inputs
@@ -1299,7 +1328,7 @@ idrisMain opts =
12991328 do let inputs = opt getFile opts
13001329 let quiet = Quiet `elem` opts
13011330 let nobanner = NoBanner `elem` opts
1302− let idesl = Ideslave `elem` opts
1331+ let idesl = Ideslave `elem` opts || IdeslaveSocket `elem` opts
13031332 let runrepl = not (NoREPL `elem` opts)
13041333 let verbose = runrepl || Verbose `elem` opts
13051334 let output = opt getOutput opts
@@ -1336,7 +1365,6 @@ idrisMain opts =
13361365 mapM_ addLangExt (opt getLanguageExt opts)
13371366 setREPL runrepl
13381367 setQuiet (quiet || isJust script || not (null immediate))
1339− setIdeSlave idesl
13401368 setVerbose verbose
13411369 setCmdLine opts
13421370 setOutputTy outty
@@ -1362,9 +1390,9 @@ idrisMain opts =
13621390 addPkgDir "base"
13631391 mapM_ addPkgDir pkgdirs
13641392 elabPrims
1365− when (not (NoBuiltins `elem` opts)) $ do x <- loadModule stdout "Builtins"
1393+ when (not (NoBuiltins `elem` opts)) $ do x <- loadModule "Builtins"
13661394 return ()
1367− when (not (NoPrelude `elem` opts)) $ do x <- loadModule stdout "Prelude"
1395+ when (not (NoPrelude `elem` opts)) $ do x <- loadModule "Prelude"
13681396 return ()
13691397
13701398 when (runrepl && not idesl) initScript
@@ -1380,14 +1408,14 @@ idrisMain opts =
13801408 iputStrLn banner
13811409
13821410 orig <- getIState
1383− loadInputs stdout inputs Nothing
1411+ when (not idesl) $ loadInputs inputs Nothing
13841412
13851413 runIO $ hSetBuffering stdout LineBuffering
13861414
13871415 ok <- noErrors
13881416 when ok $ case output of
13891417 [] -> return ()
1390− (o:_) -> idrisCatch (process stdout "" (Compile cgn o))
1418+ (o:_) -> idrisCatch (process "" (Compile cgn o))
13911419 (\e -> do ist <- getIState ; iputStrLn $ pshow ist e)
13921420
13931421 case immediate of
@@ -1398,7 +1426,7 @@ idrisMain opts =
13981426 case parseExpr ist str of
13991427 Failure err -> do iputStrLn $ show (fixColour c err)
14001428 runIO $ exitWith (ExitFailure 1)
1401− Success e -> process stdout "" (Eval e))
1429+ Success e -> process "" (Eval e))
14021430 exprs
14031431 runIO $ exitWith ExitSuccess
14041432
@@ -1420,7 +1448,8 @@ idrisMain opts =
14201448-- clearOrigPats
14211449 startServer orig inputs
14221450 runInputT (replSettings (Just historyFile)) $ repl orig inputs
1423− when (idesl) $ ideslaveStart orig inputs
1451+ let idesock = IdeslaveSocket `elem` opts
1452+ when (idesl) $ ideslaveStart idesock orig inputs
14241453 ok <- noErrors
14251454 when (not ok) $ runIO (exitWith (ExitFailure 1))
14261455 where
@@ -1482,7 +1511,7 @@ initScript = do script <- getInitScript
14821511 Success Edit -> iPrintError "Init scripts cannot invoke the editor"
14831512 Success Proofs -> proofs i
14841513 Success Quit -> iPrintError "Init scripts cannot quit Idris"
1485− Success cmd -> process stdout [] cmd
1514+ Success cmd -> process [] cmd
14861515
14871516getFile :: Opt -> Maybe String
14881517getFile (Filename str) = Just str