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