gc: delegated mallocs in GarbageAlloc to hs-boehmgc (Mate.GC.Boehm.mallocBytes);
[mate.git] / Mate / GarbageAlloc.hs
1 {-# LANGUAGE ForeignFunctionInterface #-}
2 {-# LANGUAGE CPP #-}
3 #include "debug.h"
4 module Mate.GarbageAlloc(
5     mallocClassData,
6     mallocString,
7     mallocObject,
8     getHeapMemory)  where
9
10 import Foreign
11 import Foreign.C
12
13 import Mate.GC.Boehm
14
15 import Text.Printf
16 import Mate.Debug
17
18 -- unified place for allocating Memory
19 -- TODO: implement GC stuff ;-)
20
21 mallocClassData :: Int -> IO (Ptr a)
22 mallocClassData size = do
23   printfStr "mallocClassData: %d\n" size
24   mallocBytesGC size
25
26 mallocString :: Int -> IO (Ptr a)
27 mallocString size = do
28   printfStr "mallocString: %d\n" size
29   mallocBytesGC size
30
31 foreign export ccall mallocObject :: Int -> IO CPtrdiff
32 mallocObject :: Int -> IO CPtrdiff
33 mallocObject size = do
34   ptr <- mallocBytesGC size
35   printfStr "mallocObject: %d\n" size
36   return $ fromIntegral $ ptrToIntPtr ptr
37
38 -- TODO: delete me
39 foreign export ccall demoInterfaceCall :: CUInt -> IO ()
40 demoInterfaceCall :: CUInt -> IO ()
41 demoInterfaceCall val = do
42   printf "demoInterfaceCall: 0x%08x\n" (fromIntegral val :: Word32)
43   return ()
44
45 getHeapMemory :: IO Int
46 getHeapMemory = getHeapSize
47