[project @ 2000-04-14 15:18:05 by sewardj]
[ghc-hetmet.git] / ghc / interpreter / output.c
index 4a59efa..ad8b0ff 100644 (file)
  * included in the distribution.
  *
  * $RCSfile: output.c,v $
- * $Revision: 1.6 $
- * $Date: 1999/10/15 21:40:53 $
+ * $Revision: 1.17 $
+ * $Date: 2000/03/23 14:54:21 $
  * ------------------------------------------------------------------------*/
 
-#include "prelude.h"
+#include "hugsbasictypes.h"
 #include "storage.h"
 #include "connect.h"
 #include "errors.h"
  * Local function prototypes:
  * ------------------------------------------------------------------------*/
 
-static Void local put            Args((Int,Cell));
-static Void local putFlds        Args((Cell,List));
-static Void local putComp        Args((Cell,List));
-static Void local putQual        Args((Cell));
-static Bool local isDictVal      Args((Cell));
-static Cell local maySkipDict    Args((Cell));
-static Void local putAp          Args((Int,Cell));
-static Void local putOverInfix   Args((Int,Text,Syntax,Cell));
-static Void local putInfix       Args((Int,Text,Syntax,Cell,Cell));
-static Void local putSimpleAp    Args((Cell,Int));
-static Void local putTuple       Args((Int,Cell));
-static Int  local unusedTups     Args((Int,Cell));
-static Void local unlexOp        Args((Text));
-
-static Void local putSigType     Args((Cell));
-static Void local putContext     Args((List,List,Int));
-static Void local putPred        Args((Cell,Int));
-static Void local putType        Args((Cell,Int,Int));
-static Void local putTyVar       Args((Int));
-static Bool local putTupleType   Args((Cell,Int));
-static Void local putApType      Args((Type,Int,Int));
-
-static Void local putKind        Args((Kind));
-static Void local putKinds       Args((Kinds));
+static Void local put            ( Int,Cell );
+static Void local putFlds        ( Cell,List );
+static Void local putComp        ( Cell,List );
+static Void local putQual        ( Cell );
+static Bool local isDictVal      ( Cell );
+static Cell local maySkipDict    ( Cell );
+static Void local putAp          ( Int,Cell );
+static Void local putOverInfix   ( Int,Text,Syntax,Cell );
+static Void local putInfix       ( Int,Text,Syntax,Cell,Cell );
+static Void local putSimpleAp    ( Cell,Int );
+static Void local putTuple       ( Int,Cell );
+static Int  local unusedTups     ( Int,Cell );
+static Void local unlexOp        ( Text );
+
+static Void local putSigType     ( Cell );
+static Void local putContext     ( List,List,Int );
+static Void local putPred        ( Cell,Int );
+static Void local putType        ( Cell,Int,Int );
+static Void local putTyVar       ( Int );
+static Bool local putTupleType   ( Cell,Int );
+static Void local putApType      ( Type,Int,Int );
+
+static Void local putKind        ( Kind );
+static Void local putKinds       ( Kinds );
+
 
 /* --------------------------------------------------------------------------
  * Basic output routines:
@@ -148,6 +149,18 @@ Cell e; {
         case CONOPCELL  : unlexVar(textOf(e));
                           break;
 
+#if IPARAM
+       case IPVAR      : putChr('?');
+                         unlexVar(textOf(e));
+                         break;
+
+       case WITHEXP    : OPEN(d>WHERE_PREC);
+                         putStr("dlet {...} in ");
+                         put(WHERE_PREC+1,fst(snd(e)));
+                         CLOSE(d>WHERE_PREC);
+                         break;
+#endif
+
 #if TREX
         case RECSEL     : putChr('#');
                           unlexVar(extText(snd(e)));
@@ -193,7 +206,7 @@ Cell e; {
 
         case FLOATCELL  : {   Float f = floatOf(e);
                               if (f<0 && d>=UMINUS_PREC) putChr('(');
-                              putStr(floatToString(f));
+                              putStr(floatToString(e));
                               if (f<0 && d>=UMINUS_PREC) putChr(')');
                           }
                           break;
@@ -202,7 +215,7 @@ Cell e; {
                           break;
 
         case LETREC     : OPEN(d>WHERE_PREC);
-#if DEBUG_CODE
+#if 0
                           putStr("let {");
                           put(NEVER,fst(snd(e)));
                           putStr("} in ");
@@ -258,7 +271,7 @@ Cell e; {
 
         case CASE       : putStr("case ");
                           put(NEVER,fst(snd(e)));
-#if DEBUG_CODE
+#if 0
                           putStr(" of {");
                           put(NEVER,snd(snd(e)));
                           putChr('}');
@@ -344,7 +357,7 @@ Cell q; {
 
 static Bool local isDictVal(e)          /* Look for dictionary value       */
 Cell e; {
-#if !DEBUG_CODE
+#if 0   /* was !DEBUG_CODE -- is it necessary? */
     Cell h = getHead(e);
     switch (whatIs(h)) {
         case DICTVAR : return TRUE;
@@ -365,7 +378,7 @@ static Void local putAp(d,e)            /* print application (args>=1)     */
 Int  d;
 Cell e; {
     Cell   h;
-    Text   t;
+    Text   t = 0;                       /* bogus init to keep gcc -O happy */
     Syntax sy;
     Int    args = 0;
 
@@ -379,14 +392,12 @@ Cell e; {
     }
 
     switch (whatIs(h)) {
-#if NPLUSK
         case ADDPAT     : if (args==1)
                               putInfix(d,textPlus,syntaxOf(namePlus),
                                          arg(e),mkInt(intValOf(fun(e))));
                           else
                               putStr("ADDPAT");
                           return;
-#endif
 
         case TUPLE      : OPEN(args>tupleOf(h) && d>=FUN_PREC);
                           putTuple(tupleOf(h),e);
@@ -538,12 +549,13 @@ Cell e; {                               /* args not yet printed ...        */
     return ts;
 }
 
-Void unlexVar(t)                       /* print text as a variable name    */
-Text t; {                              /* operator symbols must be enclosed*/
-    String s = textToStr(t);           /* in parentheses... except [] ...  */
-
+Void unlexVarStr(s)
+String s; {
     if ((isascii((int)(s[0])) && isalpha((int)(s[0]))) 
-       || s[0]=='_' || s[0]=='[' || s[0]=='(')
+        || s[0]=='_' || s[0]=='[' || s[0]=='('
+        || s[0]=='$'
+        || (s[0]==':' && s[1]=='D')
+       )
         putStr(s);
     else {
         putChr('(');
@@ -552,6 +564,11 @@ Text t; {                              /* operator symbols must be enclosed*/
     }
 }
 
+Void unlexVar(t)                       /* print text as a variable name    */
+Text t; {                              /* operator symbols must be enclosed*/
+    unlexVarStr(textToStr(t));         /* in parentheses... except [] ...  */
+}
+
 static Void local unlexOp(t)           /* print text as operator name      */
 Text t; {                              /* alpha numeric symbols must be    */
     String s = textToStr(t);           /* enclosed by backquotes           */
@@ -622,9 +639,13 @@ List qs;
 Int  fr; {
     Int len = length(ps) + length(qs);
     Int c   = len;
-    if (len!=1) {
+#if IPARAM
+    Bool useParens = len!=1 || isIP(fun(hd(ps)));
+#else
+    Bool useParens = len!=1;
+#endif
+    if (useParens)
         putChr('(');
-    }
     for (; nonNull(ps); ps=tl(ps)) {
         putPred(hd(ps),fr);
         if (--c > 0) {
@@ -637,9 +658,8 @@ Int  fr; {
             putStr(", ");
         }
     }
-    if (len!=1) {
+    if (useParens)
         putChr(')');
-    }
 }
 
 static Void local putPred(pi,fr)        /* Output predicate                */
@@ -654,6 +674,15 @@ Int  fr; {
             return;
         }
 #endif
+#if IPARAM
+       if (whatIs(fun(pi)) == IPCELL) {
+           putChr('?');
+           putPred(fun(pi),fr);
+           putStr(" :: ");
+           putType(arg(pi),NEVER,fr);
+           return;
+       }
+#endif
         putPred(fun(pi),fr);
         putChr(' ');
         putType(arg(pi),ALWAYS,fr);
@@ -662,6 +691,10 @@ Int  fr; {
         putStr(textToStr(cclass(pi).text));
     else if (isCon(pi))
         putStr(textToStr(textOf(pi)));
+#if IPARAM
+    else if (whatIs(pi) == IPCELL)
+        unlexVar(textOf(pi));
+#endif
     else
         putStr("<unknownPredicate>");
 }
@@ -688,7 +721,7 @@ Int  fr; {
                              for (; isAp(ks); ks=tl(ks)) {
                                  putTyVar(fr++);
                                  if (isAp(tl(ks)))
-                                     putChr(',');
+                                     putChr(' ');
                              }
                              putStr(". ");
                              putType(monotypeOf(t),NEVER,fr);
@@ -747,12 +780,14 @@ Int  fr; {
                                     CLOSE(prec>=ARROW_PREC);
                                     return;
                                 }
+#if 0
                                 else if (argCount==1) {
                                     putChr('(');
                                     putType(arg(t),ARROW_PREC,fr);
                                     putStr("->)");
                                     return;
                                 }
+#endif
                             }
                             else if (isTuple(typeHead)) {
                                 if (argCount==tupleOf(typeHead)) {
@@ -770,7 +805,7 @@ Int  fr; {
                                         putStr(punc);
                                         punc = ", ";
                                         putStr(textToStr(extText(typeHead)));
-                                        putStr("::");
+                                        putStr(" :: ");
                                         putType(extField(t),NEVER,fr);
                                         t        = extRow(t);
                                         typeHead = getHead(t);
@@ -890,6 +925,11 @@ Kinds ks; {
  * Main drivers:
  * ------------------------------------------------------------------------*/
 
+FILE *mystdout ( Void ) {
+  /* We use this from the gdb command line when debugging */
+  return stdout;
+}
+
 Void printExp(fp,e)                     /* print expr on specified stream  */
 FILE *fp;
 Cell e; {
@@ -933,4 +973,24 @@ Kinds ks; {
     putKinds(ks);
 }
 
+Void printFD(fp,fd)                    /* print functional dependency     */
+FILE* fp;
+Pair  fd; {
+    List us;
+    outputStream = fp;
+    for (us=fst(fd); nonNull(us); us=tl(us)) {
+        putTyVar(offsetOf(hd(us)));
+       if (nonNull(tl(us))) {
+           putChr(' ');
+       }
+    }
+    putStr(" -> ");
+    for (us=snd(fd); nonNull(us); us=tl(us)) {
+       putTyVar(offsetOf(hd(us)));
+       if (nonNull(tl(us))) {
+           putChr(' ');
+       }
+    }
+}
+  
 /*-------------------------------------------------------------------------*/