-module Mate.MemoryManager ( ) where
+module Mate.MemoryManager (evacuateList, AllocationManager,
+ TwoSpace, initTwoSpace) where
where alloc :: TwoSpace -> IntPtr -> StateT TwoSpace IO (Ptr b)
alloc state end = do let ptr = toHeap state
put $ state { toHeap = end }
where alloc :: TwoSpace -> IntPtr -> StateT TwoSpace IO (Ptr b)
alloc state end = do let ptr = toHeap state
put $ state { toHeap = end }
evacuate'' obj = do (size,payload) <- liftIO ((,) <$> size obj <*> payload obj)
-- malloc in TwoSpace
newPtr <- mallocBytes size
evacuate'' obj = do (size,payload) <- liftIO ((,) <$> size obj <*> payload obj)
-- malloc in TwoSpace
newPtr <- mallocBytes size
-- copy data over and leave notice
liftIO (copyBytes newPtr (intPtrToPtr payload) size >>
newRef obj (cast newPtr))
-- copy data over and leave notice
liftIO (copyBytes newPtr (intPtrToPtr payload) size >>
newRef obj (cast newPtr))
-evacuate :: (RefObj a, AllocationManager b) => [a] -> b -> IO ()
-evacuate objs manager = evalStateT (evacuate' objs) manager
+evacuateList :: (RefObj a, AllocationManager b) => [a] -> b -> IO ()
+evacuateList objs manager = evalStateT (evacuate' objs) manager
fromSpace <- Alloc.mallocBytes size
toSpace <- Alloc.mallocBytes size
if fromSpace /= nullPtr && toSpace /= nullPtr
then return $ buildToSpace fromSpace toSpace
fromSpace <- Alloc.mallocBytes size
toSpace <- Alloc.mallocBytes size
if fromSpace /= nullPtr && toSpace /= nullPtr
then return $ buildToSpace fromSpace toSpace
where buildToSpace from to = let fromBase' = ptrToIntPtr from
toBase' = ptrToIntPtr to
fromExtreme' = ptrToIntPtr $ from `plusPtr` size
where buildToSpace from to = let fromBase' = ptrToIntPtr from
toBase' = ptrToIntPtr to
fromExtreme' = ptrToIntPtr $ from `plusPtr` size