[project @ 2000-04-12 16:22:48 by simonmar]
[ghc-hetmet.git] / ghc / interpreter / derive.c
index 26f26ec..cd83f89 100644 (file)
@@ -2,22 +2,22 @@
 /* --------------------------------------------------------------------------
  * 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.6 $
- * $Date: 1999/04/27 10:06:50 $
+ * $Revision: 1.14 $
+ * $Date: 2000/03/23 14:54:20 $
  * ------------------------------------------------------------------------*/
 
-#include "prelude.h"
+#include "hugsbasictypes.h"
 #include "storage.h"
-#include "backend.h"
 #include "connect.h"
 #include "errors.h"
 #include "Assembler.h"
-#include "link.h"
 
 List cfunSfuns;                        /* List of (Cfun,[SelectorVar])    */
 
@@ -25,25 +25,25 @@ 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));
-static List  local makeDPats2           Args((Cell,Int));
-static Bool  local isEnumType           Args((Tycon));
-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 );
 
 
 /* --------------------------------------------------------------------------
@@ -128,7 +128,7 @@ Tycon t; {                      /* type (i.e. all constructors arity == 0) */
  * constructors in the datatype definition.
  * ------------------------------------------------------------------------*/
 
-static Pair  local mkAltEq              Args((Int,List));
+static Pair  local mkAltEq              ( Int,List );
 
 List deriveEq(t)                        /* generate binding for derived == */
 Type t; {                               /* for some TUPLE or DATATYPE t    */
@@ -168,7 +168,7 @@ List pats; {                            /* arguments                       */
 }
 
 
-static Pair  local mkAltOrd             Args((Int,List));
+static Pair  local mkAltOrd             ( Int,List );
 
 List deriveOrd(t)                       /* make binding for derived compare*/
 Type t; {                               /* for some TUPLE or DATATYPE t    */
@@ -253,25 +253,15 @@ Tycon t; {
     implementTagToCon(t);
     return cons(mkBind("toEnum",      mkVarAlts(l,tycon(t).tagToCon)),
            cons(mkBind("fromEnum",    mkVarAlts(l,tycon(t).conToTag)),
-           cons(mkBind("enumFrom",    singleton(pair(singleton(x),  
-                                        pair(mkInt(l),
-                                        ap2(nameFromTo,x,last))))),
-           /* default instance of enumFromTo is good */
-           cons(mkBind("enumFromThen",singleton(pair(doubleton(x,y),
-                                        pair(mkInt(l),
-                                        ap3(nameFromThenTo,x,y,
-                                        ap(COND,triple(ap2(nameLe,x,y),
-                                        last,first))))))),
-           /* default instance of enumFromThenTo is good */
-           NIL))));
+           NIL));
 }
 
 
-static List  local mkIxBindsEnum        Args((Tycon));
-static List  local mkIxBinds            Args((Int,Cell,Int));
-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 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; {
@@ -338,19 +328,22 @@ 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),
+    return cons(prodRange(line,singleton(pr),ls,us,js),
            cons(prodIndex(line,pats,ls,us,is),
            cons(prodInRange(line,pats,ls,us,is),
            NIL)));
@@ -542,10 +535,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,
@@ -921,7 +915,6 @@ Tycon t; {
         name(nm).arity  = 1;
         name(nm).stgVar = mkStgVar(mkStgLambda(singleton(v),mkStgCase(v,alts)),
                                    NIL);
-        name(nm).stgSize = stgSize(stgVarBody(name(nm).stgVar));
         tycon(t).conToTag = nm;
         /* hack to make it print out */
         stgGlobals = cons(pair(nm,name(nm).stgVar),stgGlobals); 
@@ -1001,7 +994,6 @@ Tycon t; {
                                     mkStgPrimCase(v2,alts))))),
                             NIL
                           );
-        name(nm).stgSize = stgSize(stgVarBody(name(nm).stgVar));
         tycon(t).tagToCon = nm;
         /* hack to make it print out */
         stgGlobals = cons(pair(nm,name(nm).stgVar),stgGlobals); 
@@ -1016,8 +1008,7 @@ Tycon t; {
 Void deriveControl(what)
 Int what; {
     switch (what) {
-        case INSTALL :
-                /* deliberate fall through */
+        case PREPREL :
         case RESET   : 
                 diVars      = NIL;
                 diNum       = 0;
@@ -1028,6 +1019,8 @@ Int what; {
                 mark(diVars);
                 mark(cfunSfuns);
                 break;
+
+       case POSTPREL: break;
     }
 }