summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Llorens <lloda@sarc.name>2020-02-05 17:23:40 +0100
committerDaniel Llorens <lloda@sarc.name>2020-04-09 16:59:39 +0200
commitefe2317aff1da9f4310f33a0eb246e6630534227 (patch)
tree91f1a0c2ac801b6ee6d03c500e8758a5ccaedfc2
parent88d690e15ee89c3331a84cb73700b0653c1a57c7 (diff)
downloadguile-efe2317aff1da9f4310f33a0eb246e6630534227.tar.gz
Move bitvector functions using array_handle to libguile/array-handle.[ch]
-rw-r--r--NEWS-wip-vector-cleanup.txt2
-rw-r--r--libguile/array-handle.c28
-rw-r--r--libguile/array-handle.h4
-rw-r--r--libguile/bitvectors.c22
-rw-r--r--libguile/bitvectors.h5
-rw-r--r--libguile/posix.c1
-rw-r--r--libguile/vectors.c1
-rw-r--r--libguile/vectors.h2
8 files changed, 35 insertions, 30 deletions
diff --git a/NEWS-wip-vector-cleanup.txt b/NEWS-wip-vector-cleanup.txt
index c0cbaf256..b8770e1e7 100644
--- a/NEWS-wip-vector-cleanup.txt
+++ b/NEWS-wip-vector-cleanup.txt
@@ -58,6 +58,8 @@ instead of the correct result #1@1(0 1 2 0 0). This buggy support has been remov
* 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
- 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).
diff --git a/libguile/array-handle.c b/libguile/array-handle.c
index 6ca19cccb..6c30d77b9 100644
--- a/libguile/array-handle.c
+++ b/libguile/array-handle.c
@@ -333,6 +333,10 @@ scm_array_handle_release (scm_t_array_handle *h)
*/
}
+// -----------------------------------------------
+// scm_array_handle_TYPE_(writable_)elements FIXME
+// -----------------------------------------------
+
const SCM *
scm_array_handle_elements (scm_t_array_handle *h)
{
@@ -352,10 +356,32 @@ 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 *
scm_array1_bit_elements (SCM vec, size_t *lenp, ssize_t *incp, size_t *offp)
{
scm_t_array_handle h;
diff --git a/libguile/array-handle.h b/libguile/array-handle.h
index 4a97bc19f..c2ff20429 100644
--- a/libguile/array-handle.h
+++ b/libguile/array-handle.h
@@ -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_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 uint32_t * scm_array1_bit_writable_elements (SCM vec, size_t *lenp, ssize_t *incp, size_t *offp);
diff --git a/libguile/bitvectors.c b/libguile/bitvectors.c
index fa549bb71..9ae410dfa 100644
--- a/libguile/bitvectors.c
+++ b/libguile/bitvectors.c
@@ -183,28 +183,6 @@ SCM_DEFINE (scm_bitvector_length, "bitvector-length", 1, 0, 0,
}
#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) \
do { \
SCM_ASSERT_TYPE (IS_BITVECTOR (v), v, pos, __func__, \
diff --git a/libguile/bitvectors.h b/libguile/bitvectors.h
index 1c5b7dfcc..b3a30b5ea 100644
--- a/libguile/bitvectors.h
+++ b/libguile/bitvectors.h
@@ -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 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 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 uint32_t *scm_bitvector_writable_elements (SCM vec, size_t *lenp);
diff --git a/libguile/posix.c b/libguile/posix.c
index ca561f0ae..d7ecda506 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -65,6 +65,7 @@
#include "async.h"
#include "bitvectors.h"
+#include "array-handle.h"
#include "dynwind.h"
#include "extensions.h"
#include "feature.h"
diff --git a/libguile/vectors.c b/libguile/vectors.c
index 56f475fb6..6df2dc58d 100644
--- a/libguile/vectors.c
+++ b/libguile/vectors.c
@@ -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)
-
void
scm_init_vectors ()
{
diff --git a/libguile/vectors.h b/libguile/vectors.h
index 455e39432..fe5f92779 100644
--- a/libguile/vectors.h
+++ b/libguile/vectors.h
@@ -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)
SCM_INTERNAL SCM scm_i_vector_equal_p (SCM x, SCM y);
-
-
SCM_INTERNAL void scm_init_vectors (void);
#endif /* SCM_VECTORS_H */