-- Declarations
-------------------------------------------------------
-repTopDs :: HsGroup Name -> DsM (Core [M.Decl])
+repTopDs :: HsGroup Name -> DsM (Core (M.Q [M.Dec]))
repTopDs group
= do { let { bndrs = groupBinders group } ;
ss <- mkGenSyms bndrs ;
-- more needed
return (val_ds ++ catMaybes tycl_ds ++ inst_ds) }) ;
- core_list <- coreList declTyConName decls ;
- wrapNongenSyms ss core_list
+ decl_ty <- lookupType declTyConName ;
+ let { core_list = coreList' decl_ty decls } ;
+ q_decs <- repSequenceQ decl_ty core_list ;
+
+ wrapNongenSyms ss q_decs
-- Do *not* gensym top-level binders
}
repE (RecordUpdOut _ _ _ _) = panic "DsMeta.repE: No record update yet"
repE (ExprWithTySig e ty) = do { e1 <- repE e; t1 <- repTy ty; repSigExp e1 t1 }
-repE (ArithSeqOut _ aseq) =
+repE (ArithSeqIn aseq) =
case aseq of
From e -> do { ds1 <- repE e; repFrom ds1 }
FromThen e1 e2 -> do
RecCon pairs -> error "No records in template haskell yet"
InfixCon p1 p2 -> do { qs <- repPs [p1,p2]; repPcon con_str qs }
}
+repP (NPatIn l (Just _)) = panic "Can't cope with negative overloaded patterns yet (repP (NPatIn _ (Just _)))"
+repP (NPatIn l Nothing) = do { a <- repOverloadedLiteral l; repPlit a }
repP other = panic "Exotic pattern inside meta brackets"
repListPat :: [Pat Name] -> DsM (Core M.Patt)
-- Just like wrapGenSym, but don't actually do the gensym
-- Instead use the existing name
-- Only used for [Decl]
-wrapNongenSyms :: [GenSymBind]
- -> Core [M.Decl] -> DsM (Core [M.Decl])
-wrapNongenSyms binds body@(MkC b)
- = go binds
+wrapNongenSyms :: [GenSymBind] -> Core a -> DsM (Core a)
+wrapNongenSyms binds (MkC body)
+ = do { binds' <- mapM do_one binds ;
+ return (MkC (mkLets binds' body)) }
where
- go [] = return body
- go ((name,id) : binds)
- = do { MkC body' <- go binds
- ; MkC lit_str <- localVar name -- No gensym
- ; return (MkC (Let (NonRec id lit_str) body'))
- }
+ do_one (name,id)
+ = do { MkC lit_str <- localVar name -- No gensym
+ ; return (NonRec id lit_str) }
void = placeHolderType
repBindQ ty_a ty_b (MkC x) (MkC y)
= rep2 bindQName [Type ty_a, Type ty_b, x, y]
+repSequenceQ :: Type -> Core [M.Q a] -> DsM (Core (M.Q [a]))
+repSequenceQ ty_a (MkC list)
+ = rep2 sequenceQName [Type ty_a, list]
+
------------ Lists and Tuples -------------------
-- turn a list of patterns into a single pattern matching a list
bindStName, letStName, noBindStName, parStName,
fromName, fromThenName, fromToName, fromThenToName,
funName, valName, liftName,
- gensymName, returnQName, bindQName,
+ gensymName, returnQName, bindQName, sequenceQName,
matchName, clauseName, funName, valName, dataDName, classDName,
instName, protoName, tvarName, tconName, tappName,
arrowTyConName, tupleTyConName, listTyConName, namedTyConName,
gensymName = varQual FSLIT("gensym") gensymIdKey
returnQName = varQual FSLIT("returnQ") returnQIdKey
bindQName = varQual FSLIT("bindQ") bindQIdKey
+sequenceQName = varQual FSLIT("sequenceQ") sequenceQIdKey
-- type Mat = ...
matchName = varQual FSLIT("match") matchIdKey
instIdKey = mkPreludeMiscIdUnique 216
dataDIdKey = mkPreludeMiscIdUnique 217
+sequenceQIdKey = mkPreludeMiscIdUnique 218
plitIdKey = mkPreludeMiscIdUnique 220
pvarIdKey = mkPreludeMiscIdUnique 221
import Type ( Type )
import BasicTypes( Boxity(..), RecFlag(Recursive),
NewOrData(..), StrictnessMark(..) )
-import FastString( mkFastString )
+import ForeignCall ( Safety(..), CCallConv(..), CCallTarget(..) )
+import HsDecls ( CImportSpec(..), ForeignImport(..), ForeignDecl(..) )
+import FastString( mkFastString, nilFS )
import Char ( ord, isAlphaNum )
import List ( partition )
import Outputable
cvt_top (Proto nm typ) = SigD (Sig (vName nm) (cvtType typ) loc0)
+cvt_top (Foreign (Import callconv safety from nm typ))
+ = ForD (ForeignImport (vName nm) (cvtType typ) fi False loc0)
+ where fi = CImport CCallConv (PlaySafe True) c_header nilFS cis
+ (c_header', c_func') = break (== ' ') from
+ c_header = mkFastString c_header'
+ c_func = tail c_func'
+ cis = CFunction (StaticTarget (mkFastString c_func))
+
noContext = []
noExistentials = []
noFunDeps = []
import TcExpr ( tcMonoExpr )
import TcHsSyn ( TcExpr, TypecheckedHsExpr, mkHsLet, zonkTopExpr )
import TcSimplify ( tcSimplifyTop )
-import TcType ( TcType, openTypeKind )
+import TcType ( TcType, openTypeKind, mkAppTy )
import TcEnv ( spliceOK, tcMetaTy )
import TcRnTypes ( TopEnv(..) )
import TcMType ( newTyVarTy )
import TcRnMonad
import TysWiredIn ( mkListTy )
-import DsMeta ( exprTyConName, declTyConName )
+import DsMeta ( exprTyConName, declTyConName, decTyConName, qTyConName )
import Outputable
import GHC.Base ( unsafeCoerce# ) -- Should have a better home in the module hierarchy
\end{code}
= newTyVarTy openTypeKind `thenM` \ any_ty ->
tcMonoExpr expr any_ty `thenM_`
tcMetaTy exprTyConName
+ -- Result type is Expr (= Q Exp)
tcBracket (DecBr decls)
= tcTopSrcDecls decls `thenM_`
- tcMetaTy declTyConName `thenM` \ decl_ty ->
- returnM (mkListTy decl_ty)
+ tcMetaTy decTyConName `thenM` \ decl_ty ->
+ tcMetaTy qTyConName `thenM` \ q_ty ->
+ returnM (mkAppTy q_ty (mkListTy decl_ty))
+ -- Result type is Q [Dec]
\end{code}
+
%************************************************************************
%* *
\subsection{Splicing an expression}
\begin{code}
-- Always at top level
tcSpliceDecls expr
- = tcMetaTy declTyConName `thenM` \ meta_dec_ty ->
+ = tcMetaTy decTyConName `thenM` \ meta_dec_ty ->
+ tcMetaTy qTyConName `thenM` \ meta_q_ty ->
setStage topSpliceStage (
- getLIE (tcMonoExpr expr (mkListTy meta_dec_ty))
+ getLIE (tcMonoExpr expr (mkAppTy meta_q_ty (mkListTy meta_dec_ty)))
) `thenM` \ (expr', lie) ->
-- Solve the constraints
tcSimplifyTop lie `thenM` \ const_binds ->
\begin{code}
runMetaE :: TypecheckedHsExpr -- Of type (Q Exp)
-> TcM Meta.Exp -- Of type Exp
-runMetaE e = runMeta tcRunQ e
+runMetaE e = runMeta e
-runMetaD :: TypecheckedHsExpr -- Of type [Q Dec]
+runMetaD :: TypecheckedHsExpr -- Of type Q [Dec]
-> TcM [Meta.Dec] -- Of type [Dec]
-runMetaD e = runMeta run_decl e
- where
- run_decl :: [Meta.Decl] -> TcM [Meta.Dec]
- run_decl ds = mappM tcRunQ ds
+runMetaD e = runMeta e
-- Warning: if Q is anything other than IO, we need to change this
tcRunQ :: Meta.Q a -> TcM a
tcRunQ thing = ioToTcRn thing
-runMeta :: (x -> TcM t) -- :: X -> IO t
- -> TypecheckedHsExpr -- Of type X
+runMeta :: TypecheckedHsExpr -- Of type X
-> TcM t -- Of type t
-runMeta run_it expr :: TcM t
+runMeta expr
= getTopEnv `thenM` \ top_env ->
getEps `thenM` \ eps ->
getNameCache `thenM` \ name_cache ->
ioToTcRn (HscMain.compileExpr hsc_env pcs this_mod
print_unqual expr) `thenM` \ hval ->
- tryM (run_it (unsafeCoerce# hval)) `thenM` \ either_tval ->
+ tryM (tcRunQ (unsafeCoerce# hval)) `thenM` \ either_tval ->
case either_tval of
Left exn -> failWithTc (vcat [text "Exception when running compile-time code:",