srfi-4.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. #ifndef SCM_SRFI_4_H
  2. #define SCM_SRFI_4_H
  3. /* srfi-4.c --- Homogeneous numeric vector datatypes.
  4. Copyright 2001,2004,2006,2008-2011,2014,2018
  5. Free Software Foundation, Inc.
  6. This file is part of Guile.
  7. Guile is free software: you can redistribute it and/or modify it
  8. under the terms of the GNU Lesser General Public License as published
  9. by the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11. Guile is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  14. License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with Guile. If not, see
  17. <https://www.gnu.org/licenses/>. */
  18. #include "libguile/array-handle.h"
  19. SCM_API SCM scm_make_srfi_4_vector (SCM type, SCM len, SCM fill);
  20. /* Specific procedures.
  21. */
  22. SCM_API SCM scm_u8vector_p (SCM obj);
  23. SCM_API SCM scm_make_u8vector (SCM n, SCM fill);
  24. SCM_API SCM scm_take_u8vector (uint8_t *data, size_t n);
  25. SCM_API SCM scm_u8vector (SCM l);
  26. SCM_API SCM scm_u8vector_length (SCM uvec);
  27. SCM_API SCM scm_u8vector_ref (SCM uvec, SCM index);
  28. SCM_API SCM scm_u8vector_set_x (SCM uvec, SCM index, SCM value);
  29. SCM_API SCM scm_u8vector_to_list (SCM uvec);
  30. SCM_API SCM scm_list_to_u8vector (SCM l);
  31. SCM_API SCM scm_any_to_u8vector (SCM obj);
  32. SCM_API const uint8_t *scm_array_handle_u8_elements (scm_t_array_handle *h);
  33. SCM_API uint8_t *scm_array_handle_u8_writable_elements (scm_t_array_handle *h);
  34. SCM_API const uint8_t *scm_u8vector_elements (SCM uvec,
  35. scm_t_array_handle *h,
  36. size_t *lenp, ssize_t *incp);
  37. SCM_API uint8_t *scm_u8vector_writable_elements (SCM uvec,
  38. scm_t_array_handle *h,
  39. size_t *lenp,
  40. ssize_t *incp);
  41. SCM_API SCM scm_s8vector_p (SCM obj);
  42. SCM_API SCM scm_make_s8vector (SCM n, SCM fill);
  43. SCM_API SCM scm_take_s8vector (int8_t *data, size_t n);
  44. SCM_API SCM scm_s8vector (SCM l);
  45. SCM_API SCM scm_s8vector_length (SCM uvec);
  46. SCM_API SCM scm_s8vector_ref (SCM uvec, SCM index);
  47. SCM_API SCM scm_s8vector_set_x (SCM uvec, SCM index, SCM value);
  48. SCM_API SCM scm_s8vector_to_list (SCM uvec);
  49. SCM_API SCM scm_list_to_s8vector (SCM l);
  50. SCM_API SCM scm_any_to_s8vector (SCM obj);
  51. SCM_API const int8_t *scm_array_handle_s8_elements (scm_t_array_handle *h);
  52. SCM_API int8_t *scm_array_handle_s8_writable_elements (scm_t_array_handle *h);
  53. SCM_API const int8_t *scm_s8vector_elements (SCM uvec,
  54. scm_t_array_handle *h,
  55. size_t *lenp, ssize_t *incp);
  56. SCM_API int8_t *scm_s8vector_writable_elements (SCM uvec,
  57. scm_t_array_handle *h,
  58. size_t *lenp,
  59. ssize_t *incp);
  60. SCM_API SCM scm_u16vector_p (SCM obj);
  61. SCM_API SCM scm_make_u16vector (SCM n, SCM fill);
  62. SCM_API SCM scm_take_u16vector (uint16_t *data, size_t n);
  63. SCM_API SCM scm_u16vector (SCM l);
  64. SCM_API SCM scm_u16vector_length (SCM uvec);
  65. SCM_API SCM scm_u16vector_ref (SCM uvec, SCM index);
  66. SCM_API SCM scm_u16vector_set_x (SCM uvec, SCM index, SCM value);
  67. SCM_API SCM scm_u16vector_to_list (SCM uvec);
  68. SCM_API SCM scm_list_to_u16vector (SCM l);
  69. SCM_API SCM scm_any_to_u16vector (SCM obj);
  70. SCM_API const uint16_t *scm_array_handle_u16_elements (scm_t_array_handle *h);
  71. SCM_API uint16_t *scm_array_handle_u16_writable_elements (scm_t_array_handle *h);
  72. SCM_API const uint16_t *scm_u16vector_elements (SCM uvec,
  73. scm_t_array_handle *h,
  74. size_t *lenp,
  75. ssize_t *incp);
  76. SCM_API uint16_t *scm_u16vector_writable_elements (SCM uvec,
  77. scm_t_array_handle *h,
  78. size_t *lenp,
  79. ssize_t *incp);
  80. SCM_API SCM scm_s16vector_p (SCM obj);
  81. SCM_API SCM scm_make_s16vector (SCM n, SCM fill);
  82. SCM_API SCM scm_take_s16vector (int16_t *data, size_t n);
  83. SCM_API SCM scm_s16vector (SCM l);
  84. SCM_API SCM scm_s16vector_length (SCM uvec);
  85. SCM_API SCM scm_s16vector_ref (SCM uvec, SCM index);
  86. SCM_API SCM scm_s16vector_set_x (SCM uvec, SCM index, SCM value);
  87. SCM_API SCM scm_s16vector_to_list (SCM uvec);
  88. SCM_API SCM scm_list_to_s16vector (SCM l);
  89. SCM_API SCM scm_any_to_s16vector (SCM obj);
  90. SCM_API const int16_t *scm_array_handle_s16_elements (scm_t_array_handle *h);
  91. SCM_API int16_t *scm_array_handle_s16_writable_elements (scm_t_array_handle *h);
  92. SCM_API const int16_t *scm_s16vector_elements (SCM uvec,
  93. scm_t_array_handle *h,
  94. size_t *lenp, ssize_t *incp);
  95. SCM_API int16_t *scm_s16vector_writable_elements (SCM uvec,
  96. scm_t_array_handle *h,
  97. size_t *lenp,
  98. ssize_t *incp);
  99. SCM_API SCM scm_u32vector_p (SCM obj);
  100. SCM_API SCM scm_make_u32vector (SCM n, SCM fill);
  101. SCM_API SCM scm_take_u32vector (uint32_t *data, size_t n);
  102. SCM_API SCM scm_u32vector (SCM l);
  103. SCM_API SCM scm_u32vector_length (SCM uvec);
  104. SCM_API SCM scm_u32vector_ref (SCM uvec, SCM index);
  105. SCM_API SCM scm_u32vector_set_x (SCM uvec, SCM index, SCM value);
  106. SCM_API SCM scm_u32vector_to_list (SCM uvec);
  107. SCM_API SCM scm_list_to_u32vector (SCM l);
  108. SCM_API SCM scm_any_to_u32vector (SCM obj);
  109. SCM_API const uint32_t *scm_array_handle_u32_elements (scm_t_array_handle *h);
  110. SCM_API uint32_t *scm_array_handle_u32_writable_elements (scm_t_array_handle *h);
  111. SCM_API const uint32_t *scm_u32vector_elements (SCM uvec,
  112. scm_t_array_handle *h,
  113. size_t *lenp,
  114. ssize_t *incp);
  115. SCM_API uint32_t *scm_u32vector_writable_elements (SCM uvec,
  116. scm_t_array_handle *h,
  117. size_t *lenp,
  118. ssize_t *incp);
  119. SCM_API SCM scm_s32vector_p (SCM obj);
  120. SCM_API SCM scm_make_s32vector (SCM n, SCM fill);
  121. SCM_API SCM scm_take_s32vector (int32_t *data, size_t n);
  122. SCM_API SCM scm_s32vector (SCM l);
  123. SCM_API SCM scm_s32vector_length (SCM uvec);
  124. SCM_API SCM scm_s32vector_ref (SCM uvec, SCM index);
  125. SCM_API SCM scm_s32vector_set_x (SCM uvec, SCM index, SCM value);
  126. SCM_API SCM scm_s32vector_to_list (SCM uvec);
  127. SCM_API SCM scm_list_to_s32vector (SCM l);
  128. SCM_API SCM scm_any_to_s32vector (SCM obj);
  129. SCM_API const int32_t *scm_array_handle_s32_elements (scm_t_array_handle *h);
  130. SCM_API int32_t *scm_array_handle_s32_writable_elements (scm_t_array_handle *h);
  131. SCM_API const int32_t *scm_s32vector_elements (SCM uvec,
  132. scm_t_array_handle *h,
  133. size_t *lenp, ssize_t *incp);
  134. SCM_API int32_t *scm_s32vector_writable_elements (SCM uvec,
  135. scm_t_array_handle *h,
  136. size_t *lenp,
  137. ssize_t *incp);
  138. SCM_API SCM scm_u64vector_p (SCM obj);
  139. SCM_API SCM scm_make_u64vector (SCM n, SCM fill);
  140. SCM_API SCM scm_u64vector (SCM l);
  141. SCM_API SCM scm_u64vector_length (SCM uvec);
  142. SCM_API SCM scm_u64vector_ref (SCM uvec, SCM index);
  143. SCM_API SCM scm_u64vector_set_x (SCM uvec, SCM index, SCM value);
  144. SCM_API SCM scm_u64vector_to_list (SCM uvec);
  145. SCM_API SCM scm_list_to_u64vector (SCM l);
  146. SCM_API SCM scm_any_to_u64vector (SCM obj);
  147. SCM_API SCM scm_take_u64vector (uint64_t *data, size_t n);
  148. SCM_API const uint64_t *scm_array_handle_u64_elements (scm_t_array_handle *h);
  149. SCM_API uint64_t *scm_array_handle_u64_writable_elements (scm_t_array_handle *h);
  150. SCM_API const uint64_t *scm_u64vector_elements (SCM uvec,
  151. scm_t_array_handle *h,
  152. size_t *lenp,
  153. ssize_t *incp);
  154. SCM_API uint64_t *scm_u64vector_writable_elements (SCM uvec,
  155. scm_t_array_handle *h,
  156. size_t *lenp,
  157. ssize_t *incp);
  158. SCM_API SCM scm_s64vector_p (SCM obj);
  159. SCM_API SCM scm_make_s64vector (SCM n, SCM fill);
  160. SCM_API SCM scm_s64vector (SCM l);
  161. SCM_API SCM scm_s64vector_length (SCM uvec);
  162. SCM_API SCM scm_s64vector_ref (SCM uvec, SCM index);
  163. SCM_API SCM scm_s64vector_set_x (SCM uvec, SCM index, SCM value);
  164. SCM_API SCM scm_s64vector_to_list (SCM uvec);
  165. SCM_API SCM scm_list_to_s64vector (SCM l);
  166. SCM_API SCM scm_any_to_s64vector (SCM obj);
  167. SCM_API SCM scm_take_s64vector (int64_t *data, size_t n);
  168. SCM_API const int64_t *scm_array_handle_s64_elements (scm_t_array_handle *h);
  169. SCM_API int64_t *scm_array_handle_s64_writable_elements (scm_t_array_handle *h);
  170. SCM_API const int64_t *scm_s64vector_elements (SCM uvec,
  171. scm_t_array_handle *h,
  172. size_t *lenp, ssize_t *incp);
  173. SCM_API int64_t *scm_s64vector_writable_elements (SCM uvec,
  174. scm_t_array_handle *h,
  175. size_t *lenp,
  176. ssize_t *incp);
  177. SCM_API SCM scm_f32vector_p (SCM obj);
  178. SCM_API SCM scm_make_f32vector (SCM n, SCM fill);
  179. SCM_API SCM scm_take_f32vector (float *data, size_t n);
  180. SCM_API SCM scm_f32vector (SCM l);
  181. SCM_API SCM scm_f32vector_length (SCM uvec);
  182. SCM_API SCM scm_f32vector_ref (SCM uvec, SCM index);
  183. SCM_API SCM scm_f32vector_set_x (SCM uvec, SCM index, SCM value);
  184. SCM_API SCM scm_f32vector_to_list (SCM uvec);
  185. SCM_API SCM scm_list_to_f32vector (SCM l);
  186. SCM_API SCM scm_any_to_f32vector (SCM obj);
  187. SCM_API const float *scm_array_handle_f32_elements (scm_t_array_handle *h);
  188. SCM_API float *scm_array_handle_f32_writable_elements (scm_t_array_handle *h);
  189. SCM_API const float *scm_f32vector_elements (SCM uvec,
  190. scm_t_array_handle *h,
  191. size_t *lenp, ssize_t *incp);
  192. SCM_API float *scm_f32vector_writable_elements (SCM uvec,
  193. scm_t_array_handle *h,
  194. size_t *lenp,
  195. ssize_t *incp);
  196. SCM_API SCM scm_f64vector_p (SCM obj);
  197. SCM_API SCM scm_make_f64vector (SCM n, SCM fill);
  198. SCM_API SCM scm_take_f64vector (double *data, size_t n);
  199. SCM_API SCM scm_f64vector (SCM l);
  200. SCM_API SCM scm_f64vector_length (SCM uvec);
  201. SCM_API SCM scm_f64vector_ref (SCM uvec, SCM index);
  202. SCM_API SCM scm_f64vector_set_x (SCM uvec, SCM index, SCM value);
  203. SCM_API SCM scm_f64vector_to_list (SCM uvec);
  204. SCM_API SCM scm_list_to_f64vector (SCM l);
  205. SCM_API SCM scm_any_to_f64vector (SCM obj);
  206. SCM_API const double *scm_array_handle_f64_elements (scm_t_array_handle *h);
  207. SCM_API double *scm_array_handle_f64_writable_elements (scm_t_array_handle *h);
  208. SCM_API const double *scm_f64vector_elements (SCM uvec,
  209. scm_t_array_handle *h,
  210. size_t *lenp, ssize_t *incp);
  211. SCM_API double *scm_f64vector_writable_elements (SCM uvec,
  212. scm_t_array_handle *h,
  213. size_t *lenp,
  214. ssize_t *incp);
  215. SCM_API SCM scm_c32vector_p (SCM obj);
  216. SCM_API SCM scm_make_c32vector (SCM n, SCM fill);
  217. SCM_API SCM scm_take_c32vector (float *data, size_t n);
  218. SCM_API SCM scm_c32vector (SCM l);
  219. SCM_API SCM scm_c32vector_length (SCM uvec);
  220. SCM_API SCM scm_c32vector_ref (SCM uvec, SCM index);
  221. SCM_API SCM scm_c32vector_set_x (SCM uvec, SCM index, SCM value);
  222. SCM_API SCM scm_c32vector_to_list (SCM uvec);
  223. SCM_API SCM scm_list_to_c32vector (SCM l);
  224. SCM_API SCM scm_any_to_c32vector (SCM obj);
  225. SCM_API const float *scm_array_handle_c32_elements (scm_t_array_handle *h);
  226. SCM_API float *scm_array_handle_c32_writable_elements (scm_t_array_handle *h);
  227. SCM_API const float *scm_c32vector_elements (SCM uvec,
  228. scm_t_array_handle *h,
  229. size_t *lenp, ssize_t *incp);
  230. SCM_API float *scm_c32vector_writable_elements (SCM uvec,
  231. scm_t_array_handle *h,
  232. size_t *lenp,
  233. ssize_t *incp);
  234. SCM_API SCM scm_c64vector_p (SCM obj);
  235. SCM_API SCM scm_make_c64vector (SCM n, SCM fill);
  236. SCM_API SCM scm_take_c64vector (double *data, size_t n);
  237. SCM_API SCM scm_c64vector (SCM l);
  238. SCM_API SCM scm_c64vector_length (SCM uvec);
  239. SCM_API SCM scm_c64vector_ref (SCM uvec, SCM index);
  240. SCM_API SCM scm_c64vector_set_x (SCM uvec, SCM index, SCM value);
  241. SCM_API SCM scm_c64vector_to_list (SCM uvec);
  242. SCM_API SCM scm_list_to_c64vector (SCM l);
  243. SCM_API SCM scm_any_to_c64vector (SCM obj);
  244. SCM_API const double *scm_array_handle_c64_elements (scm_t_array_handle *h);
  245. SCM_API double *scm_array_handle_c64_writable_elements (scm_t_array_handle *h);
  246. SCM_API const double *scm_c64vector_elements (SCM uvec,
  247. scm_t_array_handle *h,
  248. size_t *lenp, ssize_t *incp);
  249. SCM_API double *scm_c64vector_writable_elements (SCM uvec,
  250. scm_t_array_handle *h,
  251. size_t *lenp,
  252. ssize_t *incp);
  253. SCM_INTERNAL void scm_init_srfi_4 (void);
  254. #endif /* SCM_SRFI_4_H */