*** empty log message ***
[bpt/guile.git] / libguile / pairs.h
1 /* classes: h_files */
2
3 #ifndef PAIRSH
4 #define PAIRSH
5 /* Copyright (C) 1995,1996, 2000 Free Software Foundation, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this software; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307 USA
21 *
22 * As a special exception, the Free Software Foundation gives permission
23 * for additional uses of the text contained in its release of GUILE.
24 *
25 * The exception is that, if you link the GUILE library with other files
26 * to produce an executable, this does not by itself cause the
27 * resulting executable to be covered by the GNU General Public License.
28 * Your use of that executable is in no way restricted on account of
29 * linking the GUILE library code into it.
30 *
31 * This exception does not however invalidate any other reasons why
32 * the executable file might be covered by the GNU General Public License.
33 *
34 * This exception applies only to the code released by the
35 * Free Software Foundation under the name GUILE. If you copy
36 * code from other Free Software Foundation releases into a copy of
37 * GUILE, as the General Public License permits, the exception does
38 * not apply to the code that you add in this way. To avoid misleading
39 * anyone as to the status of such modified files, you must delete
40 * this exception notice from them.
41 *
42 * If you write modifications of your own for GUILE, it is your choice
43 * whether to permit this exception to apply to your modifications.
44 * If you do not wish that, delete this exception notice. */
45
46 /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
47 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
48
49 \f
50
51 #include "libguile/__scm.h"
52
53 \f
54
55 typedef struct scm_cell
56 {
57 SCM car;
58 SCM cdr;
59 } scm_cell;
60
61 /* SCM_PTR_LT defines how to compare two SCM_CELLPTRs (which may not be in the
62 * same scm_array). SCM_CELLPTR is a pointer to a cons cell which may be
63 * compared or differenced. SCMPTR is used for stack bounds.
64 */
65
66 #if !defined(__TURBOC__) || defined(__TOS__)
67
68 typedef scm_cell *SCM_CELLPTR;
69 typedef SCM *SCMPTR;
70
71 # ifdef nosve
72 # define SCM_PTR_MASK 0xffffffffffff
73 # define SCM_PTR_LT(x, y) (((int)(x)&SCM_PTR_MASK) < ((int)(y)&SCM_PTR_MASK))
74 # else
75 # define SCM_PTR_LT(x, y) ((x) < (y))
76 # endif /* def nosve */
77
78 #else /* defined(__TURBOC__) && !defined(__TOS__) */
79
80 # ifdef PROT386
81 typedef scm_cell *SCM_CELLPTR;
82 typedef SCM *SCMPTR;
83 # define SCM_PTR_LT(x, y) (((long)(x)) < ((long)(y)))
84 # else
85 typedef scm_cell huge *SCM_CELLPTR;
86 typedef SCM huge *SCMPTR;
87 # define SCM_PTR_LT(x, y) ((x) < (y))
88 # endif /* def PROT386 */
89
90 #endif /* defined(__TURBOC__) && !defined(__TOS__) */
91
92 #define SCM_PTR_GT(x, y) SCM_PTR_LT(y, x)
93 #define SCM_PTR_LE(x, y) (!SCM_PTR_GT(x, y))
94 #define SCM_PTR_GE(x, y) (!SCM_PTR_LT(x, y))
95
96 #define SCM_NULLP(x) (SCM_EOL == (x))
97 #define SCM_NNULLP(x) (SCM_EOL != (x))
98
99
100 \f
101
102 /* Cons Pairs
103 */
104
105 #define SCM_CAR(x) (((scm_cell *)(SCM2PTR(x)))->car)
106 #define SCM_CDR(x) (((scm_cell *)(SCM2PTR(x)))->cdr)
107 #define SCM_GCCDR(x) SCM_PACK(~1L & SCM_UNPACK (SCM_CDR(x)))
108 #define SCM_SETCAR(x, v) (SCM_CAR(x) = SCM_PACK(v))
109 #define SCM_SETCDR(x, v) (SCM_CDR(x) = SCM_PACK(v))
110
111 #define SCM_CARLOC(x) (&SCM_CAR (x))
112 #define SCM_CDRLOC(x) (&SCM_CDR (x))
113
114 #define SCM_SETAND_CAR(x, y)\
115 (SCM_CAR (x) = SCM_PACK (SCM_UNPACK (SCM_CAR (x)) & (y)))
116 #define SCM_SETAND_CDR(x, y)\
117 (SCM_CDR (x) = SCM_PACK (SCM_UNPACK (SCM_CDR (x)) & (y)))
118 #define SCM_SETOR_CAR(x, y)\
119 (SCM_CAR (x) = SCM_PACK (SCM_UNPACK (SCM_CAR (x)) | (y)))
120 #define SCM_SETOR_CDR(x, y)\
121 (SCM_CDR (x) = SCM_PACK (SCM_UNPACK (SCM_CDR (x)) | (y)))
122
123 #define SCM_CAAR(OBJ) SCM_CAR (SCM_CAR (OBJ))
124 #define SCM_CDAR(OBJ) SCM_CDR (SCM_CAR (OBJ))
125 #define SCM_CADR(OBJ) SCM_CAR (SCM_CDR (OBJ))
126 #define SCM_CDDR(OBJ) SCM_CDR (SCM_CDR (OBJ))
127
128 #define SCM_CAAAR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (OBJ)))
129 #define SCM_CDAAR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (OBJ)))
130 #define SCM_CADAR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (OBJ)))
131 #define SCM_CDDAR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (OBJ)))
132 #define SCM_CAADR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (OBJ)))
133 #define SCM_CDADR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (OBJ)))
134 #define SCM_CADDR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (OBJ)))
135 #define SCM_CDDDR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (OBJ)))
136
137 #define SCM_CAAAAR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (SCM_CAR (OBJ))))
138 #define SCM_CDAAAR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (SCM_CAR (OBJ))))
139 #define SCM_CADAAR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (SCM_CAR (OBJ))))
140 #define SCM_CDDAAR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (SCM_CAR (OBJ))))
141 #define SCM_CAADAR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (SCM_CAR (OBJ))))
142 #define SCM_CDADAR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (SCM_CAR (OBJ))))
143 #define SCM_CADDAR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (SCM_CAR (OBJ))))
144 #define SCM_CDDDAR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (SCM_CAR (OBJ))))
145 #define SCM_CAAADR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (SCM_CDR (OBJ))))
146 #define SCM_CDAADR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (SCM_CDR (OBJ))))
147 #define SCM_CADADR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (SCM_CDR (OBJ))))
148 #define SCM_CDDADR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (SCM_CDR (OBJ))))
149 #define SCM_CAADDR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (SCM_CDR (OBJ))))
150 #define SCM_CDADDR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (SCM_CDR (OBJ))))
151 #define SCM_CADDDR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (SCM_CDR (OBJ))))
152 #define SCM_CDDDDR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (SCM_CDR (OBJ))))
153
154 /* the allocated thing: The car of newcells are set to
155 scm_tc16_allocated to avoid the fragile state of newcells wrt the
156 gc. If it stays as a freecell, any allocation afterwards could
157 cause the cell to go back on the freelist, which will bite you
158 sometime afterwards */
159
160 #ifdef GUILE_DEBUG_FREELIST
161 #define SCM_NEWCELL(_into) do { _into = scm_debug_newcell (); } while (0)
162 #else
163 #define SCM_NEWCELL(_into) \
164 do { \
165 if (SCM_IMP(scm_freelist)) \
166 _into = scm_gc_for_newcell();\
167 else \
168 { \
169 _into = scm_freelist; \
170 scm_freelist = SCM_CDR(scm_freelist);\
171 SCM_SETCAR(_into, scm_tc16_allocated); \
172 ++scm_cells_allocated; \
173 } \
174 } while(0)
175 #endif
176
177 \f
178
179 extern SCM scm_cons (SCM x, SCM y);
180 extern SCM scm_cons2 (SCM w, SCM x, SCM y);
181 extern SCM scm_pair_p (SCM x);
182 extern SCM scm_set_car_x (SCM pair, SCM value);
183 extern SCM scm_set_cdr_x (SCM pair, SCM value);
184 extern void scm_init_pairs (void);
185
186 #endif /* PAIRSH */