inline.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* classes: h_files */
  2. #ifndef SCM_INLINE_H
  3. #define SCM_INLINE_H
  4. /* Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2009, 2010,
  5. * 2011, 2013 Free Software Foundation, Inc.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * as published by the Free Software Foundation; either version 3 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. */
  22. /* This file is for inline functions. On platforms that don't support
  23. inlining functions, they are turned into ordinary functions. On
  24. platforms that do support inline functions, the definitions are still
  25. compiled into the library, once, in inline.c. */
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include "libguile/__scm.h"
  29. #include "libguile/pairs.h"
  30. #include "libguile/gc.h"
  31. #include "libguile/threads.h"
  32. #include "libguile/array-handle.h"
  33. #include "libguile/ports.h"
  34. #include "libguile/numbers.h"
  35. #include "libguile/error.h"
  36. SCM_INLINE int scm_is_pair (SCM x);
  37. SCM_INLINE int scm_is_string (SCM x);
  38. SCM_INLINE int scm_get_byte_or_eof (SCM port);
  39. SCM_INLINE int scm_peek_byte_or_eof (SCM port);
  40. SCM_INLINE void scm_putc (char c, SCM port);
  41. SCM_INLINE void scm_puts (const char *str_data, SCM port);
  42. SCM_INLINE SCM scm_cell (scm_t_bits car, scm_t_bits cdr);
  43. SCM_INLINE SCM scm_double_cell (scm_t_bits car, scm_t_bits cbr,
  44. scm_t_bits ccr, scm_t_bits cdr);
  45. SCM_INLINE SCM scm_words (scm_t_bits car, scm_t_uint16 n_words);
  46. #if SCM_CAN_INLINE || defined SCM_INLINE_C_IMPLEMENTING_INLINES
  47. /* Either inlining, or being included from inline.c. */
  48. SCM_INLINE_IMPLEMENTATION int
  49. scm_is_pair (SCM x)
  50. {
  51. /* The following "workaround_for_gcc_295" avoids bad code generated by
  52. i386 gcc 2.95.4 (the Debian packaged 2.95.4-24 at least).
  53. Under the default -O2 the inlined SCM_I_CONSP test gets "optimized" so
  54. the fetch of the tag word from x is done before confirming it's a
  55. non-immediate (SCM_NIMP). Needless to say that bombs badly if x is a
  56. immediate. This was seen to afflict scm_srfi1_split_at and something
  57. deep in the bowels of ceval(). In both cases segvs resulted from
  58. deferencing a random immediate value. srfi-1.test exposes the problem
  59. through a short list, the immediate being SCM_EOL in that case.
  60. Something in syntax.test exposed the ceval() problem.
  61. Just "volatile SCM workaround_for_gcc_295 = lst" is enough to avoid the
  62. problem, without even using that variable. The "w=w" is just to
  63. prevent a warning about it being unused.
  64. */
  65. #if defined (__GNUC__) && __GNUC__ == 2 && __GNUC_MINOR__ == 95
  66. volatile SCM workaround_for_gcc_295 = x;
  67. workaround_for_gcc_295 = workaround_for_gcc_295;
  68. #endif
  69. return SCM_I_CONSP (x);
  70. }
  71. SCM_INLINE_IMPLEMENTATION int
  72. scm_is_string (SCM x)
  73. {
  74. return SCM_NIMP (x) && (SCM_TYP7 (x) == scm_tc7_string);
  75. }
  76. /* Port I/O. */
  77. SCM_INLINE_IMPLEMENTATION int
  78. scm_get_byte_or_eof (SCM port)
  79. {
  80. scm_t_port *pt = SCM_PTAB_ENTRY (port);
  81. if (SCM_LIKELY ((pt->rw_active == SCM_PORT_READ || !pt->rw_random)
  82. && pt->read_pos < pt->read_end))
  83. return *pt->read_pos++;
  84. else
  85. return scm_slow_get_byte_or_eof (port);
  86. }
  87. /* Like `scm_get_byte_or_eof' but does not change PORT's `read_pos'. */
  88. SCM_INLINE_IMPLEMENTATION int
  89. scm_peek_byte_or_eof (SCM port)
  90. {
  91. scm_t_port *pt = SCM_PTAB_ENTRY (port);
  92. if (SCM_LIKELY ((pt->rw_active == SCM_PORT_READ || !pt->rw_random)
  93. && pt->read_pos < pt->read_end))
  94. return *pt->read_pos;
  95. else
  96. return scm_slow_peek_byte_or_eof (port);
  97. }
  98. SCM_INLINE_IMPLEMENTATION void
  99. scm_putc (char c, SCM port)
  100. {
  101. SCM_ASSERT_TYPE (SCM_OPOUTPORTP (port), port, 0, NULL, "output port");
  102. scm_lfwrite (&c, 1, port);
  103. }
  104. SCM_INLINE_IMPLEMENTATION void
  105. scm_puts (const char *s, SCM port)
  106. {
  107. SCM_ASSERT_TYPE (SCM_OPOUTPORTP (port), port, 0, NULL, "output port");
  108. scm_lfwrite (s, strlen (s), port);
  109. }
  110. #endif
  111. #endif