[project @ 1996-01-11 14:06:51 by partain]
[ghc-hetmet.git] / ghc / includes / SMClosures.lh
1 %************************************************************************
2 %*                                                                      *
3 \section[closure-layout]{Closure Layout}
4 %*                                                                      *
5 %************************************************************************
6
7 We first describes the data structures that are shared by
8 both the reducer and storage manager and then go on to describe
9 the interface and its implementation.
10
11 The heap consists of a contiguous sequence of closures. Each standard
12 closure occupies a contiguous sequence of machine words, which is laid
13 out as follows:
14
15 \begin{rawlatex}
16 \begin{center}
17 \mbox{\epsffile{closure.ps}}
18 \end{center}
19 \end{rawlatex}
20
21 \begin{onlyinfo}
22 \begin{verbatim}
23 < fixed-hdr-size> < var-hdr-size  >
24 -----------------+-----------------+---------+-------------+
25 |info|     |     |     |     |     | ptrs... | nonptrs ... |
26 -----------------+-----------------+---------+-------------+
27 <------------- header ------------>
28 \end{verbatim}
29 \end{onlyinfo}
30
31 The closure starts with a header. Typically, the first word in the
32 header is the {\em info pointer}, and points to its {\em info-table}.
33 The rest of the header is used for bookkeeping and depends on the
34 compiler options used. The fixed header is the same for all closures
35 while the variable header may depend on the closure type.
36
37 Following the header is a block of words each of which contains a
38 pointer to another closure, followed by a block of words containing
39 non-pointers. The non-pointers may include an unused portion of
40 ``slop'' needed to pad the closure.  This is to satisfy any minimum
41 closure size requirements, primarily for updates in place.  The
42 distinction between the pointers and non-pointers is that the garbage
43 collector must follow the former but not the latter.  The pointers are
44 placed first to mimimize the number of distinct closure shapes that
45 have to be managed by the garbage collector.
46
47 There are a few non-standard closures which do not follow the convention
48 of placing all pointers first, but they are all administrative closures
49 which require their own unique garbage collection code anyway (such as
50 @TSO@'s and @STKO@'s in the threaded world).
51
52 The heap grows upwards (towards higher addresses), and closures are
53 laid out with the info pointer at the lowest address.
54
55 During reduction, the heap pointer (@Hp@) points to the last word of
56 allocated space (and not to the first word of free space) and the heap
57 limit (@HpLim@) points to the last word of available space.
58
59 %************************************************************************
60 %*                                                                      *
61 \subsection[closure-size]{The ``Size'' of Closures}
62 %*                                                                      *
63 %************************************************************************
64
65 When we speak of the ``size'' of a closure, we mean {\em the number of
66 words in the closure, excluding the fixed header, but including the
67 variable header, the pointers, non-pointers and slop, if any}.
68
69 All closures which may be updated must have a size of at least
70 @MIN_UPD_SIZE@---currently, this is two, so that they may be directly
71 overwritten with a small constructor closure, such as a @(:)@ cell or
72 an indirection on the ``mutables'' list.
73
74 %************************************************************************
75 %*                                                                      *
76 \subsection[closure-kinds]{Types of Closure}
77 %*                                                                      *
78 %************************************************************************
79
80 {\em This section is now hopelessly out-of-date}.  This stuff is {\em
81 important} if you want newcomers to understand GHC.  Am I the only
82 person who bothers with documentation?! KH
83
84 Yes, Kevin, you are.  I've taken a stab at this section.  I think {\em
85 hopelessly out-of-date} is a bit overboard, especially compared to
86 some of the other documentation in this system.  If you still don't
87 like it, you're welcome to update it.
88
89 (Umm... Before we update it, would anyone like to go for a pizza?
90 [WDP 95/03])
91
92 We identify several kinds of heap closures. Each type of closure
93 is treated differently by the storage manager. Different
94 info-table macros are used to declare the appropriate info-tables used
95 by the storage manager (see section \ref{info-table-macros}).
96
97 Note: it is vitally important that every closure has an appropriate
98 info-table attached---otherwise chaos results!
99
100 \begin{description}
101
102 \item[@SPEC@ closures:] These are standard closures which contain
103 specialized garbage collection code that ``knows'' the @size@/@ptrs@
104 of the closure. It is only possible to use a specialized info-table if
105 appropriately specialized garbage collection code is present in the
106 runtime system. This implies that the compiler needs to know which
107 @size@/@ptr@ combinations have specialized info-tables. A link-time
108 error results if the compiler attempts to build a @SPEC@ closure for
109 an inappropriate @size@/@ptr@ combination.
110
111 \item[@GEN@ closures:] These are normal closures which use generic
112 code for garbage collection. This interprets the @size@/@ptrs@
113 information stored in the info table. @GEN@ closures can be built for
114 any @size@/@ptrs@ combination.
115
116 \item[@DYN@ closures:] Dynamic closures have the layout information
117 (@size@/@ptrs@) stored within the variable header of the closure
118 itself. They are currently only used for partial applications (@PAP@s)
119 and the ``stable pointer table.''
120 %partain:\begin{center}
121 \begin{tabular}{|c|c|c|c|c|c|}
122 \hline
123 {\em Fixed Hdr} & {\em Size} & {\em No of ptrs} & {\em Pointers\ldots} & {\em Non-pointers\ldots}       \\ \hline
124 \end{tabular}
125 %partain:\end{center}
126
127 \item[@TUPLE@ closure:] These are similar to @DYN@ closures but for
128 closures which contain only pointers.  They are currently used for
129 primitive arrays of pointers when mutuples and immutuples do not have
130 to be distinguished during garbage collection.
131 %partain:\begin{center}
132 \begin{tabular}{|c|c|c|c|}
133 \hline
134 {\em Fixed Hdr} & {\em Size (= No of ptrs + TUPLE\_VHS)} & {\em Pointers\ldots} \\ \hline
135 \end{tabular}
136 %partain:\end{center}
137
138 \item[@DATA@ closures:] These are also similar to @DYN@ closures but
139 for closures containing only non-pointers. They are currently used for
140 primitive arrays of bytes (arbitrary precision integers and arrays of
141 unboxed values, for example).
142 %partain:\begin{center}
143 \begin{tabular}{|c|c|c|}
144 \hline
145 {\em Fixed Hdr} & {\em Size (= No of non-ptr words + DATA\_VHS)} & {\em Non-pointers\ldots} \\ \hline
146 \end{tabular}
147 %partain:\end{center}
148
149 \item[@MUTUPLE@ closures:] These are a variant of the @TUPLE@
150 closure. They are used when the garbage collection strategy requires a
151 distinction between mutable and immutable tuples (i.e. when there is a
152 ``mutables'' list.)  Such an array may be frozen, becoming an @IMMUTUPLE@,
153 with a different info-table.
154 %partain:\begin{center}
155 \begin{tabular}{|c|c|c|c|}
156 \hline
157 {\em Fixed Hdr} & {\em Size (= No of ptrs + MUTUPLE\_VHS)} & {\em Pointers\ldots} \\ \hline
158 \end{tabular}
159 %partain:\end{center}
160
161 \item[@IMMUTUPLE@ closures:] These are frozen @MUTUPLE@ closures.
162 %mattson:\begin{center}
163 \begin{tabular}{|c|c|c|c|}
164 \hline
165 {\em Fixed Hdr} & {\em Size (= No of ptrs + MUTUPLE\_VHS)} & {\em Pointers\ldots} \\ \hline
166 \end{tabular}
167 %mattson:\end{center}
168
169 \end{description}
170
171 %************************************************************************
172 %*                                                                      *
173 \subsection[special-closure-types]{Special types}
174 %*                                                                      *
175 %************************************************************************
176
177 Special kinds of closures are required for static closures, ``black
178 holes'', indirections, and in-place updates.
179
180 When a ``black hole'' is updated it must be updated with a closure of
181 size @MIN_UPD_SIZE@ or less.  Updates to some specific closure types
182 are handled specially, as follows:
183
184 \begin{itemize}
185 \item
186 if the new closure is of zero arity, then the black hole is replaced by
187 the corresponding static closure (@CONST@);
188 \item
189 if the data type of the new closure is isomorphic to Char (one
190 constructor, with argument type @Char#@), then the black hole is
191 replaced by the corresponding member of the static character table
192 (@CHARLIKE@);
193 \item
194 if the data type of the new closure is isomorphic to Int (one
195 constructor, with argument type @Int#@), and the argument is in the
196 range of the static small-int table then the black hole is replaced by
197 the corresponding member of the integer table (@INTLIKE@).
198 \end{itemize}   
199
200 The special kinds of closure are:
201
202 \begin{description}
203
204 \item[@STATIC@ closures:] These are closures which are declared
205 statically and hence do not reside in the heap. Such closures must not
206 contain any heap pointers and must not be updated.  @CAF@ closures are
207 an exception; see below.
208
209 \item[@CONST@ closures:] There need be only one (static) closure for a
210 nullary constructor. These are declared static at compile time and all
211 references use the static closure (avoiding heap allocation). However,
212 dynamic heap-allocated ones will nevertheless arise through updates.
213
214 \item[@CHARLIKE@ and @INTLIKE@ closures] There is a similar story for
215 constructors which have a single primitive data field such as @Int#@
216 or @Char#@. During garbage collection, pointers to these closures can
217 be replaced with a known @STATIC@ closure if an appropriate one exists.
218
219 \item[@BH@ closures:] Black hole closures are used to overwrite
220 closures currently being evaluated. They inform the garbage collector
221 that there are no live roots in the closure, thus removing a potential
222 space leak.  They also become synchronization points in the threaded
223 world.
224
225 \item[@BQ@ closures:] Blocking queue closures are black holes with a
226 list of blocked threads to be awakened when the black hole is updated.
227
228 \item[@IND@ closures:] Indirection closures just point to other
229 closures. They are introduced when a closure is updated with a closure
230 that has to be allocated in the heap. The closure to be updated is
231 {\em indirected} to the new closure.  Indirections are normally
232 removed during garbage collection.  However, when profiling, it may be
233 necessary to maintain cost center information in an indirection, so
234 there are also ``permanent indirections'' which are retained forever.
235
236 \item[@CAF@ indirections:] These are statically defined closures which have
237 been updated with a heap-allocated result.
238 Initially these are exactly the same as a @STATIC@ closure but with
239 special entry code. On entering the closure the entry code must:
240 \begin{itemize}
241 \item Allocate a black hole in the heap which will be updated with
242       the result.
243 \item Overwrite the static closure with a special @CAF@ indirection.
244
245 \item Link the static indirection onto the list of updated @CAF@s.
246 \end{itemize}
247 The indirection and the link field require the initial @STATIC@
248 closure to be of at least size @MIN_UPD_SIZE@ (excluding the fixed
249 header).
250
251 @CAF@s are treated as special garbage collection roots.  These roots
252 are explicitly collected by the garbage collector, since they may
253 appear in code even if they are not linked with the main heap.  They
254 consequently represent potentially enormous space-leaks.  A @CAF@
255 closure retains a fixed location in statically allocated data space.
256 When updated, the contents of the @CAF@ indirection are changed to
257 reflect the new closure. @CAF@ indirections require special garbage
258 collection code.
259
260 \item[@FETCHME@ closures:] These are simply references to remote
261 objects in the parallel system.
262
263 \item[@TSO@ closures:] These are ``thread state objects,'' which are
264 used in the threaded world to maintain the context (STG registers,
265 PC location when asleep, etc.) for individual threads of computation.
266
267 \item[@STKO@ closures:] These are ``stack objects,'' which are
268 used in the threaded world as the stack for each thread is allocated
269 from the heap in smallish chunks.  (The stack in the sequential world
270 is allocated outside of the heap.)
271
272 \item[@SPEC_RBH@ and @GEN_RBH@ closures:] These are ``revertible black
273 holes'' for updatable @SPEC@ (respectively @GEN@) closures.  They are
274 currently used in the parallel system, but they could also be used for
275 speculation.  They act like a black hole for thread synchronization,
276 but they can also be reverted back to the original @SPEC@
277 (respectively @GEN@) form (so they do introduce a space leak).
278
279 \end{description}
280
281 %************************************************************************
282 %*                                                                      *
283 \subsection[closure-layout-macros]{Closure layout macros}
284 %*                                                                      *
285 %************************************************************************
286
287 \begin{description}
288 \item[@FIXED_HS@:]
289 This is the number of fixed-header words present in every closures.
290 This includes the info pointer---always the first word---and any
291 other fixed info.  Because this name occurs so often, @_FHS@ is used as
292 a shorthand form.
293
294 \item[@SET_FIXED_HDR(closure, infolbl, costcentre)@:] Initialize the
295 fixed-header part of @closure@, putting @infolbl@ into the first word
296 (where the info-table pointer normally lives). Note that @infolbl@
297 should be the name of the appropriate info-table. If we are profiling
298 on a sequential machine, then the cost centre will be placed in the
299 second word of the fixed header.
300
301 \item[@<closure-kind>_VHS@:]
302 This is the number of words in the variable part of the header.  This
303 includes the @size@ and/or @ptr@ fields if required for this closure
304 type, and any words which are reserved for garbage collection.
305
306 @SPEC@, @CONST@, @CHARLIKE@, @INTLIKE@, @BH@ and @IND@ do
307 not have variable header parts, hence no @<closure-kind>_VHS@ macro is
308 defined for any of these closure types.
309
310 \item[@SET_<closure-kind>_HDR(closure,infolbl,costcentre,size,no-of-ptrs)@:]
311 This is used to initialize the header of a \tr{<closure-kind>} closure.
312 The fixed header is set by using @SET_FIXED_HDR(closure,infolbl,costcentre)@
313 macro.
314
315 The variable part of the header, if present, uses the
316 @size@/@ptrs@ fields.  The @size@ should {\em include} any slop
317 words in the closure.  Any field that is not used may be junk.
318
319 The fields actually used depend on the type of the closure (other
320 fields are ignored):
321
322 %partain:\begin{center}
323 \begin{tabular}{|l|l|} \hline
324 Closure     & Fields Used                              \\ \hline
325             &                                          \\
326 \tr{SPEC}   & size/nonptrs fields ignored              \\
327 \tr{GEN}    & both fields also ignored                 \\
328 \tr{DYN}    & both fields used                         \\
329 \tr{TUPLE}  & size used (ptrs = size - \tr{TUPLE_VHS}) \\
330 \tr{DATA}   & size used (ptrs = 0)                      \\\hline
331 \end{tabular}
332 %partain:\end{center}
333
334 \item[@<closure-kind>_HS@:]
335 Total number of words in the header:
336
337 \pl{TOT_HDR = FIXED_HDR + VAR_HDR}.
338
339 \item[@<closure-kind>_CLOSURE_SIZE(closure)@:]
340 Returns the size of a closure of this kind.  This includes any @VAR_HDR@
341 words and slop---but excludes the @FIXED_HDR@ words.
342
343 \item[@<closure-kind>_CLOSURE_NoPTRS(closure)@:]
344 Returns the number of closure pointer words in a closure of this kind.
345
346 \item[@<closure-kind>_CLOSURE_NoNONPTRS(closure)@:]
347 Returns the number of useful non-pointer words (including slop) in a
348 closure of this kind.  These follow the pointer words in the closure;
349 \pl{NoNONPTRS = SIZE - NoPTRS - VAR_HDR}.
350
351 \item[@<closure-kind>_CLOSURE_PTR(closure,nth)@:]
352 Returns the $n$th closure pointer in the closure (starting at 1).
353
354 If a loop needs to process all the pointers and non-pointers in a closure then
355 this macro should be avoided. Instead, have a pointer run over the closure;
356 for example (from @StgUpdate.lhc@):
357 \begin{pseudocode}
358 { P_ p = PapClosure + FIXED_HS + DYN_VHS;
359   I_ NPtrWords = DYN_CLOSURE_NoPTRS(Node);
360   I_ NNonPtrWords = DYN_CLOSURE_NoNONPTRS(Node);
361   for (i=0; i<NPtrWords;    i++) SpA[AREL(i)] = *(p++);
362   for (i=0; i<NNonPtrWords; i++) SpB[BREL(i)] = *(p++);
363 }
364 \end{pseudocode}
365
366 \end{description}
367
368
369 %************************************************************************
370 %*                                                                      *
371 \subsection[SMinterface.h-implementation]{Interface implementation}
372 %*                                                                      *
373 %************************************************************************
374
375 This section details the implementation of the storage manager
376 interface.
377
378 NB: Heap objects specific to parallel implementations are not defined
379 here, but in \tr{Parallel.lh} instead.
380
381 %************************************************************************
382 %*                                                                      *
383 \subsubsection[common-to-all-closures]{Bits common to all closures (esp. @FIXED_HS@)}
384 %*                                                                      *
385 %************************************************************************
386
387 The maximum number of pointers in a generic closure (@GEN@, @DYN@,
388 @TUPLE@, @DATA@) is defined here.
389
390 Multi-slurp protection:
391 \begin{code}
392 #ifndef SMClosures_H
393 #define SMClosures_H
394 \end{code}
395
396 Macros to make rep-table names:
397 If you change either of these, change .../nativeGen/StixInfo.lhs
398 too---or else!
399 \begin{code}
400
401 #define MK_REP_LBL(n,s,p)       CAT6(n,_,s,_,p,_rtbl)
402 #define MK_REP_REF(n,s,p)       CAT6(n,_,s,_,p,_rtbl)
403
404 \end{code}
405
406 At the start of a closure is a fixed header. The info-pointer is
407 normally the first word of a closure, in the fixed header.  Following
408 this we may have any of (but occuring in this order): parallel words
409 (currently a global address); profiling words (currently a cost
410 centre).  It is possible to change the ordering of fixed header
411 components by changing the @_HDR_POSN@ macros in the appropriate
412 files, and the @SET_FIXED_HDR@/@SET_STATIC_FIXED_HDR@ macros below.
413
414 The @FIXED_HS@, @SET_FIXED_HDR@ macros and the components
415 which are used to define them must all be defined consistently.
416
417 \begin{code}
418
419 #define FIXED_HS (INFO_FIXED_HDR + PAR_FIXED_HDR + PROF_FIXED_HDR + TICKY_FIXED_HDR)
420
421 /* NB: this *defines* the intended order for the pieces of 
422    the fixed header.  Care should be taken to ensure that this
423    is followed below and in the component headers.
424 */
425
426 #define _FHS                    FIXED_HS /* shorthand */
427
428 #define SET_FIXED_HDR(closure,infolbl,costcentre)       \
429         SET_INFO_PTR(closure,infolbl);                  \
430         SET_GRAN_HDR(closure,ThisPE);                   \
431         SET_PAR_HDR(closure,LOCAL_GA);                  \
432         SET_PROF_HDR(closure,costcentre);               \
433         SET_TICKY_HDR(closure,0)
434
435 #define UPD_FIXED_HDR(closure,infolbl,costcentre)       \
436         SET_INFO_PTR(closure,infolbl);                  \
437         SET_PROF_HDR(closure,costcentre);               \
438         SET_TICKY_HDR(closure,1)
439         /* fiddling SET_PAR_HDR would be a bug (says Patrick) */
440         /* We set ticky-hdr to 1 because the only place we
441            use this macro is when we have just done an update
442            (WDP 96/01)
443         */
444
445 /* These items are comma-separated */
446
447 #define SET_STATIC_FIXED_HDR(closure,infolbl,cc_ident)  \
448         SET_STATIC_INFO_PTR(infolbl)                    \
449         SET_STATIC_PROCS(closure)                       \
450         SET_STATIC_PAR_HDR(closure)                     \
451         SET_STATIC_PROF_HDR(cc_ident)                   \
452         SET_STATIC_TICKY_HDR()
453
454 \end{code}
455
456 We define @MIN_UPD_SIZE@ to be the minimum size for updatable
457 closures. This must be at least 2, to allow for @(:)@ cells and
458 indirections on the ``mutables'' list. This is defined in
459 \tr{GhcConstants.lh}.
460
461 All updates are performed on closures of this size so @BH@ and @IND@
462 closures all have this size.
463
464 Finally we define the number of words that the storage-manager needs
465 to reserve in the variable header for mutable closures:
466
467 \begin{code}
468 #if defined(GCap) || defined(GCgn)
469 # define GC_MUT_REQUIRED
470 # define GC_MUT_RESERVED_WORDS          1
471 # define MUT_NOT_LINKED                 1 /* Assuming 1 is not a valid pointer */
472 # define MUT_LINK(closure)              (((P_)(closure))[FIXED_HS])
473 # define SET_MUT_RESERVED_WORDS(closure) MUT_LINK(closure) = MUT_NOT_LINKED
474 # define SET_STATIC_MUT_RESERVED_WORDS  , (W_) MUT_NOT_LINKED
475 #else
476 # define GC_MUT_RESERVED_WORDS          0
477 # define SET_STATIC_MUT_RESERVED_WORDS
478 #endif
479 \end{code}
480
481
482 %************************************************************************
483 %*                                                                      *
484 \subsubsection[SPEC-closures]{@SPEC@ (specialized) closure macros}
485 %*                                                                      *
486 %************************************************************************
487
488 @SPEC@ closures have no variable header size---it is always 0.
489 @SPEC_VHS@ is left undefined, so that if anyone tries to use it,
490 they will hear about it soon enough (WDP 95/05).
491
492 \begin{code}
493 #define SPEC_HS         (FIXED_HS)
494
495 #define SPEC_SIZE(fields) (FIXED_HS + (fields))
496                         /*notational convenience; in SMscan.lc + elsewhere */
497
498 #define SPEC_CLOSURE_PTR(closure, no)   (((P_)(closure))[SPEC_HS + (no) - 1])
499 #define SPEC_CLOSURE_SIZE(closure)      ((W_)INFO_SIZE(INFO_PTR(closure)))
500 #define SPEC_CLOSURE_NoPTRS(closure)    ((W_)INFO_NoPTRS(INFO_PTR(closure)))
501 #define SPEC_CLOSURE_NoNONPTRS(closure) (SPEC_CLOSURE_SIZE(closure)-SPEC_CLOSURE_NoPTRS(closure)/*-SPEC_VHS*/)
502
503 #define SET_SPEC_HDR(closure,infolbl,cc,size,ptrs) \
504                                         SET_FIXED_HDR(closure,infolbl,cc)
505 \end{code}
506
507 %************************************************************************
508 %*                                                                      *
509 \subsubsection[MallocPtr-closures]{@MallocPtr@ closure macros}
510 %*                                                                      *
511 %************************************************************************
512
513 Here's what a MallocPtr looks like:
514
515 \begin{verbatim}
516             <Var  Hdr> 
517 +----------+----------+------+------+
518 | Info Ptr | Forward  | Data | List |
519 +----------+----------+------+------+
520 \end{verbatim}
521
522 The list is a pointer to the next MallocPtr in the list of all
523 MallocPtrs.  Note that it is essential that the garbage collector {\em
524 not\/} follow this link but that the link must get updated with the
525 new address.
526
527 The optional @Forward@ field is used by copying collectors to insert
528 the forwarding pointer into.  (If we overwrite the @Data@ part, we
529 don't know which MallocPtr has just died; if we overwrite the @List@ part,
530 we can't traverse the list of all MallocPtrs.)
531
532 \begin{code}
533 #if !defined(PAR)
534
535 # if defined(_INFO_COPYING)
536 #  define MallocPtr_VHS                         1
537 # else
538 #  define MallocPtr_VHS                         0
539 # endif
540
541 # define MallocPtr_HS                   (FIXED_HS + MallocPtr_VHS)
542 # define MallocPtr_SIZE                 (MallocPtr_VHS + 2)
543
544 # define MallocPtr_CLOSURE_NoPTRS(closure)  0
545 # define MallocPtr_CLOSURE_DATA(closure)    (((StgMallocPtr *)(closure))[MallocPtr_HS + 0])
546 # define MallocPtr_CLOSURE_LINK(closure)    (((StgPtrPtr) (closure))[MallocPtr_HS + 1])
547
548 # define SET_MallocPtr_HDR(closure,infolbl,cc,size,ptrs) \
549                                         SET_FIXED_HDR(closure,infolbl,cc)
550 \end{code}
551
552 And to check that a Malloc ptr closure is valid
553
554 \begin{code}
555 EXTDATA_RO(MallocPtr_info);
556
557 # if defined(DEBUG)
558
559 #  define CHECK_MallocPtr_CLOSURE( closure ) \
560 do {                                       \
561   CHECK_MallocPtr_InfoTable( closure );    \
562 } while (0)
563
564 #  define CHECK_MallocPtr_InfoTable( closure ) \
565   ASSERT( (*((PP_)(closure))) == MallocPtr_info )
566
567 extern void Validate_MallocPtrList( P_ MPlist );
568 #  define VALIDATE_MallocPtrList( mplist ) Validate_MallocPtrList( mplist )
569
570 # else /* !DEBUG */
571
572 #  define CHECK_MallocPtr_CLOSURE( closure ) /* nothing */
573 #  define VALIDATE_MallocPtrList( mplist ) /* nothing */
574
575 # endif /* !DEBUG */
576 #endif /* !PAR */
577 \end{code}
578
579 %************************************************************************
580 %*                                                                      *
581 \subsubsection[SP-table-closures]{@SPTable@ Stable Pointer Table closure macros}
582 %*                                                                      *
583 %************************************************************************
584
585
586 A stable pointer is a name for a Haskell object which can be passed to
587 the external world.  It is ``stable'' in the sense that the name does
588 not change when the Haskell garbage collector runs---in contrast to
589 the address of the object which may well change.
590
591 The stable pointer type is parameterized by the type of the thing
592 which is named.
593
594 \begin{verbatim}
595 type StablePtr# a
596 \end{verbatim}
597
598 A stable pointer is represented by an index into the (unique,
599 heap-allocated) @StablePointerTable@.  The Haskell garbage collector
600 treats the @StablePointerTable@ as a source of roots for GC.
601
602 In order to provide efficient access to stable pointers and to be able
603 to cope with any number of stable pointers ($0 \ldots 100000$), the
604 table of stable pointers is an array stored on the heap and can grow
605 when it overflows.  (Since we cannot compact the table by moving
606 stable pointers about, it seems unlikely that a half-empty table can
607 be reduced in size---this could be fixed if neccessary by using a
608 hash table of some sort.)
609
610 In general a stable pointer table closure looks like this:
611
612 \begin{verbatim}
613 <------------header--------------->
614 +------+------------+------+-------+---+---+---+-----+-----+--+--+--+----+
615 | Info | GCReserved | Size | NPtrs |SP0|SP1|...|SPn-1| Top |s0|s1|..|sn-1|
616 +------+------------+------+-------+---+---+---+-----+-----+--+--+--+----+
617 \end{verbatim}
618
619 The fields are:
620 \begin{description}
621
622 \item[@Size@:] number of words excluding fixed header ($= @DYN_VHS@ + @NPtrs@ + 1 + @NPtrs@$)
623
624 \item[@NPtrs@:] number of (stable) pointers.
625
626 \item[@SPi@:] ``unstable'' pointer to a closure.  This is the pointer
627 that gets updated when the garbage collector moves an object we have a
628 stable pointer to.  If the pointer is not in use, it points to a
629 static closure.
630
631 \item[@si@:] entry in a stack of unused pointers.  Entries in
632 use will contain a number in the range $0\ldots n-1$.
633
634 \item[@Top@] is the index of the first element above the top of the stack.
635
636 \end{description}
637
638 For example, with $n = 4$ and pointers @0@ and @3@ in use (pointing to
639 @p1@ and @p2@ respectively), the table might look like this:
640
641 \begin{verbatim}
642 +------+----+---+----+---+---+----+---+---+---+---+---+
643 | Info | 11 | 4 | p1 | x | x | p2 | 2 | 2 | 1 | ? | ? |
644 +------+----+---+----+---+---+----+---+---+---+---+---+
645                                    +-----------^
646 \end{verbatim}
647
648 From the above description, it should be clear that this is just a
649 special case of a @DYN@ closure.  However, a few macros to access the
650 various fields would be jolly useful.
651
652 Nota Bene: one might think that since the table is mutable, we'd need
653 to treat it a bit more like a @MUTUPLE@.  This isn't necessary because
654 we treat the stable pointer table as a root.
655
656 \begin{code}
657 #if !defined(PAR)
658 \end{code}
659
660 \begin{code}
661 # define SPT_SIZE(closure)         DYN_CLOSURE_SIZE(closure)
662 # define SPT_NoPTRS(closure)       DYN_CLOSURE_NoPTRS(closure)
663 # define SPT_TOP(closure)          (((I_ *) closure)[DYN_HS + SPT_NoPTRS(closure)])
664 # define SPT_SPTR(closure,index)   (((PP_) closure)[DYN_HS + index])
665 # define SPT_FREE(closure,index)   (((I_ *) closure)[DYN_HS + SPT_NoPTRS(closure) + 1 + index])
666 \end{code}
667
668 And to implement the stack:
669
670 \begin{code}
671 # define SPT_FULL(closure)         (SPT_TOP(closure) == SPT_NoPTRS(closure))
672 # define SPT_EMPTY(closure)        (SPT_TOP(closure) == 0)
673
674 # define SPT_PUSH(closure,free)    SPT_FREE(closure,SPT_TOP(closure)++) = free
675 # define SPT_POP(closure)          SPT_FREE(closure,--SPT_TOP(closure))
676 \end{code}
677
678 And to check that an SPT_Closure is what it's supposed to be, we check
679 that the size and number of pointers match up and we check that the
680 free list and sptr areas are consistent.  
681
682 Note that we cannot always check the info table since we might be
683 halfway through garbage collection when we call these (eg in
684 @freeStablePointer@.
685
686 \begin{code}
687 # if defined(DEBUG)
688
689 #  define CHECK_SPT_CLOSURE( closure ) \
690 do {                                 \
691   CHECK_SPT_InfoTable( closure );    \
692   CHECK_SPT_Size( closure );         \
693   CHECK_SPT_Contents( closure );     \
694 } while (0)
695
696 EXTDATA_RO(StablePointerTable_info);
697 EXTDATA_RO(EmptyStablePointerTable_info);
698 EXTDATA(EmptySPTable_closure);
699 extern int ValidateSPTable PROTO(( P_ SPTable ));
700
701 #  define CHECK_SPT_InfoTable( closure ) \
702   ASSERT( (*((PP_) (closure)) == EmptyStablePointerTable_info && (closure == EmptySPTable_closure) ) || \
703           (*((PP_) (closure)) == StablePointerTable_info) )
704
705 #  define CHECK_SPT_Size( closure ) \
706   ASSERT( SPT_SIZE( closure ) == DYN_VHS + 2 * SPT_NoPTRS( closure ) + 1 )
707
708 #  define CHECK_SPT_Contents( closure ) \
709   ASSERT( ValidateSPTable( closure ) == 0 )
710
711 # else
712
713 #  define CHECK_SPT_InfoTable( closure ) /* nothing */
714 #  define CHECK_SPT_Contents( closure ) /* nothing */
715 #  define CHECK_SPT_Size( closure ) /* nothing */
716 #  define CHECK_SPT_CLOSURE( closure ) /* nothing */
717
718 # endif /* DEBUG */
719 #endif  /* !PAR */
720 \end{code}
721
722 %************************************************************************
723 %*                                                                      *
724 \subsubsection[GEN-closures]{@GEN@ (generic) closure macros}
725 %*                                                                      *
726 %************************************************************************
727
728 \begin{code}
729 #define GEN_VHS         0
730 #define GEN_HS          (FIXED_HS + GEN_VHS)
731
732 #define GEN_N_VHS       GEN_VHS
733 #define GEN_N_HS        GEN_HS
734
735 #define GEN_S_VHS       GEN_VHS
736 #define GEN_S_HS        GEN_HS
737
738 #define GEN_U_VHS       GEN_VHS
739 #define GEN_U_HS        GEN_HS
740
741 #define GEN_CLOSURE_SIZE(closure)       GEN_INFO_SIZE(INFO_PTR(closure))
742 #define GEN_CLOSURE_NoPTRS(closure)     GEN_INFO_NoPTRS(INFO_PTR(closure))
743
744 #define GEN_CLOSURE_NoNONPTRS(closure)  (GEN_CLOSURE_SIZE(closure) - GEN_CLOSURE_NoPTRS(closure) - GEN_VHS) 
745 #define GEN_CLOSURE_PTR(closure, no)    (((P_)(closure))[GEN_HS + (no) - 1])
746
747 #define SET_GEN_HDR(closure,infolbl,cc,size,ptrs) SET_FIXED_HDR(closure,infolbl,cc)
748 \end{code}
749
750 %************************************************************************
751 %*                                                                      *
752 \subsubsection[DYN-closures]{@DYN@ (dynamic) closure macros}
753 %*                                                                      *
754 %************************************************************************
755
756 For dynamic closures (with both pointers and data stored within the closure).
757
758 \begin{code}
759 #define DYN_VHS                 2
760 #define DYN_HS                  (FIXED_HS + DYN_VHS)
761
762 #define DYN_CLOSURE_SIZE(closure)       (((P_)(closure))[FIXED_HS])
763 #define DYN_CLOSURE_NoPTRS(closure)     (((P_)(closure))[FIXED_HS + 1])
764
765 #define DYN_CLOSURE_NoNONPTRS(closure)  (DYN_CLOSURE_SIZE(closure) - DYN_CLOSURE_NoPTRS(closure) - DYN_VHS)
766 #define DYN_CLOSURE_PTR(closure, no)    (((P_)(closure))[DYN_HS + (no) - 1])
767
768 #define SET_DYN_HDR(closure,infolbl,cc,size,ptrs) \
769         { SET_FIXED_HDR(closure,infolbl,cc);    \
770           DYN_CLOSURE_NoPTRS(closure) = (W_)(ptrs); \
771           DYN_CLOSURE_SIZE(closure) = (W_)(size); }
772 \end{code}
773
774 %************************************************************************
775 %*                                                                      *
776 \subsubsection[TUPLE-closures]{@TUPLE@ (big purely-pointer) closure macros}
777 %*                                                                      *
778 %************************************************************************
779
780 For tuple closures (which contain only pointers after the variable header).
781
782 \begin{code}
783 #define TUPLE_VHS               1
784 #define TUPLE_HS                (FIXED_HS + TUPLE_VHS)
785
786 #define TUPLE_CLOSURE_SIZE(closure)     (((P_)(closure))[FIXED_HS])
787
788 #define TUPLE_CLOSURE_NoPTRS(closure)   (TUPLE_CLOSURE_SIZE(closure) - TUPLE_VHS)
789 #define TUPLE_CLOSURE_NoNONPTRS(closure) 0L
790 #define TUPLE_CLOSURE_PTR(closure, no)  (((P_)(closure))[TUPLE_HS + (no) - 1])
791
792 #define SET_TUPLE_HDR(closure,infolbl,cc,size,ptrs) \
793         { SET_FIXED_HDR(closure,infolbl,cc);    \
794           TUPLE_CLOSURE_SIZE(closure) = (W_)(size); }
795 \end{code}
796
797 %************************************************************************
798 %*                                                                      *
799 \subsubsection[DATA-closures]{@DATA@ (big purely non-pointer) closure macros}
800 %*                                                                      *
801 %************************************************************************
802
803 For data closures (which contain only raw data (no pointers) after the
804 variable header):
805
806 \begin{code}
807 #define DATA_VHS        1
808 #define DATA_HS         (FIXED_HS + DATA_VHS)
809
810 #define DATA_CLOSURE_SIZE(closure)      (((P_)(closure))[FIXED_HS])
811
812 #define DATA_CLOSURE_NoPTRS(closure)    ((I_)0)
813 #define DATA_CLOSURE_NoNONPTRS(closure) (DATA_CLOSURE_SIZE(closure) - DATA_VHS)
814
815 #define SET_DATA_HDR(closure,infolbl,cc,size,ptrs/*==0*/)       \
816         { SET_FIXED_HDR(closure,infolbl,cc);                    \
817           DATA_CLOSURE_SIZE(closure) = (W_)(size); }
818 \end{code}
819
820
821 %************************************************************************
822 %*                                                                      *
823 \subsubsection[MUTUPLE-closures]{@MUTUPLE@ (mutable pointer) closure macros}
824 %*                                                                      *
825 %************************************************************************
826
827 Mutable closures of pointers have to be treated specially for the
828 benefit of generational garbage collection schemes. If the garbage
829 collection scheme does not need to treat them specially
830 @GC_MUT_REQUIRED@ is undefined and the closures are defined
831 identical to @TUPLE@ closures.
832
833 \begin{code}
834
835 #if defined(GC_MUT_REQUIRED)
836
837 # define MUTUPLE_VHS            (1 + GC_MUT_RESERVED_WORDS)
838 # define MUTUPLE_HS             (FIXED_HS + MUTUPLE_VHS)
839
840 # define MUTUPLE_CLOSURE_SIZE(closure)    (((P_)(closure))[FIXED_HS + GC_MUT_RESERVED_WORDS])
841
842 # define MUTUPLE_CLOSURE_NoPTRS(closure)    (MUTUPLE_CLOSURE_SIZE(closure) - MUTUPLE_VHS)
843 # define MUTUPLE_CLOSURE_NoNONPTRS(closure) 0L
844 # define MUTUPLE_CLOSURE_PTR(closure, no)   (((P_)(closure))[MUTUPLE_HS + (no) - 1])
845
846 # define SET_MUTUPLE_HDR(closure,infolbl,cc,size,ptrs) \
847         { SET_FIXED_HDR(closure,infolbl,cc);    \
848           SET_MUT_RESERVED_WORDS(closure);      \
849           MUTUPLE_CLOSURE_SIZE(closure) = (W_)(size); }
850
851 #else   /* ! GC_MUT_REQUIRED---define as TUPLE closure */
852
853 # define MUTUPLE_VHS TUPLE_VHS
854 # define MUTUPLE_HS  TUPLE_HS   
855 # define MUTUPLE_CLOSURE_SIZE(closure)      TUPLE_CLOSURE_SIZE(closure)
856 # define MUTUPLE_CLOSURE_NoPTRS(closure)    TUPLE_CLOSURE_NoPTRS(closure)
857 # define MUTUPLE_CLOSURE_NoNONPTRS(closure) TUPLE_CLOSURE_NoNONPTRS(closure)
858 # define MUTUPLE_CLOSURE_PTR(closure, no)   TUPLE_CLOSURE_PTR(closure, no)
859 # define SET_MUTUPLE_HDR(closure,infolbl,cc,size,ptrs) \
860          SET_TUPLE_HDR(closure,infolbl,cc,size,ptrs)
861 #endif
862
863 \end{code}
864
865 %************************************************************************
866 %*                                                                      *
867 \subsubsection[STATIC-closures]{@STATIC@ closure macros}
868 %*                                                                      *
869 %************************************************************************
870
871 Static closures are those that are allocated in text/data space at
872 compile time (i.e., not in dynamic heap).  The odd-looking macro
873 @SET_STATIC_HDR@ depends on the compiler to cooperate---it must drop
874 in the closure free-variable words and the concluding @};@!  Also note
875 that the info-table label is a ``base'' label.
876
877 @SET_STATIC_HDR@ is for SPEC-layout closures.
878
879 \begin{code}
880 #define STATIC_VHS              0
881 #define STATIC_HS               (FIXED_HS)
882
883 #define STATIC_CLOSURE_SIZE(closure)            (STATIC_INFO_SIZE(INFO_PTR(closure)))
884 #define STATIC_CLOSURE_NoPTRS(closure)          (STATIC_INFO_NoPTRS(INFO_PTR(closure)))
885 #define STATIC_CLOSURE_NoNONPTRS(closure)       (STATIC_CLOSURE_SIZE(closure)-STATIC_CLOSURE_NoPTRS(closure)-STATIC_VHS)
886
887 #define SET_STATIC_HDR(closure,infolbl,cc,closure_localness,info_localness_macro) \
888         info_localness_macro(infolbl); \
889         closure_localness \
890         W_ closure[] = {SET_STATIC_FIXED_HDR(&closure[0],infolbl,cc)
891 \end{code}
892
893 %************************************************************************
894 %*                                                                      *
895 \subsubsection[IND-closures]{@IND@ (indirection) closure macros}
896 %*                                                                      *
897 %************************************************************************
898
899 Indirections are introduced when closures are updated. They are only
900 built by the update macros and the special @CAF@ entry macro in
901 @SMupdate.lh@.
902
903 Indirections also have a fixed size of @IND_CLOSURE_SIZE(closure)@.
904
905 Both for @CAF@s and for normal nodes in Appel's collector we have to
906 be able to identify and link together lists of indirections which are
907 treated specially by the garbage collector. For this purpose we use
908 the @MUT_LINK@ field.
909
910 @CAF@s (which look like indirections) need to be linked regardless of
911 whether or not we're doing generational collection, so we don't rely
912 on @MUT_LINK@ being defined.
913
914 \begin{code}
915 #define IND_VHS                 (1)
916 #define IND_HS                  (FIXED_HS + IND_VHS)
917
918 #define IND_CLOSURE_SIZE(closure) (MIN_UPD_SIZE)
919 #define IND_CLOSURE_NoPTRS(closure) 1
920 #define IND_CLOSURE_NoNONPTRS(closure) \
921             (IND_CLOSURE_SIZE(closure)-IND_CLOSURE_NoPTRS(closure)-IND_VHS)
922 \end{code}
923
924 Indirections must store a pointer to the closure which is the target
925 of the indirection:
926 \begin{code}
927 #define IND_CLOSURE_PTR(closure)  (((P_)(closure))[IND_HS])
928 #define IND_CLOSURE_LINK(closure) (((P_)(closure))[FIXED_HS])
929 \end{code}
930
931 When we are profiling, we occasionally use ``permanent indirections''
932 to store cost centres associated in some way with PAPs.  Don't ask me
933 why.  For now, a permanent indirection must have the same shape as a
934 regular indirection.  The only difference is that it is, well,
935 permanent.  That is to say, it is never short-circuited.  (What is the
936 point, anyway?)
937
938 Presumably, such objects could shrink as they moved into the old
939 generation, but then their header size would change as well (the word
940 that they get to lose is the VHS word of a standard indirection), and
941 I just don't feel up to it today.  --JSM.
942
943 \begin{code}
944 #if defined(PROFILING) || defined(TICKY_TICKY)
945
946 #define PERM_IND_CLOSURE_PTR(closure,dummy) IND_CLOSURE_PTR(closure)
947     /* really *must* be the same as IND_CLOSURE_PTR; it is
948        merely a "two-argument" variant, to fit in with the
949        bizarre goings-on in SMmark.lhc and friends. WDP 95/12
950     */
951 #endif
952 \end{code}
953
954 %************************************************************************
955 %*                                                                      *
956 \subsubsection[BH-closures]{@BH@ (black hole) closure macros}
957 %*                                                                      *
958 %************************************************************************
959
960 There are two flavours of black holes; one for updatable closures
961 (size @MIN_UPD_SIZE@) and one for single entry closures (size
962 @MIN_NONUPD_SIZE@).  Note that single-entry black holes can never
963 become blocking queues, because that would imply multiple entries
964 to the closure.
965
966 Black holes are introduced either on entering a closure or when
967 performing garbage collection (see section
968 \ref{black-hole-overwrite}). They indicate that the pointers within
969 the closure are no longer needed.
970
971 The compiler will also allocate an updatable black hole on entering a
972 @CAF@.
973
974 \begin{code}
975 #define BH_HS           (FIXED_HS)
976 #define BH_VHS          0L
977
978 #define BH_U_SIZE       MIN_UPD_SIZE
979 #define BH_N_SIZE       MIN_NONUPD_SIZE
980
981 #define BH_CLOSURE_SIZE(closure)        ((W_)INFO_SIZE(INFO_PTR(closure)))
982 #define BH_CLOSURE_NoPTRS(closure)      0L
983 #define BH_CLOSURE_NoNONPTRS(closure)   (BH_CLOSURE_SIZE(closure)-BH_CLOSURE_NoPTRS(closure)-BH_VHS)
984
985 #define SET_BH_HDR(closure,infolbl,cc,size,ptrs) \
986         SET_FIXED_HDR(closure,infolbl,cc)
987         /* most args aren't used, but are required for SET_*_HDR uniformity */
988 \end{code}
989
990 %************************************************************************
991 %*                                                                      *
992 \subsubsection[RBH-closures]{@RBH@ (revertible black hole) closure macros}
993 %*                                                                      *
994 %************************************************************************
995
996 There are two kinds of revertible black holes, produced from GEN or
997 SPEC closures, respectively.  There's no @SET_RBH_HDR@ macro -- use
998 @convertToRBH@ instead!!
999
1000 Note that the NoPTRS and NoNONPTRS macros refer to the *original* closure.
1001
1002 \begin{code}
1003 #define SPEC_RBH_VHS                            (1L)
1004 #define SPEC_RBH_HS                             (FIXED_HS + SPEC_RBH_VHS)
1005
1006 #define SPEC_RBH_CLOSURE_PTR(closure, no)       (((P_)(closure))[SPEC_RBH_HS + (no) - 1])
1007 #define SPEC_RBH_CLOSURE_SIZE(closure)          ((W_)INFO_SIZE(REVERT_INFOPTR(INFO_PTR(closure))))
1008 #define SPEC_RBH_CLOSURE_NoPTRS(closure)        ((W_)INFO_NoPTRS(REVERT_INFOPTR(INFO_PTR(closure))))
1009 #define SPEC_RBH_CLOSURE_NoNONPTRS(closure)     (SPEC_RBH_CLOSURE_SIZE(closure)-SPEC_RBH_CLOSURE_NoPTRS(closure))
1010
1011 #define SPEC_RBH_BQ_LOCN                        (SPEC_RBH_HS)
1012 #define SPEC_RBH_BQ(closure)                    (((P_)(closure))[SPEC_RBH_BQ_LOCN])
1013
1014 #define GEN_RBH_VHS                             (1L)
1015 #define GEN_RBH_HS                              (FIXED_HS + GEN_RBH_VHS)
1016
1017 #define GEN_RBH_CLOSURE_PTR(closure, no)        (((P_)(closure))[GEN_RBH_HS + (no) - 1])
1018 #define GEN_RBH_CLOSURE_SIZE(closure)           (GEN_INFO_SIZE(REVERT_INFOPTR(INFO_PTR(closure))))
1019 #define GEN_RBH_CLOSURE_NoPTRS(closure)         (GEN_INFO_NoPTRS(REVERT_INFOPTR(INFO_PTR(closure))))
1020 #define GEN_RBH_CLOSURE_NoNONPTRS(closure)      (GEN_RBH_CLOSURE_SIZE(closure)-GEN_RBH_CLOSURE_NoPTRS(closure)-GEN_VHS)
1021
1022 #define GEN_RBH_BQ_LOCN                         (GEN_RBH_HS)
1023 #define GEN_RBH_BQ(closure)                     (((P_)(closure))[GEN_RBH_BQ_LOCN])
1024
1025 \end{code}
1026
1027
1028 %************************************************************************
1029 %*                                                                      *
1030 \subsubsection[CONST-closures]{@CONST@ (nullary data-constructor) closure macros}
1031 %*                                                                      *
1032 %************************************************************************
1033
1034 These are never allocated normally---static closures are used
1035 instead.  They arise only as a result of in-place updates which use
1036 @INPLACE_UPD_HDR@.
1037
1038 \begin{code}
1039 #define CONST_HS                                (FIXED_HS)
1040 #define CONST_VHS                               (0L)
1041
1042 #define CONST_CLOSURE_SIZE(closure)             (0L)
1043 #define CONST_CLOSURE_NoPTRS(closure)           (0L)
1044 #define CONST_CLOSURE_NoNONPTRS(closure)        (0L)
1045 \end{code}
1046
1047 %************************************************************************
1048 %*                                                                      *
1049 \subsubsection[CHARLIKE-closures]{@CHARLIKE@ closure macros}
1050 %*                                                                      *
1051 %************************************************************************
1052
1053 These are never allocated normally.  They are a static array of
1054 closures indexed by literal characters.  As with @CONST@ closures,
1055 @CHARLIKE@ closures only arise from in-place updates using
1056 @INPLACE_UPD_HDR@.
1057 \begin{code}
1058 #define CHARLIKE_HS             (FIXED_HS)
1059 #define CHARLIKE_VHS                            (0L)
1060
1061 #define CHARLIKE_CLOSURE_SIZE(closure)          (1L)
1062 #define CHARLIKE_CLOSURE_NoPTRS(closure)        (0L)
1063 #define CHARLIKE_CLOSURE_NoNONPTRS(closure)     (1L)
1064
1065 /* Array of static charlike closures */
1066 extern const W_ CHARLIKE_closures[];
1067
1068 /* Macro to retrieve static charlike closure */
1069 #define CHARLIKE_CLOSURE(the_char) \
1070         (& CHARLIKE_closures[(CHARLIKE_HS+1) * ((W_)(the_char))])
1071
1072 #define CHARLIKE_VALUE(closure) \
1073         (((P_)(closure))[CHARLIKE_HS])
1074
1075 /* INPLACE_UPD_HDR used for inplace updates */
1076 \end{code}
1077
1078
1079 %************************************************************************
1080 %*                                                                      *
1081 \subsubsection[INTLIKE-closures]{@INTLIKE@ closure macros}
1082 %*                                                                      *
1083 %************************************************************************
1084
1085 These may be allocated normally (@SET_INTLIKE_HDR@) or result from
1086 inplace updates (@INPLACE_UPD_HDR@). They may be converted to a static
1087 closure during garbage collection.
1088
1089 Note: the garbage collector (@EVAC_FN(IntLike)@) assumes that this has
1090 the same structure as a @SPEC_1_0@ closure.
1091
1092 \begin{code}
1093 #define INTLIKE_HS              (FIXED_HS)
1094 #define INTLIKE_VHS                             (0L)
1095
1096 #define INTLIKE_CLOSURE_SIZE(closure)           (1L)
1097 #define INTLIKE_CLOSURE_NoPTRS(closure)         (0L)
1098 #define INTLIKE_CLOSURE_NoNONPTRS(closure)      (1L)
1099
1100 /* Array of static intlike closures */
1101 extern P_ INTLIKE_closures;
1102
1103 /* Range of static intlike closures MAX_INTLIKE, MIN_INTLIKE is in GhcConstants.lh */
1104
1105 /* Macro to retrieve static intlike closure */
1106 #define INTLIKE_CLOSURE(the_int) \
1107         (INTLIKE_closures + ((INTLIKE_HS+1) * ((I_)(the_int))))
1108
1109 #define INTLIKE_VALUE(closure) \
1110         ((I_) ((P_)(closure))[INTLIKE_HS])
1111
1112 #define SET_INTLIKE_HDR(closure,infolbl,cc,size,ptrs) \
1113         SET_FIXED_HDR(closure,infolbl,cc)
1114
1115 /* INPLACE_UPD_HDR used for inplace updates */
1116 \end{code}
1117
1118
1119 End multi-slurp protection:
1120 \begin{code}
1121 #endif /* SMClosures_H */
1122 \end{code}