[project @ 1999-09-16 08:29:01 by sof]
[ghc-hetmet.git] / ghc / rts / Main.c
1 /* -----------------------------------------------------------------------------
2  * $Id: Main.c,v 1.11 1999/09/16 08:29:01 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 "SchedAPI.h"
15 #include "RtsFlags.h"
16 #include "Schedule.h"  /* for MainTSO */
17 #include "RtsUtils.h"
18
19 #ifdef DEBUG
20 #include "Printer.h"   /* for printing        */
21 #endif
22
23 #ifdef INTERPRETER
24 #include "Assembler.h"
25 #endif
26
27 #ifdef PAR
28 #include "ParInit.h"
29 #include "Parallel.h"
30 #include "LLC.h"
31 #endif
32
33 #ifdef HAVE_WINDOWS_H
34 #include <windows.h>
35 #endif
36
37
38 /* Hack: we assume that we're building a batch-mode system unless 
39  * INTERPRETER is set
40  */
41 # ifndef INTERPRETER /* Hack */
42 int main(int argc, char *argv[])
43 {
44     SchedulerStatus status;
45     startupHaskell(argc,argv);
46
47 #  ifndef PAR
48     MainTSO = createIOThread(stg_max(BLOCK_SIZE_W,
49                                      RtsFlags.GcFlags.initialStkSize),
50                              (StgClosure *)&mainIO_closure);
51     status = schedule(MainTSO,NULL);
52 #  else
53     if (IAmMainThread == rtsTrue) {
54     /*Just to show we're alive */
55       fprintf(stderr, "Main Thread Started ...\n");
56      
57       MainTSO = createIOThread(stg_max(BLOCK_SIZE_W,
58                                        RtsFlags.GcFlags.initialStkSize),
59                                (StgClosure *)&mainIO_closure);
60       status = schedule(MainTSO,NULL);
61     } else {
62       WaitForPEOp(PP_FINISH,SysManTask);
63       exit(EXIT_SUCCESS);
64     }
65 #  endif /* PAR */
66     switch (status) {
67     case AllBlocked:
68       barf("Scheduler stopped, all threads blocked");
69     case Deadlock:
70       shutdownHaskell();
71       barf("No threads to run!  Deadlock?");
72     case Killed:
73       belch("%s: warning: main thread killed", prog_argv[0]);
74     case Success:
75     case Interrupted:
76       /* carry on */
77     }
78     shutdownHaskellAndExit(EXIT_SUCCESS);
79 }
80 # endif /* BATCH_MODE */