Merge branch 'boehm-demers-weiser-gc' into bdw-gc-static-alloc
[bpt/guile.git] / libguile / pairs.h
1 /* classes: h_files */
2
3 #ifndef SCM_PAIRS_H
4 #define SCM_PAIRS_H
5
6 /* Copyright (C) 1995,1996,2000,2001, 2004, 2006, 2008 Free Software Foundation, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 */
23
24 \f
25
26 #include "libguile/__scm.h"
27
28 \f
29
30 #if (SCM_DEBUG_PAIR_ACCESSES == 1)
31 # define SCM_VALIDATE_PAIR(cell, expr) \
32 ((!scm_is_pair (cell) ? scm_error_pair_access (cell), 0 : 0), (expr))
33 #else
34 # define SCM_VALIDATE_PAIR(cell, expr) (expr)
35 #endif
36
37 #define scm_is_null(x) (scm_is_eq ((x), SCM_EOL))
38
39 #define SCM_CAR(x) (SCM_VALIDATE_PAIR (x, SCM_CELL_OBJECT_0 (x)))
40 #define SCM_CDR(x) (SCM_VALIDATE_PAIR (x, SCM_CELL_OBJECT_1 (x)))
41
42 #define SCM_SETCAR(x, v) (SCM_VALIDATE_PAIR (x, SCM_SET_CELL_OBJECT_0 ((x), (v))))
43 #define SCM_SETCDR(x, v) (SCM_VALIDATE_PAIR (x, SCM_SET_CELL_OBJECT_1 ((x), (v))))
44
45 #define SCM_CAAR(OBJ) SCM_CAR (SCM_CAR (OBJ))
46 #define SCM_CDAR(OBJ) SCM_CDR (SCM_CAR (OBJ))
47 #define SCM_CADR(OBJ) SCM_CAR (SCM_CDR (OBJ))
48 #define SCM_CDDR(OBJ) SCM_CDR (SCM_CDR (OBJ))
49
50 #define SCM_CAAAR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (OBJ)))
51 #define SCM_CDAAR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (OBJ)))
52 #define SCM_CADAR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (OBJ)))
53 #define SCM_CDDAR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (OBJ)))
54 #define SCM_CAADR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (OBJ)))
55 #define SCM_CDADR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (OBJ)))
56 #define SCM_CADDR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (OBJ)))
57 #define SCM_CDDDR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (OBJ)))
58
59 #define SCM_CAAAAR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (SCM_CAR (OBJ))))
60 #define SCM_CDAAAR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (SCM_CAR (OBJ))))
61 #define SCM_CADAAR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (SCM_CAR (OBJ))))
62 #define SCM_CDDAAR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (SCM_CAR (OBJ))))
63 #define SCM_CAADAR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (SCM_CAR (OBJ))))
64 #define SCM_CDADAR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (SCM_CAR (OBJ))))
65 #define SCM_CADDAR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (SCM_CAR (OBJ))))
66 #define SCM_CDDDAR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (SCM_CAR (OBJ))))
67 #define SCM_CAAADR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (SCM_CDR (OBJ))))
68 #define SCM_CDAADR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (SCM_CDR (OBJ))))
69 #define SCM_CADADR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (SCM_CDR (OBJ))))
70 #define SCM_CDDADR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (SCM_CDR (OBJ))))
71 #define SCM_CAADDR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (SCM_CDR (OBJ))))
72 #define SCM_CDADDR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (SCM_CDR (OBJ))))
73 #define SCM_CADDDR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (SCM_CDR (OBJ))))
74 #define SCM_CDDDDR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (SCM_CDR (OBJ))))
75
76 \f
77
78 #if (SCM_DEBUG_PAIR_ACCESSES == 1)
79 SCM_API void scm_error_pair_access (SCM);
80 #endif
81
82 SCM_API SCM scm_cons (SCM x, SCM y);
83 SCM_API SCM scm_cons2 (SCM w, SCM x, SCM y);
84 SCM_API SCM scm_pair_p (SCM x);
85 SCM_API SCM scm_car (SCM x);
86 SCM_API SCM scm_cdr (SCM x);
87 SCM_API SCM scm_set_car_x (SCM pair, SCM value);
88 SCM_API SCM scm_set_cdr_x (SCM pair, SCM value);
89
90 #define SCM_I_D_PAT 0x02 /* 00000010 */
91 #define SCM_I_A_PAT 0x03 /* 00000011 */
92 #define SCM_I_DD_PAT 0x0a /* 00001010 */
93 #define SCM_I_DA_PAT 0x0b /* 00001011 */
94 #define SCM_I_AD_PAT 0x0e /* 00001110 */
95 #define SCM_I_AA_PAT 0x0f /* 00001111 */
96 #define SCM_I_DDD_PAT 0x2a /* 00101010 */
97 #define SCM_I_DDA_PAT 0x2b /* 00101011 */
98 #define SCM_I_DAD_PAT 0x2e /* 00101110 */
99 #define SCM_I_DAA_PAT 0x2f /* 00101111 */
100 #define SCM_I_ADD_PAT 0x3a /* 00111010 */
101 #define SCM_I_ADA_PAT 0x3b /* 00111011 */
102 #define SCM_I_AAD_PAT 0x3e /* 00111110 */
103 #define SCM_I_AAA_PAT 0x3f /* 00111111 */
104 #define SCM_I_DDDD_PAT 0xaa /* 10101010 */
105 #define SCM_I_DDDA_PAT 0xab /* 10101011 */
106 #define SCM_I_DDAD_PAT 0xae /* 10101110 */
107 #define SCM_I_DDAA_PAT 0xaf /* 10101111 */
108 #define SCM_I_DADD_PAT 0xba /* 10111010 */
109 #define SCM_I_DADA_PAT 0xbb /* 10111011 */
110 #define SCM_I_DAAD_PAT 0xbe /* 10111110 */
111 #define SCM_I_DAAA_PAT 0xbf /* 10111111 */
112 #define SCM_I_ADDD_PAT 0xea /* 11101010 */
113 #define SCM_I_ADDA_PAT 0xeb /* 11101011 */
114 #define SCM_I_ADAD_PAT 0xee /* 11101110 */
115 #define SCM_I_ADAA_PAT 0xef /* 11101111 */
116 #define SCM_I_AADD_PAT 0xfa /* 11111010 */
117 #define SCM_I_AADA_PAT 0xfb /* 11111011 */
118 #define SCM_I_AAAD_PAT 0xfe /* 11111110 */
119 #define SCM_I_AAAA_PAT 0xff /* 11111111 */
120
121 SCM_API SCM scm_i_chase_pairs (SCM x, scm_t_uint32 pattern);
122
123 #define scm_cddr(x) scm_i_chase_pairs ((x), SCM_I_DD_PAT)
124 #define scm_cdar(x) scm_i_chase_pairs ((x), SCM_I_DA_PAT)
125 #define scm_cadr(x) scm_i_chase_pairs ((x), SCM_I_AD_PAT)
126 #define scm_caar(x) scm_i_chase_pairs ((x), SCM_I_AA_PAT)
127 #define scm_cdddr(x) scm_i_chase_pairs ((x), SCM_I_DDD_PAT)
128 #define scm_cddar(x) scm_i_chase_pairs ((x), SCM_I_DDA_PAT)
129 #define scm_cdadr(x) scm_i_chase_pairs ((x), SCM_I_DAD_PAT)
130 #define scm_cdaar(x) scm_i_chase_pairs ((x), SCM_I_DAA_PAT)
131 #define scm_caddr(x) scm_i_chase_pairs ((x), SCM_I_ADD_PAT)
132 #define scm_cadar(x) scm_i_chase_pairs ((x), SCM_I_ADA_PAT)
133 #define scm_caadr(x) scm_i_chase_pairs ((x), SCM_I_AAD_PAT)
134 #define scm_caaar(x) scm_i_chase_pairs ((x), SCM_I_AAA_PAT)
135 #define scm_cddddr(x) scm_i_chase_pairs ((x), SCM_I_DDDD_PAT)
136 #define scm_cdddar(x) scm_i_chase_pairs ((x), SCM_I_DDDA_PAT)
137 #define scm_cddadr(x) scm_i_chase_pairs ((x), SCM_I_DDAD_PAT)
138 #define scm_cddaar(x) scm_i_chase_pairs ((x), SCM_I_DDAA_PAT)
139 #define scm_cdaddr(x) scm_i_chase_pairs ((x), SCM_I_DADD_PAT)
140 #define scm_cdadar(x) scm_i_chase_pairs ((x), SCM_I_DADA_PAT)
141 #define scm_cdaadr(x) scm_i_chase_pairs ((x), SCM_I_DAAD_PAT)
142 #define scm_cdaaar(x) scm_i_chase_pairs ((x), SCM_I_DAAA_PAT)
143 #define scm_cadddr(x) scm_i_chase_pairs ((x), SCM_I_ADDD_PAT)
144 #define scm_caddar(x) scm_i_chase_pairs ((x), SCM_I_ADDA_PAT)
145 #define scm_cadadr(x) scm_i_chase_pairs ((x), SCM_I_ADAD_PAT)
146 #define scm_cadaar(x) scm_i_chase_pairs ((x), SCM_I_ADAA_PAT)
147 #define scm_caaddr(x) scm_i_chase_pairs ((x), SCM_I_AADD_PAT)
148 #define scm_caadar(x) scm_i_chase_pairs ((x), SCM_I_AADA_PAT)
149 #define scm_caaadr(x) scm_i_chase_pairs ((x), SCM_I_AAAD_PAT)
150 #define scm_caaaar(x) scm_i_chase_pairs ((x), SCM_I_AAAA_PAT)
151
152 SCM_INTERNAL void scm_init_pairs (void);
153
154 #endif /* SCM_PAIRS_H */
155
156 /*
157 Local Variables:
158 c-file-style: "gnu"
159 End:
160 */