| 1 | % |
|---|
| 2 | % (c) The University of Glasgow 2001-2006 |
|---|
| 3 | % |
|---|
| 4 | \begin{code} |
|---|
| 5 | {-# OPTIONS -fno-warn-tabs #-} |
|---|
| 6 | -- The above warning supression flag is a temporary kludge. |
|---|
| 7 | -- While working on this module you are encouraged to remove it and |
|---|
| 8 | -- detab the module (please do the detabbing in a separate patch). See |
|---|
| 9 | -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces |
|---|
| 10 | -- for details |
|---|
| 11 | |
|---|
| 12 | module ExternalCore where |
|---|
| 13 | |
|---|
| 14 | data Module |
|---|
| 15 | = Module Mname [Tdef] [Vdefg] |
|---|
| 16 | |
|---|
| 17 | data Tdef |
|---|
| 18 | = Data (Qual Tcon) [Tbind] [Cdef] |
|---|
| 19 | | Newtype (Qual Tcon) (Qual Tcon) [Tbind] Ty |
|---|
| 20 | |
|---|
| 21 | data Cdef |
|---|
| 22 | = Constr (Qual Dcon) [Tbind] [Ty] |
|---|
| 23 | | GadtConstr (Qual Dcon) Ty |
|---|
| 24 | |
|---|
| 25 | data Vdefg |
|---|
| 26 | = Rec [Vdef] |
|---|
| 27 | | Nonrec Vdef |
|---|
| 28 | |
|---|
| 29 | -- Top-level bindings are qualified, so that the printer doesn't have to pass |
|---|
| 30 | -- around the module name. |
|---|
| 31 | type Vdef = (Bool,Qual Var,Ty,Exp) |
|---|
| 32 | |
|---|
| 33 | data Exp |
|---|
| 34 | = Var (Qual Var) |
|---|
| 35 | | Dcon (Qual Dcon) |
|---|
| 36 | | Lit Lit |
|---|
| 37 | | App Exp Exp |
|---|
| 38 | | Appt Exp Ty |
|---|
| 39 | | Lam Bind Exp |
|---|
| 40 | | Let Vdefg Exp |
|---|
| 41 | | Case Exp Vbind Ty [Alt] {- non-empty list -} |
|---|
| 42 | | Cast Exp Ty |
|---|
| 43 | | Tick String Exp {- XXX probably wrong -} |
|---|
| 44 | | External String String Ty {- target name, convention, and type -} |
|---|
| 45 | | DynExternal String Ty {- convention and type (incl. Addr# of target as first arg) -} |
|---|
| 46 | | Label String |
|---|
| 47 | |
|---|
| 48 | data Bind |
|---|
| 49 | = Vb Vbind |
|---|
| 50 | | Tb Tbind |
|---|
| 51 | |
|---|
| 52 | data Alt |
|---|
| 53 | = Acon (Qual Dcon) [Tbind] [Vbind] Exp |
|---|
| 54 | | Alit Lit Exp |
|---|
| 55 | | Adefault Exp |
|---|
| 56 | |
|---|
| 57 | type Vbind = (Var,Ty) |
|---|
| 58 | type Tbind = (Tvar,Kind) |
|---|
| 59 | |
|---|
| 60 | -- Internally, we represent types and coercions separately; but for |
|---|
| 61 | -- the purposes of external core (at least for now) it's still |
|---|
| 62 | -- convenient to collapse them into a single type. |
|---|
| 63 | data Ty |
|---|
| 64 | = Tvar Tvar |
|---|
| 65 | | Tcon (Qual Tcon) |
|---|
| 66 | | Tapp Ty Ty |
|---|
| 67 | | Tforall Tbind Ty |
|---|
| 68 | -- We distinguish primitive coercions because External Core treats |
|---|
| 69 | -- them specially, so we have to print them out with special syntax. |
|---|
| 70 | | TransCoercion Ty Ty |
|---|
| 71 | | SymCoercion Ty |
|---|
| 72 | | UnsafeCoercion Ty Ty |
|---|
| 73 | | InstCoercion Ty Ty |
|---|
| 74 | | NthCoercion Int Ty |
|---|
| 75 | |
|---|
| 76 | data Kind |
|---|
| 77 | = Klifted |
|---|
| 78 | | Kunlifted |
|---|
| 79 | | Kunboxed |
|---|
| 80 | | Kopen |
|---|
| 81 | | Karrow Kind Kind |
|---|
| 82 | |
|---|
| 83 | data Lit |
|---|
| 84 | = Lint Integer Ty |
|---|
| 85 | | Lrational Rational Ty |
|---|
| 86 | | Lchar Char Ty |
|---|
| 87 | | Lstring String Ty |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | type Mname = Id |
|---|
| 91 | type Var = Id |
|---|
| 92 | type Tvar = Id |
|---|
| 93 | type Tcon = Id |
|---|
| 94 | type Dcon = Id |
|---|
| 95 | |
|---|
| 96 | type Qual t = (Mname,t) |
|---|
| 97 | |
|---|
| 98 | type Id = String |
|---|
| 99 | |
|---|
| 100 | primMname :: Mname |
|---|
| 101 | -- For truly horrible reasons, this must be z-encoded. |
|---|
| 102 | -- With any hope, the z-encoding will die soon. |
|---|
| 103 | primMname = "ghczmprim:GHCziPrim" |
|---|
| 104 | |
|---|
| 105 | tcArrow :: Qual Tcon |
|---|
| 106 | tcArrow = (primMname, "(->)") |
|---|
| 107 | |
|---|
| 108 | \end{code} |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|