1 /* ----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2004
5 * API for invoking Haskell functions via the RTS
7 * --------------------------------------------------------------------------*/
19 * Running the scheduler
22 NoStatus, /* not finished yet */
23 Success, /* completed successfully */
24 Killed, /* uncaught exception */
25 Interrupted /* stopped in response to a call to interruptStgRts */
28 typedef StgClosure *HaskellObj;
31 * An abstract type representing the token returned by rts_lock() and
32 * used when allocating objects and threads in the RTS.
34 typedef struct Capability_ Capability;
36 /* ----------------------------------------------------------------------------
37 Starting up and shutting down the Haskell RTS.
38 ------------------------------------------------------------------------- */
39 extern void startupHaskell ( int argc, char *argv[],
40 void (*init_root)(void) );
41 extern void shutdownHaskell ( void );
42 extern void shutdownHaskellAndExit ( int exitCode );
43 extern void getProgArgv ( int *argc, char **argv[] );
44 extern void setProgArgv ( int argc, char *argv[] );
45 extern void getFullProgArgv ( int *argc, char **argv[] );
46 extern void setFullProgArgv ( int argc, char *argv[] );
48 #ifndef mingw32_HOST_OS
49 extern void shutdownHaskellAndSignal (int sig);
53 extern void (*exitFn)(int);
55 /* ----------------------------------------------------------------------------
58 You have to surround all access to the RtsAPI with these calls.
59 ------------------------------------------------------------------------- */
61 // acquires a token which may be used to create new objects and
63 Capability *rts_lock (void);
65 // releases the token acquired with rts_lock().
66 void rts_unlock (Capability *token);
68 /* ----------------------------------------------------------------------------
69 Building Haskell objects from C datatypes.
70 ------------------------------------------------------------------------- */
71 HaskellObj rts_mkChar ( Capability *, HsChar c );
72 HaskellObj rts_mkInt ( Capability *, HsInt i );
73 HaskellObj rts_mkInt8 ( Capability *, HsInt8 i );
74 HaskellObj rts_mkInt16 ( Capability *, HsInt16 i );
75 HaskellObj rts_mkInt32 ( Capability *, HsInt32 i );
76 HaskellObj rts_mkInt64 ( Capability *, HsInt64 i );
77 HaskellObj rts_mkWord ( Capability *, HsWord w );
78 HaskellObj rts_mkWord8 ( Capability *, HsWord8 w );
79 HaskellObj rts_mkWord16 ( Capability *, HsWord16 w );
80 HaskellObj rts_mkWord32 ( Capability *, HsWord32 w );
81 HaskellObj rts_mkWord64 ( Capability *, HsWord64 w );
82 HaskellObj rts_mkPtr ( Capability *, HsPtr a );
83 HaskellObj rts_mkFunPtr ( Capability *, HsFunPtr a );
84 HaskellObj rts_mkFloat ( Capability *, HsFloat f );
85 HaskellObj rts_mkDouble ( Capability *, HsDouble f );
86 HaskellObj rts_mkStablePtr ( Capability *, HsStablePtr s );
87 HaskellObj rts_mkBool ( Capability *, HsBool b );
88 HaskellObj rts_mkString ( Capability *, char *s );
90 HaskellObj rts_apply ( Capability *, HaskellObj, HaskellObj );
92 /* ----------------------------------------------------------------------------
93 Deconstructing Haskell objects
94 ------------------------------------------------------------------------- */
95 HsChar rts_getChar ( HaskellObj );
96 HsInt rts_getInt ( HaskellObj );
97 HsInt8 rts_getInt8 ( HaskellObj );
98 HsInt16 rts_getInt16 ( HaskellObj );
99 HsInt32 rts_getInt32 ( HaskellObj );
100 HsInt64 rts_getInt64 ( HaskellObj );
101 HsWord rts_getWord ( HaskellObj );
102 HsWord8 rts_getWord8 ( HaskellObj );
103 HsWord16 rts_getWord16 ( HaskellObj );
104 HsWord32 rts_getWord32 ( HaskellObj );
105 HsWord64 rts_getWord64 ( HaskellObj );
106 HsPtr rts_getPtr ( HaskellObj );
107 HsFunPtr rts_getFunPtr ( HaskellObj );
108 HsFloat rts_getFloat ( HaskellObj );
109 HsDouble rts_getDouble ( HaskellObj );
110 HsStablePtr rts_getStablePtr ( HaskellObj );
111 HsBool rts_getBool ( HaskellObj );
113 /* ----------------------------------------------------------------------------
114 Evaluating Haskell expressions
116 The versions ending in '_' allow you to specify an initial stack size.
117 Note that these calls may cause Garbage Collection, so all HaskellObj
118 references are rendered invalid by these calls.
119 ------------------------------------------------------------------------- */
121 rts_eval (Capability *, HaskellObj p, /*out*/HaskellObj *ret);
124 rts_eval_ (Capability *, HaskellObj p, unsigned int stack_size,
125 /*out*/HaskellObj *ret);
128 rts_evalIO (Capability *, HaskellObj p, /*out*/HaskellObj *ret);
131 rts_evalStableIO (Capability *, HsStablePtr s, /*out*/HsStablePtr *ret);
134 rts_evalLazyIO (Capability *, HaskellObj p, /*out*/HaskellObj *ret);
137 rts_evalLazyIO_ (Capability *, HaskellObj p, unsigned int stack_size,
138 /*out*/HaskellObj *ret);
141 rts_checkSchedStatus (char* site, Capability *);
144 rts_getSchedStatus (Capability *cap);
146 /* --------------------------------------------------------------------------
149 These are used by foreign export and foreign import "wrapper" stubs.
150 ----------------------------------------------------------------------- */
152 extern StgWord base_GHCziTopHandler_runIO_closure[];
153 extern StgWord base_GHCziTopHandler_runNonIO_closure[];
154 #define runIO_closure base_GHCziTopHandler_runIO_closure
155 #define runNonIO_closure base_GHCziTopHandler_runNonIO_closure
157 /* ------------------------------------------------------------------------ */
163 #endif /* RTSAPI_H */