Skip to content

Commit

Permalink
ucd2haskell: Compress further Identifier types
Browse files Browse the repository at this point in the history
Use Shamochu algorithm
  • Loading branch information
wismill committed Jun 14, 2024
1 parent 8acd9c3 commit c524fd9
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 820 deletions.
22 changes: 18 additions & 4 deletions ucd2haskell/exe/UCD2Haskell/Modules/Security/IdentifierType.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ import qualified Data.Set as Set
import qualified Unicode.CharacterDatabase.Parser.Common as U
import qualified Unicode.CharacterDatabase.Parser.Properties.Single as Prop

import UCD2Haskell.Generator (FileRecipe (..), unlinesBB, apacheLicense, genEnumBitmap, splitPlanes)
import UCD2Haskell.Common (Fold (..))
import UCD2Haskell.Generator (
FileRecipe (..),
apacheLicense,
genEnumBitmapShamochu,
splitPlanes,
unlinesBB,
)

recipe :: FileRecipe Prop.Entry
recipe = ModuleRecipe
Expand Down Expand Up @@ -146,11 +152,13 @@ genIdentifierTypeModule moduleName = Fold step mempty done
, "(IdentifierType(..), identifierTypes, decodeIdentifierTypes)"
, "where"
, ""
, "import Data.Bits (Bits(..))"
, "import Data.Char (ord)"
, "import Data.Int (Int8)"
, "import Data.List.NonEmpty (NonEmpty)"
, "import Data.Word (Word8)"
, "import Data.Word (Word8, Word16)"
, "import GHC.Exts (Ptr(..))"
, "import Unicode.Internal.Bits (lookupWord8AsInt)"
, "import Unicode.Internal.Bits (lookupWord8AsInt, lookupWord16AsInt)"
, ""
, "-- | Identifier type"
, "--"
Expand Down Expand Up @@ -195,14 +203,20 @@ genIdentifierTypeModule moduleName = Fold step mempty done
, " _ -> " <> mkHaskellConstructorsList def
, ""
, "-- | Returns the 'IdentifierType's corresponding to a character."
, genEnumBitmap
, genEnumBitmapShamochu
"identifierTypes"
(NE.singleton 3)
[5]
toWord8
(defIdx, BB.intDec (fromEnum defIdx))
(defIdx, BB.intDec (fromEnum defIdx))
planes0To3
plane14
]
where
toWord8 =
assert (fromEnum (maxBound :: IdentifierType) < 0xff)
(fromIntegral . fromEnum)
(planes0To3, plane14) = splitPlanes
"Cannot generate: genIdentifierTypeModule"
(== defIdx)
Expand Down
Loading

0 comments on commit c524fd9

Please sign in to comment.