srfi-4.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. #ifndef SCM_SRFI_4_H
  2. #define SCM_SRFI_4_H
  3. /* srfi-4.c --- Homogeneous numeric vector datatypes.
  4. *
  5. * Copyright (C) 2001, 2004, 2006 Free Software Foundation, Inc.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libguile/__scm.h"
  22. #include "libguile/unif.h"
  23. /* Generic procedures.
  24. */
  25. SCM_API SCM scm_uniform_vector_p (SCM v);
  26. SCM_API SCM scm_uniform_vector_length (SCM v);
  27. SCM_API SCM scm_uniform_vector_ref (SCM v, SCM idx);
  28. SCM_API SCM scm_uniform_vector_set_x (SCM v, SCM idx, SCM val);
  29. SCM_API SCM scm_uniform_vector_to_list (SCM v);
  30. SCM_API SCM scm_uniform_vector_read_x (SCM v, SCM port_or_fd,
  31. SCM start, SCM end);
  32. SCM_API SCM scm_uniform_vector_write (SCM v, SCM port_or_fd,
  33. SCM start, SCM end);
  34. SCM_API int scm_is_uniform_vector (SCM obj);
  35. SCM_API size_t scm_c_uniform_vector_length (SCM v);
  36. SCM_API SCM scm_c_uniform_vector_ref (SCM v, size_t idx);
  37. SCM_API void scm_c_uniform_vector_set_x (SCM v, size_t idx, SCM val);
  38. SCM_API size_t scm_array_handle_uniform_element_size (scm_t_array_handle *h);
  39. SCM_API const void *scm_array_handle_uniform_elements (scm_t_array_handle *h);
  40. SCM_API void *scm_array_handle_uniform_writable_elements (scm_t_array_handle *h);
  41. SCM_API const void *scm_uniform_vector_elements (SCM uvec,
  42. scm_t_array_handle *h,
  43. size_t *lenp, ssize_t *incp);
  44. SCM_API void *scm_uniform_vector_writable_elements (SCM uvec,
  45. scm_t_array_handle *h,
  46. size_t *lenp,
  47. ssize_t *incp);
  48. /* Specific procedures.
  49. */
  50. SCM_API SCM scm_u8vector_p (SCM obj);
  51. SCM_API SCM scm_make_u8vector (SCM n, SCM fill);
  52. SCM_API SCM scm_take_u8vector (scm_t_uint8 *data, size_t n);
  53. SCM_API SCM scm_u8vector (SCM l);
  54. SCM_API SCM scm_u8vector_length (SCM uvec);
  55. SCM_API SCM scm_u8vector_ref (SCM uvec, SCM index);
  56. SCM_API SCM scm_u8vector_set_x (SCM uvec, SCM index, SCM value);
  57. SCM_API SCM scm_u8vector_to_list (SCM uvec);
  58. SCM_API SCM scm_list_to_u8vector (SCM l);
  59. SCM_API SCM scm_any_to_u8vector (SCM obj);
  60. SCM_API const scm_t_uint8 *scm_array_handle_u8_elements (scm_t_array_handle *h);
  61. SCM_API scm_t_uint8 *scm_array_handle_u8_writable_elements (scm_t_array_handle *h);
  62. SCM_API const scm_t_uint8 *scm_u8vector_elements (SCM uvec,
  63. scm_t_array_handle *h,
  64. size_t *lenp, ssize_t *incp);
  65. SCM_API scm_t_uint8 *scm_u8vector_writable_elements (SCM uvec,
  66. scm_t_array_handle *h,
  67. size_t *lenp,
  68. ssize_t *incp);
  69. SCM_API SCM scm_s8vector_p (SCM obj);
  70. SCM_API SCM scm_make_s8vector (SCM n, SCM fill);
  71. SCM_API SCM scm_take_s8vector (scm_t_int8 *data, size_t n);
  72. SCM_API SCM scm_s8vector (SCM l);
  73. SCM_API SCM scm_s8vector_length (SCM uvec);
  74. SCM_API SCM scm_s8vector_ref (SCM uvec, SCM index);
  75. SCM_API SCM scm_s8vector_set_x (SCM uvec, SCM index, SCM value);
  76. SCM_API SCM scm_s8vector_to_list (SCM uvec);
  77. SCM_API SCM scm_list_to_s8vector (SCM l);
  78. SCM_API SCM scm_any_to_s8vector (SCM obj);
  79. SCM_API const scm_t_int8 *scm_array_handle_s8_elements (scm_t_array_handle *h);
  80. SCM_API scm_t_int8 *scm_array_handle_s8_writable_elements (scm_t_array_handle *h);
  81. SCM_API const scm_t_int8 *scm_s8vector_elements (SCM uvec,
  82. scm_t_array_handle *h,
  83. size_t *lenp, ssize_t *incp);
  84. SCM_API scm_t_int8 *scm_s8vector_writable_elements (SCM uvec,
  85. scm_t_array_handle *h,
  86. size_t *lenp,
  87. ssize_t *incp);
  88. SCM_API SCM scm_u16vector_p (SCM obj);
  89. SCM_API SCM scm_make_u16vector (SCM n, SCM fill);
  90. SCM_API SCM scm_take_u16vector (scm_t_uint16 *data, size_t n);
  91. SCM_API SCM scm_u16vector (SCM l);
  92. SCM_API SCM scm_u16vector_length (SCM uvec);
  93. SCM_API SCM scm_u16vector_ref (SCM uvec, SCM index);
  94. SCM_API SCM scm_u16vector_set_x (SCM uvec, SCM index, SCM value);
  95. SCM_API SCM scm_u16vector_to_list (SCM uvec);
  96. SCM_API SCM scm_list_to_u16vector (SCM l);
  97. SCM_API SCM scm_any_to_u16vector (SCM obj);
  98. SCM_API const scm_t_uint16 *scm_array_handle_u16_elements (scm_t_array_handle *h);
  99. SCM_API scm_t_uint16 *scm_array_handle_u16_writable_elements (scm_t_array_handle *h);
  100. SCM_API const scm_t_uint16 *scm_u16vector_elements (SCM uvec,
  101. scm_t_array_handle *h,
  102. size_t *lenp,
  103. ssize_t *incp);
  104. SCM_API scm_t_uint16 *scm_u16vector_writable_elements (SCM uvec,
  105. scm_t_array_handle *h,
  106. size_t *lenp,
  107. ssize_t *incp);
  108. SCM_API SCM scm_s16vector_p (SCM obj);
  109. SCM_API SCM scm_make_s16vector (SCM n, SCM fill);
  110. SCM_API SCM scm_take_s16vector (scm_t_int16 *data, size_t n);
  111. SCM_API SCM scm_s16vector (SCM l);
  112. SCM_API SCM scm_s16vector_length (SCM uvec);
  113. SCM_API SCM scm_s16vector_ref (SCM uvec, SCM index);
  114. SCM_API SCM scm_s16vector_set_x (SCM uvec, SCM index, SCM value);
  115. SCM_API SCM scm_s16vector_to_list (SCM uvec);
  116. SCM_API SCM scm_list_to_s16vector (SCM l);
  117. SCM_API SCM scm_any_to_s16vector (SCM obj);
  118. SCM_API const scm_t_int16 *scm_array_handle_s16_elements (scm_t_array_handle *h);
  119. SCM_API scm_t_int16 *scm_array_handle_s16_writable_elements (scm_t_array_handle *h);
  120. SCM_API const scm_t_int16 *scm_s16vector_elements (SCM uvec,
  121. scm_t_array_handle *h,
  122. size_t *lenp, ssize_t *incp);
  123. SCM_API scm_t_int16 *scm_s16vector_writable_elements (SCM uvec,
  124. scm_t_array_handle *h,
  125. size_t *lenp,
  126. ssize_t *incp);
  127. SCM_API SCM scm_u32vector_p (SCM obj);
  128. SCM_API SCM scm_make_u32vector (SCM n, SCM fill);
  129. SCM_API SCM scm_take_u32vector (scm_t_uint32 *data, size_t n);
  130. SCM_API SCM scm_u32vector (SCM l);
  131. SCM_API SCM scm_u32vector_length (SCM uvec);
  132. SCM_API SCM scm_u32vector_ref (SCM uvec, SCM index);
  133. SCM_API SCM scm_u32vector_set_x (SCM uvec, SCM index, SCM value);
  134. SCM_API SCM scm_u32vector_to_list (SCM uvec);
  135. SCM_API SCM scm_list_to_u32vector (SCM l);
  136. SCM_API SCM scm_any_to_u32vector (SCM obj);
  137. SCM_API const scm_t_uint32 *scm_array_handle_u32_elements (scm_t_array_handle *h);
  138. SCM_API scm_t_uint32 *scm_array_handle_u32_writable_elements (scm_t_array_handle *h);
  139. SCM_API const scm_t_uint32 *scm_u32vector_elements (SCM uvec,
  140. scm_t_array_handle *h,
  141. size_t *lenp,
  142. ssize_t *incp);
  143. SCM_API scm_t_uint32 *scm_u32vector_writable_elements (SCM uvec,
  144. scm_t_array_handle *h,
  145. size_t *lenp,
  146. ssize_t *incp);
  147. SCM_API SCM scm_s32vector_p (SCM obj);
  148. SCM_API SCM scm_make_s32vector (SCM n, SCM fill);
  149. SCM_API SCM scm_take_s32vector (scm_t_int32 *data, size_t n);
  150. SCM_API SCM scm_s32vector (SCM l);
  151. SCM_API SCM scm_s32vector_length (SCM uvec);
  152. SCM_API SCM scm_s32vector_ref (SCM uvec, SCM index);
  153. SCM_API SCM scm_s32vector_set_x (SCM uvec, SCM index, SCM value);
  154. SCM_API SCM scm_s32vector_to_list (SCM uvec);
  155. SCM_API SCM scm_list_to_s32vector (SCM l);
  156. SCM_API SCM scm_any_to_s32vector (SCM obj);
  157. SCM_API const scm_t_int32 *scm_array_handle_s32_elements (scm_t_array_handle *h);
  158. SCM_API scm_t_int32 *scm_array_handle_s32_writable_elements (scm_t_array_handle *h);
  159. SCM_API const scm_t_int32 *scm_s32vector_elements (SCM uvec,
  160. scm_t_array_handle *h,
  161. size_t *lenp, ssize_t *incp);
  162. SCM_API scm_t_int32 *scm_s32vector_writable_elements (SCM uvec,
  163. scm_t_array_handle *h,
  164. size_t *lenp,
  165. ssize_t *incp);
  166. SCM_API SCM scm_u64vector_p (SCM obj);
  167. SCM_API SCM scm_make_u64vector (SCM n, SCM fill);
  168. SCM_API SCM scm_u64vector (SCM l);
  169. SCM_API SCM scm_u64vector_length (SCM uvec);
  170. SCM_API SCM scm_u64vector_ref (SCM uvec, SCM index);
  171. SCM_API SCM scm_u64vector_set_x (SCM uvec, SCM index, SCM value);
  172. SCM_API SCM scm_u64vector_to_list (SCM uvec);
  173. SCM_API SCM scm_list_to_u64vector (SCM l);
  174. SCM_API SCM scm_any_to_u64vector (SCM obj);
  175. #if SCM_HAVE_T_UINT64
  176. SCM_API SCM scm_take_u64vector (scm_t_uint64 *data, size_t n);
  177. SCM_API const scm_t_uint64 *scm_array_handle_u64_elements (scm_t_array_handle *h);
  178. SCM_API scm_t_uint64 *scm_array_handle_u64_writable_elements (scm_t_array_handle *h);
  179. SCM_API const scm_t_uint64 *scm_u64vector_elements (SCM uvec,
  180. scm_t_array_handle *h,
  181. size_t *lenp,
  182. ssize_t *incp);
  183. SCM_API scm_t_uint64 *scm_u64vector_writable_elements (SCM uvec,
  184. scm_t_array_handle *h,
  185. size_t *lenp,
  186. ssize_t *incp);
  187. #endif
  188. SCM_API SCM scm_s64vector_p (SCM obj);
  189. SCM_API SCM scm_make_s64vector (SCM n, SCM fill);
  190. SCM_API SCM scm_s64vector (SCM l);
  191. SCM_API SCM scm_s64vector_length (SCM uvec);
  192. SCM_API SCM scm_s64vector_ref (SCM uvec, SCM index);
  193. SCM_API SCM scm_s64vector_set_x (SCM uvec, SCM index, SCM value);
  194. SCM_API SCM scm_s64vector_to_list (SCM uvec);
  195. SCM_API SCM scm_list_to_s64vector (SCM l);
  196. SCM_API SCM scm_any_to_s64vector (SCM obj);
  197. #if SCM_HAVE_T_INT64
  198. SCM_API SCM scm_take_s64vector (scm_t_int64 *data, size_t n);
  199. SCM_API const scm_t_int64 *scm_array_handle_s64_elements (scm_t_array_handle *h);
  200. SCM_API scm_t_int64 *scm_array_handle_s64_writable_elements (scm_t_array_handle *h);
  201. SCM_API const scm_t_int64 *scm_s64vector_elements (SCM uvec,
  202. scm_t_array_handle *h,
  203. size_t *lenp, ssize_t *incp);
  204. SCM_API scm_t_int64 *scm_s64vector_writable_elements (SCM uvec,
  205. scm_t_array_handle *h,
  206. size_t *lenp,
  207. ssize_t *incp);
  208. #endif
  209. SCM_API SCM scm_f32vector_p (SCM obj);
  210. SCM_API SCM scm_make_f32vector (SCM n, SCM fill);
  211. SCM_API SCM scm_take_f32vector (float *data, size_t n);
  212. SCM_API SCM scm_f32vector (SCM l);
  213. SCM_API SCM scm_f32vector_length (SCM uvec);
  214. SCM_API SCM scm_f32vector_ref (SCM uvec, SCM index);
  215. SCM_API SCM scm_f32vector_set_x (SCM uvec, SCM index, SCM value);
  216. SCM_API SCM scm_f32vector_to_list (SCM uvec);
  217. SCM_API SCM scm_list_to_f32vector (SCM l);
  218. SCM_API SCM scm_any_to_f32vector (SCM obj);
  219. SCM_API const float *scm_array_handle_f32_elements (scm_t_array_handle *h);
  220. SCM_API float *scm_array_handle_f32_writable_elements (scm_t_array_handle *h);
  221. SCM_API const float *scm_f32vector_elements (SCM uvec,
  222. scm_t_array_handle *h,
  223. size_t *lenp, ssize_t *incp);
  224. SCM_API float *scm_f32vector_writable_elements (SCM uvec,
  225. scm_t_array_handle *h,
  226. size_t *lenp,
  227. ssize_t *incp);
  228. SCM_API SCM scm_f64vector_p (SCM obj);
  229. SCM_API SCM scm_make_f64vector (SCM n, SCM fill);
  230. SCM_API SCM scm_take_f64vector (double *data, size_t n);
  231. SCM_API SCM scm_f64vector (SCM l);
  232. SCM_API SCM scm_f64vector_length (SCM uvec);
  233. SCM_API SCM scm_f64vector_ref (SCM uvec, SCM index);
  234. SCM_API SCM scm_f64vector_set_x (SCM uvec, SCM index, SCM value);
  235. SCM_API SCM scm_f64vector_to_list (SCM uvec);
  236. SCM_API SCM scm_list_to_f64vector (SCM l);
  237. SCM_API SCM scm_any_to_f64vector (SCM obj);
  238. SCM_API const double *scm_array_handle_f64_elements (scm_t_array_handle *h);
  239. SCM_API double *scm_array_handle_f64_writable_elements (scm_t_array_handle *h);
  240. SCM_API const double *scm_f64vector_elements (SCM uvec,
  241. scm_t_array_handle *h,
  242. size_t *lenp, ssize_t *incp);
  243. SCM_API double *scm_f64vector_writable_elements (SCM uvec,
  244. scm_t_array_handle *h,
  245. size_t *lenp,
  246. ssize_t *incp);
  247. SCM_API SCM scm_c32vector_p (SCM obj);
  248. SCM_API SCM scm_make_c32vector (SCM n, SCM fill);
  249. SCM_API SCM scm_take_c32vector (float *data, size_t n);
  250. SCM_API SCM scm_c32vector (SCM l);
  251. SCM_API SCM scm_c32vector_length (SCM uvec);
  252. SCM_API SCM scm_c32vector_ref (SCM uvec, SCM index);
  253. SCM_API SCM scm_c32vector_set_x (SCM uvec, SCM index, SCM value);
  254. SCM_API SCM scm_c32vector_to_list (SCM uvec);
  255. SCM_API SCM scm_list_to_c32vector (SCM l);
  256. SCM_API SCM scm_any_to_c32vector (SCM obj);
  257. SCM_API const float *scm_array_handle_c32_elements (scm_t_array_handle *h);
  258. SCM_API float *scm_array_handle_c32_writable_elements (scm_t_array_handle *h);
  259. SCM_API const float *scm_c32vector_elements (SCM uvec,
  260. scm_t_array_handle *h,
  261. size_t *lenp, ssize_t *incp);
  262. SCM_API float *scm_c32vector_writable_elements (SCM uvec,
  263. scm_t_array_handle *h,
  264. size_t *lenp,
  265. ssize_t *incp);
  266. SCM_API SCM scm_c64vector_p (SCM obj);
  267. SCM_API SCM scm_make_c64vector (SCM n, SCM fill);
  268. SCM_API SCM scm_take_c64vector (double *data, size_t n);
  269. SCM_API SCM scm_c64vector (SCM l);
  270. SCM_API SCM scm_c64vector_length (SCM uvec);
  271. SCM_API SCM scm_c64vector_ref (SCM uvec, SCM index);
  272. SCM_API SCM scm_c64vector_set_x (SCM uvec, SCM index, SCM value);
  273. SCM_API SCM scm_c64vector_to_list (SCM uvec);
  274. SCM_API SCM scm_list_to_c64vector (SCM l);
  275. SCM_API SCM scm_any_to_c64vector (SCM obj);
  276. SCM_API const double *scm_array_handle_c64_elements (scm_t_array_handle *h);
  277. SCM_API double *scm_array_handle_c64_writable_elements (scm_t_array_handle *h);
  278. SCM_API const double *scm_c64vector_elements (SCM uvec,
  279. scm_t_array_handle *h,
  280. size_t *lenp, ssize_t *incp);
  281. SCM_API double *scm_c64vector_writable_elements (SCM uvec,
  282. scm_t_array_handle *h,
  283. size_t *lenp,
  284. ssize_t *incp);
  285. SCM_API SCM scm_i_generalized_vector_type (SCM vec);
  286. SCM_API const char *scm_i_uniform_vector_tag (SCM uvec);
  287. SCM_API scm_i_t_array_ref scm_i_uniform_vector_ref_proc (SCM uvec);
  288. SCM_API scm_i_t_array_set scm_i_uniform_vector_set_proc (SCM uvec);
  289. #if SCM_ENABLE_DEPRECATED
  290. /* Deprecated because we want people to use the scm_t_array_handle
  291. interface.
  292. */
  293. SCM_API size_t scm_uniform_element_size (SCM obj);
  294. #endif
  295. SCM_API void scm_init_srfi_4 (void);
  296. #endif /* SCM_SRFI_4_H */