[project @ 2000-01-11 14:21:43 by sewardj]
[ghc-hetmet.git] / ghc / interpreter / hugs.c
index 76e5549..d788d47 100644 (file)
@@ -9,8 +9,8 @@
  * included in the distribution.
  *
  * $RCSfile: hugs.c,v $
- * $Revision: 1.27 $
- * $Date: 1999/12/03 14:38:39 $
+ * $Revision: 1.35 $
+ * $Date: 2000/01/11 14:21:43 $
  * ------------------------------------------------------------------------*/
 
 #include <setjmp.h>
@@ -97,7 +97,7 @@ static Void   local browse          Args((Void));
  * Machine dependent code for Hugs interpreter:
  * ------------------------------------------------------------------------*/
 
-       Bool   combined      = FALSE;
+       Bool   combined      = TRUE;
 
 #include "machdep.c"
 #ifdef WANT_TIMER
@@ -158,6 +158,8 @@ static Int    hpSize     = DEFAULTHEAP; /* Desired heap size               */
        String hugsEdit   = 0;           /* String for editor command       */
        String hugsPath   = 0;           /* String for file search path     */
 
+       List  ifaces_outstanding = NIL;
+
 #if REDIRECT_OUTPUT
 static Bool disableOutput = FALSE;      /* redirect output to buffer?      */
 #endif
@@ -306,7 +308,21 @@ String argv[]; {
 
    namesUpto = numScripts = 0;
 
-   for (i=1; i<argc; ++i) {            /* process command line arguments  */
+   /* Pre-scan flags to see if -c or +c is present.  This needs to
+      precede adding the stack entry for Prelude.  On the other hand,
+      that stack entry needs to be made before the cmd line args are
+      properly examined.  Hence the following pre-scan of them.
+   */
+   for (i=1; i < argc; ++i) {
+      if (strcmp(argv[i], "--")==0) break;
+      if (strcmp(argv[i], "-c")==0) combined = FALSE;
+      if (strcmp(argv[i], "+c")==0) combined = TRUE;
+   }
+
+   addStackEntry("Prelude");
+   if (combined) addStackEntry("PrelHugs");
+
+   for (i=1; i < argc; ++i) {            /* process command line arguments  */
         if (strcmp(argv[i], "--")==0) break;
         if (strcmp(argv[i],"+")==0 && i+1<argc) {
             if (proj) {
@@ -321,8 +337,6 @@ String argv[]; {
         }
     }
 
-   addStackEntry("Prelude");
-
 #if DEBUG
     { 
        char exe_name[N_INSTALLDIR + 6];
@@ -353,7 +367,8 @@ String argv[]; {
         Printf("Standalone mode: Restart with command line +c for combined mode\n\n" );
     }
  
-    everybody(INSTALL);
+    everybody(PREPREL);
+
     evalModule = findText("");      /* evaluate wrt last module by default */
     if (proj) {
         if (namesUpto>1) {
@@ -586,7 +601,8 @@ String s; {                             /* return FALSE if none found.     */
                                   "You can't enable/disable combined"
                                   " operation inside Hugs\n" );
                        } else {
-                          combined = state;
+                         /* don't do anything, since pre-scan of args
+                             will have got it already */
                        }
                        return TRUE;
 
@@ -950,6 +966,7 @@ String s; {                            /* to be read in ...                */
 /* Return TRUE if no imports were needed; FALSE otherwise. */
 static Bool local addScript(stacknum)   /* read single file                */
 Int stacknum; {
+   Bool didPrelude;
    static char name[FILENAME_MAX+1];
    Int len = scriptInfo[stacknum].size;
 
@@ -960,7 +977,6 @@ Int stacknum; {
 
     //   setLastEdit(name,0);
 
-   nameObj[0] = 0;
    strcpy(name, scriptInfo[stacknum].path);
    strcat(name, scriptInfo[stacknum].modName);
    if (scriptInfo[stacknum].fromSource)
@@ -970,7 +986,13 @@ Int stacknum; {
    scriptFile = name;
 
    if (scriptInfo[stacknum].fromSource) {
-      if (lastWasObject) finishInterfaces();
+      if (lastWasObject) {
+         didPrelude = processInterfaces();
+         if (didPrelude) {
+            preludeLoaded = TRUE;
+            everybody(POSTPREL);
+         }
+      }
       lastWasObject = FALSE;
       Printf("Reading script \"%s\":\n",name);
       needsImports = FALSE;
@@ -980,6 +1002,12 @@ Int stacknum; {
       typeCheckDefns();
       compileDefns();
    } else {
+      Cell    iface;
+      List    imports;
+      ZTriple iface_info;
+      char    nameObj[FILENAME_MAX+1];
+      Int     sizeObj;
+
       Printf("Reading  iface \"%s\":\n", name);
       scriptFile = name;
       needsImports = FALSE;
@@ -990,14 +1018,21 @@ Int stacknum; {
       strcat(nameObj, DLL_ENDING);
       sizeObj = scriptInfo[stacknum].oSize;
 
-      loadInterface(name,len);
+      iface = readInterface(name,len);
+      imports = zsnd(iface); iface = zfst(iface);
+
+      if (nonNull(imports)) chase(imports);
       scriptFile = 0;
       lastWasObject = TRUE;
+
+      iface_info = ztriple(iface, findText(nameObj), mkInt(sizeObj) );
+      ifaces_outstanding = cons(iface_info,ifaces_outstanding);
+
       if (needsImports) return FALSE;
    }
  
    scriptFile = 0;
-   preludeLoaded = TRUE;
+
    return TRUE;
 }
 
@@ -1118,6 +1153,7 @@ Int n; {                                /* loading everything after and    */
     Time timeStamp;                     /* including the first script which*/
     Long fileSize;                      /* has been either changed or added*/
     static char name[FILENAME_MAX+1];
+    Bool didPrelude;
 
     lastWasObject = FALSE;
     ppSmStack("readscripts-begin");
@@ -1174,7 +1210,7 @@ Int n; {                                /* loading everything after and    */
     //numScripts = 0;
 
     while (numScripts < namesUpto) {
-ppSmStack ( "readscripts-loop2" );
+       ppSmStack ( "readscripts-loop2" );
 
        if (scriptInfo[numScripts].fromSource) {
 
@@ -1183,7 +1219,7 @@ ppSmStack ( "readscripts-loop2" );
           nextNumScripts = NUM_SCRIPTS; //bogus initialisation
           if (addScript(numScripts)) {
              numScripts++;
-assert(nextNumScripts==NUM_SCRIPTS);
+             assert(nextNumScripts==NUM_SCRIPTS);
           }
           else
              dropScriptsFrom(numScripts-1);
@@ -1201,21 +1237,26 @@ assert(nextNumScripts==NUM_SCRIPTS);
              nextNumScripts = NUM_SCRIPTS;
              if (addScript(numScripts)) {
                 numScripts++;
-assert(nextNumScripts==NUM_SCRIPTS);
+                assert(nextNumScripts==NUM_SCRIPTS);
              } else {
                //while (!scriptInfo[numScripts].fromSource && numScripts > 0)
                //   numScripts--;
                //if (scriptInfo[numScripts].fromSource)
                //   numScripts++;
                 numScripts = nextNumScripts;
-assert(nextNumScripts<NUM_SCRIPTS);
+                assert(nextNumScripts<NUM_SCRIPTS);
              }
           }
        }
-if (numScripts==namesUpto) ppSmStack( "readscripts-final") ;
+       if (numScripts==namesUpto) ppSmStack( "readscripts-final") ;
+    }
+
+    didPrelude = processInterfaces();
+    if (didPrelude) {
+       preludeLoaded = TRUE;
+       everybody(POSTPREL);
     }
 
-    finishInterfaces();
 
     { Int  m     = namesUpto-1;
       Text mtext = findText(scriptInfo[m].modName);
@@ -1345,6 +1386,7 @@ static Void local evaluator() {        /* evaluate expr and print value    */
     checkExp();
     defaultDefns = evalDefaults;
     type         = typeCheckExp(TRUE);
+
     if (isPolyType(type)) {
         ks = polySigOf(type);
         bd = monotypeOf(type);
@@ -1366,7 +1408,7 @@ static Void local evaluator() {        /* evaluate expr and print value    */
 
 #if 1
     if (isProgType(ks,bd)) {
-        inputExpr = ap(nameRunIO,inputExpr);
+        inputExpr = ap(nameRunIO_toplevel,inputExpr);
         evalExp();
         Putchar('\n');
     } else {
@@ -1378,9 +1420,9 @@ static Void local evaluator() {        /* evaluate expr and print value    */
             ERRTEXT   "\n"
             EEND;
         }
-        inputExpr = ap2(findName(findText("show")),d,inputExpr);
-        inputExpr = ap(findName(findText("putStr")), inputExpr);
-        inputExpr = ap(nameRunIO, inputExpr);
+        inputExpr = ap2(nameShow,           d,inputExpr);
+        inputExpr = ap (namePutStr,         inputExpr);
+        inputExpr = ap (nameRunIO_toplevel, inputExpr);
 
         evalExp(); printf("\n");
         if (addType) {
@@ -1784,7 +1826,7 @@ Text t; {
         } else {
             Printf("<unknown type>");
         }
-
+printf("\n");print(name(nm).type,10);printf("\n");
         if (isCfun(nm)) {
             Printf("  -- data constructor");
         } else if (isMfun(nm)) {
@@ -2375,8 +2417,11 @@ FILE* fp; {
 
 Void everybody(what)            /* send command `what' to each component of*/
 Int what; {                     /* system to respond as appropriate ...    */
+#if 0
+  fprintf ( stderr, "EVERYBODY %d\n", what );
+#endif
     machdep(what);              /* The order of calling each component is  */
-    storage(what);              /* important for the INSTALL command       */
+    storage(what);              /* important for the PREPREL command       */
     substitution(what);
     input(what);
     translateControl(what);