X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=utils%2Fext-core%2FCore.hs;h=9df300e010a3519522f4d2e9e2fe523149a59275;hp=ce2a11d9517a18c4b5cf61fe56b329c83e762955;hb=c287bea94592fffe63f85831ab651c28d64e4d6e;hpb=420a27dc9fb7de5fc6c96fe078ddd4dc87222d44 diff --git a/utils/ext-core/Core.hs b/utils/ext-core/Core.hs index ce2a11d..9df300e 100644 --- a/utils/ext-core/Core.hs +++ b/utils/ext-core/Core.hs @@ -2,26 +2,33 @@ module Core where import Encoding +import Data.Generics import List (elemIndex) data Module = Module AnMname [Tdef] [Vdefg] + deriving (Data, Typeable) data Tdef = Data (Qual Tcon) [Tbind] [Cdef] - | Newtype (Qual Tcon) [Tbind] Axiom (Maybe Ty) + -- type constructor; coercion name; type arguments; type rep + -- If we have: (Newtype tc co tbs (Just t)) + -- there is an implicit axiom: + -- co tbs :: tc tbs :=: t + | Newtype (Qual Tcon) (Qual Tcon) [Tbind] (Maybe Ty) + deriving (Data, Typeable) data Cdef = Constr (Qual Dcon) [Tbind] [Ty] - --- Newtype coercion -type Axiom = (Qual Tcon, [Tbind], (Ty,Ty)) + deriving (Data, Typeable) data Vdefg = Rec [Vdef] | Nonrec Vdef + deriving (Data, Typeable) newtype Vdef = Vdef (Qual Var,Ty,Exp) + deriving (Data, Typeable) data Exp = Var (Qual Var) @@ -35,15 +42,18 @@ data Exp | Cast Exp Ty | Note String Exp | External String Ty + deriving (Data, Typeable) data Bind = Vb Vbind | Tb Tbind + deriving (Data, Typeable) data Alt = Acon (Qual Dcon) [Tbind] [Vbind] Exp | Alit Lit Exp | Adefault Exp + deriving (Data, Typeable) type Vbind = (Var,Ty) type Tbind = (Tvar,Kind) @@ -60,8 +70,10 @@ data Ty | TransCoercion Ty Ty | SymCoercion Ty | UnsafeCoercion Ty Ty + | InstCoercion Ty Ty | LeftCoercion Ty | RightCoercion Ty + deriving (Data, Typeable) data Kind = Klifted @@ -69,6 +81,7 @@ data Kind | Kopen | Karrow Kind Kind | Keq Ty Ty + deriving (Data, Typeable) -- A CoercionKind isn't really a Kind at all, but rather, -- corresponds to an arbitrary user-declared axiom. @@ -90,13 +103,13 @@ data CoercionKind = data KindOrCoercion = Kind Kind | Coercion CoercionKind data Lit = Literal CoreLit Ty - deriving Eq -- with nearlyEqualTy + deriving (Data, Typeable, Eq) -- with nearlyEqualTy data CoreLit = Lint Integer | Lrational Rational | Lchar Char | Lstring String - deriving Eq + deriving (Data, Typeable, Eq) -- Right now we represent module names as triples: -- (package name, hierarchical names, leaf name) @@ -108,8 +121,10 @@ data CoreLit = Lint Integer -- with Nothing. type Mname = Maybe AnMname -type AnMname = (Pname, [Id], Id) -type Pname = Id +newtype AnMname = M (Pname, [Id], Id) + deriving (Eq, Ord, Data, Typeable) +newtype Pname = P Id + deriving (Eq, Ord, Data, Typeable) type Var = Id type Tvar = Id type Tcon = Id @@ -123,6 +138,9 @@ qual mn t = (Just mn, t) unqual :: t -> Qual t unqual = (,) Nothing +getModule :: Qual t -> Mname +getModule = fst + type Id = String eqKind :: Kind -> Kind -> Bool @@ -131,9 +149,9 @@ eqKind Kunlifted Kunlifted = True eqKind Kopen Kopen = True eqKind (Karrow k1 k2) (Karrow l1 l2) = k1 `eqKind` l1 && k2 `eqKind` l2 -eqKind _ _ = False -- no Keq kind is ever equal to any other... - -- maybe ok for now? - +eqKind (Keq t1 t2) (Keq u1 u2) = t1 == u1 + && t2 == u2 +eqKind _ _ = False splitTyConApp_maybe :: Ty -> Maybe (Qual Tcon,[Ty]) splitTyConApp_maybe (Tvar _) = Nothing @@ -179,18 +197,25 @@ isPrimVar _ = False primMname = mkPrimMname "Prim" errMname = mkBaseMname "Err" mkBaseMname,mkPrimMname :: Id -> AnMname -mkBaseMname mn = (basePkg, ghcPrefix, mn) -mkPrimMname mn = (primPkg, ghcPrefix, mn) -basePkg = "base" -mainPkg = "main" -primPkg = zEncodeString "ghc-prim" +mkBaseMname mn = M (basePkg, ghcPrefix, mn) +mkPrimMname mn = M (primPkg, ghcPrefix, mn) +basePkg = P "base" +mainPkg = P "main" +primPkg = P $ zEncodeString "ghc-prim" ghcPrefix = ["GHC"] mainPrefix = [] baseMname = mkBaseMname "Base" boolMname = mkPrimMname "Bool" mainVar = qual mainMname "main" -mainMname = (mainPkg, mainPrefix, "Main") -wrapperMainMname = Just (mainPkg, mainPrefix, "ZCMain") +wrapperMainVar = qual wrapperMainMname "main" +mainMname = M (mainPkg, mainPrefix, "Main") +wrapperMainMname = M (mainPkg, mainPrefix, "ZCMain") +wrapperMainAnMname = Just wrapperMainMname + +dcTrue :: Dcon +dcTrue = "True" +dcFalse :: Dcon +dcFalse = "False" tcArrow :: Qual Tcon tcArrow = (Just primMname, "ZLzmzgZR") @@ -198,6 +223,9 @@ tcArrow = (Just primMname, "ZLzmzgZR") tArrow :: Ty -> Ty -> Ty tArrow t1 t2 = Tapp (Tapp (Tcon tcArrow) t1) t2 +mkFunTy :: Ty -> Ty -> Ty +mkFunTy randTy resultTy = + Tapp (Tapp (Tcon tcArrow) randTy) resultTy ktArrow :: Kind ktArrow = Karrow Kopen (Karrow Kopen Klifted) @@ -240,4 +268,8 @@ dcUtupleTy n = utuple :: [Ty] -> [Exp] -> Exp utuple ts es = foldl App (foldl Appt (Dcon (dcUtuple (length es))) ts) es - +---- snarfed from GHC's CoreSyn +flattenBinds :: [Vdefg] -> [Vdef] -- Get all the lhs/rhs pairs +flattenBinds (Nonrec vd : binds) = vd : flattenBinds binds +flattenBinds (Rec prs1 : binds) = prs1 ++ flattenBinds binds +flattenBinds [] = []