Skip to content

Commit

Permalink
Support pure foreign functions
Browse files Browse the repository at this point in the history
  • Loading branch information
edsko committed Apr 19, 2024
1 parent f70b040 commit e86be9f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/Test/TraceForeignCalls/UsePlugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@
{-# OPTIONS_GHC -fplugin=Plugin.TraceForeignCalls #-}

module Test.TraceForeignCalls.UsePlugin (
-- * IO functions
answerIO
, answerPure
, slowAddIO
, slowAddPure
) where

import Foreign.C

foreign import capi "test_cbits.h answer" c_answerIO :: IO CInt
foreign import capi "test_cbits.h slow_add" c_slowAddIO :: CLong -> CLong -> IO CLong
foreign import capi "test_cbits.h answer" c_answerIO :: IO CInt
foreign import capi "test_cbits.h answer" c_answerPure :: CInt

foreign import capi "test_cbits.h slow_add" c_slowAddIO :: CLong -> CLong -> IO CLong
foreign import capi "test_cbits.h slow_add" c_slowAddPure :: CLong -> CLong -> CLong

answerIO :: IO Int
answerIO = fromIntegral <$> c_answerIO

answerPure :: Int
answerPure = fromIntegral $ c_answerPure

slowAddIO :: Int -> Int -> IO Int
slowAddIO a b = fromIntegral <$> c_slowAddIO (fromIntegral a) (fromIntegral b)

slowAddPure :: Int -> Int -> Int
slowAddPure a b = fromIntegral $ c_slowAddPure (fromIntegral a) (fromIntegral b)

0 comments on commit e86be9f

Please sign in to comment.