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