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