__scm.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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, 2007, 2008, 2009 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 License
  8. * as published by the Free Software Foundation; either version 3 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful, but
  12. * 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
  19. * 02110-1301 USA
  20. */
  21. /**********************************************************************
  22. This file is Guile's central public header.
  23. When included by other files, this file should preceed any include
  24. other than __scm.h.
  25. Under *NO* circumstances should new items be added to the global
  26. namespace (via adding #define, typedef, or similar to this file) with
  27. generic names. This usually means that any new names should be
  28. prefixed by either SCM_ or GUILE_. i.e. do *not* #define HAVE_FOO or
  29. SIZEOF_BAR. See configure.in, gen-scmconfig.h.in, and
  30. gen-scmconfig.c for examples of how to properly handle this issue.
  31. The main documentation is in gen-scmconfig.c.
  32. "What's the difference between _scm.h and __scm.h?"
  33. _scm.h is not installed; it's only visible to the libguile sources
  34. themselves, and it includes config.h, the private config header.
  35. __scm.h is installed, and is #included by <libguile.h>. If both
  36. the client and libguile need some piece of information, and it
  37. doesn't fit well into the header file for any particular module, it
  38. should go in __scm.h. __scm.h includes scmconfig.h, the public
  39. config header.
  40. **********************************************************************/
  41. /* What did the configure script discover about the outside world? */
  42. #include "libguile/scmconfig.h"
  43. /* {Compiler hints}
  44. *
  45. * The following macros are used to provide additional information for the
  46. * compiler, which may help to do better error checking and code
  47. * optimization. A second benefit of these macros is, that they also provide
  48. * additional information to the developers.
  49. */
  50. /* The macro SCM_NORETURN indicates that a function will never return.
  51. * Examples:
  52. * 1) int foo (char arg) SCM_NORETURN;
  53. */
  54. #ifdef __GNUC__
  55. #define SCM_NORETURN __attribute__ ((noreturn))
  56. #else
  57. #define SCM_NORETURN
  58. #endif
  59. /* The macro SCM_UNUSED indicates that a function, function argument or
  60. * variable may potentially be unused.
  61. * Examples:
  62. * 1) static int unused_function (char arg) SCM_UNUSED;
  63. * 2) int foo (char unused_argument SCM_UNUSED);
  64. * 3) int unused_variable SCM_UNUSED;
  65. */
  66. #ifdef __GNUC__
  67. #define SCM_UNUSED __attribute__ ((unused))
  68. #else
  69. #define SCM_UNUSED
  70. #endif
  71. /* The SCM_EXPECT macros provide branch prediction hints to the compiler. To
  72. * use only in places where the result of the expression under "normal"
  73. * circumstances is known. */
  74. #if defined(__GNUC__) && (__GNUC__ >= 3)
  75. # define SCM_EXPECT __builtin_expect
  76. #else
  77. # define SCM_EXPECT(_expr, _value) (_expr)
  78. #endif
  79. #define SCM_LIKELY(_expr) SCM_EXPECT ((_expr), 1)
  80. #define SCM_UNLIKELY(_expr) SCM_EXPECT ((_expr), 0)
  81. /* The SCM_INTERNAL macro makes it possible to explicitly declare a function
  82. * as having "internal" linkage. However our current tack on this problem is
  83. * to use GCC 4's -fvisibility=hidden, making functions internal by default,
  84. * and then SCM_API marks them for export. */
  85. #define SCM_INTERNAL extern
  86. /* {Supported Options}
  87. *
  88. * These may be defined or undefined.
  89. */
  90. /* #define GUILE_DEBUG_FREELIST */
  91. /* All the number support there is.
  92. */
  93. #define BIGNUMS
  94. /* GC should relinquish empty cons-pair arenas. */
  95. /* cmm:FIXME look at this after done mangling the GC */
  96. /* #define GC_FREE_SEGMENTS */
  97. /* Provide a scheme-accessible count-down timer that
  98. * generates a pseudo-interrupt.
  99. */
  100. #define TICKS
  101. /* Use engineering notation when converting numbers strings?
  102. */
  103. #undef ENGNOT
  104. /* {Unsupported Options}
  105. *
  106. * These must be defined as given here.
  107. */
  108. /* Guile Scheme supports the #f/() distinction; Guile Lisp won't. We
  109. have horrible plans for their unification. */
  110. #undef SICP
  111. /* Random options (not yet supported or in final form). */
  112. #define STACK_CHECKING
  113. #undef NO_CEVAL_STACK_CHECKING
  114. /* SCM_API is a macro prepended to all function and data definitions
  115. which should be exported from libguile. */
  116. #if BUILDING_LIBGUILE && HAVE_VISIBILITY
  117. # define SCM_API extern __attribute__((__visibility__("default")))
  118. #elif BUILDING_LIBGUILE && defined _MSC_VER
  119. # define SCM_API __declspec(dllexport) extern
  120. #elif defined _MSC_VER
  121. # define SCM_API __declspec(dllimport) extern
  122. #else
  123. # define SCM_API extern
  124. #endif
  125. /* {Debugging Options}
  126. *
  127. * These compile time options determine whether to include code that is only
  128. * useful for debugging guile itself or C level extensions to guile. The
  129. * common prefix for all option macros of this kind is "SCM_DEBUG_". It is
  130. * guaranteed that a macro named SCM_DEBUG_XXX is always defined (typically to
  131. * either 0 or 1), i. e. there is no need to test for the undefined case.
  132. * This allows to use these definitions comfortably within code, as in the
  133. * following example:
  134. * #define FOO do { if (SCM_DEBUG_XXX) bar(); else baz(); } while (0)
  135. * Any sane compiler will remove the unused branch without any performance
  136. * penalty for the resulting code.
  137. *
  138. * Note: Some SCM_DEBUG_XXX options are not settable at configure time.
  139. * To change the value of such options you will have to edit this header
  140. * file or give suitable options to make, like:
  141. * make all CFLAGS="-DSCM_DEBUG_XXX=1 ..."
  142. */
  143. /* The value of SCM_DEBUG determines the default for most of the not yet
  144. * defined debugging options. This allows, for example, to enable most of the
  145. * debugging options by simply defining SCM_DEBUG as 1.
  146. */
  147. #ifndef SCM_DEBUG
  148. #define SCM_DEBUG 0
  149. #endif
  150. /* For debugging purposes: define this is to ensure nobody is using
  151. * the mark bits outside of the marking phase. This is meant for
  152. * debugging purposes only.
  153. */
  154. #ifndef SCM_DEBUG_MARKING_API
  155. #define SCM_DEBUG_MARKING_API 0
  156. #endif
  157. /* If SCM_DEBUG_CELL_ACCESSES is set to 1, cell accesses will perform
  158. * exhaustive parameter checking: It will be verified that cell parameters
  159. * actually point to a valid heap cell. Note: If this option is enabled,
  160. * guile will run about ten times slower than normally.
  161. */
  162. #ifndef SCM_DEBUG_CELL_ACCESSES
  163. #define SCM_DEBUG_CELL_ACCESSES SCM_DEBUG
  164. #endif
  165. /* If SCM_DEBUG_INTERRUPTS is set to 1, with every deferring and allowing of
  166. * interrupts a consistency check will be performed.
  167. */
  168. #ifndef SCM_DEBUG_INTERRUPTS
  169. #define SCM_DEBUG_INTERRUPTS SCM_DEBUG
  170. #endif
  171. /* If SCM_DEBUG_PAIR_ACCESSES is set to 1, accesses to cons cells will be
  172. * exhaustively checked. Note: If this option is enabled, guile will run
  173. * slower than normally.
  174. */
  175. #ifndef SCM_DEBUG_PAIR_ACCESSES
  176. #define SCM_DEBUG_PAIR_ACCESSES SCM_DEBUG
  177. #endif
  178. /* If SCM_DEBUG_REST_ARGUMENT is set to 1, functions that take rest arguments
  179. * will check whether the rest arguments are actually passed as a proper list.
  180. * Otherwise, if SCM_DEBUG_REST_ARGUMENT is 0, functions that take rest
  181. * arguments will take it for granted that these are passed as a proper list.
  182. */
  183. #ifndef SCM_DEBUG_REST_ARGUMENT
  184. #define SCM_DEBUG_REST_ARGUMENT SCM_DEBUG
  185. #endif
  186. /* The macro SCM_DEBUG_TYPING_STRICTNESS indicates what level of type checking
  187. * shall be performed with respect to the use of the SCM datatype. The macro
  188. * may be defined to one of the values 0, 1 and 2.
  189. *
  190. * A value of 0 means that there will be no compile time type checking, since
  191. * the SCM datatype will be declared as an integral type. This setting should
  192. * only be used on systems, where casting from integral types to pointers may
  193. * lead to loss of bit information.
  194. *
  195. * A value of 1 means that there will an intermediate level of compile time
  196. * type checking, since the SCM datatype will be declared as a pointer to an
  197. * undefined struct. This setting is the default, since it does not cost
  198. * anything in terms of performance or code size.
  199. *
  200. * A value of 2 provides a maximum level of compile time type checking since
  201. * the SCM datatype will be declared as a struct. This setting should be used
  202. * for _compile time_ type checking only, since the compiled result is likely
  203. * to be quite inefficient. The right way to make use of this option is to do
  204. * a 'make clean; make CFLAGS=-DSCM_DEBUG_TYPING_STRICTNESS=2', fix your
  205. * errors, and then do 'make clean; make'.
  206. */
  207. #ifndef SCM_DEBUG_TYPING_STRICTNESS
  208. #define SCM_DEBUG_TYPING_STRICTNESS 1
  209. #endif
  210. /* If SCM_DEBUG_DEBUGGING_SUPPORT is set to 1, guile will provide a set of
  211. * special functions that support debugging with a debugger like gdb or
  212. * debugging of guile internals on the scheme level. The behaviour of guile
  213. * is not changed by this macro, only the set of functions that are available
  214. * will differ. All functions that are introduced this way have the prefix
  215. * 'scm_dbg_' on the C level and the prefix 'dbg-' on the scheme level. This
  216. * allows to easily determine the set of support functions, given that your
  217. * debugger or repl provide automatic name completion. Note that these
  218. * functions are intended to be used during interactive debugging sessions
  219. * only. They are not considered part of guile's official API. They may
  220. * change or disappear without notice or deprecation phase.
  221. */
  222. #ifndef SCM_DEBUG_DEBUGGING_SUPPORT
  223. #define SCM_DEBUG_DEBUGGING_SUPPORT SCM_DEBUG
  224. #endif
  225. /* {Feature Options}
  226. *
  227. * These compile time options determine whether code for certain features
  228. * should be compiled into guile. The common prefix for all option macros
  229. * of this kind is "SCM_ENABLE_". It is guaranteed that a macro named
  230. * SCM_ENABLE_XXX is defined to be either 0 or 1, i. e. there is no need to
  231. * test for the undefined case. This allows to use these definitions
  232. * comfortably within code, as in the following example:
  233. * #define FOO do { if (SCM_ENABLE_XXX) bar(); else baz(); } while (0)
  234. * Any sane compiler will remove the unused branch without any performance
  235. * penalty for the resulting code.
  236. *
  237. * Note: Some SCM_ENABLE_XXX options are not settable at configure time.
  238. * To change the value of such options you will have to edit this header
  239. * file or give suitable options to make, like:
  240. * make all CFLAGS="-DSCM_ENABLE_XXX=1 ..."
  241. */
  242. /* If SCM_ENABLE_DEPRECATED is set to 1, deprecated code will be included in
  243. * guile, as well as some functions to issue run-time warnings about uses of
  244. * deprecated functions.
  245. */
  246. #ifndef SCM_ENABLE_DEPRECATED
  247. #define SCM_ENABLE_DEPRECATED 0
  248. #endif
  249. /* {Architecture and compiler properties}
  250. *
  251. * Guile as of today can only work on systems which fulfill at least the
  252. * following requirements:
  253. *
  254. * - scm_t_bits and SCM variables have at least 32 bits.
  255. * Guile's type system is based on this assumption.
  256. *
  257. * - sizeof (scm_t_bits) >= sizeof (void*) and sizeof (SCM) >= sizeof (void*)
  258. * Guile's type system is based on this assumption, since it must be
  259. * possible to store pointers to cells on the heap in scm_t_bits and SCM
  260. * variables.
  261. *
  262. * - sizeof (scm_t_bits) >= 4 and sizeof (scm_t_bits) is a power of 2.
  263. * Guile's type system is based on this assumption. In particular, it is
  264. * assumed that cells, i. e. pairs of scm_t_bits variables, are eight
  265. * character aligned. This is because three bits of a scm_t_bits variable
  266. * that is holding a pointer to a cell on the heap must be available for
  267. * storing type data.
  268. *
  269. * - sizeof (scm_t_bits) <= sizeof (void*) and sizeof (SCM) <= sizeof (void*)
  270. * In some parts of guile, scm_t_bits and SCM variables are passed to
  271. * functions as void* arguments. Together with the requirement above, this
  272. * requires a one-to-one correspondence between the size of a void* and the
  273. * sizes of scm_t_bits and SCM variables.
  274. *
  275. * - numbers are encoded using two's complement.
  276. * The implementation of the bitwise scheme level operations is based on
  277. * this assumption.
  278. *
  279. * - ... add more
  280. */
  281. #ifdef CHAR_BIT
  282. # define SCM_CHAR_BIT CHAR_BIT
  283. #else
  284. # define SCM_CHAR_BIT 8
  285. #endif
  286. #ifdef LONG_BIT
  287. # define SCM_LONG_BIT LONG_BIT
  288. #else
  289. # define SCM_LONG_BIT (SCM_CHAR_BIT * sizeof (long) / sizeof (char))
  290. #endif
  291. #ifdef UCHAR_MAX
  292. # define SCM_CHAR_CODE_LIMIT (UCHAR_MAX + 1L)
  293. #else
  294. # define SCM_CHAR_CODE_LIMIT 256L
  295. #endif
  296. #define SCM_I_UTYPE_MAX(type) ((type)-1)
  297. #define SCM_I_TYPE_MAX(type,umax) ((type)((umax)/2))
  298. #define SCM_I_TYPE_MIN(type,umax) (-((type)((umax)/2))-1)
  299. #define SCM_T_UINT8_MAX SCM_I_UTYPE_MAX(scm_t_uint8)
  300. #define SCM_T_INT8_MIN SCM_I_TYPE_MIN(scm_t_int8,SCM_T_UINT8_MAX)
  301. #define SCM_T_INT8_MAX SCM_I_TYPE_MAX(scm_t_int8,SCM_T_UINT8_MAX)
  302. #define SCM_T_UINT16_MAX SCM_I_UTYPE_MAX(scm_t_uint16)
  303. #define SCM_T_INT16_MIN SCM_I_TYPE_MIN(scm_t_int16,SCM_T_UINT16_MAX)
  304. #define SCM_T_INT16_MAX SCM_I_TYPE_MAX(scm_t_int16,SCM_T_UINT16_MAX)
  305. #define SCM_T_UINT32_MAX SCM_I_UTYPE_MAX(scm_t_uint32)
  306. #define SCM_T_INT32_MIN SCM_I_TYPE_MIN(scm_t_int32,SCM_T_UINT32_MAX)
  307. #define SCM_T_INT32_MAX SCM_I_TYPE_MAX(scm_t_int32,SCM_T_UINT32_MAX)
  308. #if SCM_HAVE_T_INT64
  309. #define SCM_T_UINT64_MAX SCM_I_UTYPE_MAX(scm_t_uint64)
  310. #define SCM_T_INT64_MIN SCM_I_TYPE_MIN(scm_t_int64,SCM_T_UINT64_MAX)
  311. #define SCM_T_INT64_MAX SCM_I_TYPE_MAX(scm_t_int64,SCM_T_UINT64_MAX)
  312. #endif
  313. #if SCM_SIZEOF_LONG_LONG
  314. #define SCM_I_ULLONG_MAX SCM_I_UTYPE_MAX(unsigned long long)
  315. #define SCM_I_LLONG_MIN SCM_I_TYPE_MIN(long long,SCM_I_ULLONG_MAX)
  316. #define SCM_I_LLONG_MAX SCM_I_TYPE_MAX(long long,SCM_I_ULLONG_MAX)
  317. #endif
  318. #define SCM_T_UINTMAX_MAX SCM_I_UTYPE_MAX(scm_t_uintmax)
  319. #define SCM_T_INTMAX_MIN SCM_I_TYPE_MIN(scm_t_intmax,SCM_T_UINTMAX_MAX)
  320. #define SCM_T_INTMAX_MAX SCM_I_TYPE_MAX(scm_t_intmax,SCM_T_UINTMAX_MAX)
  321. #define SCM_I_SIZE_MAX SCM_I_UTYPE_MAX(size_t)
  322. #define SCM_I_SSIZE_MIN SCM_I_TYPE_MIN(ssize_t,SCM_I_SIZE_MAX)
  323. #define SCM_I_SSIZE_MAX SCM_I_TYPE_MAX(ssize_t,SCM_I_SIZE_MAX)
  324. #include "libguile/tags.h"
  325. #ifdef vms
  326. # ifndef CHEAP_CONTINUATIONS
  327. typedef int jmp_buf[17];
  328. extern int setjump(jmp_buf env);
  329. extern int longjump(jmp_buf env, int ret);
  330. # define setjmp setjump
  331. # define longjmp longjump
  332. # else
  333. # include <setjmp.h>
  334. # endif
  335. #else /* ndef vms */
  336. # ifdef _CRAY1
  337. typedef int jmp_buf[112];
  338. extern int setjump(jmp_buf env);
  339. extern int longjump(jmp_buf env, int ret);
  340. # define setjmp setjump
  341. # define longjmp longjump
  342. # else /* ndef _CRAY1 */
  343. # if defined (__ia64__)
  344. /* For IA64, emulate the setjmp API using getcontext. */
  345. # include <signal.h>
  346. # include <ucontext.h>
  347. typedef struct {
  348. ucontext_t ctx;
  349. int fresh;
  350. } jmp_buf;
  351. # define setjmp(JB) \
  352. ( (JB).fresh = 1, \
  353. getcontext (&((JB).ctx)), \
  354. ((JB).fresh ? ((JB).fresh = 0, 0) : 1) )
  355. # define longjmp(JB,VAL) scm_ia64_longjmp (&(JB), VAL)
  356. void scm_ia64_longjmp (jmp_buf *, int);
  357. # else /* ndef __ia64__ */
  358. # include <setjmp.h>
  359. # endif /* ndef __ia64__ */
  360. # endif /* ndef _CRAY1 */
  361. #endif /* ndef vms */
  362. /* James Clark came up with this neat one instruction fix for
  363. * continuations on the SPARC. It flushes the register windows so
  364. * that all the state of the process is contained in the stack.
  365. */
  366. #if defined (sparc) || defined (__sparc__) || defined (__sparc)
  367. # define SCM_FLUSH_REGISTER_WINDOWS asm("ta 3")
  368. #else
  369. # define SCM_FLUSH_REGISTER_WINDOWS /* empty */
  370. #endif
  371. /* If stack is not longword aligned then
  372. */
  373. /* #define SHORT_ALIGN */
  374. #ifdef THINK_C
  375. # define SHORT_ALIGN
  376. #endif
  377. #ifdef MSDOS
  378. # define SHORT_ALIGN
  379. #endif
  380. #ifdef atarist
  381. # define SHORT_ALIGN
  382. #endif
  383. #ifdef SHORT_ALIGN
  384. typedef short SCM_STACKITEM;
  385. #else
  386. typedef long SCM_STACKITEM;
  387. #endif
  388. /* Cast pointer through (void *) in order to avoid compiler warnings
  389. when strict aliasing is enabled */
  390. #define SCM_STACK_PTR(ptr) ((SCM_STACKITEM *) (void *) (ptr))
  391. #define SCM_ASYNC_TICK /*fixme* should change names */ \
  392. do { \
  393. if (SCM_I_CURRENT_THREAD->pending_asyncs) \
  394. scm_async_click (); \
  395. } while (0)
  396. /* Anthony Green writes:
  397. When the compiler sees...
  398. DEFER_INTS;
  399. [critical code here]
  400. ALLOW_INTS;
  401. ...it doesn't actually promise to keep the critical code within the
  402. boundries of the DEFER/ALLOW_INTS instructions. It may very well
  403. schedule it outside of the magic defined in those macros.
  404. However, GCC's volatile asm feature forms a barrier over which code is
  405. never moved. So if you add...
  406. asm ("");
  407. ...to each of the DEFER_INTS and ALLOW_INTS macros, the critical
  408. code will always remain in place. asm's without inputs or outputs
  409. are implicitly volatile. */
  410. #ifdef __GNUC__
  411. #define SCM_FENCE asm /* volatile */ ("")
  412. #elif defined (__INTEL_COMPILER) && defined (__ia64)
  413. #define SCM_FENCE __memory_barrier()
  414. #else
  415. #define SCM_FENCE
  416. #endif
  417. #define SCM_TICK \
  418. do { \
  419. SCM_ASYNC_TICK; \
  420. SCM_THREAD_SWITCHING_CODE; \
  421. } while (0)
  422. /** SCM_ASSERT
  423. **
  424. **/
  425. #ifdef SCM_RECKLESS
  426. #define SCM_ASSERT(_cond, _arg, _pos, _subr)
  427. #define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr, _msg)
  428. #define SCM_ASRTGO(_cond, _label)
  429. #else
  430. #define SCM_ASSERT(_cond, _arg, _pos, _subr) \
  431. do { if (SCM_UNLIKELY (!(_cond))) \
  432. scm_wrong_type_arg (_subr, _pos, _arg); } while (0)
  433. #define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr, _msg) \
  434. do { if (SCM_UNLIKELY (!(_cond))) \
  435. scm_wrong_type_arg_msg(_subr, _pos, _arg, _msg); } while (0)
  436. #define SCM_ASRTGO(_cond, _label) \
  437. do { if (SCM_UNLIKELY (!(_cond))) \
  438. goto _label; } while (0)
  439. #endif
  440. /*
  441. * SCM_WTA_DISPATCH
  442. */
  443. /* Dirk:FIXME:: In all of the SCM_WTA_DISPATCH_* macros it is assumed that
  444. * 'gf' is zero if uninitialized. It would be cleaner if some valid SCM value
  445. * like SCM_BOOL_F or SCM_UNDEFINED was chosen.
  446. */
  447. SCM_API SCM scm_call_generic_0 (SCM gf);
  448. #define SCM_WTA_DISPATCH_0(gf, subr) \
  449. return (SCM_UNPACK (gf) \
  450. ? scm_call_generic_0 ((gf)) \
  451. : (scm_error_num_args_subr ((subr)), SCM_UNSPECIFIED))
  452. #define SCM_GASSERT0(cond, gf, subr) \
  453. if (SCM_UNLIKELY(!(cond))) \
  454. SCM_WTA_DISPATCH_0((gf), (subr))
  455. SCM_API SCM scm_call_generic_1 (SCM gf, SCM a1);
  456. #define SCM_WTA_DISPATCH_1(gf, a1, pos, subr) \
  457. return (SCM_UNPACK (gf) \
  458. ? scm_call_generic_1 ((gf), (a1)) \
  459. : (scm_wrong_type_arg ((subr), (pos), (a1)), SCM_UNSPECIFIED))
  460. #define SCM_GASSERT1(cond, gf, a1, pos, subr) \
  461. if (SCM_UNLIKELY (!(cond))) \
  462. SCM_WTA_DISPATCH_1((gf), (a1), (pos), (subr))
  463. SCM_API SCM scm_call_generic_2 (SCM gf, SCM a1, SCM a2);
  464. #define SCM_WTA_DISPATCH_2(gf, a1, a2, pos, subr) \
  465. return (SCM_UNPACK (gf) \
  466. ? scm_call_generic_2 ((gf), (a1), (a2)) \
  467. : (scm_wrong_type_arg ((subr), (pos), \
  468. (pos) == SCM_ARG1 ? (a1) : (a2)), \
  469. SCM_UNSPECIFIED))
  470. #define SCM_GASSERT2(cond, gf, a1, a2, pos, subr) \
  471. if (SCM_UNLIKELY (!(cond))) \
  472. SCM_WTA_DISPATCH_2((gf), (a1), (a2), (pos), (subr))
  473. SCM_API SCM scm_apply_generic (SCM gf, SCM args);
  474. #define SCM_WTA_DISPATCH_n(gf, args, pos, subr) \
  475. return (SCM_UNPACK (gf) \
  476. ? scm_apply_generic ((gf), (args)) \
  477. : (scm_wrong_type_arg ((subr), (pos), \
  478. scm_list_ref ((args), \
  479. scm_from_int ((pos) - 1))), \
  480. SCM_UNSPECIFIED))
  481. #define SCM_GASSERTn(cond, gf, args, pos, subr) \
  482. if (SCM_UNLIKELY (!(cond))) \
  483. SCM_WTA_DISPATCH_n((gf), (args), (pos), (subr))
  484. #ifndef SCM_MAGIC_SNARFER
  485. /* Let these macros pass through if
  486. we are snarfing; thus we can tell the
  487. difference between the use of an actual
  488. number vs. the use of one of these macros --
  489. actual numbers in SCM_VALIDATE_* and SCM_ASSERT
  490. constructs must match the formal argument name,
  491. but using SCM_ARG* avoids the test */
  492. #define SCM_ARGn 0
  493. #define SCM_ARG1 1
  494. #define SCM_ARG2 2
  495. #define SCM_ARG3 3
  496. #define SCM_ARG4 4
  497. #define SCM_ARG5 5
  498. #define SCM_ARG6 6
  499. #define SCM_ARG7 7
  500. #endif /* SCM_MAGIC_SNARFER */
  501. /* SCM_EXIT_SUCCESS is the default code to return from SCM if no errors
  502. * were encountered. SCM_EXIT_FAILURE is the default code to return from
  503. * SCM if errors were encountered. The return code can be explicitly
  504. * specified in a SCM program with (scm_quit <n>).
  505. */
  506. #ifndef SCM_EXIT_SUCCESS
  507. #ifdef vms
  508. #define SCM_EXIT_SUCCESS 1
  509. #else
  510. #define SCM_EXIT_SUCCESS 0
  511. #endif /* def vms */
  512. #endif /* ndef SCM_EXIT_SUCCESS */
  513. #ifndef SCM_EXIT_FAILURE
  514. #ifdef vms
  515. #define SCM_EXIT_FAILURE 2
  516. #else
  517. #define SCM_EXIT_FAILURE 1
  518. #endif /* def vms */
  519. #endif /* ndef SCM_EXIT_FAILURE */
  520. /* Define SCM_C_INLINE_KEYWORD so that it can be used as a replacement
  521. for the "inline" keyword, expanding to nothing when "inline" is not
  522. available.
  523. */
  524. #ifdef SCM_C_INLINE
  525. #define SCM_C_INLINE_KEYWORD SCM_C_INLINE
  526. #else
  527. #define SCM_C_INLINE_KEYWORD
  528. #endif
  529. #endif /* SCM___SCM_H */
  530. /*
  531. Local Variables:
  532. c-file-style: "gnu"
  533. End:
  534. */