Disambiguate record selectors by type signature
[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 // in a parallel setup, where we have many instances of this code
58 // running on different PEs, we should do this only for the main PE
59 // (IAmMainThread is set in startupHaskell)
60
61 // ToDo: want to start with a larger stack size
62 {
63 Capability *cap = rts_lock();
64 rts_evalLazyIO(&cap, main_closure, NULL);
65 status = rts_getSchedStatus(cap);
66 rts_unlock(cap);
67 }
68
69 // check the status of the entire Haskell computation
70 switch (status) {
71 case Killed:
72 errorBelch("main thread exited (uncaught exception)");
73 exit_status = EXIT_KILLED;
74 break;
75 case Interrupted:
76 errorBelch("interrupted");
77 exit_status = EXIT_INTERRUPTED;
78 break;
79 case HeapExhausted:
80 exit_status = EXIT_HEAPOVERFLOW;
81 break;
82 case Success:
83 exit_status = EXIT_SUCCESS;
84 break;
85 default:
86 barf("main thread completed with invalid status");
87 }
88
89 END_WINDOWS_VEH_HANDLER
90
91 shutdownHaskellAndExit(exit_status, 0 /* !fastExit */);
92 // No code beyond this point. Dead code elimination will remove it
93 }
94 # endif /* BATCH_MODE */