[project @ 1999-02-19 18:26:04 by sewardj]
[ghc-hetmet.git] / ghc / includes / Closures.h
1 /* ----------------------------------------------------------------------------
2  * $Id: Closures.h,v 1.9 1999/02/19 18:26:04 sewardj 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     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     StgClosure *value;
186     struct StgCAF_ *link;
187 } StgCAF;
188
189 typedef struct {
190     StgHeader  header;
191     struct StgTSO_ *blocking_queue;
192     StgMutClosure *mut_link;
193 } StgBlockingQueue;
194
195 typedef struct {
196     StgHeader  header;
197     StgWord    words;
198     StgWord    payload[0];
199 } StgArrWords;
200
201 typedef struct {
202     StgHeader   header;
203     StgWord     ptrs;
204     StgMutClosure *mut_link;    /* mutable list */
205     StgClosure *payload[0];
206 } StgMutArrPtrs;
207
208 typedef struct {
209     StgHeader   header;
210     StgClosure *var;
211     StgMutClosure *mut_link;
212 } StgMutVar;
213
214 typedef struct _StgUpdateFrame {
215     StgHeader  header;
216     struct _StgUpdateFrame *link;
217     StgClosure *updatee;
218 } StgUpdateFrame;
219
220 typedef struct {
221     StgHeader  header;
222     struct _StgUpdateFrame *link;
223 } StgSeqFrame;  
224
225 typedef struct {
226     StgHeader  header;
227     struct _StgUpdateFrame *link;
228     StgClosure *handler;
229 } StgCatchFrame;
230
231 typedef struct {
232     StgHeader  header;
233 } StgStopFrame;  
234
235 typedef struct {
236     StgHeader   header;
237     StgClosure *evacuee;
238 } StgEvacuated;
239
240 typedef struct {
241   StgHeader header;
242   StgWord data;
243 } StgIntCharlikeClosure;
244
245 /* statically allocated */
246 typedef struct {
247   StgHeader  header;
248 } StgRetry;
249
250 typedef struct _StgForeignObj {
251   StgHeader      header;
252   StgAddr        data;          /* pointer to data in non-haskell-land */
253 } StgForeignObj;
254   
255 typedef struct _StgStableName {
256   StgHeader      header;
257   StgWord        sn;
258 } StgStableName;
259   
260 typedef struct _StgWeak {       /* Weak v */
261   StgHeader header;
262   StgClosure *key;
263   StgClosure *value;            /* v */
264   StgClosure *finalizer;
265   struct _StgWeak *link;
266 } StgWeak;
267
268 /* Dynamic stack frames - these have a liveness mask in the object
269  * itself, rather than in the info table.  Useful for generic heap
270  * check code.
271  */
272  
273 typedef struct {
274   StgHeader      header;
275   StgWord        liveness;
276   StgWord        ret_addr;
277   StgWord        payload[0];
278 } StgRetDyn;
279
280 /* Concurrent communication objects */
281
282 typedef struct {
283   StgHeader       header;
284   struct StgTSO_ *head;
285   StgMutClosure  *mut_link;
286   struct StgTSO_ *tail;
287   StgClosure*     value;
288 } StgMVar;
289
290 /* Parallel FETCH_ME closures */
291 #ifdef PAR
292 typedef struct {
293   StgHeader    header;
294   void        *ga;              /* type globalAddr is abstract here */
295 } StgFetchMe;
296 #endif
297
298 #endif /* CLOSURES_H */