inline-c-cpp (empty) → 0.1.0.0
raw patch · 6 files changed
+117/−0 lines, 6 filesdep +basedep +inline-cdep +inline-c-cppsetup-changed
Dependencies added: base, inline-c, inline-c-cpp, template-haskell
Files
- LICENSE +20/−0
- Setup.hs +2/−0
- inline-c-cpp.cabal +37/−0
- src/Language/C/Inline/Cpp.hs +32/−0
- test/tests.cpp +11/−0
- test/tests.hs +15/−0
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 FP Complete Corporation.++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ inline-c-cpp.cabal view
@@ -0,0 +1,37 @@+name: inline-c-cpp+version: 0.1.0.0+synopsis: Lets you embed C++ code into Haskell.+description: Utilities to inline C++ code into Haskell using inline-c. See+ tests for example on how to build.+license: MIT+license-file: LICENSE+author: Francesco Mazzoli+maintainer: francesco@fpcomplete.com+copyright: (c) 2015 FP Complete Corporation+category: FFI+tested-with: GHC == 7.8.4, GHC == 7.10.1+build-type: Simple+cabal-version: >=1.10++source-repository head+ type: git+ location: https://github.com/fpco/inline-c-cpp++library+ exposed-modules: Language.C.Inline.Cpp+ ghc-options: -Wall+ build-depends: base >=4.7 && <5+ , inline-c+ , template-haskell+ hs-source-dirs: src+ default-language: Haskell2010++test-suite tests+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: tests.hs+ c-sources: test/tests.cpp+ build-depends: base >=4 && <5+ , inline-c-cpp+ default-language: Haskell2010+ extra-libraries: stdc++
+ src/Language/C/Inline/Cpp.hs view
@@ -0,0 +1,32 @@+-- | Module exposing a 'Context' to inline C++ code. We only have used+-- this for experiments, so use with caution. See the C++ tests to see+-- how to build inline C++ code.+module Language.C.Inline.Cpp+ ( module Language.C.Inline+ , cppCtx+ , using+ ) where++import Data.Monoid ((<>), mempty)+import qualified Language.Haskell.TH as TH++import Language.C.Inline+import Language.C.Inline.Context++-- | The equivalent of 'C.baseCtx' for C++. It specifies the @.cpp@+-- file extension for the C file, so that g++ will decide to build C+++-- instead of C. See the @.cabal@ test target for an example on how to+-- build.+cppCtx :: Context+cppCtx = baseCtx <> mempty+ { ctxFileExtension = Just "cpp"+ , ctxOutput = Just $ \s -> "extern \"C\" {\n" ++ s ++ "\n}"+ }++-- | Emits an @using@ directive, e.g.+--+-- @+-- C.using "namespace std" ==> using namespace std+-- @+using :: String -> TH.DecsQ+using s = verbatim $ "using " ++ s ++ ";"
+ test/tests.cpp view
@@ -0,0 +1,11 @@++#include <iostream>++extern "C" {+void inline_c_0_e9878d13a3494fc92f462122a4f7dd84b38a6a80(int x_inline_c_0) {++ std::cout << "Hello, world!" << x_inline_c_0 << std::endl;+ +}++}
+ test/tests.hs view
@@ -0,0 +1,15 @@+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE ForeignFunctionInterface #-}+import qualified Language.C.Inline.Cpp as C++C.context C.cppCtx++C.include "<iostream>"++main :: IO ()+main = do+ let x = 3+ [C.block| void {+ std::cout << "Hello, world!" << $(int x) << std::endl;+ } |]