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