| 1 | /* classes: h_files */ |
| 2 | |
| 3 | #ifndef PAIRSH |
| 4 | #define PAIRSH |
| 5 | /* Copyright (C) 1995,1996 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | * |
| 21 | * As a special exception, the Free Software Foundation gives permission |
| 22 | * for additional uses of the text contained in its release of GUILE. |
| 23 | * |
| 24 | * The exception is that, if you link the GUILE library with other files |
| 25 | * to produce an executable, this does not by itself cause the |
| 26 | * resulting executable to be covered by the GNU General Public License. |
| 27 | * Your use of that executable is in no way restricted on account of |
| 28 | * linking the GUILE library code into it. |
| 29 | * |
| 30 | * This exception does not however invalidate any other reasons why |
| 31 | * the executable file might be covered by the GNU General Public License. |
| 32 | * |
| 33 | * This exception applies only to the code released by the |
| 34 | * Free Software Foundation under the name GUILE. If you copy |
| 35 | * code from other Free Software Foundation releases into a copy of |
| 36 | * GUILE, as the General Public License permits, the exception does |
| 37 | * not apply to the code that you add in this way. To avoid misleading |
| 38 | * anyone as to the status of such modified files, you must delete |
| 39 | * this exception notice from them. |
| 40 | * |
| 41 | * If you write modifications of your own for GUILE, it is your choice |
| 42 | * whether to permit this exception to apply to your modifications. |
| 43 | * If you do not wish that, delete this exception notice. |
| 44 | */ |
| 45 | \f |
| 46 | |
| 47 | #include "libguile/__scm.h" |
| 48 | |
| 49 | \f |
| 50 | |
| 51 | typedef struct scm_cell |
| 52 | { |
| 53 | SCM car; |
| 54 | SCM cdr; |
| 55 | } scm_cell; |
| 56 | |
| 57 | /* SCM_PTR_LT defines how to compare two SCM_CELLPTRs (which may not be in the |
| 58 | * same scm_array). SCM_CELLPTR is a pointer to a cons cell which may be |
| 59 | * compared or differenced. SCMPTR is used for stack bounds. |
| 60 | */ |
| 61 | |
| 62 | #if !defined(__TURBOC__) || defined(__TOS__) |
| 63 | |
| 64 | typedef scm_cell *SCM_CELLPTR; |
| 65 | typedef SCM *SCMPTR; |
| 66 | |
| 67 | # ifdef nosve |
| 68 | # define SCM_PTR_MASK 0xffffffffffff |
| 69 | # define SCM_PTR_LT(x, y) (((int)(x)&SCM_PTR_MASK) < ((int)(y)&SCM_PTR_MASK)) |
| 70 | # else |
| 71 | # define SCM_PTR_LT(x, y) ((x) < (y)) |
| 72 | # endif /* def nosve */ |
| 73 | |
| 74 | #else /* defined(__TURBOC__) && !defined(__TOS__) */ |
| 75 | |
| 76 | # ifdef PROT386 |
| 77 | typedef scm_cell *SCM_CELLPTR; |
| 78 | typedef SCM *SCMPTR; |
| 79 | # define SCM_PTR_LT(x, y) (((long)(x)) < ((long)(y))) |
| 80 | # else |
| 81 | typedef scm_cell huge *SCM_CELLPTR; |
| 82 | typedef SCM huge *SCMPTR; |
| 83 | # define SCM_PTR_LT(x, y) ((x) < (y)) |
| 84 | # endif /* def PROT386 */ |
| 85 | |
| 86 | #endif /* defined(__TURBOC__) && !defined(__TOS__) */ |
| 87 | |
| 88 | #define SCM_PTR_GT(x, y) SCM_PTR_LT(y, x) |
| 89 | #define SCM_PTR_LE(x, y) (!SCM_PTR_GT(x, y)) |
| 90 | #define SCM_PTR_GE(x, y) (!SCM_PTR_LT(x, y)) |
| 91 | |
| 92 | #define SCM_NULLP(x) (SCM_EOL == (x)) |
| 93 | #define SCM_NNULLP(x) (SCM_EOL != (x)) |
| 94 | |
| 95 | |
| 96 | \f |
| 97 | |
| 98 | /* Cons Pairs |
| 99 | */ |
| 100 | |
| 101 | #define SCM_CAR(x) (((scm_cell *)(SCM2PTR(x)))->car) |
| 102 | #define SCM_CDR(x) (((scm_cell *)(SCM2PTR(x)))->cdr) |
| 103 | #define SCM_GCCDR(x) (~1L & SCM_CDR(x)) |
| 104 | #define SCM_SETCAR(x, v) (SCM_CAR(x) = (SCM)(v)) |
| 105 | #define SCM_SETCDR(x, v) (SCM_CDR(x) = (SCM)(v)) |
| 106 | |
| 107 | #define SCM_CARLOC(x) (&SCM_CAR (x)) |
| 108 | #define SCM_CDRLOC(x) (&SCM_CDR (x)) |
| 109 | |
| 110 | #define SCM_SETAND_CAR(x, y) (SCM_CAR (x) &= (y)) |
| 111 | #define SCM_SETAND_CDR(x, y) (SCM_CDR (x) &= (y)) |
| 112 | #define SCM_SETOR_CAR(x, y) (SCM_CAR (x) |= (y)) |
| 113 | #define SCM_SETOR_CDR(x, y) (SCM_CDR (x) |= (y)) |
| 114 | |
| 115 | #define SCM_CAAR(OBJ) SCM_CAR (SCM_CAR (OBJ)) |
| 116 | #define SCM_CDAR(OBJ) SCM_CDR (SCM_CAR (OBJ)) |
| 117 | #define SCM_CADR(OBJ) SCM_CAR (SCM_CDR (OBJ)) |
| 118 | #define SCM_CDDR(OBJ) SCM_CDR (SCM_CDR (OBJ)) |
| 119 | |
| 120 | #define SCM_CAAAR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (OBJ))) |
| 121 | #define SCM_CDAAR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (OBJ))) |
| 122 | #define SCM_CADAR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (OBJ))) |
| 123 | #define SCM_CDDAR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (OBJ))) |
| 124 | #define SCM_CAADR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (OBJ))) |
| 125 | #define SCM_CDADR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (OBJ))) |
| 126 | #define SCM_CADDR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (OBJ))) |
| 127 | #define SCM_CDDDR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (OBJ))) |
| 128 | |
| 129 | #define SCM_CAAAAR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (SCM_CAR (OBJ)))) |
| 130 | #define SCM_CDAAAR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (SCM_CAR (OBJ)))) |
| 131 | #define SCM_CADAAR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (SCM_CAR (OBJ)))) |
| 132 | #define SCM_CDDAAR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (SCM_CAR (OBJ)))) |
| 133 | #define SCM_CAADAR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (SCM_CAR (OBJ)))) |
| 134 | #define SCM_CDADAR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (SCM_CAR (OBJ)))) |
| 135 | #define SCM_CADDAR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (SCM_CAR (OBJ)))) |
| 136 | #define SCM_CDDDAR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (SCM_CAR (OBJ)))) |
| 137 | #define SCM_CAAADR(OBJ) SCM_CAR (SCM_CAR (SCM_CAR (SCM_CDR (OBJ)))) |
| 138 | #define SCM_CDAADR(OBJ) SCM_CDR (SCM_CAR (SCM_CAR (SCM_CDR (OBJ)))) |
| 139 | #define SCM_CADADR(OBJ) SCM_CAR (SCM_CDR (SCM_CAR (SCM_CDR (OBJ)))) |
| 140 | #define SCM_CDDADR(OBJ) SCM_CDR (SCM_CDR (SCM_CAR (SCM_CDR (OBJ)))) |
| 141 | #define SCM_CAADDR(OBJ) SCM_CAR (SCM_CAR (SCM_CDR (SCM_CDR (OBJ)))) |
| 142 | #define SCM_CDADDR(OBJ) SCM_CDR (SCM_CAR (SCM_CDR (SCM_CDR (OBJ)))) |
| 143 | #define SCM_CADDDR(OBJ) SCM_CAR (SCM_CDR (SCM_CDR (SCM_CDR (OBJ)))) |
| 144 | #define SCM_CDDDDR(OBJ) SCM_CDR (SCM_CDR (SCM_CDR (SCM_CDR (OBJ)))) |
| 145 | |
| 146 | |
| 147 | #ifdef DEBUG_FREELIST |
| 148 | #define SCM_NEWCELL(_into) (scm_debug_newcell (&_into)) |
| 149 | #else |
| 150 | #define SCM_NEWCELL(_into) \ |
| 151 | { \ |
| 152 | if (SCM_IMP(scm_freelist)) \ |
| 153 | _into = scm_gc_for_newcell();\ |
| 154 | else \ |
| 155 | { \ |
| 156 | _into = scm_freelist; \ |
| 157 | scm_freelist = SCM_CDR(scm_freelist);\ |
| 158 | ++scm_cells_allocated; \ |
| 159 | } \ |
| 160 | } |
| 161 | #endif |
| 162 | |
| 163 | \f |
| 164 | |
| 165 | extern SCM scm_cons SCM_P ((SCM x, SCM y)); |
| 166 | extern SCM scm_cons2 SCM_P ((SCM w, SCM x, SCM y)); |
| 167 | extern SCM scm_pair_p SCM_P ((SCM x)); |
| 168 | extern SCM scm_set_car_x SCM_P ((SCM pair, SCM value)); |
| 169 | extern SCM scm_set_cdr_x SCM_P ((SCM pair, SCM value)); |
| 170 | extern void scm_init_pairs SCM_P ((void)); |
| 171 | |
| 172 | #endif /* PAIRSH */ |