mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-23 03:54:12 +02:00
Make bytevectors accessible using the generalized-vector API.
As a side effect, this allows compilation of literal bytevectors ("#vu8(...)"), which gets done by the generic array handling of the GLIL->assembly compiler. * doc/ref/api-compound.texi (Generalized Vectors): Mention bytevectors. (Arrays, Array Syntax): Likewise. * doc/ref/api-data.texi (Bytevectors as Generalized Vectors): New node. * libguile/bytevectors.c (scm_i_bytevector_generalized_set_x): New. * libguile/bytevectors.h (scm_i_bytevector_generalized_set_x): New declaration. * libguile/srfi-4.c (scm_i_generalized_vector_type, scm_array_handle_uniform_element_size, scm_array_handle_uniform_writable_elements): Add support for bytevectors. * libguile/unif.c (type_creator_table): Add `vu8'. (bytevector_ref, bytevector_set): New functions. (memoize_ref, memoize_set): Add support for bytevectors. * libguile/vectors.c (scm_is_generalized_vector, scm_c_generalized_vector_length, scm_c_generalized_vector_ref, scm_c_generalized_vector_set_x): Add support for bytevectors. * test-suite/tests/bytevectors.test ("Generalized Vectors"): New test set.
This commit is contained in:
parent
404bb5f87b
commit
438974d08d
8 changed files with 173 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
|||
/* srfi-4.c --- Uniform numeric vector datatypes.
|
||||
*
|
||||
* Copyright (C) 2001, 2004, 2006 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2001, 2004, 2006, 2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
|
@ -29,6 +29,7 @@
|
|||
#include "libguile/_scm.h"
|
||||
#include "libguile/__scm.h"
|
||||
#include "libguile/srfi-4.h"
|
||||
#include "libguile/bytevectors.h"
|
||||
#include "libguile/error.h"
|
||||
#include "libguile/read.h"
|
||||
#include "libguile/ports.h"
|
||||
|
@ -609,6 +610,8 @@ scm_i_generalized_vector_type (SCM v)
|
|||
return scm_sym_b;
|
||||
else if (scm_is_uniform_vector (v))
|
||||
return scm_from_locale_symbol (uvec_tags[SCM_UVEC_TYPE(v)]);
|
||||
else if (scm_is_bytevector (v))
|
||||
return scm_from_locale_symbol ("vu8");
|
||||
else
|
||||
return SCM_BOOL_F;
|
||||
}
|
||||
|
@ -750,6 +753,8 @@ scm_array_handle_uniform_element_size (scm_t_array_handle *h)
|
|||
vec = SCM_I_ARRAY_V (vec);
|
||||
if (scm_is_uniform_vector (vec))
|
||||
return uvec_sizes[SCM_UVEC_TYPE(vec)];
|
||||
if (scm_is_bytevector (vec))
|
||||
return 1U;
|
||||
scm_wrong_type_arg_msg (NULL, 0, h->array, "uniform array");
|
||||
}
|
||||
|
||||
|
@ -790,6 +795,8 @@ scm_array_handle_uniform_writable_elements (scm_t_array_handle *h)
|
|||
char *elts = SCM_UVEC_BASE (vec);
|
||||
return (void *) (elts + size*h->base);
|
||||
}
|
||||
if (scm_is_bytevector (vec))
|
||||
return SCM_BYTEVECTOR_CONTENTS (vec);
|
||||
scm_wrong_type_arg_msg (NULL, 0, h->array, "uniform array");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue