set stdin/stdout to binary mode; remove UTF8 decoding
This commit is contained in:
parent
e27d3305cc
commit
52d72a32b1
11
Interp.hs
11
Interp.hs
|
@ -7,11 +7,10 @@ import Prelude hiding (lookup)
|
|||
import qualified Data.Map as M
|
||||
import qualified Data.ByteString.Char8 as BSC
|
||||
import qualified Network.Socket as SO
|
||||
import qualified System.IO.UTF8 as UTF8
|
||||
import Data.List (intercalate)
|
||||
import Control.Monad.Trans (lift)
|
||||
import Control.Monad.Trans.State (StateT, runStateT, evalStateT, get, put)
|
||||
import System.IO (Handle, hPutStr, hGetLine, hFlush, hClose, hIsEOF, openBinaryFile, IOMode(..), stdout, stdin)
|
||||
import System.IO (Handle, hPutStr, hGetLine, hFlush, hClose, hIsEOF, openBinaryFile, hSetBinaryMode, IOMode(..), stdout, stdin)
|
||||
import System.Directory (doesFileExist)
|
||||
import System.FilePath (FilePath, splitExtension, takeBaseName)
|
||||
import AST
|
||||
|
@ -117,7 +116,7 @@ _fputstr (TupleV [StreamV h, StrV str]) = do
|
|||
_fgetline (StreamV h) = do
|
||||
(handles,_) <- get
|
||||
let handle = handles !! h
|
||||
str <- lift $ UTF8.hGetLine handle
|
||||
str <- lift $ hGetLine handle
|
||||
if last str == '\r' then -- remove trailing CR
|
||||
return . StrV $ init str
|
||||
else return $ StrV str
|
||||
|
@ -412,6 +411,12 @@ apply (Builtin (BIF fn)) arg = fn arg
|
|||
|
||||
-- some helper programs for evaluation
|
||||
|
||||
-- sets up stdin/stdout for binary mode
|
||||
initIO :: IO ()
|
||||
initIO = do
|
||||
hSetBinaryMode stdin True
|
||||
hSetBinaryMode stdout True
|
||||
|
||||
evalProgram :: [AST] -> InterpState Value
|
||||
evalProgram nodes = foldr1 (>>) $ map eval nodes
|
||||
|
||||
|
|
3
Lamb.hs
3
Lamb.hs
|
@ -5,7 +5,7 @@
|
|||
import System.Environment (getArgs)
|
||||
import System.Directory (doesFileExist)
|
||||
import System.FilePath (FilePath, splitExtension)
|
||||
import Interp (evalFileV, Value(UnitV))
|
||||
import Interp (evalFileV, initIO, Value(UnitV))
|
||||
|
||||
-- returns Nothing if all files exist, or Just path for the first one that doesn't
|
||||
allExist :: [FilePath] -> IO (Maybe FilePath)
|
||||
|
@ -22,4 +22,5 @@ main = do
|
|||
case exist of
|
||||
Just file -> putStrLn $ "error: file " ++ file ++ " doesn't exist"
|
||||
Nothing ->
|
||||
initIO >>
|
||||
mapM_ evalFileV args
|
Loading…
Reference in New Issue