From c108d3f61b1a5fefa8e15aa6ada4ff547bcbb4e5 Mon Sep 17 00:00:00 2001 From: simonmar Date: Thu, 30 Mar 2000 12:03:31 +0000 Subject: [PATCH] [project @ 2000-03-30 12:03:30 by simonmar] HEADS UP!!! change the type of startupHaskell(): void startupHaskell ( int argc, char *argv[], void *init_root ); the extra parameter is a pointer to the initialisation function for the root module in the program. eg., Main.c now passes __init_Main for this parameter. It can be left as NULL if there is no root module. This interface may need to be revised, since in some circumstances there may be more than one "root module". Sigbjorn: H/Direct will need some changes to stay in sync here. --- ghc/includes/RtsAPI.h | 4 ++-- ghc/rts/Main.c | 5 +++-- ghc/rts/RtsStartup.c | 24 +++++++++++++++--------- ghc/rts/StgStartup.hc | 14 +++++++------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/ghc/includes/RtsAPI.h b/ghc/includes/RtsAPI.h index b6d5df7..81a43db 100644 --- a/ghc/includes/RtsAPI.h +++ b/ghc/includes/RtsAPI.h @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- - * $Id: RtsAPI.h,v 1.9 2000/01/13 12:40:15 simonmar Exp $ + * $Id: RtsAPI.h,v 1.10 2000/03/30 12:03:31 simonmar Exp $ * * (c) The GHC Team, 1998-1999 * @@ -26,7 +26,7 @@ typedef StgClosure *HaskellObj; /* ---------------------------------------------------------------------------- Starting up and shutting down the Haskell RTS. ------------------------------------------------------------------------- */ -extern void startupHaskell ( int argc, char *argv[] ); +extern void startupHaskell ( int argc, char *argv[], void *init_root ); extern void shutdownHaskell ( void ); extern void shutdownHaskellAndExit ( int exitCode ); diff --git a/ghc/rts/Main.c b/ghc/rts/Main.c index e5e00c7..86d4ac9 100644 --- a/ghc/rts/Main.c +++ b/ghc/rts/Main.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: Main.c,v 1.18 2000/03/14 09:55:05 simonmar Exp $ + * $Id: Main.c,v 1.19 2000/03/30 12:03:30 simonmar Exp $ * * (c) The GHC Team 1998-2000 * @@ -38,6 +38,7 @@ # include #endif +EXTFUN(__init_Main); /* Hack: we assume that we're building a batch-mode system unless * INTERPRETER is set @@ -49,7 +50,7 @@ int main(int argc, char *argv[]) SchedulerStatus status; /* all GranSim/GUM init is done in startupHaskell; sets IAmMainThread! */ - startupHaskell(argc,argv); + startupHaskell(argc,argv,__init_Main); /* kick off the computation by creating the main thread with a pointer to mainIO_closure representing the computation of the overall program; diff --git a/ghc/rts/RtsStartup.c b/ghc/rts/RtsStartup.c index 3a2b472..62258f2 100644 --- a/ghc/rts/RtsStartup.c +++ b/ghc/rts/RtsStartup.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: RtsStartup.c,v 1.35 2000/03/21 14:33:18 simonmar Exp $ + * $Id: RtsStartup.c,v 1.36 2000/03/30 12:03:30 simonmar Exp $ * * (c) The GHC Team, 1998-2000 * @@ -49,10 +49,11 @@ static int rts_has_started_up = 0; static ullong startTime = 0; #endif -static void initModules ( void ); +EXTFUN(__init_Prelude); +static void initModules ( void * ); void -startupHaskell(int argc, char *argv[]) +startupHaskell(int argc, char *argv[], void *init_root) { /* To avoid repeated initialisations of the RTS */ if (rts_has_started_up) @@ -131,7 +132,7 @@ startupHaskell(int argc, char *argv[]) /* run the per-module initialisation code */ #if !defined(INTERPRETER) - initModules(); + initModules(init_root); #endif #if defined(PROFILING) || defined(DEBUG) @@ -200,16 +201,21 @@ startupHaskell(int argc, char *argv[]) /* The init functions use an explicit stack... */ #define INIT_STACK_SIZE (BLOCK_SIZE * 4) -F_ *init_stack; +F_ *init_stack = NULL; +nat init_sp = 0; static void -initModules ( void ) +initModules ( void *init_root ) { - /* this storage will be reclaimed by the garbage collector, - * as a large block. - */ + 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 */); } diff --git a/ghc/rts/StgStartup.hc b/ghc/rts/StgStartup.hc index 40f1198..c8e5465 100644 --- a/ghc/rts/StgStartup.hc +++ b/ghc/rts/StgStartup.hc @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: StgStartup.hc,v 1.9 2000/03/21 14:33:18 simonmar Exp $ + * $Id: StgStartup.hc,v 1.10 2000/03/30 12:03:30 simonmar Exp $ * * (c) The GHC Team, 1998-1999 * @@ -146,15 +146,15 @@ STGFUN(stg_init_ret) FE_ } +/* On entry to stg_init: + * init_stack[0] = &stg_init_ret; + * init_stack[1] = __init_Something; + */ STGFUN(stg_init) { - EF_(__init_PrelMain); - EF_(__init_Prelude); FB_ - Sp = (P_)init_stack; - PUSH_INIT_STACK(stg_init_ret); - PUSH_INIT_STACK(__init_Prelude); - JMP_(__init_PrelMain); + Sp = MainRegTable.rSp; + JMP_(POP_INIT_STACK()); FE_ } -- 1.7.10.4