Skip to content

Commit

Permalink
Rename lookupIntN to lookupWord8AsInt
Browse files Browse the repository at this point in the history
This name is confusing; we are better served with an explicit name.
  • Loading branch information
wismill committed Jun 12, 2024
1 parent dfb502e commit 3cac43f
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions ucd2haskell/exe/UCD2Haskell/Generator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ucd2haskell/exe/UCD2Haskell/Modules/Scripts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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/)."
, "--"
Expand Down
2 changes: 1 addition & 1 deletion ucd2haskell/exe/UCD2Haskell/Modules/ScriptsExtensions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
, "--"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
, ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions unicode-data-scripts/lib/Unicode/Internal/Char/Scripts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
--
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
--
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions unicode-data/lib/Unicode/Internal/Bits.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

module Unicode.Internal.Bits
( lookupBit64,
lookupIntN,
lookupWord8AsInt,
lookupWord32#
) where

Expand Down Expand Up @@ -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:
Expand All @@ -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#)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 3cac43f

Please sign in to comment.