From 3cac43f36cea2253d6bb361c978702bb632b202c Mon Sep 17 00:00:00 2001 From: Pierre Le Marre Date: Wed, 12 Jun 2024 10:24:53 +0200 Subject: [PATCH] Rename lookupIntN to lookupWord8AsInt This name is confusing; we are better served with an explicit name. --- ucd2haskell/exe/UCD2Haskell/Generator.hs | 6 +++--- ucd2haskell/exe/UCD2Haskell/Modules/Scripts.hs | 2 +- ucd2haskell/exe/UCD2Haskell/Modules/ScriptsExtensions.hs | 2 +- .../exe/UCD2Haskell/Modules/Security/IdentifierType.hs | 2 +- .../UCD2Haskell/Modules/UnicodeData/GeneralCategory.hs | 4 ++-- .../lib/Unicode/Internal/Char/ScriptExtensions.hs | 6 +++--- unicode-data-scripts/lib/Unicode/Internal/Char/Scripts.hs | 6 +++--- .../lib/Unicode/Internal/Char/Security/IdentifierType.hs | 6 +++--- unicode-data/lib/Unicode/Internal/Bits.hs | 8 ++++---- .../Unicode/Internal/Char/UnicodeData/GeneralCategory.hs | 8 ++++---- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ucd2haskell/exe/UCD2Haskell/Generator.hs b/ucd2haskell/exe/UCD2Haskell/Generator.hs index b5ad6754..895e50de 100644 --- a/ucd2haskell/exe/UCD2Haskell/Generator.hs +++ b/ucd2haskell/exe/UCD2Haskell/Generator.hs @@ -267,7 +267,7 @@ genEnumBitmap funcName (defPUA, pPUA) (def, pDef) planes0To3 plane14 = , showPaddedHeXB (length planes0To3') , " then " , pDef - , " else lookupIntN bitmap# cp\n" + , " else lookupWord8AsInt bitmap# cp\n" , " where\n" ] , planes0To3' ) -- All the planes @@ -279,12 +279,12 @@ genEnumBitmap funcName (defPUA, pPUA) (def, pDef) planes0To3 plane14 = [ " c\n" , " -- Planes 0-3\n" , " | cp < 0x", showPaddedHeXB bound1 - , " = lookupIntN bitmap# cp\n" + , " = lookupWord8AsInt bitmap# cp\n" , " -- Planes 4-13: ", showB def, "\n" , " | cp < 0xE0000 = " <> pDef, "\n" , " -- Plane 14\n" , " | cp < 0x", showPaddedHeXB bound2 - , " = lookupIntN bitmap# (cp - 0x" + , " = lookupWord8AsInt bitmap# (cp - 0x" , showPaddedHeXB (0xE0000 - bound1) , ")\n" , if defPUA == def diff --git a/ucd2haskell/exe/UCD2Haskell/Modules/Scripts.hs b/ucd2haskell/exe/UCD2Haskell/Modules/Scripts.hs index cf4f231d..801bb162 100644 --- a/ucd2haskell/exe/UCD2Haskell/Modules/Scripts.hs +++ b/ucd2haskell/exe/UCD2Haskell/Modules/Scripts.hs @@ -55,7 +55,7 @@ genScriptsModule moduleName aliases = Fold step mempty done , "import Data.Ix (Ix)" , "import Data.Word (Word8)" , "import GHC.Exts (Ptr(..))" - , "import Unicode.Internal.Bits (lookupIntN)" + , "import Unicode.Internal.Bits (lookupWord8AsInt)" , "" , "-- | Unicode [script](https://www.unicode.org/reports/tr24/)." , "--" diff --git a/ucd2haskell/exe/UCD2Haskell/Modules/ScriptsExtensions.hs b/ucd2haskell/exe/UCD2Haskell/Modules/ScriptsExtensions.hs index b3f9a9f4..b484e925 100644 --- a/ucd2haskell/exe/UCD2Haskell/Modules/ScriptsExtensions.hs +++ b/ucd2haskell/exe/UCD2Haskell/Modules/ScriptsExtensions.hs @@ -106,7 +106,7 @@ genScriptExtensionsModule moduleName aliases extensions = Fold step mempty done , "import Data.Word (Word8)" , "import GHC.Exts (Ptr(..))" , "import Unicode.Internal.Char.Scripts (Script(..))" - , "import Unicode.Internal.Bits (lookupIntN)" + , "import Unicode.Internal.Bits (lookupWord8AsInt)" , "" , "-- | Useful to decode the output of 'scriptExtensions'." , "decodeScriptExtensions :: Int -> NonEmpty Script" diff --git a/ucd2haskell/exe/UCD2Haskell/Modules/Security/IdentifierType.hs b/ucd2haskell/exe/UCD2Haskell/Modules/Security/IdentifierType.hs index 46240ae3..6250ac19 100644 --- a/ucd2haskell/exe/UCD2Haskell/Modules/Security/IdentifierType.hs +++ b/ucd2haskell/exe/UCD2Haskell/Modules/Security/IdentifierType.hs @@ -150,7 +150,7 @@ genIdentifierTypeModule moduleName = Fold step mempty done , "import Data.List.NonEmpty (NonEmpty)" , "import Data.Word (Word8)" , "import GHC.Exts (Ptr(..))" - , "import Unicode.Internal.Bits (lookupIntN)" + , "import Unicode.Internal.Bits (lookupWord8AsInt)" , "" , "-- | Identifier type" , "--" diff --git a/ucd2haskell/exe/UCD2Haskell/Modules/UnicodeData/GeneralCategory.hs b/ucd2haskell/exe/UCD2Haskell/Modules/UnicodeData/GeneralCategory.hs index 6bba97b6..48f2cd49 100644 --- a/ucd2haskell/exe/UCD2Haskell/Modules/UnicodeData/GeneralCategory.hs +++ b/ucd2haskell/exe/UCD2Haskell/Modules/UnicodeData/GeneralCategory.hs @@ -103,7 +103,7 @@ genGeneralCategoryModule moduleName = Fold step initial done , "import Data.Char (ord)" , "import Data.Word (Word8)" , "import GHC.Exts (Ptr(..))" - , "import Unicode.Internal.Bits (lookupIntN)" + , "import Unicode.Internal.Bits (lookupWord8AsInt)" , "" , "--------------------------------------------------------------------------------" , "-- General category patterns" @@ -122,7 +122,7 @@ genGeneralCategoryModule moduleName = Fold step initial done , "-- The caller of this function must ensure its parameter is \\< @0x40000@." , "{-# INLINE generalCategoryPlanes0To3 #-}" , "generalCategoryPlanes0To3 :: Int -> Int" - , "generalCategoryPlanes0To3 = lookupIntN bitmap#" + , "generalCategoryPlanes0To3 = lookupWord8AsInt bitmap#" , " where" , " !(Ptr bitmap#) = generalCategoryBitmap" , "" diff --git a/unicode-data-scripts/lib/Unicode/Internal/Char/ScriptExtensions.hs b/unicode-data-scripts/lib/Unicode/Internal/Char/ScriptExtensions.hs index 38bd49fa..2c09df13 100644 --- a/unicode-data-scripts/lib/Unicode/Internal/Char/ScriptExtensions.hs +++ b/unicode-data-scripts/lib/Unicode/Internal/Char/ScriptExtensions.hs @@ -18,7 +18,7 @@ import Data.List.NonEmpty (NonEmpty) import Data.Word (Word8) import GHC.Exts (Ptr(..)) import Unicode.Internal.Char.Scripts (Script(..)) -import Unicode.Internal.Bits (lookupIntN) +import Unicode.Internal.Bits (lookupWord8AsInt) -- | Useful to decode the output of 'scriptExtensions'. decodeScriptExtensions :: Int -> NonEmpty Script @@ -249,11 +249,11 @@ decodeScriptExtensions = \case scriptExtensions :: Char -> Int scriptExtensions c -- Planes 0-3 - | cp < 0x323B0 = lookupIntN bitmap# cp + | cp < 0x323B0 = lookupWord8AsInt bitmap# cp -- Planes 4-13: 211 | cp < 0xE0000 = 211 -- Plane 14 - | cp < 0xE01F0 = lookupIntN bitmap# (cp - 0xADC50) + | cp < 0xE01F0 = lookupWord8AsInt bitmap# (cp - 0xADC50) -- Default: 211 | otherwise = 211 where diff --git a/unicode-data-scripts/lib/Unicode/Internal/Char/Scripts.hs b/unicode-data-scripts/lib/Unicode/Internal/Char/Scripts.hs index 68624f2f..7257d707 100644 --- a/unicode-data-scripts/lib/Unicode/Internal/Char/Scripts.hs +++ b/unicode-data-scripts/lib/Unicode/Internal/Char/Scripts.hs @@ -17,7 +17,7 @@ import Data.Int (Int32) import Data.Ix (Ix) import Data.Word (Word8) import GHC.Exts (Ptr(..)) -import Unicode.Internal.Bits (lookupIntN) +import Unicode.Internal.Bits (lookupWord8AsInt) -- | Unicode [script](https://www.unicode.org/reports/tr24/). -- @@ -371,11 +371,11 @@ scriptDefinition b = case b of script :: Char -> Int script c -- Planes 0-3 - | cp < 0x323B0 = lookupIntN bitmap# cp + | cp < 0x323B0 = lookupWord8AsInt bitmap# cp -- Planes 4-13: 156 | cp < 0xE0000 = 156 -- Plane 14 - | cp < 0xE01F0 = lookupIntN bitmap# (cp - 0xADC50) + | cp < 0xE01F0 = lookupWord8AsInt bitmap# (cp - 0xADC50) -- Default: 156 | otherwise = 156 where diff --git a/unicode-data-security/lib/Unicode/Internal/Char/Security/IdentifierType.hs b/unicode-data-security/lib/Unicode/Internal/Char/Security/IdentifierType.hs index d040bdef..67403341 100644 --- a/unicode-data-security/lib/Unicode/Internal/Char/Security/IdentifierType.hs +++ b/unicode-data-security/lib/Unicode/Internal/Char/Security/IdentifierType.hs @@ -17,7 +17,7 @@ import Data.Char (ord) import Data.List.NonEmpty (NonEmpty) import Data.Word (Word8) import GHC.Exts (Ptr(..)) -import Unicode.Internal.Bits (lookupIntN) +import Unicode.Internal.Bits (lookupWord8AsInt) -- | Identifier type -- @@ -93,11 +93,11 @@ decodeIdentifierTypes = \case identifierTypes :: Char -> Int identifierTypes c -- Planes 0-3 - | cp < 0x323B0 = lookupIntN bitmap# cp + | cp < 0x323B0 = lookupWord8AsInt bitmap# cp -- Planes 4-13: 0 | cp < 0xE0000 = 0 -- Plane 14 - | cp < 0xE01F0 = lookupIntN bitmap# (cp - 0xADC50) + | cp < 0xE01F0 = lookupWord8AsInt bitmap# (cp - 0xADC50) -- Default: 0 | otherwise = 0 where diff --git a/unicode-data/lib/Unicode/Internal/Bits.hs b/unicode-data/lib/Unicode/Internal/Bits.hs index 6ed08dcc..5717d5c2 100644 --- a/unicode-data/lib/Unicode/Internal/Bits.hs +++ b/unicode-data/lib/Unicode/Internal/Bits.hs @@ -13,7 +13,7 @@ module Unicode.Internal.Bits ( lookupBit64, - lookupIntN, + lookupWord8AsInt, lookupWord32# ) where @@ -56,7 +56,7 @@ lookupBit64 addr# (I# index#) = W# (word## `and#` bitMask##) /= 0 bitIndex# = index# `andI#` fbs# bitMask## = 1## `uncheckedShiftL#` bitIndex# -{-| @lookupIntN addr index@ looks up for the @index@-th @8@-bits word in +{-| @lookupWord8AsInt addr index@ looks up for the @index@-th @8@-bits word in the bitmap starting at @addr@, then convert it to an 'Int'. The caller must make sure that: @@ -65,11 +65,11 @@ The caller must make sure that: @since 0.3.0 -} -lookupIntN +lookupWord8AsInt :: Addr# -- ^ Bitmap address -> Int -- ^ Word index -> Int -- ^ Resulting word as 'Int' -lookupIntN addr# (I# index#) = I# (word2Int# word##) +lookupWord8AsInt addr# (I# index#) = I# (word2Int# word##) where #if MIN_VERSION_base(4,16,0) word## = word8ToWord# (indexWord8OffAddr# addr# index#) diff --git a/unicode-data/lib/Unicode/Internal/Char/UnicodeData/GeneralCategory.hs b/unicode-data/lib/Unicode/Internal/Char/UnicodeData/GeneralCategory.hs index 5ef74063..5bf745a4 100644 --- a/unicode-data/lib/Unicode/Internal/Char/UnicodeData/GeneralCategory.hs +++ b/unicode-data/lib/Unicode/Internal/Char/UnicodeData/GeneralCategory.hs @@ -59,7 +59,7 @@ module Unicode.Internal.Char.UnicodeData.GeneralCategory import Data.Char (ord) import Data.Word (Word8) import GHC.Exts (Ptr(..)) -import Unicode.Internal.Bits (lookupIntN) +import Unicode.Internal.Bits (lookupWord8AsInt) -------------------------------------------------------------------------------- -- General category patterns @@ -226,7 +226,7 @@ pattern MaxIsSeparator = 0x3000 -- The caller of this function must ensure its parameter is \< @0x40000@. {-# INLINE generalCategoryPlanes0To3 #-} generalCategoryPlanes0To3 :: Int -> Int -generalCategoryPlanes0To3 = lookupIntN bitmap# +generalCategoryPlanes0To3 = lookupWord8AsInt bitmap# where !(Ptr bitmap#) = generalCategoryBitmap @@ -235,11 +235,11 @@ generalCategoryPlanes0To3 = lookupIntN bitmap# generalCategory :: Char -> Int generalCategory c -- Planes 0-3 - | cp < 0x323B0 = lookupIntN bitmap# cp + | cp < 0x323B0 = lookupWord8AsInt bitmap# cp -- Planes 4-13: Cn | cp < 0xE0000 = NotAssigned -- Plane 14 - | cp < 0xE01F0 = lookupIntN bitmap# (cp - 0xADC50) + | cp < 0xE01F0 = lookupWord8AsInt bitmap# (cp - 0xADC50) -- Plane 14: Cn | cp < 0xF0000 = NotAssigned -- Plane 15: Co