vectors.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /* Copyright 1995-1996,1998-2001,2006,2008-2012,2014,2018-2020
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include <string.h>
  19. #include "array-handle.h"
  20. #include "bdw-gc.h"
  21. #include "boolean.h"
  22. #include "deprecation.h"
  23. #include "eq.h"
  24. #include "generalized-vectors.h"
  25. #include "gsubr.h"
  26. #include "list.h"
  27. #include "numbers.h"
  28. #include "pairs.h"
  29. #include "vectors.h"
  30. #define VECTOR_MAX_LENGTH (SCM_T_BITS_MAX >> 8)
  31. #define SCM_VALIDATE_MUTABLE_VECTOR(pos, v) \
  32. do { \
  33. SCM_ASSERT_TYPE (SCM_I_IS_MUTABLE_VECTOR (v), v, pos, FUNC_NAME, \
  34. "mutable vector"); \
  35. } while (0)
  36. int
  37. scm_is_vector (SCM obj)
  38. {
  39. return SCM_I_IS_VECTOR (obj);
  40. }
  41. const SCM *
  42. scm_vector_elements (SCM array, scm_t_array_handle *h,
  43. size_t *lenp, ssize_t *incp)
  44. {
  45. scm_array_get_handle (array, h);
  46. if (1 != scm_array_handle_rank (h))
  47. {
  48. scm_array_handle_release (h);
  49. scm_wrong_type_arg_msg (NULL, 0, array, "rank 1 array of Scheme values");
  50. }
  51. if (lenp)
  52. {
  53. scm_t_array_dim *dim = scm_array_handle_dims (h);
  54. *lenp = dim->ubnd - dim->lbnd + 1;
  55. *incp = dim->inc;
  56. }
  57. return scm_array_handle_elements (h);
  58. }
  59. SCM *
  60. scm_vector_writable_elements (SCM array, scm_t_array_handle *h,
  61. size_t *lenp, ssize_t *incp)
  62. {
  63. const SCM *ret = scm_vector_elements (array, h, lenp, incp);
  64. if (h->writable_elements != h->elements)
  65. scm_wrong_type_arg_msg (NULL, 0, array, "mutable rank 1 array of Scheme values");
  66. return (SCM *) ret;
  67. }
  68. SCM_DEFINE (scm_vector_p, "vector?", 1, 0, 0,
  69. (SCM obj),
  70. "Return @code{#t} if @var{obj} is a vector, otherwise return\n"
  71. "@code{#f}.")
  72. #define FUNC_NAME s_scm_vector_p
  73. {
  74. return scm_from_bool (scm_is_vector (obj));
  75. }
  76. #undef FUNC_NAME
  77. SCM_DEFINE (scm_vector_length, "vector-length", 1, 0, 0,
  78. (SCM v),
  79. "Returns the number of elements in @var{vector} as an exact integer.")
  80. #define FUNC_NAME s_scm_vector_length
  81. {
  82. return scm_from_size_t (scm_c_vector_length (v));
  83. }
  84. #undef FUNC_NAME
  85. size_t
  86. scm_c_vector_length (SCM v)
  87. #define FUNC_NAME s_scm_vector_length
  88. {
  89. SCM_VALIDATE_VECTOR (1, v);
  90. return SCM_I_VECTOR_LENGTH (v);
  91. }
  92. #undef FUNC_NAME
  93. SCM_REGISTER_PROC (s_list_to_vector, "list->vector", 1, 0, 0, scm_vector);
  94. /*
  95. "Return a newly created vector initialized to the elements of"
  96. "the list @var{list}.\n\n"
  97. "@lisp\n"
  98. "(vector->list '#(dah dah didah)) @result{} (dah dah didah)\n"
  99. "(list->vector '(dididit dah)) @result{} #(dididit dah)\n"
  100. "@end lisp")
  101. */
  102. SCM_DEFINE (scm_vector, "vector", 0, 0, 1,
  103. (SCM l),
  104. "@deffnx {Scheme Procedure} list->vector l\n"
  105. "Return a newly allocated vector composed of the\n"
  106. "given arguments. Analogous to @code{list}.\n"
  107. "\n"
  108. "@lisp\n"
  109. "(vector 'a 'b 'c) @result{} #(a b c)\n"
  110. "@end lisp")
  111. #define FUNC_NAME s_scm_vector
  112. {
  113. SCM res;
  114. SCM *data;
  115. long i, len;
  116. SCM_VALIDATE_LIST_COPYLEN (1, l, len);
  117. res = scm_c_make_vector (len, SCM_UNSPECIFIED);
  118. data = SCM_I_VECTOR_WELTS (res);
  119. i = 0;
  120. while (scm_is_pair (l) && i < len)
  121. {
  122. data[i] = SCM_CAR (l);
  123. l = SCM_CDR (l);
  124. i += 1;
  125. }
  126. return res;
  127. }
  128. #undef FUNC_NAME
  129. SCM_DEFINE (scm_vector_ref, "vector-ref", 2, 0, 0,
  130. (SCM vector, SCM k),
  131. "@var{k} must be a valid index of @var{vector}.\n"
  132. "@samp{Vector-ref} returns the contents of element @var{k} of\n"
  133. "@var{vector}.\n\n"
  134. "@lisp\n"
  135. "(vector-ref '#(1 1 2 3 5 8 13 21) 5) @result{} 8\n"
  136. "(vector-ref '#(1 1 2 3 5 8 13 21)\n"
  137. " (let ((i (round (* 2 (acos -1)))))\n"
  138. " (if (inexact? i)\n"
  139. " (inexact->exact i)\n"
  140. " i))) @result{} 13\n"
  141. "@end lisp")
  142. #define FUNC_NAME s_scm_vector_ref
  143. {
  144. return scm_c_vector_ref (vector, scm_to_size_t (k));
  145. }
  146. #undef FUNC_NAME
  147. SCM
  148. scm_c_vector_ref (SCM v, size_t k)
  149. #define FUNC_NAME s_scm_vector_ref
  150. {
  151. SCM_VALIDATE_VECTOR (1, v);
  152. if (k >= SCM_I_VECTOR_LENGTH (v))
  153. scm_out_of_range (NULL, scm_from_size_t (k));
  154. return SCM_SIMPLE_VECTOR_REF (v, k);
  155. }
  156. #undef FUNC_NAME
  157. SCM_DEFINE (scm_vector_set_x, "vector-set!", 3, 0, 0,
  158. (SCM vector, SCM k, SCM obj),
  159. "@var{k} must be a valid index of @var{vector}.\n"
  160. "@code{Vector-set!} stores @var{obj} in element @var{k} of @var{vector}.\n"
  161. "The value returned by @samp{vector-set!} is unspecified.\n"
  162. "@lisp\n"
  163. "(let ((vec (vector 0 '(2 2 2 2) \"Anna\")))\n"
  164. " (vector-set! vec 1 '(\"Sue\" \"Sue\"))\n"
  165. " vec) @result{} #(0 (\"Sue\" \"Sue\") \"Anna\")\n"
  166. "(vector-set! '#(0 1 2) 1 \"doe\") @result{} @emph{error} ; constant vector\n"
  167. "@end lisp")
  168. #define FUNC_NAME s_scm_vector_set_x
  169. {
  170. scm_c_vector_set_x (vector, scm_to_size_t (k), obj);
  171. return SCM_UNSPECIFIED;
  172. }
  173. #undef FUNC_NAME
  174. void
  175. scm_c_vector_set_x (SCM v, size_t k, SCM obj)
  176. #define FUNC_NAME s_scm_vector_set_x
  177. {
  178. SCM_VALIDATE_MUTABLE_VECTOR (1, v);
  179. if (k >= SCM_I_VECTOR_LENGTH (v))
  180. scm_out_of_range (NULL, scm_from_size_t (k));
  181. SCM_SIMPLE_VECTOR_SET (v, k, obj);
  182. }
  183. #undef FUNC_NAME
  184. SCM_DEFINE (scm_make_vector, "make-vector", 1, 1, 0,
  185. (SCM k, SCM fill),
  186. "Return a newly allocated vector of @var{k} elements. If a\n"
  187. "second argument is given, then each position is initialized to\n"
  188. "@var{fill}. Otherwise the initial contents of each position is\n"
  189. "unspecified.")
  190. #define FUNC_NAME s_scm_make_vector
  191. {
  192. size_t l = scm_to_unsigned_integer (k, 0, VECTOR_MAX_LENGTH);
  193. if (SCM_UNBNDP (fill))
  194. fill = SCM_UNSPECIFIED;
  195. return scm_c_make_vector (l, fill);
  196. }
  197. #undef FUNC_NAME
  198. static SCM
  199. make_vector (size_t size)
  200. {
  201. return scm_words ((size << 8) | scm_tc7_vector, size + 1);
  202. }
  203. SCM
  204. scm_c_make_vector (size_t k, SCM fill)
  205. #define FUNC_NAME s_scm_make_vector
  206. {
  207. SCM vector;
  208. size_t j;
  209. SCM_ASSERT_RANGE (1, scm_from_size_t (k), k <= VECTOR_MAX_LENGTH);
  210. vector = make_vector (k);
  211. for (j = 0; j < k; ++j)
  212. SCM_SIMPLE_VECTOR_SET (vector, j, fill);
  213. return vector;
  214. }
  215. #undef FUNC_NAME
  216. SCM_DEFINE (scm_vector_copy_partial, "vector-copy", 1, 2, 0,
  217. (SCM vec, SCM start, SCM end),
  218. "Returns a freshly allocated vector containing the elements\n"
  219. "of @var{vec} between @var{start} and @var{end}.\n\n"
  220. "@var{start} defaults to 0 and @var{end} defaults to the\n"
  221. "length of @var{vec}.")
  222. #define FUNC_NAME s_scm_vector_copy_partial
  223. {
  224. SCM result;
  225. if (SCM_I_IS_VECTOR (vec))
  226. {
  227. size_t cstart = 0, cend = SCM_I_VECTOR_LENGTH (vec);
  228. if (!SCM_UNBNDP (start))
  229. {
  230. cstart = scm_to_size_t (start);
  231. SCM_ASSERT_RANGE (SCM_ARG2, start, cstart<=cend);
  232. if (!SCM_UNBNDP (end))
  233. {
  234. size_t e = scm_to_size_t (end);
  235. SCM_ASSERT_RANGE (SCM_ARG3, end, e>=cstart && e<=cend);
  236. cend = e;
  237. }
  238. }
  239. size_t len = cend-cstart;
  240. result = make_vector (len);
  241. memcpy (SCM_I_VECTOR_WELTS (result), SCM_I_VECTOR_ELTS (vec) + cstart,
  242. len * sizeof(SCM));
  243. }
  244. else
  245. {
  246. scm_t_array_handle handle;
  247. size_t i, len;
  248. ssize_t inc;
  249. const SCM *src;
  250. SCM *dst;
  251. src = scm_vector_elements (vec, &handle, &len, &inc);
  252. scm_c_issue_deprecation_warning
  253. ("Using vector-copy on arrays is deprecated. "
  254. "Use array-copy instead.");
  255. if (SCM_UNBNDP (start))
  256. scm_misc_error (s_scm_vector_copy_partial, "Too many arguments", SCM_EOL);
  257. result = make_vector (len);
  258. dst = SCM_I_VECTOR_WELTS (result);
  259. for (i = 0; i < len; i++, src += inc)
  260. dst[i] = *src;
  261. scm_array_handle_release (&handle);
  262. }
  263. return result;
  264. }
  265. #undef FUNC_NAME
  266. SCM
  267. scm_vector_copy (SCM vec)
  268. {
  269. return scm_vector_copy_partial (vec, SCM_UNDEFINED, SCM_UNDEFINED);
  270. }
  271. SCM_DEFINE (scm_vector_copy_x, "vector-copy!", 3, 2, 0,
  272. (SCM dst, SCM at, SCM src, SCM start, SCM end),
  273. "Copy a block of elements from @var{src} to @var{dst}, both of which must be\n"
  274. "vectors, starting in @var{dst} at @var{at} and starting in @var{src} at\n"
  275. "@var{start} and ending at @var{end}.\n\n"
  276. "It is an error for @var{dst} to have a length less than\n"
  277. "@var{at} + (@var{end} - @var{start}). @var{at} and @var{start} default\n"
  278. "to 0 and @var{end} defaults to the length of @var{src}.\n\n"
  279. "If source and destination overlap, copying takes place as if the source\n"
  280. "is first copied into a temporary vector and then into the destination.")
  281. #define FUNC_NAME s_scm_vector_copy_x
  282. {
  283. SCM_VALIDATE_MUTABLE_VECTOR (1, dst);
  284. SCM_VALIDATE_VECTOR (3, src);
  285. size_t src_org = 0;
  286. size_t dst_org = scm_to_size_t (at);
  287. size_t src_end = SCM_I_VECTOR_LENGTH (src);
  288. size_t dst_end = SCM_I_VECTOR_LENGTH (dst);
  289. if (!SCM_UNBNDP (start))
  290. {
  291. src_org = scm_to_size_t (start);
  292. SCM_ASSERT_RANGE (SCM_ARG4, start, src_org<=src_end);
  293. if (!SCM_UNBNDP (end))
  294. {
  295. size_t e = scm_to_size_t (end);
  296. SCM_ASSERT_RANGE (SCM_ARG5, end, e>=src_org && e<=src_end);
  297. src_end = e;
  298. }
  299. }
  300. size_t len = src_end-src_org;
  301. SCM_ASSERT_RANGE (SCM_ARG2, at, dst_org<=dst_end && len<=dst_end-dst_org);
  302. memmove (SCM_I_VECTOR_WELTS (dst) + dst_org, SCM_I_VECTOR_ELTS (src) + src_org,
  303. len * sizeof(SCM));
  304. return SCM_UNSPECIFIED;
  305. }
  306. #undef FUNC_NAME
  307. SCM_DEFINE (scm_vector_to_list, "vector->list", 1, 0, 0,
  308. (SCM vec),
  309. "Return a newly allocated list composed of the elements of @var{vec}.\n"
  310. "\n"
  311. "@lisp\n"
  312. "(vector->list '#(dah dah didah)) @result{} (dah dah didah)\n"
  313. "(list->vector '(dididit dah)) @result{} #(dididit dah)\n"
  314. "@end lisp")
  315. #define FUNC_NAME s_scm_vector_to_list
  316. {
  317. SCM res = SCM_EOL;
  318. if (SCM_I_IS_VECTOR (vec))
  319. {
  320. ssize_t len = SCM_I_VECTOR_LENGTH (vec);
  321. const SCM * data = SCM_I_VECTOR_ELTS (vec);
  322. for (ssize_t i = len-1; i >= 0; --i)
  323. res = scm_cons (data[i], res);
  324. }
  325. else
  326. {
  327. const SCM *data;
  328. scm_t_array_handle handle;
  329. size_t i, count, len;
  330. ssize_t inc;
  331. data = scm_vector_elements (vec, &handle, &len, &inc);
  332. scm_c_issue_deprecation_warning
  333. ("Using vector->list on arrays is deprecated. "
  334. "Use array->list instead.");
  335. for (i = (len - 1) * inc, count = 0;
  336. count < len;
  337. i -= inc, count++)
  338. res = scm_cons (data[i], res);
  339. scm_array_handle_release (&handle);
  340. }
  341. return res;
  342. }
  343. #undef FUNC_NAME
  344. static SCM scm_vector_fill_partial_x (SCM vec, SCM fill, SCM start, SCM end);
  345. SCM_DEFINE_STATIC (scm_vector_fill_partial_x, "vector-fill!", 2, 2, 0,
  346. (SCM vec, SCM fill, SCM start, SCM end),
  347. "Assign the value of every location in vector @var{vec} in the range\n"
  348. "[@var{start} ... @var{end}) to @var{fill}. @var{start} defaults\n"
  349. "to 0 and @var{end} defaults to the length of @var{vec}. The value\n"
  350. "returned by @code{vector-fill!} is unspecified.")
  351. #define FUNC_NAME s_scm_vector_fill_partial_x
  352. {
  353. SCM_VALIDATE_MUTABLE_VECTOR(1, vec);
  354. size_t i = 0;
  355. size_t c_end = SCM_I_VECTOR_LENGTH (vec);
  356. SCM *data = SCM_I_VECTOR_WELTS (vec);
  357. if (!SCM_UNBNDP (start))
  358. i = scm_to_unsigned_integer (start, 0, c_end);
  359. if (!SCM_UNBNDP (end))
  360. c_end = scm_to_unsigned_integer (end, i, c_end);
  361. for (; i < c_end; ++i)
  362. data[i] = fill;
  363. return SCM_UNSPECIFIED;
  364. }
  365. #undef FUNC_NAME
  366. SCM
  367. scm_vector_fill_x (SCM vec, SCM fill)
  368. #define FUNC_NAME s_scm_vector_fill_x
  369. {
  370. return scm_vector_fill_partial_x (vec, fill, SCM_UNDEFINED, SCM_UNDEFINED);
  371. }
  372. #undef FUNC_NAME
  373. SCM
  374. scm_i_vector_equal_p (SCM x, SCM y)
  375. {
  376. long i;
  377. for (i = SCM_I_VECTOR_LENGTH (x) - 1; i >= 0; i--)
  378. if (scm_is_false (scm_equal_p (SCM_I_VECTOR_ELTS (x)[i],
  379. SCM_I_VECTOR_ELTS (y)[i])))
  380. return SCM_BOOL_F;
  381. return SCM_BOOL_T;
  382. }
  383. SCM_DEFINE (scm_vector_move_left_x, "vector-move-left!", 5, 0, 0,
  384. (SCM vec1, SCM start1, SCM end1, SCM vec2, SCM start2),
  385. "Copy elements from @var{vec1}, positions @var{start1} to @var{end1},\n"
  386. "to @var{vec2} starting at position @var{start2}. @var{start1} and\n"
  387. "@var{start2} are inclusive indices; @var{end1} is exclusive.\n\n"
  388. "@code{vector-move-left!} copies elements in leftmost order.\n"
  389. "Therefore, in the case where @var{vec1} and @var{vec2} refer to the\n"
  390. "same vector, @code{vector-move-left!} is usually appropriate when\n"
  391. "@var{start1} is greater than @var{start2}.")
  392. #define FUNC_NAME s_scm_vector_move_left_x
  393. {
  394. if (SCM_I_IS_VECTOR (vec1) && SCM_I_IS_VECTOR (vec2))
  395. {
  396. SCM_VALIDATE_MUTABLE_VECTOR (1, vec2);
  397. const SCM *elts1 = SCM_I_VECTOR_ELTS (vec1);
  398. SCM *elts2 = SCM_I_VECTOR_WELTS (vec2);
  399. size_t len1 = SCM_I_VECTOR_LENGTH (vec1);
  400. size_t len2 = SCM_I_VECTOR_LENGTH (vec2);
  401. size_t i, j, e;
  402. i = scm_to_unsigned_integer (start1, 0, len1);
  403. e = scm_to_unsigned_integer (end1, i, len1);
  404. SCM_ASSERT_RANGE (SCM_ARG3, end1, (e-i) <= len2);
  405. j = scm_to_unsigned_integer (start2, 0, len2);
  406. SCM_ASSERT_RANGE (SCM_ARG5, start2, j <= len2 - (e - i));
  407. for (; i < e; ++i, ++j)
  408. elts2[j] = elts1[i];
  409. }
  410. else
  411. {
  412. scm_t_array_handle handle1, handle2;
  413. const SCM *elts1;
  414. SCM *elts2;
  415. size_t len1, len2;
  416. ssize_t inc1, inc2;
  417. size_t i, j, e;
  418. elts1 = scm_vector_elements (vec1, &handle1, &len1, &inc1);
  419. elts2 = scm_vector_writable_elements (vec2, &handle2, &len2, &inc2);
  420. scm_c_issue_deprecation_warning
  421. ("Using vector-move-left! on arrays is deprecated. "
  422. "Use array-copy-in-order! instead.");
  423. i = scm_to_unsigned_integer (start1, 0, len1);
  424. e = scm_to_unsigned_integer (end1, i, len1);
  425. SCM_ASSERT_RANGE (SCM_ARG3, end1, (e-i) <= len2);
  426. j = scm_to_unsigned_integer (start2, 0, len2);
  427. SCM_ASSERT_RANGE (SCM_ARG5, start2, j <= len2 - (e - i));
  428. i *= inc1;
  429. e *= inc1;
  430. j *= inc2;
  431. for (; i < e; i += inc1, j += inc2)
  432. elts2[j] = elts1[i];
  433. scm_array_handle_release (&handle2);
  434. scm_array_handle_release (&handle1);
  435. }
  436. return SCM_UNSPECIFIED;
  437. }
  438. #undef FUNC_NAME
  439. SCM_DEFINE (scm_vector_move_right_x, "vector-move-right!", 5, 0, 0,
  440. (SCM vec1, SCM start1, SCM end1, SCM vec2, SCM start2),
  441. "Copy elements from @var{vec1}, positions @var{start1} to @var{end1},\n"
  442. "to @var{vec2} starting at position @var{start2}. @var{start1} and\n"
  443. "@var{start2} are inclusive indices; @var{end1} is exclusive.\n\n"
  444. "@code{vector-move-right!} copies elements in rightmost order.\n"
  445. "Therefore, in the case where @var{vec1} and @var{vec2} refer to the\n"
  446. "same vector, @code{vector-move-right!} is usually appropriate when\n"
  447. "@var{start1} is less than @var{start2}.")
  448. #define FUNC_NAME s_scm_vector_move_right_x
  449. {
  450. if (SCM_I_IS_VECTOR (vec1) && SCM_I_IS_VECTOR (vec2))
  451. {
  452. SCM_VALIDATE_MUTABLE_VECTOR (1, vec2);
  453. const SCM *elts1 = SCM_I_VECTOR_ELTS (vec1);
  454. SCM *elts2 = SCM_I_VECTOR_WELTS (vec2);
  455. size_t len1 = SCM_I_VECTOR_LENGTH (vec1);
  456. size_t len2 = SCM_I_VECTOR_LENGTH (vec2);
  457. size_t i, j, e;
  458. i = scm_to_unsigned_integer (start1, 0, len1);
  459. e = scm_to_unsigned_integer (end1, i, len1);
  460. SCM_ASSERT_RANGE (SCM_ARG3, end1, (e-i) <= len2);
  461. j = scm_to_unsigned_integer (start2, 0, len2);
  462. SCM_ASSERT_RANGE (SCM_ARG5, start2, j <= len2 - (e - i));
  463. j += (e - i);
  464. while (i < e)
  465. {
  466. --e;
  467. --j;
  468. elts2[j] = elts1[e];
  469. }
  470. }
  471. else
  472. {
  473. scm_t_array_handle handle1, handle2;
  474. const SCM *elts1;
  475. SCM *elts2;
  476. size_t len1, len2;
  477. ssize_t inc1, inc2;
  478. size_t i, j, e;
  479. elts1 = scm_vector_elements (vec1, &handle1, &len1, &inc1);
  480. elts2 = scm_vector_writable_elements (vec2, &handle2, &len2, &inc2);
  481. scm_c_issue_deprecation_warning
  482. ("Using vector-move-right! on arrays is deprecated. "
  483. "Use array-copy-in-order! instead.");
  484. i = scm_to_unsigned_integer (start1, 0, len1);
  485. e = scm_to_unsigned_integer (end1, i, len1);
  486. SCM_ASSERT_RANGE (SCM_ARG3, end1, (e-i) <= len2);
  487. j = scm_to_unsigned_integer (start2, 0, len2);
  488. SCM_ASSERT_RANGE (SCM_ARG5, start2, j <= len2 - (e - i));
  489. j += (e - i);
  490. i *= inc1;
  491. e *= inc1;
  492. j *= inc2;
  493. while (i < e)
  494. {
  495. e -= inc1;
  496. j -= inc2;
  497. elts2[j] = elts1[e];
  498. }
  499. scm_array_handle_release (&handle2);
  500. scm_array_handle_release (&handle1);
  501. }
  502. return SCM_UNSPECIFIED;
  503. }
  504. #undef FUNC_NAME
  505. SCM_VECTOR_IMPLEMENTATION (SCM_ARRAY_ELEMENT_TYPE_SCM, scm_make_vector)
  506. void
  507. scm_init_vectors ()
  508. {
  509. #include "vectors.x"
  510. }