Data.Primitive.Addr

primitive-0.6.1.0: Primitive memory-related operations

Copyright | (c) Roman Leshchinskiy 2009-2012
License | BSD-style
Maintainer | Roman Leshchinskiy <rl@cse.unsw.edu.au>
Portability | non-portable
Safe Haskell | None
Language | Haskell2010

Data.Primitive.Addr

Contents

- Types
- Address arithmetic
- Element access
- Block operations

Description

Primitive operations on machine addresses

Synopsis

- data Addr = Addr Addr#
- nullAddr :: Addr
- plusAddr :: Addr -> Int -> Addr
- minusAddr :: Addr -> Addr -> Int
- remAddr :: Addr -> Int -> Int
- indexOffAddr :: Prim a => Addr -> Int -> a
- readOffAddr :: (Prim a, PrimMonad m) => Addr -> Int -> m a
- writeOffAddr :: (Prim a, PrimMonad m) => Addr -> Int -> a -> m ()
- copyAddr :: PrimMonad m => Addr -> Addr -> Int -> m ()
- moveAddr :: PrimMonad m => Addr -> Addr -> Int -> m ()
- setAddr :: (Prim a, PrimMonad m) => Addr -> Int -> a -> m ()

# Types

data Addr #

A machine address

Constructors

Addr Addr# |

Instances

Eq Addr # |
Methods (==) :: Addr -> Addr -> Bool # (/=) :: Addr -> Addr -> Bool #
Data Addr # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Addr -> c Addr # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Addr # toConstr :: Addr -> Constr # dataTypeOf :: Addr -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Addr) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Addr) # gmapT :: (forall b. Data b => b -> b) -> Addr -> Addr # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Addr -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Addr -> r # gmapQ :: (forall d. Data d => d -> u) -> Addr -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Addr -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Addr -> m Addr # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Addr -> m Addr # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Addr -> m Addr #
Ord Addr # |
Methods compare :: Addr -> Addr -> Ordering # (<) :: Addr -> Addr -> Bool # (<=) :: Addr -> Addr -> Bool # (>) :: Addr -> Addr -> Bool # (>=) :: Addr -> Addr -> Bool # max :: Addr -> Addr -> Addr # min :: Addr -> Addr -> Addr #
Prim Addr # |
Methods sizeOf# :: Addr -> Int# # alignment# :: Addr -> Int# # indexByteArray# :: ByteArray# -> Int# -> Addr # readByteArray# :: MutableByteArray# s -> Int# -> State# s -> (#VoidRep, PtrRepLifted, State# s, Addr#) # writeByteArray# :: MutableByteArray# s -> Int# -> Addr -> State# s -> State# s # setByteArray# :: MutableByteArray# s -> Int# -> Int# -> Addr -> State# s -> State# s # indexOffAddr# :: Addr# -> Int# -> Addr # readOffAddr# :: Addr# -> Int# -> State# s -> (#VoidRep, PtrRepLifted, State# s, Addr#) # writeOffAddr# :: Addr# -> Int# -> Addr -> State# s -> State# s # setOffAddr# :: Addr# -> Int# -> Int# -> Addr -> State# s -> State# s #

# Address arithmetic

nullAddr :: Addr #

The null address

plusAddr :: Addr -> Int -> Addr infixl 6 #

Offset an address by the given number of bytes

minusAddr :: Addr -> Addr -> Int infixl 6 #

Distance in bytes between two addresses. The result is only valid if the difference fits in an `Int`.

remAddr :: Addr -> Int -> Int infixl 7 #

The remainder of the address and the integer.

# Element access

indexOffAddr :: Prim a => Addr -> Int -> a #

Read a value from a memory position given by an address and an offset. The memory block the address refers to must be immutable. The offset is in elements of type `a` rather than in bytes.

readOffAddr :: (Prim a, PrimMonad m) => Addr -> Int -> m a #

Read a value from a memory position given by an address and an offset. The offset is in elements of type `a` rather than in bytes.

writeOffAddr :: (Prim a, PrimMonad m) => Addr -> Int -> a -> m () #

Write a value to a memory position given by an address and an offset. The offset is in elements of type `a` rather than in bytes.

# Block operations

copyAddr #

Arguments

:: PrimMonad m |
=> Addr | destination address
-> Addr | source address
-> Int | number of bytes
-> m () |

Copy the given number of bytes from the second `Addr` to the first. The areas may not overlap.

moveAddr #

Arguments

:: PrimMonad m |
=> Addr | destination address
-> Addr | source address
-> Int | number of bytes
-> m () |

Copy the given number of bytes from the second `Addr` to the first. The areas may overlap.

setAddr :: (Prim a, PrimMonad m) => Addr -> Int -> a -> m () #

Fill a memory block of with the given value. The length is in elements of type `a` rather than in bytes.