Main.c 1.9 KB
Newer Older
1
/* -----------------------------------------------------------------------------
2
 * $Id: Main.c,v 1.13 2000/01/13 12:40:15 simonmar Exp $
3 4
 *
 * (c) The GHC Team 1998-1999
5 6 7 8 9
 *
 * Main function for a standalone Haskell program.
 *
 * ---------------------------------------------------------------------------*/

sof's avatar
sof committed
10 11
#define COMPILING_RTS_MAIN

12 13
#include "Rts.h"
#include "RtsAPI.h"
sof's avatar
sof committed
14
#include "SchedAPI.h"
15
#include "RtsFlags.h"
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include "RtsUtils.h"

#ifdef DEBUG
#include "Printer.h"   /* for printing        */
#endif

#ifdef INTERPRETER
#include "Assembler.h"
#endif

#ifdef PAR
#include "ParInit.h"
#include "Parallel.h"
#include "LLC.h"
#endif

sof's avatar
sof committed
32 33 34 35 36
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif


37 38 39
/* Hack: we assume that we're building a batch-mode system unless 
 * INTERPRETER is set
 */
sof's avatar
sof committed
40
# ifndef INTERPRETER /* Hack */
41 42
int main(int argc, char *argv[])
{
43 44
    int exit_status;

45 46 47
    SchedulerStatus status;
    startupHaskell(argc,argv);

sof's avatar
sof committed
48
#  ifndef PAR
49 50
    /* ToDo: want to start with a larger stack size */
    status = rts_evalIO((StgClosure *)&mainIO_closure, NULL);
sof's avatar
sof committed
51
#  else
52 53 54 55
    if (IAmMainThread == rtsTrue) {
    /*Just to show we're alive */
      fprintf(stderr, "Main Thread Started ...\n");
     
56
      status = rts_evalIO((StgClosure *)&mainIO_closure, NULL);
57 58 59 60
    } else {
      WaitForPEOp(PP_FINISH,SysManTask);
      exit(EXIT_SUCCESS);
    }
sof's avatar
sof committed
61
#  endif /* PAR */
62 63
    switch (status) {
    case Deadlock:
64 65 66
      prog_belch("no threads to run:  infinite loop or deadlock?");
      exit_status = EXIT_DEADLOCK;
      break;
67
    case Killed:
68 69 70
      prog_belch("main thread killed");
      exit_status = EXIT_KILLED;
      break;
71
    case Interrupted:
72 73 74 75 76 77 78 79
      prog_belch("interrupted");
      exit_status = EXIT_INTERRUPTED;
      break;
    case Success:
      exit_status = EXIT_SUCCESS;
      break;
    case NoStatus:
      barf("main thread completed with no status");
80
    }
81
    shutdownHaskellAndExit(exit_status);
82
}
sof's avatar
sof committed
83
# endif /* BATCH_MODE */