Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
592996c9 DH |
3 | #ifndef SCM_WEAKS_H |
4 | #define SCM_WEAKS_H | |
0527e687 | 5 | |
1e3fd6a0 | 6 | /* Copyright (C) 1995,1996,2000,2001, 2003, 2006, 2008, 2009, 2011, 2014 Free Software Foundation, Inc. |
0527e687 | 7 | * |
73be1d9e | 8 | * This library is free software; you can redistribute it and/or |
53befeb7 NJ |
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. | |
0527e687 | 12 | * |
53befeb7 NJ |
13 | * This library is distributed in the hope that it will be useful, but |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
73be1d9e MV |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. | |
0527e687 | 17 | * |
73be1d9e MV |
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 | |
53befeb7 NJ |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
21 | * 02110-1301 USA | |
73be1d9e | 22 | */ |
d3a6bc94 | 23 | |
0f2d19dd JB |
24 | \f |
25 | ||
b4309c3c | 26 | #include "libguile/__scm.h" |
0f2d19dd JB |
27 | |
28 | \f | |
29 | ||
c35738c1 MD |
30 | #define SCM_WVECTF_WEAK_KEY 1 |
31 | #define SCM_WVECTF_WEAK_VALUE 2 | |
c35738c1 | 32 | |
06c1d900 MV |
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) | |
0f2d19dd | 35 | |
06c1d900 MV |
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) | |
56a68067 | 43 | |
0f2d19dd | 44 | \f |
986ec822 LC |
45 | /* Weak pairs. */ |
46 | ||
238f9a4f LC |
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); | |
986ec822 LC |
50 | |
51 | /* Testing the weak component(s) of a cell for reachability. */ | |
52 | #define SCM_WEAK_PAIR_WORD_DELETED_P(_cell, _word) \ | |
b2b33168 | 53 | (SCM_UNPACK (SCM_CELL_OBJECT ((_cell), (_word))) == 0) |
986ec822 LC |
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 | ||
aef9e3bd LC |
63 | /* Accessing the components of a weak cell. These return `SCM_UNDEFINED' if |
64 | the car/cdr has been collected. */ | |
986ec822 | 65 | #define SCM_WEAK_PAIR_WORD(_cell, _word) \ |
aef9e3bd LC |
66 | (SCM_WEAK_PAIR_WORD_DELETED_P ((_cell), (_word)) \ |
67 | ? SCM_UNDEFINED \ | |
68 | : SCM_CELL_OBJECT ((_cell), (_word))) | |
986ec822 LC |
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. */ | |
0f2d19dd | 75 | |
33b001fd MV |
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); | |
1e3fd6a0 AW |
79 | SCM_API SCM scm_weak_vector_length (SCM v); |
80 | SCM_API SCM scm_weak_vector_ref (SCM v, SCM k); | |
81 | SCM_API SCM scm_weak_vector_set_x (SCM v, SCM k, SCM x); | |
82 | ||
83 | SCM_API SCM scm_c_make_weak_vector (size_t k, SCM fill); | |
84 | SCM_API int scm_is_weak_vector (SCM obj); | |
85 | SCM_API size_t scm_c_weak_vector_length (SCM vec); | |
86 | SCM_API SCM scm_c_weak_vector_ref (SCM v, size_t k); | |
87 | SCM_API void scm_c_weak_vector_set_x (SCM v, size_t k, SCM x); | |
88 | ||
c35738c1 MD |
89 | SCM_API SCM scm_make_weak_key_alist_vector (SCM k); |
90 | SCM_API SCM scm_make_weak_value_alist_vector (SCM k); | |
91 | SCM_API SCM scm_make_doubly_weak_alist_vector (SCM k); | |
92 | SCM_API SCM scm_weak_key_alist_vector_p (SCM x); | |
93 | SCM_API SCM scm_weak_value_alist_vector_p (SCM x); | |
94 | SCM_API SCM scm_doubly_weak_alist_vector_p (SCM x); | |
102dbb6f | 95 | SCM_INTERNAL SCM scm_init_weaks_builtins (void); |
6f03035f | 96 | SCM_INTERNAL void scm_weaks_prehistory (void); |
102dbb6f | 97 | SCM_INTERNAL void scm_init_weaks (void); |
0f2d19dd | 98 | |
102dbb6f LC |
99 | SCM_INTERNAL void scm_i_init_weak_vectors_for_gc (void); |
100 | SCM_INTERNAL void scm_i_mark_weak_vector (SCM w); | |
101 | SCM_INTERNAL int scm_i_mark_weak_vectors_non_weaks (void); | |
102 | SCM_INTERNAL void scm_i_remove_weaks_from_weak_vectors (void); | |
06c1d900 | 103 | |
5dbc6c06 | 104 | |
592996c9 | 105 | #endif /* SCM_WEAKS_H */ |
89e00824 ML |
106 | |
107 | /* | |
108 | Local Variables: | |
109 | c-file-style: "gnu" | |
110 | End: | |
111 | */ |