on master help sign in
Allow REPL to run on another port (flag --port)
commit4fd6bc6bdf2528d8aae121e9b71e60c8467833a4 authorSebastian de Bellefon <arnaudpourseb@gmail.com> dateSat 27 Sep 2014, 13:26 (12 years ago) parent400f147
8 files changed+42−15
main/Main.hs+5−3 src/Idris/AbsSyntaxTree.hs+1 src/Idris/CmdOptions.hs+1 src/Idris/REPL.hs+26−12 test/interactive006/expected+2 test/interactive006/input+1 test/interactive006/interactive006.idr+3 test/interactive006/run+3
main/Main.hs+5−3
@@ -42,13 +42,15 @@ main = do opts <- runArgParser
4242 runMain (runIdris opts)
4343
4444runIdris :: [Opt] -> Idris ()
45−runIdris [Client c] = do setVerbose False
46− setQuiet True
47− runIO $ runClient c
4845runIdris opts = do
4946 when (ShowIncs `elem` opts) $ runIO showIncs
5047 when (ShowLibs `elem` opts) $ runIO showLibs
5148 when (ShowLibdir `elem` opts) $ runIO showLibdir
49+ case opt getClient opts of
50+ [] -> return ()
51+ (c:_) -> do setVerbose False
52+ setQuiet True
53+ runIO $ runClient (getPort opts) c
5254 case opt getPkgCheck opts of
5355 [] -> return ()
5456 fs -> do runIO $ mapM_ (checkPkg (WarnOnly `elem` opts) True) fs
src/Idris/AbsSyntaxTree.hs+1
@@ -393,6 +393,7 @@ data Opt = Filename String
393393 | ErrContext
394394 | ShowImpl
395395 | Verbose
396+ | Port String -- REPL TCP port
396397 | IBCSubDir String
397398 | ImportDir String
398399 | PkgBuild String
src/Idris/CmdOptions.hs+1
@@ -96,6 +96,7 @@ parseFlags = many $
9696 <|> (ImportDir <$> strOption (short 'i' <> long "idrispath" <> help "Add directory to the list of import paths"))
9797 <|> flag' WarnOnly (long "warn")
9898 <|> (Pkg <$> strOption (short 'p' <> long "package"))
99+ <|> (Port <$> strOption (long "port" <> metavar "PORT" <> help "REPL TCP port"))
99100 -- Package commands
100101 <|> (PkgBuild <$> strOption (long "build" <> metavar "IPKG" <> help "Build package"))
101102 <|> (PkgInstall <$> strOption (long "install" <> metavar "IPKG" <> help "Install package"))
src/Idris/REPL.hs+26−12
@@ -140,14 +140,12 @@ repl orig mods
140140 showM c thm n = if c then colouriseFun thm (show n)
141141 else show n
142142
143−-- | Run the REPL server
144−startServer :: IState -> [FilePath] -> Idris ()
145−startServer orig fn_in = do tid <- runIO $ forkOS serverLoop
146− return ()
147− where serverLoop :: IO ()
148− -- TODO: option for port number
149− serverLoop = withSocketsDo $
150− do sock <- listenOnLocalhost $ PortNumber 4294
143+-- | Run the REPL seDver
144+startServer :: PortID -> IState -> [FilePath] -> Idris ()
145+startServer port orig fn_in = do tid <- runIO $ forkOS (serverLoop port)
146+ return ()
147+ where serverLoop port = withSocketsDo $
148+ do sock <- listenOnLocalhost port
151149 loop fn orig { idris_colourRepl = False } sock
152150
153151 fn = case fn_in of
@@ -201,9 +199,9 @@ processNetCmd orig i h fn cmd
201199 IdeSlave n _ -> ist {idris_outputmode = IdeSlave n h}
202200
203201-- | Run a command on the server on localhost
204−runClient :: String -> IO ()
205−runClient str = withSocketsDo $ do
206− h <- connectTo "localhost" (PortNumber 4294)
202+runClient :: PortID -> String -> IO ()
203+runClient port str = withSocketsDo $ do
204+ h <- connectTo "localhost" port
207205 hSetEncoding h utf8
208206 hPutStrLn h str
209207 resp <- hGetResp "" h
@@ -1428,6 +1426,7 @@ idrisMain opts =
14281426 runIO $ exitWith (ExitFailure 1)
14291427 [expr] -> return (Just expr)
14301428 let immediate = opt getEvalExpr opts
1429+ let port = getPort opts
14311430
14321431 when (DefaultTotal `elem` opts) $ do i <- getIState
14331432 putIState (i { default_total = True })
@@ -1516,7 +1515,7 @@ idrisMain opts =
15161515
15171516 when (runrepl && not idesl) $ do
15181517-- clearOrigPats
1519− startServer orig inputs
1518+ startServer port orig inputs
15201519 runInputT (replSettings (Just historyFile)) $ repl orig inputs
15211520 let idesock = IdeslaveSocket `elem` opts
15221521 when (idesl) $ ideslaveStart idesock orig inputs
@@ -1679,11 +1678,26 @@ getColour :: Opt -> Maybe Bool
16791678getColour (ColourREPL b) = Just b
16801679getColour _ = Nothing
16811680
1681+getClient :: Opt -> Maybe String
1682+getClient (Client x) = Just x
1683+getClient _ = Nothing
1684+
1685+-- Get the first valid port
1686+getPort :: [Opt] -> PortID
1687+getPort [] = defaultPort
1688+getPort (Port p:xs)
1689+ | all (`elem` ['0'..'9']) p = PortNumber $ fromIntegral (read p)
1690+ | otherwise = getPort xs
1691+getPort (_:xs) = getPort xs
1692+
16821693opt :: (Opt -> Maybe a) -> [Opt] -> [a]
16831694opt = mapMaybe
16841695
16851696ver = showVersion version ++ gitHash
16861697
1698+defaultPort :: PortID
1699+defaultPort = PortNumber (fromIntegral 4294)
1700+
16871701banner = " ____ __ _ \n" ++
16881702 " / _/___/ /____(_)____ \n" ++
16891703 " / // __ / ___/ / ___/ Version " ++ ver ++ "\n" ++
test/interactive006/expectednew file+2
@@ -0,0 +1,2 @@
1+Type checking ./interactive006.idr
2+plus ?foo_rhs2 ?foo_rhs3
test/interactive006/inputnew file+1
@@ -0,0 +1 @@
1+:ref 2 foo_rhs1 plus
test/interactive006/interactive006.idrnew file+3
@@ -0,0 +1,3 @@
1+foo : Nat -> Nat -> Nat
2+foo k j = ?foo_rhs1
3+
test/interactive006/runnew file+3
@@ -0,0 +1,3 @@
1+#!/usr/bin/env bash
2+idris --quiet --port 5000 interactive006.idr < input
3+rm -f *.ibc