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