1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00

Move bitvector functions using array_handle to libguile/array-handle.[ch]

This commit is contained in:
Daniel Llorens 2020-02-05 17:23:40 +01:00
parent 88d690e15e
commit efe2317aff
8 changed files with 35 additions and 30 deletions

View file

@ -58,6 +58,8 @@ instead of the correct result #1@1(0 1 2 0 0). This buggy support has been remov
* Rationale / TODO * Rationale / TODO
The ultimate goal of this patch set is to have arrays be strictly layered above typed vectors so they can be replaced by a different implementation without affecting the latter.
** Status as of 3.0.0 ** Status as of 3.0.0
- The _elements functions require the array handle interface even for true vectors, when all of handle, inc and off are unnecessary. This creates a burden (having to declare & release handles, etc). - The _elements functions require the array handle interface even for true vectors, when all of handle, inc and off are unnecessary. This creates a burden (having to declare & release handles, etc).

View file

@ -333,6 +333,10 @@ scm_array_handle_release (scm_t_array_handle *h)
*/ */
} }
// -----------------------------------------------
// scm_array_handle_TYPE_(writable_)elements FIXME
// -----------------------------------------------
const SCM * const SCM *
scm_array_handle_elements (scm_t_array_handle *h) scm_array_handle_elements (scm_t_array_handle *h)
{ {
@ -352,9 +356,31 @@ scm_array_handle_writable_elements (scm_t_array_handle *h)
} }
// ----------------------------------------------- // -----------------------------------------------
// FIXME adding scm_array1_xxx_(writable_)elements // scm_array1_TYPE_(writable_)elements FIXME
// ----------------------------------------------- // -----------------------------------------------
const uint32_t *
scm_array_handle_bit_elements (scm_t_array_handle *h)
{
if (h->element_type != SCM_ARRAY_ELEMENT_TYPE_BIT)
scm_wrong_type_arg_msg (NULL, 0, h->array, "bit array");
return ((const uint32_t *) h->elements) + h->base/32;
}
uint32_t *
scm_array_handle_bit_writable_elements (scm_t_array_handle *h)
{
if (h->writable_elements != h->elements)
scm_wrong_type_arg_msg (NULL, 0, h->array, "mutable bit array");
return (uint32_t *) scm_array_handle_bit_elements (h);
}
size_t
scm_array_handle_bit_elements_offset (scm_t_array_handle *h)
{
return h->base % 32;
}
const uint32_t * const uint32_t *
scm_array1_bit_elements (SCM vec, size_t *lenp, ssize_t *incp, size_t *offp) scm_array1_bit_elements (SCM vec, size_t *lenp, ssize_t *incp, size_t *offp)
{ {

View file

@ -127,6 +127,10 @@ scm_array_handle_set (scm_t_array_handle *h, ssize_t p, SCM v)
SCM_INTERNAL void scm_init_array_handle (void); SCM_INTERNAL void scm_init_array_handle (void);
SCM_API const uint32_t *scm_array_handle_bit_elements (scm_t_array_handle *h);
SCM_API uint32_t *scm_array_handle_bit_writable_elements (scm_t_array_handle *h);
SCM_API size_t scm_array_handle_bit_elements_offset (scm_t_array_handle *h);
SCM_API const uint32_t * scm_array1_bit_elements (SCM vec, size_t *lenp, ssize_t *incp, size_t *offp); SCM_API const uint32_t * scm_array1_bit_elements (SCM vec, size_t *lenp, ssize_t *incp, size_t *offp);
SCM_API uint32_t * scm_array1_bit_writable_elements (SCM vec, size_t *lenp, ssize_t *incp, size_t *offp); SCM_API uint32_t * scm_array1_bit_writable_elements (SCM vec, size_t *lenp, ssize_t *incp, size_t *offp);

View file

@ -183,28 +183,6 @@ SCM_DEFINE (scm_bitvector_length, "bitvector-length", 1, 0, 0,
} }
#undef FUNC_NAME #undef FUNC_NAME
const uint32_t *
scm_array_handle_bit_elements (scm_t_array_handle *h)
{
if (h->element_type != SCM_ARRAY_ELEMENT_TYPE_BIT)
scm_wrong_type_arg_msg (NULL, 0, h->array, "bit array");
return ((const uint32_t *) h->elements) + h->base/32;
}
uint32_t *
scm_array_handle_bit_writable_elements (scm_t_array_handle *h)
{
if (h->writable_elements != h->elements)
scm_wrong_type_arg_msg (NULL, 0, h->array, "mutable bit array");
return (uint32_t *) scm_array_handle_bit_elements (h);
}
size_t
scm_array_handle_bit_elements_offset (scm_t_array_handle *h)
{
return h->base % 32;
}
#define SCM_VALIDATE_BITVECTOR(pos, v) \ #define SCM_VALIDATE_BITVECTOR(pos, v) \
do { \ do { \
SCM_ASSERT_TYPE (IS_BITVECTOR (v), v, pos, __func__, \ SCM_ASSERT_TYPE (IS_BITVECTOR (v), v, pos, __func__, \

View file

@ -22,7 +22,7 @@
#include "libguile/array-handle.h" #include "libguile/scm.h"
@ -54,9 +54,6 @@ SCM_API SCM scm_c_make_bitvector (size_t len, SCM fill);
SCM_API size_t scm_c_bitvector_length (SCM vec); SCM_API size_t scm_c_bitvector_length (SCM vec);
SCM_API SCM scm_c_bitvector_ref (SCM vec, size_t idx); SCM_API SCM scm_c_bitvector_ref (SCM vec, size_t idx);
SCM_API void scm_c_bitvector_set_x (SCM vec, size_t idx, SCM val); SCM_API void scm_c_bitvector_set_x (SCM vec, size_t idx, SCM val);
SCM_API const uint32_t *scm_array_handle_bit_elements (scm_t_array_handle *h);
SCM_API uint32_t *scm_array_handle_bit_writable_elements (scm_t_array_handle *h);
SCM_API size_t scm_array_handle_bit_elements_offset (scm_t_array_handle *h);
SCM_API const uint32_t *scm_bitvector_elements (SCM vec, size_t *lenp); SCM_API const uint32_t *scm_bitvector_elements (SCM vec, size_t *lenp);
SCM_API uint32_t *scm_bitvector_writable_elements (SCM vec, size_t *lenp); SCM_API uint32_t *scm_bitvector_writable_elements (SCM vec, size_t *lenp);

View file

@ -65,6 +65,7 @@
#include "async.h" #include "async.h"
#include "bitvectors.h" #include "bitvectors.h"
#include "array-handle.h"
#include "dynwind.h" #include "dynwind.h"
#include "extensions.h" #include "extensions.h"
#include "feature.h" #include "feature.h"

View file

@ -405,7 +405,6 @@ SCM_DEFINE (scm_vector_move_right_x, "vector-move-right!", 5, 0, 0,
SCM_VECTOR_IMPLEMENTATION (SCM_ARRAY_ELEMENT_TYPE_SCM, scm_make_vector) SCM_VECTOR_IMPLEMENTATION (SCM_ARRAY_ELEMENT_TYPE_SCM, scm_make_vector)
void void
scm_init_vectors () scm_init_vectors ()
{ {

View file

@ -83,8 +83,6 @@ SCM_API SCM *scm_vector_writable_elements (SCM vec, size_t *lenp);
#define SCM_I_VECTOR_LENGTH(x) (((size_t) SCM_CELL_WORD_0 (x)) >> 8) #define SCM_I_VECTOR_LENGTH(x) (((size_t) SCM_CELL_WORD_0 (x)) >> 8)
SCM_INTERNAL SCM scm_i_vector_equal_p (SCM x, SCM y); SCM_INTERNAL SCM scm_i_vector_equal_p (SCM x, SCM y);
SCM_INTERNAL void scm_init_vectors (void); SCM_INTERNAL void scm_init_vectors (void);
#endif /* SCM_VECTORS_H */ #endif /* SCM_VECTORS_H */