on master help sign in
Ensure that the backend output is UTF8
8809bf2Niklas Larsson
src/IRTS/CodegenC.hs+1−1
@@ -64,7 +64,7 @@ codegenC' defs out exec incs objs libs flags exports iface dbg
64 (if (exec == Executable) then mprog else hi)
64 (if (exec == Executable) then mprog else hi)
65 case exec of
65 case exec of
66 MavenProject -> putStrLn ("FAILURE: output type not supported")
66 MavenProject -> putStrLn ("FAILURE: output type not supported")
67− Raw -> writeFile out cout
67+ Raw -> writeSource out cout
68 _ -> do
68 _ -> do
69 (tmpn, tmph) <- tempfile
69 (tmpn, tmph) <- tempfile
70 hPutStr tmph cout
70 hPutStr tmph cout
src/IRTS/CodegenJavaScript.hs+6−6
@@ -132,12 +132,12 @@ codegenJS_all target definitions includes libs filename outputType = do
132 ++ idrRuntime
132 ++ idrRuntime
133 ++ tgtRuntime
133 ++ tgtRuntime
134 )
134 )
135− TIO.writeFile filename ( T.pack runtime
135+ writeSourceText filename ( T.pack runtime
136− `T.append` T.concat (map compileJS opt)
136+ `T.append` T.concat (map compileJS opt)
137− `T.append` T.concat (map compileJS cons)
137+ `T.append` T.concat (map compileJS cons)
138− `T.append` main
138+ `T.append` main
139− `T.append` invokeMain
139+ `T.append` invokeMain
140− )
140+ )
141 setPermissions filename (emptyPermissions { readable = True
141 setPermissions filename (emptyPermissions { readable = True
142 , executable = target == Node
142 , executable = target == Node
143 , writable = True
143 , writable = True
src/Util/System.hs+8−1
@@ -1,9 +1,12 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows,
2module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows,
3+ writeSource, writeSourceText, readSource,
3− writeSource, readSource, setupBundledCC) where
4+ setupBundledCC) where
4
5
5-- System helper functions.
6-- System helper functions.
6import Control.Monad (when)
7import Control.Monad (when)
8+import qualified Data.Text as T
9+import qualified Data.Text.IO as TIO
7import System.Directory (getTemporaryDirectory
10import System.Directory (getTemporaryDirectory
8 , removeFile
11 , removeFile
9 , removeDirectoryRecursive
12 , removeDirectoryRecursive
@@ -44,6 +47,10 @@ readSource f = do h <- openFile f ReadMode
44writeSource :: FilePath -> String -> IO ()
47writeSource :: FilePath -> String -> IO ()
45writeSource f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> hPutStr h s)
48writeSource f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> hPutStr h s)
46
49
50+-- | Write a utf-8 source file from Text
51+writeSourceText :: FilePath -> T.Text -> IO ()
52+writeSourceText f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> TIO.hPutStr h s)
53+
47withTempdir :: String -> (FilePath -> IO a) -> IO a
54withTempdir :: String -> (FilePath -> IO a) -> IO a
48withTempdir subdir callback
55withTempdir subdir callback
49 = do dir <- getTemporaryDirectory
56 = do dir <- getTemporaryDirectory