mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-01 07:20:20 +02:00
* libguile/gc.h: * libguile/pairs.h (scm_pair_car_loc, scm_pair_cdr_loc): New helpers. (SCM_CARLOC, SCM_CDRLOC): Move here from gc.h. * libguile/list.c (scm_list_1, scm_list_2, scm_list_3): Just use scm_cons.
239 lines
6.7 KiB
C
239 lines
6.7 KiB
C
#ifndef SCM_PAIRS_H
|
||
#define SCM_PAIRS_H
|
||
|
||
/* Copyright 1995-1996,2000-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/error.h"
|
||
#include "libguile/gc.h"
|
||
#include "libguile/inline.h"
|
||
|
||
|
||
|
||
|
||
/*
|
||
* Use scm_is_null_and_not_nil if it's important (for correctness)
|
||
* that #nil must NOT be considered null.
|
||
*/
|
||
#define scm_is_null_and_not_nil(x) (scm_is_eq ((x), SCM_EOL))
|
||
|
||
/*
|
||
* Use scm_is_null_assume_not_nil if
|
||
#nil will never be tested,
|
||
* for increased efficiency.
|
||
*/
|
||
#define scm_is_null_assume_not_nil(x) (scm_is_eq ((x), SCM_EOL))
|
||
|
||
/*
|
||
* See the comments preceeding the definitions of SCM_BOOL_F and
|
||
* SCM_MATCHES_BITS_IN_COMMON in scm.h for more information on how the
|
||
* following macro works.
|
||
*/
|
||
#define scm_is_null_or_nil(x) \
|
||
(SCM_MATCHES_BITS_IN_COMMON ((x), SCM_ELISP_NIL, SCM_EOL))
|
||
|
||
|
||
|
||
|
||
/* Older spellings for these null, nil, and pair predicates. */
|
||
#define SCM_NILP(x) (scm_is_eq ((x), SCM_ELISP_NIL))
|
||
#define SCM_NULL_OR_NIL_P(x) (scm_is_null_or_nil (x))
|
||
#define SCM_NULLP(x) (scm_is_null (x))
|
||
#define SCM_NNULLP(x) (!scm_is_null (x))
|
||
#define SCM_CONSP(x) (scm_is_pair (x))
|
||
#define SCM_NCONSP(x) (!SCM_CONSP (x))
|
||
|
||
|
||
|
||
|
||
/* #nil is null. */
|
||
#define scm_is_null(x) (scm_is_null_or_nil(x))
|
||
|
||
struct scm_pair
|
||
{
|
||
SCM car;
|
||
SCM cdr;
|
||
};
|
||
|
||
static inline int
|
||
scm_is_pair (SCM x)
|
||
{
|
||
return SCM_I_CONSP (x);
|
||
}
|
||
|
||
static inline struct scm_pair *
|
||
scm_to_pair (SCM x)
|
||
{
|
||
if (!scm_is_pair (x))
|
||
abort ();
|
||
return (struct scm_pair *) SCM_UNPACK_POINTER (x);
|
||
}
|
||
|
||
static inline SCM
|
||
scm_from_pair (struct scm_pair *pair)
|
||
{
|
||
return SCM_PACK_POINTER (pair);
|
||
}
|
||
|
||
static inline SCM
|
||
scm_pair_car (struct scm_pair *pair)
|
||
{
|
||
return pair->car;
|
||
}
|
||
|
||
static inline SCM
|
||
scm_pair_cdr (struct scm_pair *pair)
|
||
{
|
||
return pair->cdr;
|
||
}
|
||
|
||
static inline void
|
||
scm_pair_set_car_x (struct scm_pair *pair, SCM car)
|
||
{
|
||
pair->car = car;
|
||
}
|
||
|
||
static inline void
|
||
scm_pair_set_cdr_x (struct scm_pair *pair, SCM cdr)
|
||
{
|
||
pair->cdr = cdr;
|
||
}
|
||
|
||
static inline SCM*
|
||
scm_pair_car_loc (struct scm_pair *pair)
|
||
{
|
||
return &pair->car;
|
||
}
|
||
|
||
static inline SCM*
|
||
scm_pair_cdr_loc (struct scm_pair *pair)
|
||
{
|
||
return &pair->cdr;
|
||
}
|
||
|
||
#define SCM_CAR(x) (scm_pair_car (scm_to_pair (x)))
|
||
#define SCM_CDR(x) (scm_pair_cdr (scm_to_pair (x)))
|
||
|
||
#define SCM_SETCAR(x, v) (scm_pair_set_car_x (scm_to_pair (x), v))
|
||
#define SCM_SETCDR(x, v) (scm_pair_set_cdr_x (scm_to_pair (x), v))
|
||
|
||
#define SCM_CARLOC(x) (scm_pair_car_loc (scm_to_pair (x)))
|
||
#define SCM_CDRLOC(x) (scm_pair_cdr_loc (scm_to_pair (x)))
|
||
|
||
#define SCM_CAAR(OBJ) SCM_CAR (SCM_CAR (OBJ))
|
||
#define SCM_CDAR(OBJ) SCM_CDR (SCM_CAR (OBJ))
|
||
#define SCM_CADR(OBJ) SCM_CAR (SCM_CDR (OBJ))
|
||
#define SCM_CDDR(OBJ) SCM_CDR (SCM_CDR (OBJ))
|
||
|
||
#define SCM_CAAAR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (OBJ)))
|
||
#define SCM_CDAAR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (OBJ)))
|
||
#define SCM_CADAR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (OBJ)))
|
||
#define SCM_CDDAR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (OBJ)))
|
||
#define SCM_CAADR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (OBJ)))
|
||
#define SCM_CDADR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (OBJ)))
|
||
#define SCM_CADDR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (OBJ)))
|
||
#define SCM_CDDDR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (OBJ)))
|
||
|
||
#define SCM_CAAAAR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (SCM_CAR (OBJ))))
|
||
#define SCM_CDAAAR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (SCM_CAR (OBJ))))
|
||
#define SCM_CADAAR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (SCM_CAR (OBJ))))
|
||
#define SCM_CDDAAR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (SCM_CAR (OBJ))))
|
||
#define SCM_CAADAR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (SCM_CAR (OBJ))))
|
||
#define SCM_CDADAR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (SCM_CAR (OBJ))))
|
||
#define SCM_CADDAR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (SCM_CAR (OBJ))))
|
||
#define SCM_CDDDAR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (SCM_CAR (OBJ))))
|
||
#define SCM_CAAADR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (SCM_CDR (OBJ))))
|
||
#define SCM_CDAADR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (SCM_CDR (OBJ))))
|
||
#define SCM_CADADR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (SCM_CDR (OBJ))))
|
||
#define SCM_CDDADR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (SCM_CDR (OBJ))))
|
||
#define SCM_CAADDR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (SCM_CDR (OBJ))))
|
||
#define SCM_CDADDR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (SCM_CDR (OBJ))))
|
||
#define SCM_CADDDR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (SCM_CDR (OBJ))))
|
||
#define SCM_CDDDDR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (SCM_CDR (OBJ))))
|
||
|
||
|
||
|
||
|
||
#define SCM_VALIDATE_NULL(pos, scm) \
|
||
SCM_I_MAKE_VALIDATE_MSG2 (pos, scm, scm_is_null, "empty list")
|
||
|
||
#define SCM_VALIDATE_NULL_OR_NIL(pos, scm) \
|
||
SCM_MAKE_VALIDATE_MSG (pos, scm, NULL_OR_NIL_P, "empty list")
|
||
|
||
#define SCM_VALIDATE_CONS(pos, scm) \
|
||
SCM_I_MAKE_VALIDATE_MSG2 (pos, scm, scm_is_pair, "pair")
|
||
|
||
#ifdef BUILDING_LIBGUILE
|
||
#define SCM_VALIDATE_MUTABLE_PAIR(pos, scm) \
|
||
SCM_I_MAKE_VALIDATE_MSG2 (pos, scm, scm_is_mutable_pair, "mutable pair")
|
||
#endif /* BUILDING_LIBGUILE */
|
||
|
||
#define SCM_VALIDATE_NULLORCONS(pos, env) \
|
||
do { \
|
||
SCM_ASSERT (scm_is_null (env) || scm_is_pair (env), env, pos, FUNC_NAME); \
|
||
} while (0)
|
||
|
||
|
||
|
||
|
||
SCM_API SCM scm_cons (SCM x, SCM y);
|
||
SCM_API SCM scm_car (SCM x);
|
||
SCM_API SCM scm_cdr (SCM x);
|
||
|
||
SCM_INTERNAL int scm_is_mutable_pair (SCM x);
|
||
|
||
SCM_API SCM scm_cons2 (SCM w, SCM x, SCM y);
|
||
SCM_API SCM scm_pair_p (SCM x);
|
||
SCM_API SCM scm_set_car_x (SCM pair, SCM value);
|
||
SCM_API SCM scm_set_cdr_x (SCM pair, SCM value);
|
||
|
||
SCM_API SCM scm_cddr (SCM x);
|
||
SCM_API SCM scm_cdar (SCM x);
|
||
SCM_API SCM scm_cadr (SCM x);
|
||
SCM_API SCM scm_caar (SCM x);
|
||
SCM_API SCM scm_cdddr (SCM x);
|
||
SCM_API SCM scm_cddar (SCM x);
|
||
SCM_API SCM scm_cdadr (SCM x);
|
||
SCM_API SCM scm_cdaar (SCM x);
|
||
SCM_API SCM scm_caddr (SCM x);
|
||
SCM_API SCM scm_cadar (SCM x);
|
||
SCM_API SCM scm_caadr (SCM x);
|
||
SCM_API SCM scm_caaar (SCM x);
|
||
SCM_API SCM scm_cddddr (SCM x);
|
||
SCM_API SCM scm_cdddar (SCM x);
|
||
SCM_API SCM scm_cddadr (SCM x);
|
||
SCM_API SCM scm_cddaar (SCM x);
|
||
SCM_API SCM scm_cdaddr (SCM x);
|
||
SCM_API SCM scm_cdadar (SCM x);
|
||
SCM_API SCM scm_cdaadr (SCM x);
|
||
SCM_API SCM scm_cdaaar (SCM x);
|
||
SCM_API SCM scm_cadddr (SCM x);
|
||
SCM_API SCM scm_caddar (SCM x);
|
||
SCM_API SCM scm_cadadr (SCM x);
|
||
SCM_API SCM scm_cadaar (SCM x);
|
||
SCM_API SCM scm_caaddr (SCM x);
|
||
SCM_API SCM scm_caadar (SCM x);
|
||
SCM_API SCM scm_caaadr (SCM x);
|
||
SCM_API SCM scm_caaaar (SCM x);
|
||
|
||
SCM_INTERNAL void scm_init_pairs (void);
|
||
|
||
#endif /* SCM_PAIRS_H */
|