Commit | Line | Data |
---|---|---|
1ee2c72e LC |
1 | #ifndef SCM_BYTEVECTORS_H |
2 | #define SCM_BYTEVECTORS_H | |
3 | ||
059a588f | 4 | /* Copyright (C) 2009, 2011 Free Software Foundation, Inc. |
1ee2c72e LC |
5 | * |
6 | * This library is free software; you can redistribute it and/or | |
53befeb7 NJ |
7 | * modify it under the terms of the GNU Lesser General Public License |
8 | * as published by the Free Software Foundation; either version 3 of | |
9 | * the License, or (at your option) any later version. | |
1ee2c72e | 10 | * |
53befeb7 NJ |
11 | * This library is distributed in the hope that it will be useful, but |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1ee2c72e LC |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
53befeb7 NJ |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | * 02110-1301 USA | |
1ee2c72e LC |
20 | */ |
21 | ||
22 | \f | |
23 | ||
24 | #include "libguile/__scm.h" | |
25 | ||
26 | ||
27 | /* R6RS bytevectors. */ | |
28 | ||
3fe87cf7 LC |
29 | /* The size in words of the bytevector header (type tag and flags, length, |
30 | and pointer to the underlying buffer). */ | |
059a588f | 31 | #define SCM_BYTEVECTOR_HEADER_SIZE 4U |
0665b3ff | 32 | |
1ee2c72e | 33 | #define SCM_BYTEVECTOR_LENGTH(_bv) \ |
807e5a66 | 34 | ((size_t) SCM_CELL_WORD_1 (_bv)) |
3fe87cf7 LC |
35 | #define SCM_BYTEVECTOR_CONTENTS(_bv) \ |
36 | ((signed char *) SCM_CELL_WORD_2 (_bv)) | |
059a588f AW |
37 | #define SCM_BYTEVECTOR_PARENT(_bv) \ |
38 | (SCM_CELL_OBJECT_3 (_bv)) | |
1ee2c72e LC |
39 | |
40 | ||
41 | SCM_API SCM scm_endianness_big; | |
42 | SCM_API SCM scm_endianness_little; | |
43 | ||
2d34e924 | 44 | SCM_API SCM scm_c_make_bytevector (size_t); |
404bb5f8 LC |
45 | SCM_API int scm_is_bytevector (SCM); |
46 | SCM_API size_t scm_c_bytevector_length (SCM); | |
47 | SCM_API scm_t_uint8 scm_c_bytevector_ref (SCM, size_t); | |
48 | SCM_API void scm_c_bytevector_set_x (SCM, size_t, scm_t_uint8); | |
49 | ||
50 | SCM_API SCM scm_make_bytevector (SCM, SCM); | |
1ee2c72e LC |
51 | SCM_API SCM scm_native_endianness (void); |
52 | SCM_API SCM scm_bytevector_p (SCM); | |
53 | SCM_API SCM scm_bytevector_length (SCM); | |
54 | SCM_API SCM scm_bytevector_eq_p (SCM, SCM); | |
55 | SCM_API SCM scm_bytevector_fill_x (SCM, SCM); | |
56 | SCM_API SCM scm_bytevector_copy_x (SCM, SCM, SCM, SCM, SCM); | |
57 | SCM_API SCM scm_bytevector_copy (SCM); | |
58 | ||
782a82ee AW |
59 | SCM_API SCM scm_uniform_array_to_bytevector (SCM); |
60 | ||
1ee2c72e LC |
61 | SCM_API SCM scm_bytevector_to_u8_list (SCM); |
62 | SCM_API SCM scm_u8_list_to_bytevector (SCM); | |
63 | SCM_API SCM scm_uint_list_to_bytevector (SCM, SCM, SCM); | |
64 | SCM_API SCM scm_bytevector_to_uint_list (SCM, SCM, SCM); | |
65 | SCM_API SCM scm_sint_list_to_bytevector (SCM, SCM, SCM); | |
66 | SCM_API SCM scm_bytevector_to_sint_list (SCM, SCM, SCM); | |
67 | ||
68 | SCM_API SCM scm_bytevector_u16_native_ref (SCM, SCM); | |
69 | SCM_API SCM scm_bytevector_s16_native_ref (SCM, SCM); | |
70 | SCM_API SCM scm_bytevector_u32_native_ref (SCM, SCM); | |
71 | SCM_API SCM scm_bytevector_s32_native_ref (SCM, SCM); | |
72 | SCM_API SCM scm_bytevector_u64_native_ref (SCM, SCM); | |
73 | SCM_API SCM scm_bytevector_s64_native_ref (SCM, SCM); | |
74 | SCM_API SCM scm_bytevector_u8_ref (SCM, SCM); | |
75 | SCM_API SCM scm_bytevector_s8_ref (SCM, SCM); | |
76 | SCM_API SCM scm_bytevector_uint_ref (SCM, SCM, SCM, SCM); | |
77 | SCM_API SCM scm_bytevector_sint_ref (SCM, SCM, SCM, SCM); | |
78 | SCM_API SCM scm_bytevector_u16_ref (SCM, SCM, SCM); | |
79 | SCM_API SCM scm_bytevector_s16_ref (SCM, SCM, SCM); | |
80 | SCM_API SCM scm_bytevector_u32_ref (SCM, SCM, SCM); | |
81 | SCM_API SCM scm_bytevector_s32_ref (SCM, SCM, SCM); | |
82 | SCM_API SCM scm_bytevector_u64_ref (SCM, SCM, SCM); | |
83 | SCM_API SCM scm_bytevector_s64_ref (SCM, SCM, SCM); | |
84 | SCM_API SCM scm_bytevector_u16_native_set_x (SCM, SCM, SCM); | |
85 | SCM_API SCM scm_bytevector_s16_native_set_x (SCM, SCM, SCM); | |
86 | SCM_API SCM scm_bytevector_u32_native_set_x (SCM, SCM, SCM); | |
87 | SCM_API SCM scm_bytevector_s32_native_set_x (SCM, SCM, SCM); | |
88 | SCM_API SCM scm_bytevector_u64_native_set_x (SCM, SCM, SCM); | |
89 | SCM_API SCM scm_bytevector_s64_native_set_x (SCM, SCM, SCM); | |
90 | SCM_API SCM scm_bytevector_u8_set_x (SCM, SCM, SCM); | |
91 | SCM_API SCM scm_bytevector_s8_set_x (SCM, SCM, SCM); | |
92 | SCM_API SCM scm_bytevector_uint_set_x (SCM, SCM, SCM, SCM, SCM); | |
93 | SCM_API SCM scm_bytevector_sint_set_x (SCM, SCM, SCM, SCM, SCM); | |
94 | SCM_API SCM scm_bytevector_u16_set_x (SCM, SCM, SCM, SCM); | |
95 | SCM_API SCM scm_bytevector_s16_set_x (SCM, SCM, SCM, SCM); | |
96 | SCM_API SCM scm_bytevector_u32_set_x (SCM, SCM, SCM, SCM); | |
97 | SCM_API SCM scm_bytevector_s32_set_x (SCM, SCM, SCM, SCM); | |
98 | SCM_API SCM scm_bytevector_u64_set_x (SCM, SCM, SCM, SCM); | |
99 | SCM_API SCM scm_bytevector_s64_set_x (SCM, SCM, SCM, SCM); | |
100 | SCM_API SCM scm_bytevector_ieee_single_ref (SCM, SCM, SCM); | |
101 | SCM_API SCM scm_bytevector_ieee_single_native_ref (SCM, SCM); | |
102 | SCM_API SCM scm_bytevector_ieee_single_set_x (SCM, SCM, SCM, SCM); | |
103 | SCM_API SCM scm_bytevector_ieee_single_native_set_x (SCM, SCM, SCM); | |
104 | SCM_API SCM scm_bytevector_ieee_double_ref (SCM, SCM, SCM); | |
105 | SCM_API SCM scm_bytevector_ieee_double_native_ref (SCM, SCM); | |
106 | SCM_API SCM scm_bytevector_ieee_double_set_x (SCM, SCM, SCM, SCM); | |
107 | SCM_API SCM scm_bytevector_ieee_double_native_set_x (SCM, SCM, SCM); | |
108 | SCM_API SCM scm_string_to_utf8 (SCM); | |
109 | SCM_API SCM scm_string_to_utf16 (SCM, SCM); | |
110 | SCM_API SCM scm_string_to_utf32 (SCM, SCM); | |
111 | SCM_API SCM scm_utf8_to_string (SCM); | |
112 | SCM_API SCM scm_utf16_to_string (SCM, SCM); | |
113 | SCM_API SCM scm_utf32_to_string (SCM, SCM); | |
114 | ||
115 | ||
116 | \f | |
117 | /* Internal API. */ | |
118 | ||
807e5a66 | 119 | #define SCM_BYTEVECTOR_P(x) \ |
dc7da0be | 120 | (SCM_HAS_TYP7 (x, scm_tc7_bytevector)) |
807e5a66 LC |
121 | #define SCM_BYTEVECTOR_FLAGS(_bv) \ |
122 | (SCM_CELL_TYPE (_bv) >> 7UL) | |
0665b3ff LC |
123 | #define SCM_SET_BYTEVECTOR_FLAGS(_bv, _f) \ |
124 | SCM_SET_CELL_TYPE ((_bv), \ | |
125 | scm_tc7_bytevector | ((scm_t_bits)(_f) << 7UL)) | |
807e5a66 | 126 | |
e286c973 | 127 | #define SCM_BYTEVECTOR_ELEMENT_TYPE(_bv) \ |
3fe87cf7 LC |
128 | (SCM_BYTEVECTOR_FLAGS (_bv) & 0xffUL) |
129 | #define SCM_BYTEVECTOR_CONTIGUOUS_P(_bv) \ | |
130 | (SCM_BYTEVECTOR_FLAGS (_bv) >> 8UL) | |
1ee2c72e LC |
131 | |
132 | /* Hint that is passed to `scm_gc_malloc ()' and friends. */ | |
133 | #define SCM_GC_BYTEVECTOR "bytevector" | |
134 | ||
3dc2afe2 AW |
135 | SCM_INTERNAL SCM scm_i_make_typed_bytevector (size_t, scm_t_array_element_type); |
136 | SCM_INTERNAL SCM scm_c_take_typed_bytevector (signed char *, size_t, | |
059a588f | 137 | scm_t_array_element_type, SCM); |
3dc2afe2 | 138 | |
cfb4702f LC |
139 | SCM_INTERNAL void scm_bootstrap_bytevectors (void); |
140 | SCM_INTERNAL void scm_init_bytevectors (void); | |
1ee2c72e | 141 | |
caa92f5e | 142 | SCM_INTERNAL SCM scm_i_native_endianness; |
8b66aa8f | 143 | SCM_INTERNAL SCM scm_c_take_gc_bytevector (signed char *, size_t, SCM); |
1ee2c72e | 144 | |
807e5a66 LC |
145 | SCM_INTERNAL int scm_i_print_bytevector (SCM, SCM, scm_print_state *); |
146 | ||
0665b3ff | 147 | SCM_INTERNAL SCM scm_c_shrink_bytevector (SCM, size_t); |
438974d0 | 148 | SCM_INTERNAL void scm_i_bytevector_generalized_set_x (SCM, size_t, SCM); |
1ee2c72e LC |
149 | SCM_INTERNAL SCM scm_null_bytevector; |
150 | ||
151 | #endif /* SCM_BYTEVECTORS_H */ |