diff options
author | Ludovic Courtès <ludo@gnu.org> | 2009-06-22 00:51:08 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2009-06-22 01:09:39 +0200 |
commit | 438974d08dcb96a01fe62ea9b0446b8420e703c4 (patch) | |
tree | 94b75ea2cf4c9d1b4c6fda2dbecaac1b49f9ecf6 /libguile/vectors.c | |
parent | 404bb5f87b66709206507acdf7b899101185a7a0 (diff) |
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.
Diffstat (limited to 'libguile/vectors.c')
-rw-r--r-- | libguile/vectors.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libguile/vectors.c b/libguile/vectors.c index ae0fc319f..6dc994f55 100644 --- a/libguile/vectors.c +++ b/libguile/vectors.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2006, 2008 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2006, 2008, 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 @@ -31,6 +31,7 @@ #include "libguile/validate.h" #include "libguile/vectors.h" #include "libguile/unif.h" +#include "libguile/bytevectors.h" #include "libguile/ramap.h" #include "libguile/srfi-4.h" #include "libguile/strings.h" @@ -523,7 +524,7 @@ SCM_DEFINE (scm_vector_move_right_x, "vector-move-right!", 5, 0, 0, } #undef FUNC_NAME - + /* Generalized vectors. */ int @@ -532,7 +533,8 @@ scm_is_generalized_vector (SCM obj) return (scm_is_vector (obj) || scm_is_string (obj) || scm_is_bitvector (obj) - || scm_is_uniform_vector (obj)); + || scm_is_uniform_vector (obj) + || scm_is_bytevector (obj)); } SCM_DEFINE (scm_generalized_vector_p, "generalized-vector?", 1, 0, 0, @@ -564,6 +566,8 @@ scm_c_generalized_vector_length (SCM v) return scm_c_bitvector_length (v); else if (scm_is_uniform_vector (v)) return scm_c_uniform_vector_length (v); + else if (scm_is_bytevector (v)) + return scm_c_bytevector_length (v); else scm_wrong_type_arg_msg (NULL, 0, v, "generalized vector"); } @@ -588,6 +592,8 @@ scm_c_generalized_vector_ref (SCM v, size_t idx) return scm_c_bitvector_ref (v, idx); else if (scm_is_uniform_vector (v)) return scm_c_uniform_vector_ref (v, idx); + else if (scm_is_bytevector (v)) + return scm_from_uint8 (scm_c_bytevector_ref (v, idx)); else scm_wrong_type_arg_msg (NULL, 0, v, "generalized vector"); } @@ -613,6 +619,8 @@ scm_c_generalized_vector_set_x (SCM v, size_t idx, SCM val) scm_c_bitvector_set_x (v, idx, val); else if (scm_is_uniform_vector (v)) scm_c_uniform_vector_set_x (v, idx, val); + else if (scm_is_bytevector (v)) + scm_i_bytevector_generalized_set_x (v, idx, val); else scm_wrong_type_arg_msg (NULL, 0, v, "generalized vector"); } |