X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Futils%2FCharSeq.lhs;fp=ghc%2Fcompiler%2Futils%2FCharSeq.lhs;h=43dfb7f4781163c8c2d3f0b411903a17d445728d;hb=e7498a3ee1d0484d02a9e86633cc179c76ebf36e;hp=68948f4c6678934e89b32067237db546551aa9ed;hpb=30cf375e0bc79a6b71074a5e0fd2ec393241a751;p=ghc-hetmet.git diff --git a/ghc/compiler/utils/CharSeq.lhs b/ghc/compiler/utils/CharSeq.lhs index 68948f4..43dfb7f 100644 --- a/ghc/compiler/utils/CharSeq.lhs +++ b/ghc/compiler/utils/CharSeq.lhs @@ -31,12 +31,12 @@ module CharSeq ( #if ! defined(COMPILING_GHC) ) where #else - , cAppendFile + , cPutStr ) where CHK_Ubiq() -- debugging consistency check +IMPORT_1_3(IO) -import PreludeGlaST #endif \end{code} @@ -65,7 +65,7 @@ cCh :: Char -> CSeq cInt :: Int -> CSeq #if defined(COMPILING_GHC) -cAppendFile :: _FILE -> CSeq -> IO () +cPutStr :: Handle -> CSeq -> IO () #endif \end{code} @@ -86,7 +86,7 @@ data CSeq | CCh Char | CInt Int -- equiv to "CStr (show the_int)" #if defined(COMPILING_GHC) - | CPStr _PackedString + | CPStr FAST_STRING #endif \end{code} @@ -125,11 +125,6 @@ cShow seq = flatten ILIT(0) _TRUE_ seq [] cShows seq rest = cShow seq ++ rest cLength seq = length (cShow seq) -- *not* the best way to do this! #endif - -#if defined(COMPILING_GHC) -cAppendFile file_star seq - = flattenIO file_star seq `seqPrimIO` return () -#endif \end{code} This code is {\em hammered}. We are not above doing sleazy @@ -156,14 +151,14 @@ flatten n _FALSE_ (CStr s) seqs = s ++ flattenS _FALSE_ seqs flatten n _FALSE_ (CCh c) seqs = c : flattenS _FALSE_ seqs flatten n _FALSE_ (CInt i) seqs = show i ++ flattenS _FALSE_ seqs #if defined(COMPILING_GHC) -flatten n _FALSE_ (CPStr s) seqs = _unpackPS s ++ flattenS _FALSE_ seqs +flatten n _FALSE_ (CPStr s) seqs = _UNPK_ s ++ flattenS _FALSE_ seqs #endif flatten n _TRUE_ (CStr s) seqs = mkIndent n (s ++ flattenS _FALSE_ seqs) flatten n _TRUE_ (CCh c) seqs = mkIndent n (c : flattenS _FALSE_ seqs) flatten n _TRUE_ (CInt i) seqs = mkIndent n (show i ++ flattenS _FALSE_ seqs) #if defined(COMPILING_GHC) -flatten n _TRUE_ (CPStr s) seqs = mkIndent n (_unpackPS s ++ flattenS _FALSE_ seqs) +flatten n _TRUE_ (CPStr s) seqs = mkIndent n ( _UNPK_ s ++ flattenS _FALSE_ seqs) #endif \end{code} @@ -187,61 +182,21 @@ Now the I/O version. This code is massively {\em hammered}. It {\em ignores} indentation. +(NB: 1.3 compiler: efficiency hacks removed for now!) + \begin{code} #if defined(COMPILING_GHC) -flattenIO :: _FILE -- file we are writing to - -> CSeq -- Seq to print - -> PrimIO () - -flattenIO file sq - | file == ``NULL'' = error "panic:flattenIO" -- really just to force eval :-) - | otherwise - = flat sq +cPutStr handle sq = flat sq where - flat CNil = returnPrimIO () + flat CNil = return () flat (CIndent n2 seq) = flat seq - flat (CAppend s1 s2) = flat s1 `seqPrimIO` flat s2 - flat CNewline = _ccall_ stg_putc '\n' file - flat (CCh c) = _ccall_ stg_putc c file - flat (CInt i) = _ccall_ fprintf file percent_d i - flat (CStr s) = put_str s - flat (CPStr s) = put_pstr s - - ----- - put_str, put_str2 :: String -> PrimIO () - - put_str str - = --put_str2 ``stderr'' (str ++ "\n") `seqPrimIO` - put_str2 str - - put_str2 [] = returnPrimIO () - - put_str2 (c1@(C# _) : c2@(C# _) : c3@(C# _) : c4@(C# _) : cs) - = _ccall_ stg_putc c1 file `seqPrimIO` - _ccall_ stg_putc c2 file `seqPrimIO` - _ccall_ stg_putc c3 file `seqPrimIO` - _ccall_ stg_putc c4 file `seqPrimIO` - put_str2 cs -- efficiency hack? who knows... (WDP 94/10) - - put_str2 (c1@(C# _) : c2@(C# _) : c3@(C# _) : cs) - = _ccall_ stg_putc c1 file `seqPrimIO` - _ccall_ stg_putc c2 file `seqPrimIO` - _ccall_ stg_putc c3 file `seqPrimIO` - put_str2 cs -- efficiency hack? who knows... (WDP 94/10) - - put_str2 (c1@(C# _) : c2@(C# _) : cs) - = _ccall_ stg_putc c1 file `seqPrimIO` - _ccall_ stg_putc c2 file `seqPrimIO` - put_str2 cs -- efficiency hack? who knows... (WDP 94/10) - - put_str2 (c1@(C# _) : cs) - = _ccall_ stg_putc c1 file `seqPrimIO` - put_str2 cs -- efficiency hack? who knows... (WDP 94/10) - - put_pstr ps = _putPS file ps - -percent_d = _psToByteArray SLIT("%d") + flat (CAppend s1 s2) = flat s1 >> flat s2 + flat CNewline = hPutChar handle '\n' + flat (CCh c) = hPutChar handle c + flat (CInt i) = hPutStr handle (show i) + flat (CStr s) = hPutStr handle s + flat (CPStr s) = hPutStr handle (_UNPK_ s) #endif {- COMPILING_GHC -} \end{code}