blob: dbd9ddc296b5c1cfe5b05fee7ad5fdf47f172e0a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TemplateHaskell #-}
module Data.Array.Nested.Internal.Arith.Foreign where
import Control.Monad
import Data.Int
import Data.Maybe
import Foreign.Ptr
import Language.Haskell.TH
import Data.Array.Nested.Internal.Arith.Lists
$(fmap concat . forM typesList $ \arithtype -> do
let ttyp = conT (atType arithtype)
fmap concat . forM binopsList $ \arithop -> do
let base = aboName arithop ++ "_" ++ atCName arithtype
sequence $ catMaybes
[Just (ForeignD . ImportF CCall Unsafe ("oxarop_" ++ base ++ "_sv") (mkName ("c_" ++ base ++ "_sv")) <$>
[t| Int64 -> Ptr $ttyp -> $ttyp -> Ptr $ttyp -> IO () |])
,Just (ForeignD . ImportF CCall Unsafe ("oxarop_" ++ base ++ "_vv") (mkName ("c_" ++ base ++ "_vv")) <$>
[t| Int64 -> Ptr $ttyp -> Ptr $ttyp -> Ptr $ttyp -> IO () |])
,guard (aboComm arithop == NonComm) >>
Just (ForeignD . ImportF CCall Unsafe ("oxarop_" ++ base ++ "_vs") (mkName ("c_" ++ base ++ "_vs")) <$>
[t| Int64 -> Ptr $ttyp -> Ptr $ttyp -> $ttyp -> IO () |])
])
$(fmap concat . forM typesList $ \arithtype -> do
let ttyp = conT (atType arithtype)
forM unopsList $ \arithop -> do
let base = auoName arithop ++ "_" ++ atCName arithtype
ForeignD . ImportF CCall Unsafe ("oxarop_" ++ base) (mkName ("c_" ++ base)) <$>
[t| Int64 -> Ptr $ttyp -> Ptr $ttyp -> IO () |])
|