/* Copyright (C) 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
*/
\f
/* R6RS bytevectors. */
+/* The size in words of the bytevector header (type tag, flags, and
+ length). */
+#define SCM_BYTEVECTOR_HEADER_SIZE 2U
+
#define SCM_BYTEVECTOR_LENGTH(_bv) \
- ((unsigned) SCM_SMOB_DATA (_bv))
-#define SCM_BYTEVECTOR_CONTENTS(_bv) \
- (SCM_BYTEVECTOR_INLINE_P (_bv) \
- ? (signed char *) SCM_SMOB_OBJECT_2_LOC (_bv) \
- : (signed char *) SCM_SMOB_DATA_2 (_bv))
+ ((size_t) SCM_CELL_WORD_1 (_bv))
+#define SCM_BYTEVECTOR_CONTENTS(_bv) \
+ ((signed char *) SCM_CELL_OBJECT_LOC ((_bv), \
+ SCM_BYTEVECTOR_HEADER_SIZE))
SCM_API SCM scm_endianness_big;
SCM_API SCM scm_endianness_little;
+SCM_API SCM scm_c_make_bytevector (size_t);
+SCM_API int scm_is_bytevector (SCM);
+SCM_API size_t scm_c_bytevector_length (SCM);
+SCM_API scm_t_uint8 scm_c_bytevector_ref (SCM, size_t);
+SCM_API void scm_c_bytevector_set_x (SCM, size_t, scm_t_uint8);
+
SCM_API SCM scm_make_bytevector (SCM, SCM);
-SCM_API SCM scm_c_make_bytevector (unsigned);
SCM_API SCM scm_native_endianness (void);
SCM_API SCM scm_bytevector_p (SCM);
SCM_API SCM scm_bytevector_length (SCM);
\f
/* Internal API. */
-/* The threshold (in octets) under which bytevectors are stored "in-line",
- i.e., without allocating memory beside the SMOB itself (a double cell).
- This optimization is necessary since small bytevectors are expected to be
- common. */
-#define SCM_BYTEVECTOR_INLINE_THRESHOLD (2 * sizeof (SCM))
-#define SCM_BYTEVECTOR_INLINEABLE_SIZE_P(_size) \
- ((_size) <= SCM_BYTEVECTOR_INLINE_THRESHOLD)
-#define SCM_BYTEVECTOR_INLINE_P(_bv) \
- (SCM_BYTEVECTOR_INLINEABLE_SIZE_P (SCM_BYTEVECTOR_LENGTH (_bv)))
+#define SCM_BYTEVECTOR_P(x) \
+ (!SCM_IMP (x) && SCM_TYP7(x) == scm_tc7_bytevector)
+#define SCM_BYTEVECTOR_FLAGS(_bv) \
+ (SCM_CELL_TYPE (_bv) >> 7UL)
+#define SCM_SET_BYTEVECTOR_FLAGS(_bv, _f) \
+ SCM_SET_CELL_TYPE ((_bv), \
+ scm_tc7_bytevector | ((scm_t_bits)(_f) << 7UL))
+
+#define SCM_BYTEVECTOR_ELEMENT_TYPE(_bv) \
+ (SCM_BYTEVECTOR_FLAGS (_bv))
/* Hint that is passed to `scm_gc_malloc ()' and friends. */
#define SCM_GC_BYTEVECTOR "bytevector"
-SCM_API void scm_init_bytevectors (void);
+SCM_INTERNAL SCM scm_i_make_typed_bytevector (size_t, scm_t_array_element_type);
+SCM_INTERNAL SCM scm_c_take_typed_bytevector (signed char *, size_t,
+ scm_t_array_element_type);
+
+SCM_INTERNAL void scm_bootstrap_bytevectors (void);
+SCM_INTERNAL void scm_init_bytevectors (void);
-SCM_INTERNAL scm_t_bits scm_tc16_bytevector;
-SCM_INTERNAL SCM scm_c_take_bytevector (signed char *, unsigned);
+SCM_INTERNAL SCM scm_i_native_endianness;
+SCM_INTERNAL SCM scm_c_take_bytevector (signed char *, size_t);
-#define scm_c_shrink_bytevector(_bv, _len) \
- (SCM_BYTEVECTOR_INLINE_P (_bv) \
- ? (_bv) \
- : scm_i_shrink_bytevector ((_bv), (_len)))
+SCM_INTERNAL int scm_i_print_bytevector (SCM, SCM, scm_print_state *);
-SCM_INTERNAL SCM scm_i_shrink_bytevector (SCM, unsigned);
+SCM_INTERNAL SCM scm_c_shrink_bytevector (SCM, size_t);
+SCM_INTERNAL void scm_i_bytevector_generalized_set_x (SCM, size_t, SCM);
SCM_INTERNAL SCM scm_null_bytevector;
#endif /* SCM_BYTEVECTORS_H */