[project @ 2000-03-10 14:53:00 by sewardj]
[ghc-hetmet.git] / ghc / interpreter / subst.h
1
2 /* --------------------------------------------------------------------------
3  * Definitions for substitution data structure and operations.
4  *
5  * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the
6  * Yale Haskell Group, and the Oregon Graduate Institute of Science and
7  * Technology, 1994-1999, All rights reserved.  It is distributed as
8  * free software under the license in the file "License", which is
9  * included in the distribution.
10  *
11  * $RCSfile: subst.h,v $
12  * $Revision: 1.7 $
13  * $Date: 2000/03/10 14:53:00 $
14  * ------------------------------------------------------------------------*/
15
16 typedef struct {                        /* Each type variable contains:    */
17     Type bound;                         /* A type skeleton (unbound==NIL)  */
18     Int  offs;                          /* Offset for skeleton             */
19     Kind kind;                          /* kind annotation                 */
20 } Tyvar;
21
22 #if     FIXED_SUBST                     /* storage for type variables      */
23 extern  Tyvar           tyvars[];
24 #else
25 extern  Tyvar           *tyvars;        /* storage for type variables      */
26 #endif
27 extern  Int             typeOff;        /* offset of result type           */
28 extern  Type            typeIs;         /* skeleton of result type         */
29 extern  Int             typeFree;       /* freedom in instantiated type    */
30 extern  List            predsAre;       /* list of predicates in type      */
31 extern  List            genericVars;    /* list of generic vars            */
32 extern  List            btyvars;        /* explicitly scoped type vars     */
33
34 #define tyvar(n)        (tyvars+(n))    /* nth type variable               */
35 #define tyvNum(t)       ((t)-tyvars)    /* and the corresp. inverse funct. */
36 #define isBound(t)      (((t)->bound) && ((t)->bound!=SKOLEM))
37 #define aVar            mkOffset(0)     /* Simple skeletons for type vars  */
38 #define bVar            mkOffset(1)
39 #define enterBtyvs()    btyvars = cons(NIL,btyvars)
40 #define leaveBtyvs()    btyvars = tl(btyvars)
41
42 #define deRef(tyv,t,o)  while ((tyv=getTypeVar(t,o)) && isBound(tyv)) { \
43                             t = tyv->bound;                             \
44                             o = tyv->offs;                              \
45                         }
46
47                                         /* offs values when isNull(bound): */
48 #define FIXED_TYVAR     0               /* fixed in current assumption     */
49 #define UNUSED_GENERIC  1               /* not fixed, not yet encountered  */
50 #define GENERIC         2               /* GENERIC+n==nth generic var found*/
51
52 extern  char            *unifyFails;    /* Unification error message       */
53
54 extern Void  emptySubstitution  Args((Void));
55 extern Int   newTyvars          Args((Int));
56 #define      newKindvars(n)     newTyvars(n)
57 extern Int   newKindedVars      Args((Kind));
58 extern Void  instantiate        Args((Type));
59
60 extern Pair  findBtyvs          Args((Text));
61 extern Void  markBtyvs          Args((Void));
62 extern Type  localizeBtyvs      Args((Type));
63
64 extern Tyvar *getTypeVar        Args((Type,Int));
65 extern Void  tyvarType          Args((Int));
66 extern Void  bindTv             Args((Int,Type,Int));
67 extern Cell  getDerefHead       Args((Type,Int));
68 extern Void  expandSyn          Args((Tycon, Int, Type *, Int *));
69
70 extern Void  clearMarks         Args((Void));
71 extern Void  markAllVars        Args((Void));
72 extern Void  resetGenerics      Args((Void));
73 extern Void  markTyvar          Args((Int));
74 extern Void  markType           Args((Type,Int));
75 extern Void  markPred           Args((Cell));
76
77 extern Type  copyTyvar          Args((Int));
78 extern Type  copyType           Args((Type,Int));
79 extern Cell  copyPred           Args((Cell,Int));
80 extern Type  dropRank2          Args((Type,Int,Int));
81 extern Type  dropRank1          Args((Type,Int,Int));
82 extern Void  liftRank2Args      Args((List,Int,Int));
83 extern Type  liftRank2          Args((Type,Int,Int));
84 extern Type  liftRank1          Args((Type,Int,Int));
85 #ifdef DEBUG_TYPES
86 extern Type  debugTyvar         Args((Int));
87 extern Type  debugType          Args((Type,Int));
88 #endif
89 extern Kind  copyKindvar        Args((Int));
90 extern Kind  copyKind           Args((Kind,Int));
91
92 extern Bool  eqKind             Args((Kind,Kind));
93 extern Kind  getKind            Args((Cell,Int));
94
95 extern List  genvarTyvar        Args((Int,List));
96 extern List  genvarType         Args((Type,Int,List));
97
98 extern Bool  doesntOccurIn      Args((Tyvar*,Type,Int));
99 extern Bool  unify              Args((Type,Int,Type,Int));
100 extern Bool  kunify             Args((Kind,Int,Kind,Int));
101
102 extern Void  typeTuple          Args((Cell));
103 extern Void  varKind            Args((Int));
104
105 extern Bool  samePred           Args((Cell,Int,Cell,Int));
106 extern Bool  matchPred          Args((Cell,Int,Cell,Int));
107 extern Bool  unifyPred          Args((Cell,Int,Cell,Int));
108 extern Inst  findInstFor        Args((Cell,Int));
109
110 extern Void  improve            Args((Int,List,List));
111 extern Void  improve1           Args((Int,List,Cell,Int));
112
113 extern Bool  sameSchemes        Args((Type,Type));
114 extern Bool  sameType           Args((Type,Int,Type,Int));
115 extern Bool  matchType          Args((Type,Int,Type,Int));
116
117 /*-------------------------------------------------------------------------*/