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