diff options
author | Ian Lynagh <igloo@earth.li> | 2012-07-14 20:48:42 +0100 |
---|---|---|
committer | Ian Lynagh <igloo@earth.li> | 2012-07-14 20:57:37 +0100 |
commit | 7ae1bec53801069661e249e47ebd6998d6450093 (patch) | |
tree | 3bf00efb097a569173b2c2e9fe1d10347508c6ba /compiler/coreSyn | |
parent | 18f82197efbc2b930b123032fd7828626c04ee43 (diff) | |
download | haskell-7ae1bec53801069661e249e47ebd6998d6450093.tar.gz |
Implement FastBytes, and use it for MachStr
This is a first step on the way to refactoring the FastString type.
FastBytes currently has no unique, mainly because there isn't currently
a nice way to produce them in Binary.
Also, we don't currently do the "Dictionary" thing with FastBytes in
Binary. I'm not sure whether this is important.
We can change both decisions later, but in the meantime this gets the
refactoring underway.
Diffstat (limited to 'compiler/coreSyn')
-rw-r--r-- | compiler/coreSyn/CoreUnfold.lhs | 2 | ||||
-rw-r--r-- | compiler/coreSyn/ExternalCore.lhs | 4 | ||||
-rw-r--r-- | compiler/coreSyn/MkCore.lhs | 4 | ||||
-rw-r--r-- | compiler/coreSyn/MkExternalCore.lhs | 2 | ||||
-rw-r--r-- | compiler/coreSyn/PprExternalCore.lhs | 4 |
5 files changed, 10 insertions, 6 deletions
diff --git a/compiler/coreSyn/CoreUnfold.lhs b/compiler/coreSyn/CoreUnfold.lhs index 816d34e87b..6c61f4294c 100644 --- a/compiler/coreSyn/CoreUnfold.lhs +++ b/compiler/coreSyn/CoreUnfold.lhs @@ -508,7 +508,7 @@ sizeExpr bOMB_OUT_SIZE top_args expr litSize :: Literal -> Int -- Used by CoreUnfold.sizeExpr litSize (LitInteger {}) = 100 -- Note [Size of literal integers] -litSize (MachStr str) = 10 + 10 * ((lengthFS str + 3) `div` 4) +litSize (MachStr str) = 10 + 10 * ((lengthFB str + 3) `div` 4) -- If size could be 0 then @f "x"@ might be too small -- [Sept03: make literal strings a bit bigger to avoid fruitless -- duplication of little strings] diff --git a/compiler/coreSyn/ExternalCore.lhs b/compiler/coreSyn/ExternalCore.lhs index 3d416f78a4..d2f6691a7c 100644 --- a/compiler/coreSyn/ExternalCore.lhs +++ b/compiler/coreSyn/ExternalCore.lhs @@ -11,6 +11,8 @@ module ExternalCore where +import Data.Word + data Module = Module Mname [Tdef] [Vdefg] @@ -84,7 +86,7 @@ data Lit = Lint Integer Ty | Lrational Rational Ty | Lchar Char Ty - | Lstring String Ty + | Lstring [Word8] Ty type Mname = Id diff --git a/compiler/coreSyn/MkCore.lhs b/compiler/coreSyn/MkCore.lhs index 410d62db7d..3a696d1914 100644 --- a/compiler/coreSyn/MkCore.lhs +++ b/compiler/coreSyn/MkCore.lhs @@ -283,11 +283,11 @@ mkStringExprFS str | all safeChar chars = do unpack_id <- lookupId unpackCStringName - return (App (Var unpack_id) (Lit (MachStr str))) + return (App (Var unpack_id) (Lit (MachStr (fastStringToFastBytes str)))) | otherwise = do unpack_id <- lookupId unpackCStringUtf8Name - return (App (Var unpack_id) (Lit (MachStr str))) + return (App (Var unpack_id) (Lit (MachStr (fastStringToFastBytes str)))) where chars = unpackFS str diff --git a/compiler/coreSyn/MkExternalCore.lhs b/compiler/coreSyn/MkExternalCore.lhs index b6c682ffc0..d05da2a420 100644 --- a/compiler/coreSyn/MkExternalCore.lhs +++ b/compiler/coreSyn/MkExternalCore.lhs @@ -221,7 +221,7 @@ make_lit dflags l = -- For a character bigger than 0xff, we represent it in ext-core -- as an int lit with a char type. MachChar i -> C.Lint (fromIntegral $ ord i) t - MachStr s -> C.Lstring (unpackFS s) t + MachStr s -> C.Lstring (bytesFB s) t MachNullAddr -> C.Lint 0 t MachInt i -> C.Lint i t MachInt64 i -> C.Lint i t diff --git a/compiler/coreSyn/PprExternalCore.lhs b/compiler/coreSyn/PprExternalCore.lhs index 571b816e59..9c6846c494 100644 --- a/compiler/coreSyn/PprExternalCore.lhs +++ b/compiler/coreSyn/PprExternalCore.lhs @@ -199,7 +199,9 @@ plit (Lint i t) = parens (integer i <> text "::" <> pty t) plit (Lrational r t) = parens (text (show (numerator r)) <+> char '%' <+> text (show (denominator r)) <> text "::" <> pty t) plit (Lchar c t) = parens (text ("\'" ++ escape [c] ++ "\'") <> text "::" <> pty t) -plit (Lstring s t) = parens (pstring s <> text "::" <> pty t) +-- This is a little messy. We shouldn't really be going via String. +plit (Lstring bs t) = parens (pstring str <> text "::" <> pty t) + where str = map (chr . fromIntegral) bs pstring :: String -> Doc pstring s = doubleQuotes(text (escape s)) |