[project @ 2000-03-14 09:55:05 by simonmar]
[ghc-hetmet.git] / ghc / interpreter / input.c
index aeb47ef..cb744af 100644 (file)
@@ -9,17 +9,15 @@
  * included in the distribution.
  *
  * $RCSfile: input.c,v $
- * $Revision: 1.17 $
- * $Date: 1999/12/06 16:20:26 $
+ * $Revision: 1.21 $
+ * $Date: 2000/03/13 11:37:16 $
  * ------------------------------------------------------------------------*/
 
 #include "prelude.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"
@@ -80,51 +78,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 Void 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 );
 
 
 /* --------------------------------------------------------------------------
@@ -145,7 +143,7 @@ static Text textBang,    textDot,      textAll,    textImplies;
 static Text textWildcard;
 
 static Text textModule,  textImport,    textInterface,  textInstImport;
-static Text textHiding,  textQualified, textAsMod;
+static Text textHiding,  textQualified, textAsMod,      textPrivileged;
 static Text textExport,  textDynamic,   textUUExport;
 static Text textUnsafe,  textUUAll,     textUUUsage;
 
@@ -166,6 +164,7 @@ 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    */
 
@@ -1520,6 +1519,7 @@ 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
@@ -1595,9 +1595,10 @@ Name n; {
  * main entry points to parser/lexer:
  * ------------------------------------------------------------------------*/
 
-static Void local parseInput(startWith)/* Parse input with given first tok,*/
+static Cell local parseInput(startWith)/* Parse input with given first tok,*/
 Int startWith; {                       /* determining whether to read a    */
-    firstToken   = TRUE;               /* script or an expression          */
+    Cell final   = NIL;                /* script or an expression          */
+    firstToken   = TRUE;
     firstTokenIs = startWith;
     if (startWith==INTERFACE) {
        offsideON = FALSE; readingInterface = TRUE; 
@@ -1610,9 +1611,10 @@ Int startWith; {                       /* determining whether to read a    */
         ERRMSG(row) "Parser overflow"  /* as all syntax errors are caught  */
         EEND;                          /* in the parser...                 */
     }
-    drop();
+    final = pop();
     if (!stackEmpty())                 /* stack should now be empty        */
         internal("parseInput");
+    return final;
 }
 
 #ifdef HSCRIPT
@@ -1675,12 +1677,12 @@ Void parseContext() {                  /* Read a context to prove   */
 }
 #endif
 
-Void parseInterface(nm,len)            /* Read a GHC interface file        */
+Cell parseInterface(nm,len)            /* Read a GHC interface file        */
 String nm;
 Long   len; {                          /* Used to set a target for reading */
-    input(RESET);
-    fileInput(nm,len);
-    parseInput(INTERFACE);
+   input(RESET);
+   fileInput(nm,len);
+   return parseInput(INTERFACE);
 }
 
 
@@ -1691,7 +1693,9 @@ Long   len; {                          /* Used to set a target for reading */
 Void input(what)
 Int what; {
     switch (what) {
-        case INSTALL : initCharTab();
+        case POSTPREL: break;
+
+        case PREPREL : initCharTab();
                        textCase       = findText("case");
                        textOfK        = findText("of");
                        textData       = findText("data");
@@ -1745,6 +1749,7 @@ Int what; {
                        textHiding     = findText("hiding");
                        textQualified  = findText("qualified");
                        textAsMod      = findText("as");
+                       textPrivileged = findText("privileged");
                        textWildcard   = findText("_");
                        textAll        = findText("forall");
                        textUUAll      = findText("__forall");
@@ -1756,6 +1761,7 @@ Int what; {
                        varHiding      = mkVar(textHiding);
                        varQualified   = mkVar(textQualified);
                        varAsMod       = mkVar(textAsMod);
+                       varPrivileged  = mkVar(textPrivileged);
                        conMain        = mkCon(findText("Main"));
                        varMain        = mkVar(findText("main"));
                        evalDefaults   = NIL;
@@ -1770,7 +1776,6 @@ Int what; {
                        instDefns    = NIL;
                        selDefns     = NIL;
                        genDefns     = NIL;
-                       //primDefns    = NIL;
                        unqualImports= NIL;
                        foreignImports= NIL;
                        foreignExports= NIL;
@@ -1792,7 +1797,6 @@ Int what; {
                        mark(instDefns);
                        mark(selDefns);
                        mark(genDefns);
-                       //mark(primDefns);
                        mark(unqualImports);
                        mark(foreignImports);
                        mark(foreignExports);
@@ -1806,6 +1810,7 @@ Int what; {
                        mark(varHiding);
                        mark(varQualified);
                        mark(varAsMod);
+                       mark(varPrivileged);
                        mark(varMain);
                        mark(conMain);
                        mark(imps);