09e6e218a9d6fd464ae1024503aa7ab8ac7020cf
[ghc-hetmet.git] / ghc / rts / Main.c
1 /* -----------------------------------------------------------------------------
2  * $Id: Main.c,v 1.13 2000/01/13 12:40:15 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     int exit_status;
44
45     SchedulerStatus status;
46     startupHaskell(argc,argv);
47
48 #  ifndef PAR
49     /* ToDo: want to start with a larger stack size */
50     status = rts_evalIO((StgClosure *)&mainIO_closure, NULL);
51 #  else
52     if (IAmMainThread == rtsTrue) {
53     /*Just to show we're alive */
54       fprintf(stderr, "Main Thread Started ...\n");
55      
56       status = rts_evalIO((StgClosure *)&mainIO_closure, NULL);
57     } else {
58       WaitForPEOp(PP_FINISH,SysManTask);
59       exit(EXIT_SUCCESS);
60     }
61 #  endif /* PAR */
62     switch (status) {
63     case Deadlock:
64       prog_belch("no threads to run:  infinite loop or deadlock?");
65       exit_status = EXIT_DEADLOCK;
66       break;
67     case Killed:
68       prog_belch("main thread killed");
69       exit_status = EXIT_KILLED;
70       break;
71     case Interrupted:
72       prog_belch("interrupted");
73       exit_status = EXIT_INTERRUPTED;
74       break;
75     case Success:
76       exit_status = EXIT_SUCCESS;
77       break;
78     case NoStatus:
79       barf("main thread completed with no status");
80     }
81     shutdownHaskellAndExit(exit_status);
82 }
83 # endif /* BATCH_MODE */