vectors.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 SCM scm_vector_copy_partial (SCM vec, SCM start, SCM end);
  34. SCM_API SCM scm_vector_copy_x (SCM dst, SCM at, SCM src, SCM start, SCM end);
  35. SCM_API int scm_is_vector (SCM obj);
  36. SCM_API SCM scm_c_make_vector (size_t len, SCM fill);
  37. SCM_API size_t scm_c_vector_length (SCM vec);
  38. SCM_API SCM scm_c_vector_ref (SCM vec, size_t k);
  39. SCM_API void scm_c_vector_set_x (SCM vec, size_t k, SCM obj);
  40. SCM_API const SCM *scm_vector_elements (SCM array,
  41. scm_t_array_handle *h,
  42. size_t *lenp, ssize_t *incp);
  43. SCM_API SCM *scm_vector_writable_elements (SCM array,
  44. scm_t_array_handle *h,
  45. size_t *lenp, ssize_t *incp);
  46. #define SCM_VALIDATE_VECTOR(pos, v) \
  47. do { \
  48. SCM_ASSERT (scm_is_vector (v), v, pos, FUNC_NAME); \
  49. } while (0)
  50. #define SCM_VALIDATE_VECTOR_LEN(pos, v, len) \
  51. do { \
  52. SCM_ASSERT (scm_is_vector (v) && len == scm_c_vector_length (v), v, pos, FUNC_NAME); \
  53. } while (0)
  54. /* Fast, non-checking accessors
  55. */
  56. #define SCM_SIMPLE_VECTOR_LENGTH(x) SCM_I_VECTOR_LENGTH(x)
  57. #define SCM_SIMPLE_VECTOR_REF(x,idx) ((SCM_I_VECTOR_ELTS(x))[idx])
  58. #define SCM_SIMPLE_VECTOR_SET(x,idx,val) ((SCM_I_VECTOR_WELTS(x))[idx]=(val))
  59. /* Internals */
  60. /* Vectors residualized into compiled objects have scm_tc7_vector in the
  61. low 7 bits, but also an additional bit set to indicate
  62. immutability. */
  63. #define SCM_F_VECTOR_IMMUTABLE 0x80UL
  64. #define SCM_I_IS_MUTABLE_VECTOR(x) \
  65. (SCM_NIMP (x) && \
  66. ((SCM_CELL_TYPE (x) & (0x7f | SCM_F_VECTOR_IMMUTABLE)) \
  67. == scm_tc7_vector))
  68. #define SCM_I_IS_VECTOR(x) (SCM_HAS_TYP7 (x, scm_tc7_vector))
  69. #define SCM_I_VECTOR_ELTS(x) ((const SCM *) SCM_I_VECTOR_WELTS (x))
  70. #define SCM_I_VECTOR_WELTS(x) (SCM_CELL_OBJECT_LOC (x, 1))
  71. #define SCM_I_VECTOR_LENGTH(x) (((size_t) SCM_CELL_WORD_0 (x)) >> 8)
  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 */