|
#ifndef SCM_PAIRS_H |
|
#define SCM_PAIRS_H |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "libguile/error.h" |
|
#include "libguile/gc.h" |
|
#include "libguile/inline.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define scm_is_null_and_not_nil(x) (scm_is_eq ((x), SCM_EOL)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
#define scm_is_null_assume_not_nil(x) (scm_is_eq ((x), SCM_EOL)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
#define scm_is_null_or_nil(x) \ |
|
(SCM_MATCHES_BITS_IN_COMMON ((x), SCM_ELISP_NIL, SCM_EOL)) |
|
|
|
|
|
|
|
|
|
|
|
#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)) |
|
|
|
|
|
|
|
|
|
|
|
#define scm_is_null(x) (scm_is_null_or_nil(x)) |
|
|
|
#define SCM_CAR(x) (SCM_VALIDATE_PAIR (x, SCM_CELL_OBJECT_0 (x))) |
|
#define SCM_CDR(x) (SCM_VALIDATE_PAIR (x, SCM_CELL_OBJECT_1 (x))) |
|
|
|
#define SCM_SETCAR(x, v) (SCM_VALIDATE_PAIR (x, SCM_SET_CELL_OBJECT_0 ((x), (v)))) |
|
#define SCM_SETCDR(x, v) (SCM_VALIDATE_PAIR (x, SCM_SET_CELL_OBJECT_1 ((x), (v)))) |
|
|
|
#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") |
|
|
|
#if (SCM_DEBUG_PAIR_ACCESSES == 1) |
|
# define SCM_VALIDATE_PAIR(cell, expr) \ |
|
((!scm_is_pair (cell) ? scm_error_pair_access (cell), 0 : 0), (expr)) |
|
#else |
|
# define SCM_VALIDATE_PAIR(cell, expr) (expr) |
|
#endif |
|
|
|
#ifdef BUILDING_LIBGUILE |
|
#define SCM_VALIDATE_MUTABLE_PAIR(pos, scm) \ |
|
SCM_I_MAKE_VALIDATE_MSG2 (pos, scm, scm_is_mutable_pair, "mutable pair") |
|
#endif |
|
|
|
#define SCM_VALIDATE_NULLORCONS(pos, env) \ |
|
do { \ |
|
SCM_ASSERT (scm_is_null (env) || scm_is_pair (env), env, pos, FUNC_NAME); \ |
|
} while (0) |
|
|
|
|
|
|
|
|
|
#if (SCM_DEBUG_PAIR_ACCESSES == 1) |
|
SCM_API void scm_error_pair_access (SCM); |
|
#endif |
|
|
|
SCM_INLINE int scm_is_pair (SCM x); |
|
SCM_INLINE SCM scm_cons (SCM x, SCM y); |
|
SCM_INLINE SCM scm_car (SCM x); |
|
SCM_INLINE SCM scm_cdr (SCM x); |
|
|
|
#if SCM_CAN_INLINE || defined SCM_INLINE_C_IMPLEMENTING_INLINES |
|
|
|
|
|
|
|
SCM_INLINE_IMPLEMENTATION SCM |
|
scm_cons (SCM x, SCM y) |
|
{ |
|
return scm_cell (SCM_UNPACK (x), SCM_UNPACK (y)); |
|
} |
|
|
|
SCM_INLINE_IMPLEMENTATION int |
|
scm_is_pair (SCM x) |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined (__GNUC__) && __GNUC__ == 2 && __GNUC_MINOR__ == 95 |
|
volatile SCM workaround_for_gcc_295 = x; |
|
workaround_for_gcc_295 = workaround_for_gcc_295; |
|
#endif |
|
|
|
return SCM_I_CONSP (x); |
|
} |
|
|
|
SCM_INLINE_IMPLEMENTATION SCM |
|
scm_car (SCM x) |
|
{ |
|
if (SCM_UNLIKELY (!scm_is_pair (x))) |
|
scm_wrong_type_arg_msg ("car", 0, x, "pair"); |
|
return SCM_CAR (x); |
|
} |
|
|
|
SCM_INLINE_IMPLEMENTATION SCM |
|
scm_cdr (SCM x) |
|
{ |
|
if (SCM_UNLIKELY (!scm_is_pair (x))) |
|
scm_wrong_type_arg_msg ("cdr", 0, x, "pair"); |
|
return SCM_CDR (x); |
|
} |
|
#endif |
|
|
|
#ifdef BUILDING_LIBGUILE |
|
#ifndef HAVE_GC_IS_HEAP_PTR |
|
static int |
|
GC_is_heap_ptr (void *ptr) |
|
{ |
|
return GC_base (ptr) != NULL; |
|
} |
|
#endif |
|
|
|
static inline int |
|
scm_is_mutable_pair (SCM x) |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return scm_is_pair (x) && GC_is_heap_ptr (SCM2PTR (x)); |
|
} |
|
#endif |
|
|
|
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 |
|
|