import RnHsSyn ( RenamedHsDecl, RenamedForeignDecl )
import TcMonad
-import TcEnv ( newLocalName )
import TcMonoType ( tcHsSigType, UserTypeCtxt(..) )
import TcHsSyn ( TcMonoBinds, TypecheckedForeignDecl, TcForeignExportDecl )
import TcExpr ( tcExpr )
import Inst ( emptyLIE, LIE, plusLIE )
import ErrUtils ( Message )
-import Id ( Id, mkLocalId )
-import Name ( nameOccName )
+import Id ( Id, mkLocalId, setIdLocalExported )
import PrimRep ( getPrimRepSize, isFloatingRep )
+import Module ( Module )
import Type ( typePrimRep )
+import OccName ( mkForeignExportOcc )
+import Name ( NamedThing(..), mkExternalName )
import TcType ( Type, tcSplitFunTys, tcSplitTyConApp_maybe,
tcSplitForAllTys,
isFFIArgumentTy, isFFIImportResultTy,
isFFIExternalTy, isFFIDynArgumentTy,
isFFIDynResultTy, isForeignPtrTy
)
-import ForeignCall ( CCallSpec(..), CExportSpec(..), CCallTarget(..),
+import ForeignCall ( CExportSpec(..), CCallTarget(..),
isDynamicTarget, isCasmTarget )
import CStrings ( CLabelString, isCLabelString )
import PrelNames ( hasKey, ioTyConKey )
id = mkLocalId nm sig_ty
in
tcCheckFIType sig_ty arg_tys res_ty imp_decl `thenNF_Tc_`
+ -- can't use sig_ty here because it :: Type and we need HsType Id
+ -- hence the undefined
returnTc (id, ForeignImport id undefined imp_decl isDeprec src_loc)
\end{code}
-- valid foreign type. For legacy reasons ft -> IO (Ptr ft) as well
-- as ft -> IO Addr is accepted, too. The use of the latter two forms
-- is DEPRECATED, though.
- checkCg checkCOrAsm `thenNF_Tc_`
+ checkCg checkCOrAsmOrInterp `thenNF_Tc_`
case arg_tys of
[arg1_ty] -> checkForeignArgs isFFIExternalTy arg1_tys `thenNF_Tc_`
checkForeignRes nonIOok isFFIExportResultTy res1_ty `thenNF_Tc_`
%************************************************************************
\begin{code}
-tcForeignExports :: [RenamedHsDecl] -> TcM (LIE, TcMonoBinds, [TcForeignExportDecl])
-tcForeignExports decls =
+tcForeignExports :: Module -> [RenamedHsDecl]
+ -> TcM (LIE, TcMonoBinds, [TcForeignExportDecl])
+tcForeignExports mod decls =
foldlTc combine (emptyLIE, EmptyMonoBinds, [])
[foreign_decl | ForD foreign_decl <- decls, isForeignExport foreign_decl]
where
combine (lie, binds, fs) fe =
- tcFExport fe `thenTc ` \ (a_lie, b, f) ->
+ tcFExport mod fe `thenTc ` \ (a_lie, b, f) ->
returnTc (lie `plusLIE` a_lie, b `AndMonoBinds` binds, f:fs)
-tcFExport :: RenamedForeignDecl -> TcM (LIE, TcMonoBinds, TcForeignExportDecl)
-tcFExport fo@(ForeignExport nm hs_ty spec isDeprec src_loc) =
+tcFExport :: Module -> RenamedForeignDecl -> TcM (LIE, TcMonoBinds, TcForeignExportDecl)
+tcFExport mod fo@(ForeignExport nm hs_ty spec isDeprec src_loc) =
tcAddSrcLoc src_loc $
tcAddErrCtxt (foreignDeclCtxt fo) $
-- constrained than its declared/inferred type. Hence the need
-- to create a local binding which will call the exported function
-- at a particular type (and, maybe, overloading).
- newLocalName nm `thenNF_Tc` \ id_name ->
+
+ tcGetUnique `thenNF_Tc` \ uniq ->
let
- id = mkLocalId id_name sig_ty
+ gnm = mkExternalName uniq mod (mkForeignExportOcc (getOccName nm)) src_loc
+ id = setIdLocalExported (mkLocalId gnm sig_ty)
bind = VarMonoBind id rhs
in
returnTc (lie, bind, ForeignExport id undefined spec isDeprec src_loc)