[project @ 1999-11-29 18:59:23 by sewardj]
[ghc-hetmet.git] / ghc / interpreter / output.c
index 8cf7aa9..d20af2c 100644 (file)
@@ -3,14 +3,15 @@
  * Unparse expressions and types - for use in error messages, type checker
  * and for debugging.
  *
- * Hugs 98 is Copyright (c) Mark P Jones, Alastair Reid and the Yale
- * Haskell Group 1994-99, and is distributed as Open Source software
- * under the Artistic License; see the file "Artistic" that is included
- * in the distribution for details.
+ * 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: output.c,v $
- * $Revision: 1.4 $
- * $Date: 1999/03/01 14:46:50 $
+ * $Revision: 1.13 $
+ * $Date: 1999/11/29 18:59:29 $
  * ------------------------------------------------------------------------*/
 
 #include "prelude.h"
@@ -50,6 +51,7 @@ static Void local putApType      Args((Type,Int,Int));
 static Void local putKind        Args((Kind));
 static Void local putKinds       Args((Kinds));
 
+
 /* --------------------------------------------------------------------------
  * Basic output routines:
  * ------------------------------------------------------------------------*/
@@ -147,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)));
@@ -190,18 +204,9 @@ Cell e; {
                           }
                           break;
 
-#if BIGNUMS
-        case NEGNUM     :
-        case ZERONUM    :
-        case POSNUM     : xs = bigOut(e,NIL,d>=UMINUS_PREC);
-                          for (; nonNull(xs); xs=tl(xs))
-                              putChr(charOf(arg(hd(xs))));
-                          break;
-#endif
-
         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;
@@ -373,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;
 
@@ -403,9 +408,6 @@ Cell e; {
 
         case NAME       : if (args==1 &&
                               ((h==nameFromInt     && isInt(arg(e)))    ||
-#if BIGNUMS
-                               (h==nameFromInteger && isBignum(arg(e))) ||
-#endif
                                (h==nameFromDouble  && isFloat(arg(e))))) {
                               put(d,arg(e));
                               return;
@@ -549,12 +551,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('(');
@@ -563,6 +566,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           */
@@ -633,9 +641,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) {
@@ -648,9 +660,8 @@ Int  fr; {
             putStr(", ");
         }
     }
-    if (len!=1) {
+    if (useParens)
         putChr(')');
-    }
 }
 
 static Void local putPred(pi,fr)        /* Output predicate                */
@@ -665,6 +676,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);
@@ -673,6 +693,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>");
 }
@@ -699,7 +723,7 @@ Int  fr; {
                              for (; isAp(ks); ks=tl(ks)) {
                                  putTyVar(fr++);
                                  if (isAp(tl(ks)))
-                                     putChr(',');
+                                     putChr(' ');
                              }
                              putStr(". ");
                              putType(monotypeOf(t),NEVER,fr);
@@ -758,12 +782,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)) {
@@ -781,7 +807,7 @@ Int  fr; {
                                         putStr(punc);
                                         punc = ", ";
                                         putStr(textToStr(extText(typeHead)));
-                                        putStr("::");
+                                        putStr(" :: ");
                                         putType(extField(t),NEVER,fr);
                                         t        = extRow(t);
                                         typeHead = getHead(t);
@@ -901,6 +927,12 @@ Kinds ks; {
  * Main drivers:
  * ------------------------------------------------------------------------*/
 
+extern FILE *mystdout Args((Void));
+FILE *mystdout() {
+  /* 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; {
@@ -944,4 +976,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(' ');
+       }
+    }
+}
+  
 /*-------------------------------------------------------------------------*/