[project @ 1999-01-13 17:25:37 by simonm]
[ghc-hetmet.git] / ghc / includes / Closures.h
1 /* ----------------------------------------------------------------------------
2  * $Id: Closures.h,v 1.3 1999/01/13 17:25:53 simonm 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         StgProfHeader         prof;
95         StgGranHeader         par;
96         StgTickyHeader        ticky;
97 } StgHeader;
98
99 #define FIXED_HS (sizeof(StgHeader))
100
101 /* -----------------------------------------------------------------------------
102    Closure Types
103
104    For any given closure type (defined in InfoTables.h), there is a
105    corresponding structure defined below.  The name of the structure
106    is obtained by concatenating the closure type with '_closure'
107    -------------------------------------------------------------------------- */
108
109 /* All closures follow the generic format */
110
111 typedef struct StgClosure_ {
112     StgHeader   header;
113     struct StgClosure_ *payload[0];
114 } StgClosure;
115
116 /* What a stroke of luck - all our mutable closures follow the same
117  * basic layout, with the mutable link field as the second field after
118  * the header.  This means the following structure is the supertype of
119  * mutable closures.
120  */
121
122 typedef struct StgMutClosure_ {
123     StgHeader   header;
124     StgPtr     *padding;
125     struct StgMutClosure_ *mut_link;
126     struct StgClosure_ *payload[0];
127 } StgMutClosure;
128
129 typedef struct {
130     StgHeader   header;
131     StgClosure *selectee;
132 } StgSelector;
133
134 typedef struct {
135     StgHeader   header;
136     StgWord     n_args;
137     StgClosure *fun;
138     StgPtr      payload[0];
139 } StgPAP;
140
141 typedef struct {
142     StgHeader   header;
143     StgWord     n_args;
144     StgClosure *fun;
145     StgPtr      payload[0];
146 } StgAP_UPD;
147
148 typedef struct {
149     StgHeader  header;
150     StgWord    n_ptrs;
151     StgWord    n_words;
152     StgWord    n_instrs;
153     StgPtr     payload[0];
154 } StgBCO;
155
156 typedef struct {
157     StgHeader   header;
158     StgClosure *indirectee;
159 } StgInd;
160
161 typedef struct {
162     StgHeader   header;
163     StgClosure *indirectee;
164     StgMutClosure *mut_link;
165 } StgIndOldGen;
166
167 typedef struct {
168     StgHeader   header;
169     StgClosure *indirectee;
170     StgClosure *static_link;
171 } StgIndStatic;
172
173 typedef struct StgCAF_ {
174     StgHeader   header;
175     StgClosure *body;
176     StgClosure *value;
177     struct StgCAF_ *link;
178 } StgCAF;
179
180 typedef struct {
181     StgHeader  header;
182     struct StgTSO_ *blocking_queue;
183 } StgBlackHole;
184
185 typedef struct {
186     StgHeader  header;
187     StgWord    words;
188     StgWord    payload[0];
189 } StgArrWords;
190
191 typedef struct {
192     StgHeader   header;
193     StgWord     ptrs;
194     StgMutClosure *mut_link;    /* mutable list */
195     StgClosure *payload[0];
196 } StgMutArrPtrs;
197
198 typedef struct {
199     StgHeader   header;
200     StgClosure *var;
201     StgMutClosure *mut_link;
202 } StgMutVar;
203
204 typedef struct _StgUpdateFrame {
205     StgHeader  header;
206     struct _StgUpdateFrame *link;
207     StgClosure *updatee;
208 } StgUpdateFrame;
209
210 typedef struct {
211     StgHeader  header;
212     struct _StgUpdateFrame *link;
213 } StgSeqFrame;  
214
215 typedef struct {
216     StgHeader  header;
217     struct _StgUpdateFrame *link;
218     StgClosure *handler;
219 } StgCatchFrame;
220
221 typedef struct {
222     StgHeader  header;
223 } StgStopFrame;  
224
225 typedef struct {
226     StgHeader   header;
227     StgClosure *evacuee;
228 } StgEvacuated;
229
230 typedef struct {
231   StgHeader header;
232   StgWord data;
233 } StgIntCharlikeClosure;
234
235 /* statically allocated */
236 typedef struct {
237   StgHeader  header;
238 } StgRetry;
239
240 typedef struct _StgForeignObj {
241   StgHeader      header;
242   StgAddr        data;          /* pointer to data in non-haskell-land */
243 } StgForeignObj;
244   
245 typedef struct _StgWeak {       /* Weak v */
246   StgHeader header;
247   StgClosure *key;
248   StgClosure *value;            /* v */
249   StgClosure *finaliser;
250   struct _StgWeak *link;
251 } StgWeak;
252
253 /* Dynamic stack frames - these have a liveness mask in the object
254  * itself, rather than in the info table.  Useful for generic heap
255  * check code.
256  */
257  
258 typedef struct {
259   StgHeader      header;
260   StgWord        liveness;
261   StgWord        ret_addr;
262   StgWord        payload[0];
263 } StgRetDyn;
264
265 /* Concurrent communication objects */
266
267 typedef struct {
268   StgHeader       header;
269   struct StgTSO_ *head;
270   StgMutClosure  *mut_link;
271   struct StgTSO_ *tail;
272   StgClosure*     value;
273 } StgMVar;
274
275 /* Parallel FETCH_ME closures */
276 #ifdef PAR
277 typedef struct {
278   StgHeader    header;
279   void        *ga;              /* type globalAddr is abstract here */
280 } StgFetchMe;
281 #endif
282
283 #endif /* CLOSURES_H */