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
28 #include "libguile/_scm.h"
29 #include "libguile/__scm.h"
31 #include "libguile/uniform.h"
34 const size_t scm_i_array_element_type_sizes
[SCM_ARRAY_ELEMENT_TYPE_LAST
+ 1] = {
48 scm_array_handle_uniform_element_size (scm_t_array_handle
*h
)
50 size_t ret
= scm_i_array_element_type_sizes
[h
->element_type
];
51 if (ret
&& ret
% 8 == 0)
54 scm_wrong_type_arg_msg (NULL
, 0, h
->array
, "byte-aligned uniform array");
56 scm_wrong_type_arg_msg (NULL
, 0, h
->array
, "uniform array");
60 scm_array_handle_uniform_element_bit_size (scm_t_array_handle
*h
)
62 size_t ret
= scm_i_array_element_type_sizes
[h
->element_type
];
66 scm_wrong_type_arg_msg (NULL
, 0, h
->array
, "uniform array");
70 scm_array_handle_uniform_elements (scm_t_array_handle
*h
)
72 return scm_array_handle_uniform_writable_elements (h
);
76 scm_array_handle_uniform_writable_elements (scm_t_array_handle
*h
)
81 esize
= scm_array_handle_uniform_element_size (h
);
82 ret
= ((scm_t_uint8
*) h
->writable_elements
) + h
->base
* esize
;
87 scm_is_uniform_vector (SCM obj
)
92 if (scm_is_generalized_vector (obj
))
94 scm_generalized_vector_get_handle (obj
, &h
);
95 ret
= SCM_ARRAY_ELEMENT_TYPE_IS_UNBOXED (h
.element_type
);
96 scm_array_handle_release (&h
);
102 scm_c_uniform_vector_length (SCM uvec
)
104 scm_t_array_handle h
;
108 scm_uniform_vector_elements (uvec
, &h
, &len
, &inc
);
109 scm_array_handle_release (&h
);
113 SCM_DEFINE (scm_uniform_vector_p
, "uniform-vector?", 1, 0, 0,
115 "Return @code{#t} if @var{obj} is a uniform vector.")
116 #define FUNC_NAME s_scm_uniform_vector_p
118 return scm_from_bool (scm_is_uniform_vector (obj
));
122 SCM_DEFINE (scm_uniform_vector_element_type
, "uniform-vector-element-type", 1, 0, 0,
124 "Return the type of the elements in the uniform vector, @var{v}.")
125 #define FUNC_NAME s_scm_uniform_vector_element_type
127 scm_t_array_handle h
;
130 if (!scm_is_uniform_vector (v
))
131 scm_wrong_type_arg_msg (FUNC_NAME
, SCM_ARG1
, v
, "uniform vector");
132 scm_array_get_handle (v
, &h
);
133 ret
= scm_array_handle_element_type (&h
);
134 scm_array_handle_release (&h
);
139 SCM_DEFINE (scm_uniform_vector_element_size
, "uniform-vector-element-size", 1, 0, 0,
141 "Return the number of bytes allocated to each element in the\n"
142 "uniform vector, @var{v}.")
143 #define FUNC_NAME s_scm_uniform_vector_element_size
145 scm_t_array_handle h
;
149 scm_uniform_vector_elements (v
, &h
, &len
, &inc
);
150 ret
= scm_from_size_t (scm_array_handle_uniform_element_size (&h
));
151 scm_array_handle_release (&h
);
157 scm_c_uniform_vector_ref (SCM v
, size_t idx
)
159 if (!scm_is_uniform_vector (v
))
160 scm_wrong_type_arg_msg (NULL
, 0, v
, "uniform vector");
161 return scm_c_generalized_vector_ref (v
, idx
);
164 SCM_DEFINE (scm_uniform_vector_ref
, "uniform-vector-ref", 2, 0, 0,
166 "Return the element at index @var{idx} of the\n"
167 "homogenous numeric vector @var{v}.")
168 #define FUNC_NAME s_scm_uniform_vector_ref
170 return scm_c_uniform_vector_ref (v
, scm_to_size_t (idx
));
175 scm_c_uniform_vector_set_x (SCM v
, size_t idx
, SCM val
)
177 if (!scm_is_uniform_vector (v
))
178 scm_wrong_type_arg_msg (NULL
, 0, v
, "uniform vector");
179 scm_c_generalized_vector_set_x (v
, idx
, val
);
182 SCM_DEFINE (scm_uniform_vector_set_x
, "uniform-vector-set!", 3, 0, 0,
183 (SCM v
, SCM idx
, SCM val
),
184 "Set the element at index @var{idx} of the\n"
185 "homogenous numeric vector @var{v} to @var{val}.")
186 #define FUNC_NAME s_scm_uniform_vector_set_x
188 scm_c_uniform_vector_set_x (v
, scm_to_size_t (idx
), val
);
189 return SCM_UNSPECIFIED
;
193 SCM_DEFINE (scm_uniform_vector_to_list
, "uniform-vector->list", 1, 0, 0,
195 "Convert the uniform numeric vector @var{uvec} to a list.")
196 #define FUNC_NAME s_scm_uniform_vector_to_list
198 if (!scm_is_uniform_vector (uvec
))
199 scm_wrong_type_arg_msg (FUNC_NAME
, SCM_ARG1
, uvec
, "uniform vector");
200 return scm_generalized_vector_to_list (uvec
);
205 scm_uniform_vector_elements (SCM uvec
,
206 scm_t_array_handle
*h
,
207 size_t *lenp
, ssize_t
*incp
)
209 return scm_uniform_vector_writable_elements (uvec
, h
, lenp
, incp
);
213 scm_uniform_vector_writable_elements (SCM uvec
,
214 scm_t_array_handle
*h
,
215 size_t *lenp
, ssize_t
*incp
)
218 scm_generalized_vector_get_handle (uvec
, h
);
219 /* FIXME nonlocal exit */
220 ret
= scm_array_handle_uniform_writable_elements (h
);
223 scm_t_array_dim
*dim
= scm_array_handle_dims (h
);
224 *lenp
= dim
->ubnd
- dim
->lbnd
+ 1;
230 SCM_DEFINE (scm_uniform_vector_length
, "uniform-vector-length", 1, 0, 0,
232 "Return the number of elements in the uniform vector @var{v}.")
233 #define FUNC_NAME s_scm_uniform_vector_length
235 return scm_from_size_t (scm_c_uniform_vector_length (v
));
241 scm_init_uniform (void)
243 #include "libguile/uniform.x"