Remove unused macros in goops.c
[bpt/guile.git] / libguile / array-handle.h
CommitLineData
c53c0893
AW
1/* classes: h_files */
2
3#ifndef SCM_ARRAY_HANDLE_H
4#define SCM_ARRAY_HANDLE_H
5
9c3fa20a 6/* Copyright (C) 1995, 1996, 1997, 1999, 2000, 2001, 2004, 2006,
7070f12b 7 * 2008, 2009, 2011, 2013, 2014 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"
18cd9aff
AW
28#include "libguile/error.h"
29#include "libguile/numbers.h"
c53c0893
AW
30
31\f
32
cf64dca6
AW
33typedef SCM (*scm_t_vector_ref) (SCM, size_t);
34typedef void (*scm_t_vector_set) (SCM, size_t, SCM);
2a610be5 35
c53c0893
AW
36typedef struct scm_t_array_dim
37{
38 ssize_t lbnd;
39 ssize_t ubnd;
40 ssize_t inc;
41} scm_t_array_dim;
42
9c3fa20a
LC
43typedef enum
44 {
45 SCM_ARRAY_ELEMENT_TYPE_SCM = 0, /* SCM values */
46 SCM_ARRAY_ELEMENT_TYPE_CHAR = 1, /* characters */
47 SCM_ARRAY_ELEMENT_TYPE_BIT = 2, /* packed numeric values */
48 SCM_ARRAY_ELEMENT_TYPE_VU8 = 3,
49 SCM_ARRAY_ELEMENT_TYPE_U8 = 4,
50 SCM_ARRAY_ELEMENT_TYPE_S8 = 5,
51 SCM_ARRAY_ELEMENT_TYPE_U16 = 6,
52 SCM_ARRAY_ELEMENT_TYPE_S16 = 7,
53 SCM_ARRAY_ELEMENT_TYPE_U32 = 8,
54 SCM_ARRAY_ELEMENT_TYPE_S32 = 9,
55 SCM_ARRAY_ELEMENT_TYPE_U64 = 10,
56 SCM_ARRAY_ELEMENT_TYPE_S64 = 11,
57 SCM_ARRAY_ELEMENT_TYPE_F32 = 12,
58 SCM_ARRAY_ELEMENT_TYPE_F64 = 13,
59 SCM_ARRAY_ELEMENT_TYPE_C32 = 14,
60 SCM_ARRAY_ELEMENT_TYPE_C64 = 15,
61 SCM_ARRAY_ELEMENT_TYPE_LAST = 15
62 } scm_t_array_element_type;
2a610be5
AW
63
64SCM_INTERNAL SCM scm_i_array_element_types[];
c53c0893 65
c53c0893
AW
66
67typedef struct scm_t_array_handle {
68 SCM array;
cf64dca6 69
2a610be5
AW
70 /* `Base' is an offset into elements or writable_elements, corresponding to
71 the first element in the array. It would be nicer just to adjust the
72 elements/writable_elements pointer, but we can't because that element might
73 not even be byte-addressable, as is the case with bitvectors. A nicer
74 solution would be, well, nice.
75 */
c53c0893 76 size_t base;
2a610be5 77 size_t ndims; /* ndims == the rank of the array */
c53c0893
AW
78 scm_t_array_dim *dims;
79 scm_t_array_dim dim0;
2a610be5 80 scm_t_array_element_type element_type;
c53c0893
AW
81 const void *elements;
82 void *writable_elements;
a0ef1252
AW
83
84 /* The backing store for the array, and its accessors. */
85 SCM vector;
cf64dca6
AW
86 scm_t_vector_ref vref;
87 scm_t_vector_set vset;
c53c0893
AW
88} scm_t_array_handle;
89
2a610be5
AW
90#define scm_array_handle_rank(h) ((h)->ndims)
91#define scm_array_handle_dims(h) ((h)->dims)
92
c53c0893 93SCM_API void scm_array_get_handle (SCM array, scm_t_array_handle *h);
c53c0893 94SCM_API ssize_t scm_array_handle_pos (scm_t_array_handle *h, SCM indices);
336c9211
AW
95SCM_API ssize_t scm_array_handle_pos_1 (scm_t_array_handle *h, ssize_t idx0);
96SCM_API ssize_t scm_array_handle_pos_2 (scm_t_array_handle *h, ssize_t idx0, ssize_t idx1);
2a610be5 97SCM_API SCM scm_array_handle_element_type (scm_t_array_handle *h);
c53c0893 98SCM_API void scm_array_handle_release (scm_t_array_handle *h);
2a610be5
AW
99SCM_API const SCM* scm_array_handle_elements (scm_t_array_handle *h);
100SCM_API SCM* scm_array_handle_writable_elements (scm_t_array_handle *h);
c53c0893 101
18cd9aff
AW
102
103SCM_INLINE SCM scm_array_handle_ref (scm_t_array_handle *h, ssize_t pos);
104SCM_INLINE void scm_array_handle_set (scm_t_array_handle *h, ssize_t pos, SCM val);
105
106#if SCM_CAN_INLINE || defined SCM_INLINE_C_IMPLEMENTING_INLINES
107/* Either inlining, or being included from inline.c. */
108
109SCM_INLINE_IMPLEMENTATION SCM
110scm_array_handle_ref (scm_t_array_handle *h, ssize_t p)
111{
112 if (SCM_UNLIKELY (p < 0 && ((size_t)-p) > h->base))
113 /* catch overflow */
114 scm_out_of_range (NULL, scm_from_ssize_t (p));
115 /* perhaps should catch overflow here too */
cf64dca6 116 return h->vref (h->vector, h->base + p);
18cd9aff
AW
117}
118
119SCM_INLINE_IMPLEMENTATION void
120scm_array_handle_set (scm_t_array_handle *h, ssize_t p, SCM v)
121{
122 if (SCM_UNLIKELY (p < 0 && ((size_t)-p) > h->base))
123 /* catch overflow */
124 scm_out_of_range (NULL, scm_from_ssize_t (p));
125 /* perhaps should catch overflow here too */
cf64dca6 126 h->vset (h->vector, h->base + p, v);
18cd9aff
AW
127}
128
129#endif
130
c53c0893
AW
131
132SCM_INTERNAL void scm_init_array_handle (void);
133
134
135#endif /* SCM_ARRAY_HANDLE_H */
136
137/*
138 Local Variables:
139 c-file-style: "gnu"
140 End:
141*/