[project @ 1999-05-11 16:47:39 by keithw]
[ghc-hetmet.git] / ghc / includes / Closures.h
1 /* ----------------------------------------------------------------------------
2  * $Id: Closures.h,v 1.13 1999/05/11 16:47:40 keithw 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     StgClosure *handler;
230 } StgCatchFrame;
231
232 typedef struct {
233     StgHeader  header;
234 } StgStopFrame;  
235
236 typedef struct {
237     StgHeader   header;
238     StgClosure *evacuee;
239 } StgEvacuated;
240
241 typedef struct {
242   StgHeader header;
243   StgWord data;
244 } StgIntCharlikeClosure;
245
246 /* statically allocated */
247 typedef struct {
248   StgHeader  header;
249 } StgRetry;
250
251 typedef struct _StgForeignObj {
252   StgHeader      header;
253   StgAddr        data;          /* pointer to data in non-haskell-land */
254 } StgForeignObj;
255   
256 typedef struct _StgStableName {
257   StgHeader      header;
258   StgWord        sn;
259 } StgStableName;
260   
261 typedef struct _StgWeak {       /* Weak v */
262   StgHeader header;
263   StgClosure *key;
264   StgClosure *value;            /* v */
265   StgClosure *finalizer;
266   struct _StgWeak *link;
267 } StgWeak;
268
269 typedef struct _StgDeadWeak {   /* Weak v */
270   StgHeader header;
271   struct _StgWeak *link;
272 } StgDeadWeak;
273
274 /* Dynamic stack frames - these have a liveness mask in the object
275  * itself, rather than in the info table.  Useful for generic heap
276  * check code.
277  */
278  
279 typedef struct {
280   const struct _StgInfoTable* info;
281   StgWord        liveness;
282   StgWord        ret_addr;
283   StgWord        payload[0];
284 } StgRetDyn;
285
286 /* Concurrent communication objects */
287
288 typedef struct {
289   StgHeader       header;
290   struct StgTSO_ *head;
291   StgMutClosure  *mut_link;
292   struct StgTSO_ *tail;
293   StgClosure*     value;
294 } StgMVar;
295
296 /* Parallel FETCH_ME closures */
297 #ifdef PAR
298 typedef struct {
299   StgHeader    header;
300   void        *ga;              /* type globalAddr is abstract here */
301 } StgFetchMe;
302 #endif
303
304 #endif /* CLOSURES_H */