mirror of
https://github.com/gren-lang/compiler.git
synced 2024-09-11 16:56:29 +03:00
Cosmetic changes.
This commit is contained in:
parent
5f9c114b4b
commit
24c5f86381
@ -1,56 +1,47 @@
|
||||
module Generate.VLQ
|
||||
( encode
|
||||
) where
|
||||
module Generate.VLQ
|
||||
( encode,
|
||||
)
|
||||
where
|
||||
|
||||
import Data.Bits ((.|.), (.&.))
|
||||
import Data.Bits ((.&.), (.|.))
|
||||
import Data.Bits qualified as Bit
|
||||
import Data.Foldable.WithIndex (ifoldr)
|
||||
import Data.Function ((&))
|
||||
import Data.List qualified as List
|
||||
import Data.Map (Map, (!))
|
||||
import Data.Map qualified as Map
|
||||
import Data.Function ((&))
|
||||
import Data.Foldable.WithIndex (ifoldr)
|
||||
|
||||
|
||||
{- Ported from the Elm package Janiczek/elm-vlq
|
||||
-}
|
||||
|
||||
encode :: Int -> String
|
||||
encode num =
|
||||
let
|
||||
numWithSign =
|
||||
if num < 0
|
||||
then (negate num `Bit.shiftL` 1) .|. 1
|
||||
else num `Bit.shiftL` 1
|
||||
in
|
||||
encodeHelp numWithSign ""
|
||||
encode num =
|
||||
let numWithSign =
|
||||
if num < 0
|
||||
then (negate num `Bit.shiftL` 1) .|. 1
|
||||
else num `Bit.shiftL` 1
|
||||
in encodeHelp numWithSign ""
|
||||
|
||||
encodeHelp :: Int -> String -> String
|
||||
encodeHelp num acc =
|
||||
let
|
||||
clamped =
|
||||
num .&. 31
|
||||
let clamped =
|
||||
num .&. 31
|
||||
|
||||
newNum =
|
||||
num `Bit.shiftR` 5
|
||||
num `Bit.shiftR` 5
|
||||
|
||||
newClamped =
|
||||
if newNum > 0 then
|
||||
clamped .|. 32
|
||||
|
||||
else
|
||||
clamped
|
||||
if newNum > 0
|
||||
then clamped .|. 32
|
||||
else clamped
|
||||
|
||||
newAcc =
|
||||
base64Table ! newClamped : acc
|
||||
in
|
||||
if newNum > 0 then
|
||||
encodeHelp newNum newAcc
|
||||
|
||||
else
|
||||
List.reverse newAcc
|
||||
|
||||
base64Table ! newClamped : acc
|
||||
in if newNum > 0
|
||||
then encodeHelp newNum newAcc
|
||||
else List.reverse newAcc
|
||||
|
||||
base64Table :: Map Int Char
|
||||
base64Table =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='"
|
||||
& ifoldr Map.insert Map.empty
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='"
|
||||
& ifoldr Map.insert Map.empty
|
||||
|
@ -3,7 +3,6 @@ module Generate.VLQSpec (spec) where
|
||||
import Generate.VLQ (encode)
|
||||
import Test.Hspec (Spec, describe, it, shouldBe)
|
||||
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "VLQ tests" $ do
|
||||
|
Loading…
Reference in New Issue
Block a user