[project @ 1999-07-14 13:38:27 by simonmar]
[ghc-hetmet.git] / ghc / rts / Main.c
index 9f2c9c1..6ed8ac2 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Main.c,v 1.5 1999/02/26 16:46:50 simonm Exp $
+ * $Id: Main.c,v 1.10 1999/07/14 13:38:27 simonmar Exp $
  *
  * (c) The GHC Team 1998-1999
  *
@@ -7,14 +7,16 @@
  *
  * ---------------------------------------------------------------------------*/
 
+#define COMPILING_RTS_MAIN
+
 #include "Rts.h"
 #include "RtsAPI.h"
+#include "SchedAPI.h"
 #include "RtsFlags.h"
 #include "Schedule.h"  /* for MainTSO */
 #include "RtsUtils.h"
 
 #ifdef DEBUG
-#include "RtsFlags.h"  /* for debugging flags */
 #include "Printer.h"   /* for printing        */
 #endif
 
 #include "LLC.h"
 #endif
 
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
+
+#ifndef ENABLE_WIN32_DLL_SUPPORT
+
 /* Hack: we assume that we're building a batch-mode system unless 
  * INTERPRETER is set
  */
-#ifndef INTERPRETER /* Hack */
+# ifndef INTERPRETER /* Hack */
 int main(int argc, char *argv[])
 {
     SchedulerStatus status;
     startupHaskell(argc,argv);
 
-#ifndef PAR
+#  ifndef PAR
     MainTSO = createIOThread(stg_max(BLOCK_SIZE_W,
                                     RtsFlags.GcFlags.initialStkSize),
                             (StgClosure *)&mainIO_closure);
     status = schedule(MainTSO,NULL);
-#else
+#  else
     if (IAmMainThread == rtsTrue) {
     /*Just to show we're alive */
       fprintf(stderr, "Main Thread Started ...\n");
@@ -55,7 +64,7 @@ int main(int argc, char *argv[])
       WaitForPEOp(PP_FINISH,SysManTask);
       exit(EXIT_SUCCESS);
     }
-#endif /* PAR */
+#  endif /* PAR */
     switch (status) {
     case AllBlocked:
       barf("Scheduler stopped, all threads blocked");
@@ -68,7 +77,34 @@ int main(int argc, char *argv[])
     case Interrupted:
       /* carry on */
     }
+    shutdownHaskellAndExit(EXIT_SUCCESS);
+}
+# endif /* BATCH_MODE */
+
+#else   /* !ENABLE_WIN32_DLL_SUPPORT */
+
+static char* args[] = { "ghcRts" };
+
+BOOL
+WINAPI
+DllMain ( HINSTANCE hInstance
+        , DWORD reason
+       , LPVOID reserved
+       )
+{
+  /*
+    ToDo: let the user configure RTS options to use
+          via the registry.
+   */
+  switch (reason) {
+  case DLL_PROCESS_ATTACH:
+    startupHaskell(1,args);
+    /* ToDo: gracefully handle startupHaskell() failures.. */
+    return TRUE;
+  case DLL_PROCESS_DETACH:
     shutdownHaskell();
-    stg_exit(EXIT_SUCCESS);
+  }
+  return TRUE;
 }
-#endif /* BATCH_MODE */
+
+#endif /* !ENABLE_WIN32_DLL_SUPPORT */