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