* __scm.h, stackchk.h, stackchk.c: Guile now performs stack
[bpt/guile.git] / libguile / weaks.c
1 /* Copyright (C) 1995,1996 Free Software Foundation, Inc.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16 *
17 * As a special exception, Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of this library.
19 *
20 * The exception is that, if you link this library with other files
21 * to produce an executable, this does not by itself cause the
22 * resulting executable to be covered by the GNU General Public License.
23 * Your use of that executable is in no way restricted on account of
24 * linking this library code into it.
25 *
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
28 *
29 * This exception applies only to the code released by
30 * Free Software Foundation as part of this library. If you copy
31 * code from other releases distributed under the terms of the GPL into a copy of
32 * this library, as the General Public License permits, the exception does
33 * not apply to the code that you add in this way. To avoid misleading
34 * anyone as to the status of such modified files, you must delete
35 * this exception notice from such code.
36 *
37 * If you write modifications of your own for this library, it is your choice
38 * whether to permit this exception to apply to your modifications.
39 * If you do not wish that, delete this exception notice.
40 */
41 \f
42 #include <stdio.h>
43 #include "_scm.h"
44
45 \f
46
47
48 /* {Weak Vectors}
49 */
50
51
52 SCM_PROC(s_make_weak_vector, "make-weak-vector", 1, 1, 0, scm_make_weak_vector);
53 #ifdef __STDC__
54 SCM
55 scm_make_weak_vector (SCM k, SCM fill)
56 #else
57 SCM
58 scm_make_weak_vector (k, fill)
59 SCM k;
60 SCM fill;
61 #endif
62 {
63 SCM v;
64 v = scm_make_vector (scm_sum (k, SCM_MAKINUM (1)), fill, SCM_UNDEFINED);
65 SCM_DEFER_INTS;
66 SCM_SETLENGTH(v, SCM_INUM (k), scm_tc7_wvect);
67 SCM_VELTS(v)[0] = (SCM)0;
68 SCM_SETVELTS(v, SCM_VELTS(v) + 1);
69 SCM_ALLOW_INTS;
70 return v;
71 }
72
73
74 SCM_PROC(s_weak_vector, "weak-vector", 0, 0, 1, scm_weak_vector);
75 SCM_PROC(s_list_to_weak_vector, "list->weak-vector", 1, 0, 0, scm_weak_vector);
76 #ifdef __STDC__
77 SCM
78 scm_weak_vector (SCM l)
79 #else
80 SCM
81 scm_weak_vector (l)
82 SCM l;
83 #endif
84 {
85 SCM res;
86 register SCM *data;
87 long i;
88
89 i = scm_ilength (l);
90 SCM_ASSERT (i >= 0, l, SCM_ARG1, s_weak_vector);
91 res = scm_make_weak_vector (SCM_MAKINUM (i), SCM_UNSPECIFIED);
92 data = SCM_VELTS (res);
93 for (;
94 i && SCM_NIMP (l) && SCM_CONSP (l);
95 --i, l = SCM_CDR (l))
96 *data++ = SCM_CAR (l);
97 return res;
98 }
99
100
101 SCM_PROC(s_weak_vector_p, "weak-vector?", 1, 0, 0, scm_weak_vector_p);
102 #ifdef __STDC__
103 SCM
104 scm_weak_vector_p (SCM x)
105 #else
106 SCM
107 scm_weak_vector_p (x)
108 SCM x;
109 #endif
110 {
111 return ((SCM_NIMP (x) && SCM_WVECTP (x) && !SCM_IS_WHVEC (x))
112 ? SCM_BOOL_T
113 : SCM_BOOL_F);
114 }
115
116
117
118 \f
119
120
121
122 SCM_PROC(s_make_weak_key_hash_table, "make-weak-key-hash-table", 1, 0, 0, scm_make_weak_key_hash_table);
123 #ifdef __STDC__
124 SCM
125 scm_make_weak_key_hash_table (SCM k)
126 #else
127 SCM
128 scm_make_weak_key_hash_table (k)
129 SCM k;
130 #endif
131 {
132 SCM v;
133 SCM_ASSERT (SCM_INUMP (k), k, SCM_ARG1, s_make_weak_key_hash_table);
134 v = scm_make_weak_vector (k, SCM_EOL);
135 SCM_ALLOW_INTS;
136 SCM_VELTS (v)[-1] = 1;
137 SCM_ALLOW_INTS;
138 return v;
139 }
140
141
142 SCM_PROC (s_make_weak_value_hash_table, "make-weak-value-hash-table", 1, 0, 0, scm_make_weak_value_hash_table);
143 #ifdef __STDC__
144 SCM
145 scm_make_weak_value_hash_table (SCM k)
146 #else
147 SCM
148 scm_make_weak_value_hash_table (k)
149 SCM k;
150 #endif
151 {
152 SCM v;
153 SCM_ASSERT (SCM_INUMP (k), k, SCM_ARG1, s_make_weak_value_hash_table);
154 v = scm_make_weak_vector (k, SCM_EOL);
155 SCM_ALLOW_INTS;
156 SCM_VELTS (v)[-1] = 2;
157 SCM_ALLOW_INTS;
158 return v;
159 }
160
161
162
163 SCM_PROC (s_make_doubly_weak_hash_table, "make-doubly-weak-hash-table", 1, 0, 0, scm_make_doubly_weak_hash_table);
164 #ifdef __STDC__
165 SCM
166 scm_make_doubly_weak_hash_table (SCM k)
167 #else
168 SCM
169 scm_make_doubly_weak_hash_table (k)
170 SCM k;
171 #endif
172 {
173 SCM v;
174 SCM_ASSERT (SCM_INUMP (k), k, SCM_ARG1, s_make_doubly_weak_hash_table);
175 v = scm_make_weak_vector (k, SCM_EOL);
176 SCM_ALLOW_INTS;
177 SCM_VELTS (v)[-1] = 3;
178 SCM_ALLOW_INTS;
179 return v;
180 }
181
182 SCM_PROC(s_weak_key_hash_table_p, "weak-key-hash-table?", 1, 0, 0, scm_weak_key_hash_table_p);
183 #ifdef __STDC__
184 SCM
185 scm_weak_key_hash_table_p (SCM x)
186 #else
187 SCM
188 scm_weak_key_hash_table_p (x)
189 SCM x;
190 #endif
191 {
192 return ((SCM_NIMP (x) && SCM_WVECTP (x) && SCM_IS_WHVEC(x))
193 ? SCM_BOOL_T
194 : SCM_BOOL_F);
195 }
196
197
198 SCM_PROC (s_weak_value_hash_table_p, "weak-value-hash-table?", 1, 0, 0, scm_weak_value_hash_table_p);
199 #ifdef __STDC__
200 SCM
201 scm_weak_value_hash_table_p (SCM x)
202 #else
203 SCM
204 scm_weak_value_hash_table_p (x)
205 SCM x;
206 #endif
207 {
208 return ((SCM_NIMP (x) && SCM_WVECTP (x) && SCM_IS_WHVEC_V(x))
209 ? SCM_BOOL_T
210 : SCM_BOOL_F);
211 }
212
213
214 SCM_PROC (s_doubly_weak_hash_table_p, "doubly-weak-hash-table?", 1, 0, 0, scm_doubly_weak_hash_table_p);
215 #ifdef __STDC__
216 SCM
217 scm_doubly_weak_hash_table_p (SCM x)
218 #else
219 SCM
220 scm_doubly_weak_hash_table_p (x)
221 SCM x;
222 #endif
223 {
224 return ((SCM_NIMP (x) && SCM_WVECTP (x) && SCM_IS_WHVEC_B (x))
225 ? SCM_BOOL_T
226 : SCM_BOOL_F);
227 }
228
229
230 \f
231
232 #ifdef __STDC__
233 void
234 scm_init_weaks (void)
235 #else
236 void
237 scm_init_weaks ()
238 #endif
239 {
240 #include "weaks.x"
241 }
242