[project @ 1999-02-05 16:02:18 by simonm]
[ghc-hetmet.git] / ghc / includes / Closures.h
1 /* ----------------------------------------------------------------------------
2  * $Id: Closures.h,v 1.7 1999/02/05 16:02:21 simonm Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Closures
7  *
8  * -------------------------------------------------------------------------- */
9
10 #ifndef CLOSURES_H
11 #define CLOSURES_H
12
13 /*
14  * The Layout of a closure header depends on which kind of system we're
15  * compiling for: profiling, parallel, ticky, etc.
16  */
17
18 /* -----------------------------------------------------------------------------
19    The profiling header
20    -------------------------------------------------------------------------- */
21
22 #ifdef PROFILING
23
24 typedef struct {
25    CostCentreStack *ccs;
26 } StgProfHeader;
27
28 #else /* !PROFILING */
29
30 typedef struct {
31         /* empty */
32 } StgProfHeader;
33
34 #endif /* PROFILING */
35
36 /* -----------------------------------------------------------------------------
37    The parallel header
38    -------------------------------------------------------------------------- */
39
40 #ifdef GRAN
41
42 typedef struct {
43   W_ procs;
44 } StgGranHeader;
45
46 #else /* !PAR */
47
48 typedef struct {
49   /* empty */
50 } StgGranHeader;
51
52 #endif /* PAR */
53
54 /* -----------------------------------------------------------------------------
55    The ticky-ticky header
56
57    Comment from old Ticky.h:
58
59    This is used to record if a closure has been updated but not yet
60    entered. It is set when the closure is updated and cleared when
61    subsequently entered.
62    
63    NB: It is {\em not} an ``entry count'', it is an
64    ``entries-after-update count.''
65    
66    The commoning up of @CONST@, @CHARLIKE@ and @INTLIKE@ closures is
67    turned off(?) if this is required. This has only been done for 2s
68    collection.  It is done using a nasty hack which defines the
69    @_Evacuate@ and @_Scavenge@ code for @CONST@, @CHARLIKE@ and @INTLIKE@
70    info tables to be @_Evacuate_1@ and @_Scavenge_1_0@.
71    -------------------------------------------------------------------------- */
72
73 #ifdef TICKY
74
75 typedef struct {
76   W_ updated;
77 } StgTickyHeader;
78
79 #else /* !TICKY */
80
81 typedef struct {
82         /* empty */
83 } StgTickyHeader;
84
85 #endif /* TICKY */
86
87 /* -----------------------------------------------------------------------------
88    The full fixed-size closure header
89
90    The size of the fixed header is the sum of the optional parts plus a single
91    word for the entry code pointer.
92    -------------------------------------------------------------------------- */
93
94 typedef struct {
95         const struct _StgInfoTable* info;
96 #ifdef PROFILING
97         StgProfHeader         prof;
98 #endif
99 #ifdef GRAN
100         StgGranHeader         par;
101 #endif
102 #ifdef TICKY
103         StgTickyHeader        ticky;
104 #endif
105 } StgHeader;
106
107 #define FIXED_HS (sizeof(StgHeader))
108
109 /* -----------------------------------------------------------------------------
110    Closure Types
111
112    For any given closure type (defined in InfoTables.h), there is a
113    corresponding structure defined below.  The name of the structure
114    is obtained by concatenating the closure type with '_closure'
115    -------------------------------------------------------------------------- */
116
117 /* All closures follow the generic format */
118
119 typedef struct StgClosure_ {
120     StgHeader   header;
121     struct StgClosure_ *payload[0];
122 } StgClosure;
123
124 /* What a stroke of luck - all our mutable closures follow the same
125  * basic layout, with the mutable link field as the second field after
126  * the header.  This means the following structure is the supertype of
127  * mutable closures.
128  */
129
130 typedef struct StgMutClosure_ {
131     StgHeader   header;
132     StgPtr     *padding;
133     struct StgMutClosure_ *mut_link;
134     struct StgClosure_ *payload[0];
135 } StgMutClosure;
136
137 typedef struct {
138     StgHeader   header;
139     StgClosure *selectee;
140 } StgSelector;
141
142 typedef struct {
143     StgHeader   header;
144     StgWord     n_args;
145     StgClosure *fun;
146     StgPtr      payload[0];
147 } StgPAP;
148
149 typedef struct {
150     StgHeader   header;
151     StgWord     n_args;
152     StgClosure *fun;
153     StgPtr      payload[0];
154 } StgAP_UPD;
155
156 typedef struct {
157     StgHeader  header;
158     StgWord    n_ptrs;
159     StgWord    n_words;
160     StgWord    n_instrs;
161     StgPtr     payload[0];
162 } StgBCO;
163
164 typedef struct {
165     StgHeader   header;
166     StgClosure *indirectee;
167 } StgInd;
168
169 typedef struct {
170     StgHeader   header;
171     StgClosure *indirectee;
172     StgMutClosure *mut_link;
173 } StgIndOldGen;
174
175 typedef struct {
176     StgHeader   header;
177     StgClosure *indirectee;
178     StgClosure *static_link;
179 } StgIndStatic;
180
181 typedef struct StgCAF_ {
182     StgHeader   header;
183     StgClosure *body;
184     StgClosure *value;
185     struct StgCAF_ *link;
186 } StgCAF;
187
188 typedef struct {
189     StgHeader  header;
190     struct StgTSO_ *blocking_queue;
191     StgMutClosure *mut_link;
192 } StgBlockingQueue;
193
194 typedef struct {
195     StgHeader  header;
196     StgWord    words;
197     StgWord    payload[0];
198 } StgArrWords;
199
200 typedef struct {
201     StgHeader   header;
202     StgWord     ptrs;
203     StgMutClosure *mut_link;    /* mutable list */
204     StgClosure *payload[0];
205 } StgMutArrPtrs;
206
207 typedef struct {
208     StgHeader   header;
209     StgClosure *var;
210     StgMutClosure *mut_link;
211 } StgMutVar;
212
213 typedef struct _StgUpdateFrame {
214     StgHeader  header;
215     struct _StgUpdateFrame *link;
216     StgClosure *updatee;
217 } StgUpdateFrame;
218
219 typedef struct {
220     StgHeader  header;
221     struct _StgUpdateFrame *link;
222 } StgSeqFrame;  
223
224 typedef struct {
225     StgHeader  header;
226     struct _StgUpdateFrame *link;
227     StgClosure *handler;
228 } StgCatchFrame;
229
230 typedef struct {
231     StgHeader  header;
232 } StgStopFrame;  
233
234 typedef struct {
235     StgHeader   header;
236     StgClosure *evacuee;
237 } StgEvacuated;
238
239 typedef struct {
240   StgHeader header;
241   StgWord data;
242 } StgIntCharlikeClosure;
243
244 /* statically allocated */
245 typedef struct {
246   StgHeader  header;
247 } StgRetry;
248
249 typedef struct _StgForeignObj {
250   StgHeader      header;
251   StgAddr        data;          /* pointer to data in non-haskell-land */
252 } StgForeignObj;
253   
254 typedef struct _StgStableName {
255   StgHeader      header;
256   StgWord        sn;
257 } StgStableName;
258   
259 typedef struct _StgWeak {       /* Weak v */
260   StgHeader header;
261   StgClosure *key;
262   StgClosure *value;            /* v */
263   StgClosure *finaliser;
264   struct _StgWeak *link;
265 } StgWeak;
266
267 /* Dynamic stack frames - these have a liveness mask in the object
268  * itself, rather than in the info table.  Useful for generic heap
269  * check code.
270  */
271  
272 typedef struct {
273   StgHeader      header;
274   StgWord        liveness;
275   StgWord        ret_addr;
276   StgWord        payload[0];
277 } StgRetDyn;
278
279 /* Concurrent communication objects */
280
281 typedef struct {
282   StgHeader       header;
283   struct StgTSO_ *head;
284   StgMutClosure  *mut_link;
285   struct StgTSO_ *tail;
286   StgClosure*     value;
287 } StgMVar;
288
289 /* Parallel FETCH_ME closures */
290 #ifdef PAR
291 typedef struct {
292   StgHeader    header;
293   void        *ga;              /* type globalAddr is abstract here */
294 } StgFetchMe;
295 #endif
296
297 #endif /* CLOSURES_H */