vectors.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef SCM_VECTORS_H
  2. #define SCM_VECTORS_H
  3. /* Copyright 1995-1996,1998,2000-2002,2004-2006,2008-2009,2011,2014,2018
  4. Free Software Foundation, Inc.
  5. This file is part of Guile.
  6. Guile is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Guile is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with Guile. If not, see
  16. <https://www.gnu.org/licenses/>. */
  17. #include "libguile/array-handle.h"
  18. #include <libguile/error.h>
  19. #include "libguile/gc.h"
  20. SCM_API SCM scm_vector_p (SCM x);
  21. SCM_API SCM scm_vector_length (SCM v);
  22. SCM_API SCM scm_vector (SCM l);
  23. SCM_API SCM scm_vector_ref (SCM v, SCM k);
  24. SCM_API SCM scm_vector_set_x (SCM v, SCM k, SCM obj);
  25. SCM_API SCM scm_make_vector (SCM k, SCM fill);
  26. SCM_API SCM scm_vector_to_list (SCM v);
  27. SCM_API SCM scm_vector_fill_x (SCM v, SCM fill_x);
  28. SCM_API SCM scm_vector_move_left_x (SCM vec1, SCM start1, SCM end1,
  29. SCM vec2, SCM start2);
  30. SCM_API SCM scm_vector_move_right_x (SCM vec1, SCM start1, SCM end1,
  31. SCM vec2, SCM start2);
  32. SCM_API SCM scm_vector_copy (SCM vec);
  33. SCM_API int scm_is_vector (SCM obj);
  34. SCM_API int scm_is_simple_vector (SCM obj);
  35. SCM_API SCM scm_c_make_vector (size_t len, SCM fill);
  36. SCM_API size_t scm_c_vector_length (SCM vec);
  37. SCM_API SCM scm_c_vector_ref (SCM vec, size_t k);
  38. SCM_API void scm_c_vector_set_x (SCM vec, size_t k, SCM obj);
  39. SCM_API const SCM *scm_vector_elements (SCM vec,
  40. scm_t_array_handle *h,
  41. size_t *lenp, ssize_t *incp);
  42. SCM_API SCM *scm_vector_writable_elements (SCM vec,
  43. scm_t_array_handle *h,
  44. size_t *lenp, ssize_t *incp);
  45. #define SCM_VALIDATE_VECTOR(pos, v) \
  46. do { \
  47. SCM_ASSERT (scm_is_vector (v), v, pos, FUNC_NAME); \
  48. } while (0)
  49. #define SCM_VALIDATE_VECTOR_LEN(pos, v, len) \
  50. do { \
  51. SCM_ASSERT (scm_is_vector (v) && len == scm_c_vector_length (v), v, pos, FUNC_NAME); \
  52. } while (0)
  53. /* Fast, non-checking accessors for simple vectors.
  54. */
  55. #define SCM_SIMPLE_VECTOR_LENGTH(x) SCM_I_VECTOR_LENGTH(x)
  56. #define SCM_SIMPLE_VECTOR_REF(x,idx) ((SCM_I_VECTOR_ELTS(x))[idx])
  57. #define SCM_SIMPLE_VECTOR_SET(x,idx,val) ((SCM_I_VECTOR_WELTS(x))[idx]=(val))
  58. /* Internals */
  59. /* Vectors residualized into compiled objects have scm_tc11_vector in the
  60. low 11 bits, but also an additional bit set to indicate
  61. immutability. */
  62. #define SCM_F_VECTOR_IMMUTABLE 0x800UL
  63. #define SCM_I_IS_MUTABLE_VECTOR(x) \
  64. (SCM_NIMP (x) && \
  65. ((SCM_CELL_TYPE (x) & (0x7ff | SCM_F_VECTOR_IMMUTABLE)) \
  66. == scm_tc11_vector))
  67. #define SCM_I_IS_VECTOR(x) (SCM_HAS_TYP11 (x, scm_tc11_vector))
  68. #define SCM_I_VECTOR_ELTS(x) ((const SCM *) SCM_I_VECTOR_WELTS (x))
  69. #define SCM_I_VECTOR_WELTS(x) (SCM_CELL_OBJECT_LOC (x, 1))
  70. /* XXXXXXX On 32-bit systems, the length will be quite limited. Fix. */
  71. #define SCM_I_VECTOR_LENGTH(x) (((size_t) SCM_CELL_WORD_0 (x)) >> 12)
  72. SCM_INTERNAL SCM scm_i_vector_equal_p (SCM x, SCM y);
  73. SCM_INTERNAL void scm_init_vectors (void);
  74. #endif /* SCM_VECTORS_H */