[project @ 1999-03-03 19:20:41 by sof]
[ghc-hetmet.git] / ghc / rts / Main.c
1 /* -----------------------------------------------------------------------------
2  * $Id: Main.c,v 1.6 1999/03/03 19:20:42 sof 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 "RtsFlags.h"
15 #include "Schedule.h"  /* for MainTSO */
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 /* Hack: we assume that we're building a batch-mode system unless 
33  * INTERPRETER is set
34  */
35 #ifndef INTERPRETER /* Hack */
36 int main(int argc, char *argv[])
37 {
38     SchedulerStatus status;
39     startupHaskell(argc,argv);
40
41 #ifndef PAR
42     MainTSO = createIOThread(stg_max(BLOCK_SIZE_W,
43                                      RtsFlags.GcFlags.initialStkSize),
44                              (StgClosure *)&mainIO_closure);
45     status = schedule(MainTSO,NULL);
46 #else
47     if (IAmMainThread == rtsTrue) {
48     /*Just to show we're alive */
49       fprintf(stderr, "Main Thread Started ...\n");
50      
51       MainTSO = createIOThread(stg_max(BLOCK_SIZE_W,
52                                        RtsFlags.GcFlags.initialStkSize),
53                                (StgClosure *)&mainIO_closure);
54       status = schedule(MainTSO,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     shutdownHaskell();
73     stg_exit(EXIT_SUCCESS);
74 }
75 #endif /* BATCH_MODE */