Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
729dbac3 DH |
3 | #ifndef SCM___SCM_H |
4 | #define SCM___SCM_H | |
b3fcac34 | 5 | /* Copyright (C) 1995,1996,1998,1999,2000,2001 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 | 45 | \f |
176067df JB |
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 | ||
e81d98ec DH |
58 | /* {Compiler hints} |
59 | * | |
60 | * The following macros are used to provide additional information for the | |
61 | * compiler, which may help to do better error checking and code | |
62 | * optimization. A second benefit of these macros is, that they also provide | |
63 | * additional information to the developers. | |
64 | */ | |
65 | ||
66 | /* The macro SCM_NORETURN indicates that a function will never return. | |
67 | * Examples: | |
68 | * 1) int foo (char arg) SCM_NORETURN; | |
69 | */ | |
70 | #ifdef __GNUC__ | |
71 | #define SCM_NORETURN __attribute__ ((noreturn)) | |
72 | #else | |
73 | #define SCM_NORETURN | |
74 | #endif | |
75 | ||
76 | /* The macro SCM_UNUSED indicates that a function, function argument or | |
77 | * variable may potentially be unused. | |
78 | * Examples: | |
79 | * 1) static int unused_function (char arg) SCM_UNUSED; | |
80 | * 2) int foo (char unused_argument SCM_UNUSED); | |
81 | * 3) int unused_variable SCM_UNUSED; | |
82 | */ | |
83 | #ifdef __GNUC__ | |
84 | #define SCM_UNUSED __attribute__ ((unused)) | |
85 | #else | |
86 | #define SCM_UNUSED | |
87 | #endif | |
88 | ||
89 | ||
0f2d19dd JB |
90 | /* {Supported Options} |
91 | * | |
92 | * These may be defined or undefined. | |
93 | */ | |
94 | ||
9f0e55a6 MD |
95 | /* Old async mechanism */ |
96 | /* #define GUILE_OLD_ASYNC_CLICK */ | |
97 | ||
16d35552 | 98 | /* #define GUILE_DEBUG_FREELIST */ |
70d63753 | 99 | |
cf7c17e9 | 100 | /* If the compile FLAG `SCM_CAUTIOUS' is #defined then the number of |
0f2d19dd | 101 | * arguments is always checked for application of closures. If the |
cf7c17e9 | 102 | * compile FLAG `SCM_RECKLESS' is #defined then they are not checked. |
904a077d MV |
103 | * Otherwise, number of argument checks for closures are made only |
104 | * when the function position (whose value is the closure) of a | |
105 | * combination is not an ILOC or a variable (true?). When the | |
106 | * function position of a combination is a symbol it will be checked | |
107 | * only the first time it is evaluated because it will then be | |
108 | * replaced with an ILOC or variable. | |
0f2d19dd | 109 | */ |
cf7c17e9 JB |
110 | #undef SCM_RECKLESS |
111 | #define SCM_CAUTIOUS | |
0f2d19dd JB |
112 | |
113 | /* After looking up a local for the first time, rewrite the | |
114 | * code graph, caching its position. | |
115 | */ | |
116 | #define MEMOIZE_LOCALS | |
117 | ||
118 | /* All the number support there is. | |
119 | */ | |
0f2d19dd JB |
120 | #define BIGNUMS |
121 | ||
686765af ML |
122 | /* GC should relinquish empty cons-pair arenas. */ |
123 | /* cmm:FIXME look at this after done mangling the GC */ | |
124 | /* #define GC_FREE_SEGMENTS */ | |
0f2d19dd JB |
125 | |
126 | /* Provide a scheme-accessible count-down timer that | |
127 | * generates a pseudo-interrupt. | |
128 | */ | |
129 | #define TICKS | |
130 | ||
131 | ||
132 | /* Use engineering notation when converting numbers strings? | |
133 | */ | |
134 | #undef ENGNOT | |
135 | ||
0f2d19dd JB |
136 | \f |
137 | /* {Unsupported Options} | |
138 | * | |
3c205827 | 139 | * These must be defined as given here. |
0f2d19dd JB |
140 | */ |
141 | ||
142 | ||
143 | #define CCLO | |
3c205827 JB |
144 | |
145 | /* Guile Scheme supports the #f/() distinction; Guile Lisp won't. We | |
146 | have horrible plans for their unification. */ | |
147 | #undef SICP | |
0f2d19dd JB |
148 | |
149 | \f | |
150 | ||
80c78696 | 151 | /* Random options (not yet supported or in final form). */ |
0f2d19dd | 152 | |
80c78696 MD |
153 | #define STACK_CHECKING |
154 | #undef NO_CEVAL_STACK_CHECKING | |
0f2d19dd | 155 | |
43ff3170 | 156 | \f |
3a9809df | 157 | |
43ff3170 GH |
158 | /* What did the configure script discover about the outside world? */ |
159 | #include "libguile/scmconfig.h" | |
160 | ||
3a9809df DH |
161 | \f |
162 | ||
163 | /* {Debugging Options} | |
164 | * | |
165 | * These compile time options determine whether to include code that is only | |
166 | * useful for debugging guile itself or C level extensions to guile. The | |
167 | * common prefix for all option macros of this kind is "SCM_DEBUG_". It is | |
168 | * guaranteed that a macro named SCM_DEBUG_XXX is defined to be either 0 or 1, | |
169 | * i. e. there is no need to test for the undefined case. This allows to use | |
170 | * these definitions comfortably in macro code, as in the following example: | |
171 | * #define FOO do { if (SCM_DEBUG_XXX) bar(); else baz(); } while (0) | |
172 | * Any sane compiler will remove the unused branch without any performance | |
173 | * penalty for the resulting code. | |
174 | * | |
175 | * Note: Some SCM_DEBUG_XXX options are not settable at configure time. | |
176 | * To change the value of such options you will have to edit this header | |
56100716 DH |
177 | * file or give suitable options to make, like: |
178 | * make all CFLAGS="-DSCM_DEBUG_XXX=1 ..." | |
3a9809df DH |
179 | */ |
180 | ||
181 | ||
c8a54c4b DH |
182 | /* The value of SCM_DEBUG determines the default for most of the not yet |
183 | * defined debugging options. This allows, for example, to enable most of the | |
184 | * debugging options by simply defining SCM_DEBUG as 1. | |
185 | */ | |
186 | #ifndef SCM_DEBUG | |
187 | #define SCM_DEBUG 0 | |
188 | #endif | |
189 | ||
46d53380 DH |
190 | /* If SCM_DEBUG_CELL_ACCESSES is set to 1, cell accesses will perform |
191 | * exhaustive parameter checking: It will be verified that cell parameters | |
192 | * actually point to a valid heap cell. Note: If this option is enabled, | |
193 | * guile will run about ten times slower than normally. | |
194 | */ | |
195 | #ifndef SCM_DEBUG_CELL_ACCESSES | |
196 | #define SCM_DEBUG_CELL_ACCESSES SCM_DEBUG | |
197 | #endif | |
198 | ||
3a9809df DH |
199 | /* If SCM_DEBUG_DEPRECATED is set to 1, deprecated code is not compiled. This |
200 | * can be used by developers to get rid of references to deprecated code. | |
201 | */ | |
202 | #ifndef SCM_DEBUG_DEPRECATED | |
c8a54c4b DH |
203 | #define SCM_DEBUG_DEPRECATED SCM_DEBUG |
204 | #endif | |
205 | ||
216eedfc DH |
206 | /* If SCM_DEBUG_INTERRUPTS is set to 1, with every deferring and allowing of |
207 | * interrupts a consistency check will be performed. | |
208 | */ | |
209 | #ifndef SCM_DEBUG_INTERRUPTS | |
210 | #define SCM_DEBUG_INTERRUPTS SCM_DEBUG | |
211 | #endif | |
212 | ||
e81d98ec DH |
213 | /* If SCM_DEBUG_PAIR_ACCESSES is set to 1, accesses to cons cells will be |
214 | * exhaustively checked. Note: If this option is enabled, guile will run | |
215 | * slower than normally. | |
216 | */ | |
217 | #ifndef SCM_DEBUG_PAIR_ACCESSES | |
218 | #define SCM_DEBUG_PAIR_ACCESSES SCM_DEBUG | |
219 | #endif | |
220 | ||
af45e3b0 DH |
221 | /* If SCM_DEBUG_REST_ARGUMENT is set to 1, functions that take rest arguments |
222 | * will check whether the rest arguments are actually passed as a proper list. | |
223 | * Otherwise, if SCM_DEBUG_REST_ARGUMENT is 0, functions that take rest | |
224 | * arguments will take it for granted that these are passed as a proper list. | |
c8a54c4b | 225 | */ |
af45e3b0 DH |
226 | #ifndef SCM_DEBUG_REST_ARGUMENT |
227 | #define SCM_DEBUG_REST_ARGUMENT SCM_DEBUG | |
3a9809df DH |
228 | #endif |
229 | ||
56100716 DH |
230 | /* Use this for _compile time_ type checking only, since the compiled result |
231 | * will be quite inefficient. The right way to make use of this option is to | |
232 | * do a 'make clean; make CFLAGS=-DSCM_DEBUG_TYPING_STRICTNESS=1', fix your | |
233 | * errors, and then do 'make clean; make'. | |
c8a54c4b | 234 | */ |
56100716 | 235 | #ifndef SCM_DEBUG_TYPING_STRICTNESS |
729dbac3 | 236 | #define SCM_DEBUG_TYPING_STRICTNESS 1 |
56100716 DH |
237 | #endif |
238 | ||
86d31dfe | 239 | /* If SCM_ENABLE_VCELLS is set to 1, a couple of functions that deal |
cf504ee0 | 240 | * with vcells are defined for compatibility reasons. Supporting |
86d31dfe MV |
241 | * vcells reduces performance however. |
242 | * | |
243 | * We use a dedicated macro instead of just SCM_DEBUG_DEPRECATED so | |
244 | * that code the belongs to the `vcell' feature is easier to find. | |
245 | */ | |
246 | #define SCM_ENABLE_VCELLS !SCM_DEBUG_DEPRECATED | |
247 | ||
3a9809df DH |
248 | \f |
249 | ||
43ff3170 GH |
250 | #ifdef HAVE_LONG_LONGS |
251 | ||
0f2d19dd JB |
252 | /* Some auto-generated .h files contain unused prototypes |
253 | * that need these typedefs. | |
254 | */ | |
1be6b49c ML |
255 | |
256 | #if (SCM_DEBUG_DEPRECATED == 0) | |
afe5177e GH |
257 | typedef long long long_long; |
258 | typedef unsigned long long ulong_long; | |
1be6b49c | 259 | #endif |
0f2d19dd | 260 | |
43ff3170 | 261 | #endif /* HAVE_LONG_LONGS */ |
b971d089 JB |
262 | |
263 | \f | |
0f2d19dd | 264 | |
5c75b29f | 265 | /* {Architecture and compiler properties} |
0f2d19dd | 266 | * |
5c75b29f DH |
267 | * Guile as of today can only work on systems which fulfill at least the |
268 | * following requirements: | |
269 | * - long ints have at least 32 bits. | |
270 | * Guile's type system is based on this assumption. | |
271 | * - long ints consist of at least four characters. | |
272 | * It is assumed that cells, i. e. pairs of long ints, are eight character | |
273 | * aligned, because three bits of a cell pointer are used for type data. | |
274 | * - sizeof (void*) == sizeof (long int) | |
275 | * Pointers are stored in SCM objects, and sometimes SCM objects are passed | |
276 | * as void*. Thus, there has to be a one-to-one correspondence. | |
277 | * - numbers are encoded using two's complement. | |
278 | * The implementation of the bitwise scheme level operations is based on | |
279 | * this assumption. | |
280 | * - ... add more | |
0f2d19dd JB |
281 | */ |
282 | ||
38956d84 MV |
283 | #ifndef HAVE_PTRDIFF_T |
284 | typedef long ptrdiff_t; | |
285 | #endif | |
286 | ||
b971d089 | 287 | #ifdef HAVE_LIMITS_H |
0f2d19dd | 288 | # include <limits.h> |
5c75b29f DH |
289 | #endif |
290 | ||
291 | #ifdef CHAR_BIT | |
292 | # define SCM_CHAR_BIT CHAR_BIT | |
293 | #else | |
294 | # define SCM_CHAR_BIT 8 | |
295 | #endif | |
296 | ||
297 | #ifdef LONG_BIT | |
298 | # define SCM_LONG_BIT LONG_BIT | |
299 | #else | |
300 | # define SCM_LONG_BIT (SCM_CHAR_BIT * sizeof (long) / sizeof (char)) | |
301 | #endif | |
302 | ||
303 | #ifdef UCHAR_MAX | |
304 | # define SCM_CHAR_CODE_LIMIT (UCHAR_MAX + 1L) | |
0f2d19dd | 305 | #else |
e2806c10 | 306 | # define SCM_CHAR_CODE_LIMIT 256L |
5c75b29f DH |
307 | #endif |
308 | ||
0f2d19dd JB |
309 | \f |
310 | ||
2a1d8241 JB |
311 | #ifdef STDC_HEADERS |
312 | # include <stdlib.h> | |
1be6b49c ML |
313 | # if HAVE_SYS_TYPES_H |
314 | # include <sys/types.h> | |
315 | # endif | |
316 | # if HAVE_SYS_STDTYPES_H | |
317 | # include <sys/stdtypes.h> | |
318 | # endif | |
2a1d8241 | 319 | # include <stddef.h> |
2a1d8241 JB |
320 | #endif /* def STDC_HEADERS */ |
321 | ||
1be6b49c ML |
322 | #if (SCM_DEBUG_DEPRECATED == 0) |
323 | # define scm_sizet size_t | |
324 | #endif | |
325 | ||
2a1d8241 JB |
326 | \f |
327 | ||
328 | #include "libguile/tags.h" | |
0f2d19dd JB |
329 | |
330 | \f | |
331 | #ifdef vms | |
332 | # ifndef CHEAP_CONTINUATIONS | |
333 | typedef int jmp_buf[17]; | |
334 | extern int setjump(jmp_buf env); | |
335 | extern int longjump(jmp_buf env, int ret); | |
336 | # define setjmp setjump | |
337 | # define longjmp longjump | |
338 | # else | |
339 | # include <setjmp.h> | |
340 | # endif | |
341 | #else /* ndef vms */ | |
342 | # ifdef _CRAY1 | |
343 | typedef int jmp_buf[112]; | |
344 | extern int setjump(jmp_buf env); | |
345 | extern int longjump(jmp_buf env, int ret); | |
346 | # define setjmp setjump | |
347 | # define longjmp longjump | |
348 | # else /* ndef _CRAY1 */ | |
349 | # include <setjmp.h> | |
350 | # endif /* ndef _CRAY1 */ | |
351 | #endif /* ndef vms */ | |
352 | ||
0f2d19dd JB |
353 | /* James Clark came up with this neat one instruction fix for |
354 | * continuations on the SPARC. It flushes the register windows so | |
355 | * that all the state of the process is contained in the stack. | |
356 | */ | |
357 | ||
358 | #ifdef sparc | |
359 | # define SCM_FLUSH_REGISTER_WINDOWS asm("ta 3") | |
360 | #else | |
361 | # define SCM_FLUSH_REGISTER_WINDOWS /* empty */ | |
362 | #endif | |
363 | ||
364 | /* If stack is not longword aligned then | |
365 | */ | |
366 | ||
367 | /* #define SHORT_ALIGN */ | |
368 | #ifdef THINK_C | |
369 | # define SHORT_ALIGN | |
370 | #endif | |
371 | #ifdef MSDOS | |
372 | # define SHORT_ALIGN | |
373 | #endif | |
374 | #ifdef atarist | |
375 | # define SHORT_ALIGN | |
376 | #endif | |
377 | ||
378 | #ifdef SHORT_ALIGN | |
379 | typedef short SCM_STACKITEM; | |
380 | #else | |
381 | typedef long SCM_STACKITEM; | |
382 | #endif | |
383 | \f | |
384 | ||
82339094 | 385 | #ifndef USE_THREADS |
216eedfc DH |
386 | #define SCM_CRITICAL_SECTION_START |
387 | #define SCM_CRITICAL_SECTION_END | |
25d3ee9d | 388 | #define SCM_THREAD_SWITCHING_CODE |
82339094 MD |
389 | #endif |
390 | ||
9f0e55a6 | 391 | #ifdef GUILE_OLD_ASYNC_CLICK |
0f2d19dd | 392 | extern unsigned int scm_async_clock; |
82339094 | 393 | |
25d3ee9d | 394 | #define SCM_ASYNC_TICK \ |
bfc69694 | 395 | do { \ |
25d3ee9d MD |
396 | if (0 == --scm_async_clock) \ |
397 | scm_async_click (); \ | |
bfc69694 | 398 | } while(0) |
9f0e55a6 MD |
399 | #else |
400 | extern int scm_asyncs_pending_p; | |
401 | ||
402 | #define SCM_ASYNC_TICK /*fixme* should change names */ \ | |
403 | do { \ | |
404 | if (scm_asyncs_pending_p) \ | |
405 | scm_async_click (); \ | |
406 | } while (0) | |
407 | #endif | |
25d3ee9d | 408 | |
216eedfc DH |
409 | #if (SCM_DEBUG_INTERRUPTS == 1) |
410 | #include <stdio.h> | |
0f2d19dd | 411 | #define SCM_CHECK_NOT_DISABLED \ |
216eedfc DH |
412 | do { \ |
413 | if (scm_ints_disabled) \ | |
414 | fprintf(stderr, "ints already disabled (at %s:%d)\n", \ | |
415 | __FILE__, __LINE__); \ | |
416 | } while (0) | |
0f2d19dd JB |
417 | |
418 | #define SCM_CHECK_NOT_ENABLED \ | |
216eedfc DH |
419 | do { \ |
420 | if (!scm_ints_disabled) \ | |
421 | fprintf(stderr, "ints already enabled (at %s:%d)\n", \ | |
422 | __FILE__, __LINE__); \ | |
423 | } while (0) | |
0f2d19dd JB |
424 | |
425 | #else | |
426 | #define SCM_CHECK_NOT_DISABLED | |
427 | #define SCM_CHECK_NOT_ENABLED | |
428 | #endif | |
429 | ||
430 | ||
8417b665 JB |
431 | /* Anthony Green writes: |
432 | When the compiler sees... | |
433 | DEFER_INTS; | |
434 | [critical code here] | |
435 | ALLOW_INTS; | |
436 | ...it doesn't actually promise to keep the critical code within the | |
437 | boundries of the DEFER/ALLOW_INTS instructions. It may very well | |
438 | schedule it outside of the magic defined in those macros. | |
439 | ||
440 | However, GCC's volatile asm feature forms a barrier over which code is | |
441 | never moved. So if you add... | |
35eec738 JB |
442 | asm (""); |
443 | ...to each of the DEFER_INTS and ALLOW_INTS macros, the critical | |
444 | code will always remain in place. asm's without inputs or outputs | |
445 | are implicitly volatile. */ | |
8417b665 | 446 | #ifdef __GNUC__ |
35eec738 | 447 | #define SCM_FENCE asm /* volatile */ ("") |
8417b665 JB |
448 | #else |
449 | #define SCM_FENCE | |
450 | #endif | |
451 | ||
0f2d19dd | 452 | #define SCM_DEFER_INTS \ |
bfc69694 | 453 | do { \ |
8417b665 | 454 | SCM_FENCE; \ |
0f2d19dd | 455 | SCM_CHECK_NOT_DISABLED; \ |
216eedfc | 456 | SCM_CRITICAL_SECTION_START; \ |
8417b665 | 457 | SCM_FENCE; \ |
0f2d19dd | 458 | scm_ints_disabled = 1; \ |
8417b665 | 459 | SCM_FENCE; \ |
bfc69694 | 460 | } while (0) |
0f2d19dd JB |
461 | |
462 | ||
463 | #define SCM_ALLOW_INTS_ONLY \ | |
bfc69694 | 464 | do { \ |
216eedfc | 465 | SCM_CRITICAL_SECTION_END; \ |
0f2d19dd | 466 | scm_ints_disabled = 0; \ |
bfc69694 | 467 | } while (0) |
0f2d19dd JB |
468 | |
469 | ||
470 | #define SCM_ALLOW_INTS \ | |
bfc69694 | 471 | do { \ |
8417b665 | 472 | SCM_FENCE; \ |
0f2d19dd | 473 | SCM_CHECK_NOT_ENABLED; \ |
216eedfc | 474 | SCM_CRITICAL_SECTION_END; \ |
c72cc5fb | 475 | SCM_FENCE; \ |
0f2d19dd | 476 | scm_ints_disabled = 0; \ |
8417b665 | 477 | SCM_FENCE; \ |
216eedfc | 478 | SCM_THREAD_SWITCHING_CODE; \ |
8417b665 | 479 | SCM_FENCE; \ |
bfc69694 | 480 | } while (0) |
0f2d19dd JB |
481 | |
482 | ||
483 | #define SCM_REDEFER_INTS \ | |
bfc69694 | 484 | do { \ |
c72cc5fb | 485 | SCM_FENCE; \ |
216eedfc | 486 | SCM_CRITICAL_SECTION_START; \ |
0f2d19dd | 487 | ++scm_ints_disabled; \ |
c72cc5fb | 488 | SCM_FENCE; \ |
bfc69694 | 489 | } while (0) |
0f2d19dd JB |
490 | |
491 | ||
492 | #define SCM_REALLOW_INTS \ | |
bfc69694 | 493 | do { \ |
c72cc5fb | 494 | SCM_FENCE; \ |
216eedfc | 495 | SCM_CRITICAL_SECTION_END; \ |
c72cc5fb | 496 | SCM_FENCE; \ |
0f2d19dd | 497 | --scm_ints_disabled; \ |
c72cc5fb | 498 | SCM_FENCE; \ |
bfc69694 | 499 | } while (0) |
0f2d19dd JB |
500 | |
501 | ||
c72cc5fb | 502 | #define SCM_TICK \ |
bfc69694 | 503 | do { \ |
cd911565 | 504 | SCM_ASYNC_TICK; \ |
216eedfc | 505 | SCM_THREAD_SWITCHING_CODE; \ |
bfc69694 | 506 | } while (0) |
0f2d19dd JB |
507 | |
508 | \f | |
509 | ||
f83e2737 MD |
510 | /* Classification of critical sections |
511 | * | |
512 | * When Guile moves to POSIX threads, it won't be possible to prevent | |
513 | * context switching. In fact, the whole idea of context switching is | |
514 | * bogus if threads are run by different processors. Therefore, we | |
515 | * must ultimately eliminate all critical sections or enforce them by | |
516 | * use of mutecis. | |
517 | * | |
518 | * All instances of SCM_DEFER_INTS and SCM_ALLOW_INTS should therefore | |
519 | * be classified and replaced by one of the delimiters below. If you | |
520 | * understand what this is all about, I'd like to encourage you to | |
521 | * help with this task. The set of classes below must of course be | |
522 | * incrementally augmented. | |
523 | * | |
524 | * MDJ 980419 <djurfeldt@nada.kth.se> | |
525 | */ | |
526 | ||
527 | /* A sections | |
528 | * | |
529 | * Allocation of a cell with type tag in the CAR. | |
530 | * | |
531 | * With POSIX threads, each thread will have a private pool of free | |
532 | * cells. Therefore, this type of section can be removed. But! It | |
533 | * is important that the CDR is initialized first (with the CAR still | |
534 | * indicating a free cell) so that we can guarantee a consistent heap | |
535 | * at all times. | |
536 | */ | |
537 | ||
216eedfc DH |
538 | #define SCM_ENTER_A_SECTION SCM_CRITICAL_SECTION_START |
539 | #define SCM_EXIT_A_SECTION SCM_CRITICAL_SECTION_END | |
f83e2737 MD |
540 | |
541 | \f | |
542 | ||
0f2d19dd JB |
543 | /** SCM_ASSERT |
544 | ** | |
545 | **/ | |
546 | ||
547 | ||
548 | #ifdef SCM_RECKLESS | |
549 | #define SCM_ASSERT(_cond, _arg, _pos, _subr) | |
23deee81 | 550 | #define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr, _msg) |
0f2d19dd JB |
551 | #define SCM_ASRTGO(_cond, _label) |
552 | #else | |
553 | #define SCM_ASSERT(_cond, _arg, _pos, _subr) \ | |
554 | if (!(_cond)) \ | |
b3fcac34 | 555 | scm_wrong_type_arg (_subr, _pos, _arg) |
b6791b2e GB |
556 | #define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr, _msg) \ |
557 | if (!(_cond)) \ | |
558 | scm_wrong_type_arg_msg(_subr, _pos, _arg, _msg) | |
0f2d19dd JB |
559 | #define SCM_ASRTGO(_cond, _label) \ |
560 | if (!(_cond)) \ | |
561 | goto _label | |
562 | #endif | |
95b88819 | 563 | |
9de33deb MD |
564 | /* |
565 | * SCM_WTA_DISPATCH | |
566 | */ | |
567 | ||
451e591c DH |
568 | /* Dirk:FIXME:: In all of the SCM_WTA_DISPATCH_* macros it is assumed that |
569 | * 'gf' is zero if uninitialized. It would be cleaner if some valid SCM value | |
570 | * like SCM_BOOL_F or SCM_UNDEFINED was chosen. | |
571 | */ | |
572 | ||
b3c8a0f5 MD |
573 | extern SCM scm_call_generic_0 (SCM gf); |
574 | ||
e68fc829 | 575 | #define SCM_WTA_DISPATCH_0(gf, subr) \ |
c07b3fef MD |
576 | return (SCM_UNPACK (gf) \ |
577 | ? scm_call_generic_0 ((gf)) \ | |
e68fc829 MV |
578 | : (scm_error_num_args_subr ((subr)), SCM_UNSPECIFIED)) |
579 | #define SCM_GASSERT0(cond, gf, subr) \ | |
580 | if (!(cond)) SCM_WTA_DISPATCH_0((gf), (subr)) | |
b3c8a0f5 | 581 | |
9de33deb MD |
582 | extern SCM scm_call_generic_1 (SCM gf, SCM a1); |
583 | ||
c07b3fef MD |
584 | #define SCM_WTA_DISPATCH_1(gf, a1, pos, subr) \ |
585 | return (SCM_UNPACK (gf) \ | |
586 | ? scm_call_generic_1 ((gf), (a1)) \ | |
587 | : (scm_wrong_type_arg ((subr), (pos), (a1)), SCM_UNSPECIFIED)) | |
9de33deb MD |
588 | #define SCM_GASSERT1(cond, gf, a1, pos, subr) \ |
589 | if (!(cond)) SCM_WTA_DISPATCH_1((gf), (a1), (pos), (subr)) | |
590 | ||
591 | extern SCM scm_call_generic_2 (SCM gf, SCM a1, SCM a2); | |
592 | ||
c07b3fef MD |
593 | #define SCM_WTA_DISPATCH_2(gf, a1, a2, pos, subr) \ |
594 | return (SCM_UNPACK (gf) \ | |
595 | ? scm_call_generic_2 ((gf), (a1), (a2)) \ | |
596 | : (scm_wrong_type_arg ((subr), (pos), \ | |
597 | (pos) == SCM_ARG1 ? (a1) : (a2)), \ | |
598 | SCM_UNSPECIFIED)) | |
9de33deb MD |
599 | #define SCM_GASSERT2(cond, gf, a1, a2, pos, subr) \ |
600 | if (!(cond)) SCM_WTA_DISPATCH_2((gf), (a1), (a2), (pos), (subr)) | |
601 | ||
89c358b1 MD |
602 | extern SCM scm_apply_generic (SCM gf, SCM args); |
603 | ||
c07b3fef MD |
604 | #define SCM_WTA_DISPATCH_n(gf, args, pos, subr) \ |
605 | return (SCM_UNPACK (gf) \ | |
606 | ? scm_apply_generic ((gf), (args)) \ | |
607 | : (scm_wrong_type_arg ((subr), (pos), \ | |
608 | scm_list_ref ((args), \ | |
609 | SCM_MAKINUM ((pos) - 1))), \ | |
610 | SCM_UNSPECIFIED)) | |
89c358b1 MD |
611 | #define SCM_GASSERTn(cond, gf, args, pos, subr) \ |
612 | if (!(cond)) SCM_WTA_DISPATCH_n((gf), (args), (pos), (subr)) | |
613 | ||
c751e5e3 GB |
614 | #ifndef SCM_MAGIC_SNARFER |
615 | /* Let these macros pass through if | |
616 | we are snarfing; thus we can tell the | |
617 | difference between the use of an actual | |
618 | number vs. the use of one of these macros -- | |
f5421cfc | 619 | actual numbers in SCM_VALIDATE_* and SCM_ASSERT |
c751e5e3 GB |
620 | constructs must match the formal argument name, |
621 | but using SCM_ARG* avoids the test */ | |
622 | ||
0f2d19dd JB |
623 | #define SCM_ARGn 0 |
624 | #define SCM_ARG1 1 | |
625 | #define SCM_ARG2 2 | |
626 | #define SCM_ARG3 3 | |
627 | #define SCM_ARG4 4 | |
628 | #define SCM_ARG5 5 | |
1146b6cd GH |
629 | #define SCM_ARG6 6 |
630 | #define SCM_ARG7 7 | |
0f2d19dd | 631 | |
b63a956d DH |
632 | #if (SCM_DEBUG_DEPRECATED == 0) |
633 | ||
b3fcac34 DH |
634 | /* Use SCM_WRONG_NUM_ARGS instead of: */ |
635 | #define SCM_WNA 8 | |
636 | ||
b63a956d DH |
637 | /* Use SCM_ASSERT_RANGE or SCM_VALIDATE_XXX_RANGE instead of: */ |
638 | #define SCM_OUTOFRANGE 10 | |
639 | ||
640 | /* Use scm_memory_error instead of: */ | |
641 | #define SCM_NALLOC 11 | |
642 | ||
643 | #define SCM_HUP_SIGNAL 14 | |
644 | #define SCM_INT_SIGNAL 15 | |
645 | #define SCM_FPE_SIGNAL 16 | |
646 | #define SCM_BUS_SIGNAL 17 | |
647 | #define SCM_SEGV_SIGNAL 18 | |
648 | #define SCM_ALRM_SIGNAL 19 | |
649 | #define SCM_GC_SIGNAL 20 | |
650 | #define SCM_TICK_SIGNAL 21 | |
651 | #define SCM_SIG_ORD(X) ((X) - SCM_HUP_SIGNAL) | |
652 | #define SCM_ORD_SIG(X) ((X) + SCM_HUP_SIGNAL) | |
653 | #define SCM_NUM_SIGS (SCM_SIG_ORD (SCM_TICK_SIGNAL) + 1) | |
654 | ||
655 | #endif /* SCM_DEBUG_DEPRECATED == 0 */ | |
656 | ||
c751e5e3 | 657 | #endif /* SCM_MAGIC_SNARFER */ |
0f2d19dd | 658 | |
0f2d19dd JB |
659 | \f |
660 | ||
661 | /* SCM_EXIT_SUCCESS is the default code to return from SCM if no errors | |
662 | * were encountered. SCM_EXIT_FAILURE is the default code to return from | |
663 | * SCM if errors were encountered. The return code can be explicitly | |
664 | * specified in a SCM program with (scm_quit <n>). | |
665 | */ | |
666 | ||
667 | #ifndef SCM_EXIT_SUCCESS | |
668 | #ifdef vms | |
669 | #define SCM_EXIT_SUCCESS 1 | |
670 | #else | |
671 | #define SCM_EXIT_SUCCESS 0 | |
672 | #endif /* def vms */ | |
673 | #endif /* ndef SCM_EXIT_SUCCESS */ | |
674 | #ifndef SCM_EXIT_FAILURE | |
675 | #ifdef vms | |
676 | #define SCM_EXIT_FAILURE 2 | |
677 | #else | |
678 | #define SCM_EXIT_FAILURE 1 | |
679 | #endif /* def vms */ | |
680 | #endif /* ndef SCM_EXIT_FAILURE */ | |
681 | ||
0f2d19dd | 682 | \f |
0f2d19dd | 683 | |
729dbac3 | 684 | #endif /* SCM___SCM_H */ |
89e00824 ML |
685 | |
686 | /* | |
687 | Local Variables: | |
688 | c-file-style: "gnu" | |
689 | End: | |
690 | */ |