[project @ 2000-07-26 14:48:16 by simonmar]
[ghc-hetmet.git] / ghc / interpreter / derive.c
index e6698c2..fccff4f 100644 (file)
 /* --------------------------------------------------------------------------
  * Deriving
  *
- * Copyright (c) The University of Nottingham and Yale University, 1994-1997.
- * All rights reserved. See NOTICE for details and conditions of use etc...
- * Hugs version 1.4, December 1997
+ * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the
+ * Yale Haskell Group, and the Oregon Graduate Institute of Science and
+ * Technology, 1994-1999, All rights reserved.  It is distributed as
+ * free software under the license in the file "License", which is
+ * included in the distribution.
  *
  * $RCSfile: derive.c,v $
- * $Revision: 1.3 $
- * $Date: 1999/02/03 17:08:27 $
+ * $Revision: 1.15 $
+ * $Date: 2000/04/27 16:35:29 $
  * ------------------------------------------------------------------------*/
 
-#include "prelude.h"
+#include "hugsbasictypes.h"
 #include "storage.h"
-#include "backend.h"
 #include "connect.h"
 #include "errors.h"
 
-static Cell varTrue;
-static Cell varFalse;
-#if DERIVE_ORD
-static Cell varCompAux;                /* auxiliary function for compares */
-static Cell varCompare;
-static Cell varEQ;
-#endif
-#if DERIVE_IX
-static Cell varRangeSize;              /* calculate size of index range   */
-static Cell varInRange;
-static Cell varRange;
-static Cell varIndex;
-static Cell varMult; 
-static Cell varPlus;
-static Cell varMap;
-static Cell varMinus;
-static Cell varError;
-#endif
-#if DERIVE_ENUM
-static Cell varToEnum;
-static Cell varFromEnum; 
-static Cell varEnumFromTo;    
-static Cell varEnumFromThenTo;  
-#endif
-#if DERIVE_BOUNDED
-static Cell varMinBound;
-static Cell varMaxBound;
-#endif
-#if DERIVE_SHOW
-       Cell conCons;
-static Cell varShowField;              /* display single field            */
-static Cell varShowParen;              /* wrap with parens                */
-static Cell varCompose;                /* function composition            */
-static Cell varShowsPrec;
-static Cell varLe;
-#endif                                 
-#if DERIVE_READ                        
-static Cell varReadField;              /* read single field               */
-static Cell varReadParen;              /* unwrap from parens              */
-static Cell varLex;                    /* lexer                           */
-static Cell varReadsPrec;
-static Cell varGt;
-#endif                                 
-#if DERIVE_SHOW || DERIVE_READ         
-static Cell varAppend;                 /* list append                     */
-List cfunSfuns;                        /* List of (Cfun,[SelectorVar])    */
-#endif                                 
-#if DERIVE_EQ || DERIVE_IX             
-static Cell varAnd;                    /* built-in logical connectives    */
-#endif
-#if DERIVE_EQ || DERIVE_ORD            
-static Cell varEq;
-#endif
+#include "Rts.h"       /* to make StgPtr visible in Assembler.h */
+#include "Assembler.h"
 
+List cfunSfuns;                        /* List of (Cfun,[SelectorVar])    */
 
 /* --------------------------------------------------------------------------
  * local function prototypes:
  * ------------------------------------------------------------------------*/
 
-static List  local getDiVars            Args((Int));
-static Cell  local mkBind               Args((String,List));
-static Cell  local mkVarAlts            Args((Int,Cell));
-
-#if DERIVE_EQ || DERIVE_ORD
-static List  local makeDPats2           Args((Cell,Int));
-#endif
-#if DERIVE_ORD || DERIVE_ENUM || DERIVE_IX || DERIVE_BOUNDED
-static Bool  local isEnumType           Args((Tycon));
-#endif
-
-static Pair   local mkAltEq             Args((Int,List));
-static Pair   local mkAltOrd            Args((Int,List));
-static Cell   local prodRange           Args((Int,List,Cell,Cell,Cell));
-static Cell   local prodIndex           Args((Int,List,Cell,Cell,Cell));
-static Cell   local prodInRange         Args((Int,List,Cell,Cell,Cell));
-static List   local mkIxBinds           Args((Int,Cell,Int));
-static Cell   local mkAltShow           Args((Int,Cell,Int));
-static Cell   local showsPrecRhs        Args((Cell,Cell,Int));
-static Cell   local mkReadCon           Args((Name,Cell,Cell));
-static Cell   local mkReadPrefix        Args((Cell));
-static Cell   local mkReadInfix         Args((Cell));
-static Cell   local mkReadTuple         Args((Cell));
-static Cell   local mkReadRecord        Args((Cell,List));
-static List   local mkBndBinds          Args((Int,Cell,Int));
-
+static List   local getDiVars           ( Int );
+static Cell   local mkBind              ( String,List );
+static Cell   local mkVarAlts           ( Int,Cell );
+static List   local makeDPats2          ( Cell,Int );
+static Bool   local isEnumType          ( Tycon );
+static Pair   local mkAltEq             ( Int,List );
+static Pair   local mkAltOrd            ( Int,List );
+static Cell   local prodRange           ( Int,List,Cell,Cell,Cell );
+static Cell   local prodIndex           ( Int,List,Cell,Cell,Cell );
+static Cell   local prodInRange         ( Int,List,Cell,Cell,Cell );
+static List   local mkIxBinds           ( Int,Cell,Int );
+static Cell   local mkAltShow           ( Int,Cell,Int );
+static Cell   local showsPrecRhs        ( Cell,Cell,Int );
+static Cell   local mkReadCon           ( Name,Cell,Cell );
+static Cell   local mkReadPrefix        ( Cell );
+static Cell   local mkReadInfix         ( Cell );
+static Cell   local mkReadTuple         ( Cell );
+static Cell   local mkReadRecord        ( Cell,List );
+static List   local mkBndBinds          ( Int,Cell,Int );
 
 
 /* --------------------------------------------------------------------------
@@ -131,6 +75,43 @@ Cell r; {
     return singleton(pair(NIL,pair(mkInt(line),r)));
 }
 
+static List local makeDPats2(h,n)       /* generate pattern list           */
+Cell h;                                 /* by putting two new patterns with*/
+Int  n; {                               /* head h and new var components   */
+    List us = getDiVars(2*n);
+    List vs = NIL;
+    Cell p;
+    Int  i;
+
+    for (i=0, p=h; i<n; ++i) {          /* make first version of pattern   */
+        p  = ap(p,hd(us));
+        us = tl(us);
+    }
+    vs = cons(p,vs);
+
+    for (i=0, p=h; i<n; ++i) {          /* make second version of pattern  */
+        p  = ap(p,hd(us));
+        us = tl(us);
+    }
+    return cons(p,vs);
+}
+
+static Bool local isEnumType(t) /* Determine whether t is an enumeration   */
+Tycon t; {                      /* type (i.e. all constructors arity == 0) */
+    if (isTycon(t) && (tycon(t).what==DATATYPE || tycon(t).what==NEWTYPE)) {
+        List cs = tycon(t).defn;
+        for (; hasCfun(cs); cs=tl(cs)) {
+            if (name(hd(cs)).arity!=0) {
+                return FALSE;
+            }
+        }
+        /* ToDo: correct?  addCfunTable(t); */
+        return TRUE;
+    }
+    return FALSE;
+}
+
+
 /* --------------------------------------------------------------------------
  * Given a datatype:   data T a b = A a b | B Int | C  deriving (Eq, Ord)
  * The derived definitions of equality and ordering are given by:
@@ -149,9 +130,9 @@ Cell r; {
  * constructors in the datatype definition.
  * ------------------------------------------------------------------------*/
 
-#define ap2(f,x,y) ap(ap(f,x),y)
+static Pair  local mkAltEq              ( Int,List );
 
-List local deriveEq(t)                  /* generate binding for derived == */
+List deriveEq(t)                        /* generate binding for derived == */
 Type t; {                               /* for some TUPLE or DATATYPE t    */
     List alts = NIL;
     if (isTycon(t)) {                   /* deal with type constrs          */
@@ -166,8 +147,7 @@ Type t; {                               /* for some TUPLE or DATATYPE t    */
                              pair(mkInt(tycon(t).line),nameFalse)),alts);
         }
         alts = rev(alts);
-    }
-    else {                              /* special case for tuples         */
+    } else {                            /* special case for tuples         */
         alts = singleton(mkAltEq(0,makeDPats2(t,tupleOf(t))));
     }
     return singleton(mkBind("==",alts));
@@ -189,11 +169,25 @@ List pats; {                            /* arguments                       */
     return pair(pats,pair(mkInt(line),e));
 }
 
+
+static Pair  local mkAltOrd             ( Int,List );
+
 List deriveOrd(t)                       /* make binding for derived compare*/
 Type t; {                               /* for some TUPLE or DATATYPE t    */
     List alts = NIL;
     if (isEnumType(t)) {                /* special case for enumerations   */
-        alts = mkVarAlts(tycon(t).line,nameConCmp);
+        Cell u = inventVar();
+        Cell w = inventVar();
+        Cell rhs = NIL;
+        if (cfunOf(hd(tycon(t).defn))!=0) {
+            implementConToTag(t);
+            rhs = ap2(nameCompare,
+                      ap(tycon(t).conToTag,u),
+                      ap(tycon(t).conToTag,w));
+        } else {
+            rhs = nameEQ;
+        }
+        alts = singleton(pair(doubleton(u,w),pair(mkInt(tycon(t).line),rhs)));
     } else if (isTycon(t)) {            /* deal with type constrs          */
         List cs = tycon(t).defn;
         for (; hasCfun(cs); cs=tl(cs)) {
@@ -204,9 +198,13 @@ Type t; {                               /* for some TUPLE or DATATYPE t    */
         if (cfunOf(hd(tycon(t).defn))!=0) {
             Cell u = inventVar();
             Cell w = inventVar();
-            alts   = cons(pair(cons(u,singleton(w)),
+            implementConToTag(t);
+            alts   = cons(pair(doubleton(u,w),
                                pair(mkInt(tycon(t).line),
-                                    ap2(nameConCmp,u,w))),alts);
+                                    ap2(nameCompare,
+                                        ap(tycon(t).conToTag,u),
+                                        ap(tycon(t).conToTag,w)))),
+                          alts);
         }
         alts = rev(alts);
     } else {                            /* special case for tuples         */
@@ -225,33 +223,13 @@ List pats; {                            /* arguments                       */
     if (isAp(p)) {
         e = ap2(nameCompare,arg(p),arg(q));
         for (p=fun(p), q=fun(q); isAp(p); p=fun(p), q=fun(q)) {
-            e = ap(ap2(nameCompAux,arg(p),arg(q)),e);
+            e = ap3(nameCompAux,arg(p),arg(q),e);
         }
     }
 
     return pair(pats,pair(mkInt(line),e));
 }
 
-static List local makeDPats2(h,n)       /* generate pattern list           */
-Cell h;                                 /* by putting two new patterns with*/
-Int  n; {                               /* head h and new var components   */
-    List us = getDiVars(2*n);
-    List vs = NIL;
-    Cell p;
-    Int  i;
-
-    for (i=0, p=h; i<n; ++i) {          /* make first version of pattern   */
-        p  = ap(p,hd(us));
-        us = tl(us);
-    }
-    vs = cons(p,vs);
-
-    for (i=0, p=h; i<n; ++i) {          /* make second version of pattern  */
-        p  = ap(p,hd(us));
-        us = tl(us);
-    }
-    return cons(p,vs);
-}
 
 /* --------------------------------------------------------------------------
  * Deriving Ix and Enum:
@@ -259,27 +237,40 @@ Int  n; {                               /* head h and new var components   */
 
 List deriveEnum(t)              /* Construct definition of enumeration     */
 Tycon t; {
-    Int l = tycon(t).line;
+    Int  l     = tycon(t).line;
+    Cell x     = inventVar();
+    Cell y     = inventVar();
+    Cell first = hd(tycon(t).defn);
+    Cell last  = tycon(t).defn;
 
     if (!isEnumType(t)) {
         ERRMSG(l) "Can only derive instances of Enum for enumeration types"
         EEND;
     }
-
-    return cons(mkBind("toEnum",mkVarAlts(l,ap(nameEnToEn,hd(tycon(t).defn)))),
-            cons(mkBind("fromEnum",mkVarAlts(l,nameEnFrEn)),
-             cons(mkBind("enumFrom",mkVarAlts(l,nameEnFrom)),
-              cons(mkBind("enumFromTo",mkVarAlts(l,nameEnFrTo)),
-               cons(mkBind("enumFromThen",mkVarAlts(l,nameEnFrTh)),NIL)))));
+    while (hasCfun(tl(last))) {
+        last = tl(last);
+    }
+    last = hd(last);
+    implementConToTag(t);
+    implementTagToCon(t);
+    return cons(mkBind("toEnum",      mkVarAlts(l,tycon(t).tagToCon)),
+           cons(mkBind("fromEnum",    mkVarAlts(l,tycon(t).conToTag)),
+           NIL));
 }
 
+
+static List  local mkIxBindsEnum        ( Tycon );
+static List  local mkIxBinds            ( Int,Cell,Int );
+static Cell  local prodRange            ( Int,List,Cell,Cell,Cell );
+static Cell  local prodIndex            ( Int,List,Cell,Cell,Cell );
+static Cell  local prodInRange          ( Int,List,Cell,Cell,Cell );
+
 List deriveIx(t)                /* Construct definition of indexing        */
 Tycon t; {
     if (isEnumType(t)) {        /* Definitions for enumerations            */
-        return cons(mkBind("range",mkVarAlts(tycon(t).line,nameEnRange)),
-                cons(mkBind("index",mkVarAlts(tycon(t).line,nameEnIndex)),
-                 cons(mkBind("inRange",mkVarAlts(tycon(t).line,nameEnInRng)),
-                  NIL)));
+        implementConToTag(t);
+        implementTagToCon(t);
+        return mkIxBindsEnum(t);
     } else if (isTuple(t)) {    /* Definitions for product types           */
         return mkIxBinds(0,t,tupleOf(t));
     } else if (isTycon(t) && cfunOf(hd(tycon(t).defn))==0) {
@@ -293,19 +284,42 @@ Tycon t; {
     return NIL;/* NOTREACHED*/
 }
 
-static Bool local isEnumType(t) /* Determine whether t is an enumeration   */
-Tycon t; {                      /* type (i.e. all constructors arity == 0) */
-    if (isTycon(t) && (tycon(t).what==DATATYPE || tycon(t).what==NEWTYPE)) {
-        List cs = tycon(t).defn;
-        for (; hasCfun(cs); cs=tl(cs)) {
-            if (name(hd(cs)).arity!=0) {
-                return FALSE;
-            }
-        }
-        /* ToDo: correct?  addCfunTable(t); */
-        return TRUE;
-    }
-    return FALSE;
+/* instance  Ix T  where
+ *     range (c1,c2)       =  map tagToCon [conToTag c1 .. conToTag c2]
+ *     index b@(c1,c2) ci
+ *        | inRange b ci  =  conToTag ci - conToTag c1
+ *        | otherwise     =  error "Ix.index.T: Index out of range."
+ *     inRange (c1,c2) ci  =  conToTag c1 <= i && i <= conToTag c2
+ *                           where i = conToTag ci
+ */
+static List local mkIxBindsEnum(t)
+Tycon t; {
+    Int l = tycon(t).line;
+    Name tagToCon = tycon(t).tagToCon;
+    Name conToTag = tycon(t).conToTag;
+    Cell b  = inventVar();
+    Cell c1 = inventVar();
+    Cell c2 = inventVar();
+    Cell ci = inventVar();
+    return cons(mkBind("range",  singleton(pair(singleton(ap2(mkTuple(2),
+                                 c1,c2)), pair(mkInt(l),ap2(nameMap,tagToCon,
+                                 ap2(nameFromTo,ap(conToTag,c1),
+                                 ap(conToTag,c2))))))),
+           cons(mkBind("index",  singleton(pair(doubleton(ap(ASPAT,pair(b,
+                                 ap2(mkTuple(2),c1,c2))),ci), 
+                                 pair(mkInt(l),ap(COND,
+                                 triple(ap2(nameInRange,b,ci),
+                                 ap2(nameMinus,ap(conToTag,ci),
+                                 ap(conToTag,c1)),
+                                 ap(nameError,mkStr(findText(
+                                 "Ix.index: Index out of range"))))))))),
+           cons(mkBind("inRange",singleton(pair(doubleton(ap2(mkTuple(2),
+                                 c1,c2),ci), pair(mkInt(l),ap2(nameAnd,
+                                 ap2(nameLe,ap(conToTag,c1),ap(conToTag,ci)),
+                                 ap2(nameLe,ap(conToTag,ci),
+                                 ap(conToTag,c2))))))), 
+                                        /* ToDo: share conToTag ci         */
+           NIL)));
 }
 
 static List local mkIxBinds(line,h,n)   /* build bindings for derived Ix on*/
@@ -316,21 +330,25 @@ Int  n; {
     Cell ls   = h;
     Cell us   = h;
     Cell is   = h;
+    Cell js   = h;
     Cell pr   = NIL;
     Cell pats = NIL;
+    
     Int  i;
 
     for (i=0; i<n; ++i, vs=tl(vs)) {    /* build three patterns for values */
         ls = ap(ls,hd(vs));             /* of the datatype concerned       */
         us = ap(us,hd(vs=tl(vs)));
         is = ap(is,hd(vs=tl(vs)));
+       js = ap(js,hd(vs));             /* ... and one expression          */
     }
     pr   = ap2(mkTuple(2),ls,us);       /* Build (ls,us)                   */
     pats = cons(pr,cons(is,NIL));       /* Build [(ls,us),is]              */
 
-    return cons(prodRange(line,singleton(pr),ls,us,is),
-                cons(prodIndex(line,pats,ls,us,is),
-                     cons(prodInRange(line,pats,ls,us,is),NIL)));
+    return cons(prodRange(line,singleton(pr),ls,us,js),
+           cons(prodIndex(line,pats,ls,us,is),
+           cons(prodInRange(line,pats,ls,us,is),
+           NIL)));
 }
 
 static Cell local prodRange(line,pats,ls,us,is)
@@ -395,6 +413,7 @@ Cell ls, us, is; {
     return mkBind("inRange",e);
 }
 
+
 /* --------------------------------------------------------------------------
  * Deriving Show:
  * ------------------------------------------------------------------------*/
@@ -518,10 +537,11 @@ Int  a; {
             if (defaultSyntax(name(h).text)==APPLIC) {
                 rhs = ap(showsBQ,
                          ap2(nameComp,
-                             ap(nameApp,mkStr(name(h).text)),
+                            ap(nameApp,mkStr(fixLitText(name(h).text))),
                              ap(showsBQ,rhs)));
             } else {
-                rhs = ap2(nameComp,ap(nameApp,mkStr(name(h).text)),rhs);
+               rhs = ap2(nameComp,
+                         ap(nameApp,mkStr(fixLitText(name(h).text))),rhs);
             }
 
             rhs = ap2(nameComp,
@@ -823,8 +843,6 @@ List fs; {
  * Deriving Bounded:
  * ------------------------------------------------------------------------*/
 
-#if DERIVE_BOUNDED
-
 List deriveBounded(t)             /* construct definition of bounds        */
 Tycon t; {
     if (isEnumType(t)) {
@@ -863,7 +881,124 @@ Int  n; {
             cons(mkBind("maxBound",mkVarAlts(line,maxB)),
              NIL));
 }
-#endif /* DERIVE_BOUNDED */
+
+
+/* --------------------------------------------------------------------------
+ * Helpers: conToTag and tagToCon
+ * ------------------------------------------------------------------------*/
+
+/* \ v -> case v of { ...; Ci _ _ -> i; ... } */
+Void implementConToTag(t)
+Tycon t; {                    
+    if (isNull(tycon(t).conToTag)) {
+        List   cs  = tycon(t).defn;
+        Name   nm  = newName(inventText(),NIL);
+        StgVar v   = mkStgVar(NIL,NIL);
+        List alts  = NIL; /* can't fail */
+
+        assert(isTycon(t) && (tycon(t).what==DATATYPE 
+                              || tycon(t).what==NEWTYPE));
+        for (; hasCfun(cs); cs=tl(cs)) {
+            Name    c   = hd(cs);
+            Int     num = cfunOf(c) == 0 ? 0 : cfunOf(c)-1;
+            StgVar  r   = mkStgVar(mkStgCon(nameMkI,singleton(mkInt(num))),
+                                   NIL);
+            StgExpr tag = mkStgLet(singleton(r),r);
+            List    vs  = NIL;
+            Int i;
+            for(i=0; i < name(c).arity; ++i) {
+                vs = cons(mkStgVar(NIL,NIL),vs);
+            }
+            alts = cons(mkStgCaseAlt(c,vs,tag),alts);
+        }
+
+        name(nm).line    = tycon(t).line;
+        name(nm).type    = conToTagType(t);
+        name(nm).arity   = 1;
+        name(nm).closure = mkStgVar(mkStgLambda(singleton(v),mkStgCase(v,alts)),
+                                    NIL);
+        tycon(t).conToTag = nm;
+        addToCodeList ( currentModule, nm );
+    }
+}
+
+/* \ v -> case v of { ...; i -> Ci; ... } */
+Void implementTagToCon(t)
+Tycon t; {
+    if (isNull(tycon(t).tagToCon)) {
+        String tyconname;
+        List   cs;
+        Name   nm;
+        StgVar v1;
+        StgVar v2;
+        Cell   txt0;
+        StgVar bind1;
+        StgVar bind2;
+        StgVar bind3;
+        List   alts;
+        char   etxt[200];
+
+        assert(nameMkA);
+        assert(nameUnpackString);
+        assert(nameError);
+        assert(isTycon(t) && (tycon(t).what==DATATYPE 
+                              || tycon(t).what==NEWTYPE));
+
+        tyconname  = textToStr(tycon(t).text);
+        if (strlen(tyconname) > 100) 
+           internal("implementTagToCon: tycon name too long");
+
+        sprintf(etxt, 
+                "out-of-range arg for `toEnum' "
+                "in derived `instance Enum %s'", 
+                tyconname);
+        
+        cs  = tycon(t).defn;
+        nm  = newName(inventText(),NIL);
+        v1  = mkStgVar(NIL,NIL);
+        v2  = mkStgPrimVar(NIL,mkStgRep(INT_REP),NIL);
+
+        txt0  = mkStr(findText(etxt));
+        bind1 = mkStgVar(mkStgCon(nameMkA,singleton(txt0)),NIL);
+        bind2 = mkStgVar(mkStgApp(nameUnpackString,singleton(bind1)),NIL);
+        bind3 = mkStgVar(mkStgApp(nameError,singleton(bind2)),NIL);
+
+        alts  = singleton(
+                   mkStgPrimAlt(
+                      singleton(
+                         mkStgPrimVar(NIL,mkStgRep(INT_REP),NIL)
+                      ),
+                      makeStgLet ( tripleton(bind1,bind2,bind3), bind3 )
+                   )
+                );
+
+        for (; hasCfun(cs); cs=tl(cs)) {
+            Name   c   = hd(cs);
+            Int    num = cfunOf(c) == 0 ? 0 : cfunOf(c)-1;
+            StgVar pat = mkStgPrimVar(mkInt(num),mkStgRep(INT_REP),NIL);
+            assert(name(c).arity==0);
+            alts = cons(mkStgPrimAlt(singleton(pat),c),alts);
+        }
+
+        name(nm).line    = tycon(t).line;
+        name(nm).type    = tagToConType(t);
+        name(nm).arity   = 1;
+        name(nm).closure = mkStgVar(
+                             mkStgLambda(
+                               singleton(v1),
+                               mkStgCase(
+                                 v1,
+                                 singleton(
+                                   mkStgCaseAlt(
+                                     nameMkI,
+                                     singleton(v2),
+                                     mkStgPrimCase(v2,alts))))),
+                             NIL
+                           );
+        tycon(t).tagToCon = nm;
+        addToCodeList ( currentModule, nm );
+    }
+}
 
 
 /* --------------------------------------------------------------------------
@@ -872,128 +1007,20 @@ Int  n; {
 
 Void deriveControl(what)
 Int what; {
-    Text textPrelude = findText("PreludeBuiltin");
     switch (what) {
-        case INSTALL :
-                varTrue           = mkQVar(textPrelude,findText("True"));
-                varFalse          = mkQVar(textPrelude,findText("False"));
-#if DERIVE_ORD
-                varCompAux        = mkQVar(textPrelude,findText("primCompAux"));
-                varCompare        = mkQVar(textPrelude,findText("compare"));
-                varEQ             = mkQVar(textPrelude,findText("EQ"));
-#endif
-#if DERIVE_IX   
-                varRangeSize      = mkQVar(textPrelude,findText("rangeSize"));
-                varInRange        = mkQVar(textPrelude,findText("inRange"));
-                varRange          = mkQVar(textPrelude,findText("range"));
-                varIndex          = mkQVar(textPrelude,findText("index"));
-                varMult           = mkQVar(textPrelude,findText("*"));
-                varPlus           = mkQVar(textPrelude,findText("+"));
-                varMap            = mkQVar(textPrelude,findText("map"));
-                varMinus          = mkQVar(textPrelude,findText("-"));
-                varError          = mkQVar(textPrelude,findText("error"));
-#endif
-#if DERIVE_ENUM
-                varToEnum         = mkQVar(textPrelude,findText("toEnum"));
-                varFromEnum       = mkQVar(textPrelude,findText("fromEnum"));  
-                varEnumFromTo     = mkQVar(textPrelude,findText("enumFromTo"));      
-                varEnumFromThenTo = mkQVar(textPrelude,findText("enumFromThenTo"));  
-#endif
-#if DERIVE_BOUNDED
-                varMinBound       = mkQVar(textPrelude,findText("minBound"));
-                varMaxBound       = mkQVar(textPrelude,findText("maxBound"));
-#endif
-#if DERIVE_SHOW 
-                conCons           = mkQCon(textPrelude,findText(":"));
-                varShowField      = mkQVar(textPrelude,findText("primShowField"));
-                varShowParen      = mkQVar(textPrelude,findText("showParen"));
-                varCompose        = mkQVar(textPrelude,findText("."));
-                varShowsPrec      = mkQVar(textPrelude,findText("showsPrec"));
-                varLe             = mkQVar(textPrelude,findText("<="));
-#endif          
-#if DERIVE_READ
-                varReadField      = mkQVar(textPrelude,findText("primReadField"));
-                varReadParen      = mkQVar(textPrelude,findText("readParen"));
-                varLex            = mkQVar(textPrelude,findText("lex"));
-                varReadsPrec      = mkQVar(textPrelude,findText("readsPrec"));
-                varGt             = mkQVar(textPrelude,findText(">"));
-#endif
-#if DERIVE_SHOW || DERIVE_READ         
-                varAppend         = mkQVar(textPrelude,findText("++"));
-#endif                                 
-#if DERIVE_EQ || DERIVE_IX             
-                varAnd            = mkQVar(textPrelude,findText("&&"));
-#endif
-#if DERIVE_EQ || DERIVE_ORD            
-                varEq             = mkQVar(textPrelude,findText("=="));
-#endif
-                /* deliberate fall through */
+        case PREPREL :
         case RESET   : 
                 diVars      = NIL;
                 diNum       = 0;
-#if DERIVE_SHOW | DERIVE_READ
                 cfunSfuns   = NIL;
-#endif
                 break;
 
         case MARK    : 
                 mark(diVars);
-#if DERIVE_SHOW | DERIVE_READ
                 mark(cfunSfuns);
-#endif
-                mark(varTrue);        
-                mark(varFalse);        
-#if DERIVE_ORD
-                mark(varCompAux);        
-                mark(varCompare);        
-                mark(varEQ);        
-#endif                            
-#if DERIVE_IX                     
-                mark(varRangeSize);      
-                mark(varInRange);        
-                mark(varRange);          
-                mark(varIndex);          
-                mark(varMult);           
-                mark(varPlus);           
-                mark(varMap);           
-                mark(varMinus);           
-                mark(varError);           
-#endif                            
-#if DERIVE_ENUM                   
-                mark(varToEnum); 
-                mark(varFromEnum);   
-                mark(varEnumFromTo);     
-                mark(varEnumFromThenTo);   
-#endif                            
-#if DERIVE_BOUNDED                
-                mark(varMinBound);       
-                mark(varMaxBound);       
-#endif                            
-#if DERIVE_SHOW                   
-                mark(conCons);
-                mark(varShowField);      
-                mark(varShowParen);      
-                mark(varCompose);        
-                mark(varShowsPrec);      
-                mark(varLe);             
-#endif                            
-#if DERIVE_READ                   
-                mark(varReadField);      
-                mark(varReadParen);      
-                mark(varLex);            
-                mark(varReadsPrec);      
-                mark(varGt);             
-#endif                            
-#if DERIVE_SHOW || DERIVE_READ    
-                mark(varAppend);         
-#endif                            
-#if DERIVE_EQ || DERIVE_IX        
-                mark(varAnd);            
-#endif                            
-#if DERIVE_EQ || DERIVE_ORD       
-                mark(varEq);             
-#endif
                 break;
+
+       case POSTPREL: break;
     }
 }