mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-01 15:20:34 +02:00
Also move most internal vector representation into a private header file. * libguile/vectors-internal.h: New file. * libguile/vectors.h (SCM_I_IS_MUTABLE_VECTOR, SCM_I_VECTOR_WELTS) (SCM_I_VECTOR_ELTS, SCM_I_VECTOR_LENGTH): Remove these internal definitions. * libguile/vectors.c: Adapt to use new data types. * libguile/eval.c: Include internal file. * libguile/init.c: Include internal file. * libguile/array-handle.c (scm_array_get_handle): Use new functions.
93 lines
2.1 KiB
C
93 lines
2.1 KiB
C
#ifndef SCM_VECTORS_INTERNAL_H
|
||
#define SCM_VECTORS_INTERNAL_H
|
||
|
||
/* Copyright 1995-1996,1998,2000-2002,2004-2006,2008-2009,2011,2014,2018,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
|
||
<https://www.gnu.org/licenses/>. */
|
||
|
||
|
||
|
||
#include "libguile/vectors.h"
|
||
|
||
|
||
|
||
#define SCM_F_VECTOR_IMMUTABLE 0x80UL
|
||
|
||
struct scm_vector
|
||
{
|
||
scm_t_bits tag_and_size;
|
||
SCM slots[];
|
||
};
|
||
|
||
static inline int
|
||
scm_is_mutable_vector (SCM x)
|
||
{
|
||
return SCM_NIMP (x) &&
|
||
(SCM_CELL_TYPE (x) & (0x7f | SCM_F_VECTOR_IMMUTABLE)) == scm_tc7_vector;
|
||
}
|
||
|
||
static inline struct scm_vector *
|
||
scm_to_vector (SCM v)
|
||
{
|
||
if (!scm_is_vector (v))
|
||
abort ();
|
||
return (struct scm_vector *) SCM_UNPACK_POINTER (v);
|
||
}
|
||
|
||
static inline SCM
|
||
scm_from_vector (struct scm_vector *v)
|
||
{
|
||
return SCM_PACK_POINTER (v);
|
||
}
|
||
|
||
static inline size_t
|
||
scm_i_vector_length (struct scm_vector *v)
|
||
{
|
||
return v->tag_and_size >> 8;
|
||
}
|
||
|
||
static inline SCM*
|
||
scm_i_vector_slots (struct scm_vector *v)
|
||
{
|
||
return v->slots;
|
||
}
|
||
|
||
static inline SCM*
|
||
scm_i_vector_slot (struct scm_vector *v, size_t idx)
|
||
{
|
||
if (idx >= scm_i_vector_length (v))
|
||
abort ();
|
||
return &scm_i_vector_slots (v)[idx];
|
||
}
|
||
|
||
static inline SCM
|
||
scm_i_vector_ref (struct scm_vector *v, size_t idx)
|
||
{
|
||
return *scm_i_vector_slot (v, idx);
|
||
}
|
||
|
||
static inline void
|
||
scm_i_vector_set_x (struct scm_vector *v, size_t idx, SCM val)
|
||
{
|
||
*scm_i_vector_slot (v, idx) = val;
|
||
}
|
||
|
||
SCM_INTERNAL SCM scm_i_vector_equal_p (SCM x, SCM y);
|
||
SCM_INTERNAL void scm_init_vectors (void);
|
||
|
||
#endif /* SCM_VECTORS_INTERNAL_H */
|