on master help sign in
Generate escape characters properly in strings

The writeWord16Array# function was little-endian (or whichever one is the weird one) I’m not sure if this is platform specific, so I just switched to writing the bytes individually to avoid the issue.

commit30c71b0d0997edea91ca78ee9a3983a9439d033c authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 20 Nov 2018, 23:49 (8 years ago) parent1308e3d
2 files changed+11−16
compiler/src/Data/Utf8.hs+7−12 compiler/src/Parse/Primitives/Utf8.hs+4−4
compiler/src/Data/Utf8.hs+7−12
@@ -27,12 +27,12 @@ import GHC.Exts
2727 , newByteArray#, unsafeFreezeByteArray#
2828 , sizeofByteArray#
2929 , copyAddrToByteArray#, copyByteArrayToAddr#
30− , writeWord8Array#, writeWord16Array#
30+ , writeWord8Array#,
3131 )
3232import GHC.IO
3333import GHC.ST (ST(ST), runST)
3434import GHC.Prim
35−import GHC.Word (Word8(W8#), Word16(W16#))
35+import GHC.Word (Word8(W8#))
3636
3737
3838
@@ -122,7 +122,7 @@ empty =
122122
123123data Chunk
124124 = Slice Int Int -- TODO try UNPACK
125− | Escape Word16
125+ | Escape Word8
126126 | CodePoint Int
127127
128128
@@ -165,7 +165,8 @@ writeChunks ptr mba offset chunks =
165165 writeChunks ptr mba newOffset chunks
166166
167167 Escape word ->
168− do writeWord16 mba offset word
168+ do writeWord8 mba offset 0x5C {- \ -}
169+ writeWord8 mba (offset + 1) word
169170 let !newOffset = offset + 2
170171 writeChunks ptr mba newOffset chunks
171172
@@ -185,7 +186,8 @@ writeChunks ptr mba offset chunks =
185186-- TODO see if it is faster to writeWord32 a block of hex-as-ascii
186187writeCode :: MBA RealWorld -> Int -> Int -> ST RealWorld ()
187188writeCode mba offset code =
188− do writeWord16 mba offset 0x5C75 {- \u -}
189+ do writeWord8 mba offset 0x5C {- \ -}
190+ writeWord8 mba offset 0x75 {- u -}
189191 writeHex mba (offset + 2) (shiftR code 12)
190192 writeHex mba (offset + 3) (shiftR code 8)
191193 writeHex mba (offset + 4) (shiftR code 4)
@@ -341,10 +343,3 @@ writeWord8 (MBA# mba#) (I# i#) (W8# w#) =
341343 ST $ \s ->
342344 case writeWord8Array# mba# i# w# s of
343345 s -> (# s, () #)
344−
345−
346−writeWord16 :: MBA s -> Int -> Word16 -> ST s ()
347−writeWord16 (MBA# mba#) (I# i#) (W16# w#) =
348− ST $ \s ->
349− case writeWord16Array# mba# i# w# s of
350− s -> (# s, () #)
compiler/src/Parse/Primitives/Utf8.hs+4−4
@@ -296,25 +296,25 @@ eatUnicode fp offset terminal =
296296{-# NOINLINE singleQuote #-}
297297singleQuote :: Utf8.Chunk
298298singleQuote =
299− Utf8.Escape 0x5C27 {- \' -}
299+ Utf8.Escape 0x27 {- ' -}
300300
301301
302302{-# NOINLINE doubleQuote #-}
303303doubleQuote :: Utf8.Chunk
304304doubleQuote =
305− Utf8.Escape 0x5C22 {- \" -}
305+ Utf8.Escape 0x22 {- " -}
306306
307307
308308{-# NOINLINE newline #-}
309309newline :: Utf8.Chunk
310310newline =
311− Utf8.Escape 0x5C6E {- \n -}
311+ Utf8.Escape 0x6E {- n -}
312312
313313
314314{-# NOINLINE carriageReturn #-}
315315carriageReturn :: Utf8.Chunk
316316carriageReturn =
317− Utf8.Escape 0x5C72 {- \r -}
317+ Utf8.Escape 0x72 {- \r -}
318318
319319
320320{-# NOINLINE placeholder #-}