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