[project @ 1999-11-02 15:05:38 by simonmar]
[ghc-hetmet.git] / ghc / rts / Main.c
1 /* -----------------------------------------------------------------------------
2  * $Id: Main.c,v 1.12 1999/11/02 15:05:58 simonmar Exp $
3  *
4  * (c) The GHC Team 1998-1999
5  *
6  * Main function for a standalone Haskell program.
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #define COMPILING_RTS_MAIN
11
12 #include "Rts.h"
13 #include "RtsAPI.h"
14 #include "SchedAPI.h"
15 #include "RtsFlags.h"
16 #include "RtsUtils.h"
17
18 #ifdef DEBUG
19 #include "Printer.h"   /* for printing        */
20 #endif
21
22 #ifdef INTERPRETER
23 #include "Assembler.h"
24 #endif
25
26 #ifdef PAR
27 #include "ParInit.h"
28 #include "Parallel.h"
29 #include "LLC.h"
30 #endif
31
32 #ifdef HAVE_WINDOWS_H
33 #include <windows.h>
34 #endif
35
36
37 /* Hack: we assume that we're building a batch-mode system unless 
38  * INTERPRETER is set
39  */
40 # ifndef INTERPRETER /* Hack */
41 int main(int argc, char *argv[])
42 {
43     SchedulerStatus status;
44     startupHaskell(argc,argv);
45
46 #  ifndef PAR
47     /* ToDo: want to start with a larger stack size */
48     status = rts_evalIO((StgClosure *)&mainIO_closure, NULL);
49 #  else
50     if (IAmMainThread == rtsTrue) {
51     /*Just to show we're alive */
52       fprintf(stderr, "Main Thread Started ...\n");
53      
54       status = rts_evalIO((StgClosure *)&mainIO_closure, NULL);
55     } else {
56       WaitForPEOp(PP_FINISH,SysManTask);
57       exit(EXIT_SUCCESS);
58     }
59 #  endif /* PAR */
60     switch (status) {
61     case AllBlocked:
62       barf("Scheduler stopped, all threads blocked");
63     case Deadlock:
64       shutdownHaskell();
65       barf("No threads to run!  Deadlock?");
66     case Killed:
67       belch("%s: warning: main thread killed", prog_argv[0]);
68     case Success:
69     case Interrupted:
70       /* carry on */
71     }
72     shutdownHaskellAndExit(EXIT_SUCCESS);
73 }
74 # endif /* BATCH_MODE */