* gc.h (SCM_[SET_]CELL_{WORD,OBJECT}, SCM_VALIDATE_CELL): brought
[bpt/guile.git] / libguile / __scm.h
1 /* classes: h_files */
2
3 #ifndef __SCMH
4 #define __SCMH
5 /* Copyright (C) 1995, 1996, 1998, 1999, 2000 Free Software Foundation, Inc.
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
19 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307 USA
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.
44 * If you do not wish that, delete this exception notice. */
45 \f
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
58 /* {Supported Options}
59 *
60 * These may be defined or undefined.
61 */
62
63 /* Old async mechanism */
64 /* #define GUILE_OLD_ASYNC_CLICK */
65
66 /* #define GUILE_DEBUG_FREELIST */
67
68 /* If the compile FLAG `SCM_CAUTIOUS' is #defined then the number of
69 * arguments is always checked for application of closures. If the
70 * compile FLAG `SCM_RECKLESS' is #defined then they are not checked.
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 */
77 #undef SCM_RECKLESS
78 #define SCM_CAUTIOUS
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 */
87 #define BIGNUMS
88
89 /* GC should relinquish empty cons-pair arenas. */
90 /* cmm:FIXME look at this after done mangling the GC */
91 /* #define GC_FREE_SEGMENTS */
92
93 /* Provide a scheme-accessible count-down timer that
94 * generates a pseudo-interrupt.
95 */
96 #define TICKS
97
98
99 /* Use engineering notation when converting numbers strings?
100 */
101 #undef ENGNOT
102
103 #undef SCM_CAREFUL_INTS
104 \f
105 /* {Unsupported Options}
106 *
107 * These must be defined as given here.
108 */
109
110
111 #define CCLO
112
113 /* Guile Scheme supports the #f/() distinction; Guile Lisp won't. We
114 have horrible plans for their unification. */
115 #undef SICP
116
117 \f
118
119 /* Random options (not yet supported or in final form). */
120
121 #define STACK_CHECKING
122 #undef NO_CEVAL_STACK_CHECKING
123
124 \f
125
126 /* What did the configure script discover about the outside world? */
127 #include "libguile/scmconfig.h"
128
129 \f
130
131 /* {Debugging Options}
132 *
133 * These compile time options determine whether to include code that is only
134 * useful for debugging guile itself or C level extensions to guile. The
135 * common prefix for all option macros of this kind is "SCM_DEBUG_". It is
136 * guaranteed that a macro named SCM_DEBUG_XXX is defined to be either 0 or 1,
137 * i. e. there is no need to test for the undefined case. This allows to use
138 * these definitions comfortably in macro code, as in the following example:
139 * #define FOO do { if (SCM_DEBUG_XXX) bar(); else baz(); } while (0)
140 * Any sane compiler will remove the unused branch without any performance
141 * penalty for the resulting code.
142 *
143 * Note: Some SCM_DEBUG_XXX options are not settable at configure time.
144 * To change the value of such options you will have to edit this header
145 * file or give suitable options to make, like:
146 * make all CFLAGS="-DSCM_DEBUG_XXX=1 ..."
147 */
148
149
150 /* The value of SCM_DEBUG determines the default for most of the not yet
151 * defined debugging options. This allows, for example, to enable most of the
152 * debugging options by simply defining SCM_DEBUG as 1.
153 */
154 #ifndef SCM_DEBUG
155 #define SCM_DEBUG 0
156 #endif
157
158 /* If SCM_DEBUG_CELL_ACCESSES is set to 1, cell accesses will perform
159 * exhaustive parameter checking: It will be verified that cell parameters
160 * actually point to a valid heap cell. Note: If this option is enabled,
161 * guile will run about ten times slower than normally.
162 */
163 #ifndef SCM_DEBUG_CELL_ACCESSES
164 #define SCM_DEBUG_CELL_ACCESSES SCM_DEBUG
165 #endif
166
167 /* If SCM_DEBUG_DEPRECATED is set to 1, deprecated code is not compiled. This
168 * can be used by developers to get rid of references to deprecated code.
169 */
170 #ifndef SCM_DEBUG_DEPRECATED
171 #define SCM_DEBUG_DEPRECATED SCM_DEBUG
172 #endif
173
174 /* If SCM_DEBUG_REST_ARGUMENT is set to 1, functions that take rest arguments
175 * will check whether the rest arguments are actually passed as a proper list.
176 * Otherwise, if SCM_DEBUG_REST_ARGUMENT is 0, functions that take rest
177 * arguments will take it for granted that these are passed as a proper list.
178 */
179 #ifndef SCM_DEBUG_REST_ARGUMENT
180 #define SCM_DEBUG_REST_ARGUMENT SCM_DEBUG
181 #endif
182
183 /* Use this for _compile time_ type checking only, since the compiled result
184 * will be quite inefficient. The right way to make use of this option is to
185 * do a 'make clean; make CFLAGS=-DSCM_DEBUG_TYPING_STRICTNESS=1', fix your
186 * errors, and then do 'make clean; make'.
187 */
188 #ifndef SCM_DEBUG_TYPING_STRICTNESS
189 #define SCM_DEBUG_TYPING_STRICTNESS 0
190 #endif
191
192 \f
193
194 #ifdef HAVE_LONG_LONGS
195
196 /* Some auto-generated .h files contain unused prototypes
197 * that need these typedefs.
198 */
199 typedef long long long_long;
200 typedef unsigned long long ulong_long;
201
202 #endif /* HAVE_LONG_LONGS */
203
204 \f
205
206 /* Define
207 *
208 * SCM_CHAR_CODE_LIMIT == UCHAR_MAX + 1
209 * SCM_MOST_POSITIVE_FIXNUM (LONG_MAX>>2)
210 * SCM_MOST_NEGATIVE_FIXNUM == SCM_SRS((long)LONG_MIN, 2)
211 */
212
213 #ifdef HAVE_LIMITS_H
214 # include <limits.h>
215 # ifdef UCHAR_MAX
216 # define SCM_CHAR_CODE_LIMIT (UCHAR_MAX+1L)
217 # else
218 # define SCM_CHAR_CODE_LIMIT 256L
219 # endif /* def UCHAR_MAX */
220 # define SCM_MOST_POSITIVE_FIXNUM (LONG_MAX>>2)
221 # ifdef _UNICOS /* Stupid cray bug */
222 # define SCM_MOST_NEGATIVE_FIXNUM ((long)LONG_MIN/4)
223 # else
224 # define SCM_MOST_NEGATIVE_FIXNUM SCM_SRS((long)LONG_MIN, 2)
225 # endif /* UNICOS */
226 #else
227 # define SCM_CHAR_CODE_LIMIT 256L
228 # define SCM_MOST_POSITIVE_FIXNUM ((long)((unsigned long)~0L>>3))
229 # if (0 != ~0)
230 # define SCM_MOST_NEGATIVE_FIXNUM (-SCM_MOST_POSITIVE_FIXNUM-1)
231 # else
232 # define SCM_MOST_NEGATIVE_FIXNUM (-SCM_MOST_POSITIVE_FIXNUM)
233 # endif /* (0 != ~0) */
234 #endif /* def HAVE_LIMITS_H */
235 \f
236
237 #ifdef STDC_HEADERS
238 # include <stdlib.h>
239 # ifdef AMIGA
240 # include <stddef.h>
241 # endif /* def AMIGA */
242 # define scm_sizet size_t
243 #else
244 # ifdef _SIZE_T
245 # define scm_sizet size_t
246 # else
247 # define scm_sizet unsigned int
248 # endif /* def _SIZE_T */
249 #endif /* def STDC_HEADERS */
250
251 \f
252
253 #include "libguile/tags.h"
254
255 \f
256 #ifdef vms
257 # ifndef CHEAP_CONTINUATIONS
258 typedef int jmp_buf[17];
259 extern int setjump(jmp_buf env);
260 extern int longjump(jmp_buf env, int ret);
261 # define setjmp setjump
262 # define longjmp longjump
263 # else
264 # include <setjmp.h>
265 # endif
266 #else /* ndef vms */
267 # ifdef _CRAY1
268 typedef int jmp_buf[112];
269 extern int setjump(jmp_buf env);
270 extern int longjump(jmp_buf env, int ret);
271 # define setjmp setjump
272 # define longjmp longjump
273 # else /* ndef _CRAY1 */
274 # include <setjmp.h>
275 # endif /* ndef _CRAY1 */
276 #endif /* ndef vms */
277
278 /* James Clark came up with this neat one instruction fix for
279 * continuations on the SPARC. It flushes the register windows so
280 * that all the state of the process is contained in the stack.
281 */
282
283 #ifdef sparc
284 # define SCM_FLUSH_REGISTER_WINDOWS asm("ta 3")
285 #else
286 # define SCM_FLUSH_REGISTER_WINDOWS /* empty */
287 #endif
288
289 /* If stack is not longword aligned then
290 */
291
292 /* #define SHORT_ALIGN */
293 #ifdef THINK_C
294 # define SHORT_ALIGN
295 #endif
296 #ifdef MSDOS
297 # define SHORT_ALIGN
298 #endif
299 #ifdef atarist
300 # define SHORT_ALIGN
301 #endif
302
303 #ifdef SHORT_ALIGN
304 typedef short SCM_STACKITEM;
305 #else
306 typedef long SCM_STACKITEM;
307 #endif
308 \f
309
310 #ifndef USE_THREADS
311 #define SCM_THREAD_DEFER
312 #define SCM_THREAD_ALLOW
313 #define SCM_THREAD_REDEFER
314 #define SCM_THREAD_SWITCHING_CODE
315 #endif
316
317 #ifdef GUILE_OLD_ASYNC_CLICK
318 extern unsigned int scm_async_clock;
319
320 #define SCM_ASYNC_TICK \
321 do { \
322 if (0 == --scm_async_clock) \
323 scm_async_click (); \
324 } while(0)
325 #else
326 extern int scm_asyncs_pending_p;
327
328 #define SCM_ASYNC_TICK /*fixme* should change names */ \
329 do { \
330 if (scm_asyncs_pending_p) \
331 scm_async_click (); \
332 } while (0)
333 #endif
334
335 #ifdef SCM_CAREFUL_INTS
336 #define SCM_CHECK_NOT_DISABLED \
337 if (scm_ints_disabled) \
338 fputs("ints already disabled\n", stderr); \
339
340 #define SCM_CHECK_NOT_ENABLED \
341 if (!scm_ints_disabled) \
342 fputs("ints already enabled\n", stderr); \
343
344 #else
345 #define SCM_CHECK_NOT_DISABLED
346 #define SCM_CHECK_NOT_ENABLED
347 #endif
348
349
350 /* Anthony Green writes:
351 When the compiler sees...
352 DEFER_INTS;
353 [critical code here]
354 ALLOW_INTS;
355 ...it doesn't actually promise to keep the critical code within the
356 boundries of the DEFER/ALLOW_INTS instructions. It may very well
357 schedule it outside of the magic defined in those macros.
358
359 However, GCC's volatile asm feature forms a barrier over which code is
360 never moved. So if you add...
361 asm ("");
362 ...to each of the DEFER_INTS and ALLOW_INTS macros, the critical
363 code will always remain in place. asm's without inputs or outputs
364 are implicitly volatile. */
365 #ifdef __GNUC__
366 #define SCM_FENCE asm /* volatile */ ("")
367 #else
368 #define SCM_FENCE
369 #endif
370
371 #define SCM_DEFER_INTS \
372 do { \
373 SCM_FENCE; \
374 SCM_CHECK_NOT_DISABLED; \
375 SCM_THREAD_DEFER; \
376 SCM_FENCE; \
377 scm_ints_disabled = 1; \
378 SCM_FENCE; \
379 } while (0)
380
381
382 #define SCM_ALLOW_INTS_ONLY \
383 do { \
384 SCM_THREAD_ALLOW; \
385 scm_ints_disabled = 0; \
386 } while (0)
387
388
389 #define SCM_ALLOW_INTS \
390 do { \
391 SCM_FENCE; \
392 SCM_CHECK_NOT_ENABLED; \
393 SCM_THREAD_SWITCHING_CODE; \
394 SCM_FENCE; \
395 scm_ints_disabled = 0; \
396 SCM_FENCE; \
397 SCM_THREAD_ALLOW; \
398 SCM_FENCE; \
399 } while (0)
400
401
402 #define SCM_REDEFER_INTS \
403 do { \
404 SCM_FENCE; \
405 SCM_THREAD_REDEFER; \
406 ++scm_ints_disabled; \
407 SCM_FENCE; \
408 } while (0)
409
410
411 #define SCM_REALLOW_INTS \
412 do { \
413 SCM_FENCE; \
414 SCM_THREAD_SWITCHING_CODE; \
415 SCM_FENCE; \
416 --scm_ints_disabled; \
417 SCM_FENCE; \
418 } while (0)
419
420
421 #define SCM_TICK \
422 do { \
423 SCM_DEFER_INTS; \
424 SCM_ALLOW_INTS; \
425 SCM_ASYNC_TICK; \
426 } while (0)
427
428 \f
429
430 /* Classification of critical sections
431 *
432 * When Guile moves to POSIX threads, it won't be possible to prevent
433 * context switching. In fact, the whole idea of context switching is
434 * bogus if threads are run by different processors. Therefore, we
435 * must ultimately eliminate all critical sections or enforce them by
436 * use of mutecis.
437 *
438 * All instances of SCM_DEFER_INTS and SCM_ALLOW_INTS should therefore
439 * be classified and replaced by one of the delimiters below. If you
440 * understand what this is all about, I'd like to encourage you to
441 * help with this task. The set of classes below must of course be
442 * incrementally augmented.
443 *
444 * MDJ 980419 <djurfeldt@nada.kth.se>
445 */
446
447 /* A sections
448 *
449 * Allocation of a cell with type tag in the CAR.
450 *
451 * With POSIX threads, each thread will have a private pool of free
452 * cells. Therefore, this type of section can be removed. But! It
453 * is important that the CDR is initialized first (with the CAR still
454 * indicating a free cell) so that we can guarantee a consistent heap
455 * at all times.
456 */
457
458 #ifdef SCM_POSIX_THREADS
459 #define SCM_ENTER_A_SECTION
460 #define SCM_EXIT_A_SECTION
461 #else
462 #define SCM_ENTER_A_SECTION SCM_DEFER_INTS
463 #define SCM_EXIT_A_SECTION SCM_ALLOW_INTS
464 #endif
465
466 \f
467
468 /** SCM_ASSERT
469 **
470 **/
471
472
473 #ifdef SCM_RECKLESS
474 #define SCM_ASSERT(_cond, _arg, _pos, _subr)
475 #define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr)
476 #define SCM_ASRTGO(_cond, _label)
477 #else
478 #define SCM_ASSERT(_cond, _arg, _pos, _subr) \
479 if (!(_cond)) \
480 scm_wta(_arg, (char *)(_pos), _subr)
481 #define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr, _msg) \
482 if (!(_cond)) \
483 scm_wrong_type_arg_msg(_subr, _pos, _arg, _msg)
484 #define SCM_ASRTGO(_cond, _label) \
485 if (!(_cond)) \
486 goto _label
487 #endif
488
489 /*
490 * SCM_WTA_DISPATCH
491 */
492
493 /* Dirk:FIXME:: In all of the SCM_WTA_DISPATCH_* macros it is assumed that
494 * 'gf' is zero if uninitialized. It would be cleaner if some valid SCM value
495 * like SCM_BOOL_F or SCM_UNDEFINED was chosen.
496 */
497
498 extern SCM scm_call_generic_0 (SCM gf);
499
500 #define SCM_WTA_DISPATCH_0(gf, arg, pos, subr) \
501 return (SCM_UNPACK (gf) \
502 ? scm_call_generic_0 ((gf)) \
503 : scm_wta ((arg), (char *) (pos), (subr)))
504 #define SCM_GASSERT0(cond, gf, arg, pos, subr) \
505 if (!(cond)) SCM_WTA_DISPATCH_0((gf), (arg), (pos), (subr))
506
507 extern SCM scm_call_generic_1 (SCM gf, SCM a1);
508
509 #define SCM_WTA_DISPATCH_1(gf, a1, pos, subr) \
510 return (SCM_UNPACK (gf) \
511 ? scm_call_generic_1 ((gf), (a1)) \
512 : scm_wta ((a1), (char *) (pos), (subr)))
513 #define SCM_GASSERT1(cond, gf, a1, pos, subr) \
514 if (!(cond)) SCM_WTA_DISPATCH_1((gf), (a1), (pos), (subr))
515
516 extern SCM scm_call_generic_2 (SCM gf, SCM a1, SCM a2);
517
518 #define SCM_WTA_DISPATCH_2(gf, a1, a2, pos, subr) \
519 return (SCM_UNPACK (gf) \
520 ? scm_call_generic_2 ((gf), (a1), (a2)) \
521 : scm_wta ((pos) == SCM_ARG1 ? (a1) : (a2), (char *) (pos), (subr)))
522 #define SCM_GASSERT2(cond, gf, a1, a2, pos, subr) \
523 if (!(cond)) SCM_WTA_DISPATCH_2((gf), (a1), (a2), (pos), (subr))
524
525 extern SCM scm_apply_generic (SCM gf, SCM args);
526
527 #define SCM_WTA_DISPATCH_n(gf, args, pos, subr) \
528 return (SCM_UNPACK (gf) \
529 ? scm_apply_generic ((gf), (args)) \
530 : scm_wta (scm_list_ref ((args), SCM_MAKINUM ((pos) - 1)), \
531 (char *) (pos), \
532 (subr)))
533 #define SCM_GASSERTn(cond, gf, args, pos, subr) \
534 if (!(cond)) SCM_WTA_DISPATCH_n((gf), (args), (pos), (subr))
535
536 #ifndef SCM_MAGIC_SNARFER
537 /* Let these macros pass through if
538 we are snarfing; thus we can tell the
539 difference between the use of an actual
540 number vs. the use of one of these macros --
541 actual numbers in SCM_VALIDATE_* and SCM_ASSERT
542 constructs must match the formal argument name,
543 but using SCM_ARG* avoids the test */
544
545 #define SCM_ARGn 0
546 #define SCM_ARG1 1
547 #define SCM_ARG2 2
548 #define SCM_ARG3 3
549 #define SCM_ARG4 4
550 #define SCM_ARG5 5
551 #define SCM_ARG6 6
552 #define SCM_ARG7 7
553 /* #define SCM_ARGERR(X) ((X) < SCM_WNA \
554 ? (char *)(X) \
555 : "wrong type argument")
556 */
557
558 /* Following must match entry indexes in scm_errmsgs[].
559 * Also, SCM_WNA must follow the last SCM_ARGn in sequence.
560 */
561 #define SCM_WNA 8
562 /* #define SCM_OVSCM_FLOW 9 */
563 #define SCM_OUTOFRANGE 10
564 #define SCM_NALLOC 11
565 /* #define SCM_STACK_OVFLOW 12 */
566 /* #define SCM_EXIT 13 */
567
568 #endif /* SCM_MAGIC_SNARFER */
569
570 /* (...still matching scm_errmsgs) These
571 * are signals. Signals may become errors
572 * but are distinguished because they first
573 * try to invoke a handler that can resume
574 * the interrupted routine.
575 */
576 #define SCM_HUP_SIGNAL 14
577 #define SCM_INT_SIGNAL 15
578 #define SCM_FPE_SIGNAL 16
579 #define SCM_BUS_SIGNAL 17
580 #define SCM_SEGV_SIGNAL 18
581 #define SCM_ALRM_SIGNAL 19
582 #define SCM_GC_SIGNAL 20
583 #define SCM_TICK_SIGNAL 21
584
585 #define SCM_SIG_ORD(X) ((X) - SCM_HUP_SIGNAL)
586 #define SCM_ORD_SIG(X) ((X) + SCM_HUP_SIGNAL)
587 #define SCM_NUM_SIGS (SCM_SIG_ORD (SCM_TICK_SIGNAL) + 1)
588
589 #if 0
590 struct errdesc
591 {
592 char *msg;
593 char *s_response;
594 short parent_err;
595 };
596
597
598 extern struct errdesc scm_errmsgs[];
599 #endif
600
601 \f
602
603 /* SCM_EXIT_SUCCESS is the default code to return from SCM if no errors
604 * were encountered. SCM_EXIT_FAILURE is the default code to return from
605 * SCM if errors were encountered. The return code can be explicitly
606 * specified in a SCM program with (scm_quit <n>).
607 */
608
609 #ifndef SCM_EXIT_SUCCESS
610 #ifdef vms
611 #define SCM_EXIT_SUCCESS 1
612 #else
613 #define SCM_EXIT_SUCCESS 0
614 #endif /* def vms */
615 #endif /* ndef SCM_EXIT_SUCCESS */
616 #ifndef SCM_EXIT_FAILURE
617 #ifdef vms
618 #define SCM_EXIT_FAILURE 2
619 #else
620 #define SCM_EXIT_FAILURE 1
621 #endif /* def vms */
622 #endif /* ndef SCM_EXIT_FAILURE */
623
624
625
626 \f
627
628 #endif /* __SCMH */
629
630 /*
631 Local Variables:
632 c-file-style: "gnu"
633 End:
634 */