diff options
author | Alec Theriault <alec.theriault@gmail.com> | 2018-03-25 13:59:27 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-03-25 14:33:22 -0400 |
commit | ceb914771aece0aa6d87339227ce406c7179d1d1 (patch) | |
tree | 1b63f9af0e0c7e212c840e1ccd1e6add484774cf /testsuite/tests/th/T14298.hs | |
parent | affdea82bb70e5a912b679a169c6e9a230e4c93e (diff) | |
download | haskell-ceb914771aece0aa6d87339227ce406c7179d1d1.tar.gz |
Support adding objects from TH
The user facing TH interface changes are:
* 'addForeignFile' is renamed to 'addForeignSource'
* 'qAddForeignFile'/'addForeignFile' now expect 'FilePath's
* 'RawObject' is now a constructor for 'ForeignSrcLang'
* 'qAddTempFile'/'addTempFile' let you request a temporary file
from the compiler.
Test Plan: unsure about this, added a TH test
Reviewers: goldfire, bgamari, angerman
Reviewed By: bgamari, angerman
Subscribers: hsyl20, mboes, carter, simonmar, bitonic, ljli, rwbarton, thomie
GHC Trac Issues: #14298
Differential Revision: https://phabricator.haskell.org/D4217
Diffstat (limited to 'testsuite/tests/th/T14298.hs')
-rw-r--r-- | testsuite/tests/th/T14298.hs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/testsuite/tests/th/T14298.hs b/testsuite/tests/th/T14298.hs new file mode 100644 index 0000000000..7896e491cb --- /dev/null +++ b/testsuite/tests/th/T14298.hs @@ -0,0 +1,24 @@ +{-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE TemplateHaskell #-} + +import Language.Haskell.TH.Syntax +import System.IO (hFlush, stdout) + +foreign import ccall foo :: Int -> IO Int + +do fpIn <- addTempFile "c" + let cSrc = (unlines [ "#include <stdio.h>" + , "int foo(int x) {" + , " printf(\"calling f(%d)\\n\",x);" + , " fflush(stdout);" + , " return 1 + x;" + , "}" + ]) + runIO $ writeFile fpIn cSrc + addForeignFilePath LangC fpIn + return [] + +main :: IO () +main = do + foo 2 >>= print + hFlush stdout |