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