Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

DRAFT Update basement for GHC 9.2 #555

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions basement/Basement/Alg/UTF8.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import Basement.PrimType
import Basement.UTF8.Helper
import Basement.UTF8.Table
import Basement.UTF8.Types
import Basement.HeadHackageUtils

nextAscii :: Indexable container Word8 => container -> Offset Word8 -> StepASCII
nextAscii ba n = StepASCII w
Expand Down Expand Up @@ -95,8 +96,8 @@ nextWith h ba n =
prev :: Indexable container Word8 => container -> Offset Word8 -> StepBack
prev ba offset =
case index ba prevOfs1 of
(W8# v1) | isContinuation# v1 -> atLeast2 (maskContinuation# v1)
| otherwise -> StepBack (toChar# v1) prevOfs1
(W8# v1) | isContinuation# (word8ToWordCompat# v1) -> atLeast2 (maskContinuation# (word8ToWordCompat# v1))
| otherwise -> StepBack (toChar# (word8ToWordCompat# v1)) prevOfs1
where
sz1 = CountOf 1
!prevOfs1 = offset `offsetMinusE` sz1
Expand All @@ -105,15 +106,15 @@ prev ba offset =
prevOfs4 = prevOfs3 `offsetMinusE` sz1
atLeast2 !v =
case index ba prevOfs2 of
(W8# v2) | isContinuation# v2 -> atLeast3 (or# (uncheckedShiftL# (maskContinuation# v2) 6#) v)
| otherwise -> StepBack (toChar# (or# (uncheckedShiftL# (maskHeader2# v2) 6#) v)) prevOfs2
(W8# v2) | isContinuation# (word8ToWordCompat# v2) -> atLeast3 (or# (uncheckedShiftL# (maskContinuation# (word8ToWordCompat# v2)) 6#) v)
| otherwise -> StepBack (toChar# (or# (uncheckedShiftL# (maskHeader2# (word8ToWordCompat# v2)) 6#) v)) prevOfs2
atLeast3 !v =
case index ba prevOfs3 of
(W8# v3) | isContinuation# v3 -> atLeast4 (or# (uncheckedShiftL# (maskContinuation# v3) 12#) v)
| otherwise -> StepBack (toChar# (or# (uncheckedShiftL# (maskHeader3# v3) 12#) v)) prevOfs3
(W8# v3) | isContinuation# (word8ToWordCompat# v3) -> atLeast4 (or# (uncheckedShiftL# (maskContinuation# (word8ToWordCompat# v3)) 12#) v)
| otherwise -> StepBack (toChar# (or# (uncheckedShiftL# (maskHeader3# (word8ToWordCompat# v3)) 12#) v)) prevOfs3
atLeast4 !v =
case index ba prevOfs4 of
(W8# v4) -> StepBack (toChar# (or# (uncheckedShiftL# (maskHeader4# v4) 18#) v)) prevOfs4
(W8# v4) -> StepBack (toChar# (or# (uncheckedShiftL# (maskHeader4# (word8ToWordCompat# v4)) 18#) v)) prevOfs4

prevSkip :: Indexable container Word8 => container -> Offset Word8 -> Offset Word8
prevSkip ba offset = loop (offset `offsetMinusE` sz1)
Expand All @@ -139,32 +140,32 @@ writeUTF8 mba !i !c
!(I# xi) = fromEnum c
!x = int2Word# xi

encode1 = write mba i (W8# x) >> pure (i + Offset 1)
encode1 = write mba i (W8# (wordToWord8Compat# x)) >> pure (i + Offset 1)
encode2 = do
let x1 = or# (uncheckedShiftRL# x 6#) 0xc0##
x2 = toContinuation x
write mba i (W8# x1)
write mba (i+1) (W8# x2)
write mba i (W8# (wordToWord8Compat# x1))
write mba (i+1) (W8# (wordToWord8Compat# x2))
pure (i + Offset 2)

encode3 = do
let x1 = or# (uncheckedShiftRL# x 12#) 0xe0##
x2 = toContinuation (uncheckedShiftRL# x 6#)
x3 = toContinuation x
write mba i (W8# x1)
write mba (i+Offset 1) (W8# x2)
write mba (i+Offset 2) (W8# x3)
write mba i (W8# (wordToWord8Compat# x1))
write mba (i+Offset 1) (W8# (wordToWord8Compat# x2))
write mba (i+Offset 2) (W8# (wordToWord8Compat# x3))
pure (i + Offset 3)

encode4 = do
let x1 = or# (uncheckedShiftRL# x 18#) 0xf0##
x2 = toContinuation (uncheckedShiftRL# x 12#)
x3 = toContinuation (uncheckedShiftRL# x 6#)
x4 = toContinuation x
write mba i (W8# x1)
write mba (i+Offset 1) (W8# x2)
write mba (i+Offset 2) (W8# x3)
write mba (i+Offset 3) (W8# x4)
write mba i (W8# (wordToWord8Compat# x1))
write mba (i+Offset 1) (W8# (wordToWord8Compat# x2))
write mba (i+Offset 2) (W8# (wordToWord8Compat# x3))
write mba (i+Offset 3) (W8# (wordToWord8Compat# x4))
pure (i + Offset 4)

toContinuation :: Word# -> Word#
Expand Down
17 changes: 9 additions & 8 deletions basement/Basement/Base16.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Basement.Base16
import GHC.Prim
import GHC.Types
import GHC.Word
import Basement.HeadHackageUtils
import Basement.Types.Char7

data Base16Escape = Base16Escape {-# UNPACK #-} !Char7 {-# UNPACK #-} !Char7
Expand All @@ -27,11 +28,11 @@ unsafeConvertByte :: Word# -> (# Word#, Word# #)
unsafeConvertByte b = (# r tableHi b, r tableLo b #)
where
r :: Table -> Word# -> Word#
r (Table !table) index = indexWord8OffAddr# table (word2Int# index)
r (Table !table) index = word8ToWordCompat# (indexWord8OffAddr# table (word2Int# index))
{-# INLINE unsafeConvertByte #-}

escapeByte :: Word8 -> Base16Escape
escapeByte !(W8# b) = Base16Escape (r tableHi b) (r tableLo b)
escapeByte !(W8# b) = Base16Escape (r tableHi (word8ToWordCompat# b)) (r tableLo (word8ToWordCompat# b))
where
r :: Table -> Word# -> Char7
r (Table !table) index = Char7 (W8# (indexWord8OffAddr# table (word2Int# index)))
Expand All @@ -43,8 +44,8 @@ hexWord16 (W16# w) = (toChar w1,toChar w2,toChar w3,toChar w4)
where
toChar :: Word# -> Char
toChar c = C# (chr# (word2Int# c))
!(# w1, w2 #) = unsafeConvertByte (uncheckedShiftRL# w 8#)
!(# w3, w4 #) = unsafeConvertByte (and# w 0xff##)
!(# w1, w2 #) = unsafeConvertByte (uncheckedShiftRL# (word16ToWordCompat# w) 8#)
!(# w3, w4 #) = unsafeConvertByte (and# (word16ToWordCompat# w) 0xff##)

-- | hex word32
hexWord32 :: Word32 -> (Char, Char, Char, Char, Char, Char, Char, Char)
Expand All @@ -53,10 +54,10 @@ hexWord32 (W32# w) = (toChar w1,toChar w2,toChar w3,toChar w4
where
toChar :: Word# -> Char
toChar c = C# (chr# (word2Int# c))
!(# w1, w2 #) = unsafeConvertByte (uncheckedShiftRL# w 24#)
!(# w3, w4 #) = unsafeConvertByte (and# (uncheckedShiftRL# w 16#) 0xff##)
!(# w5, w6 #) = unsafeConvertByte (and# (uncheckedShiftRL# w 8#) 0xff##)
!(# w7, w8 #) = unsafeConvertByte (and# w 0xff##)
!(# w1, w2 #) = unsafeConvertByte (uncheckedShiftRL# (word32ToWordCompat# w) 24#)
!(# w3, w4 #) = unsafeConvertByte (and# (uncheckedShiftRL# (word32ToWordCompat# w) 16#) 0xff##)
!(# w5, w6 #) = unsafeConvertByte (and# (uncheckedShiftRL# (word32ToWordCompat# w) 8#) 0xff##)
!(# w7, w8 #) = unsafeConvertByte (and# (word32ToWordCompat# w) 0xff##)

data Table = Table Addr#

Expand Down
Loading