(scm_string_filter, scm_string_delete): For char and
[bpt/guile.git] / libguile / srfi-4.i.c
index 755589f..101eb38 100644 (file)
@@ -1,4 +1,4 @@
-/* This file defines the procedures related to one type of homogenous
+/* This file defines the procedures related to one type of uniform
    numeric vector.  It is included multiple time in srfi-4.c, once for
    each type.
 
@@ -21,6 +21,8 @@
    The C type of the elements, for example scm_t_uint8.  The code
    below will never do sizeof (CTYPE), thus you can use just 'float'
    for the c32 type, for example.
+
+   When CTYPE is not defined, the functions using it are excluded.
 */
 
 /* The first level does not expand macros in the arguments. */
@@ -45,7 +47,7 @@ SCM_DEFINE (F(scm_,TAG,vector_p), S(TAG)"vector?", 1, 0, 0,
 
 SCM_DEFINE (F(scm_make_,TAG,vector), "make-"S(TAG)"vector", 1, 1, 0,
             (SCM len, SCM fill),
-           "Return a newly allocated homogeneous numeric vector which can\n"
+           "Return a newly allocated uniform numeric vector which can\n"
            "hold @var{len} elements.  If @var{fill} is given, it is used to\n"
            "initialize the elements, otherwise the contents of the vector\n"
            "is unspecified.")
@@ -55,17 +57,9 @@ SCM_DEFINE (F(scm_make_,TAG,vector), "make-"S(TAG)"vector", 1, 1, 0,
 }
 #undef FUNC_NAME
 
-SCM
-F(scm_take_,TAG,vector) (const CTYPE *data, size_t n)
-{
-  scm_gc_register_collectable_memory ((void *)data, n*uvec_sizes[TYPE],
-                                     uvec_names[TYPE]);
-  return take_uvec (TYPE, data, n);
-}
-
 SCM_DEFINE (F(scm_,TAG,vector), S(TAG)"vector", 0, 0, 1,
             (SCM l),
-           "Return a newly allocated homogeneous numeric vector containing\n"
+           "Return a newly allocated uniform numeric vector containing\n"
            "all argument values.")
 #define FUNC_NAME s_F(scm_,TAG,vector)
 {
@@ -76,7 +70,7 @@ SCM_DEFINE (F(scm_,TAG,vector), S(TAG)"vector", 0, 0, 1,
 
 SCM_DEFINE (F(scm_,TAG,vector_length), S(TAG)"vector-length", 1, 0, 0,
             (SCM uvec),
-           "Return the number of elements in the homogeneous numeric vector\n"
+           "Return the number of elements in the uniform numeric vector\n"
            "@var{uvec}.")
 #define FUNC_NAME s_F(scm_,TAG,vector_length)
 {
@@ -87,7 +81,7 @@ SCM_DEFINE (F(scm_,TAG,vector_length), S(TAG)"vector-length", 1, 0, 0,
 
 SCM_DEFINE (F(scm_,TAG,vector_ref), S(TAG)"vector-ref", 2, 0, 0,
             (SCM uvec, SCM index),
-           "Return the element at @var{index} in the homogeneous numeric\n"
+           "Return the element at @var{index} in the uniform numeric\n"
            "vector @var{uvec}.")
 #define FUNC_NAME s_F(scm_,TAG,vector_ref)
 {
@@ -98,7 +92,7 @@ SCM_DEFINE (F(scm_,TAG,vector_ref), S(TAG)"vector-ref", 2, 0, 0,
 
 SCM_DEFINE (F(scm_,TAG,vector_set_x), S(TAG)"vector-set!", 3, 0, 0,
             (SCM uvec, SCM index, SCM value),
-           "Set the element at @var{index} in the homogeneous numeric\n"
+           "Set the element at @var{index} in the uniform numeric\n"
            "vector @var{uvec} to @var{value}.  The return value is not\n"
            "specified.")
 #define FUNC_NAME s_F(scm_,TAG,vector_set_x)
@@ -110,7 +104,7 @@ SCM_DEFINE (F(scm_,TAG,vector_set_x), S(TAG)"vector-set!", 3, 0, 0,
 
 SCM_DEFINE (F(scm_,TAG,vector_to_list), S(TAG)"vector->list", 1, 0, 0,
             (SCM uvec),
-           "Convert the homogeneous numeric vector @var{uvec} to a list.")
+           "Convert the uniform numeric vector @var{uvec} to a list.")
 #define FUNC_NAME s_F(scm_,TAG,vector_to_list)
 {
   return uvec_to_list (TYPE, uvec);
@@ -120,7 +114,7 @@ SCM_DEFINE (F(scm_,TAG,vector_to_list), S(TAG)"vector->list", 1, 0, 0,
 
 SCM_DEFINE (F(scm_list_to_,TAG,vector), "list->"S(TAG)"vector", 1, 0, 0,
             (SCM l),
-           "Convert the list @var{l} to a numeric homogeneous vector.")
+           "Convert the list @var{l} to a numeric uniform vector.")
 #define FUNC_NAME s_F(scm_list_to_,TAG,vector)
 {
   return list_to_uvec (TYPE, l);
@@ -130,7 +124,7 @@ SCM_DEFINE (F(scm_list_to_,TAG,vector), "list->"S(TAG)"vector", 1, 0, 0,
 SCM_DEFINE (F(scm_any_to_,TAG,vector), "any->"S(TAG)"vector", 1, 0, 0,
            (SCM obj),
            "Convert @var{obj}, which can be a list, vector, or\n"
-           "homogenous vector, to a numeric homogenous vector of\n"
+           "uniform vector, to a numeric uniform vector of\n"
            "type " S(TAG)".")
 #define FUNC_NAME s_F(scm_any_to_,TAG,vector)
 {
@@ -138,11 +132,70 @@ SCM_DEFINE (F(scm_any_to_,TAG,vector), "any->"S(TAG)"vector", 1, 0, 0,
 }
 #undef FUNC_NAME
 
+#ifdef CTYPE
+
+SCM
+F(scm_take_,TAG,vector) (const CTYPE *data, size_t n)
+{
+  scm_gc_register_collectable_memory ((void *)data, n*uvec_sizes[TYPE],
+                                     uvec_names[TYPE]);
+  return take_uvec (TYPE, data, n);
+}
+
+const CTYPE *
+F(scm_array_handle_,TAG,_elements) (scm_t_array_handle *h)
+{
+  return F(scm_array_handle_,TAG,_writable_elements) (h);
+}
+
 CTYPE *
-F(scm_,TAG,vector_elements) (SCM obj)
+F(scm_array_handle_,TAG,_writable_elements) (scm_t_array_handle *h)
+{
+  SCM vec = h->array;
+  if (SCM_I_ARRAYP (vec))
+    vec = SCM_I_ARRAY_V (vec);
+  uvec_assert (TYPE, vec);
+  if (TYPE == SCM_UVEC_C32 || TYPE == SCM_UVEC_C64)
+    return ((CTYPE *)SCM_UVEC_BASE (vec)) + 2*h->base;
+  else
+    return ((CTYPE *)SCM_UVEC_BASE (vec)) + h->base;
+}
+
+const CTYPE *
+F(scm_,TAG,vector_elements) (SCM uvec, 
+                            scm_t_array_handle *h,
+                            size_t *lenp, ssize_t *incp)
+{
+  return F(scm_,TAG,vector_writable_elements) (uvec, h, lenp, incp);
+}
+
+CTYPE *
+F(scm_,TAG,vector_writable_elements) (SCM uvec, 
+                                     scm_t_array_handle *h,
+                                     size_t *lenp, ssize_t *incp)
+{
+  scm_generalized_vector_get_handle (uvec, h);
+  if (lenp)
+    {
+      scm_t_array_dim *dim = scm_array_handle_dims (h);
+      *lenp = dim->ubnd - dim->lbnd + 1;
+      *incp = dim->inc;
+    }
+  return F(scm_array_handle_,TAG,_writable_elements) (h);
+}
+
+#endif
+
+static SCM
+F(,TAG,ref) (scm_t_array_handle *handle, ssize_t pos)
+{
+  return uvec_fast_ref (TYPE, handle->elements, pos);
+}
+
+static void
+F(,TAG,set) (scm_t_array_handle *handle, ssize_t pos, SCM val)
 {
-  uvec_assert (TYPE, obj);
-  return (CTYPE *)SCM_UVEC_BASE (obj);
+  uvec_fast_set_x (TYPE, handle->writable_elements, pos, val);
 }
 
 #undef paste