Commit | Line | Data |
---|---|---|
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 |
56 | typedef 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 | 66 | typedef 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 | |
77 | #define SCM2PTR(x) ((SCM_CELLPTR) (SCM_UNPACK (x) >> 3)) | |
78 | #define PTR2SCM(x) (SCM_PACK (((scm_bits_t) (x)) << 3)) | |
79 | #else | |
80 | #define SCM2PTR(x) ((SCM_CELLPTR) (SCM_UNPACK (x))) | |
81 | #define PTR2SCM(x) (SCM_PACK ((scm_bits_t) (x))) | |
82 | #endif /* def _UNICOS */ | |
83 | ||
84 | ||
85 | /* Low level cell data accessing macros: | |
86 | */ | |
87 | ||
a564e775 | 88 | #define SCM_VALIDATE_CELL(x) \ |
05a85bae MD |
89 | ((void) \ |
90 | (SCM_DEBUG_CELL_ACCESSES ? (!scm_cellp (x) ? (abort (), 0) : 1) : 1)) | |
46d53380 DH |
91 | |
92 | #define SCM_CELL_WORD(x, n) \ | |
93 | ((SCM_VALIDATE_CELL (x)), \ | |
94 | (((scm_bits_t *) SCM2PTR (x)) [n])) | |
2549a709 DH |
95 | #define SCM_CELL_WORD_0(x) SCM_CELL_WORD (x, 0) |
96 | #define SCM_CELL_WORD_1(x) SCM_CELL_WORD (x, 1) | |
97 | #define SCM_CELL_WORD_2(x) SCM_CELL_WORD (x, 2) | |
98 | #define SCM_CELL_WORD_3(x) SCM_CELL_WORD (x, 3) | |
99 | ||
46d53380 DH |
100 | #define SCM_CELL_OBJECT(x, n) \ |
101 | ((SCM_VALIDATE_CELL (x)), \ | |
102 | (SCM_PACK (((scm_bits_t *) SCM2PTR (x)) [n]))) | |
2549a709 DH |
103 | #define SCM_CELL_OBJECT_0(x) SCM_CELL_OBJECT (x, 0) |
104 | #define SCM_CELL_OBJECT_1(x) SCM_CELL_OBJECT (x, 1) | |
105 | #define SCM_CELL_OBJECT_2(x) SCM_CELL_OBJECT (x, 2) | |
106 | #define SCM_CELL_OBJECT_3(x) SCM_CELL_OBJECT (x, 3) | |
107 | ||
46d53380 DH |
108 | #define SCM_SET_CELL_WORD(x, n, v) \ |
109 | ((SCM_VALIDATE_CELL (x)), \ | |
110 | ((((scm_bits_t *) SCM2PTR (x)) [n]) = (scm_bits_t) (v))) | |
2549a709 DH |
111 | #define SCM_SET_CELL_WORD_0(x, v) SCM_SET_CELL_WORD (x, 0, v) |
112 | #define SCM_SET_CELL_WORD_1(x, v) SCM_SET_CELL_WORD (x, 1, v) | |
113 | #define SCM_SET_CELL_WORD_2(x, v) SCM_SET_CELL_WORD (x, 2, v) | |
114 | #define SCM_SET_CELL_WORD_3(x, v) SCM_SET_CELL_WORD (x, 3, v) | |
115 | ||
46d53380 DH |
116 | #define SCM_SET_CELL_OBJECT(x, n, v) \ |
117 | ((SCM_VALIDATE_CELL (x)), \ | |
118 | ((((scm_bits_t *) SCM2PTR (x)) [n]) = SCM_UNPACK (v))) | |
2549a709 DH |
119 | #define SCM_SET_CELL_OBJECT_0(x, v) SCM_SET_CELL_OBJECT (x, 0, v) |
120 | #define SCM_SET_CELL_OBJECT_1(x, v) SCM_SET_CELL_OBJECT (x, 1, v) | |
121 | #define SCM_SET_CELL_OBJECT_2(x, v) SCM_SET_CELL_OBJECT (x, 2, v) | |
122 | #define SCM_SET_CELL_OBJECT_3(x, v) SCM_SET_CELL_OBJECT (x, 3, v) | |
123 | ||
124 | #define SCM_CELL_TYPE(x) SCM_CELL_WORD_0 (x) | |
125 | #define SCM_SET_CELL_TYPE(x, t) SCM_SET_CELL_WORD_0 (x, t) | |
126 | ||
e828cb75 DH |
127 | #define SCM_SETAND_CAR(x, y) \ |
128 | (SCM_SETCAR ((x), SCM_PACK (SCM_UNPACK (SCM_CAR (x)) & (y)))) | |
2549a709 | 129 | #define SCM_SETAND_CDR(x, y)\ |
e828cb75 | 130 | (SCM_SETCDR ((x), SCM_PACK (SCM_UNPACK (SCM_CDR (x)) & (y)))) |
2549a709 | 131 | #define SCM_SETOR_CAR(x, y)\ |
e828cb75 | 132 | (SCM_SETCAR ((x), SCM_PACK (SCM_UNPACK (SCM_CAR (x)) | (y)))) |
2549a709 | 133 | #define SCM_SETOR_CDR(x, y)\ |
e828cb75 | 134 | (SCM_SETCDR ((x), SCM_PACK (SCM_UNPACK (SCM_CDR (x)) | (y)))) |
2549a709 DH |
135 | |
136 | #define SCM_CELL_WORD_LOC(x, n) (&SCM_CELL_WORD (x, n)) | |
4b479d98 DH |
137 | #define SCM_CARLOC(x) ((SCM *) (&(((scm_bits_t *) SCM2PTR (x)) [0]))) |
138 | #define SCM_CDRLOC(x) ((SCM *) (&(((scm_bits_t *) SCM2PTR (x)) [1]))) | |
2549a709 DH |
139 | |
140 | ||
6ba93e5e DH |
141 | /* SCM_PTR_LT and friends define how to compare two SCM_CELLPTRs (which may |
142 | * point to cells in different heap segments). | |
2549a709 | 143 | */ |
6ba93e5e DH |
144 | #define SCM_PTR_LT(x, y) ((x) < (y)) |
145 | #define SCM_PTR_GT(x, y) (SCM_PTR_LT (y, x)) | |
2549a709 DH |
146 | #define SCM_PTR_LE(x, y) (!SCM_PTR_GT (x, y)) |
147 | #define SCM_PTR_GE(x, y) (!SCM_PTR_LT (x, y)) | |
148 | ||
149 | ||
2d67e390 DH |
150 | /* Dirk:FIXME:: */ |
151 | /* Freelists consist of linked cells where the type entry holds the value | |
152 | * scm_tc_free_cell and the second entry holds a pointer to the next cell of | |
153 | * the freelist. Due to this structure, freelist cells are not cons cells | |
154 | * and thus may not be accessed using SCM_CAR and SCM_CDR. | |
155 | */ | |
156 | ||
157 | /* the allocated thing: The car of new cells is set to | |
2549a709 | 158 | scm_tc16_allocated to avoid the fragile state of newcells wrt the |
2d67e390 | 159 | gc. If it stays as a freecell, any allocation afterwards could |
2549a709 | 160 | cause the cell to go back on the freelist, which will bite you |
2d67e390 | 161 | sometime afterwards. */ |
2549a709 DH |
162 | |
163 | #ifdef GUILE_DEBUG_FREELIST | |
164 | #define SCM_NEWCELL(_into) do { _into = scm_debug_newcell (); } while (0) | |
165 | #define SCM_NEWCELL2(_into) do { _into = scm_debug_newcell2 (); } while (0) | |
166 | #else | |
2549a709 DH |
167 | /* When we introduce POSIX threads support, every thread will have |
168 | a freelist of its own. Then it won't any longer be necessary to | |
169 | initialize cells with scm_tc16_allocated. */ | |
170 | #define SCM_NEWCELL(_into) \ | |
171 | do { \ | |
172 | if (SCM_IMP (scm_freelist)) \ | |
173 | _into = scm_gc_for_newcell (&scm_master_freelist, \ | |
174 | &scm_freelist); \ | |
175 | else \ | |
176 | { \ | |
177 | _into = scm_freelist; \ | |
2d67e390 DH |
178 | scm_freelist = SCM_CDR (scm_freelist); \ |
179 | SCM_SET_CELL_TYPE (_into, scm_tc16_allocated); \ | |
2549a709 DH |
180 | } \ |
181 | } while(0) | |
182 | #define SCM_NEWCELL2(_into) \ | |
183 | do { \ | |
184 | if (SCM_IMP (scm_freelist2)) \ | |
185 | _into = scm_gc_for_newcell (&scm_master_freelist2, \ | |
186 | &scm_freelist2); \ | |
187 | else \ | |
188 | { \ | |
189 | _into = scm_freelist2; \ | |
2d67e390 DH |
190 | scm_freelist2 = SCM_CDR (scm_freelist2); \ |
191 | SCM_SET_CELL_TYPE (_into, scm_tc16_allocated); \ | |
2549a709 DH |
192 | } \ |
193 | } while(0) | |
2549a709 DH |
194 | #endif |
195 | ||
196 | ||
2d67e390 DH |
197 | #define SCM_FREEP(x) (SCM_NIMP (x) && (SCM_CELL_TYPE (x) == scm_tc_free_cell)) |
198 | #define SCM_NFREEP(x) (!SCM_FREEP (x)) | |
0f2d19dd | 199 | |
79e3f9e2 MD |
200 | /* 1. This shouldn't be used on immediates. |
201 | 2. It thinks that subrs are always unmarked (harmless). */ | |
2d67e390 DH |
202 | #define SCM_MARKEDP(x) ((SCM_CELL_TYPE (x) & 5) == 5 \ |
203 | ? SCM_GC8MARKP (x) \ | |
204 | : SCM_GCMARKP (x)) | |
205 | #define SCM_NMARKEDP(x) (!SCM_MARKEDP (x)) | |
79e3f9e2 | 206 | |
a00c95d9 | 207 | extern struct scm_heap_seg_data_t *scm_heap_table; |
0f2d19dd JB |
208 | extern int scm_n_heap_segs; |
209 | extern int scm_take_stdin; | |
210 | extern int scm_block_gc; | |
211 | extern int scm_gc_heap_lock; | |
212 | \f | |
213 | ||
4c48ba06 | 214 | extern scm_sizet scm_max_segment_size; |
0f2d19dd | 215 | extern SCM_CELLPTR scm_heap_org; |
4a4c9785 | 216 | extern SCM scm_freelist; |
a00c95d9 | 217 | extern struct scm_freelist_t scm_master_freelist; |
4a4c9785 | 218 | extern SCM scm_freelist2; |
a00c95d9 | 219 | extern struct scm_freelist_t scm_master_freelist2; |
0f2d19dd | 220 | extern unsigned long scm_gc_cells_collected; |
8b0d194f | 221 | extern unsigned long scm_gc_yield; |
0f2d19dd JB |
222 | extern unsigned long scm_gc_malloc_collected; |
223 | extern unsigned long scm_gc_ports_collected; | |
224 | extern unsigned long scm_cells_allocated; | |
a5c314c8 | 225 | extern long scm_mallocated; |
15e9d186 | 226 | extern unsigned long scm_mtrigger; |
0f2d19dd | 227 | |
9b3e180c MD |
228 | extern SCM scm_after_gc_hook; |
229 | ||
230 | extern scm_c_hook_t scm_before_gc_c_hook; | |
231 | extern scm_c_hook_t scm_before_mark_c_hook; | |
232 | extern scm_c_hook_t scm_before_sweep_c_hook; | |
233 | extern scm_c_hook_t scm_after_sweep_c_hook; | |
234 | extern scm_c_hook_t scm_after_gc_c_hook; | |
235 | ||
bb2c57fa | 236 | #if defined (GUILE_DEBUG) || defined (GUILE_DEBUG_FREELIST) |
25748c78 | 237 | extern SCM scm_map_free_list (void); |
5384bc5b | 238 | extern SCM scm_free_list_length (void); |
bb2c57fa MD |
239 | #endif |
240 | #ifdef GUILE_DEBUG_FREELIST | |
f2333166 | 241 | extern SCM scm_debug_newcell (void); |
16d35552 | 242 | extern SCM scm_debug_newcell2 (void); |
25748c78 | 243 | extern SCM scm_gc_set_debug_check_freelist_x (SCM flag); |
88256b2e JB |
244 | #endif |
245 | ||
0f2d19dd | 246 | \f |
0f2d19dd | 247 | |
8163d1e4 | 248 | extern SCM scm_object_address (SCM obj); |
fe1a46f0 JB |
249 | extern SCM scm_unhash_name (SCM name); |
250 | extern SCM scm_gc_stats (void); | |
3eeba8d4 | 251 | extern void scm_gc_start (const char *what); |
fe1a46f0 JB |
252 | extern void scm_gc_end (void); |
253 | extern SCM scm_gc (void); | |
a00c95d9 | 254 | extern void scm_gc_for_alloc (struct scm_freelist_t *freelist); |
a00c95d9 | 255 | extern SCM scm_gc_for_newcell (struct scm_freelist_t *master, SCM *freelist); |
4c48ba06 | 256 | #if 0 |
a00c95d9 | 257 | extern void scm_alloc_cluster (struct scm_freelist_t *master); |
4c48ba06 | 258 | #endif |
3eeba8d4 | 259 | extern void scm_igc (const char *what); |
fe1a46f0 JB |
260 | extern void scm_gc_mark (SCM p); |
261 | extern void scm_mark_locations (SCM_STACKITEM x[], scm_sizet n); | |
262 | extern int scm_cellp (SCM value); | |
263 | extern void scm_gc_sweep (void); | |
07806695 JB |
264 | extern void * scm_must_malloc (scm_sizet len, const char *what); |
265 | extern void * scm_must_realloc (void *where, | |
fe1a46f0 | 266 | scm_sizet olen, scm_sizet len, |
3eeba8d4 | 267 | const char *what); |
fe1a46f0 | 268 | extern void scm_done_malloc (long size); |
07806695 | 269 | extern void scm_must_free (void *obj); |
fe1a46f0 JB |
270 | extern void scm_remember (SCM * ptr); |
271 | extern SCM scm_return_first (SCM elt, ...); | |
41b0806d | 272 | extern int scm_return_first_int (int x, ...); |
fe1a46f0 JB |
273 | extern SCM scm_permanent_object (SCM obj); |
274 | extern SCM scm_protect_object (SCM obj); | |
275 | extern SCM scm_unprotect_object (SCM obj); | |
dd45c0df | 276 | extern int scm_init_storage (scm_sizet init_heap_size, int trig, |
4c48ba06 MD |
277 | scm_sizet init_heap2_size, int trig2, |
278 | scm_sizet max_segment_size); | |
fe1a46f0 | 279 | extern void scm_init_gc (void); |
0f2d19dd | 280 | #endif /* GCH */ |
89e00824 ML |
281 | |
282 | /* | |
283 | Local Variables: | |
284 | c-file-style: "gnu" | |
285 | End: | |
286 | */ |