/* -----------------------------------------------------------------------------
- * $Id: RtsStartup.c,v 1.38 2000/04/03 15:54:50 simonmar Exp $
+ * $Id: RtsStartup.c,v 1.48 2001/02/09 13:09:16 simonmar Exp $
*
* (c) The GHC Team, 1998-2000
*
#include "StgStartup.h"
#include "Prelude.h" /* fixupRTStoPreludeRefs */
+#ifdef GHCI
+#include "HsFFI.h"
+#include "Linker.h"
+#endif
+
+#if defined(RTS_GTK_FRONTPANEL)
+#include "FrontPanel.h"
+#endif
+
#if defined(PROFILING) || defined(DEBUG)
# include "Profiling.h"
# include "ProfHeap.h"
#endif
EXTFUN(__init_Prelude);
-static void initModules ( void * );
+static void initModules ( void (*)(void) );
+
+void
+setProgArgv(int argc, char *argv[])
+{
+ /* Usually this is done by startupHaskell, so we don't need to call this.
+ However, sometimes Hugs wants to change the arguments which Haskell
+ getArgs >>= ... will be fed. So you can do that by calling here
+ _after_ calling startupHaskell.
+ */
+ prog_argc = argc;
+ prog_argv = argv;
+}
+
+void
+getProgArgv(int *argc, char **argv[])
+{
+ *argc = prog_argc;
+ *argv = prog_argv;
+}
+
void
-startupHaskell(int argc, char *argv[], void *init_root)
+startupHaskell(int argc, char *argv[], void (*init_root)(void))
{
/* To avoid repeated initialisations of the RTS */
if (rts_has_started_up)
/* The very first thing we do is grab the start time...just in case we're
* collecting timing statistics.
*/
- start_time();
+ stat_startInit();
#ifdef PAR
/*
/* initialize the storage manager */
initStorage();
+ /* initialise the object linker, if necessary */
+#ifdef GHCI
+ initLinker();
+#endif
+
/* initialise the stable pointer table */
initStablePtrTable();
#endif
/* run the per-module initialisation code */
-#if !defined(INTERPRETER)
initModules(init_root);
-#endif
#if defined(PROFILING) || defined(DEBUG)
initProfiling2();
init_default_handlers();
#endif
-#if !defined(INTERPRETER)
- /* Initialise pointers from the RTS to the prelude.
- Only for compiled code -- the interpreter
- will call this itself later, so don't do so now.
- */
- fixupRTStoPreludeRefs(NULL);
+#ifdef RTS_GTK_FRONTPANEL
+ if (RtsFlags.GcFlags.frontpanel) {
+ initFrontPanel();
+ }
#endif
/* Record initialization times */
- end_init();
+ stat_endInit();
}
/* -----------------------------------------------------------------------------
StgRun to call this stuff.
-------------------------------------------------------------------------- */
-#ifndef INTERPRETER
-
/* The init functions use an explicit stack...
*/
#define INIT_STACK_SIZE (BLOCK_SIZE * 4)
nat init_sp = 0;
static void
-initModules ( void *init_root )
+initModules ( void (*init_root)(void) )
{
- init_sp = 0;
- init_stack = (F_ *)allocate(INIT_STACK_SIZE / sizeof(W_));
- init_stack[init_sp++] = (F_)stg_init_ret;
- init_stack[init_sp++] = (F_)__init_Prelude;
- if (init_root != NULL) {
- init_stack[init_sp++] = (F_)init_root;
- }
-
- MainRegTable.rSp = (P_)(init_stack + init_sp);
- StgRun((StgFunPtr)stg_init, NULL/* no reg table */);
-}
+#ifdef SMP
+ Capability cap;
+#else
+#define cap MainRegTable
+#endif
-#endif /* !INTERPRETER */
+ init_sp = 0;
+ init_stack = (F_ *)allocate(INIT_STACK_SIZE / sizeof(W_));
+ init_stack[init_sp++] = (F_)stg_init_ret;
+ init_stack[init_sp++] = (F_)__init_Prelude;
+ if (init_root != NULL) {
+ init_stack[init_sp++] = (F_)init_root;
+ }
+
+ cap.rSp = (P_)(init_stack + init_sp);
+ StgRun((StgFunPtr)stg_init, &cap);
+}
/* -----------------------------------------------------------------------------
* Shutting down the RTS - two ways of doing this, one which
*/
exitStorage();
+#ifdef RTS_GTK_FRONTPANEL
+ if (RtsFlags.GcFlags.frontpanel) {
+ stopFrontPanel();
+ }
+#endif
+
#if defined(PROFILING) || defined(DEBUG)
endProfiling();
#endif