1 /* ----------------------------------------------------------------------------
2 * $Id: RtsAPI.h,v 1.34 2003/02/06 09:56:07 simonmar Exp $
4 * (c) The GHC Team, 1998-1999
6 * API for invoking Haskell functions via the RTS
8 * --------------------------------------------------------------------------*/
20 * Running the scheduler
23 NoStatus, /* not finished yet */
24 Success, /* completed successfully */
25 Killed, /* uncaught exception */
26 Interrupted /* stopped in response to a call to interruptStgRts */
29 typedef StgClosure *HaskellObj;
31 /* ----------------------------------------------------------------------------
32 Starting up and shutting down the Haskell RTS.
33 ------------------------------------------------------------------------- */
34 extern void startupHaskell ( int argc, char *argv[],
35 void (*init_root)(void) );
36 extern void shutdownHaskell ( void );
37 extern void shutdownHaskellAndExit ( int exitCode );
38 extern void getProgArgv ( int *argc, char **argv[] );
39 extern void setProgArgv ( int argc, char *argv[] );
42 /* ----------------------------------------------------------------------------
45 In a multithreaded environments, you have to surround all access to the
46 RtsAPI with these calls.
47 ------------------------------------------------------------------------- */
55 /* ----------------------------------------------------------------------------
56 Building Haskell objects from C datatypes.
57 ------------------------------------------------------------------------- */
58 HaskellObj rts_mkChar ( HsChar c );
59 HaskellObj rts_mkInt ( HsInt i );
60 HaskellObj rts_mkInt8 ( HsInt8 i );
61 HaskellObj rts_mkInt16 ( HsInt16 i );
62 HaskellObj rts_mkInt32 ( HsInt32 i );
63 HaskellObj rts_mkInt64 ( HsInt64 i );
64 HaskellObj rts_mkWord ( HsWord w );
65 HaskellObj rts_mkWord8 ( HsWord8 w );
66 HaskellObj rts_mkWord16 ( HsWord16 w );
67 HaskellObj rts_mkWord32 ( HsWord32 w );
68 HaskellObj rts_mkWord64 ( HsWord64 w );
69 HaskellObj rts_mkPtr ( HsPtr a );
70 HaskellObj rts_mkFunPtr ( HsFunPtr a );
71 HaskellObj rts_mkFloat ( HsFloat f );
72 HaskellObj rts_mkDouble ( HsDouble f );
73 HaskellObj rts_mkStablePtr ( HsStablePtr s );
74 HaskellObj rts_mkBool ( HsBool b );
75 HaskellObj rts_mkString ( char *s );
77 HaskellObj rts_apply ( HaskellObj, HaskellObj );
79 /* ----------------------------------------------------------------------------
80 Deconstructing Haskell objects
81 ------------------------------------------------------------------------- */
82 HsChar rts_getChar ( HaskellObj );
83 HsInt rts_getInt ( HaskellObj );
84 HsInt8 rts_getInt8 ( HaskellObj );
85 HsInt16 rts_getInt16 ( HaskellObj );
86 HsInt32 rts_getInt32 ( HaskellObj );
87 HsInt64 rts_getInt64 ( HaskellObj );
88 HsWord rts_getWord ( HaskellObj );
89 HsWord8 rts_getWord8 ( HaskellObj );
90 HsWord16 rts_getWord16 ( HaskellObj );
91 HsWord32 rts_getWord32 ( HaskellObj );
92 HsWord64 rts_getWord64 ( HaskellObj );
93 HsPtr rts_getPtr ( HaskellObj );
94 HsFunPtr rts_getFunPtr ( HaskellObj );
95 HsFloat rts_getFloat ( HaskellObj );
96 HsDouble rts_getDouble ( HaskellObj );
97 HsStablePtr rts_getStablePtr ( HaskellObj );
98 HsBool rts_getBool ( HaskellObj );
100 /* ----------------------------------------------------------------------------
101 Evaluating Haskell expressions
103 The versions ending in '_' allow you to specify an initial stack size.
104 Note that these calls may cause Garbage Collection, so all HaskellObj
105 references are rendered invalid by these calls.
106 ------------------------------------------------------------------------- */
108 rts_eval ( HaskellObj p, /*out*/HaskellObj *ret );
111 rts_eval_ ( HaskellObj p, unsigned int stack_size, /*out*/HaskellObj *ret );
114 rts_evalIO ( HaskellObj p, /*out*/HaskellObj *ret );
116 #if defined(COMPILING_RTS_MAIN)
117 /* Used by the RTS' main() only */
119 rts_mainEvalIO ( HaskellObj p, /*out*/HaskellObj *ret );
123 rts_evalStableIO ( HsStablePtr s, /*out*/HsStablePtr *ret );
126 rts_evalLazyIO ( HaskellObj p, unsigned int stack_size, /*out*/HaskellObj *ret );
129 rts_checkSchedStatus ( char* site, SchedulerStatus rc);
131 /* --------------------------------------------------------------------------
134 These are used by foreign export and foreign import "wrapper" stubs.
135 ----------------------------------------------------------------------- */
137 extern StgClosure GHCziTopHandler_runIO_closure;
138 extern StgClosure GHCziTopHandler_runNonIO_closure;
139 #define runIO_closure (&GHCziTopHandler_runIO_closure)
140 #define runNonIO_closure (&GHCziTopHandler_runNonIO_closure)
142 /* ------------------------------------------------------------------------ */
148 #endif /* RTSAPI_H */