* Signal an error when adding entries to a hash table with no slots.
[bpt/guile.git] / libguile / gc.h
CommitLineData
0f2d19dd
JB
1/* classes: h_files */
2
3#ifndef GCH
4#define GCH
16d35552 5/* Copyright (C) 1995, 96, 98, 99, 2000 Free Software Foundation, Inc.
a00c95d9 6 *
0f2d19dd
JB
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
a00c95d9 11 *
0f2d19dd
JB
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
a00c95d9 16 *
0f2d19dd
JB
17 * You should have received a copy of the GNU General Public License
18 * along with this software; see the file COPYING. If not, write to
82892bed
JB
19 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307 USA
0f2d19dd
JB
21 *
22 * As a special exception, the Free Software Foundation gives permission
23 * for additional uses of the text contained in its release of GUILE.
24 *
25 * The exception is that, if you link the GUILE library with other files
26 * to produce an executable, this does not by itself cause the
27 * resulting executable to be covered by the GNU General Public License.
28 * Your use of that executable is in no way restricted on account of
29 * linking the GUILE library code into it.
30 *
31 * This exception does not however invalidate any other reasons why
32 * the executable file might be covered by the GNU General Public License.
33 *
34 * This exception applies only to the code released by the
35 * Free Software Foundation under the name GUILE. If you copy
36 * code from other Free Software Foundation releases into a copy of
37 * GUILE, as the General Public License permits, the exception does
38 * not apply to the code that you add in this way. To avoid misleading
39 * anyone as to the status of such modified files, you must delete
40 * this exception notice from them.
41 *
42 * If you write modifications of your own for GUILE, it is your choice
43 * whether to permit this exception to apply to your modifications.
82892bed 44 * If you do not wish that, delete this exception notice. */
d3a6bc94
GB
45
46/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
47 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
0f2d19dd
JB
48\f
49
b4309c3c 50#include "libguile/__scm.h"
2549a709 51
9b3e180c
MD
52#include "libguile/hooks.h"
53
0f2d19dd
JB
54\f
55
2549a709
DH
56typedef struct scm_cell
57{
e828cb75
DH
58 scm_bits_t word_0;
59 scm_bits_t word_1;
2549a709
DH
60} scm_cell;
61
62
63/* SCM_CELLPTR is a pointer to a cons cell which may be compared or
64 * differenced.
65 */
56100716 66typedef scm_cell * SCM_CELLPTR;
2549a709
DH
67
68
69/* Cray machines have pointers that are incremented once for each word,
70 * rather than each byte, the 3 most significant bits encode the byte
71 * within the word. The following macros deal with this by storing the
72 * native Cray pointers like the ones that looks like scm expects. This
73 * is done for any pointers that might appear in the car of a scm_cell,
74 * pointers to scm_vector elts, functions, &c are not munged.
75 */
76#ifdef _UNICOS
076d6063
MD
77# define SCM2PTR(x) ((SCM_CELLPTR) (SCM_UNPACK (x) >> 3))
78# define PTR2SCM(x) (SCM_PACK (((scm_bits_t) (x)) << 3))
2549a709 79#else
076d6063
MD
80# define SCM2PTR(x) ((SCM_CELLPTR) (SCM_UNPACK (x)))
81# define PTR2SCM(x) (SCM_PACK ((scm_bits_t) (x)))
2549a709
DH
82#endif /* def _UNICOS */
83
84
85/* Low level cell data accessing macros:
86 */
87
708cb87c
MD
88#if SCM_DEBUG_CELL_ACCESSES == 1
89#define SCM_VALIDATE_CELL(cell, expr) \
90 (!scm_cellp (cell) ? abort (), 0 : (expr))
91#else
92#define SCM_VALIDATE_CELL(cell, expr) expr
93#endif
46d53380 94
708cb87c
MD
95#define SCM_CELL_WORD(x, n) \
96 SCM_VALIDATE_CELL ((x), \
97 ((scm_bits_t *) SCM2PTR (x)) [n])
2549a709
DH
98#define SCM_CELL_WORD_0(x) SCM_CELL_WORD (x, 0)
99#define SCM_CELL_WORD_1(x) SCM_CELL_WORD (x, 1)
100#define SCM_CELL_WORD_2(x) SCM_CELL_WORD (x, 2)
101#define SCM_CELL_WORD_3(x) SCM_CELL_WORD (x, 3)
102
708cb87c
MD
103#define SCM_CELL_OBJECT(x, n) \
104 SCM_VALIDATE_CELL ((x), \
105 SCM_PACK (((scm_bits_t *) SCM2PTR (x)) [n]))
2549a709
DH
106#define SCM_CELL_OBJECT_0(x) SCM_CELL_OBJECT (x, 0)
107#define SCM_CELL_OBJECT_1(x) SCM_CELL_OBJECT (x, 1)
108#define SCM_CELL_OBJECT_2(x) SCM_CELL_OBJECT (x, 2)
109#define SCM_CELL_OBJECT_3(x) SCM_CELL_OBJECT (x, 3)
110
708cb87c
MD
111#define SCM_SET_CELL_WORD(x, n, v) \
112 SCM_VALIDATE_CELL ((x), \
113 ((scm_bits_t *) SCM2PTR (x)) [n] = (scm_bits_t) (v))
2549a709
DH
114#define SCM_SET_CELL_WORD_0(x, v) SCM_SET_CELL_WORD (x, 0, v)
115#define SCM_SET_CELL_WORD_1(x, v) SCM_SET_CELL_WORD (x, 1, v)
116#define SCM_SET_CELL_WORD_2(x, v) SCM_SET_CELL_WORD (x, 2, v)
117#define SCM_SET_CELL_WORD_3(x, v) SCM_SET_CELL_WORD (x, 3, v)
118
708cb87c
MD
119#define SCM_SET_CELL_OBJECT(x, n, v) \
120 SCM_VALIDATE_CELL ((x), \
121 ((scm_bits_t *) SCM2PTR (x)) [n] = SCM_UNPACK (v))
2549a709
DH
122#define SCM_SET_CELL_OBJECT_0(x, v) SCM_SET_CELL_OBJECT (x, 0, v)
123#define SCM_SET_CELL_OBJECT_1(x, v) SCM_SET_CELL_OBJECT (x, 1, v)
124#define SCM_SET_CELL_OBJECT_2(x, v) SCM_SET_CELL_OBJECT (x, 2, v)
125#define SCM_SET_CELL_OBJECT_3(x, v) SCM_SET_CELL_OBJECT (x, 3, v)
126
127#define SCM_CELL_TYPE(x) SCM_CELL_WORD_0 (x)
128#define SCM_SET_CELL_TYPE(x, t) SCM_SET_CELL_WORD_0 (x, t)
129
e828cb75
DH
130#define SCM_SETAND_CAR(x, y) \
131 (SCM_SETCAR ((x), SCM_PACK (SCM_UNPACK (SCM_CAR (x)) & (y))))
2549a709 132#define SCM_SETAND_CDR(x, y)\
e828cb75 133 (SCM_SETCDR ((x), SCM_PACK (SCM_UNPACK (SCM_CDR (x)) & (y))))
2549a709 134#define SCM_SETOR_CAR(x, y)\
e828cb75 135 (SCM_SETCAR ((x), SCM_PACK (SCM_UNPACK (SCM_CAR (x)) | (y))))
2549a709 136#define SCM_SETOR_CDR(x, y)\
e828cb75 137 (SCM_SETCDR ((x), SCM_PACK (SCM_UNPACK (SCM_CDR (x)) | (y))))
2549a709
DH
138
139#define SCM_CELL_WORD_LOC(x, n) (&SCM_CELL_WORD (x, n))
4b479d98
DH
140#define SCM_CARLOC(x) ((SCM *) (&(((scm_bits_t *) SCM2PTR (x)) [0])))
141#define SCM_CDRLOC(x) ((SCM *) (&(((scm_bits_t *) SCM2PTR (x)) [1])))
2549a709
DH
142
143
6ba93e5e
DH
144/* SCM_PTR_LT and friends define how to compare two SCM_CELLPTRs (which may
145 * point to cells in different heap segments).
2549a709 146 */
6ba93e5e
DH
147#define SCM_PTR_LT(x, y) ((x) < (y))
148#define SCM_PTR_GT(x, y) (SCM_PTR_LT (y, x))
2549a709
DH
149#define SCM_PTR_LE(x, y) (!SCM_PTR_GT (x, y))
150#define SCM_PTR_GE(x, y) (!SCM_PTR_LT (x, y))
151
152
2d67e390
DH
153/* Dirk:FIXME:: */
154/* Freelists consist of linked cells where the type entry holds the value
155 * scm_tc_free_cell and the second entry holds a pointer to the next cell of
156 * the freelist. Due to this structure, freelist cells are not cons cells
157 * and thus may not be accessed using SCM_CAR and SCM_CDR.
158 */
159
160/* the allocated thing: The car of new cells is set to
2549a709 161 scm_tc16_allocated to avoid the fragile state of newcells wrt the
2d67e390 162 gc. If it stays as a freecell, any allocation afterwards could
2549a709 163 cause the cell to go back on the freelist, which will bite you
2d67e390 164 sometime afterwards. */
2549a709
DH
165
166#ifdef GUILE_DEBUG_FREELIST
167#define SCM_NEWCELL(_into) do { _into = scm_debug_newcell (); } while (0)
168#define SCM_NEWCELL2(_into) do { _into = scm_debug_newcell2 (); } while (0)
169#else
2549a709
DH
170/* When we introduce POSIX threads support, every thread will have
171 a freelist of its own. Then it won't any longer be necessary to
172 initialize cells with scm_tc16_allocated. */
173#define SCM_NEWCELL(_into) \
174 do { \
175 if (SCM_IMP (scm_freelist)) \
176 _into = scm_gc_for_newcell (&scm_master_freelist, \
177 &scm_freelist); \
178 else \
179 { \
180 _into = scm_freelist; \
2d67e390
DH
181 scm_freelist = SCM_CDR (scm_freelist); \
182 SCM_SET_CELL_TYPE (_into, scm_tc16_allocated); \
2549a709
DH
183 } \
184 } while(0)
185#define SCM_NEWCELL2(_into) \
186 do { \
187 if (SCM_IMP (scm_freelist2)) \
188 _into = scm_gc_for_newcell (&scm_master_freelist2, \
189 &scm_freelist2); \
190 else \
191 { \
192 _into = scm_freelist2; \
2d67e390
DH
193 scm_freelist2 = SCM_CDR (scm_freelist2); \
194 SCM_SET_CELL_TYPE (_into, scm_tc16_allocated); \
2549a709
DH
195 } \
196 } while(0)
2549a709
DH
197#endif
198
199
2d67e390
DH
200#define SCM_FREEP(x) (SCM_NIMP (x) && (SCM_CELL_TYPE (x) == scm_tc_free_cell))
201#define SCM_NFREEP(x) (!SCM_FREEP (x))
0f2d19dd 202
79e3f9e2
MD
203/* 1. This shouldn't be used on immediates.
204 2. It thinks that subrs are always unmarked (harmless). */
2d67e390
DH
205#define SCM_MARKEDP(x) ((SCM_CELL_TYPE (x) & 5) == 5 \
206 ? SCM_GC8MARKP (x) \
207 : SCM_GCMARKP (x))
208#define SCM_NMARKEDP(x) (!SCM_MARKEDP (x))
79e3f9e2 209
a00c95d9 210extern struct scm_heap_seg_data_t *scm_heap_table;
0f2d19dd
JB
211extern int scm_n_heap_segs;
212extern int scm_take_stdin;
213extern int scm_block_gc;
214extern int scm_gc_heap_lock;
215\f
216
aeacfc8f
MD
217extern int scm_default_init_heap_size_1;
218extern int scm_default_min_yield_1;
219extern int scm_default_init_heap_size_2;
220extern int scm_default_min_yield_2;
221extern int scm_default_max_segment_size;
222
4c48ba06 223extern scm_sizet scm_max_segment_size;
0f2d19dd 224extern SCM_CELLPTR scm_heap_org;
4a4c9785 225extern SCM scm_freelist;
a00c95d9 226extern struct scm_freelist_t scm_master_freelist;
4a4c9785 227extern SCM scm_freelist2;
a00c95d9 228extern struct scm_freelist_t scm_master_freelist2;
0f2d19dd 229extern unsigned long scm_gc_cells_collected;
8b0d194f 230extern unsigned long scm_gc_yield;
0f2d19dd
JB
231extern unsigned long scm_gc_malloc_collected;
232extern unsigned long scm_gc_ports_collected;
233extern unsigned long scm_cells_allocated;
a5c314c8 234extern long scm_mallocated;
15e9d186 235extern unsigned long scm_mtrigger;
0f2d19dd 236
9b3e180c
MD
237extern SCM scm_after_gc_hook;
238
239extern scm_c_hook_t scm_before_gc_c_hook;
240extern scm_c_hook_t scm_before_mark_c_hook;
241extern scm_c_hook_t scm_before_sweep_c_hook;
242extern scm_c_hook_t scm_after_sweep_c_hook;
243extern scm_c_hook_t scm_after_gc_c_hook;
244
bb2c57fa 245#if defined (GUILE_DEBUG) || defined (GUILE_DEBUG_FREELIST)
25748c78 246extern SCM scm_map_free_list (void);
5384bc5b 247extern SCM scm_free_list_length (void);
bb2c57fa
MD
248#endif
249#ifdef GUILE_DEBUG_FREELIST
f2333166 250extern SCM scm_debug_newcell (void);
16d35552 251extern SCM scm_debug_newcell2 (void);
25748c78 252extern SCM scm_gc_set_debug_check_freelist_x (SCM flag);
88256b2e
JB
253#endif
254
0f2d19dd 255\f
0f2d19dd 256
8163d1e4 257extern SCM scm_object_address (SCM obj);
fe1a46f0
JB
258extern SCM scm_unhash_name (SCM name);
259extern SCM scm_gc_stats (void);
3eeba8d4 260extern void scm_gc_start (const char *what);
fe1a46f0
JB
261extern void scm_gc_end (void);
262extern SCM scm_gc (void);
a00c95d9 263extern void scm_gc_for_alloc (struct scm_freelist_t *freelist);
a00c95d9 264extern SCM scm_gc_for_newcell (struct scm_freelist_t *master, SCM *freelist);
4c48ba06 265#if 0
a00c95d9 266extern void scm_alloc_cluster (struct scm_freelist_t *master);
4c48ba06 267#endif
3eeba8d4 268extern void scm_igc (const char *what);
fe1a46f0
JB
269extern void scm_gc_mark (SCM p);
270extern void scm_mark_locations (SCM_STACKITEM x[], scm_sizet n);
271extern int scm_cellp (SCM value);
272extern void scm_gc_sweep (void);
07806695
JB
273extern void * scm_must_malloc (scm_sizet len, const char *what);
274extern void * scm_must_realloc (void *where,
fe1a46f0 275 scm_sizet olen, scm_sizet len,
3eeba8d4 276 const char *what);
fe1a46f0 277extern void scm_done_malloc (long size);
07806695 278extern void scm_must_free (void *obj);
fe1a46f0
JB
279extern void scm_remember (SCM * ptr);
280extern SCM scm_return_first (SCM elt, ...);
41b0806d 281extern int scm_return_first_int (int x, ...);
fe1a46f0
JB
282extern SCM scm_permanent_object (SCM obj);
283extern SCM scm_protect_object (SCM obj);
284extern SCM scm_unprotect_object (SCM obj);
dd45c0df 285extern int scm_init_storage (scm_sizet init_heap_size, int trig,
4c48ba06
MD
286 scm_sizet init_heap2_size, int trig2,
287 scm_sizet max_segment_size);
fe1a46f0 288extern void scm_init_gc (void);
0f2d19dd 289#endif /* GCH */
89e00824
ML
290
291/*
292 Local Variables:
293 c-file-style: "gnu"
294 End:
295*/