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