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