mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-09-21 07:28:30 +03:00
Implement bitWidth (for cue/rub).
This commit is contained in:
parent
966792b767
commit
b4b4d2ff7b
@ -6,7 +6,7 @@ import Prelude
|
|||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Numeric.Natural
|
import Data.Noun.Atom
|
||||||
import Data.Bits
|
import Data.Bits
|
||||||
|
|
||||||
import Data.List (intercalate)
|
import Data.List (intercalate)
|
||||||
@ -17,8 +17,6 @@ import qualified Control.Monad.Fail as Fail
|
|||||||
|
|
||||||
-- Types -----------------------------------------------------------------------
|
-- Types -----------------------------------------------------------------------
|
||||||
|
|
||||||
type Atom = Natural
|
|
||||||
|
|
||||||
data Cell = ACell !Noun !Noun
|
data Cell = ACell !Noun !Noun
|
||||||
deriving (Eq, Ord)
|
deriving (Eq, Ord)
|
||||||
|
|
||||||
|
27
pkg/hair/lib/Data/Noun/Atom.hs
Normal file
27
pkg/hair/lib/Data/Noun/Atom.hs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{-# LANGUAGE MagicHash, GeneralizedNewtypeDeriving, UnboxedTuples #-}
|
||||||
|
|
||||||
|
module Data.Noun.Atom where
|
||||||
|
|
||||||
|
import ClassyPrelude
|
||||||
|
import Prelude ((^))
|
||||||
|
import GHC.Integer.GMP.Internals
|
||||||
|
import GHC.Natural
|
||||||
|
import GHC.Prim
|
||||||
|
import GHC.Word
|
||||||
|
|
||||||
|
newtype Atom = Atom Natural
|
||||||
|
deriving (Eq, Ord, Show, Num)
|
||||||
|
|
||||||
|
wordBitWidth :: Word# -> Word#
|
||||||
|
wordBitWidth w = minusWord# 64## (clz# w)
|
||||||
|
|
||||||
|
bigNatBitWidth :: BigNat -> Word#
|
||||||
|
bigNatBitWidth nat =
|
||||||
|
lswBits `plusWord#` ((int2Word# lastIdx) `timesWord#` 64##)
|
||||||
|
where
|
||||||
|
(# lastIdx, _ #) = subIntC# (sizeofBigNat# nat) 1#
|
||||||
|
lswBits = wordBitWidth (indexBigNat# nat lastIdx)
|
||||||
|
|
||||||
|
bitWidth :: Atom -> Atom
|
||||||
|
bitWidth (Atom (NatS# gl)) = Atom (NatS# (wordBitWidth gl))
|
||||||
|
bitWidth (Atom (NatJ# bn)) = Atom (NatS# (bigNatBitWidth bn))
|
@ -2,6 +2,7 @@ module Data.Noun.Jam where
|
|||||||
|
|
||||||
import ClassyPrelude
|
import ClassyPrelude
|
||||||
import Data.Noun
|
import Data.Noun
|
||||||
|
import Data.Noun.Atom
|
||||||
import Data.Noun.Poet
|
import Data.Noun.Poet
|
||||||
import Data.Bits
|
import Data.Bits
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
@ -14,9 +15,6 @@ import Control.Monad (guard)
|
|||||||
jam :: Noun -> Atom
|
jam :: Noun -> Atom
|
||||||
jam = undefined
|
jam = undefined
|
||||||
|
|
||||||
bitWidth :: Atom -> Atom
|
|
||||||
bitWidth = undefined
|
|
||||||
|
|
||||||
bitIdx :: Atom -> Atom -> Bool
|
bitIdx :: Atom -> Atom -> Bool
|
||||||
bitIdx idx buf = testBit buf (fromIntegral idx)
|
bitIdx idx buf = testBit buf (fromIntegral idx)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import Prelude
|
|||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Numeric.Natural
|
import GHC.Natural
|
||||||
import Data.Noun
|
import Data.Noun
|
||||||
|
|
||||||
import Data.Word (Word, Word32, Word64)
|
import Data.Word (Word, Word32, Word64)
|
||||||
|
@ -3,5 +3,8 @@ resolver: lts-13.10
|
|||||||
packages:
|
packages:
|
||||||
- .
|
- .
|
||||||
|
|
||||||
|
ghc-options:
|
||||||
|
vere: "-fobject-code"
|
||||||
|
|
||||||
extra-deps:
|
extra-deps:
|
||||||
- para-1.1@sha256:a90eebb063ad70271e6e2a7f00a93e8e8f8b77273f100f39852fbf8301926f81
|
- para-1.1@sha256:a90eebb063ad70271e6e2a7f00a93e8e8f8b77273f100f39852fbf8301926f81
|
||||||
|
Loading…
Reference in New Issue
Block a user