Allocate vectors in a contiguous memory area.
[bpt/guile.git] / libguile / weaks.h
1 /* classes: h_files */
2
3 #ifndef SCM_WEAKS_H
4 #define SCM_WEAKS_H
5
6 /* Copyright (C) 1995,1996,2000,2001, 2003, 2006, 2008, 2009 Free Software Foundation, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 */
23
24 \f
25
26 #include "libguile/__scm.h"
27
28 \f
29
30 #define SCM_WVECTF_WEAK_KEY 1
31 #define SCM_WVECTF_WEAK_VALUE 2
32
33 #define SCM_WVECT_WEAK_KEY_P(x) (SCM_I_WVECT_EXTRA(x) & SCM_WVECTF_WEAK_KEY)
34 #define SCM_WVECT_WEAK_VALUE_P(x) (SCM_I_WVECT_EXTRA(x) & SCM_WVECTF_WEAK_VALUE)
35
36 #define SCM_I_WVECT_TYPE(x) (SCM_I_WVECT_EXTRA(x) & 7)
37 #define SCM_I_SET_WVECT_TYPE(x,t) (SCM_I_SET_WVECT_EXTRA \
38 ((x), (SCM_I_WVECT_EXTRA (x) & ~7) | (t)))
39 #define SCM_IS_WHVEC(X) (SCM_I_WVECT_TYPE (X) == 1)
40 #define SCM_IS_WHVEC_V(X) (SCM_I_WVECT_TYPE (X) == 2)
41 #define SCM_IS_WHVEC_B(X) (SCM_I_WVECT_TYPE (X) == 3)
42 #define SCM_IS_WHVEC_ANY(X) (SCM_I_WVECT_TYPE (X) != 0)
43
44 \f
45 /* Weak pairs. */
46
47 SCM_INTERNAL SCM scm_weak_car_pair (SCM car, SCM cdr);
48 SCM_INTERNAL SCM scm_weak_cdr_pair (SCM car, SCM cdr);
49 SCM_INTERNAL SCM scm_doubly_weak_pair (SCM car, SCM cdr);
50
51 /* Testing the weak component(s) of a cell for reachability. */
52 #define SCM_WEAK_PAIR_WORD_DELETED_P(_cell, _word) \
53 (SCM_CELL_OBJECT ((_cell), (_word)) == SCM_PACK (NULL))
54 #define SCM_WEAK_PAIR_CAR_DELETED_P(_cell) \
55 (SCM_WEAK_PAIR_WORD_DELETED_P ((_cell), 0))
56 #define SCM_WEAK_PAIR_CDR_DELETED_P(_cell) \
57 (SCM_WEAK_PAIR_WORD_DELETED_P ((_cell), 1))
58
59 #define SCM_WEAK_PAIR_DELETED_P(_cell) \
60 ((SCM_WEAK_PAIR_CAR_DELETED_P (_cell)) \
61 || (SCM_WEAK_PAIR_CDR_DELETED_P (_cell)))
62
63 /* Accessing the components of a weak cell. These return `SCM_UNDEFINED' if
64 the car/cdr has been collected. */
65 #define SCM_WEAK_PAIR_WORD(_cell, _word) \
66 (SCM_WEAK_PAIR_WORD_DELETED_P ((_cell), (_word)) \
67 ? SCM_UNDEFINED \
68 : SCM_CELL_OBJECT ((_cell), (_word)))
69 #define SCM_WEAK_PAIR_CAR(_cell) (SCM_WEAK_PAIR_WORD ((_cell), 0))
70 #define SCM_WEAK_PAIR_CDR(_cell) (SCM_WEAK_PAIR_WORD ((_cell), 1))
71
72
73 \f
74 /* Weak vectors and weak hash tables. */
75
76 SCM_API SCM scm_make_weak_vector (SCM k, SCM fill);
77 SCM_API SCM scm_weak_vector (SCM l);
78 SCM_API SCM scm_weak_vector_p (SCM x);
79 SCM_API SCM scm_make_weak_key_alist_vector (SCM k);
80 SCM_API SCM scm_make_weak_value_alist_vector (SCM k);
81 SCM_API SCM scm_make_doubly_weak_alist_vector (SCM k);
82 SCM_API SCM scm_weak_key_alist_vector_p (SCM x);
83 SCM_API SCM scm_weak_value_alist_vector_p (SCM x);
84 SCM_API SCM scm_doubly_weak_alist_vector_p (SCM x);
85 SCM_INTERNAL SCM scm_init_weaks_builtins (void);
86 SCM_INTERNAL void scm_weaks_prehistory (void);
87 SCM_INTERNAL void scm_init_weaks (void);
88
89 SCM_INTERNAL void scm_i_init_weak_vectors_for_gc (void);
90 SCM_INTERNAL void scm_i_mark_weak_vector (SCM w);
91 SCM_INTERNAL int scm_i_mark_weak_vectors_non_weaks (void);
92 SCM_INTERNAL void scm_i_remove_weaks_from_weak_vectors (void);
93
94
95 #endif /* SCM_WEAKS_H */
96
97 /*
98 Local Variables:
99 c-file-style: "gnu"
100 End:
101 */