{-# LANGUAGE MagicHash, UnboxedTuples #-}-- |-- Module : Data.Primitive.Addr-- Copyright : (c) Roman Leshchinskiy 2009-2012-- License : BSD-style---- Maintainer : Roman Leshchinskiy <rl@cse.unsw.edu.au>-- Portability : non-portable-- -- Primitive operations on machine addresses--moduleData.Primitive.Addr(-- * TypesAddr(..),-- * Address arithmeticnullAddr,plusAddr,minusAddr,remAddr,-- * Element accessindexOffAddr,readOffAddr,writeOffAddr,-- * Block operationscopyAddr,moveAddr,setAddr)whereimportControl.Monad.PrimitiveimportData.Primitive.TypesimportGHC.Base(Int(..))importGHC.PrimimportGHC.PtrimportForeign.Marshal.Utils-- | The null addressnullAddr::AddrnullAddr=AddrnullAddr#infixl6`plusAddr`,`minusAddr`infixl7`remAddr`-- | Offset an address by the given number of bytesplusAddr::Addr->Int->AddrplusAddr(Addra#)(I#i#)=Addr(plusAddr#a#i#)-- | Distance in bytes between two addresses. The result is only valid if the-- difference fits in an 'Int'.minusAddr::Addr->Addr->IntminusAddr(Addra#)(Addrb#)=I#(minusAddr#a#b#)-- | The remainder of the address and the integer.remAddr::Addr->Int->IntremAddr(Addra#)(I#i#)=I#(remAddr#a#i#)-- | 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.indexOffAddr::Prima=>Addr->Int->a{-# INLINE indexOffAddr #-}indexOffAddr(Addraddr#)(I#i#)=indexOffAddr#addr#i#-- | 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.readOffAddr::(Prima,PrimMonadm)=>Addr->Int->ma{-# INLINE readOffAddr #-}readOffAddr(Addraddr#)(I#i#)=primitive(readOffAddr#addr#i#)-- | 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.writeOffAddr::(Prima,PrimMonadm)=>Addr->Int->a->m(){-# INLINE writeOffAddr #-}writeOffAddr(Addraddr#)(I#i#)x=primitive_(writeOffAddr#addr#i#x)-- | Copy the given number of bytes from the second 'Addr' to the first. The-- areas may not overlap.copyAddr::PrimMonadm=>Addr-- ^ destination address->Addr-- ^ source address->Int-- ^ number of bytes->m(){-# INLINE copyAddr #-}copyAddr(Addrdst#)(Addrsrc#)n=unsafePrimToPrim$copyBytes(Ptrdst#)(Ptrsrc#)n-- | Copy the given number of bytes from the second 'Addr' to the first. The-- areas may overlap.moveAddr::PrimMonadm=>Addr-- ^ destination address->Addr-- ^ source address->Int-- ^ number of bytes->m(){-# INLINE moveAddr #-}moveAddr(Addrdst#)(Addrsrc#)n=unsafePrimToPrim$moveBytes(Ptrdst#)(Ptrsrc#)n-- | Fill a memory block of with the given value. The length is in-- elements of type @a@ rather than in bytes.setAddr::(Prima,PrimMonadm)=>Addr->Int->a->m(){-# INLINE setAddr #-}setAddr(Addraddr#)(I#n#)x=primitive_(setOffAddr#addr#0#n#x)