3 #ifndef SCM_ARRAY_HANDLE_H
4 #define SCM_ARRAY_HANDLE_H
6 /* Copyright (C) 1995, 1996, 1997, 1999, 2000, 2001, 2004, 2006,
7 * 2008, 2009, 2011 Free Software Foundation, Inc.
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.
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.
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
27 #include "libguile/__scm.h"
31 struct scm_t_array_handle
;
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
);
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
;
45 #define SCM_ARRAY_IMPLEMENTATION(tag_,mask_,vref_,vset_,handle_) \
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); \
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
);
61 typedef struct scm_t_array_dim
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
;
89 SCM_INTERNAL SCM scm_i_array_element_types
[];
92 typedef struct scm_t_array_handle
{
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.
102 size_t ndims
; /* ndims == the rank of the array */
103 scm_t_array_dim
*dims
;
104 scm_t_array_dim dim0
;
105 scm_t_array_element_type element_type
;
106 const void *elements
;
107 void *writable_elements
;
108 } scm_t_array_handle
;
110 #define scm_array_handle_rank(h) ((h)->ndims)
111 #define scm_array_handle_dims(h) ((h)->dims)
113 SCM_API
void scm_array_get_handle (SCM array
, scm_t_array_handle
*h
);
114 SCM_API ssize_t
scm_array_handle_pos (scm_t_array_handle
*h
, SCM indices
);
115 SCM_API SCM
scm_array_handle_element_type (scm_t_array_handle
*h
);
116 SCM_API
void scm_array_handle_release (scm_t_array_handle
*h
);
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
);
120 /* See inline.h for scm_array_handle_ref and scm_array_handle_set */
122 SCM_INTERNAL
void scm_init_array_handle (void);
125 #endif /* SCM_ARRAY_HANDLE_H */