@@ -30,20 +30,30 @@ alloc t = return $ CPt !(malloc (sizeOf t)) 0 t
3030free : CPtr -> IO ()
3131free (CPt p _ _) = mfree p
3232
33+withAlloc : CType -> (CPtr -> IO ()) -> IO ()
34+withAlloc t f = do m <- alloc t
35+ f m
36+ free m
37+
38+infixl 1 ~~>
39+
40+(~~>) : CType -> (CPtr -> IO ()) -> IO ()
41+(~~>) = withAlloc
42+
3343ctype : CPtr -> CType
3444ctype (CPt _ _ t) = t
3545mutual
36− peekArray : (c : CPtr) -> IO (translate (ctype c))
37− peekArray (CPt p o a@(ARRAY n t)) = do
38− os <- return $ fromList (offsets a)
39− return $ map (\x => peek (CPt p x t)) os
40−
41− pokeArray : (c : CPtr) -> translate (ctype c) -> IO ()
42− pokeArray (CPt p o a@(ARRAY n t)) x = do
43− os <- fromList $ offsets a
44− ox <- zip os x
45− map (\(x, y)=>poke (CPt p x t) y) ox
46− return ()
46+ -- peekArray : (c : CPtr) -> IO (translate (ctype c))
47+ -- peekArray (CPt p o a@(ARRAY n t)) = do
48+ -- os <- return $ fromList (offsets a)
49+ -- map (\x => peek (CPt p x t)) os
50+
51+ -- pokeArray : (c : CPtr) -> translate (ctype c) -> IO ()
52+ -- pokeArray (CPt p o a@(ARRAY n t)) x = do
53+ -- os <- fromList $ offsets a
54+ -- ox <- zip os x
55+ -- map (\(x, y)=>poke (CPt p x t) y) ox
56+ -- return ()
4757
4858 peek : (p : CPtr) -> IO (translate (ctype p))
4959 peek (CPt p o I8) = prim_peek8 p o
@@ -53,7 +63,7 @@ mutual
5363 peek (CPt p o FLOAT) = prim_peekSingle p o
5464 peek (CPt p o DOUBLE) = prim_peekDouble p o
5565 peek (CPt p o PTR) = prim_peekPtr p o
56− peek cp@(CPt p o (ARRAY n t)) = peekArray cp
66+ -- peek cp@(CPt p o (ARRAY n t)) = peekArray cp
5767 -- peek (CPt p o (UNION xs)) = ?peekUnion
5868 -- peek (CPt p o (STRUCT xs)) = ?peekStruct
5969 -- peek (CPt p o (PACKEDSTRUCT xs)) = ?peekPacked
@@ -74,7 +84,7 @@ mutual
7484 return ()
7585 poke (CPt p o DOUBLE) x = do _ <- prim_pokeDouble p o x
7686 return ()
77− poke cp@(CPt p o (ARRAY n t)) x = pokeArray cp x
87+ -- poke cp@(CPt p o (ARRAY n t)) x = pokeArray cp x
7888 -- poke (CPt p o (UNION xs)) x = ?pokeUnion
7989 -- poke (CPt p o (STRUCT xs)) x = ?pokeStruct
8090 -- poke (CPt p o (PACKEDSTRUCT xs)) x = ?pokePacked