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