[project @ 2000-07-06 20:50:37 by panne]
[ghc-hetmet.git] / ghc / interpreter / input.c
index de05f5f..63ebe07 100644 (file)
@@ -1,4 +1,3 @@
-
 /* --------------------------------------------------------------------------
  * Input functions, lexical analysis parsing etc...
  *
@@ -9,17 +8,15 @@
  * included in the distribution.
  *
  * $RCSfile: input.c,v $
- * $Revision: 1.19 $
- * $Date: 2000/03/09 02:47:13 $
+ * $Revision: 1.30 $
+ * $Date: 2000/04/25 17:43:49 $
  * ------------------------------------------------------------------------*/
 
-#include "prelude.h"
+#include "hugsbasictypes.h"
 #include "storage.h"
-#include "backend.h"
 #include "connect.h"
-#include "command.h"
 #include "errors.h"
-#include "link.h"
+
 #include <ctype.h>
 #if HAVE_GETDELIM_H
 #include "getdelim.h"
 #include <windows.h>
 #endif
 
-#if IS_WIN32 || HUGS_FOR_WINDOWS
+#if IS_WIN32
 #undef IN
 #endif
 
-#if HAVE_LIBREADLINE && HAVE_READLINE_READLINE_H && HAVE_READLINE_HISTORY_H
+#if HAVE_READLINE_LIBS && HAVE_READLINE_HEADERS
 #define USE_READLINE 1
 #else
 #define USE_READLINE 0
@@ -80,51 +77,51 @@ String preprocessor  = 0;
  * Local function prototypes:
  * ------------------------------------------------------------------------*/
 
-static Void local initCharTab     Args((Void));
-static Void local fileInput       Args((String,Long));
-static Bool local literateMode    Args((String));
-static Bool local linecmp         Args((String,String));
-static Int  local nextLine        Args((Void));
-static Void local skip            Args((Void));
-static Void local thisLineIs      Args((Int));
-static Void local newlineSkip     Args((Void));
-static Void local closeAnyInput   Args((Void));
-
-       Int  yyparse         Args((Void)); /* can't stop yacc making this   */
+static Void local initCharTab     ( Void );
+static Void local fileInput       ( String,Long );
+static Bool local literateMode    ( String );
+static Bool local linecmp         ( String,String );
+static Int  local nextLine        ( Void );
+static Void local skip            ( Void );
+static Void local thisLineIs      ( Int );
+static Void local newlineSkip     ( Void );
+static Void local closeAnyInput   ( Void );
+
+       Int  yyparse               ( Void ); /* can't stop yacc making this   */
                                           /* public, but don't advertise   */
                                           /* it in a header file.          */
 
-static Void local endToken        Args((Void));
-static Text local readOperator    Args((Void));
-static Text local readIdent       Args((Void));
-static Cell local readRadixNumber Args((Int));
-static Cell local readNumber      Args((Void));
-static Cell local readChar        Args((Void));
-static Cell local readString      Args((Void));
-static Void local saveStrChr      Args((Char));
-static Cell local readAChar       Args((Bool));
+static Void local endToken        ( Void );
+static Text local readOperator    ( Void );
+static Text local readIdent       ( Void );
+static Cell local readRadixNumber ( Int );
+static Cell local readNumber      ( Void );
+static Cell local readChar        ( Void );
+static Cell local readString      ( Void );
+static Void local saveStrChr      ( Char );
+static Cell local readAChar       ( Bool );
 
-static Bool local lazyReadMatches Args((String));
-static Cell local readEscapeChar  Args((Bool));
-static Void local skipGap         Args((Void));
-static Cell local readCtrlChar    Args((Void));
-static Cell local readOctChar     Args((Void));
-static Cell local readHexChar     Args((Void));
-static Int  local readHexDigit    Args((Char));
-static Cell local readDecChar     Args((Void));
+static Bool local lazyReadMatches ( String );
+static Cell local readEscapeChar  ( Bool );
+static Void local skipGap         ( Void );
+static Cell local readCtrlChar    ( Void );
+static Cell local readOctChar     ( Void );
+static Cell local readHexChar     ( Void );
+static Int  local readHexDigit    ( Char );
+static Cell local readDecChar     ( Void );
 
-static Void local goOffside       Args((Int));
-static Void local unOffside       Args((Void));
-static Bool local canUnOffside    Args((Void));
+static Void local goOffside       ( Int );
+static Void local unOffside       ( Void );
+static Bool local canUnOffside    ( Void );
 
-static Void local skipWhitespace  Args((Void));
-static Int  local yylex           Args((Void));
-static Int  local repeatLast      Args((Void));
+static Void local skipWhitespace  ( Void );
+static Int  local yylex           ( Void );
+static Int  local repeatLast      ( Void );
 
-static Cell local parseInput      Args((Int));
+static Cell local parseInput      ( Int );
 
-static Bool local doesNotExceed   Args((String,Int,Int));
-static Int  local stringToInt     Args((String,Int));
+static Bool local doesNotExceed   ( String,Int,Int );
+static Int  local stringToInt     ( String,Int );
 
 
 /* --------------------------------------------------------------------------
@@ -135,6 +132,7 @@ static Text textCase,    textOfK,      textData,   textType,   textIf;
 static Text textThen,    textElse,     textWhere,  textLet,    textIn;
 static Text textInfix,   textInfixl,   textInfixr, textForeign, textNewtype;
 static Text textDefault, textDeriving, textDo,     textClass,  textInstance;
+static Text textMdo;
 #if IPARAM
 static Text textWith,  textDlet;
 #endif
@@ -153,6 +151,7 @@ Text   textCcall;                       /* ccall                           */
 Text   textStdcall;                     /* stdcall                         */
 
 Text   textNum;                         /* Num                             */
+Text   textPrelPrim;                    /* PrelPrim                        */
 Text   textPrelude;                     /* Prelude                         */
 Text   textPlus;                        /* (+)                             */
 
@@ -166,7 +165,6 @@ static Cell varDot;                     /* (.)                             */
 static Cell varHiding;                  /* hiding                          */
 static Cell varQualified;               /* qualified                       */
 static Cell varAsMod;                   /* as                              */
-static Cell varPrivileged;              /* privileged                      */
 
 static List imps;                       /* List of imports to be chased    */
 
@@ -564,19 +562,19 @@ static Void local skip() {              /* move forward one char in input  */
             closeAnyInput();
         }
         else if (reading==KEYBOARD) {
-            allowBreak();
+            /* allowBreak(); */
             if (c0=='\n')
                 c1 = EOF;
             else {
                 c1 = nextConsoleChar();
-#if IS_WIN32 && !HUGS_FOR_WINDOWS
+#if IS_WIN32
                Sleep(0);
 #endif
                /* On Win32, hitting ctrl-C causes the next getchar to
                 * fail - returning "-1" to indicate an error.
                 * This is one of the rare cases where "-1" does not mean EOF.
                 */
-               if (EOF == c1 && (!feof(stdin) || broken==TRUE)) {
+               if (EOF == c1 && (!feof(stdin) /* || broken==TRUE */)) {
                     c1 = ' ';
                 }
             }
@@ -1218,7 +1216,7 @@ String readFilename() {                /* Read filename from input (if any)*/
 
     startToken();
     while (c0!=EOF && !isIn(c0,ZPACE)) {
-        if (c0=='"') {
+       if (c0=='"') {
             skip();
             while (c0!=EOF && c0!='\"') {
                 Cell c = readAChar(TRUE);
@@ -1265,7 +1263,7 @@ String readLine() {                    /* Read command line from input     */
  * - Otherwise, if no `{' follows the keywords WHERE/LET or OF, a SOFT `{'
  *   is inserted with the column number of the first token after the
  *   WHERE/LET/OF keyword.
- * - When a soft indentation is uppermost on the indetation stack with
+ * - When a soft indentation is uppermost on the indentation stack with
  *   column col' we insert:
  *    `}'  in front of token with column<col' and pop indentation off stack,
  *    `;'  in front of token with column==col'.
@@ -1521,12 +1519,12 @@ static Int local yylex() {             /* Read next input token ...        */
         if (it==textHiding)            return HIDING;
         if (it==textQualified)         return QUALIFIED;
         if (it==textAsMod)             return ASMOD;
-        if (it==textPrivileged)        return PRIVILEGED;
         if (it==textWildcard)          return '_';
         if (it==textAll && !haskell98) return ALL;
 #if IPARAM
        if (it==textWith && !haskell98) lookAhead(WITH);
        if (it==textDlet && !haskell98) lookAhead(DLET);
+        if (it==textMdo && !haskell98)  lookAhead(MDO);
 #endif
         if (it==textUUAll)             return ALL;
         if (it==textUUUsage)           return UUUSAGE;
@@ -1613,66 +1611,20 @@ Int startWith; {                       /* determining whether to read a    */
         ERRMSG(row) "Parser overflow"  /* as all syntax errors are caught  */
         EEND;                          /* in the parser...                 */
     }
+
+    if (startWith==SCRIPT) pop();      /* zap spurious closing } token     */
     final = pop();
+
     if (!stackEmpty())                 /* stack should now be empty        */
         internal("parseInput");
     return final;
 }
 
-#ifdef HSCRIPT
-static String memPrefix = "@mem@";
-static Int lenMemPrefix = 5;   /* strlen(memPrefix)*/
-
-Void makeMemScript(mem,fname)
-String mem;
-String fname; {     
-   strcat(fname,memPrefix);
-   itoa((int)mem, fname+strlen(fname), 10); 
-}
-
-Bool isMemScript(fname)
-String fname; {
-   return (strstr(fname,memPrefix) != NULL);
-}
-
-String memScriptString(fname)
-String fname; { 
-    String p = strstr(fname,memPrefix);
-    if (p) {
-        return (String)atoi(p+lenMemPrefix);
-    } else {
-        return NULL;
-    }
-}
-
-Void parseScript(fname,len)             /* Read a script, possibly from mem */
-String fname;
-Long len; {
-    input(RESET);
-    if (isMemScript(fname)) {
-        char* s = memScriptString(fname);
-        stringInput(s);
-    } else {
-        fileInput(fname,len);
-    }
-    parseInput(SCRIPT);
-}
-#else
-Void parseScript(nm,len)               /* Read a script                    */
-String nm;
-Long   len; {                          /* Used to set a target for reading */
-    input(RESET);
-    fileInput(nm,len);
-    parseInput(SCRIPT);
-}
-#endif
-
 Void parseExp() {                      /* Read an expression to evaluate   */
     parseInput(EXPR);
     setLastExpr(inputExpr);
 }
 
-
 #if EXPLAIN_INSTANCE_RESOLUTION
 Void parseContext() {                  /* Read a context to prove   */
     parseInput(CONTEXT);
@@ -1683,10 +1635,20 @@ Cell parseInterface(nm,len)            /* Read a GHC interface file        */
 String nm;
 Long   len; {                          /* Used to set a target for reading */
    input(RESET);
+   Printf("Reading interface \"%s\"\n", nm );
    fileInput(nm,len);
    return parseInput(INTERFACE);
 }
 
+Cell parseModule(nm,len)               /* Read a module                    */
+String nm;
+Long   len; {                          /* Used to set a target for reading */
+    input(RESET);
+    Printf("Reading source file \"%s\"\n", nm );
+    fileInput(nm,len);
+    return parseInput(SCRIPT);
+}
+
 
 /* --------------------------------------------------------------------------
  * Input control:
@@ -1717,6 +1679,7 @@ Int what; {
                        textDefault    = findText("default");
                        textDeriving   = findText("deriving");
                        textDo         = findText("do");
+                       textMdo        = findText("mdo");
                        textClass      = findText("class");
 #if IPARAM
                       textWith       = findText("with");
@@ -1737,6 +1700,7 @@ Int what; {
                        textBang       = findText("!");
                        textDot        = findText(".");
                        textImplies    = findText("=>");
+                       textPrelPrim   = findText("PrelPrim");
                        textPrelude    = findText("Prelude");
                        textNum        = findText("Num");
                        textModule     = findText("module");
@@ -1751,7 +1715,6 @@ Int what; {
                        textHiding     = findText("hiding");
                        textQualified  = findText("qualified");
                        textAsMod      = findText("as");
-                       textPrivileged = findText("privileged");
                        textWildcard   = findText("_");
                        textAll        = findText("forall");
                        textUUAll      = findText("__forall");
@@ -1763,7 +1726,6 @@ Int what; {
                        varHiding      = mkVar(textHiding);
                        varQualified   = mkVar(textQualified);
                        varAsMod       = mkVar(textAsMod);
-                       varPrivileged  = mkVar(textPrivileged);
                        conMain        = mkCon(findText("Main"));
                        varMain        = mkVar(findText("main"));
                        evalDefaults   = NIL;
@@ -1812,7 +1774,6 @@ Int what; {
                        mark(varHiding);
                        mark(varQualified);
                        mark(varAsMod);
-                       mark(varPrivileged);
                        mark(varMain);
                        mark(conMain);
                        mark(imps);