mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-09 05:30:21 +02:00
Give arrays a proper type in C land
As long as we have a tc7 for arrays, we should be able to access it with a struct type instead of casting each word. * libguile/arrays-internal.h: New file. * libguile/arrays.h (scm_array_p): Take just one argument. (SCM_I_ARRAYP): (SCM_I_ARRAY_NDIM): (SCM_I_ARRAY_V): (SCM_I_ARRAY_BASE): (SCM_I_ARRAY_DIMS): (SCM_I_ARRAY_SET_V): (SCM_I_ARRAY_SET_BASE): Remove. (scm_i_raw_array, scm_i_make_array, scm_i_shap2ra, scm_init_arrays): Remove internally-linked decls. * libguile/init.c: * libguile/print.c: * libguile/array-handle.c: Use interfaces from new file. * module/system/vm/assembler.scm: Update, as we now shift the dimension count by only 16. Requires a rebuild!
This commit is contained in:
parent
12e8772403
commit
9ff7c0651c
8 changed files with 248 additions and 178 deletions
86
libguile/arrays-internal.h
Normal file
86
libguile/arrays-internal.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
#ifndef SCM_ARRAYS_INTERNAL_H
|
||||
#define SCM_ARRAYS_INTERNAL_H
|
||||
|
||||
/* Copyright 1995-1997,1999-2001,2004,2006,2008-2010,2012,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/arrays.h"
|
||||
|
||||
|
||||
|
||||
struct scm_array
|
||||
{
|
||||
scm_t_bits tag_and_ndims;
|
||||
SCM vector;
|
||||
size_t base;
|
||||
struct scm_t_array_dim dims[];
|
||||
};
|
||||
|
||||
/* There is a naming confusion: scm_is_array exists and is used for
|
||||
generalized arrays, allowing e.g. (array? #(1 2 3)) to be true. Here
|
||||
we are concerned with proper multidimensional arrays, which are their
|
||||
own data type. Mostly we can use this "struct scm_array" as a way to
|
||||
avoid confusion, but we have to name this function
|
||||
"scm_is_tagged_array" instead of "scm_is_array" as we would like. */
|
||||
static inline int
|
||||
scm_is_tagged_array (SCM x)
|
||||
{
|
||||
return SCM_HAS_TYP7 (x, scm_tc7_array);
|
||||
}
|
||||
|
||||
static inline struct scm_array*
|
||||
scm_to_array (SCM x)
|
||||
{
|
||||
if (!scm_is_tagged_array (x))
|
||||
abort ();
|
||||
return (struct scm_array *) SCM_UNPACK_POINTER (x);
|
||||
}
|
||||
|
||||
static inline SCM
|
||||
scm_from_array (struct scm_array *x)
|
||||
{
|
||||
return SCM_PACK_POINTER (x);
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
scm_array_dimension_count (struct scm_array *array)
|
||||
{
|
||||
return array->tag_and_ndims >> 16;
|
||||
}
|
||||
|
||||
static inline SCM
|
||||
scm_array_vector (struct scm_array *array)
|
||||
{
|
||||
return array->vector;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
scm_array_base (struct scm_array *array)
|
||||
{
|
||||
return array->base;
|
||||
}
|
||||
|
||||
SCM_INTERNAL struct scm_array* scm_i_make_array (SCM v, size_t base, int ndim);
|
||||
SCM_INTERNAL int scm_i_print_array (SCM array, SCM port, scm_print_state *pstate);
|
||||
|
||||
SCM_INTERNAL void scm_init_arrays (void);
|
||||
|
||||
#endif /* SCM_ARRAYS_INTERNAL_H */
|
Loading…
Add table
Add a link
Reference in a new issue