Commit | Line | Data |
---|---|---|
c53c0893 AW |
1 | /* classes: h_files */ |
2 | ||
3 | #ifndef SCM_ARRAY_HANDLE_H | |
4 | #define SCM_ARRAY_HANDLE_H | |
5 | ||
9c3fa20a LC |
6 | /* Copyright (C) 1995, 1996, 1997, 1999, 2000, 2001, 2004, 2006, |
7 | * 2008, 2009, 2011 Free Software Foundation, Inc. | |
c53c0893 AW |
8 | * |
9 | * This library is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU Lesser General Public License | |
11 | * as published by the Free Software Foundation; either version 3 of | |
12 | * the License, or (at your option) any later version. | |
13 | * | |
14 | * This library is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * Lesser General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU Lesser General Public | |
20 | * License along with this library; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
22 | * 02110-1301 USA | |
23 | */ | |
24 | ||
25 | \f | |
26 | ||
27 | #include "libguile/__scm.h" | |
28 | ||
29 | \f | |
30 | ||
2a610be5 AW |
31 | struct scm_t_array_handle; |
32 | ||
33 | typedef SCM (*scm_i_t_array_ref) (struct scm_t_array_handle *, size_t); | |
34 | typedef void (*scm_i_t_array_set) (struct scm_t_array_handle *, size_t, SCM); | |
35 | ||
36 | typedef struct | |
37 | { | |
38 | scm_t_bits tag; | |
39 | scm_t_bits mask; | |
40 | scm_i_t_array_ref vref; | |
41 | scm_i_t_array_set vset; | |
42 | void (*get_handle)(SCM, struct scm_t_array_handle*); | |
43 | } scm_t_array_implementation; | |
44 | ||
45 | #define SCM_ARRAY_IMPLEMENTATION(tag_,mask_,vref_,vset_,handle_) \ | |
46 | SCM_SNARF_INIT ({ \ | |
47 | scm_t_array_implementation impl; \ | |
48 | impl.tag = tag_; impl.mask = mask_; \ | |
49 | impl.vref = vref_; impl.vset = vset_; \ | |
50 | impl.get_handle = handle_; \ | |
51 | scm_i_register_array_implementation (&impl); \ | |
52 | }) | |
53 | ||
54 | ||
55 | SCM_INTERNAL void scm_i_register_array_implementation (scm_t_array_implementation *impl); | |
56 | SCM_INTERNAL scm_t_array_implementation* scm_i_array_implementation_for_obj (SCM obj); | |
57 | ||
58 | ||
59 | \f | |
60 | ||
c53c0893 AW |
61 | typedef struct scm_t_array_dim |
62 | { | |
63 | ssize_t lbnd; | |
64 | ssize_t ubnd; | |
65 | ssize_t inc; | |
66 | } scm_t_array_dim; | |
67 | ||
9c3fa20a LC |
68 | typedef enum |
69 | { | |
70 | SCM_ARRAY_ELEMENT_TYPE_SCM = 0, /* SCM values */ | |
71 | SCM_ARRAY_ELEMENT_TYPE_CHAR = 1, /* characters */ | |
72 | SCM_ARRAY_ELEMENT_TYPE_BIT = 2, /* packed numeric values */ | |
73 | SCM_ARRAY_ELEMENT_TYPE_VU8 = 3, | |
74 | SCM_ARRAY_ELEMENT_TYPE_U8 = 4, | |
75 | SCM_ARRAY_ELEMENT_TYPE_S8 = 5, | |
76 | SCM_ARRAY_ELEMENT_TYPE_U16 = 6, | |
77 | SCM_ARRAY_ELEMENT_TYPE_S16 = 7, | |
78 | SCM_ARRAY_ELEMENT_TYPE_U32 = 8, | |
79 | SCM_ARRAY_ELEMENT_TYPE_S32 = 9, | |
80 | SCM_ARRAY_ELEMENT_TYPE_U64 = 10, | |
81 | SCM_ARRAY_ELEMENT_TYPE_S64 = 11, | |
82 | SCM_ARRAY_ELEMENT_TYPE_F32 = 12, | |
83 | SCM_ARRAY_ELEMENT_TYPE_F64 = 13, | |
84 | SCM_ARRAY_ELEMENT_TYPE_C32 = 14, | |
85 | SCM_ARRAY_ELEMENT_TYPE_C64 = 15, | |
86 | SCM_ARRAY_ELEMENT_TYPE_LAST = 15 | |
87 | } scm_t_array_element_type; | |
2a610be5 AW |
88 | |
89 | SCM_INTERNAL SCM scm_i_array_element_types[]; | |
c53c0893 | 90 | |
c53c0893 AW |
91 | |
92 | typedef struct scm_t_array_handle { | |
93 | SCM array; | |
2a610be5 AW |
94 | scm_t_array_implementation *impl; |
95 | /* `Base' is an offset into elements or writable_elements, corresponding to | |
96 | the first element in the array. It would be nicer just to adjust the | |
97 | elements/writable_elements pointer, but we can't because that element might | |
98 | not even be byte-addressable, as is the case with bitvectors. A nicer | |
99 | solution would be, well, nice. | |
100 | */ | |
c53c0893 | 101 | size_t base; |
2a610be5 | 102 | size_t ndims; /* ndims == the rank of the array */ |
c53c0893 AW |
103 | scm_t_array_dim *dims; |
104 | scm_t_array_dim dim0; | |
2a610be5 | 105 | scm_t_array_element_type element_type; |
c53c0893 AW |
106 | const void *elements; |
107 | void *writable_elements; | |
108 | } scm_t_array_handle; | |
109 | ||
2a610be5 AW |
110 | #define scm_array_handle_rank(h) ((h)->ndims) |
111 | #define scm_array_handle_dims(h) ((h)->dims) | |
112 | ||
c53c0893 | 113 | SCM_API void scm_array_get_handle (SCM array, scm_t_array_handle *h); |
c53c0893 | 114 | SCM_API ssize_t scm_array_handle_pos (scm_t_array_handle *h, SCM indices); |
2a610be5 | 115 | SCM_API SCM scm_array_handle_element_type (scm_t_array_handle *h); |
c53c0893 | 116 | SCM_API void scm_array_handle_release (scm_t_array_handle *h); |
2a610be5 AW |
117 | SCM_API const SCM* scm_array_handle_elements (scm_t_array_handle *h); |
118 | SCM_API SCM* scm_array_handle_writable_elements (scm_t_array_handle *h); | |
c53c0893 AW |
119 | |
120 | /* See inline.h for scm_array_handle_ref and scm_array_handle_set */ | |
121 | ||
122 | SCM_INTERNAL void scm_init_array_handle (void); | |
123 | ||
124 | ||
125 | #endif /* SCM_ARRAY_HANDLE_H */ | |
126 | ||
127 | /* | |
128 | Local Variables: | |
129 | c-file-style: "gnu" | |
130 | End: | |
131 | */ |