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[] );
47 extern void (*exitFn)(int);
49 /* ----------------------------------------------------------------------------
52 You have to surround all access to the RtsAPI with these calls.
53 ------------------------------------------------------------------------- */
55 // acquires a token which may be used to create new objects and
57 Capability *rts_lock (void);
59 // releases the token acquired with rts_lock().
60 void rts_unlock (Capability *token);
62 /* ----------------------------------------------------------------------------
63 Building Haskell objects from C datatypes.
64 ------------------------------------------------------------------------- */
65 HaskellObj rts_mkChar ( Capability *, HsChar c );
66 HaskellObj rts_mkInt ( Capability *, HsInt i );
67 HaskellObj rts_mkInt8 ( Capability *, HsInt8 i );
68 HaskellObj rts_mkInt16 ( Capability *, HsInt16 i );
69 HaskellObj rts_mkInt32 ( Capability *, HsInt32 i );
70 HaskellObj rts_mkInt64 ( Capability *, HsInt64 i );
71 HaskellObj rts_mkWord ( Capability *, HsWord w );
72 HaskellObj rts_mkWord8 ( Capability *, HsWord8 w );
73 HaskellObj rts_mkWord16 ( Capability *, HsWord16 w );
74 HaskellObj rts_mkWord32 ( Capability *, HsWord32 w );
75 HaskellObj rts_mkWord64 ( Capability *, HsWord64 w );
76 HaskellObj rts_mkPtr ( Capability *, HsPtr a );
77 HaskellObj rts_mkFunPtr ( Capability *, HsFunPtr a );
78 HaskellObj rts_mkFloat ( Capability *, HsFloat f );
79 HaskellObj rts_mkDouble ( Capability *, HsDouble f );
80 HaskellObj rts_mkStablePtr ( Capability *, HsStablePtr s );
81 HaskellObj rts_mkBool ( Capability *, HsBool b );
82 HaskellObj rts_mkString ( Capability *, char *s );
84 HaskellObj rts_apply ( Capability *, HaskellObj, HaskellObj );
86 /* ----------------------------------------------------------------------------
87 Deconstructing Haskell objects
88 ------------------------------------------------------------------------- */
89 HsChar rts_getChar ( HaskellObj );
90 HsInt rts_getInt ( HaskellObj );
91 HsInt8 rts_getInt8 ( HaskellObj );
92 HsInt16 rts_getInt16 ( HaskellObj );
93 HsInt32 rts_getInt32 ( HaskellObj );
94 HsInt64 rts_getInt64 ( HaskellObj );
95 HsWord rts_getWord ( HaskellObj );
96 HsWord8 rts_getWord8 ( HaskellObj );
97 HsWord16 rts_getWord16 ( HaskellObj );
98 HsWord32 rts_getWord32 ( HaskellObj );
99 HsWord64 rts_getWord64 ( HaskellObj );
100 HsPtr rts_getPtr ( HaskellObj );
101 HsFunPtr rts_getFunPtr ( HaskellObj );
102 HsFloat rts_getFloat ( HaskellObj );
103 HsDouble rts_getDouble ( HaskellObj );
104 HsStablePtr rts_getStablePtr ( HaskellObj );
105 HsBool rts_getBool ( HaskellObj );
107 /* ----------------------------------------------------------------------------
108 Evaluating Haskell expressions
110 The versions ending in '_' allow you to specify an initial stack size.
111 Note that these calls may cause Garbage Collection, so all HaskellObj
112 references are rendered invalid by these calls.
113 ------------------------------------------------------------------------- */
115 rts_eval (Capability *, HaskellObj p, /*out*/HaskellObj *ret);
118 rts_eval_ (Capability *, HaskellObj p, unsigned int stack_size,
119 /*out*/HaskellObj *ret);
122 rts_evalIO (Capability *, HaskellObj p, /*out*/HaskellObj *ret);
125 rts_evalStableIO (Capability *, HsStablePtr s, /*out*/HsStablePtr *ret);
128 rts_evalLazyIO (Capability *, HaskellObj p, /*out*/HaskellObj *ret);
131 rts_evalLazyIO_ (Capability *, HaskellObj p, unsigned int stack_size,
132 /*out*/HaskellObj *ret);
135 rts_checkSchedStatus (char* site, Capability *);
138 rts_getSchedStatus (Capability *cap);
140 /* --------------------------------------------------------------------------
143 These are used by foreign export and foreign import "wrapper" stubs.
144 ----------------------------------------------------------------------- */
146 extern StgWord base_GHCziTopHandler_runIO_closure[];
147 extern StgWord base_GHCziTopHandler_runNonIO_closure[];
148 #define runIO_closure base_GHCziTopHandler_runIO_closure
149 #define runNonIO_closure base_GHCziTopHandler_runNonIO_closure
151 /* ------------------------------------------------------------------------ */
157 #endif /* RTSAPI_H */