array-handle.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* classes: h_files */
  2. #ifndef SCM_ARRAY_HANDLE_H
  3. #define SCM_ARRAY_HANDLE_H
  4. /* Copyright (C) 1995, 1996, 1997, 1999, 2000, 2001, 2004, 2006,
  5. * 2008, 2009, 2011 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 License
  9. * as published by the Free Software Foundation; either version 3 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful, but
  13. * 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
  20. * 02110-1301 USA
  21. */
  22. #include "libguile/__scm.h"
  23. struct scm_t_array_handle;
  24. typedef SCM (*scm_i_t_array_ref) (struct scm_t_array_handle *, size_t);
  25. typedef void (*scm_i_t_array_set) (struct scm_t_array_handle *, size_t, SCM);
  26. typedef struct
  27. {
  28. scm_t_bits tag;
  29. scm_t_bits mask;
  30. scm_i_t_array_ref vref;
  31. scm_i_t_array_set vset;
  32. void (*get_handle)(SCM, struct scm_t_array_handle*);
  33. } scm_t_array_implementation;
  34. #define SCM_ARRAY_IMPLEMENTATION(tag_,mask_,vref_,vset_,handle_) \
  35. SCM_SNARF_INIT ({ \
  36. scm_t_array_implementation impl; \
  37. impl.tag = tag_; impl.mask = mask_; \
  38. impl.vref = vref_; impl.vset = vset_; \
  39. impl.get_handle = handle_; \
  40. scm_i_register_array_implementation (&impl); \
  41. })
  42. SCM_INTERNAL void scm_i_register_array_implementation (scm_t_array_implementation *impl);
  43. SCM_INTERNAL scm_t_array_implementation* scm_i_array_implementation_for_obj (SCM obj);
  44. typedef struct scm_t_array_dim
  45. {
  46. ssize_t lbnd;
  47. ssize_t ubnd;
  48. ssize_t inc;
  49. } scm_t_array_dim;
  50. typedef enum
  51. {
  52. SCM_ARRAY_ELEMENT_TYPE_SCM = 0, /* SCM values */
  53. SCM_ARRAY_ELEMENT_TYPE_CHAR = 1, /* characters */
  54. SCM_ARRAY_ELEMENT_TYPE_BIT = 2, /* packed numeric values */
  55. SCM_ARRAY_ELEMENT_TYPE_VU8 = 3,
  56. SCM_ARRAY_ELEMENT_TYPE_U8 = 4,
  57. SCM_ARRAY_ELEMENT_TYPE_S8 = 5,
  58. SCM_ARRAY_ELEMENT_TYPE_U16 = 6,
  59. SCM_ARRAY_ELEMENT_TYPE_S16 = 7,
  60. SCM_ARRAY_ELEMENT_TYPE_U32 = 8,
  61. SCM_ARRAY_ELEMENT_TYPE_S32 = 9,
  62. SCM_ARRAY_ELEMENT_TYPE_U64 = 10,
  63. SCM_ARRAY_ELEMENT_TYPE_S64 = 11,
  64. SCM_ARRAY_ELEMENT_TYPE_F32 = 12,
  65. SCM_ARRAY_ELEMENT_TYPE_F64 = 13,
  66. SCM_ARRAY_ELEMENT_TYPE_C32 = 14,
  67. SCM_ARRAY_ELEMENT_TYPE_C64 = 15,
  68. SCM_ARRAY_ELEMENT_TYPE_LAST = 15
  69. } scm_t_array_element_type;
  70. SCM_INTERNAL SCM scm_i_array_element_types[];
  71. typedef struct scm_t_array_handle {
  72. SCM array;
  73. scm_t_array_implementation *impl;
  74. /* `Base' is an offset into elements or writable_elements, corresponding to
  75. the first element in the array. It would be nicer just to adjust the
  76. elements/writable_elements pointer, but we can't because that element might
  77. not even be byte-addressable, as is the case with bitvectors. A nicer
  78. solution would be, well, nice.
  79. */
  80. size_t base;
  81. size_t ndims; /* ndims == the rank of the array */
  82. scm_t_array_dim *dims;
  83. scm_t_array_dim dim0;
  84. scm_t_array_element_type element_type;
  85. const void *elements;
  86. void *writable_elements;
  87. } scm_t_array_handle;
  88. #define scm_array_handle_rank(h) ((h)->ndims)
  89. #define scm_array_handle_dims(h) ((h)->dims)
  90. SCM_API void scm_array_get_handle (SCM array, scm_t_array_handle *h);
  91. SCM_API ssize_t scm_array_handle_pos (scm_t_array_handle *h, SCM indices);
  92. SCM_API SCM scm_array_handle_element_type (scm_t_array_handle *h);
  93. SCM_API void scm_array_handle_release (scm_t_array_handle *h);
  94. SCM_API const SCM* scm_array_handle_elements (scm_t_array_handle *h);
  95. SCM_API SCM* scm_array_handle_writable_elements (scm_t_array_handle *h);
  96. /* See inline.h for scm_array_handle_ref and scm_array_handle_set */
  97. SCM_INTERNAL void scm_init_array_handle (void);
  98. #endif /* SCM_ARRAY_HANDLE_H */
  99. /*
  100. Local Variables:
  101. c-file-style: "gnu"
  102. End:
  103. */