[project @ 1999-12-01 14:34:38 by simonmar]
[ghc-hetmet.git] / ghc / includes / Closures.h
1 /* ----------------------------------------------------------------------------
2  * $Id: Closures.h,v 1.14 1999/12/01 14:34:48 simonmar 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_TICKY
74
75 typedef struct {
76   /* old: W_ updated; */
77 } StgTickyHeader;
78
79 #else /* !TICKY_TICKY */
80
81 typedef struct {
82         /* empty */
83 } StgTickyHeader;
84
85 #endif /* TICKY_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_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     StgWord    stgexpr;
162     StgPtr     payload[0];
163 } StgBCO;
164
165 typedef struct {
166     StgHeader   header;
167     StgClosure *indirectee;
168 } StgInd;
169
170 typedef struct {
171     StgHeader   header;
172     StgClosure *indirectee;
173     StgMutClosure *mut_link;
174 } StgIndOldGen;
175
176 typedef struct {
177     StgHeader   header;
178     StgClosure *indirectee;
179     StgClosure *static_link;
180 } StgIndStatic;
181
182 typedef struct StgCAF_ {
183     StgHeader     header;
184     StgClosure    *body;
185     StgMutClosure *mut_link;
186     StgClosure    *value;
187     struct StgCAF_ *link;
188 } StgCAF;
189
190 typedef struct {
191     StgHeader  header;
192     struct StgTSO_ *blocking_queue;
193     StgMutClosure *mut_link;
194 } StgBlockingQueue;
195
196 typedef struct {
197     StgHeader  header;
198     StgWord    words;
199     StgWord    payload[0];
200 } StgArrWords;
201
202 typedef struct {
203     StgHeader   header;
204     StgWord     ptrs;
205     StgMutClosure *mut_link;    /* mutable list */
206     StgClosure *payload[0];
207 } StgMutArrPtrs;
208
209 typedef struct {
210     StgHeader   header;
211     StgClosure *var;
212     StgMutClosure *mut_link;
213 } StgMutVar;
214
215 typedef struct _StgUpdateFrame {
216     StgHeader  header;
217     struct _StgUpdateFrame *link;
218     StgClosure *updatee;
219 } StgUpdateFrame;
220
221 typedef struct {
222     StgHeader  header;
223     struct _StgUpdateFrame *link;
224 } StgSeqFrame;  
225
226 typedef struct {
227     StgHeader  header;
228     struct _StgUpdateFrame *link;
229     StgInt      exceptions_blocked;
230     StgClosure *handler;
231 } StgCatchFrame;
232
233 typedef struct {
234     StgHeader  header;
235 } StgStopFrame;  
236
237 typedef struct {
238     StgHeader   header;
239     StgClosure *evacuee;
240 } StgEvacuated;
241
242 typedef struct {
243   StgHeader header;
244   StgWord data;
245 } StgIntCharlikeClosure;
246
247 /* statically allocated */
248 typedef struct {
249   StgHeader  header;
250 } StgRetry;
251
252 typedef struct _StgForeignObj {
253   StgHeader      header;
254   StgAddr        data;          /* pointer to data in non-haskell-land */
255 } StgForeignObj;
256   
257 typedef struct _StgStableName {
258   StgHeader      header;
259   StgWord        sn;
260 } StgStableName;
261   
262 typedef struct _StgWeak {       /* Weak v */
263   StgHeader header;
264   StgClosure *key;
265   StgClosure *value;            /* v */
266   StgClosure *finalizer;
267   struct _StgWeak *link;
268 } StgWeak;
269
270 typedef struct _StgDeadWeak {   /* Weak v */
271   StgHeader header;
272   struct _StgWeak *link;
273 } StgDeadWeak;
274
275 /* Dynamic stack frames - these have a liveness mask in the object
276  * itself, rather than in the info table.  Useful for generic heap
277  * check code.
278  */
279  
280 typedef struct {
281   const struct _StgInfoTable* info;
282   StgWord        liveness;
283   StgWord        ret_addr;
284   StgWord        payload[0];
285 } StgRetDyn;
286
287 /* Concurrent communication objects */
288
289 typedef struct {
290   StgHeader       header;
291   struct StgTSO_ *head;
292   StgMutClosure  *mut_link;
293   struct StgTSO_ *tail;
294   StgClosure*     value;
295 } StgMVar;
296
297 /* Parallel FETCH_ME closures */
298 #ifdef PAR
299 typedef struct {
300   StgHeader    header;
301   void        *ga;              /* type globalAddr is abstract here */
302 } StgFetchMe;
303 #endif
304
305 #endif /* CLOSURES_H */