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