Fix -Werror build failure in RtsMain
[ghc.git] / rts / RtsMain.c
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team 1998-2000
4 *
5 * Main function for a standalone Haskell program.
6 *
7 * ---------------------------------------------------------------------------*/
8
9 #define COMPILING_RTS_MAIN
10
11 #include "PosixSource.h"
12 #include "Rts.h"
13 #include "RtsAPI.h"
14
15 #include "RtsUtils.h"
16 #include "Prelude.h"
17 #include "Task.h"
18 #include "Excn.h"
19
20 #ifdef DEBUG
21 # include "Printer.h" /* for printing */
22 #endif
23
24 // Hack: we assume that we're building a batch-mode system unless
25 // INTERPRETER is set
26
27 #ifndef INTERPRETER /* Hack */
28
29 // The rts entry point from a compiled program using a Haskell main
30 // function. This gets called from a tiny main function generated by
31 // GHC and linked into each compiled Haskell program that uses a
32 // Haskell main function.
33 //
34 // We expect the caller to pass ZCMain_main_closure for
35 // main_closure. The reason we cannot refer to this symbol directly
36 // is because we're inside the rts and we do not know for sure that
37 // we'll be using a Haskell main function.
38 //
39 // NOTE: This function is marked as _noreturn_ in Main.h
40
41 int hs_main ( int argc, char *argv[], // program args
42 StgClosure *main_closure, // closure for Main.main
43 RtsConfig rts_config) // RTS configuration
44
45 {
46 BEGIN_WINDOWS_VEH_HANDLER
47
48 int exit_status;
49 SchedulerStatus status;
50
51 hs_init_ghc(&argc, &argv, rts_config);
52
53 // kick off the computation by creating the main thread with a pointer
54 // to mainIO_closure representing the computation of the overall program;
55 // then enter the scheduler with this thread and off we go;
56 //
57 // the same for GranSim (we have only one instance of this code)
58 //
59 // in a parallel setup, where we have many instances of this code
60 // running on different PEs, we should do this only for the main PE
61 // (IAmMainThread is set in startupHaskell)
62
63 // ToDo: want to start with a larger stack size
64 {
65 Capability *cap = rts_lock();
66 rts_evalLazyIO(&cap, main_closure, NULL);
67 status = rts_getSchedStatus(cap);
68 rts_unlock(cap);
69 }
70
71 // check the status of the entire Haskell computation
72 switch (status) {
73 case Killed:
74 errorBelch("main thread exited (uncaught exception)");
75 exit_status = EXIT_KILLED;
76 break;
77 case Interrupted:
78 errorBelch("interrupted");
79 exit_status = EXIT_INTERRUPTED;
80 break;
81 case HeapExhausted:
82 exit_status = EXIT_HEAPOVERFLOW;
83 break;
84 case Success:
85 exit_status = EXIT_SUCCESS;
86 break;
87 default:
88 barf("main thread completed with invalid status");
89 }
90
91 END_WINDOWS_VEH_HANDLER
92
93 shutdownHaskellAndExit(exit_status, 0 /* !fastExit */);
94 // No code beyond this point. Dead code elimination will remove it
95 }
96 # endif /* BATCH_MODE */