[project @ 2000-03-15 15:03:20 by simonmar]
[ghc-hetmet.git] / ghc / interpreter / compiler.c
index 93c4b96..5260f20 100644 (file)
  * included in the distribution.
  *
  * $RCSfile: compiler.c,v $
- * $Revision: 1.18 $
- * $Date: 2000/02/08 15:32:29 $
+ * $Revision: 1.22 $
+ * $Date: 2000/03/13 11:37:16 $
  * ------------------------------------------------------------------------*/
 
 #include "prelude.h"
 #include "storage.h"
-#include "backend.h"
 #include "connect.h"
 #include "errors.h"
+
 #include "Rts.h"                       /* for rts_eval and related stuff   */
 #include "RtsAPI.h"                    /* for rts_eval and related stuff   */
 #include "SchedAPI.h"                  /* for RevertCAFs                   */
 #include "Schedule.h"
-#include "link.h"
-
-Addr inputCode;                        /* Addr of compiled code for expr   */
-static Name currentName;               /* Top level name being processed   */
-#if DEBUG_CODE
-Bool   debugCode     = FALSE;          /* TRUE => print G-code to screen   */
-#endif
-
-
 
 /* --------------------------------------------------------------------------
  * Local function prototypes:
  * ------------------------------------------------------------------------*/
 
-static Cell local translate             Args((Cell));
-static Void local transPair             Args((Pair));
-static Void local transTriple           Args((Triple));
-static Void local transAlt              Args((Cell));
-static Void local transCase             Args((Cell));
-static List local transBinds            Args((List));
-static Cell local transRhs              Args((Cell));
-static Cell local mkConsList            Args((List));
-static Cell local expandLetrec          Args((Cell));
-static Cell local transComp             Args((Cell,List,Cell));
-static Cell local transDo               Args((Cell,Cell,List));
-static Cell local transConFlds          Args((Cell,List));
-static Cell local transUpdFlds          Args((Cell,List,List));
-
-static Cell local refutePat             Args((Cell));
-static Cell local refutePatAp           Args((Cell));
-static Cell local matchPat              Args((Cell));
-static List local remPat                Args((Cell,Cell,List));
-static List local remPat1               Args((Cell,Cell,List));
-
-static Cell local pmcTerm               Args((Int,List,Cell));
-static Cell local pmcPair               Args((Int,List,Pair));
-static Cell local pmcTriple             Args((Int,List,Triple));
-static Cell local pmcVar                Args((List,Text));
-static Void local pmcLetrec             Args((Int,List,Pair));
-static Cell local pmcVarDef             Args((Int,List,List));
-static Void local pmcFunDef             Args((Int,List,Triple));
-static List local altsMatch             Args((Int,Int,List,List));
-static Cell local match                 Args((Int,List));
-static Cell local joinMas               Args((Int,List));
-static Bool local canFail               Args((Cell));
-static List local addConTable           Args((Cell,Cell,List));
-static Void local advance               Args((Int,Int,Cell));
-static Bool local emptyMatch            Args((Cell));
-static Cell local maDiscr               Args((Cell));
-static Bool local isNumDiscr            Args((Cell));
-static Bool local eqNumDiscr            Args((Cell,Cell));
+static Cell local translate             ( Cell );
+static Void local transPair             ( Pair );
+static Void local transTriple           ( Triple );
+static Void local transAlt              ( Cell );
+static Void local transCase             ( Cell );
+static List local transBinds            ( List );
+static Cell local transRhs              ( Cell );
+static Cell local mkConsList            ( List );
+static Cell local expandLetrec          ( Cell );
+static Cell local transComp             ( Cell,List,Cell );
+static Cell local transDo               ( Cell,Cell,List );
+static Cell local transConFlds          ( Cell,List );
+static Cell local transUpdFlds          ( Cell,List,List );
+
+static Cell local refutePat             ( Cell );
+static Cell local refutePatAp           ( Cell );
+static Cell local matchPat              ( Cell );
+static List local remPat                ( Cell,Cell,List );
+static List local remPat1               ( Cell,Cell,List );
+
+static Cell local pmcTerm               ( Int,List,Cell );
+static Cell local pmcPair               ( Int,List,Pair );
+static Cell local pmcTriple             ( Int,List,Triple );
+static Cell local pmcVar                ( List,Text );
+static Void local pmcLetrec             ( Int,List,Pair );
+static Cell local pmcVarDef             ( Int,List,List );
+static Void local pmcFunDef             ( Int,List,Triple );
+static List local altsMatch             ( Int,Int,List,List );
+static Cell local match                 ( Int,List );
+static Cell local joinMas               ( Int,List );
+static Bool local canFail               ( Cell );
+static List local addConTable           ( Cell,Cell,List );
+static Void local advance               ( Int,Int,Cell );
+static Bool local emptyMatch            ( Cell );
+static Cell local maDiscr               ( Cell );
+static Bool local isNumDiscr            ( Cell );
+static Bool local eqNumDiscr            ( Cell,Cell );
 #if TREX
-static Bool local isExtDiscr            Args((Cell));
-static Bool local eqExtDiscr            Args((Cell,Cell));
+static Bool local isExtDiscr            ( Cell );
+static Bool local eqExtDiscr            ( Cell,Cell );
 #endif
 
-static Void local compileGlobalFunction Args((Pair));
-static Void local compileGenFunction    Args((Name));
-static Name local compileSelFunction    Args((Pair));
-static List local addStgVar             Args((List,Pair));
+static Void local compileGlobalFunction ( Pair );
+static Void local compileGenFunction    ( Name );
+static Name local compileSelFunction    ( Pair );
+static List local addStgVar             ( List,Pair );
 
+static Name currentName;               /* Top level name being processed   */
 
 /* --------------------------------------------------------------------------
  * Translation:    Convert input expressions into a less complex language
@@ -188,7 +180,8 @@ Cell e; {
                                              nv));
                           }
 
-        default         : fprintf(stderr, "stuff=%d\n",whatIs(e));internal("translate");
+        default         : fprintf(stderr, "stuff=%d\n",whatIs(e));
+                          internal("translate");
     }
     return e;
 }
@@ -618,9 +611,7 @@ Cell pat; {                       /* test with pat.                        */
 
         case STRCELL   :
         case CHARCELL  :
-#if NPLUSK
         case ADDPAT    :
-#endif
         case TUPLE     :
         case NAME      : return pat;
 
@@ -636,10 +627,8 @@ Cell p; {
     Cell h = getHead(p);
     if (h==nameFromInt || h==nameFromInteger || h==nameFromDouble)
         return p;
-#if NPLUSK
     else if (whatIs(h)==ADDPAT)
         return ap(fun(p),refutePat(arg(p)));
-#endif
 #if TREX
     else if (isExt(h)) {
         Cell pf = refutePat(extField(p));
@@ -707,10 +696,8 @@ Cell pat; {                     /* replaces parts of pattern that do not   */
                              if (h==nameFromInt     ||
                                  h==nameFromInteger || h==nameFromDouble)
                                  return WILDCARD;
-#if NPLUSK
                              else if (whatIs(h)==ADDPAT)
                                  return pat;
-#endif
 #if TREX
                              else if (isExt(h)) {
                                  Cell pf = matchPat(extField(pat));
@@ -810,14 +797,12 @@ List lds; {
                              return remPat(snd(pat),nv,lds);
                          }
 
-#if NPLUSK
         case ADDPAT    : return remPat1(arg(pat),       /* n + k = expr */
                                         ap(ap(ap(namePmSub,
                                                  arg(fun(pat))),
                                                  mkInt(snd(fun(fun(pat))))),
                                                  expr),
                                         lds);
-#endif
 
         case FINLIST   : return remPat1(mkConsList(snd(pat)),expr,lds);
 
@@ -937,9 +922,7 @@ Cell e;  {                             /* e  = expr to transform           */
 
         case AP       : return pmcPair(co,sc,e);
 
-#if NPLUSK
         case ADDPAT   :
-#endif
 #if TREX
         case EXT      :
 #endif
@@ -1346,10 +1329,8 @@ Cell ma; {                      /* match, ma.                              */
     Cell h = getHead(p);
     switch (whatIs(h)) {
         case CONFLDS : return fst(snd(p));
-#if NPLUSK
         case ADDPAT  : arg(fun(p)) = translate(arg(fun(p)));
                        return fun(p);
-#endif
 #if TREX
         case EXT     : h      = fun(fun(p));
                        arg(h) = translate(arg(h));
@@ -1390,18 +1371,12 @@ Cell d; {
         case CHARCELL  : return 0;
 #if TREX
         case AP        : switch (whatIs(fun(d))) {
-#if NPLUSK
                              case ADDPAT : return 1;
-#endif
                              case EXT    : return 2;
                              default     : return 0;
                          }
 #else
-#if NPLUSK
         case AP        : return (whatIs(fun(d))==ADDPAT) ? 1 : 0;
-#else
-        case AP        : return 0;      /* must be an Int or Float lit     */
-#endif
 #endif
     }
     internal("discrArity");
@@ -1410,10 +1385,8 @@ Cell d; {
 
 static Bool local eqNumDiscr(d1,d2)     /* Determine whether two numeric   */
 Cell d1, d2; {                          /* descriptors have same value     */
-#if NPLUSK
     if (whatIs(fun(d1))==ADDPAT)
         return whatIs(fun(d2))==ADDPAT && snd(fun(d1))==snd(fun(d2));
-#endif
     if (isInt(arg(d1)))
         return isInt(arg(d2)) && intOf(arg(d1))==intOf(arg(d2));
     if (isFloat(arg(d1)))
@@ -1475,7 +1448,7 @@ void eval_ctrlbrk ( int dunnowhat )
    signal(SIGINT, eval_ctrlbrk);
 }
 
-Void evalExp() {                    /* compile and run input expression    */
+Void evalExp ( void ) {             /* compile and run input expression    */
     /* ToDo: this name (and other names generated during pattern match?)
      * get inserted in the symbol table but never get removed.
      */