/* -----------------------------------------------------------------------------
- * $Id: Main.c,v 1.2 1998/12/02 13:28:30 simonm Exp $
+ * $Id: Main.c,v 1.10 1999/07/14 13:38:27 simonmar Exp $
+ *
+ * (c) The GHC Team 1998-1999
*
* Main function for a standalone Haskell program.
*
* ---------------------------------------------------------------------------*/
+#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
- MainTSO = createIOThread(BLOCK_SIZE_W,(StgClosure *)&mainIO_closure);
+# 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");
- MainTSO = createIOThread(BLOCK_SIZE_W,(StgClosure *)&mainIO_closure);
+ MainTSO = createIOThread(stg_max(BLOCK_SIZE_W,
+ RtsFlags.GcFlags.initialStkSize),
+ (StgClosure *)&mainIO_closure);
status = schedule(MainTSO,NULL);
} else {
WaitForPEOp(PP_FINISH,SysManTask);
exit(EXIT_SUCCESS);
}
-#endif /* PAR */
+# endif /* PAR */
switch (status) {
case AllBlocked:
barf("Scheduler stopped, all threads blocked");
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 */