From 73641e01ee9dfbe83f8c6225c1f6ae2e7d621b63 Mon Sep 17 00:00:00 2001 From: simonpj Date: Fri, 8 Nov 2002 09:01:07 +0000 Subject: [PATCH] [project @ 2002-11-08 09:01:06 by simonpj] ------------------ More TH stuff (thanks to Ian L) ------------------ * Make TH Literals have an Integer not an Int * Desguar TH 'foreign import' a bit better * Minor documentation changes --- ghc/compiler/deSugar/DsMeta.hs | 37 ++++++++++++++++---------------- ghc/compiler/hsSyn/Convert.lhs | 21 +++++++++++------- ghc/docs/users_guide/glasgow_exts.sgml | 20 ++++++++++------- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/ghc/compiler/deSugar/DsMeta.hs b/ghc/compiler/deSugar/DsMeta.hs index 3414ab7..d0a5974 100644 --- a/ghc/compiler/deSugar/DsMeta.hs +++ b/ghc/compiler/deSugar/DsMeta.hs @@ -387,16 +387,15 @@ repE (HsLet bs e) = do { (ss,ds) <- repBinds bs ; z <- repLetE ds e2 ; wrapGenSyns expTyConName ss z } -- FIXME: I haven't got the types here right yet -repE (HsDo ctxt sts _ ty loc) - | isComprCtxt ctxt = do { (ss,zs) <- repSts sts; - e <- repDoE (nonEmptyCoreList zs); - wrapGenSyns expTyConName ss e } - | otherwise = - panic "DsMeta.repE: Can't represent mdo and [: :] yet" - where - isComprCtxt ListComp = True - isComprCtxt DoExpr = True - isComprCtxt _ = False +repE (HsDo DoExpr sts _ ty loc) + = do { (ss,zs) <- repSts sts; + e <- repDoE (nonEmptyCoreList zs); + wrapGenSyns expTyConName ss e } +repE (HsDo ListComp sts _ ty loc) + = do { (ss,zs) <- repSts sts; + e <- repComp (nonEmptyCoreList zs); + wrapGenSyns expTyConName ss e } +repE (HsDo _ _ _ _ _) = panic "DsMeta.repE: Can't represent mdo and [: :] yet" repE (ExplicitList ty es) = do { xs <- repEs es; repListExp xs } repE (ExplicitPArr ty es) = panic "DsMeta.repE: No explicit parallel arrays yet" @@ -953,16 +952,16 @@ repLiteral lit = do { lit_expr <- dsLit lit; rep2 lit_name [lit_expr] } where lit_name = case lit of - HsInt _ -> intLName - HsChar _ -> charLName - HsString _ -> stringLName - HsRat _ _ -> rationalLName - other -> uh_oh + HsInteger _ -> integerLName + HsChar _ -> charLName + HsString _ -> stringLName + HsRat _ _ -> rationalLName + other -> uh_oh uh_oh = pprPanic "DsMeta.repLiteral: trying to represent exotic literal" (ppr lit) repOverloadedLiteral :: HsOverLit -> DsM (Core M.Lit) -repOverloadedLiteral (HsIntegral i _) = repLiteral (HsInt i) +repOverloadedLiteral (HsIntegral i _) = repLiteral (HsInteger i) repOverloadedLiteral (HsFractional f _) = do { rat_ty <- lookupType rationalTyConName ; repLiteral (HsRat f rat_ty) } -- The type Rational will be in the environment, becuase @@ -1031,7 +1030,7 @@ templateHaskellNames :: NameSet -- The names that are implicitly mentioned by ``bracket'' -- Should stay in sync with the import list of DsMeta templateHaskellNames - = mkNameSet [ intLName,charLName, stringLName, rationalLName, + = mkNameSet [ integerLName,charLName, stringLName, rationalLName, plitName, pvarName, ptupName, pconName, ptildeName, paspatName, pwildName, varName, conName, litName, appName, infixEName, lamName, @@ -1063,7 +1062,7 @@ thModule = mkThPkgModule mETA_META_Name mk_known_key_name space str uniq = mkKnownKeyExternalName thModule (mkOccFS space str) uniq -intLName = varQual FSLIT("intL") intLIdKey +integerLName = varQual FSLIT("integerL") integerLIdKey charLName = varQual FSLIT("charL") charLIdKey stringLName = varQual FSLIT("stringL") stringLIdKey rationalLName = varQual FSLIT("rationalL") rationalLIdKey @@ -1187,7 +1186,7 @@ valIdKey = mkPreludeMiscIdUnique 209 protoIdKey = mkPreludeMiscIdUnique 210 matchIdKey = mkPreludeMiscIdUnique 211 clauseIdKey = mkPreludeMiscIdUnique 212 -intLIdKey = mkPreludeMiscIdUnique 213 +integerLIdKey = mkPreludeMiscIdUnique 213 charLIdKey = mkPreludeMiscIdUnique 214 classDIdKey = mkPreludeMiscIdUnique 215 diff --git a/ghc/compiler/hsSyn/Convert.lhs b/ghc/compiler/hsSyn/Convert.lhs index 24d34f0..e521be0 100644 --- a/ghc/compiler/hsSyn/Convert.lhs +++ b/ghc/compiler/hsSyn/Convert.lhs @@ -83,7 +83,14 @@ 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 + where fi = CImport callconv' safety' c_header nilFS cis + callconv' = case callconv of + CCall -> CCallConv + StdCall -> StdCallConv + safety' = case safety of + Unsafe -> PlayRisky + Safe -> PlaySafe False + Threadsafe -> PlaySafe True (c_header', c_func') = break (== ' ') from c_header = mkFastString c_header' c_func = tail c_func' @@ -183,9 +190,9 @@ cvtpair (x,y) = GRHS [BindStmt truePat (cvt x) loc0, ResultStmt (cvt y) loc0] loc0 cvtOverLit :: Lit -> HsOverLit -cvtOverLit (Int i) = mkHsIntegral (fromInt i) +cvtOverLit (Integer i) = mkHsIntegral i cvtOverLit (Rational r) = mkHsFractional r --- An Int is like an an (overloaded) '3' in a Haskell source program +-- An Integer is like an an (overloaded) '3' in a Haskell source program -- Similarly 3.5 for fractionals cvtLit :: Lit -> HsLit @@ -258,8 +265,9 @@ falsePat = ConPatIn (cName "False") (PrefixCon []) overloadedLit :: Lit -> Bool -- True for literals that Haskell treats as overloaded -overloadedLit (Int l) = True -overloadedLit l = False +overloadedLit (Integer l) = True +overloadedLit (Rational l) = True +overloadedLit l = False void :: Type.Type void = placeHolderType @@ -267,9 +275,6 @@ void = placeHolderType loc0 :: SrcLoc loc0 = generatedSrcLoc -fromInt :: Int -> Integer -fromInt x = toInteger x - -- variable names vName :: String -> RdrName vName = mkName varName diff --git a/ghc/docs/users_guide/glasgow_exts.sgml b/ghc/docs/users_guide/glasgow_exts.sgml index 063527b..7ccd0a6 100644 --- a/ghc/docs/users_guide/glasgow_exts.sgml +++ b/ghc/docs/users_guide/glasgow_exts.sgml @@ -3225,21 +3225,25 @@ Tim Sheard is going to expand it.) A splice can occur in place of - an expression; - a list of top-level declarations; - a pattern; - a type; + an expression; the spliced expression must have type Expr + a list of top-level declarations; ; the spliced expression must have type Q [Dec] + a type; the spliced expression must have type Type. + (Note that the syntax for a declaration splice uses "$" not "splice" as in + the paper. Also the type of the enclosed expression must be Q [Dec], not [Q Dec] + as in the paper.) A expression quotation is written in Oxford brackets, thus: - [| ... |], where the "..." is an expression; - [d| ... |], where the "..." is a list of top-level declarations; - [p| ... |], where the "..." is a pattern; - [t| ... |], where the "..." is a type; + [| ... |], where the "..." is an expression; + the quotation has type Expr. + [d| ... |], where the "..." is a list of top-level declarations; + the quotation has type Q [Dec]. + [t| ... |], where the "..." is a type; + the quotation has type Type. -- 1.7.10.4