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