summaryrefslogtreecommitdiff
path: root/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/template-haskell/Language/Haskell/TH/Syntax.hs')
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Syntax.hs29
1 files changed, 16 insertions, 13 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
index c531eeffd7..466834a9a4 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
@@ -27,6 +27,7 @@ module Language.Haskell.TH.Syntax
( module Language.Haskell.TH.Syntax
-- * Language extensions
, module Language.Haskell.TH.LanguageExtensions
+ , ForeignSrcLang(..)
) where
import Data.Data hiding (Fixity(..))
@@ -40,6 +41,7 @@ import Data.Word
import Data.Ratio
import GHC.Generics ( Generic )
import GHC.Lexeme ( startsVarSym, startsVarId )
+import GHC.ForeignSrcLang.Type
import Language.Haskell.TH.LanguageExtensions
import Numeric.Natural
@@ -92,7 +94,7 @@ class Monad m => Quasi m where
qAddTopDecls :: [Dec] -> m ()
- qAddCStub :: String -> m ()
+ qAddForeignFile :: ForeignSrcLang -> String -> m ()
qAddModFinalizer :: Q () -> m ()
@@ -133,7 +135,7 @@ instance Quasi IO where
qRecover _ _ = badIO "recover" -- Maybe we could fix this?
qAddDependentFile _ = badIO "addDependentFile"
qAddTopDecls _ = badIO "addTopDecls"
- qAddCStub _ = badIO "addCStub"
+ qAddForeignFile _ _ = badIO "addForeignFile"
qAddModFinalizer _ = badIO "addModFinalizer"
qGetQ = badIO "getQ"
qPutQ _ = badIO "putQ"
@@ -459,24 +461,25 @@ addDependentFile fp = Q (qAddDependentFile fp)
addTopDecls :: [Dec] -> Q ()
addTopDecls ds = Q (qAddTopDecls ds)
--- | Add an additional C stub. The added stub will be built and included in the
--- object file of the current module.
+-- | Emit a foreign file which will be compiled and linked to the object for
+-- the current module. Currently only languages that can be compiled with
+-- the C compiler are supported, and the flags passed as part of -optc will
+-- be also applied to the C compiler invocation that will compile them.
--
--- Compilation errors in the given string are reported next to the line of the
--- enclosing splice.
+-- Note that for non-C languages (for example C++) @extern "C"@ directives
+-- must be used to get symbols that we can access from Haskell.
--
--- The accuracy of the error location can be improved by adding
--- #line pragmas in the argument. e.g.
+-- To get better errors, it is reccomended to use #line pragmas when
+-- emitting C files, e.g.
--
-- > {-# LANGUAGE CPP #-}
-- > ...
--- > addCStub $ unlines
+-- > addForeignFile LangC $ unlines
-- > [ "#line " ++ show (__LINE__ + 1) ++ " " ++ show __FILE__
-- > , ...
-- > ]
---
-addCStub :: String -> Q ()
-addCStub str = Q (qAddCStub str)
+addForeignFile :: ForeignSrcLang -> String -> Q ()
+addForeignFile lang str = Q (qAddForeignFile lang str)
-- | Add a finalizer that will run in the Q monad after the current module has
-- been type checked. This only makes sense when run within a top-level splice.
@@ -521,7 +524,7 @@ instance Quasi Q where
qRunIO = runIO
qAddDependentFile = addDependentFile
qAddTopDecls = addTopDecls
- qAddCStub = addCStub
+ qAddForeignFile = addForeignFile
qAddModFinalizer = addModFinalizer
qGetQ = getQ
qPutQ = putQ