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