*** empty log message ***
[bpt/guile.git] / libguile / weaks.c
CommitLineData
7dc6e754 1/* Copyright (C) 1995,1996,1998 Free Software Foundation, Inc.
0f2d19dd
JB
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
82892bed
JB
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
0f2d19dd
JB
17 *
18 * As a special exception, Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of this library.
20 *
21 * The exception is that, if you link this library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking this library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by
31 * Free Software Foundation as part of this library. If you copy
32 * code from other releases distributed under the terms of the GPL into a copy of
33 * this library, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from such code.
37 *
38 * If you write modifications of your own for this library, it is your choice
39 * whether to permit this exception to apply to your modifications.
82892bed 40 * If you do not wish that, delete this exception notice. */
0f2d19dd
JB
41\f
42#include <stdio.h>
43#include "_scm.h"
44
20e6290e 45#include "weaks.h"
0f2d19dd
JB
46\f
47
48
49/* {Weak Vectors}
50 */
51
52
53SCM_PROC(s_make_weak_vector, "make-weak-vector", 1, 1, 0, scm_make_weak_vector);
1cc91f1b 54
0f2d19dd
JB
55SCM
56scm_make_weak_vector (k, fill)
57 SCM k;
58 SCM fill;
0f2d19dd
JB
59{
60 SCM v;
250da369 61 v = scm_make_vector (scm_sum (k, SCM_MAKINUM (2)), fill);
0f2d19dd
JB
62 SCM_DEFER_INTS;
63 SCM_SETLENGTH(v, SCM_INUM (k), scm_tc7_wvect);
250da369
JB
64 SCM_VELTS(v)[0] = SCM_EOL;
65 SCM_VELTS(v)[1] = (SCM)0;
66 SCM_SETVELTS(v, SCM_VELTS(v) + 2);
0f2d19dd
JB
67 SCM_ALLOW_INTS;
68 return v;
69}
70
71
72SCM_PROC(s_weak_vector, "weak-vector", 0, 0, 1, scm_weak_vector);
73SCM_PROC(s_list_to_weak_vector, "list->weak-vector", 1, 0, 0, scm_weak_vector);
1cc91f1b 74
0f2d19dd
JB
75SCM
76scm_weak_vector (l)
77 SCM l;
0f2d19dd
JB
78{
79 SCM res;
80 register SCM *data;
81 long i;
82
83 i = scm_ilength (l);
84 SCM_ASSERT (i >= 0, l, SCM_ARG1, s_weak_vector);
85 res = scm_make_weak_vector (SCM_MAKINUM (i), SCM_UNSPECIFIED);
86 data = SCM_VELTS (res);
87 for (;
88 i && SCM_NIMP (l) && SCM_CONSP (l);
89 --i, l = SCM_CDR (l))
90 *data++ = SCM_CAR (l);
91 return res;
92}
93
94
95SCM_PROC(s_weak_vector_p, "weak-vector?", 1, 0, 0, scm_weak_vector_p);
1cc91f1b 96
0f2d19dd
JB
97SCM
98scm_weak_vector_p (x)
99 SCM x;
0f2d19dd
JB
100{
101 return ((SCM_NIMP (x) && SCM_WVECTP (x) && !SCM_IS_WHVEC (x))
102 ? SCM_BOOL_T
103 : SCM_BOOL_F);
104}
105
106
107
108\f
109
110
111
8d71b0ce 112SCM_PROC(s_make_weak_key_hash_table, "make-weak-key-hash-table", 1, 0, 0, scm_make_weak_key_hash_table);
1cc91f1b 113
0f2d19dd 114SCM
8d71b0ce 115scm_make_weak_key_hash_table (k)
0f2d19dd 116 SCM k;
0f2d19dd
JB
117{
118 SCM v;
8d71b0ce 119 SCM_ASSERT (SCM_INUMP (k), k, SCM_ARG1, s_make_weak_key_hash_table);
0f2d19dd
JB
120 v = scm_make_weak_vector (k, SCM_EOL);
121 SCM_ALLOW_INTS;
122 SCM_VELTS (v)[-1] = 1;
123 SCM_ALLOW_INTS;
124 return v;
125}
126
127
128SCM_PROC (s_make_weak_value_hash_table, "make-weak-value-hash-table", 1, 0, 0, scm_make_weak_value_hash_table);
1cc91f1b 129
0f2d19dd
JB
130SCM
131scm_make_weak_value_hash_table (k)
132 SCM k;
0f2d19dd
JB
133{
134 SCM v;
135 SCM_ASSERT (SCM_INUMP (k), k, SCM_ARG1, s_make_weak_value_hash_table);
136 v = scm_make_weak_vector (k, SCM_EOL);
137 SCM_ALLOW_INTS;
138 SCM_VELTS (v)[-1] = 2;
139 SCM_ALLOW_INTS;
140 return v;
141}
142
143
144
145SCM_PROC (s_make_doubly_weak_hash_table, "make-doubly-weak-hash-table", 1, 0, 0, scm_make_doubly_weak_hash_table);
1cc91f1b 146
0f2d19dd
JB
147SCM
148scm_make_doubly_weak_hash_table (k)
149 SCM k;
0f2d19dd
JB
150{
151 SCM v;
8d71b0ce 152 SCM_ASSERT (SCM_INUMP (k), k, SCM_ARG1, s_make_doubly_weak_hash_table);
0f2d19dd
JB
153 v = scm_make_weak_vector (k, SCM_EOL);
154 SCM_ALLOW_INTS;
155 SCM_VELTS (v)[-1] = 3;
156 SCM_ALLOW_INTS;
157 return v;
158}
159
8d71b0ce 160SCM_PROC(s_weak_key_hash_table_p, "weak-key-hash-table?", 1, 0, 0, scm_weak_key_hash_table_p);
1cc91f1b 161
0f2d19dd 162SCM
8d71b0ce 163scm_weak_key_hash_table_p (x)
0f2d19dd 164 SCM x;
0f2d19dd
JB
165{
166 return ((SCM_NIMP (x) && SCM_WVECTP (x) && SCM_IS_WHVEC(x))
167 ? SCM_BOOL_T
168 : SCM_BOOL_F);
169}
170
171
172SCM_PROC (s_weak_value_hash_table_p, "weak-value-hash-table?", 1, 0, 0, scm_weak_value_hash_table_p);
1cc91f1b 173
0f2d19dd
JB
174SCM
175scm_weak_value_hash_table_p (x)
176 SCM x;
0f2d19dd
JB
177{
178 return ((SCM_NIMP (x) && SCM_WVECTP (x) && SCM_IS_WHVEC_V(x))
179 ? SCM_BOOL_T
180 : SCM_BOOL_F);
181}
182
183
184SCM_PROC (s_doubly_weak_hash_table_p, "doubly-weak-hash-table?", 1, 0, 0, scm_doubly_weak_hash_table_p);
1cc91f1b 185
0f2d19dd
JB
186SCM
187scm_doubly_weak_hash_table_p (x)
188 SCM x;
0f2d19dd
JB
189{
190 return ((SCM_NIMP (x) && SCM_WVECTP (x) && SCM_IS_WHVEC_B (x))
191 ? SCM_BOOL_T
192 : SCM_BOOL_F);
193}
194
195
196\f
197
1cc91f1b 198
0f2d19dd
JB
199void
200scm_init_weaks ()
0f2d19dd
JB
201{
202#include "weaks.x"
203}
204