on master help sign in
Merge pull request #1937 from melted/encoding
5b465a9David Christiansen
main/Main.hs+4−1
@@ -29,6 +29,7 @@ import Idris.CmdOptions
29import IRTS.System ( getLibFlags, getIdrisLibDir, getIncFlags )
29import IRTS.System ( getLibFlags, getIdrisLibDir, getIncFlags )
30
30
31import Util.DynamicLinker
31import Util.DynamicLinker
32+import Util.System
32
33
33import Pkg.Package
34import Pkg.Package
34
35
@@ -38,7 +39,9 @@ import Paths_idris
38-- on with the REPL.
39-- on with the REPL.
39
40
40main :: IO ()
41main :: IO ()
42+main = do
43+ when isWindows $ do hSetEncoding stdout utf8
41−main = do opts <- runArgParser
44+ opts <- runArgParser
42 runMain (runIdris opts)
45 runMain (runIdris opts)
43
46
44runIdris :: [Opt] -> Idris ()
47runIdris :: [Opt] -> Idris ()
src/Idris/REPL.hs+3−1
@@ -1104,10 +1104,12 @@ process fn Execute
1104 (tmpn, tmph) <- runIO tempfile
1104 (tmpn, tmph) <- runIO tempfile
1105 runIO $ hClose tmph
1105 runIO $ hClose tmph
1106 t <- codegen
1106 t <- codegen
1107+ -- gcc adds .exe when it builds windows programs
1108+ progName <- return $ if isWindows then tmpn ++ ".exe" else tmpn
1107 ir <- compile t tmpn m
1109 ir <- compile t tmpn m
1108 runIO $ generate t (fst (head (idris_imported ist))) ir
1110 runIO $ generate t (fst (head (idris_imported ist))) ir
1109 case idris_outputmode ist of
1111 case idris_outputmode ist of
1110− RawOutput h -> do runIO $ rawSystem tmpn []
1112+ RawOutput h -> do runIO $ rawSystem progName []
1111 return ()
1113 return ()
1112 IdeMode n h -> runIO . hPutStrLn h $
1114 IdeMode n h -> runIO . hPutStrLn h $
1113 IdeMode.convSExp "run-program" tmpn n)
1115 IdeMode.convSExp "run-program" tmpn n)
src/Pkg/PParser.hs+2−2
@@ -16,7 +16,7 @@ import Idris.CmdOptions
16import Control.Monad.State.Strict
16import Control.Monad.State.Strict
17import Control.Applicative
17import Control.Applicative
18
18
19−import System.Info (os)
19+import Util.System
20
20
21
21
22type PParser = StateT PkgDesc IdrisInnerParser
22type PParser = StateT PkgDesc IdrisInnerParser
@@ -63,7 +63,7 @@ pClause :: PParser ()
63pClause = do reserved "executable"; lchar '=';
63pClause = do reserved "executable"; lchar '=';
64 exec <- iName []
64 exec <- iName []
65 st <- get
65 st <- get
66− put (st { execout = Just (if os `elem` ["win32", "mingw32", "cygwin32"]
66+ put (st { execout = Just (if isWindows
67 then ((show exec) ++ ".exe")
67 then ((show exec) ++ ".exe")
68 else ( show exec )
68 else ( show exec )
69 ) })
69 ) })
src/Util/System.hs+5−1
@@ -1,4 +1,4 @@
1−module Util.System(tempfile,withTempdir,rmFile,catchIO) where
1+module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows) where
2
2
3-- System helper functions.
3-- System helper functions.
4import Control.Monad (when)
4import Control.Monad (when)
@@ -9,6 +9,7 @@ import System.Directory (getTemporaryDirectory
9 )
9 )
10import System.FilePath ((</>), normalise)
10import System.FilePath ((</>), normalise)
11import System.IO
11import System.IO
12+import System.Info
12import System.IO.Error
13import System.IO.Error
13import Control.Exception as CE
14import Control.Exception as CE
14
15
@@ -18,6 +19,9 @@ catchIO = CE.catch
18throwIO :: IOError -> IO a
19throwIO :: IOError -> IO a
19throwIO = CE.throw
20throwIO = CE.throw
20
21
22+isWindows :: Bool
23+isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
24+
21tempfile :: IO (FilePath, Handle)
25tempfile :: IO (FilePath, Handle)
22tempfile = do dir <- getTemporaryDirectory
26tempfile = do dir <- getTemporaryDirectory
23 openTempFile (normalise dir) "idris"
27 openTempFile (normalise dir) "idris"