on master help sign in
Switch AST.Source and Parse.Primitives.Utf8 to Data.Utf8
e85aa77Evan Czaplicki
compiler/src/AST/Source.hs+7−7
@@ -19,7 +19,7 @@ module AST.Source
19
19
20
20
21import qualified Data.ByteString as B
21import qualified Data.ByteString as B
22−import Data.Text (Text)
22+import Data.Utf8 (Utf8)
23
23
24import qualified AST.Utils.Binop as Binop
24import qualified AST.Utils.Binop as Binop
25import qualified AST.Utils.Shader as Shader
25import qualified AST.Utils.Shader as Shader
@@ -36,8 +36,8 @@ type Expr = A.Located Expr_
36
36
37
37
38data Expr_
38data Expr_
39− = Chr Text
39+ = Chr Utf8
40− | Str Text
40+ | Str Utf8
41 | Int Int
41 | Int Int
42 | Float Double
42 | Float Double
43 | Var VarType N.Name
43 | Var VarType N.Name
@@ -57,7 +57,7 @@ data Expr_
57 | Record [(A.Located N.Name, Expr)]
57 | Record [(A.Located N.Name, Expr)]
58 | Unit
58 | Unit
59 | Tuple Expr Expr [Expr]
59 | Tuple Expr Expr [Expr]
60− | Shader Text Text Shader.Shader
60+ | Shader Utf8 Utf8 Shader.Shader
61
61
62
62
63data VarType = Value | Ctor
63data VarType = Value | Ctor
@@ -91,8 +91,8 @@ data Pattern_
91 | PCtorQual R.Region N.Name N.Name [Pattern]
91 | PCtorQual R.Region N.Name N.Name [Pattern]
92 | PList [Pattern]
92 | PList [Pattern]
93 | PCons Pattern Pattern
93 | PCons Pattern Pattern
94− | PChr Text
94+ | PChr Utf8
95− | PStr Text
95+ | PStr Utf8
96 | PInt Int
96 | PInt Int
97
97
98
98
@@ -126,7 +126,7 @@ data Decl_
126 | Alias (A.Located N.Name) [A.Located N.Name] Type
126 | Alias (A.Located N.Name) [A.Located N.Name] Type
127 | Binop N.Name Binop.Associativity Binop.Precedence N.Name
127 | Binop N.Name Binop.Associativity Binop.Precedence N.Name
128 | Port (A.Located N.Name) Type
128 | Port (A.Located N.Name) Type
129− | Docs Text
129+ | Docs Utf8
130 | Annotation (A.Located N.Name) Type
130 | Annotation (A.Located N.Name) Type
131 | Definition (A.Located N.Name) [Pattern] Expr
131 | Definition (A.Located N.Name) [Pattern] Expr
132
132
compiler/src/Parse/Primitives/Utf8.hs+68−228
@@ -8,15 +8,9 @@ module Parse.Primitives.Utf8
8
8
9
9
10import Prelude hiding (length)
10import Prelude hiding (length)
11−import Data.Bits
12import qualified Data.ByteString.Internal as B
11import qualified Data.ByteString.Internal as B
13−import qualified Data.ByteString.UTF8 as Utf8
12+import qualified Data.ByteString.UTF8 as BS_UTF8
14−import qualified Data.Char as Char
15−import Data.Monoid ((<>))
16−import qualified Data.Text as Text
13+import qualified Data.Utf8 as Utf8
17−import qualified Data.Text.Encoding as Text
18−import qualified Data.Text.Lazy as LText
19−import qualified Data.Text.Lazy.Builder as Text
20import Foreign.ForeignPtr (ForeignPtr)
14import Foreign.ForeignPtr (ForeignPtr)
21import GHC.Word (Word8(..))
15import GHC.Word (Word8(..))
22
16
@@ -30,14 +24,14 @@ import qualified Reporting.Error.Syntax as E
30-- CHARACTER
24-- CHARACTER
31
25
32
26
33−character :: Parser Text.Text
27+character :: Parser Utf8.Utf8
34character =
28character =
35 Parser $ \(State fp offset terminal indent row col ctx) cok cerr _ eerr ->
29 Parser $ \(State fp offset terminal indent row col ctx) cok cerr _ eerr ->
36 if offset >= terminal || I.unsafeIndex fp offset /= 0x27 {- ' -} then
30 if offset >= terminal || I.unsafeIndex fp offset /= 0x27 {- ' -} then
37 eerr noError
31 eerr noError
38
32
39 else
33 else
40− case chompChar fp (offset + 1) terminal (col + 1) 0 "" of
34+ case chompChar fp (offset + 1) terminal (col + 1) 0 placeholder of
41 Bad newCol problem ->
35 Bad newCol problem ->
42 cerr (E.ParseError row newCol problem)
36 cerr (E.ParseError row newCol problem)
43
37
@@ -46,15 +40,15 @@ character =
46 cerr (E.ParseError row col (E.BadChar newCol))
40 cerr (E.ParseError row col (E.BadChar newCol))
47 else
41 else
48 let !newState = State fp newOffset terminal indent row newCol ctx in
42 let !newState = State fp newOffset terminal indent row newCol ctx in
49− cok mostRecent newState noError
43+ cok (Utf8.fromChunks fp [mostRecent]) newState noError
50
44
51
45
52data CharResult
46data CharResult
53 = Bad Int E.Problem
47 = Bad Int E.Problem
54− | Good Int Int Int Text.Text
48+ | Good Int Int Int Utf8.Chunk
55
49
56
50
57−chompChar :: ForeignPtr Word8 -> Int -> Int -> Int -> Int -> Text.Text -> CharResult
51+chompChar :: ForeignPtr Word8 -> Int -> Int -> Int -> Int -> Utf8.Chunk -> CharResult
58chompChar fp offset terminal col numChars mostRecent =
52chompChar fp offset terminal col numChars mostRecent =
59 if offset >= terminal then
53 if offset >= terminal then
60 Bad col E.EndOfFile_Char
54 Bad col E.EndOfFile_Char
@@ -70,15 +64,15 @@ chompChar fp offset terminal col numChars mostRecent =
70 Bad col E.NewLineInChar
64 Bad col E.NewLineInChar
71
65
72 else if word == 0x22 {- " -} then
66 else if word == 0x22 {- " -} then
73− chompChar fp (offset + 1) terminal (col + 1) (numChars + 1) "\\\""
67+ chompChar fp (offset + 1) terminal (col + 1) (numChars + 1) doubleQuote
74
68
75 else if word == 0x5C {- \ -} then
69 else if word == 0x5C {- \ -} then
76 case eatEscape fp (offset + 1) terminal of
70 case eatEscape fp (offset + 1) terminal of
77 EscapeNormal ->
71 EscapeNormal ->
78− chompChar fp (offset + 2) terminal (col + 2) (numChars + 1) (toText fp offset 2)
72+ chompChar fp (offset + 2) terminal (col + 2) (numChars + 1) (Utf8.Slice offset 2)
79
73
80− EscapeUnicode delta bits ->
74+ EscapeUnicode delta code ->
81− chompChar fp (offset + delta) terminal (col + delta) (numChars + 1) (Text.pack bits)
75+ chompChar fp (offset + delta) terminal (col + delta) (numChars + 1) (Utf8.CodePoint code)
82
76
83 EscapeProblem newOffset problem ->
77 EscapeProblem newOffset problem ->
84 Bad col (E.BadEscape (newOffset - offset) problem)
78 Bad col (E.BadEscape (newOffset - offset) problem)
@@ -88,19 +82,14 @@ chompChar fp offset terminal col numChars mostRecent =
88
82
89 else
83 else
90 let !width = I.getCharWidth fp offset terminal word in
84 let !width = I.getCharWidth fp offset terminal word in
91− chompChar fp (offset + width) terminal (col + 1) (numChars + 1) (toText fp offset width)
85+ chompChar fp (offset + width) terminal (col + 1) (numChars + 1) (Utf8.Slice offset width)
92−
93−
94−toText :: ForeignPtr Word8 -> Int -> Int -> Text.Text
95−toText fp offset length =
96− Text.decodeUtf8 (B.PS fp offset length)
97
86
98
87
99
88
100-- STRINGS
89-- STRINGS
101
90
102
91
103−string :: Parser Text.Text
92+string :: Parser Utf8.Utf8
104string =
93string =
105 Parser $ \(State fp offset terminal indent row col ctx) cok cerr _ eerr ->
94 Parser $ \(State fp offset terminal indent row col ctx) cok cerr _ eerr ->
106 if isDoubleQuote fp offset terminal then
95 if isDoubleQuote fp offset terminal then
@@ -117,12 +106,11 @@ string =
117 Err err ->
106 Err err ->
118 cerr err
107 cerr err
119
108
120− Ok newOffset newRow newCol builder ->
109+ Ok newOffset newRow newCol utf8 ->
121 let
110 let
122 !newState = State fp newOffset terminal indent newRow newCol ctx
111 !newState = State fp newOffset terminal indent newRow newCol ctx
123− !content = LText.toStrict (Text.toLazyText builder)
124 in
112 in
125− cok content newState noError
113+ cok utf8 newState noError
126
114
127 else
115 else
128 eerr noError
116 eerr noError
@@ -136,31 +124,32 @@ isDoubleQuote fp offset terminal =
136
124
137data StringResult
125data StringResult
138 = Err E.ParseError
126 = Err E.ParseError
139− | Ok !Int !Int !Int Text.Builder
127+ | Ok !Int !Int !Int !Utf8.Utf8
140
128
141
129
142−finalize :: ForeignPtr Word8 -> Int -> Int -> Text.Builder -> Text.Builder
130+finalize :: ForeignPtr Word8 -> Int -> Int -> [Utf8.Chunk] -> Utf8.Utf8
143−finalize fp start end builder =
131+finalize fp start end revChunks =
132+ Utf8.fromChunks fp $ reverse $
144− if start == end then
133+ if start == end then
145− builder
134+ revChunks
146− else
135+ else
147− builder <> Text.fromText (Text.decodeUtf8 (B.PS fp start (end - start)))
136+ Utf8.Slice start (end - start) : revChunks
148
137
149
138
150−addBits :: Text.Builder -> ForeignPtr Word8 -> Int -> Int -> Text.Builder -> Text.Builder
139+addEscape :: Utf8.Chunk -> Int -> Int -> [Utf8.Chunk] -> [Utf8.Chunk]
151−addBits bits fp start end builder =
140+addEscape chunk start end revChunks =
152 if start == end then
141 if start == end then
153− builder <> bits
142+ chunk : revChunks
154 else
143 else
155− builder <> Text.fromText (Text.decodeUtf8 (B.PS fp start (end - start))) <> bits
144+ chunk : Utf8.Slice start (end - start) : revChunks
156
145
157
146
158
147
159-- SINGLE STRINGS
148-- SINGLE STRINGS
160
149
161
150
162−singleString :: ForeignPtr Word8 -> Int -> Int -> Int -> Int -> Int -> Text.Builder -> StringResult
151+singleString :: ForeignPtr Word8 -> Int -> Int -> Int -> Int -> Int -> [Utf8.Chunk] -> StringResult
163−singleString fp offset terminal row col initialOffset builder =
152+singleString fp offset terminal row col initialOffset revChunks =
164 if offset >= terminal then
153 if offset >= terminal then
165 Err (E.ParseError row col E.EndOfFile_String)
154 Err (E.ParseError row col E.EndOfFile_String)
166
155
@@ -170,7 +159,7 @@ singleString fp offset terminal row col initialOffset builder =
170 in
159 in
171 if word == 0x22 {- " -} then
160 if word == 0x22 {- " -} then
172 Ok (offset + 1) row (col + 1) $
161 Ok (offset + 1) row (col + 1) $
173− finalize fp initialOffset offset builder
162+ finalize fp initialOffset offset revChunks
174
163
175 else if word == 0x0A {- \n -} then
164 else if word == 0x0A {- \n -} then
176 Err (E.ParseError row col E.NewLineInString)
165 Err (E.ParseError row col E.NewLineInString)
@@ -178,17 +167,17 @@ singleString fp offset terminal row col initialOffset builder =
178 else if word == 0x27 {- ' -} then
167 else if word == 0x27 {- ' -} then
179 let !newOffset = offset + 1 in
168 let !newOffset = offset + 1 in
180 singleString fp newOffset terminal row (col + 1) newOffset $
169 singleString fp newOffset terminal row (col + 1) newOffset $
181− addBits singleQuoteBits fp initialOffset offset builder
170+ addEscape singleQuote initialOffset offset revChunks
182
171
183 else if word == 0x5C {- \ -} then
172 else if word == 0x5C {- \ -} then
184 case eatEscape fp (offset + 1) terminal of
173 case eatEscape fp (offset + 1) terminal of
185 EscapeNormal ->
174 EscapeNormal ->
186− singleString fp (offset + 2) terminal row (col + 2) initialOffset builder
175+ singleString fp (offset + 2) terminal row (col + 2) initialOffset revChunks
187
176
188− EscapeUnicode delta bits ->
177+ EscapeUnicode delta code ->
189 let !newOffset = offset + delta in
178 let !newOffset = offset + delta in
190 singleString fp newOffset terminal row (col + delta) newOffset $
179 singleString fp newOffset terminal row (col + delta) newOffset $
191− addBits (Text.fromText (Text.pack bits)) fp initialOffset offset builder
180+ addEscape (Utf8.CodePoint code) initialOffset offset revChunks
192
181
193 EscapeProblem newOffset problem ->
182 EscapeProblem newOffset problem ->
194 Err (E.ParseError row col (E.BadEscape (newOffset - offset) problem))
183 Err (E.ParseError row col (E.BadEscape (newOffset - offset) problem))
@@ -198,15 +187,15 @@ singleString fp offset terminal row col initialOffset builder =
198
187
199 else
188 else
200 let !newOffset = offset + I.getCharWidth fp offset terminal word in
189 let !newOffset = offset + I.getCharWidth fp offset terminal word in
201− singleString fp newOffset terminal row (col + 1) initialOffset builder
190+ singleString fp newOffset terminal row (col + 1) initialOffset revChunks
202
191
203
192
204
193
205-- MULTI STRINGS
194-- MULTI STRINGS
206
195
207
196
208−multiString :: ForeignPtr Word8 -> Int -> Int -> Int -> Int -> Int -> Text.Builder -> StringResult
197+multiString :: ForeignPtr Word8 -> Int -> Int -> Int -> Int -> Int -> [Utf8.Chunk] -> StringResult
209−multiString fp offset terminal row col initialOffset builder =
198+multiString fp offset terminal row col initialOffset revChunks =
210 if offset >= terminal then
199 if offset >= terminal then
211 Err (E.ParseError row col E.EndOfFile_MultiString)
200 Err (E.ParseError row col E.EndOfFile_MultiString)
212
201
@@ -214,32 +203,32 @@ multiString fp offset terminal row col initialOffset builder =
214 let !word = I.unsafeIndex fp offset in
203 let !word = I.unsafeIndex fp offset in
215 if word == 0x22 {- " -} && isDoubleQuote fp (offset + 1) terminal && isDoubleQuote fp (offset + 2) terminal then
204 if word == 0x22 {- " -} && isDoubleQuote fp (offset + 1) terminal && isDoubleQuote fp (offset + 2) terminal then
216 Ok (offset + 3) row (col + 3) $
205 Ok (offset + 3) row (col + 3) $
217− finalize fp initialOffset offset builder
206+ finalize fp initialOffset offset revChunks
218
207
219 else if word == 0x27 {- ' -} then
208 else if word == 0x27 {- ' -} then
220 let !offset1 = offset + 1 in
209 let !offset1 = offset + 1 in
221 multiString fp offset1 terminal row (col + 1) offset1 $
210 multiString fp offset1 terminal row (col + 1) offset1 $
222− addBits singleQuoteBits fp initialOffset offset builder
211+ addEscape singleQuote initialOffset offset revChunks
223
212
224 else if word == 0x0A {- \n -} then
213 else if word == 0x0A {- \n -} then
225 let !offset1 = offset + 1 in
214 let !offset1 = offset + 1 in
226 multiString fp offset1 terminal (row + 1) 1 offset1 $
215 multiString fp offset1 terminal (row + 1) 1 offset1 $
227− addBits newlineBits fp initialOffset offset builder
216+ addEscape newline initialOffset offset revChunks
228
217
229 else if word == 0x0D {- \r -} then
218 else if word == 0x0D {- \r -} then
230 let !offset1 = offset + 1 in
219 let !offset1 = offset + 1 in
231 multiString fp offset1 terminal (row + 1) 1 offset1 $
220 multiString fp offset1 terminal (row + 1) 1 offset1 $
232− addBits carriageReturnBits fp initialOffset offset builder
221+ addEscape carriageReturn initialOffset offset revChunks
233
222
234 else if word == 0x5C {- \ -} then
223 else if word == 0x5C {- \ -} then
235 case eatEscape fp (offset + 1) terminal of
224 case eatEscape fp (offset + 1) terminal of
236 EscapeNormal ->
225 EscapeNormal ->
237− multiString fp (offset + 2) terminal row (col + 2) initialOffset builder
226+ multiString fp (offset + 2) terminal row (col + 2) initialOffset revChunks
238
227
239− EscapeUnicode delta bits ->
228+ EscapeUnicode delta code ->
240 let !newOffset = offset + delta in
229 let !newOffset = offset + delta in
241 multiString fp newOffset terminal row (col + delta) newOffset $
230 multiString fp newOffset terminal row (col + delta) newOffset $
242− addBits (Text.fromText (Text.pack bits)) fp initialOffset offset builder
231+ addEscape (Utf8.CodePoint code) initialOffset offset revChunks
243
232
244 EscapeProblem newOffset problem ->
233 EscapeProblem newOffset problem ->
245 Err (E.ParseError row col (E.BadEscape (newOffset - offset) problem))
234 Err (E.ParseError row col (E.BadEscape (newOffset - offset) problem))
@@ -249,7 +238,7 @@ multiString fp offset terminal row col initialOffset builder =
249
238
250 else
239 else
251 let !newOffset = offset + I.getCharWidth fp offset terminal word in
240 let !newOffset = offset + I.getCharWidth fp offset terminal word in
252− multiString fp newOffset terminal row (col + 1) initialOffset builder
241+ multiString fp newOffset terminal row (col + 1) initialOffset revChunks
253
242
254
243
255
244
@@ -258,7 +247,7 @@ multiString fp offset terminal row col initialOffset builder =
258
247
259data Escape
248data Escape
260 = EscapeNormal
249 = EscapeNormal
261− | EscapeUnicode !Int [Char]
250+ | EscapeUnicode !Int !Int
262 | EscapeProblem !Int E.EscapeProblem
251 | EscapeProblem !Int E.EscapeProblem
263 | EscapeEndOfFile
252 | EscapeEndOfFile
264
253
@@ -298,186 +287,37 @@ eatUnicode fp offset terminal =
298
287
299 else if numDigits < 4 || 6 < numDigits then
288 else if numDigits < 4 || 6 < numDigits then
300 EscapeProblem (newOffset + 1) $
289 EscapeProblem (newOffset + 1) $
301− E.UnicodeLength numDigits (Utf8.toString (B.PS fp digitOffset numDigits))
290+ E.UnicodeLength numDigits (BS_UTF8.toString (B.PS fp digitOffset numDigits))
302
291
303 else
292 else
304− EscapeUnicode (numDigits + 4) (codePointToBits code)
293+ EscapeUnicode (numDigits + 4) code
305−
306−
307−
308−-- CODE POINT TO BITS
309−
310−
311−codePointToBits :: Int -> [Char]
312−codePointToBits code =
313− if code < 0xFFFF then
314− wordToBits code
315−
316− else
317− let
318− (hi,lo) = divMod (code - 0x10000) 0x400
319− in
320− wordToBits (hi + 0xD800) ++ wordToBits (lo + 0xDC00)
321−
322−
323−wordToBits :: Int -> [Char]
324−wordToBits code =
325− [ '\\' -- 0x5C -- \
326− , 'u' -- 0x75 -- u
327− , toBits code 12
328− , toBits code 8
329− , toBits code 4
330− , toBits code 0
331− ]
332−
333−
334−toBits :: Int -> Int -> Char
335−toBits code offset =
336− let !n = fromIntegral (shiftR code offset .&. 0x000F) in
337− Char.chr $ if n < 10 then 0x30 + n else 0x61 + (n - 10)
338−
339−
340−{-# NOINLINE singleQuoteBits #-}
341−singleQuoteBits :: Text.Builder
342−singleQuoteBits =
343− "\\\'"
344−
345−
346−{-# NOINLINE newlineBits #-}
347−newlineBits :: Text.Builder
348−newlineBits =
349− "\\n"
350−
351−
352−{-# NOINLINE carriageReturnBits #-}
353−carriageReturnBits :: Text.Builder
354−carriageReturnBits =
355− "\\r"
356−
357−
358−
359−---- CHUNKS
360−
361−
362−--data Chunk
363−-- = Copy { _offset :: Int, _length :: Int }
364−-- | Bits [Word8]
365−
366−
367−--finalize :: Int -> Int -> [Chunk] -> [Chunk]
368−--finalize start end chunks =
369−-- reverse $
370−-- if start == end then
371−-- chunks
372−-- else
373−-- Copy start (end - start) : chunks
374−
375−
376−--addBits :: [Word8] -> Int -> Int -> [Chunk] -> [Chunk]
377−--addBits bits start end chunks =
378−-- if start == end then
379−-- Bits bits : chunks
380−-- else
381−-- Bits bits : Copy start (end - start) : chunks
382−
383−
384−--chunkLength :: Chunk -> Int
385−--chunkLength chunk =
386−-- case chunk of
387−-- Copy _ len ->
388−-- len
389−
390−-- Bits bits ->
391−-- length bits
392−
393−
394−
395−---- CHUNK TO SHORT
396−
397−
398−--chunkToShort :: ForeignPtr Word8 -> Chunk -> S.ShortByteString
399−--chunkToShort fp chunk =
400−-- unsafeDupablePerformIO $ stToIO $
401−-- do MBA mba <- newMutableByteArray (chunkLength chunk)
402−-- case chunk of
403−-- Copy offset len ->
404−-- do copyToByteArray (unsafeForeignPtrToPtr fp `plusPtr` offset) mba 0 len
405−-- freeze mba
406−
407−-- Bits bits ->
408−-- do _ <- writeBits mba 0 bits
409−-- freeze mba
410−
411−
412−
413−---- CHUNKS TO SHORT
414−
415−
416−--chunksToShort :: ForeignPtr Word8 -> [Chunk] -> S.ShortByteString
417−--chunksToShort fp chunks =
418−-- unsafeDupablePerformIO $ stToIO $
419−-- do MBA mba <- newMutableByteArray (sum (map chunkLength chunks))
420−-- chunksToShortHelp fp mba 0 chunks
421−
422−
423−--chunksToShortHelp :: ForeignPtr Word8 -> Prim.MutableByteArray# s -> Int -> [Chunk] -> ST s S.ShortByteString
424−--chunksToShortHelp fp mba index chunks =
425−-- case chunks of
426−-- [] ->
427−-- freeze mba
428−
429−-- chunk : others ->
430−-- case chunk of
431−-- Copy offset len ->
432−-- do copyToByteArray (unsafeForeignPtrToPtr fp `plusPtr` offset) mba index len
433−-- chunksToShortHelp fp mba (index + len) others
434−
435−-- Bits bits ->
436−-- do newIndex <- writeBits mba index bits
437−-- chunksToShortHelp fp mba newIndex others
438−
439−
440−
441−---- CHUNKS HELPERS
442−
443−
444−--data MBA s = MBA (Prim.MutableByteArray# s)
445−
446
294
447−--newMutableByteArray :: Int -> ST s (MBA s)
448−--newMutableByteArray (I# len) =
449−-- ST $ \s1 ->
450−-- case Prim.newByteArray# len s1 of
451−-- (# s2, mba #) -> (# s2, MBA mba #)
452
295
296+{-# NOINLINE singleQuote #-}
297+singleQuote :: Utf8.Chunk
298+singleQuote =
299+ Utf8.Escape 0x5C27 {- \' -}
453
300
454−--freeze :: Prim.MutableByteArray# s -> ST s S.ShortByteString
455−--freeze mba =
456−-- ST $ \s1 ->
457−-- case Prim.unsafeFreezeByteArray# mba s1 of
458−-- (# s2, ba #) -> (# s2, S.SBS ba #)
459
301
302+{-# NOINLINE doubleQuote #-}
303+doubleQuote :: Utf8.Chunk
304+doubleQuote =
305+ Utf8.Escape 0x5C22 {- \" -}
460
306
461−--copyToByteArray :: Ptr Word8 -> Prim.MutableByteArray# s -> Int -> Int -> ST s ()
462−--copyToByteArray (Ptr src) dst (I# dstOffset) (I# len) =
463−-- ST $ \s1 ->
464−-- case Prim.copyAddrToByteArray# src dst dstOffset len s1 of
465−-- s2 -> (# s2, () #)
466
307
308+{-# NOINLINE newline #-}
309+newline :: Utf8.Chunk
310+newline =
311+ Utf8.Escape 0x5C6E {- \n -}
467
312
468−--writeBits :: Prim.MutableByteArray# s -> Int -> [Word8] -> ST s Int
469−--writeBits mba index bits =
470−-- case bits of
471−-- [] ->
472−-- return index
473
313
474−-- word : others ->
314+{-# NOINLINE carriageReturn #-}
475−-- do writeWord8Array mba index word
315+carriageReturn :: Utf8.Chunk
476−-- writeBits mba (index + 1) others
316+carriageReturn =
317+ Utf8.Escape 0x5C72 {- \r -}
477
318
478
319
479−--writeWord8Array :: Prim.MutableByteArray# s -> Int -> Word8 -> ST s ()
320+{-# NOINLINE placeholder #-}
480−--writeWord8Array mba (I# offset) (W8# word) =
321+placeholder :: Utf8.Chunk
481−-- ST $ \s1 ->
322+placeholder =
482−-- case Prim.writeWord8Array# mba offset word s1 of
323+ Utf8.CodePoint 0xFFFD {- replacement character -}
483−-- s2 -> (# s2, () #)