Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
e81d98ec DH |
3 | #ifndef SCM_PAIRS_H |
4 | #define SCM_PAIRS_H | |
0527e687 | 5 | |
45f4cbdf | 6 | /* Copyright (C) 1995,1996,2000,2001, 2004, 2006, 2008, 2009 Free Software Foundation, Inc. |
0527e687 | 7 | * |
73be1d9e | 8 | * This library is free software; you can redistribute it and/or |
53befeb7 NJ |
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. | |
0527e687 | 12 | * |
53befeb7 NJ |
13 | * This library is distributed in the hope that it will be useful, but |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
73be1d9e MV |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. | |
0527e687 | 17 | * |
73be1d9e MV |
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 | |
53befeb7 NJ |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
21 | * 02110-1301 USA | |
73be1d9e | 22 | */ |
1bbd0b84 | 23 | |
0f2d19dd JB |
24 | \f |
25 | ||
b4309c3c | 26 | #include "libguile/__scm.h" |
0f2d19dd JB |
27 | |
28 | \f | |
29 | ||
e81d98ec | 30 | #if (SCM_DEBUG_PAIR_ACCESSES == 1) |
e81d98ec | 31 | # define SCM_VALIDATE_PAIR(cell, expr) \ |
6fcc7d48 | 32 | ((!scm_is_pair (cell) ? scm_error_pair_access (cell), 0 : 0), (expr)) |
e81d98ec DH |
33 | #else |
34 | # define SCM_VALIDATE_PAIR(cell, expr) (expr) | |
35 | #endif | |
36 | ||
45f4cbdf MW |
37 | /* |
38 | * Use scm_is_null_and_not_nil if it's important (for correctness) | |
39 | * that %nil must NOT be considered null. | |
40 | */ | |
41 | #define scm_is_null_and_not_nil(x) (scm_is_eq ((x), SCM_EOL)) | |
42 | ||
43 | /* | |
44 | * Use scm_is_null_assume_not_nil if %nil will never be tested, | |
45 | * for increased efficiency. | |
46 | */ | |
47 | #define scm_is_null_assume_not_nil(x) (scm_is_eq ((x), SCM_EOL)) | |
48 | ||
49 | /* | |
50 | * See the comments preceeding the definitions of SCM_BOOL_F and | |
51 | * SCM_MATCHES_BITS_IN_COMMON in tags.h for more information on | |
52 | * how the following macro works. | |
53 | */ | |
54 | #if SCM_ENABLE_ELISP | |
55 | # define scm_is_null_or_nil(x) \ | |
56 | (SCM_MATCHES_BITS_IN_COMMON ((x), SCM_ELISP_NIL, SCM_EOL)) | |
57 | #else | |
58 | # define scm_is_null_or_nil(x) (scm_is_null_assume_not_nil (x)) | |
59 | #endif | |
60 | ||
61 | /* XXX Should scm_is_null treat %nil as null by default? */ | |
62 | #define scm_is_null(x) (scm_is_null_and_not_nil(x)) | |
0f2d19dd | 63 | |
e81d98ec DH |
64 | #define SCM_CAR(x) (SCM_VALIDATE_PAIR (x, SCM_CELL_OBJECT_0 (x))) |
65 | #define SCM_CDR(x) (SCM_VALIDATE_PAIR (x, SCM_CELL_OBJECT_1 (x))) | |
76a369d9 | 66 | |
e81d98ec DH |
67 | #define SCM_SETCAR(x, v) (SCM_VALIDATE_PAIR (x, SCM_SET_CELL_OBJECT_0 ((x), (v)))) |
68 | #define SCM_SETCDR(x, v) (SCM_VALIDATE_PAIR (x, SCM_SET_CELL_OBJECT_1 ((x), (v)))) | |
24e68a57 | 69 | |
0f2d19dd JB |
70 | #define SCM_CAAR(OBJ) SCM_CAR (SCM_CAR (OBJ)) |
71 | #define SCM_CDAR(OBJ) SCM_CDR (SCM_CAR (OBJ)) | |
72 | #define SCM_CADR(OBJ) SCM_CAR (SCM_CDR (OBJ)) | |
73 | #define SCM_CDDR(OBJ) SCM_CDR (SCM_CDR (OBJ)) | |
74 | ||
75 | #define SCM_CAAAR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (OBJ))) | |
76 | #define SCM_CDAAR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (OBJ))) | |
77 | #define SCM_CADAR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (OBJ))) | |
78 | #define SCM_CDDAR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (OBJ))) | |
79 | #define SCM_CAADR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (OBJ))) | |
80 | #define SCM_CDADR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (OBJ))) | |
81 | #define SCM_CADDR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (OBJ))) | |
82 | #define SCM_CDDDR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (OBJ))) | |
83 | ||
84 | #define SCM_CAAAAR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (SCM_CAR (OBJ)))) | |
85 | #define SCM_CDAAAR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (SCM_CAR (OBJ)))) | |
86 | #define SCM_CADAAR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (SCM_CAR (OBJ)))) | |
87 | #define SCM_CDDAAR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (SCM_CAR (OBJ)))) | |
88 | #define SCM_CAADAR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (SCM_CAR (OBJ)))) | |
89 | #define SCM_CDADAR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (SCM_CAR (OBJ)))) | |
90 | #define SCM_CADDAR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (SCM_CAR (OBJ)))) | |
91 | #define SCM_CDDDAR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (SCM_CAR (OBJ)))) | |
92 | #define SCM_CAAADR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (SCM_CDR (OBJ)))) | |
93 | #define SCM_CDAADR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (SCM_CDR (OBJ)))) | |
94 | #define SCM_CADADR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (SCM_CDR (OBJ)))) | |
95 | #define SCM_CDDADR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (SCM_CDR (OBJ)))) | |
96 | #define SCM_CAADDR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (SCM_CDR (OBJ)))) | |
97 | #define SCM_CDADDR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (SCM_CDR (OBJ)))) | |
98 | #define SCM_CADDDR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (SCM_CDR (OBJ)))) | |
99 | #define SCM_CDDDDR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (SCM_CDR (OBJ)))) | |
100 | ||
0f2d19dd | 101 | \f |
1cc91f1b | 102 | |
e81d98ec | 103 | #if (SCM_DEBUG_PAIR_ACCESSES == 1) |
33b001fd | 104 | SCM_API void scm_error_pair_access (SCM); |
e81d98ec | 105 | #endif |
6fcc7d48 | 106 | |
33b001fd MV |
107 | SCM_API SCM scm_cons (SCM x, SCM y); |
108 | SCM_API SCM scm_cons2 (SCM w, SCM x, SCM y); | |
109 | SCM_API SCM scm_pair_p (SCM x); | |
ddda5e8f MV |
110 | SCM_API SCM scm_car (SCM x); |
111 | SCM_API SCM scm_cdr (SCM x); | |
33b001fd MV |
112 | SCM_API SCM scm_set_car_x (SCM pair, SCM value); |
113 | SCM_API SCM scm_set_cdr_x (SCM pair, SCM value); | |
ddda5e8f | 114 | |
ddda5e8f MV |
115 | #define SCM_I_D_PAT 0x02 /* 00000010 */ |
116 | #define SCM_I_A_PAT 0x03 /* 00000011 */ | |
117 | #define SCM_I_DD_PAT 0x0a /* 00001010 */ | |
118 | #define SCM_I_DA_PAT 0x0b /* 00001011 */ | |
119 | #define SCM_I_AD_PAT 0x0e /* 00001110 */ | |
120 | #define SCM_I_AA_PAT 0x0f /* 00001111 */ | |
121 | #define SCM_I_DDD_PAT 0x2a /* 00101010 */ | |
122 | #define SCM_I_DDA_PAT 0x2b /* 00101011 */ | |
123 | #define SCM_I_DAD_PAT 0x2e /* 00101110 */ | |
124 | #define SCM_I_DAA_PAT 0x2f /* 00101111 */ | |
125 | #define SCM_I_ADD_PAT 0x3a /* 00111010 */ | |
126 | #define SCM_I_ADA_PAT 0x3b /* 00111011 */ | |
127 | #define SCM_I_AAD_PAT 0x3e /* 00111110 */ | |
128 | #define SCM_I_AAA_PAT 0x3f /* 00111111 */ | |
129 | #define SCM_I_DDDD_PAT 0xaa /* 10101010 */ | |
130 | #define SCM_I_DDDA_PAT 0xab /* 10101011 */ | |
131 | #define SCM_I_DDAD_PAT 0xae /* 10101110 */ | |
132 | #define SCM_I_DDAA_PAT 0xaf /* 10101111 */ | |
133 | #define SCM_I_DADD_PAT 0xba /* 10111010 */ | |
134 | #define SCM_I_DADA_PAT 0xbb /* 10111011 */ | |
135 | #define SCM_I_DAAD_PAT 0xbe /* 10111110 */ | |
136 | #define SCM_I_DAAA_PAT 0xbf /* 10111111 */ | |
137 | #define SCM_I_ADDD_PAT 0xea /* 11101010 */ | |
138 | #define SCM_I_ADDA_PAT 0xeb /* 11101011 */ | |
139 | #define SCM_I_ADAD_PAT 0xee /* 11101110 */ | |
140 | #define SCM_I_ADAA_PAT 0xef /* 11101111 */ | |
141 | #define SCM_I_AADD_PAT 0xfa /* 11111010 */ | |
142 | #define SCM_I_AADA_PAT 0xfb /* 11111011 */ | |
143 | #define SCM_I_AAAD_PAT 0xfe /* 11111110 */ | |
144 | #define SCM_I_AAAA_PAT 0xff /* 11111111 */ | |
145 | ||
146 | SCM_API SCM scm_i_chase_pairs (SCM x, scm_t_uint32 pattern); | |
147 | ||
148 | #define scm_cddr(x) scm_i_chase_pairs ((x), SCM_I_DD_PAT) | |
149 | #define scm_cdar(x) scm_i_chase_pairs ((x), SCM_I_DA_PAT) | |
150 | #define scm_cadr(x) scm_i_chase_pairs ((x), SCM_I_AD_PAT) | |
151 | #define scm_caar(x) scm_i_chase_pairs ((x), SCM_I_AA_PAT) | |
152 | #define scm_cdddr(x) scm_i_chase_pairs ((x), SCM_I_DDD_PAT) | |
153 | #define scm_cddar(x) scm_i_chase_pairs ((x), SCM_I_DDA_PAT) | |
154 | #define scm_cdadr(x) scm_i_chase_pairs ((x), SCM_I_DAD_PAT) | |
155 | #define scm_cdaar(x) scm_i_chase_pairs ((x), SCM_I_DAA_PAT) | |
156 | #define scm_caddr(x) scm_i_chase_pairs ((x), SCM_I_ADD_PAT) | |
157 | #define scm_cadar(x) scm_i_chase_pairs ((x), SCM_I_ADA_PAT) | |
158 | #define scm_caadr(x) scm_i_chase_pairs ((x), SCM_I_AAD_PAT) | |
159 | #define scm_caaar(x) scm_i_chase_pairs ((x), SCM_I_AAA_PAT) | |
160 | #define scm_cddddr(x) scm_i_chase_pairs ((x), SCM_I_DDDD_PAT) | |
161 | #define scm_cdddar(x) scm_i_chase_pairs ((x), SCM_I_DDDA_PAT) | |
162 | #define scm_cddadr(x) scm_i_chase_pairs ((x), SCM_I_DDAD_PAT) | |
163 | #define scm_cddaar(x) scm_i_chase_pairs ((x), SCM_I_DDAA_PAT) | |
164 | #define scm_cdaddr(x) scm_i_chase_pairs ((x), SCM_I_DADD_PAT) | |
165 | #define scm_cdadar(x) scm_i_chase_pairs ((x), SCM_I_DADA_PAT) | |
166 | #define scm_cdaadr(x) scm_i_chase_pairs ((x), SCM_I_DAAD_PAT) | |
167 | #define scm_cdaaar(x) scm_i_chase_pairs ((x), SCM_I_DAAA_PAT) | |
168 | #define scm_cadddr(x) scm_i_chase_pairs ((x), SCM_I_ADDD_PAT) | |
169 | #define scm_caddar(x) scm_i_chase_pairs ((x), SCM_I_ADDA_PAT) | |
170 | #define scm_cadadr(x) scm_i_chase_pairs ((x), SCM_I_ADAD_PAT) | |
171 | #define scm_cadaar(x) scm_i_chase_pairs ((x), SCM_I_ADAA_PAT) | |
172 | #define scm_caaddr(x) scm_i_chase_pairs ((x), SCM_I_AADD_PAT) | |
173 | #define scm_caadar(x) scm_i_chase_pairs ((x), SCM_I_AADA_PAT) | |
174 | #define scm_caaadr(x) scm_i_chase_pairs ((x), SCM_I_AAAD_PAT) | |
175 | #define scm_caaaar(x) scm_i_chase_pairs ((x), SCM_I_AAAA_PAT) | |
176 | ||
102dbb6f | 177 | SCM_INTERNAL void scm_init_pairs (void); |
1cc91f1b | 178 | |
e81d98ec | 179 | #endif /* SCM_PAIRS_H */ |
89e00824 ML |
180 | |
181 | /* | |
182 | Local Variables: | |
183 | c-file-style: "gnu" | |
184 | End: | |
185 | */ |