ExternalCore.lhs 2.29 KB
Newer Older
apt's avatar
apt committed
1
%
Simon Marlow's avatar
Simon Marlow committed
2
% (c) The University of Glasgow 2001-2006
apt's avatar
apt committed
3 4 5 6
%
\begin{code}
module ExternalCore where

7 8
import Data.Word

9
data Module
apt's avatar
apt committed
10
 = Module Mname [Tdef] [Vdefg]
apt's avatar
apt committed
11

12
data Tdef
apt's avatar
apt committed
13
  = Data (Qual Tcon) [Tbind] [Cdef]
14
  | Newtype (Qual Tcon) (Qual Tcon) [Tbind] Ty
apt's avatar
apt committed
15

16
data Cdef
17 18
  = Constr (Qual Dcon) [Tbind] [Ty]
  | GadtConstr (Qual Dcon) Ty
apt's avatar
apt committed
19

20
data Vdefg
apt's avatar
apt committed
21 22 23
  = Rec [Vdef]
  | Nonrec Vdef

24 25 26
-- Top-level bindings are qualified, so that the printer doesn't have to pass
-- around the module name.
type Vdef = (Bool,Qual Var,Ty,Exp)
apt's avatar
apt committed
27

28
data Exp
apt's avatar
apt committed
29 30 31 32 33
  = Var (Qual Var)
  | Dcon (Qual Dcon)
  | Lit Lit
  | App Exp Exp
  | Appt Exp Ty
34
  | Lam Bind Exp
apt's avatar
apt committed
35
  | Let Vdefg Exp
36
  | Case Exp Vbind Ty [Alt] {- non-empty list -}
37
  | Cast Exp Coercion
38
  | Tick String Exp {- XXX probably wrong -}
39 40
  | External String String Ty {- target name, convention, and type -}
  | DynExternal String Ty {- convention and type (incl. Addr# of target as first arg) -}
41
  | Label String
apt's avatar
apt committed
42

43
data Bind
apt's avatar
apt committed
44 45 46
  = Vb Vbind
  | Tb Tbind

47
data Alt
apt's avatar
apt committed
48 49 50 51 52 53 54
  = Acon (Qual Dcon) [Tbind] [Vbind] Exp
  | Alit Lit Exp
  | Adefault Exp

type Vbind = (Var,Ty)
type Tbind = (Tvar,Kind)

55
data Ty
apt's avatar
apt committed
56 57 58
  = Tvar Tvar
  | Tcon (Qual Tcon)
  | Tapp Ty Ty
59
  | Tforall Tbind Ty
60 61

data Coercion
62 63
-- We distinguish primitive coercions because External Core treats
-- them specially, so we have to print them out with special syntax.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
  = ReflCoercion Role Ty
  | SymCoercion Coercion
  | TransCoercion Coercion Coercion
  | TyConAppCoercion Role (Qual Tcon) [Coercion]
  | AppCoercion Coercion Coercion
  | ForAllCoercion Tbind Coercion
  | CoVarCoercion Var
  | UnivCoercion Role Ty Ty
  | InstCoercion Coercion Ty
  | NthCoercion Int Coercion
  | AxiomCoercion (Qual Tcon) Int [Coercion]
  | LRCoercion LeftOrRight Coercion
  | SubCoercion Coercion

data Role = Nominal | Representational | Phantom
79 80

data LeftOrRight = CLeft | CRight
apt's avatar
apt committed
81

82
data Kind
apt's avatar
apt committed
83 84
  = Klifted
  | Kunlifted
Simon Marlow's avatar
Simon Marlow committed
85
  | Kunboxed
apt's avatar
apt committed
86 87
  | Kopen
  | Karrow Kind Kind
88 89

data Lit
apt's avatar
apt committed
90 91 92
  = Lint Integer Ty
  | Lrational Rational Ty
  | Lchar Char Ty
93
  | Lstring [Word8] Ty
94

apt's avatar
apt committed
95 96 97 98 99 100 101 102 103 104 105

type Mname = Id
type Var = Id
type Tvar = Id
type Tcon = Id
type Dcon = Id

type Qual t = (Mname,t)

type Id = String

106
primMname :: Mname
107 108
-- For truly horrible reasons, this must be z-encoded.
-- With any hope, the z-encoding will die soon.
109
primMname = "ghczmprim:GHCziPrim"
apt's avatar
apt committed
110 111

tcArrow :: Qual Tcon
112
tcArrow = (primMname, "(->)")
apt's avatar
apt committed
113 114 115 116 117 118

\end{code}