1 /* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004, 2005, 2006, 2009 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "libguile/_scm.h"
27 #include "libguile/__scm.h"
29 #include "libguile/uniform.h"
32 const size_t scm_i_array_element_type_sizes
[SCM_ARRAY_ELEMENT_TYPE_LAST
+ 1] = {
46 scm_array_handle_uniform_element_size (scm_t_array_handle
*h
)
48 size_t ret
= scm_i_array_element_type_sizes
[h
->element_type
];
49 if (ret
&& ret
% 8 == 0)
52 scm_wrong_type_arg_msg (NULL
, 0, h
->array
, "byte-aligned uniform array");
54 scm_wrong_type_arg_msg (NULL
, 0, h
->array
, "uniform array");
58 scm_array_handle_uniform_element_bit_size (scm_t_array_handle
*h
)
60 size_t ret
= scm_i_array_element_type_sizes
[h
->element_type
];
64 scm_wrong_type_arg_msg (NULL
, 0, h
->array
, "uniform array");
68 scm_array_handle_uniform_elements (scm_t_array_handle
*h
)
70 return scm_array_handle_uniform_writable_elements (h
);
74 scm_array_handle_uniform_writable_elements (scm_t_array_handle
*h
)
79 esize
= scm_array_handle_uniform_element_size (h
);
80 ret
= ((scm_t_uint8
*) h
->writable_elements
) + h
->base
* esize
;
85 scm_is_uniform_vector (SCM obj
)
90 if (scm_is_generalized_vector (obj
))
92 scm_generalized_vector_get_handle (obj
, &h
);
93 ret
= SCM_ARRAY_ELEMENT_TYPE_IS_UNBOXED (h
.element_type
);
94 scm_array_handle_release (&h
);
100 scm_c_uniform_vector_length (SCM uvec
)
102 scm_t_array_handle h
;
106 scm_uniform_vector_elements (uvec
, &h
, &len
, &inc
);
107 scm_array_handle_release (&h
);
111 SCM_DEFINE (scm_uniform_vector_p
, "uniform-vector?", 1, 0, 0,
113 "Return @code{#t} if @var{obj} is a uniform vector.")
114 #define FUNC_NAME s_scm_uniform_vector_p
116 return scm_from_bool (scm_is_uniform_vector (obj
));
120 SCM_DEFINE (scm_uniform_vector_element_type
, "uniform-vector-element-type", 1, 0, 0,
122 "Return the type of the elements in the uniform vector, @var{v}.")
123 #define FUNC_NAME s_scm_uniform_vector_element_type
125 scm_t_array_handle h
;
128 if (!scm_is_uniform_vector (v
))
129 scm_wrong_type_arg_msg (FUNC_NAME
, SCM_ARG1
, v
, "uniform vector");
130 scm_array_get_handle (v
, &h
);
131 ret
= scm_array_handle_element_type (&h
);
132 scm_array_handle_release (&h
);
137 SCM_DEFINE (scm_uniform_vector_element_size
, "uniform-vector-element-size", 1, 0, 0,
139 "Return the number of bytes allocated to each element in the\n"
140 "uniform vector, @var{v}.")
141 #define FUNC_NAME s_scm_uniform_vector_element_size
143 scm_t_array_handle h
;
147 scm_uniform_vector_elements (v
, &h
, &len
, &inc
);
148 ret
= scm_from_size_t (scm_array_handle_uniform_element_size (&h
));
149 scm_array_handle_release (&h
);
155 scm_c_uniform_vector_ref (SCM v
, size_t idx
)
157 if (!scm_is_uniform_vector (v
))
158 scm_wrong_type_arg_msg (NULL
, 0, v
, "uniform vector");
159 return scm_c_generalized_vector_ref (v
, idx
);
162 SCM_DEFINE (scm_uniform_vector_ref
, "uniform-vector-ref", 2, 0, 0,
164 "Return the element at index @var{idx} of the\n"
165 "homogenous numeric vector @var{v}.")
166 #define FUNC_NAME s_scm_uniform_vector_ref
168 return scm_c_uniform_vector_ref (v
, scm_to_size_t (idx
));
173 scm_c_uniform_vector_set_x (SCM v
, size_t idx
, SCM val
)
175 if (!scm_is_uniform_vector (v
))
176 scm_wrong_type_arg_msg (NULL
, 0, v
, "uniform vector");
177 scm_c_generalized_vector_set_x (v
, idx
, val
);
180 SCM_DEFINE (scm_uniform_vector_set_x
, "uniform-vector-set!", 3, 0, 0,
181 (SCM v
, SCM idx
, SCM val
),
182 "Set the element at index @var{idx} of the\n"
183 "homogenous numeric vector @var{v} to @var{val}.")
184 #define FUNC_NAME s_scm_uniform_vector_set_x
186 scm_c_uniform_vector_set_x (v
, scm_to_size_t (idx
), val
);
187 return SCM_UNSPECIFIED
;
191 SCM_DEFINE (scm_uniform_vector_to_list
, "uniform-vector->list", 1, 0, 0,
193 "Convert the uniform numeric vector @var{uvec} to a list.")
194 #define FUNC_NAME s_scm_uniform_vector_to_list
196 if (!scm_is_uniform_vector (uvec
))
197 scm_wrong_type_arg_msg (FUNC_NAME
, SCM_ARG1
, uvec
, "uniform vector");
198 return scm_generalized_vector_to_list (uvec
);
203 scm_uniform_vector_elements (SCM uvec
,
204 scm_t_array_handle
*h
,
205 size_t *lenp
, ssize_t
*incp
)
207 return scm_uniform_vector_writable_elements (uvec
, h
, lenp
, incp
);
211 scm_uniform_vector_writable_elements (SCM uvec
,
212 scm_t_array_handle
*h
,
213 size_t *lenp
, ssize_t
*incp
)
216 scm_generalized_vector_get_handle (uvec
, h
);
217 /* FIXME nonlocal exit */
218 ret
= scm_array_handle_uniform_writable_elements (h
);
221 scm_t_array_dim
*dim
= scm_array_handle_dims (h
);
222 *lenp
= dim
->ubnd
- dim
->lbnd
+ 1;
228 SCM_DEFINE (scm_uniform_vector_length
, "uniform-vector-length", 1, 0, 0,
230 "Return the number of elements in the uniform vector @var{v}.")
231 #define FUNC_NAME s_scm_uniform_vector_length
233 return scm_from_size_t (scm_c_uniform_vector_length (v
));
239 scm_init_uniform (void)
241 #include "libguile/uniform.x"