__scm.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /* classes: h_files */
  2. #ifndef SCM___SCM_H
  3. #define SCM___SCM_H
  4. /* Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2006,
  5. * 2007, 2008, 2009, 2010, 2011, 2012, 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. /**********************************************************************
  23. This file is Guile's central public header.
  24. When included by other files, this file should preceed any include
  25. other than __scm.h.
  26. Under *NO* circumstances should new items be added to the global
  27. namespace (via adding #define, typedef, or similar to this file) with
  28. generic names. This usually means that any new names should be
  29. prefixed by either SCM_ or GUILE_. i.e. do *not* #define HAVE_FOO or
  30. SIZEOF_BAR. See configure.in, gen-scmconfig.h.in, and
  31. gen-scmconfig.c for examples of how to properly handle this issue.
  32. The main documentation is in gen-scmconfig.c.
  33. "What's the difference between _scm.h and __scm.h?"
  34. _scm.h is not installed; it's only visible to the libguile sources
  35. themselves, and it includes config.h, the private config header.
  36. __scm.h is installed, and is #included by <libguile.h>. If both
  37. the client and libguile need some piece of information, and it
  38. doesn't fit well into the header file for any particular module, it
  39. should go in __scm.h. __scm.h includes scmconfig.h, the public
  40. config header.
  41. **********************************************************************/
  42. /* What did the configure script discover about the outside world? */
  43. #include "libguile/scmconfig.h"
  44. /* {Compiler hints}
  45. *
  46. * The following macros are used to provide additional information for the
  47. * compiler, which may help to do better error checking and code
  48. * optimization. A second benefit of these macros is, that they also provide
  49. * additional information to the developers.
  50. */
  51. /* Return true (non-zero) if GCC version MAJ.MIN or later is being used
  52. * (macro taken from glibc.) */
  53. #if defined __GNUC__ && defined __GNUC_MINOR__
  54. # define SCM_GNUC_PREREQ(maj, min) \
  55. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  56. #else
  57. # define SCM_GNUC_PREREQ(maj, min) 0
  58. #endif
  59. /* The macro SCM_NORETURN indicates that a function will never return.
  60. * Examples:
  61. * 1) int foo (char arg) SCM_NORETURN;
  62. */
  63. #ifdef __GNUC__
  64. #define SCM_NORETURN __attribute__ ((__noreturn__))
  65. #else
  66. #define SCM_NORETURN
  67. #endif
  68. /* The macro SCM_UNUSED indicates that a function, function argument or
  69. * variable may potentially be unused.
  70. * Examples:
  71. * 1) static int unused_function (char arg) SCM_UNUSED;
  72. * 2) int foo (char unused_argument SCM_UNUSED);
  73. * 3) int unused_variable SCM_UNUSED;
  74. */
  75. #ifdef __GNUC__
  76. #define SCM_UNUSED __attribute__ ((unused))
  77. #else
  78. #define SCM_UNUSED
  79. #endif
  80. /* The SCM_EXPECT macros provide branch prediction hints to the compiler. To
  81. * use only in places where the result of the expression under "normal"
  82. * circumstances is known. */
  83. #if SCM_GNUC_PREREQ (3, 0)
  84. # define SCM_EXPECT __builtin_expect
  85. #else
  86. # define SCM_EXPECT(_expr, _value) (_expr)
  87. #endif
  88. #define SCM_LIKELY(_expr) SCM_EXPECT ((_expr), 1)
  89. #define SCM_UNLIKELY(_expr) SCM_EXPECT ((_expr), 0)
  90. /* The SCM_INTERNAL macro makes it possible to explicitly declare a function
  91. * as having "internal" linkage. However our current tack on this problem is
  92. * to use GCC 4's -fvisibility=hidden, making functions internal by default,
  93. * and then SCM_API marks them for export. */
  94. #define SCM_INTERNAL extern
  95. /* The SCM_DEPRECATED macro is used in declarations of deprecated functions
  96. * or variables. Defining `SCM_BUILDING_DEPRECATED_CODE' allows deprecated
  97. * functions to be implemented in terms of deprecated functions, and allows
  98. * deprecated functions to be referred to by `scm_c_define_gsubr ()'. */
  99. #if !defined (SCM_BUILDING_DEPRECATED_CODE) && SCM_GNUC_PREREQ (3, 0)
  100. # define SCM_DEPRECATED SCM_API __attribute__ ((__deprecated__))
  101. #else
  102. # define SCM_DEPRECATED SCM_API
  103. #endif
  104. /* The SCM_ALIGNED macro, when defined, can be used to instruct the compiler
  105. * to honor the given alignment constraint. */
  106. /* Sun Studio supports alignment since Sun Studio 12 */
  107. #if defined __GNUC__ || (defined( __SUNPRO_C ) && (__SUNPRO_C - 0 >= 0x590))
  108. # define SCM_ALIGNED(x) __attribute__ ((aligned (x)))
  109. #elif defined __INTEL_COMPILER
  110. # define SCM_ALIGNED(x) __declspec (align (x))
  111. #else
  112. /* Don't know how to align things. */
  113. # undef SCM_ALIGNED
  114. #endif
  115. /* The SCM_MALLOC macro can be used in function declarations to tell the
  116. * compiler that a function may be treated as if any non-NULL pointer it returns
  117. * cannot alias any other pointer valid when the function returns. */
  118. #if SCM_GNUC_PREREQ (3, 0)
  119. # define SCM_MALLOC __attribute__ ((__malloc__))
  120. #else
  121. # define SCM_MALLOC
  122. #endif
  123. /* SCM_API is a macro prepended to all function and data definitions
  124. which should be exported from libguile. */
  125. #if defined BUILDING_LIBGUILE && defined HAVE_VISIBILITY
  126. # define SCM_API extern __attribute__((__visibility__("default")))
  127. #elif defined BUILDING_LIBGUILE && defined _MSC_VER
  128. # define SCM_API __declspec(dllexport) extern
  129. #elif defined _MSC_VER
  130. # define SCM_API __declspec(dllimport) extern
  131. #else
  132. # define SCM_API extern
  133. #endif
  134. /* We would like gnu89 extern inline semantics, not C99 extern inline
  135. semantics, so that we can be sure to avoid reifying definitions of
  136. inline functions in all compilation units, which is a possibility at
  137. low optimization levels, or if a user takes the address of an inline
  138. function.
  139. Hence the `__gnu_inline__' attribute, in accordance with:
  140. http://gcc.gnu.org/gcc-4.3/porting_to.html .
  141. With GCC 4.2, `__GNUC_STDC_INLINE__' is never defined (because C99 inline
  142. semantics are not supported), but a warning is issued in C99 mode if
  143. `__gnu_inline__' is not used.
  144. Apple's GCC build >5400 (since Xcode 3.0) doesn't support GNU inline in
  145. C99 mode and doesn't define `__GNUC_STDC_INLINE__'. Fall back to "static
  146. inline" in that case. */
  147. # if (defined __GNUC__) && (!(((defined __APPLE_CC__) && (__APPLE_CC__ > 5400)) && __STDC_VERSION__ >= 199901L))
  148. # if (defined __GNUC_STDC_INLINE__) || (__GNUC__ == 4 && __GNUC_MINOR__ == 2)
  149. # define SCM_C_EXTERN_INLINE \
  150. extern __inline__ __attribute__ ((__gnu_inline__))
  151. # else
  152. # define SCM_C_EXTERN_INLINE extern __inline__
  153. # endif
  154. # endif
  155. /* SCM_INLINE is a macro prepended to all public inline function
  156. declarations. Implementations of those functions should also be in
  157. the header file, prefixed by SCM_INLINE_IMPLEMENTATION, and protected
  158. by SCM_CAN_INLINE and a CPP define for the C file in question, like
  159. SCM_INLINE_C_INCLUDING_INLINE_H. See inline.h for an example
  160. usage. */
  161. #if defined SCM_IMPLEMENT_INLINES
  162. /* Reifying functions to a file, whether or not inlining is available. */
  163. # define SCM_CAN_INLINE 0
  164. # define SCM_INLINE SCM_API
  165. # define SCM_INLINE_IMPLEMENTATION
  166. #elif defined SCM_C_INLINE
  167. /* Declarations when inlining is available. */
  168. # define SCM_CAN_INLINE 1
  169. # ifdef SCM_C_EXTERN_INLINE
  170. # define SCM_INLINE SCM_C_EXTERN_INLINE
  171. # else
  172. /* Fall back to static inline if GNU "extern inline" is unavailable. */
  173. # define SCM_INLINE static SCM_C_INLINE
  174. # endif
  175. # define SCM_INLINE_IMPLEMENTATION SCM_INLINE
  176. #else
  177. /* Declarations when inlining is not available. */
  178. # define SCM_CAN_INLINE 0
  179. # define SCM_INLINE SCM_API
  180. /* Don't define SCM_INLINE_IMPLEMENTATION; it should never be seen in
  181. this case. */
  182. #endif
  183. /* {Debugging Options}
  184. *
  185. * These compile time options determine whether to include code that is only
  186. * useful for debugging guile itself or C level extensions to guile. The
  187. * common prefix for all option macros of this kind is "SCM_DEBUG_". It is
  188. * guaranteed that a macro named SCM_DEBUG_XXX is always defined (typically to
  189. * either 0 or 1), i. e. there is no need to test for the undefined case.
  190. * This allows to use these definitions comfortably within code, as in the
  191. * following example:
  192. * #define FOO do { if (SCM_DEBUG_XXX) bar(); else baz(); } while (0)
  193. * Any sane compiler will remove the unused branch without any performance
  194. * penalty for the resulting code.
  195. *
  196. * Note: Some SCM_DEBUG_XXX options are not settable at configure time.
  197. * To change the value of such options you will have to edit this header
  198. * file or give suitable options to make, like:
  199. * make all CFLAGS="-DSCM_DEBUG_XXX=1 ..."
  200. */
  201. /* The value of SCM_DEBUG determines the default for most of the not yet
  202. * defined debugging options. This allows, for example, to enable most of the
  203. * debugging options by simply defining SCM_DEBUG as 1.
  204. */
  205. #ifndef SCM_DEBUG
  206. #define SCM_DEBUG 0
  207. #endif
  208. /* If SCM_DEBUG_CELL_ACCESSES is set to 1, cell accesses will perform
  209. * exhaustive parameter checking: It will be verified that cell parameters
  210. * actually point to a valid heap cell. Note: If this option is enabled,
  211. * guile will run about ten times slower than normally.
  212. */
  213. #ifndef SCM_DEBUG_CELL_ACCESSES
  214. #define SCM_DEBUG_CELL_ACCESSES SCM_DEBUG
  215. #endif
  216. /* If SCM_DEBUG_PAIR_ACCESSES is set to 1, accesses to cons cells will be
  217. * exhaustively checked. Note: If this option is enabled, guile will run
  218. * slower than normally.
  219. */
  220. #ifndef SCM_DEBUG_PAIR_ACCESSES
  221. #define SCM_DEBUG_PAIR_ACCESSES SCM_DEBUG
  222. #endif
  223. /* If SCM_DEBUG_REST_ARGUMENT is set to 1, functions that take rest arguments
  224. * will check whether the rest arguments are actually passed as a proper list.
  225. * Otherwise, if SCM_DEBUG_REST_ARGUMENT is 0, functions that take rest
  226. * arguments will take it for granted that these are passed as a proper list.
  227. */
  228. #ifndef SCM_DEBUG_REST_ARGUMENT
  229. #define SCM_DEBUG_REST_ARGUMENT SCM_DEBUG
  230. #endif
  231. /* The macro SCM_DEBUG_TYPING_STRICTNESS indicates what level of type checking
  232. * shall be performed with respect to the use of the SCM datatype. The macro
  233. * may be defined to one of the values 0, 1 and 2.
  234. *
  235. * A value of 0 means that there will be no compile time type checking, since
  236. * the SCM datatype will be declared as an integral type. This setting should
  237. * only be used on systems, where casting from integral types to pointers may
  238. * lead to loss of bit information.
  239. *
  240. * A value of 1 means that there will an intermediate level of compile time
  241. * type checking, since the SCM datatype will be declared as a pointer to an
  242. * undefined struct. This setting is the default, since it does not cost
  243. * anything in terms of performance or code size.
  244. *
  245. * A value of 2 provides a maximum level of compile time type checking since
  246. * the SCM datatype will be declared as a struct. This setting should be used
  247. * for _compile time_ type checking only, since the compiled result is likely
  248. * to be quite inefficient. The right way to make use of this option is to do
  249. * a 'make clean; make CFLAGS=-DSCM_DEBUG_TYPING_STRICTNESS=2', fix your
  250. * errors, and then do 'make clean; make'.
  251. */
  252. #ifndef SCM_DEBUG_TYPING_STRICTNESS
  253. #define SCM_DEBUG_TYPING_STRICTNESS 1
  254. #endif
  255. /* {Feature Options}
  256. *
  257. * These compile time options determine whether code for certain features
  258. * should be compiled into guile. The common prefix for all option macros
  259. * of this kind is "SCM_ENABLE_". It is guaranteed that a macro named
  260. * SCM_ENABLE_XXX is defined to be either 0 or 1, i. e. there is no need to
  261. * test for the undefined case. This allows to use these definitions
  262. * comfortably within code, as in the following example:
  263. * #define FOO do { if (SCM_ENABLE_XXX) bar(); else baz(); } while (0)
  264. * Any sane compiler will remove the unused branch without any performance
  265. * penalty for the resulting code.
  266. *
  267. * Note: Some SCM_ENABLE_XXX options are not settable at configure time.
  268. * To change the value of such options you will have to edit this header
  269. * file or give suitable options to make, like:
  270. * make all CFLAGS="-DSCM_ENABLE_XXX=1 ..."
  271. */
  272. /* If SCM_ENABLE_DEPRECATED is set to 1, deprecated code will be included in
  273. * guile, as well as some functions to issue run-time warnings about uses of
  274. * deprecated functions.
  275. */
  276. #ifndef SCM_ENABLE_DEPRECATED
  277. #define SCM_ENABLE_DEPRECATED 0
  278. #endif
  279. /* {Architecture and compiler properties}
  280. *
  281. * Guile as of today can only work on systems which fulfill at least the
  282. * following requirements:
  283. *
  284. * - scm_t_bits and SCM variables have at least 32 bits.
  285. * Guile's type system is based on this assumption.
  286. *
  287. * - sizeof (scm_t_bits) >= sizeof (void*) and sizeof (SCM) >= sizeof (void*)
  288. * Guile's type system is based on this assumption, since it must be
  289. * possible to store pointers to cells on the heap in scm_t_bits and SCM
  290. * variables.
  291. *
  292. * - sizeof (scm_t_bits) >= 4 and sizeof (scm_t_bits) is a power of 2.
  293. * Guile's type system is based on this assumption. In particular, it is
  294. * assumed that cells, i. e. pairs of scm_t_bits variables, are eight
  295. * character aligned. This is because three bits of a scm_t_bits variable
  296. * that is holding a pointer to a cell on the heap must be available for
  297. * storing type data.
  298. *
  299. * - sizeof (scm_t_bits) <= sizeof (void*) and sizeof (SCM) <= sizeof (void*)
  300. * In some parts of guile, scm_t_bits and SCM variables are passed to
  301. * functions as void* arguments. Together with the requirement above, this
  302. * requires a one-to-one correspondence between the size of a void* and the
  303. * sizes of scm_t_bits and SCM variables.
  304. *
  305. * - numbers are encoded using two's complement.
  306. * The implementation of the bitwise scheme level operations is based on
  307. * this assumption.
  308. *
  309. * - ... add more
  310. */
  311. #ifdef CHAR_BIT
  312. # define SCM_CHAR_BIT CHAR_BIT
  313. #else
  314. # define SCM_CHAR_BIT 8
  315. #endif
  316. #ifdef LONG_BIT
  317. # define SCM_LONG_BIT LONG_BIT
  318. #else
  319. # define SCM_LONG_BIT (SCM_SIZEOF_LONG * 8)
  320. #endif
  321. #define SCM_I_UTYPE_MAX(type) ((type)-1)
  322. #define SCM_I_TYPE_MAX(type,umax) ((type)((umax)/2))
  323. #define SCM_I_TYPE_MIN(type,umax) (-((type)((umax)/2))-1)
  324. #define SCM_T_UINT8_MAX SCM_I_UTYPE_MAX(scm_t_uint8)
  325. #define SCM_T_INT8_MIN SCM_I_TYPE_MIN(scm_t_int8,SCM_T_UINT8_MAX)
  326. #define SCM_T_INT8_MAX SCM_I_TYPE_MAX(scm_t_int8,SCM_T_UINT8_MAX)
  327. #define SCM_T_UINT16_MAX SCM_I_UTYPE_MAX(scm_t_uint16)
  328. #define SCM_T_INT16_MIN SCM_I_TYPE_MIN(scm_t_int16,SCM_T_UINT16_MAX)
  329. #define SCM_T_INT16_MAX SCM_I_TYPE_MAX(scm_t_int16,SCM_T_UINT16_MAX)
  330. #define SCM_T_UINT32_MAX SCM_I_UTYPE_MAX(scm_t_uint32)
  331. #define SCM_T_INT32_MIN SCM_I_TYPE_MIN(scm_t_int32,SCM_T_UINT32_MAX)
  332. #define SCM_T_INT32_MAX SCM_I_TYPE_MAX(scm_t_int32,SCM_T_UINT32_MAX)
  333. #define SCM_T_UINT64_MAX SCM_I_UTYPE_MAX(scm_t_uint64)
  334. #define SCM_T_INT64_MIN SCM_I_TYPE_MIN(scm_t_int64,SCM_T_UINT64_MAX)
  335. #define SCM_T_INT64_MAX SCM_I_TYPE_MAX(scm_t_int64,SCM_T_UINT64_MAX)
  336. #define SCM_T_UINTMAX_MAX SCM_I_UTYPE_MAX(scm_t_uintmax)
  337. #define SCM_T_INTMAX_MIN SCM_I_TYPE_MIN(scm_t_intmax,SCM_T_UINTMAX_MAX)
  338. #define SCM_T_INTMAX_MAX SCM_I_TYPE_MAX(scm_t_intmax,SCM_T_UINTMAX_MAX)
  339. #define SCM_T_UINTPTR_MAX SCM_I_UTYPE_MAX(scm_t_uintptr)
  340. #define SCM_T_INTPTR_MIN SCM_I_TYPE_MIN(scm_t_intptr,SCM_T_UINTPTR_MAX)
  341. #define SCM_T_INTPTR_MAX SCM_I_TYPE_MAX(scm_t_intptr,SCM_T_UINTPTR_MAX)
  342. #include "libguile/tags.h"
  343. /* The type of subrs, i.e., Scheme procedures implemented in C. Empty
  344. function declarators are used internally for pointers to functions of
  345. any arity. However, these are equivalent to `(void)' in C++, are
  346. obsolescent as of C99, and trigger `strict-prototypes' GCC warnings
  347. (bug #23681). */
  348. #ifdef BUILDING_LIBGUILE
  349. typedef SCM (* scm_t_subr) ();
  350. #else
  351. typedef void *scm_t_subr;
  352. #endif
  353. /* scm_i_jmp_buf
  354. *
  355. * The corresponding SCM_I_SETJMP and SCM_I_LONGJMP are defined in the
  356. * _scm.h private header.
  357. */
  358. #if defined (vms)
  359. typedef int scm_i_jmp_buf[17];
  360. #elif defined (_CRAY1)
  361. typedef int scm_i_jmp_buf[112];
  362. #elif defined (__ia64__)
  363. # include <signal.h>
  364. # include <ucontext.h>
  365. typedef struct {
  366. ucontext_t ctx;
  367. int fresh;
  368. } scm_i_jmp_buf;
  369. #else
  370. # include <setjmp.h>
  371. typedef jmp_buf scm_i_jmp_buf;
  372. #endif
  373. /* If stack is not longword aligned then
  374. */
  375. /* #define SHORT_ALIGN */
  376. #ifdef THINK_C
  377. # define SHORT_ALIGN
  378. #endif
  379. #ifdef MSDOS
  380. # define SHORT_ALIGN
  381. #endif
  382. #ifdef atarist
  383. # define SHORT_ALIGN
  384. #endif
  385. #ifdef SHORT_ALIGN
  386. typedef short SCM_STACKITEM;
  387. #else
  388. typedef long SCM_STACKITEM;
  389. #endif
  390. /* Cast pointer through (void *) in order to avoid compiler warnings
  391. when strict aliasing is enabled */
  392. #define SCM_STACK_PTR(ptr) ((SCM_STACKITEM *) (void *) (ptr))
  393. #ifdef BUILDING_LIBGUILE
  394. #define SCM_TICK SCM_ASYNC_TICK
  395. #else
  396. #define SCM_TICK scm_async_tick ()
  397. #endif
  398. #ifndef SCM_MAGIC_SNARFER
  399. /* Let these macros pass through if
  400. we are snarfing; thus we can tell the
  401. difference between the use of an actual
  402. number vs. the use of one of these macros --
  403. actual numbers in SCM_VALIDATE_* and SCM_ASSERT
  404. constructs must match the formal argument name,
  405. but using SCM_ARG* avoids the test */
  406. #define SCM_ARGn 0
  407. #define SCM_ARG1 1
  408. #define SCM_ARG2 2
  409. #define SCM_ARG3 3
  410. #define SCM_ARG4 4
  411. #define SCM_ARG5 5
  412. #define SCM_ARG6 6
  413. #define SCM_ARG7 7
  414. #endif /* SCM_MAGIC_SNARFER */
  415. /* Define SCM_C_INLINE_KEYWORD so that it can be used as a replacement
  416. for the "inline" keyword, expanding to nothing when "inline" is not
  417. available.
  418. */
  419. #ifdef SCM_C_INLINE
  420. #define SCM_C_INLINE_KEYWORD SCM_C_INLINE
  421. #else
  422. #define SCM_C_INLINE_KEYWORD
  423. #endif
  424. /* Handling thread-local storage (TLS). */
  425. #ifdef SCM_HAVE_THREAD_STORAGE_CLASS
  426. # define SCM_THREAD_LOCAL __thread
  427. #else
  428. # define SCM_THREAD_LOCAL
  429. #endif
  430. #endif /* SCM___SCM_H */
  431. /*
  432. Local Variables:
  433. c-file-style: "gnu"
  434. End:
  435. */