#ifndef SCM_BITVECTORS_INTERNAL_H #define SCM_BITVECTORS_INTERNAL_H /* Copyright 1995-1997,1999-2001,2004,2006,2008-2009,2014,2018,2020,2025 Free Software Foundation, Inc. This file is part of Guile. Guile 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 3 of the License, or (at your option) any later version. Guile 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 Guile. If not, see . */ #include "libguile/bitvectors.h" #include "libguile/snarf.h" struct scm_bitvector { scm_t_bits tag_and_flags; size_t length; scm_t_bits bits[]; }; #define SCM_F_BITVECTOR_IMMUTABLE (0x80) static inline int scm_is_mutable_bitvector (SCM obj) { return SCM_NIMP (obj) && ((SCM_CELL_TYPE (obj) & (0x7f | SCM_F_BITVECTOR_IMMUTABLE)) == scm_tc7_bitvector); } static inline struct scm_bitvector* scm_to_bitvector (SCM obj) { if (!scm_is_bitvector (obj)) abort (); return (struct scm_bitvector*) SCM_UNPACK_POINTER (obj); } static inline SCM scm_from_bitvector (struct scm_bitvector *bv) { return SCM_PACK_POINTER (bv); } static inline size_t scm_bitvector_length (struct scm_bitvector *bv) { return bv->length; } static inline scm_t_bits* scm_bitvector_bits (struct scm_bitvector *bv) { return bv->bits; } #define VALIDATE_BITVECTOR(_pos, _obj) \ SCM_ASSERT_TYPE (scm_is_bitvector (_obj), (_obj), (_pos), FUNC_NAME, \ "bitvector") #define VALIDATE_MUTABLE_BITVECTOR(_pos, _obj) \ SCM_ASSERT_TYPE (scm_is_mutable_bitvector (_obj), (_obj), (_pos), \ FUNC_NAME, "mutable bitvector") static inline size_t scm_bitvector_word_length (struct scm_bitvector *bv) { const size_t bits_per_word = sizeof (scm_t_bits) * 8; return (bv->length + bits_per_word - 1) / bits_per_word; } static inline scm_t_bits scm_bitvector_last_mask (struct scm_bitvector *bv) { const size_t bits_per_word = sizeof (scm_t_bits) * 8; size_t rem = bv->length % bits_per_word; return rem ? (((scm_t_bits) 1) << rem) - 1 : -1; } SCM_INTERNAL int scm_i_print_bitvector (SCM vec, SCM port, scm_print_state *pstate); SCM_INTERNAL SCM scm_i_bitvector_equal_p (SCM vec1, SCM vec2); SCM_INTERNAL void scm_init_bitvectors (void); #endif /* SCM_BITVECTORS_INTERNAL_H */