| 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 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 |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but 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 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | \f |
| 24 | |
| 25 | #include "libguile/__scm.h" |
| 26 | |
| 27 | \f |
| 28 | |
| 29 | #define SCM_WVECTF_WEAK_KEY 1 |
| 30 | #define SCM_WVECTF_WEAK_VALUE 2 |
| 31 | |
| 32 | #define SCM_WVECT_WEAK_KEY_P(x) (SCM_I_WVECT_EXTRA(x) & SCM_WVECTF_WEAK_KEY) |
| 33 | #define SCM_WVECT_WEAK_VALUE_P(x) (SCM_I_WVECT_EXTRA(x) & SCM_WVECTF_WEAK_VALUE) |
| 34 | |
| 35 | /* The DELTA field is used by the abstract hash tables. During GC, |
| 36 | this field will be set to the number of items that have been |
| 37 | dropped. The abstract hash table will then use it to update its |
| 38 | item count. DELTA is unsigned. |
| 39 | */ |
| 40 | |
| 41 | #define SCM_I_WVECT_DELTA(x) (SCM_I_WVECT_EXTRA(x) >> 3) |
| 42 | #define SCM_I_SET_WVECT_DELTA(x,n) (SCM_I_SET_WVECT_EXTRA \ |
| 43 | ((x), ((SCM_I_WVECT_EXTRA (x) & 7) \ |
| 44 | | ((n) << 3)))) |
| 45 | |
| 46 | #define SCM_I_WVECT_TYPE(x) (SCM_I_WVECT_EXTRA(x) & 7) |
| 47 | #define SCM_I_SET_WVECT_TYPE(x,t) (SCM_I_SET_WVECT_EXTRA \ |
| 48 | ((x), (SCM_I_WVECT_EXTRA (x) & ~7) | (t))) |
| 49 | #define SCM_IS_WHVEC(X) (SCM_I_WVECT_TYPE (X) == 1) |
| 50 | #define SCM_IS_WHVEC_V(X) (SCM_I_WVECT_TYPE (X) == 2) |
| 51 | #define SCM_IS_WHVEC_B(X) (SCM_I_WVECT_TYPE (X) == 3) |
| 52 | #define SCM_IS_WHVEC_ANY(X) (SCM_I_WVECT_TYPE (X) != 0) |
| 53 | |
| 54 | \f |
| 55 | /* Weak pairs. */ |
| 56 | |
| 57 | SCM_API SCM scm_weak_car_pair (SCM car, SCM cdr); |
| 58 | SCM_API SCM scm_weak_cdr_pair (SCM car, SCM cdr); |
| 59 | SCM_API SCM scm_doubly_weak_pair (SCM car, SCM cdr); |
| 60 | |
| 61 | /* Testing the weak component(s) of a cell for reachability. */ |
| 62 | #define SCM_WEAK_PAIR_WORD_DELETED_P(_cell, _word) \ |
| 63 | (SCM_CELL_OBJECT ((_cell), (_word)) == SCM_PACK (NULL)) |
| 64 | #define SCM_WEAK_PAIR_CAR_DELETED_P(_cell) \ |
| 65 | (SCM_WEAK_PAIR_WORD_DELETED_P ((_cell), 0)) |
| 66 | #define SCM_WEAK_PAIR_CDR_DELETED_P(_cell) \ |
| 67 | (SCM_WEAK_PAIR_WORD_DELETED_P ((_cell), 1)) |
| 68 | |
| 69 | #define SCM_WEAK_PAIR_DELETED_P(_cell) \ |
| 70 | ((SCM_WEAK_PAIR_CAR_DELETED_P (_cell)) \ |
| 71 | || (SCM_WEAK_PAIR_CDR_DELETED_P (_cell))) |
| 72 | |
| 73 | /* Accessing the components of a weak cell. */ |
| 74 | #define SCM_WEAK_PAIR_WORD(_cell, _word) \ |
| 75 | ((SCM_WEAK_PAIR_WORD_DELETED_P ((_cell), (_word))) \ |
| 76 | ? SCM_BOOL_F : SCM_CAR (pair)) |
| 77 | #define SCM_WEAK_PAIR_CAR(_cell) (SCM_WEAK_PAIR_WORD ((_cell), 0)) |
| 78 | #define SCM_WEAK_PAIR_CDR(_cell) (SCM_WEAK_PAIR_WORD ((_cell), 1)) |
| 79 | |
| 80 | |
| 81 | \f |
| 82 | /* Weak vectors and weak hash tables. */ |
| 83 | |
| 84 | SCM_API SCM scm_make_weak_vector (SCM k, SCM fill); |
| 85 | SCM_API SCM scm_weak_vector (SCM l); |
| 86 | SCM_API SCM scm_weak_vector_p (SCM x); |
| 87 | SCM_API SCM scm_make_weak_key_alist_vector (SCM k); |
| 88 | SCM_API SCM scm_make_weak_value_alist_vector (SCM k); |
| 89 | SCM_API SCM scm_make_doubly_weak_alist_vector (SCM k); |
| 90 | SCM_API SCM scm_weak_key_alist_vector_p (SCM x); |
| 91 | SCM_API SCM scm_weak_value_alist_vector_p (SCM x); |
| 92 | SCM_API SCM scm_doubly_weak_alist_vector_p (SCM x); |
| 93 | SCM_INTERNAL SCM scm_init_weaks_builtins (void); |
| 94 | SCM_INTERNAL void scm_weaks_prehistory (void); |
| 95 | SCM_INTERNAL void scm_init_weaks (void); |
| 96 | |
| 97 | SCM_INTERNAL void scm_i_init_weak_vectors_for_gc (void); |
| 98 | SCM_INTERNAL void scm_i_mark_weak_vector (SCM w); |
| 99 | SCM_INTERNAL int scm_i_mark_weak_vectors_non_weaks (void); |
| 100 | SCM_INTERNAL void scm_i_remove_weaks_from_weak_vectors (void); |
| 101 | |
| 102 | |
| 103 | #endif /* SCM_WEAKS_H */ |
| 104 | |
| 105 | /* |
| 106 | Local Variables: |
| 107 | c-file-style: "gnu" |
| 108 | End: |
| 109 | */ |