__scm.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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 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. #if defined __GNUC__
  107. # define SCM_ALIGNED(x) __attribute__ ((aligned (x)))
  108. #elif defined __INTEL_COMPILER
  109. # define SCM_ALIGNED(x) __declspec (align (x))
  110. #else
  111. /* Don't know how to align things. */
  112. # undef SCM_ALIGNED
  113. #endif
  114. /* The SCM_MALLOC macro can be used in function declarations to tell the
  115. * compiler that a function may be treated as if any non-NULL pointer it returns
  116. * cannot alias any other pointer valid when the function returns. */
  117. #if SCM_GNUC_PREREQ (3, 0)
  118. # define SCM_MALLOC __attribute__ ((__malloc__))
  119. #else
  120. # define SCM_MALLOC
  121. #endif
  122. /* {Supported Options}
  123. *
  124. * These may be defined or undefined.
  125. */
  126. /* #define GUILE_DEBUG_FREELIST */
  127. /* Use engineering notation when converting numbers strings?
  128. */
  129. #undef ENGNOT
  130. /* {Unsupported Options}
  131. *
  132. * These must be defined as given here.
  133. */
  134. /* Guile Scheme supports the #f/() distinction; Guile Lisp won't. We
  135. have horrible plans for their unification. */
  136. #undef SICP
  137. /* Random options (not yet supported or in final form). */
  138. #define STACK_CHECKING
  139. #undef NO_CEVAL_STACK_CHECKING
  140. /* SCM_API is a macro prepended to all function and data definitions
  141. which should be exported from libguile. */
  142. #if defined BUILDING_LIBGUILE && defined HAVE_VISIBILITY
  143. # define SCM_API extern __attribute__((__visibility__("default")))
  144. #elif defined BUILDING_LIBGUILE && defined _MSC_VER
  145. # define SCM_API __declspec(dllexport) extern
  146. #elif defined _MSC_VER
  147. # define SCM_API __declspec(dllimport) extern
  148. #else
  149. # define SCM_API extern
  150. #endif
  151. /* {Debugging Options}
  152. *
  153. * These compile time options determine whether to include code that is only
  154. * useful for debugging guile itself or C level extensions to guile. The
  155. * common prefix for all option macros of this kind is "SCM_DEBUG_". It is
  156. * guaranteed that a macro named SCM_DEBUG_XXX is always defined (typically to
  157. * either 0 or 1), i. e. there is no need to test for the undefined case.
  158. * This allows to use these definitions comfortably within code, as in the
  159. * following example:
  160. * #define FOO do { if (SCM_DEBUG_XXX) bar(); else baz(); } while (0)
  161. * Any sane compiler will remove the unused branch without any performance
  162. * penalty for the resulting code.
  163. *
  164. * Note: Some SCM_DEBUG_XXX options are not settable at configure time.
  165. * To change the value of such options you will have to edit this header
  166. * file or give suitable options to make, like:
  167. * make all CFLAGS="-DSCM_DEBUG_XXX=1 ..."
  168. */
  169. /* The value of SCM_DEBUG determines the default for most of the not yet
  170. * defined debugging options. This allows, for example, to enable most of the
  171. * debugging options by simply defining SCM_DEBUG as 1.
  172. */
  173. #ifndef SCM_DEBUG
  174. #define SCM_DEBUG 0
  175. #endif
  176. /* For debugging purposes: define this is to ensure nobody is using
  177. * the mark bits outside of the marking phase. This is meant for
  178. * debugging purposes only.
  179. */
  180. #ifndef SCM_DEBUG_MARKING_API
  181. #define SCM_DEBUG_MARKING_API 0
  182. #endif
  183. /* If SCM_DEBUG_CELL_ACCESSES is set to 1, cell accesses will perform
  184. * exhaustive parameter checking: It will be verified that cell parameters
  185. * actually point to a valid heap cell. Note: If this option is enabled,
  186. * guile will run about ten times slower than normally.
  187. */
  188. #ifndef SCM_DEBUG_CELL_ACCESSES
  189. #define SCM_DEBUG_CELL_ACCESSES SCM_DEBUG
  190. #endif
  191. /* If SCM_DEBUG_INTERRUPTS is set to 1, with every deferring and allowing of
  192. * interrupts a consistency check will be performed.
  193. */
  194. #ifndef SCM_DEBUG_INTERRUPTS
  195. #define SCM_DEBUG_INTERRUPTS SCM_DEBUG
  196. #endif
  197. /* If SCM_DEBUG_PAIR_ACCESSES is set to 1, accesses to cons cells will be
  198. * exhaustively checked. Note: If this option is enabled, guile will run
  199. * slower than normally.
  200. */
  201. #ifndef SCM_DEBUG_PAIR_ACCESSES
  202. #define SCM_DEBUG_PAIR_ACCESSES SCM_DEBUG
  203. #endif
  204. /* If SCM_DEBUG_REST_ARGUMENT is set to 1, functions that take rest arguments
  205. * will check whether the rest arguments are actually passed as a proper list.
  206. * Otherwise, if SCM_DEBUG_REST_ARGUMENT is 0, functions that take rest
  207. * arguments will take it for granted that these are passed as a proper list.
  208. */
  209. #ifndef SCM_DEBUG_REST_ARGUMENT
  210. #define SCM_DEBUG_REST_ARGUMENT SCM_DEBUG
  211. #endif
  212. /* The macro SCM_DEBUG_TYPING_STRICTNESS indicates what level of type checking
  213. * shall be performed with respect to the use of the SCM datatype. The macro
  214. * may be defined to one of the values 0, 1 and 2.
  215. *
  216. * A value of 0 means that there will be no compile time type checking, since
  217. * the SCM datatype will be declared as an integral type. This setting should
  218. * only be used on systems, where casting from integral types to pointers may
  219. * lead to loss of bit information.
  220. *
  221. * A value of 1 means that there will an intermediate level of compile time
  222. * type checking, since the SCM datatype will be declared as a pointer to an
  223. * undefined struct. This setting is the default, since it does not cost
  224. * anything in terms of performance or code size.
  225. *
  226. * A value of 2 provides a maximum level of compile time type checking since
  227. * the SCM datatype will be declared as a struct. This setting should be used
  228. * for _compile time_ type checking only, since the compiled result is likely
  229. * to be quite inefficient. The right way to make use of this option is to do
  230. * a 'make clean; make CFLAGS=-DSCM_DEBUG_TYPING_STRICTNESS=2', fix your
  231. * errors, and then do 'make clean; make'.
  232. */
  233. #ifndef SCM_DEBUG_TYPING_STRICTNESS
  234. #define SCM_DEBUG_TYPING_STRICTNESS 2
  235. #endif
  236. /* If SCM_DEBUG_DEBUGGING_SUPPORT is set to 1, guile will provide a set of
  237. * special functions that support debugging with a debugger like gdb or
  238. * debugging of guile internals on the scheme level. The behaviour of guile
  239. * is not changed by this macro, only the set of functions that are available
  240. * will differ. All functions that are introduced this way have the prefix
  241. * 'scm_dbg_' on the C level and the prefix 'dbg-' on the scheme level. This
  242. * allows to easily determine the set of support functions, given that your
  243. * debugger or repl provide automatic name completion. Note that these
  244. * functions are intended to be used during interactive debugging sessions
  245. * only. They are not considered part of guile's official API. They may
  246. * change or disappear without notice or deprecation phase.
  247. */
  248. #ifndef SCM_DEBUG_DEBUGGING_SUPPORT
  249. #define SCM_DEBUG_DEBUGGING_SUPPORT SCM_DEBUG
  250. #endif
  251. /* {Feature Options}
  252. *
  253. * These compile time options determine whether code for certain features
  254. * should be compiled into guile. The common prefix for all option macros
  255. * of this kind is "SCM_ENABLE_". It is guaranteed that a macro named
  256. * SCM_ENABLE_XXX is defined to be either 0 or 1, i. e. there is no need to
  257. * test for the undefined case. This allows to use these definitions
  258. * comfortably within code, as in the following example:
  259. * #define FOO do { if (SCM_ENABLE_XXX) bar(); else baz(); } while (0)
  260. * Any sane compiler will remove the unused branch without any performance
  261. * penalty for the resulting code.
  262. *
  263. * Note: Some SCM_ENABLE_XXX options are not settable at configure time.
  264. * To change the value of such options you will have to edit this header
  265. * file or give suitable options to make, like:
  266. * make all CFLAGS="-DSCM_ENABLE_XXX=1 ..."
  267. */
  268. /* If SCM_ENABLE_DEPRECATED is set to 1, deprecated code will be included in
  269. * guile, as well as some functions to issue run-time warnings about uses of
  270. * deprecated functions.
  271. */
  272. #ifndef SCM_ENABLE_DEPRECATED
  273. #define SCM_ENABLE_DEPRECATED 0
  274. #endif
  275. /* {Architecture and compiler properties}
  276. *
  277. * Guile as of today can only work on systems which fulfill at least the
  278. * following requirements:
  279. *
  280. * - scm_t_bits and SCM variables have at least 32 bits.
  281. * Guile's type system is based on this assumption.
  282. *
  283. * - sizeof (scm_t_bits) >= sizeof (void*) and sizeof (SCM) >= sizeof (void*)
  284. * Guile's type system is based on this assumption, since it must be
  285. * possible to store pointers to cells on the heap in scm_t_bits and SCM
  286. * variables.
  287. *
  288. * - sizeof (scm_t_bits) >= 4 and sizeof (scm_t_bits) is a power of 2.
  289. * Guile's type system is based on this assumption. In particular, it is
  290. * assumed that cells, i. e. pairs of scm_t_bits variables, are eight
  291. * character aligned. This is because three bits of a scm_t_bits variable
  292. * that is holding a pointer to a cell on the heap must be available for
  293. * storing type data.
  294. *
  295. * - sizeof (scm_t_bits) <= sizeof (void*) and sizeof (SCM) <= sizeof (void*)
  296. * In some parts of guile, scm_t_bits and SCM variables are passed to
  297. * functions as void* arguments. Together with the requirement above, this
  298. * requires a one-to-one correspondence between the size of a void* and the
  299. * sizes of scm_t_bits and SCM variables.
  300. *
  301. * - numbers are encoded using two's complement.
  302. * The implementation of the bitwise scheme level operations is based on
  303. * this assumption.
  304. *
  305. * - ... add more
  306. */
  307. #ifdef CHAR_BIT
  308. # define SCM_CHAR_BIT CHAR_BIT
  309. #else
  310. # define SCM_CHAR_BIT 8
  311. #endif
  312. #ifdef LONG_BIT
  313. # define SCM_LONG_BIT LONG_BIT
  314. #else
  315. # define SCM_LONG_BIT (SCM_CHAR_BIT * sizeof (long) / sizeof (char))
  316. #endif
  317. #ifdef UCHAR_MAX
  318. # define SCM_CHAR_CODE_LIMIT (UCHAR_MAX + 1L)
  319. #else
  320. # define SCM_CHAR_CODE_LIMIT 256L
  321. #endif
  322. #define SCM_I_UTYPE_MAX(type) ((type)-1)
  323. #define SCM_I_TYPE_MAX(type,umax) ((type)((umax)/2))
  324. #define SCM_I_TYPE_MIN(type,umax) (-((type)((umax)/2))-1)
  325. #define SCM_T_UINT8_MAX SCM_I_UTYPE_MAX(scm_t_uint8)
  326. #define SCM_T_INT8_MIN SCM_I_TYPE_MIN(scm_t_int8,SCM_T_UINT8_MAX)
  327. #define SCM_T_INT8_MAX SCM_I_TYPE_MAX(scm_t_int8,SCM_T_UINT8_MAX)
  328. #define SCM_T_UINT16_MAX SCM_I_UTYPE_MAX(scm_t_uint16)
  329. #define SCM_T_INT16_MIN SCM_I_TYPE_MIN(scm_t_int16,SCM_T_UINT16_MAX)
  330. #define SCM_T_INT16_MAX SCM_I_TYPE_MAX(scm_t_int16,SCM_T_UINT16_MAX)
  331. #define SCM_T_UINT32_MAX SCM_I_UTYPE_MAX(scm_t_uint32)
  332. #define SCM_T_INT32_MIN SCM_I_TYPE_MIN(scm_t_int32,SCM_T_UINT32_MAX)
  333. #define SCM_T_INT32_MAX SCM_I_TYPE_MAX(scm_t_int32,SCM_T_UINT32_MAX)
  334. #define SCM_T_UINT64_MAX SCM_I_UTYPE_MAX(scm_t_uint64)
  335. #define SCM_T_INT64_MIN SCM_I_TYPE_MIN(scm_t_int64,SCM_T_UINT64_MAX)
  336. #define SCM_T_INT64_MAX SCM_I_TYPE_MAX(scm_t_int64,SCM_T_UINT64_MAX)
  337. #if SCM_SIZEOF_LONG_LONG
  338. #define SCM_I_ULLONG_MAX SCM_I_UTYPE_MAX(unsigned long long)
  339. #define SCM_I_LLONG_MIN SCM_I_TYPE_MIN(long long,SCM_I_ULLONG_MAX)
  340. #define SCM_I_LLONG_MAX SCM_I_TYPE_MAX(long long,SCM_I_ULLONG_MAX)
  341. #endif
  342. #define SCM_T_UINTMAX_MAX SCM_I_UTYPE_MAX(scm_t_uintmax)
  343. #define SCM_T_INTMAX_MIN SCM_I_TYPE_MIN(scm_t_intmax,SCM_T_UINTMAX_MAX)
  344. #define SCM_T_INTMAX_MAX SCM_I_TYPE_MAX(scm_t_intmax,SCM_T_UINTMAX_MAX)
  345. #define SCM_T_UINTPTR_MAX SCM_I_UTYPE_MAX(scm_t_uintptr)
  346. #define SCM_T_INTPTR_MIN SCM_I_TYPE_MIN(scm_t_intptr,SCM_T_UINTPTR_MAX)
  347. #define SCM_T_INTPTR_MAX SCM_I_TYPE_MAX(scm_t_intptr,SCM_T_UINTPTR_MAX)
  348. #define SCM_I_SIZE_MAX SCM_I_UTYPE_MAX(size_t)
  349. #define SCM_I_SSIZE_MIN SCM_I_TYPE_MIN(ssize_t,SCM_I_SIZE_MAX)
  350. #define SCM_I_SSIZE_MAX SCM_I_TYPE_MAX(ssize_t,SCM_I_SIZE_MAX)
  351. #include "libguile/tags.h"
  352. /* The type of subrs, i.e., Scheme procedures implemented in C. Empty
  353. function declarators are used internally for pointers to functions of
  354. any arity. However, these are equivalent to `(void)' in C++, are
  355. obsolescent as of C99, and trigger `strict-prototypes' GCC warnings
  356. (bug #23681). */
  357. #ifdef BUILDING_LIBGUILE
  358. typedef SCM (* scm_t_subr) ();
  359. #else
  360. typedef void *scm_t_subr;
  361. #endif
  362. #ifdef vms
  363. # ifndef CHEAP_CONTINUATIONS
  364. typedef int jmp_buf[17];
  365. extern int setjump(jmp_buf env);
  366. extern int longjump(jmp_buf env, int ret);
  367. # define setjmp setjump
  368. # define longjmp longjump
  369. # else
  370. # include <setjmp.h>
  371. # endif
  372. #else /* ndef vms */
  373. # ifdef _CRAY1
  374. typedef int jmp_buf[112];
  375. extern int setjump(jmp_buf env);
  376. extern int longjump(jmp_buf env, int ret);
  377. # define setjmp setjump
  378. # define longjmp longjump
  379. # else /* ndef _CRAY1 */
  380. # if defined (__ia64__)
  381. /* For IA64, emulate the setjmp API using getcontext. */
  382. # include <signal.h>
  383. # include <ucontext.h>
  384. typedef struct {
  385. ucontext_t ctx;
  386. int fresh;
  387. } scm_i_jmp_buf;
  388. # define SCM_I_SETJMP(JB) \
  389. ( (JB).fresh = 1, \
  390. getcontext (&((JB).ctx)), \
  391. ((JB).fresh ? ((JB).fresh = 0, 0) : 1) )
  392. # define SCM_I_LONGJMP(JB,VAL) scm_ia64_longjmp (&(JB), VAL)
  393. void scm_ia64_longjmp (scm_i_jmp_buf *, int);
  394. # else /* ndef __ia64__ */
  395. # include <setjmp.h>
  396. # endif /* ndef __ia64__ */
  397. # endif /* ndef _CRAY1 */
  398. #endif /* ndef vms */
  399. /* For any platform where SCM_I_SETJMP hasn't been defined in some
  400. special way above, map SCM_I_SETJMP, SCM_I_LONGJMP and
  401. scm_i_jmp_buf to setjmp, longjmp and jmp_buf. */
  402. #ifndef SCM_I_SETJMP
  403. #define scm_i_jmp_buf jmp_buf
  404. #define SCM_I_SETJMP setjmp
  405. #define SCM_I_LONGJMP longjmp
  406. #endif
  407. /* James Clark came up with this neat one instruction fix for
  408. * continuations on the SPARC. It flushes the register windows so
  409. * that all the state of the process is contained in the stack.
  410. */
  411. #if defined (sparc) || defined (__sparc__) || defined (__sparc)
  412. # define SCM_FLUSH_REGISTER_WINDOWS asm("ta 3")
  413. #else
  414. # define SCM_FLUSH_REGISTER_WINDOWS /* empty */
  415. #endif
  416. /* If stack is not longword aligned then
  417. */
  418. /* #define SHORT_ALIGN */
  419. #ifdef THINK_C
  420. # define SHORT_ALIGN
  421. #endif
  422. #ifdef MSDOS
  423. # define SHORT_ALIGN
  424. #endif
  425. #ifdef atarist
  426. # define SHORT_ALIGN
  427. #endif
  428. #ifdef SHORT_ALIGN
  429. typedef short SCM_STACKITEM;
  430. #else
  431. typedef long SCM_STACKITEM;
  432. #endif
  433. /* Cast pointer through (void *) in order to avoid compiler warnings
  434. when strict aliasing is enabled */
  435. #define SCM_STACK_PTR(ptr) ((SCM_STACKITEM *) (void *) (ptr))
  436. SCM_API void scm_async_tick (void);
  437. #ifdef BUILDING_LIBGUILE
  438. /* FIXME: should change names */
  439. # define SCM_ASYNC_TICK \
  440. do \
  441. { \
  442. if (SCM_UNLIKELY (SCM_I_CURRENT_THREAD->pending_asyncs)) \
  443. scm_async_click (); \
  444. } \
  445. while (0)
  446. /* SCM_ASYNC_TICK_WITH_CODE is only available to Guile itself */
  447. # define SCM_ASYNC_TICK_WITH_CODE(thr, stmt) \
  448. do \
  449. { \
  450. if (SCM_UNLIKELY (thr->pending_asyncs)) \
  451. { \
  452. stmt; \
  453. scm_async_click (); \
  454. } \
  455. } \
  456. while (0)
  457. #else /* !BUILDING_LIBGUILE */
  458. # define SCM_ASYNC_TICK (scm_async_tick ())
  459. #endif /* !BUILDING_LIBGUILE */
  460. /* Anthony Green writes:
  461. When the compiler sees...
  462. DEFER_INTS;
  463. [critical code here]
  464. ALLOW_INTS;
  465. ...it doesn't actually promise to keep the critical code within the
  466. boundries of the DEFER/ALLOW_INTS instructions. It may very well
  467. schedule it outside of the magic defined in those macros.
  468. However, GCC's volatile asm feature forms a barrier over which code is
  469. never moved. So if you add...
  470. asm ("");
  471. ...to each of the DEFER_INTS and ALLOW_INTS macros, the critical
  472. code will always remain in place. asm's without inputs or outputs
  473. are implicitly volatile. */
  474. #ifdef __GNUC__
  475. #define SCM_FENCE asm /* volatile */ ("")
  476. #elif defined (__INTEL_COMPILER) && defined (__ia64)
  477. #define SCM_FENCE __memory_barrier()
  478. #else
  479. #define SCM_FENCE
  480. #endif
  481. #define SCM_TICK \
  482. do { \
  483. SCM_ASYNC_TICK; \
  484. SCM_THREAD_SWITCHING_CODE; \
  485. } while (0)
  486. /** SCM_ASSERT
  487. **
  488. **/
  489. #ifdef SCM_RECKLESS
  490. #define SCM_ASSERT(_cond, _arg, _pos, _subr)
  491. #define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr, _msg)
  492. #define SCM_ASRTGO(_cond, _label)
  493. #else
  494. #define SCM_ASSERT(_cond, _arg, _pos, _subr) \
  495. do { if (SCM_UNLIKELY (!(_cond))) \
  496. scm_wrong_type_arg (_subr, _pos, _arg); } while (0)
  497. #define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr, _msg) \
  498. do { if (SCM_UNLIKELY (!(_cond))) \
  499. scm_wrong_type_arg_msg(_subr, _pos, _arg, _msg); } while (0)
  500. #define SCM_ASRTGO(_cond, _label) \
  501. do { if (SCM_UNLIKELY (!(_cond))) \
  502. goto _label; } while (0)
  503. #endif
  504. /*
  505. * SCM_WTA_DISPATCH
  506. */
  507. /* Dirk:FIXME:: In all of the SCM_WTA_DISPATCH_* macros it is assumed that
  508. * 'gf' is zero if uninitialized. It would be cleaner if some valid SCM value
  509. * like SCM_BOOL_F or SCM_UNDEFINED was chosen.
  510. */
  511. SCM_API SCM scm_call_generic_0 (SCM gf);
  512. #define SCM_WTA_DISPATCH_0(gf, subr) \
  513. return (SCM_UNPACK (gf) \
  514. ? scm_call_generic_0 ((gf)) \
  515. : (scm_error_num_args_subr ((subr)), SCM_UNSPECIFIED))
  516. #define SCM_GASSERT0(cond, gf, subr) \
  517. if (SCM_UNLIKELY(!(cond))) \
  518. SCM_WTA_DISPATCH_0((gf), (subr))
  519. SCM_API SCM scm_call_generic_1 (SCM gf, SCM a1);
  520. #define SCM_WTA_DISPATCH_1(gf, a1, pos, subr) \
  521. return (SCM_UNPACK (gf) \
  522. ? scm_call_generic_1 ((gf), (a1)) \
  523. : (scm_wrong_type_arg ((subr), (pos), (a1)), SCM_UNSPECIFIED))
  524. /* This form is for dispatching a subroutine. */
  525. #define SCM_WTA_DISPATCH_1_SUBR(subr, a1, pos) \
  526. return (SCM_UNPACK ((*SCM_SUBR_GENERIC (subr))) \
  527. ? scm_call_generic_1 ((*SCM_SUBR_GENERIC (subr)), (a1)) \
  528. : (scm_i_wrong_type_arg_symbol (SCM_SUBR_NAME (subr), (pos), (a1)), SCM_UNSPECIFIED))
  529. #define SCM_GASSERT1(cond, gf, a1, pos, subr) \
  530. if (SCM_UNLIKELY (!(cond))) \
  531. SCM_WTA_DISPATCH_1((gf), (a1), (pos), (subr))
  532. SCM_API SCM scm_call_generic_2 (SCM gf, SCM a1, SCM a2);
  533. #define SCM_WTA_DISPATCH_2(gf, a1, a2, pos, subr) \
  534. return (SCM_UNPACK (gf) \
  535. ? scm_call_generic_2 ((gf), (a1), (a2)) \
  536. : (scm_wrong_type_arg ((subr), (pos), \
  537. (pos) == SCM_ARG1 ? (a1) : (a2)), \
  538. SCM_UNSPECIFIED))
  539. #define SCM_GASSERT2(cond, gf, a1, a2, pos, subr) \
  540. if (SCM_UNLIKELY (!(cond))) \
  541. SCM_WTA_DISPATCH_2((gf), (a1), (a2), (pos), (subr))
  542. SCM_API SCM scm_apply_generic (SCM gf, SCM args);
  543. #define SCM_WTA_DISPATCH_n(gf, args, pos, subr) \
  544. return (SCM_UNPACK (gf) \
  545. ? scm_apply_generic ((gf), (args)) \
  546. : (scm_wrong_type_arg ((subr), (pos), \
  547. scm_list_ref ((args), \
  548. scm_from_int ((pos) - 1))), \
  549. SCM_UNSPECIFIED))
  550. #define SCM_GASSERTn(cond, gf, args, pos, subr) \
  551. if (SCM_UNLIKELY (!(cond))) \
  552. SCM_WTA_DISPATCH_n((gf), (args), (pos), (subr))
  553. #ifndef SCM_MAGIC_SNARFER
  554. /* Let these macros pass through if
  555. we are snarfing; thus we can tell the
  556. difference between the use of an actual
  557. number vs. the use of one of these macros --
  558. actual numbers in SCM_VALIDATE_* and SCM_ASSERT
  559. constructs must match the formal argument name,
  560. but using SCM_ARG* avoids the test */
  561. #define SCM_ARGn 0
  562. #define SCM_ARG1 1
  563. #define SCM_ARG2 2
  564. #define SCM_ARG3 3
  565. #define SCM_ARG4 4
  566. #define SCM_ARG5 5
  567. #define SCM_ARG6 6
  568. #define SCM_ARG7 7
  569. #endif /* SCM_MAGIC_SNARFER */
  570. /* SCM_EXIT_SUCCESS is the default code to return from SCM if no errors
  571. * were encountered. SCM_EXIT_FAILURE is the default code to return from
  572. * SCM if errors were encountered. The return code can be explicitly
  573. * specified in a SCM program with (scm_quit <n>).
  574. */
  575. #ifndef SCM_EXIT_SUCCESS
  576. #ifdef vms
  577. #define SCM_EXIT_SUCCESS 1
  578. #else
  579. #define SCM_EXIT_SUCCESS 0
  580. #endif /* def vms */
  581. #endif /* ndef SCM_EXIT_SUCCESS */
  582. #ifndef SCM_EXIT_FAILURE
  583. #ifdef vms
  584. #define SCM_EXIT_FAILURE 2
  585. #else
  586. #define SCM_EXIT_FAILURE 1
  587. #endif /* def vms */
  588. #endif /* ndef SCM_EXIT_FAILURE */
  589. /* Define SCM_C_INLINE_KEYWORD so that it can be used as a replacement
  590. for the "inline" keyword, expanding to nothing when "inline" is not
  591. available.
  592. */
  593. #ifdef SCM_C_INLINE
  594. #define SCM_C_INLINE_KEYWORD SCM_C_INLINE
  595. #else
  596. #define SCM_C_INLINE_KEYWORD
  597. #endif
  598. /* Handling thread-local storage (TLS). */
  599. #ifdef SCM_HAVE_THREAD_STORAGE_CLASS
  600. # define SCM_THREAD_LOCAL __thread
  601. #else
  602. # define SCM_THREAD_LOCAL
  603. #endif
  604. #endif /* SCM___SCM_H */
  605. /*
  606. Local Variables:
  607. c-file-style: "gnu"
  608. End:
  609. */