* *.[hc]: add Emacs magic at the end of file, to ensure GNU
[bpt/guile.git] / libguile / __scm.h
CommitLineData
0f2d19dd
JB
1/* classes: h_files */
2
3#ifndef __SCMH
4#define __SCMH
cd911565 5/* Copyright (C) 1995, 1996, 1998, 1999, 2000 Free Software Foundation, Inc.
0f2d19dd
JB
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this software; see the file COPYING. If not, write to
82892bed
JB
19 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307 USA
0f2d19dd
JB
21 *
22 * As a special exception, the Free Software Foundation gives permission
23 * for additional uses of the text contained in its release of GUILE.
24 *
25 * The exception is that, if you link the GUILE library with other files
26 * to produce an executable, this does not by itself cause the
27 * resulting executable to be covered by the GNU General Public License.
28 * Your use of that executable is in no way restricted on account of
29 * linking the GUILE library code into it.
30 *
31 * This exception does not however invalidate any other reasons why
32 * the executable file might be covered by the GNU General Public License.
33 *
34 * This exception applies only to the code released by the
35 * Free Software Foundation under the name GUILE. If you copy
36 * code from other Free Software Foundation releases into a copy of
37 * GUILE, as the General Public License permits, the exception does
38 * not apply to the code that you add in this way. To avoid misleading
39 * anyone as to the status of such modified files, you must delete
40 * this exception notice from them.
41 *
42 * If you write modifications of your own for GUILE, it is your choice
43 * whether to permit this exception to apply to your modifications.
82892bed 44 * If you do not wish that, delete this exception notice. */
0f2d19dd 45\f
176067df
JB
46
47/* "What's the difference between _scm.h and __scm.h?"
48
49 _scm.h is not installed; it's only visible to the libguile sources
50 themselves.
51
52 __scm.h is installed, and is #included by <libguile.h>. If both
53 the client and libguile need some piece of information, and it
54 doesn't fit well into the header file for any particular module, it
55 should go in __scm.h. */
56
57
0f2d19dd
JB
58/* {Supported Options}
59 *
60 * These may be defined or undefined.
61 */
62
83c4c29d 63/* New scheme for garbage collection */
d2f51eaf 64#define GUILE_NEW_GC_SCHEME
83c4c29d 65
16d35552 66/* #define GUILE_DEBUG_FREELIST */
70d63753 67
cf7c17e9 68/* If the compile FLAG `SCM_CAUTIOUS' is #defined then the number of
0f2d19dd 69 * arguments is always checked for application of closures. If the
cf7c17e9 70 * compile FLAG `SCM_RECKLESS' is #defined then they are not checked.
0f2d19dd
JB
71 * Otherwise, number of argument checks for closures are made only when
72 * the function position (whose value is the closure) of a combination is
73 * not an ILOC or GLOC. When the function position of a combination is a
74 * symbol it will be checked only the first time it is evaluated because
75 * it will then be replaced with an ILOC or GLOC.
76 */
cf7c17e9
JB
77#undef SCM_RECKLESS
78#define SCM_CAUTIOUS
0f2d19dd
JB
79
80/* After looking up a local for the first time, rewrite the
81 * code graph, caching its position.
82 */
83#define MEMOIZE_LOCALS
84
85/* All the number support there is.
86 */
0f2d19dd
JB
87#define BIGNUMS
88
89/* GC should relinquish empty cons-pair arenas.
90 */
d2f51eaf 91#ifndef GUILE_NEW_GC_SCHEME
0f2d19dd 92#define GC_FREE_SEGMENTS
d2f51eaf 93#endif
0f2d19dd
JB
94
95/* Provide a scheme-accessible count-down timer that
96 * generates a pseudo-interrupt.
97 */
98#define TICKS
99
100
101/* Use engineering notation when converting numbers strings?
102 */
103#undef ENGNOT
104
0f2d19dd
JB
105#undef SCM_CAREFUL_INTS
106\f
107/* {Unsupported Options}
108 *
3c205827 109 * These must be defined as given here.
0f2d19dd
JB
110 */
111
112
113#define CCLO
3c205827
JB
114
115/* Guile Scheme supports the #f/() distinction; Guile Lisp won't. We
116 have horrible plans for their unification. */
117#undef SICP
0f2d19dd
JB
118
119\f
120
80c78696 121/* Random options (not yet supported or in final form). */
0f2d19dd 122
80c78696
MD
123#define STACK_CHECKING
124#undef NO_CEVAL_STACK_CHECKING
0f2d19dd 125
43ff3170
GH
126\f
127/* What did the configure script discover about the outside world? */
128#include "libguile/scmconfig.h"
129
130#ifdef HAVE_LONG_LONGS
131
0f2d19dd
JB
132/* Some auto-generated .h files contain unused prototypes
133 * that need these typedefs.
134 */
afe5177e
GH
135typedef long long long_long;
136typedef unsigned long long ulong_long;
0f2d19dd 137
43ff3170 138#endif /* HAVE_LONG_LONGS */
b971d089
JB
139
140\f
0f2d19dd
JB
141
142/* Define
143 *
e2806c10 144 * SCM_CHAR_CODE_LIMIT == UCHAR_MAX + 1
0f2d19dd
JB
145 * SCM_MOST_POSITIVE_FIXNUM (LONG_MAX>>2)
146 * SCM_MOST_NEGATIVE_FIXNUM == SCM_SRS((long)LONG_MIN, 2)
147 */
148
b971d089 149#ifdef HAVE_LIMITS_H
0f2d19dd
JB
150# include <limits.h>
151# ifdef UCHAR_MAX
e2806c10 152# define SCM_CHAR_CODE_LIMIT (UCHAR_MAX+1L)
0f2d19dd 153# else
e2806c10 154# define SCM_CHAR_CODE_LIMIT 256L
0f2d19dd
JB
155# endif /* def UCHAR_MAX */
156# define SCM_MOST_POSITIVE_FIXNUM (LONG_MAX>>2)
157# ifdef _UNICOS /* Stupid cray bug */
158# define SCM_MOST_NEGATIVE_FIXNUM ((long)LONG_MIN/4)
159# else
160# define SCM_MOST_NEGATIVE_FIXNUM SCM_SRS((long)LONG_MIN, 2)
161# endif /* UNICOS */
162#else
e2806c10 163# define SCM_CHAR_CODE_LIMIT 256L
0f2d19dd
JB
164# define SCM_MOST_POSITIVE_FIXNUM ((long)((unsigned long)~0L>>3))
165# if (0 != ~0)
166# define SCM_MOST_NEGATIVE_FIXNUM (-SCM_MOST_POSITIVE_FIXNUM-1)
167# else
168# define SCM_MOST_NEGATIVE_FIXNUM (-SCM_MOST_POSITIVE_FIXNUM)
169# endif /* (0 != ~0) */
b971d089 170#endif /* def HAVE_LIMITS_H */
0f2d19dd
JB
171\f
172
2a1d8241
JB
173#ifdef STDC_HEADERS
174# include <stdlib.h>
175# ifdef AMIGA
176# include <stddef.h>
177# endif /* def AMIGA */
178# define scm_sizet size_t
179#else
180# ifdef _SIZE_T
181# define scm_sizet size_t
182# else
183# define scm_sizet unsigned int
184# endif /* def _SIZE_T */
185#endif /* def STDC_HEADERS */
186
187\f
188
189#include "libguile/tags.h"
0f2d19dd
JB
190
191\f
192#ifdef vms
193# ifndef CHEAP_CONTINUATIONS
194 typedef int jmp_buf[17];
195 extern int setjump(jmp_buf env);
196 extern int longjump(jmp_buf env, int ret);
197# define setjmp setjump
198# define longjmp longjump
199# else
200# include <setjmp.h>
201# endif
202#else /* ndef vms */
203# ifdef _CRAY1
204 typedef int jmp_buf[112];
205 extern int setjump(jmp_buf env);
206 extern int longjump(jmp_buf env, int ret);
207# define setjmp setjump
208# define longjmp longjump
209# else /* ndef _CRAY1 */
210# include <setjmp.h>
211# endif /* ndef _CRAY1 */
212#endif /* ndef vms */
213
0f2d19dd
JB
214/* James Clark came up with this neat one instruction fix for
215 * continuations on the SPARC. It flushes the register windows so
216 * that all the state of the process is contained in the stack.
217 */
218
219#ifdef sparc
220# define SCM_FLUSH_REGISTER_WINDOWS asm("ta 3")
221#else
222# define SCM_FLUSH_REGISTER_WINDOWS /* empty */
223#endif
224
225/* If stack is not longword aligned then
226 */
227
228/* #define SHORT_ALIGN */
229#ifdef THINK_C
230# define SHORT_ALIGN
231#endif
232#ifdef MSDOS
233# define SHORT_ALIGN
234#endif
235#ifdef atarist
236# define SHORT_ALIGN
237#endif
238
239#ifdef SHORT_ALIGN
240typedef short SCM_STACKITEM;
241#else
242typedef long SCM_STACKITEM;
243#endif
244\f
245
82339094 246#ifndef USE_THREADS
25d3ee9d
MD
247#define SCM_THREAD_DEFER
248#define SCM_THREAD_ALLOW
249#define SCM_THREAD_REDEFER
25d3ee9d 250#define SCM_THREAD_SWITCHING_CODE
82339094
MD
251#endif
252
0f2d19dd 253extern unsigned int scm_async_clock;
82339094 254
25d3ee9d 255#define SCM_ASYNC_TICK \
bfc69694 256do { \
25d3ee9d
MD
257 if (0 == --scm_async_clock) \
258 scm_async_click (); \
bfc69694 259} while(0)
25d3ee9d 260
0f2d19dd
JB
261#ifdef SCM_CAREFUL_INTS
262#define SCM_CHECK_NOT_DISABLED \
263 if (scm_ints_disabled) \
264 fputs("ints already disabled\n", stderr); \
265
266#define SCM_CHECK_NOT_ENABLED \
267 if (!scm_ints_disabled) \
268 fputs("ints already enabled\n", stderr); \
269
270#else
271#define SCM_CHECK_NOT_DISABLED
272#define SCM_CHECK_NOT_ENABLED
273#endif
274
275
8417b665
JB
276/* Anthony Green writes:
277 When the compiler sees...
278 DEFER_INTS;
279 [critical code here]
280 ALLOW_INTS;
281 ...it doesn't actually promise to keep the critical code within the
282 boundries of the DEFER/ALLOW_INTS instructions. It may very well
283 schedule it outside of the magic defined in those macros.
284
285 However, GCC's volatile asm feature forms a barrier over which code is
286 never moved. So if you add...
35eec738
JB
287 asm ("");
288 ...to each of the DEFER_INTS and ALLOW_INTS macros, the critical
289 code will always remain in place. asm's without inputs or outputs
290 are implicitly volatile. */
8417b665 291#ifdef __GNUC__
35eec738 292#define SCM_FENCE asm /* volatile */ ("")
8417b665
JB
293#else
294#define SCM_FENCE
295#endif
296
0f2d19dd 297#define SCM_DEFER_INTS \
bfc69694 298do { \
8417b665 299 SCM_FENCE; \
0f2d19dd 300 SCM_CHECK_NOT_DISABLED; \
25d3ee9d 301 SCM_THREAD_DEFER; \
8417b665 302 SCM_FENCE; \
0f2d19dd 303 scm_ints_disabled = 1; \
8417b665 304 SCM_FENCE; \
bfc69694 305} while (0)
0f2d19dd
JB
306
307
308#define SCM_ALLOW_INTS_ONLY \
bfc69694 309do { \
25d3ee9d 310 SCM_THREAD_ALLOW; \
0f2d19dd 311 scm_ints_disabled = 0; \
bfc69694 312} while (0)
0f2d19dd
JB
313
314
315#define SCM_ALLOW_INTS \
bfc69694 316do { \
8417b665 317 SCM_FENCE; \
0f2d19dd 318 SCM_CHECK_NOT_ENABLED; \
c72cc5fb
MD
319 SCM_THREAD_SWITCHING_CODE; \
320 SCM_FENCE; \
0f2d19dd 321 scm_ints_disabled = 0; \
8417b665
JB
322 SCM_FENCE; \
323 SCM_THREAD_ALLOW; \
8417b665 324 SCM_FENCE; \
bfc69694 325} while (0)
0f2d19dd
JB
326
327
328#define SCM_REDEFER_INTS \
bfc69694 329do { \
c72cc5fb 330 SCM_FENCE; \
25d3ee9d 331 SCM_THREAD_REDEFER; \
0f2d19dd 332 ++scm_ints_disabled; \
c72cc5fb 333 SCM_FENCE; \
bfc69694 334} while (0)
0f2d19dd
JB
335
336
337#define SCM_REALLOW_INTS \
bfc69694 338do { \
c72cc5fb 339 SCM_FENCE; \
c72cc5fb
MD
340 SCM_THREAD_SWITCHING_CODE; \
341 SCM_FENCE; \
0f2d19dd 342 --scm_ints_disabled; \
c72cc5fb 343 SCM_FENCE; \
bfc69694 344} while (0)
0f2d19dd
JB
345
346
c72cc5fb 347#define SCM_TICK \
bfc69694 348do { \
c72cc5fb
MD
349 SCM_DEFER_INTS; \
350 SCM_ALLOW_INTS; \
cd911565 351 SCM_ASYNC_TICK; \
bfc69694 352} while (0)
0f2d19dd
JB
353
354\f
355
f83e2737
MD
356/* Classification of critical sections
357 *
358 * When Guile moves to POSIX threads, it won't be possible to prevent
359 * context switching. In fact, the whole idea of context switching is
360 * bogus if threads are run by different processors. Therefore, we
361 * must ultimately eliminate all critical sections or enforce them by
362 * use of mutecis.
363 *
364 * All instances of SCM_DEFER_INTS and SCM_ALLOW_INTS should therefore
365 * be classified and replaced by one of the delimiters below. If you
366 * understand what this is all about, I'd like to encourage you to
367 * help with this task. The set of classes below must of course be
368 * incrementally augmented.
369 *
370 * MDJ 980419 <djurfeldt@nada.kth.se>
371 */
372
373/* A sections
374 *
375 * Allocation of a cell with type tag in the CAR.
376 *
377 * With POSIX threads, each thread will have a private pool of free
378 * cells. Therefore, this type of section can be removed. But! It
379 * is important that the CDR is initialized first (with the CAR still
380 * indicating a free cell) so that we can guarantee a consistent heap
381 * at all times.
382 */
383
384#ifdef SCM_POSIX_THREADS
385#define SCM_ENTER_A_SECTION
386#define SCM_EXIT_A_SECTION
387#else
388#define SCM_ENTER_A_SECTION SCM_DEFER_INTS
389#define SCM_EXIT_A_SECTION SCM_ALLOW_INTS
390#endif
391
392\f
393
0f2d19dd
JB
394/** SCM_ASSERT
395 **
396 **/
397
398
399#ifdef SCM_RECKLESS
400#define SCM_ASSERT(_cond, _arg, _pos, _subr)
b6791b2e 401#define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr)
0f2d19dd
JB
402#define SCM_ASRTGO(_cond, _label)
403#else
404#define SCM_ASSERT(_cond, _arg, _pos, _subr) \
405 if (!(_cond)) \
406 scm_wta(_arg, (char *)(_pos), _subr)
b6791b2e
GB
407#define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr, _msg) \
408 if (!(_cond)) \
409 scm_wrong_type_arg_msg(_subr, _pos, _arg, _msg)
0f2d19dd
JB
410#define SCM_ASRTGO(_cond, _label) \
411 if (!(_cond)) \
412 goto _label
413#endif
95b88819 414
9de33deb
MD
415/*
416 * SCM_WTA_DISPATCH
417 */
418
b3c8a0f5
MD
419extern SCM scm_call_generic_0 (SCM gf);
420
421#define SCM_WTA_DISPATCH_0(gf, arg, pos, subr) \
422 return ((gf) \
423 ? scm_call_generic_0 ((gf)) \
424 : scm_wta ((arg), (char *) (pos), (subr)))
425#define SCM_GASSERT0(cond, gf, arg, pos, subr) \
ff725a17 426 if (!(cond)) SCM_WTA_DISPATCH_0((gf), (arg), (pos), (subr))
b3c8a0f5 427
9de33deb
MD
428extern SCM scm_call_generic_1 (SCM gf, SCM a1);
429
430#define SCM_WTA_DISPATCH_1(gf, a1, pos, subr) \
431 return ((gf) \
432 ? scm_call_generic_1 ((gf), (a1)) \
433 : scm_wta ((a1), (char *) (pos), (subr)))
434#define SCM_GASSERT1(cond, gf, a1, pos, subr) \
435 if (!(cond)) SCM_WTA_DISPATCH_1((gf), (a1), (pos), (subr))
436
437extern SCM scm_call_generic_2 (SCM gf, SCM a1, SCM a2);
438
439#define SCM_WTA_DISPATCH_2(gf, a1, a2, pos, subr) \
440 return ((gf) \
441 ? scm_call_generic_2 ((gf), (a1), (a2)) \
442 : scm_wta ((pos) == SCM_ARG1 ? (a1) : (a2), (char *) (pos), (subr)))
443#define SCM_GASSERT2(cond, gf, a1, a2, pos, subr) \
444 if (!(cond)) SCM_WTA_DISPATCH_2((gf), (a1), (a2), (pos), (subr))
445
89c358b1
MD
446extern SCM scm_apply_generic (SCM gf, SCM args);
447
448#define SCM_WTA_DISPATCH_n(gf, args, pos, subr) \
449 return ((gf) \
450 ? scm_apply_generic ((gf), (args)) \
451 : scm_wta (scm_list_ref ((args), SCM_MAKINUM ((pos) - 1)), \
452 (char *) (pos), \
453 (subr)))
454#define SCM_GASSERTn(cond, gf, args, pos, subr) \
455 if (!(cond)) SCM_WTA_DISPATCH_n((gf), (args), (pos), (subr))
456
c751e5e3
GB
457#ifndef SCM_MAGIC_SNARFER
458/* Let these macros pass through if
459 we are snarfing; thus we can tell the
460 difference between the use of an actual
461 number vs. the use of one of these macros --
f5421cfc 462 actual numbers in SCM_VALIDATE_* and SCM_ASSERT
c751e5e3
GB
463 constructs must match the formal argument name,
464 but using SCM_ARG* avoids the test */
465
0f2d19dd
JB
466#define SCM_ARGn 0
467#define SCM_ARG1 1
468#define SCM_ARG2 2
469#define SCM_ARG3 3
470#define SCM_ARG4 4
471#define SCM_ARG5 5
1146b6cd
GH
472#define SCM_ARG6 6
473#define SCM_ARG7 7
f5bf2977 474 /* #define SCM_ARGERR(X) ((X) < SCM_WNA \
0f2d19dd
JB
475 ? (char *)(X) \
476 : "wrong type argument")
f5bf2977 477 */
0f2d19dd
JB
478
479/* Following must match entry indexes in scm_errmsgs[].
480 * Also, SCM_WNA must follow the last SCM_ARGn in sequence.
481 */
482#define SCM_WNA 8
e1724d20 483 /* #define SCM_OVSCM_FLOW 9 */
0f2d19dd
JB
484#define SCM_OUTOFRANGE 10
485#define SCM_NALLOC 11
f5bf2977
GH
486 /* #define SCM_STACK_OVFLOW 12 */
487 /* #define SCM_EXIT 13 */
0f2d19dd 488
c751e5e3 489#endif /* SCM_MAGIC_SNARFER */
0f2d19dd
JB
490
491/* (...still matching scm_errmsgs) These
492 * are signals. Signals may become errors
493 * but are distinguished because they first
494 * try to invoke a handler that can resume
495 * the interrupted routine.
496 */
497#define SCM_HUP_SIGNAL 14
498#define SCM_INT_SIGNAL 15
499#define SCM_FPE_SIGNAL 16
500#define SCM_BUS_SIGNAL 17
501#define SCM_SEGV_SIGNAL 18
502#define SCM_ALRM_SIGNAL 19
503#define SCM_GC_SIGNAL 20
504#define SCM_TICK_SIGNAL 21
505
506#define SCM_SIG_ORD(X) ((X) - SCM_HUP_SIGNAL)
507#define SCM_ORD_SIG(X) ((X) + SCM_HUP_SIGNAL)
508#define SCM_NUM_SIGS (SCM_SIG_ORD (SCM_TICK_SIGNAL) + 1)
509
82339094 510#if 0
0f2d19dd
JB
511struct errdesc
512{
513 char *msg;
514 char *s_response;
515 short parent_err;
516};
517
518
519extern struct errdesc scm_errmsgs[];
82339094 520#endif
0f2d19dd
JB
521
522\f
523
524/* SCM_EXIT_SUCCESS is the default code to return from SCM if no errors
525 * were encountered. SCM_EXIT_FAILURE is the default code to return from
526 * SCM if errors were encountered. The return code can be explicitly
527 * specified in a SCM program with (scm_quit <n>).
528 */
529
530#ifndef SCM_EXIT_SUCCESS
531#ifdef vms
532#define SCM_EXIT_SUCCESS 1
533#else
534#define SCM_EXIT_SUCCESS 0
535#endif /* def vms */
536#endif /* ndef SCM_EXIT_SUCCESS */
537#ifndef SCM_EXIT_FAILURE
538#ifdef vms
539#define SCM_EXIT_FAILURE 2
540#else
541#define SCM_EXIT_FAILURE 1
542#endif /* def vms */
543#endif /* ndef SCM_EXIT_FAILURE */
544
545
546
547\f
0f2d19dd
JB
548
549#endif /* __SCMH */
89e00824
ML
550
551/*
552 Local Variables:
553 c-file-style: "gnu"
554 End:
555*/