on master help sign in
Ensure that the backend output is UTF8

Not really needed for C, but Javascript can have Unicode strings and identifiers.

commit8809bf2dd7147db6ed0f5f6a7f61c776d4665087 authorNiklas Larsson <niklas@mm.st> dateWed 22 Jul 2015, 23:14 (11 years ago) parentcf4489e
3 files changed+15−8
src/IRTS/CodegenC.hs+1−1 src/IRTS/CodegenJavaScript.hs+6−6 src/Util/System.hs+8−1
src/IRTS/CodegenC.hs+1−1
@@ -64,7 +64,7 @@ codegenC' defs out exec incs objs libs flags exports iface dbg
6464 (if (exec == Executable) then mprog else hi)
6565 case exec of
6666 MavenProject -> putStrLn ("FAILURE: output type not supported")
67− Raw -> writeFile out cout
67+ Raw -> writeSource out cout
6868 _ -> do
6969 (tmpn, tmph) <- tempfile
7070 hPutStr tmph cout
src/IRTS/CodegenJavaScript.hs+6−6
@@ -132,12 +132,12 @@ codegenJS_all target definitions includes libs filename outputType = do
132132 ++ idrRuntime
133133 ++ tgtRuntime
134134 )
135− TIO.writeFile filename ( T.pack runtime
136− `T.append` T.concat (map compileJS opt)
137− `T.append` T.concat (map compileJS cons)
138− `T.append` main
139− `T.append` invokeMain
140− )
135+ writeSourceText filename ( T.pack runtime
136+ `T.append` T.concat (map compileJS opt)
137+ `T.append` T.concat (map compileJS cons)
138+ `T.append` main
139+ `T.append` invokeMain
140+ )
141141 setPermissions filename (emptyPermissions { readable = True
142142 , executable = target == Node
143143 , writable = True
src/Util/System.hs+8−1
@@ -1,9 +1,12 @@
11{-# LANGUAGE CPP #-}
22module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows,
3− writeSource, readSource, setupBundledCC) where
3+ writeSource, writeSourceText, readSource,
4+ setupBundledCC) where
45
56-- System helper functions.
67import Control.Monad (when)
8+import qualified Data.Text as T
9+import qualified Data.Text.IO as TIO
710import System.Directory (getTemporaryDirectory
811 , removeFile
912 , removeDirectoryRecursive
@@ -44,6 +47,10 @@ readSource f = do h <- openFile f ReadMode
4447writeSource :: FilePath -> String -> IO ()
4548writeSource f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> hPutStr h s)
4649
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+
4754withTempdir :: String -> (FilePath -> IO a) -> IO a
4855withTempdir subdir callback
4956 = do dir <- getTemporaryDirectory