[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / includes / Closures.h
1 /* ----------------------------------------------------------------------------
2  * $Id: Closures.h,v 1.2 1998/12/02 13:20:59 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 typedef struct {
117     StgHeader   header;
118     StgClosure *selectee;
119 } StgSelector;
120
121 typedef struct {
122     StgHeader   header;
123     StgWord     n_args;
124     StgClosure *fun;
125     StgPtr      payload[0];
126 } StgPAP;
127
128 typedef struct {
129     StgHeader   header;
130     StgWord     n_args;
131     StgClosure *fun;
132     StgPtr      payload[0];
133 } StgAP_UPD;
134
135 typedef struct {
136     StgHeader  header;
137     StgWord    n_ptrs;
138     StgWord    n_words;
139     StgWord    n_instrs;
140     StgPtr     payload[0];
141 } StgBCO;
142
143 typedef struct {
144     StgHeader   header;
145     StgClosure *indirectee;
146 } StgInd;
147
148 typedef struct {
149     StgHeader   header;
150     StgClosure *mut_link;
151     StgClosure *indirectee;
152 } StgIndOldGen;
153
154 typedef struct {
155     StgHeader   header;
156     StgClosure *indirectee;
157     StgClosure *static_link;
158 } StgIndStatic;
159
160 typedef struct StgCAF_ {
161     StgHeader   header;
162     StgClosure *body;
163     StgClosure *value;
164     struct StgCAF_ *link;
165 } StgCAF;
166
167 typedef struct {
168     StgHeader  header;
169     struct StgTSO_ *blocking_queue;
170 } StgBlackHole;
171
172 typedef struct {
173     StgHeader  header;
174     StgWord    words;
175     StgWord    payload[0];
176 } StgArrWords;
177
178 typedef struct {
179     StgHeader   header;
180     StgWord     ptrs;
181     StgClosure *payload[0];
182 } StgArrPtrs;
183
184 typedef struct {
185     StgHeader   header;
186     StgClosure *var;
187 } StgMutVar;
188
189 typedef struct _StgUpdateFrame {
190     StgHeader  header;
191     struct _StgUpdateFrame *link;
192     StgClosure *updatee;
193 } StgUpdateFrame;
194
195 typedef struct {
196     StgHeader  header;
197     struct _StgUpdateFrame *link;
198 } StgSeqFrame;  
199
200 typedef struct {
201     StgHeader  header;
202     struct _StgUpdateFrame *link;
203     StgClosure *handler;
204 } StgCatchFrame;
205
206 typedef struct {
207     StgHeader  header;
208 } StgStopFrame;  
209
210 typedef struct {
211     StgHeader   header;
212     StgClosure *evacuee;
213 } StgEvacuated;
214
215 typedef struct {
216   StgHeader header;
217   StgWord data;
218 } StgIntCharlikeClosure;
219
220 /* statically allocated */
221 typedef struct {
222   StgHeader  header;
223 } StgRetry;
224
225 typedef struct _StgForeignObj {
226   StgHeader      header;
227   StgAddr        data;          /* pointer to data in non-haskell-land */
228 } StgForeignObj;
229   
230 typedef struct _StgWeak {       /* Weak v */
231   StgHeader header;
232   StgClosure *key;
233   StgClosure *value;            /* v */
234   StgClosure *finaliser;
235   struct _StgWeak *link;
236 } StgWeak;
237
238 /* Dynamic stack frames - these have a liveness mask in the object
239  * itself, rather than in the info table.  Useful for generic heap
240  * check code.
241  */
242  
243 typedef struct {
244   StgHeader      header;
245   StgWord        liveness;
246   StgWord        ret_addr;
247   StgWord        payload[0];
248 } StgRetDyn;
249
250 /* Concurrent communication objects */
251
252 typedef struct {
253   StgHeader       header;
254   struct StgTSO_* head;
255   struct StgTSO_* tail;
256   StgClosure*     value;
257 } StgMVar;
258
259 /* Parallel FETCH_ME closures */
260 #ifdef PAR
261 typedef struct {
262   StgHeader    header;
263   void        *ga;              /* type globalAddr is abstract here */
264 } StgFetchMe;
265 #endif
266
267 #endif /* CLOSURES_H */