* init.c (scm_boot_guile): Don't return the value of
[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 #include "weaks.h"
46 \f
47
48
49 /* {Weak Vectors}
50 */
51
52
53 SCM_PROC(s_make_weak_vector, "make-weak-vector", 1, 1, 0, scm_make_weak_vector);
54
55 SCM
56 scm_make_weak_vector (k, fill)
57 SCM k;
58 SCM fill;
59 {
60 SCM v;
61 v = scm_make_vector (scm_sum (k, SCM_MAKINUM (1)), fill, SCM_UNDEFINED);
62 SCM_DEFER_INTS;
63 SCM_SETLENGTH(v, SCM_INUM (k), scm_tc7_wvect);
64 SCM_VELTS(v)[0] = (SCM)0;
65 SCM_SETVELTS(v, SCM_VELTS(v) + 1);
66 SCM_ALLOW_INTS;
67 return v;
68 }
69
70
71 SCM_PROC(s_weak_vector, "weak-vector", 0, 0, 1, scm_weak_vector);
72 SCM_PROC(s_list_to_weak_vector, "list->weak-vector", 1, 0, 0, scm_weak_vector);
73
74 SCM
75 scm_weak_vector (l)
76 SCM l;
77 {
78 SCM res;
79 register SCM *data;
80 long i;
81
82 i = scm_ilength (l);
83 SCM_ASSERT (i >= 0, l, SCM_ARG1, s_weak_vector);
84 res = scm_make_weak_vector (SCM_MAKINUM (i), SCM_UNSPECIFIED);
85 data = SCM_VELTS (res);
86 for (;
87 i && SCM_NIMP (l) && SCM_CONSP (l);
88 --i, l = SCM_CDR (l))
89 *data++ = SCM_CAR (l);
90 return res;
91 }
92
93
94 SCM_PROC(s_weak_vector_p, "weak-vector?", 1, 0, 0, scm_weak_vector_p);
95
96 SCM
97 scm_weak_vector_p (x)
98 SCM x;
99 {
100 return ((SCM_NIMP (x) && SCM_WVECTP (x) && !SCM_IS_WHVEC (x))
101 ? SCM_BOOL_T
102 : SCM_BOOL_F);
103 }
104
105
106
107 \f
108
109
110
111 SCM_PROC(s_make_weak_key_hash_table, "make-weak-key-hash-table", 1, 0, 0, scm_make_weak_key_hash_table);
112
113 SCM
114 scm_make_weak_key_hash_table (k)
115 SCM k;
116 {
117 SCM v;
118 SCM_ASSERT (SCM_INUMP (k), k, SCM_ARG1, s_make_weak_key_hash_table);
119 v = scm_make_weak_vector (k, SCM_EOL);
120 SCM_ALLOW_INTS;
121 SCM_VELTS (v)[-1] = 1;
122 SCM_ALLOW_INTS;
123 return v;
124 }
125
126
127 SCM_PROC (s_make_weak_value_hash_table, "make-weak-value-hash-table", 1, 0, 0, scm_make_weak_value_hash_table);
128
129 SCM
130 scm_make_weak_value_hash_table (k)
131 SCM k;
132 {
133 SCM v;
134 SCM_ASSERT (SCM_INUMP (k), k, SCM_ARG1, s_make_weak_value_hash_table);
135 v = scm_make_weak_vector (k, SCM_EOL);
136 SCM_ALLOW_INTS;
137 SCM_VELTS (v)[-1] = 2;
138 SCM_ALLOW_INTS;
139 return v;
140 }
141
142
143
144 SCM_PROC (s_make_doubly_weak_hash_table, "make-doubly-weak-hash-table", 1, 0, 0, scm_make_doubly_weak_hash_table);
145
146 SCM
147 scm_make_doubly_weak_hash_table (k)
148 SCM k;
149 {
150 SCM v;
151 SCM_ASSERT (SCM_INUMP (k), k, SCM_ARG1, s_make_doubly_weak_hash_table);
152 v = scm_make_weak_vector (k, SCM_EOL);
153 SCM_ALLOW_INTS;
154 SCM_VELTS (v)[-1] = 3;
155 SCM_ALLOW_INTS;
156 return v;
157 }
158
159 SCM_PROC(s_weak_key_hash_table_p, "weak-key-hash-table?", 1, 0, 0, scm_weak_key_hash_table_p);
160
161 SCM
162 scm_weak_key_hash_table_p (x)
163 SCM x;
164 {
165 return ((SCM_NIMP (x) && SCM_WVECTP (x) && SCM_IS_WHVEC(x))
166 ? SCM_BOOL_T
167 : SCM_BOOL_F);
168 }
169
170
171 SCM_PROC (s_weak_value_hash_table_p, "weak-value-hash-table?", 1, 0, 0, scm_weak_value_hash_table_p);
172
173 SCM
174 scm_weak_value_hash_table_p (x)
175 SCM x;
176 {
177 return ((SCM_NIMP (x) && SCM_WVECTP (x) && SCM_IS_WHVEC_V(x))
178 ? SCM_BOOL_T
179 : SCM_BOOL_F);
180 }
181
182
183 SCM_PROC (s_doubly_weak_hash_table_p, "doubly-weak-hash-table?", 1, 0, 0, scm_doubly_weak_hash_table_p);
184
185 SCM
186 scm_doubly_weak_hash_table_p (x)
187 SCM x;
188 {
189 return ((SCM_NIMP (x) && SCM_WVECTP (x) && SCM_IS_WHVEC_B (x))
190 ? SCM_BOOL_T
191 : SCM_BOOL_F);
192 }
193
194
195 \f
196
197
198 void
199 scm_init_weaks ()
200 {
201 #include "weaks.x"
202 }
203