* validate.h
[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,2001 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 \f
104 /* {Unsupported Options}
105 *
106 * These must be defined as given here.
107 */
108
109
110 #define CCLO
111
112 /* Guile Scheme supports the #f/() distinction; Guile Lisp won't. We
113 have horrible plans for their unification. */
114 #undef SICP
115
116 \f
117
118 /* Random options (not yet supported or in final form). */
119
120 #define STACK_CHECKING
121 #undef NO_CEVAL_STACK_CHECKING
122
123 \f
124
125 /* What did the configure script discover about the outside world? */
126 #include "libguile/scmconfig.h"
127
128 \f
129
130 /* {Debugging Options}
131 *
132 * These compile time options determine whether to include code that is only
133 * useful for debugging guile itself or C level extensions to guile. The
134 * common prefix for all option macros of this kind is "SCM_DEBUG_". It is
135 * guaranteed that a macro named SCM_DEBUG_XXX is defined to be either 0 or 1,
136 * i. e. there is no need to test for the undefined case. This allows to use
137 * these definitions comfortably in macro code, as in the following example:
138 * #define FOO do { if (SCM_DEBUG_XXX) bar(); else baz(); } while (0)
139 * Any sane compiler will remove the unused branch without any performance
140 * penalty for the resulting code.
141 *
142 * Note: Some SCM_DEBUG_XXX options are not settable at configure time.
143 * To change the value of such options you will have to edit this header
144 * file or give suitable options to make, like:
145 * make all CFLAGS="-DSCM_DEBUG_XXX=1 ..."
146 */
147
148
149 /* The value of SCM_DEBUG determines the default for most of the not yet
150 * defined debugging options. This allows, for example, to enable most of the
151 * debugging options by simply defining SCM_DEBUG as 1.
152 */
153 #ifndef SCM_DEBUG
154 #define SCM_DEBUG 0
155 #endif
156
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
166 /* If SCM_DEBUG_DEPRECATED is set to 1, deprecated code is not compiled. This
167 * can be used by developers to get rid of references to deprecated code.
168 */
169 #ifndef SCM_DEBUG_DEPRECATED
170 #define SCM_DEBUG_DEPRECATED SCM_DEBUG
171 #endif
172
173 /* If SCM_DEBUG_INTERRUPTS is set to 1, with every deferring and allowing of
174 * interrupts a consistency check will be performed.
175 */
176 #ifndef SCM_DEBUG_INTERRUPTS
177 #define SCM_DEBUG_INTERRUPTS SCM_DEBUG
178 #endif
179
180 /* If SCM_DEBUG_REST_ARGUMENT is set to 1, functions that take rest arguments
181 * will check whether the rest arguments are actually passed as a proper list.
182 * Otherwise, if SCM_DEBUG_REST_ARGUMENT is 0, functions that take rest
183 * arguments will take it for granted that these are passed as a proper list.
184 */
185 #ifndef SCM_DEBUG_REST_ARGUMENT
186 #define SCM_DEBUG_REST_ARGUMENT SCM_DEBUG
187 #endif
188
189 /* Use this for _compile time_ type checking only, since the compiled result
190 * will be quite inefficient. The right way to make use of this option is to
191 * do a 'make clean; make CFLAGS=-DSCM_DEBUG_TYPING_STRICTNESS=1', fix your
192 * errors, and then do 'make clean; make'.
193 */
194 #ifndef SCM_DEBUG_TYPING_STRICTNESS
195 #define SCM_DEBUG_TYPING_STRICTNESS 0
196 #endif
197
198 /* If SCM_ENABLE_VCELLS is set to 1, a couple of functions that deal
199 * with vcells are defined for compatability reasons. Supporting
200 * vcells reduces performance however.
201 *
202 * We use a dedicated macro instead of just SCM_DEBUG_DEPRECATED so
203 * that code the belongs to the `vcell' feature is easier to find.
204 */
205 #define SCM_ENABLE_VCELLS !SCM_DEBUG_DEPRECATED
206
207 \f
208
209 #ifdef HAVE_LONG_LONGS
210
211 /* Some auto-generated .h files contain unused prototypes
212 * that need these typedefs.
213 */
214
215 #if (SCM_DEBUG_DEPRECATED == 0)
216 typedef long long long_long;
217 typedef unsigned long long ulong_long;
218 #endif
219
220 #endif /* HAVE_LONG_LONGS */
221
222 \f
223
224 /* {Architecture and compiler properties}
225 *
226 * Guile as of today can only work on systems which fulfill at least the
227 * following requirements:
228 * - long ints have at least 32 bits.
229 * Guile's type system is based on this assumption.
230 * - long ints consist of at least four characters.
231 * It is assumed that cells, i. e. pairs of long ints, are eight character
232 * aligned, because three bits of a cell pointer are used for type data.
233 * - sizeof (void*) == sizeof (long int)
234 * Pointers are stored in SCM objects, and sometimes SCM objects are passed
235 * as void*. Thus, there has to be a one-to-one correspondence.
236 * - numbers are encoded using two's complement.
237 * The implementation of the bitwise scheme level operations is based on
238 * this assumption.
239 * - ... add more
240 */
241
242 #ifdef HAVE_LIMITS_H
243 # include <limits.h>
244 #endif
245
246 #ifdef CHAR_BIT
247 # define SCM_CHAR_BIT CHAR_BIT
248 #else
249 # define SCM_CHAR_BIT 8
250 #endif
251
252 #ifdef LONG_BIT
253 # define SCM_LONG_BIT LONG_BIT
254 #else
255 # define SCM_LONG_BIT (SCM_CHAR_BIT * sizeof (long) / sizeof (char))
256 #endif
257
258 #define SCM_BITS_LENGTH (SCM_CHAR_BIT * SCM_SIZEOF_BITS_T)
259
260 #ifdef UCHAR_MAX
261 # define SCM_CHAR_CODE_LIMIT (UCHAR_MAX + 1L)
262 #else
263 # define SCM_CHAR_CODE_LIMIT 256L
264 #endif
265
266 \f
267
268 #ifdef STDC_HEADERS
269 # include <stdlib.h>
270 # if HAVE_SYS_TYPES_H
271 # include <sys/types.h>
272 # endif
273 # if HAVE_SYS_STDTYPES_H
274 # include <sys/stdtypes.h>
275 # endif
276 # include <stddef.h>
277 #endif /* def STDC_HEADERS */
278
279 #if (SCM_DEBUG_DEPRECATED == 0)
280 # define scm_sizet size_t
281 #endif
282
283 \f
284
285 #include "libguile/tags.h"
286
287 \f
288 #ifdef vms
289 # ifndef CHEAP_CONTINUATIONS
290 typedef int jmp_buf[17];
291 extern int setjump(jmp_buf env);
292 extern int longjump(jmp_buf env, int ret);
293 # define setjmp setjump
294 # define longjmp longjump
295 # else
296 # include <setjmp.h>
297 # endif
298 #else /* ndef vms */
299 # ifdef _CRAY1
300 typedef int jmp_buf[112];
301 extern int setjump(jmp_buf env);
302 extern int longjump(jmp_buf env, int ret);
303 # define setjmp setjump
304 # define longjmp longjump
305 # else /* ndef _CRAY1 */
306 # include <setjmp.h>
307 # endif /* ndef _CRAY1 */
308 #endif /* ndef vms */
309
310 /* James Clark came up with this neat one instruction fix for
311 * continuations on the SPARC. It flushes the register windows so
312 * that all the state of the process is contained in the stack.
313 */
314
315 #ifdef sparc
316 # define SCM_FLUSH_REGISTER_WINDOWS asm("ta 3")
317 #else
318 # define SCM_FLUSH_REGISTER_WINDOWS /* empty */
319 #endif
320
321 /* If stack is not longword aligned then
322 */
323
324 /* #define SHORT_ALIGN */
325 #ifdef THINK_C
326 # define SHORT_ALIGN
327 #endif
328 #ifdef MSDOS
329 # define SHORT_ALIGN
330 #endif
331 #ifdef atarist
332 # define SHORT_ALIGN
333 #endif
334
335 #ifdef SHORT_ALIGN
336 typedef short SCM_STACKITEM;
337 #else
338 typedef long SCM_STACKITEM;
339 #endif
340 \f
341
342 #ifndef USE_THREADS
343 #define SCM_CRITICAL_SECTION_START
344 #define SCM_CRITICAL_SECTION_END
345 #define SCM_THREAD_SWITCHING_CODE
346 #endif
347
348 #ifdef GUILE_OLD_ASYNC_CLICK
349 extern unsigned int scm_async_clock;
350
351 #define SCM_ASYNC_TICK \
352 do { \
353 if (0 == --scm_async_clock) \
354 scm_async_click (); \
355 } while(0)
356 #else
357 extern int scm_asyncs_pending_p;
358
359 #define SCM_ASYNC_TICK /*fixme* should change names */ \
360 do { \
361 if (scm_asyncs_pending_p) \
362 scm_async_click (); \
363 } while (0)
364 #endif
365
366 #if (SCM_DEBUG_INTERRUPTS == 1)
367 #include <stdio.h>
368 #define SCM_CHECK_NOT_DISABLED \
369 do { \
370 if (scm_ints_disabled) \
371 fprintf(stderr, "ints already disabled (at %s:%d)\n", \
372 __FILE__, __LINE__); \
373 } while (0)
374
375 #define SCM_CHECK_NOT_ENABLED \
376 do { \
377 if (!scm_ints_disabled) \
378 fprintf(stderr, "ints already enabled (at %s:%d)\n", \
379 __FILE__, __LINE__); \
380 } while (0)
381
382 #else
383 #define SCM_CHECK_NOT_DISABLED
384 #define SCM_CHECK_NOT_ENABLED
385 #endif
386
387
388 /* Anthony Green writes:
389 When the compiler sees...
390 DEFER_INTS;
391 [critical code here]
392 ALLOW_INTS;
393 ...it doesn't actually promise to keep the critical code within the
394 boundries of the DEFER/ALLOW_INTS instructions. It may very well
395 schedule it outside of the magic defined in those macros.
396
397 However, GCC's volatile asm feature forms a barrier over which code is
398 never moved. So if you add...
399 asm ("");
400 ...to each of the DEFER_INTS and ALLOW_INTS macros, the critical
401 code will always remain in place. asm's without inputs or outputs
402 are implicitly volatile. */
403 #ifdef __GNUC__
404 #define SCM_FENCE asm /* volatile */ ("")
405 #else
406 #define SCM_FENCE
407 #endif
408
409 #define SCM_DEFER_INTS \
410 do { \
411 SCM_FENCE; \
412 SCM_CHECK_NOT_DISABLED; \
413 SCM_CRITICAL_SECTION_START; \
414 SCM_FENCE; \
415 scm_ints_disabled = 1; \
416 SCM_FENCE; \
417 } while (0)
418
419
420 #define SCM_ALLOW_INTS_ONLY \
421 do { \
422 SCM_CRITICAL_SECTION_END; \
423 scm_ints_disabled = 0; \
424 } while (0)
425
426
427 #define SCM_ALLOW_INTS \
428 do { \
429 SCM_FENCE; \
430 SCM_CHECK_NOT_ENABLED; \
431 SCM_CRITICAL_SECTION_END; \
432 SCM_FENCE; \
433 scm_ints_disabled = 0; \
434 SCM_FENCE; \
435 SCM_THREAD_SWITCHING_CODE; \
436 SCM_FENCE; \
437 } while (0)
438
439
440 #define SCM_REDEFER_INTS \
441 do { \
442 SCM_FENCE; \
443 SCM_CRITICAL_SECTION_START; \
444 ++scm_ints_disabled; \
445 SCM_FENCE; \
446 } while (0)
447
448
449 #define SCM_REALLOW_INTS \
450 do { \
451 SCM_FENCE; \
452 SCM_CRITICAL_SECTION_END; \
453 SCM_FENCE; \
454 --scm_ints_disabled; \
455 SCM_FENCE; \
456 } while (0)
457
458
459 #define SCM_TICK \
460 do { \
461 SCM_ASYNC_TICK; \
462 SCM_THREAD_SWITCHING_CODE; \
463 } while (0)
464
465 \f
466
467 /* Classification of critical sections
468 *
469 * When Guile moves to POSIX threads, it won't be possible to prevent
470 * context switching. In fact, the whole idea of context switching is
471 * bogus if threads are run by different processors. Therefore, we
472 * must ultimately eliminate all critical sections or enforce them by
473 * use of mutecis.
474 *
475 * All instances of SCM_DEFER_INTS and SCM_ALLOW_INTS should therefore
476 * be classified and replaced by one of the delimiters below. If you
477 * understand what this is all about, I'd like to encourage you to
478 * help with this task. The set of classes below must of course be
479 * incrementally augmented.
480 *
481 * MDJ 980419 <djurfeldt@nada.kth.se>
482 */
483
484 /* A sections
485 *
486 * Allocation of a cell with type tag in the CAR.
487 *
488 * With POSIX threads, each thread will have a private pool of free
489 * cells. Therefore, this type of section can be removed. But! It
490 * is important that the CDR is initialized first (with the CAR still
491 * indicating a free cell) so that we can guarantee a consistent heap
492 * at all times.
493 */
494
495 #define SCM_ENTER_A_SECTION SCM_CRITICAL_SECTION_START
496 #define SCM_EXIT_A_SECTION SCM_CRITICAL_SECTION_END
497
498 \f
499
500 /** SCM_ASSERT
501 **
502 **/
503
504
505 #ifdef SCM_RECKLESS
506 #define SCM_ASSERT(_cond, _arg, _pos, _subr)
507 #define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr, _msg)
508 #define SCM_ASRTGO(_cond, _label)
509 #else
510 #define SCM_ASSERT(_cond, _arg, _pos, _subr) \
511 if (!(_cond)) \
512 scm_wrong_type_arg (_subr, _pos, _arg)
513 #define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr, _msg) \
514 if (!(_cond)) \
515 scm_wrong_type_arg_msg(_subr, _pos, _arg, _msg)
516 #define SCM_ASRTGO(_cond, _label) \
517 if (!(_cond)) \
518 goto _label
519 #endif
520
521 /*
522 * SCM_WTA_DISPATCH
523 */
524
525 /* Dirk:FIXME:: In all of the SCM_WTA_DISPATCH_* macros it is assumed that
526 * 'gf' is zero if uninitialized. It would be cleaner if some valid SCM value
527 * like SCM_BOOL_F or SCM_UNDEFINED was chosen.
528 */
529
530 extern SCM scm_call_generic_0 (SCM gf);
531
532 #define SCM_WTA_DISPATCH_0(gf, subr) \
533 return (SCM_UNPACK (gf) \
534 ? scm_call_generic_0 ((gf)) \
535 : (scm_error_num_args_subr ((subr)), SCM_UNSPECIFIED))
536 #define SCM_GASSERT0(cond, gf, subr) \
537 if (!(cond)) SCM_WTA_DISPATCH_0((gf), (subr))
538
539 extern SCM scm_call_generic_1 (SCM gf, SCM a1);
540
541 #define SCM_WTA_DISPATCH_1(gf, a1, pos, subr) \
542 return (SCM_UNPACK (gf) \
543 ? scm_call_generic_1 ((gf), (a1)) \
544 : (scm_wrong_type_arg ((subr), (pos), (a1)), SCM_UNSPECIFIED))
545 #define SCM_GASSERT1(cond, gf, a1, pos, subr) \
546 if (!(cond)) SCM_WTA_DISPATCH_1((gf), (a1), (pos), (subr))
547
548 extern SCM scm_call_generic_2 (SCM gf, SCM a1, SCM a2);
549
550 #define SCM_WTA_DISPATCH_2(gf, a1, a2, pos, subr) \
551 return (SCM_UNPACK (gf) \
552 ? scm_call_generic_2 ((gf), (a1), (a2)) \
553 : (scm_wrong_type_arg ((subr), (pos), \
554 (pos) == SCM_ARG1 ? (a1) : (a2)), \
555 SCM_UNSPECIFIED))
556 #define SCM_GASSERT2(cond, gf, a1, a2, pos, subr) \
557 if (!(cond)) SCM_WTA_DISPATCH_2((gf), (a1), (a2), (pos), (subr))
558
559 extern SCM scm_apply_generic (SCM gf, SCM args);
560
561 #define SCM_WTA_DISPATCH_n(gf, args, pos, subr) \
562 return (SCM_UNPACK (gf) \
563 ? scm_apply_generic ((gf), (args)) \
564 : (scm_wrong_type_arg ((subr), (pos), \
565 scm_list_ref ((args), \
566 SCM_MAKINUM ((pos) - 1))), \
567 SCM_UNSPECIFIED))
568 #define SCM_GASSERTn(cond, gf, args, pos, subr) \
569 if (!(cond)) SCM_WTA_DISPATCH_n((gf), (args), (pos), (subr))
570
571 #ifndef SCM_MAGIC_SNARFER
572 /* Let these macros pass through if
573 we are snarfing; thus we can tell the
574 difference between the use of an actual
575 number vs. the use of one of these macros --
576 actual numbers in SCM_VALIDATE_* and SCM_ASSERT
577 constructs must match the formal argument name,
578 but using SCM_ARG* avoids the test */
579
580 #define SCM_ARGn 0
581 #define SCM_ARG1 1
582 #define SCM_ARG2 2
583 #define SCM_ARG3 3
584 #define SCM_ARG4 4
585 #define SCM_ARG5 5
586 #define SCM_ARG6 6
587 #define SCM_ARG7 7
588
589 #if (SCM_DEBUG_DEPRECATED == 0)
590
591 /* Use SCM_WRONG_NUM_ARGS instead of: */
592 #define SCM_WNA 8
593
594 /* Use SCM_ASSERT_RANGE or SCM_VALIDATE_XXX_RANGE instead of: */
595 #define SCM_OUTOFRANGE 10
596
597 /* Use scm_memory_error instead of: */
598 #define SCM_NALLOC 11
599
600 #define SCM_HUP_SIGNAL 14
601 #define SCM_INT_SIGNAL 15
602 #define SCM_FPE_SIGNAL 16
603 #define SCM_BUS_SIGNAL 17
604 #define SCM_SEGV_SIGNAL 18
605 #define SCM_ALRM_SIGNAL 19
606 #define SCM_GC_SIGNAL 20
607 #define SCM_TICK_SIGNAL 21
608 #define SCM_SIG_ORD(X) ((X) - SCM_HUP_SIGNAL)
609 #define SCM_ORD_SIG(X) ((X) + SCM_HUP_SIGNAL)
610 #define SCM_NUM_SIGS (SCM_SIG_ORD (SCM_TICK_SIGNAL) + 1)
611
612 #endif /* SCM_DEBUG_DEPRECATED == 0 */
613
614 #endif /* SCM_MAGIC_SNARFER */
615
616 \f
617
618 /* SCM_EXIT_SUCCESS is the default code to return from SCM if no errors
619 * were encountered. SCM_EXIT_FAILURE is the default code to return from
620 * SCM if errors were encountered. The return code can be explicitly
621 * specified in a SCM program with (scm_quit <n>).
622 */
623
624 #ifndef SCM_EXIT_SUCCESS
625 #ifdef vms
626 #define SCM_EXIT_SUCCESS 1
627 #else
628 #define SCM_EXIT_SUCCESS 0
629 #endif /* def vms */
630 #endif /* ndef SCM_EXIT_SUCCESS */
631 #ifndef SCM_EXIT_FAILURE
632 #ifdef vms
633 #define SCM_EXIT_FAILURE 2
634 #else
635 #define SCM_EXIT_FAILURE 1
636 #endif /* def vms */
637 #endif /* ndef SCM_EXIT_FAILURE */
638
639 \f
640
641 #endif /* __SCMH */
642
643 /*
644 Local Variables:
645 c-file-style: "gnu"
646 End:
647 */