pairs.h 6.7 KB

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