9062ed5d6c8858fad45125d14fbc1003109cdca9
[sbcl.git] / src / runtime / runtime.h
1 /*
2  * This software is part of the SBCL system. See the README file for
3  * more information.
4  *
5  * This software is derived from the CMU CL system, which was
6  * written at Carnegie Mellon University and released into the
7  * public domain. The software is in the public domain and is
8  * provided with absolutely no warranty. See the COPYING and CREDITS
9  * files for more information.
10  */
11
12 /* FIXME: Aren't symbols with underscore prefixes supposed to be
13  * reserved for system libraries? Perhaps rename stuff like this
14  * to names like INCLUDED_SBCL_RUNTIME_H. */
15 #ifndef _SBCL_RUNTIME_H_
16 #define _SBCL_RUNTIME_H_
17
18 #define QSHOW 0 /* Enable low-level debugging output? */
19 #if QSHOW
20 #define FSHOW(args) fprintf args
21 #define SHOW(string) FSHOW((stderr, "/%s\n", string))
22 #else
23 #define FSHOW(args)
24 #define SHOW(string)
25 #endif
26
27 /* Enable extra-verbose low-level debugging output for signals? (You
28  * probably don't want this unless you're trying to debug very early
29  * cold boot on a new machine, or one where you've just messed up
30  * signal handling.)
31  *
32  * Note: It may be that doing this is fundamentally unsound, since it
33  * causes output from signal handlers, and the i/o libraries aren't
34  * necessarily reentrant. But it can still be very convenient for
35  * figuring out what's going on when you have a signal handling
36  * problem.. */
37 #define QSHOW_SIGNALS 0
38
39 /* FIXME: There seems to be no reason that LowtagOf can't be defined
40  * as a (possibly inline) function instead of a macro. It would also
41  * be reasonable to rename the constants in ALL CAPS. */
42
43 #define lowtag_Bits 3
44 #define lowtag_Mask ((1<<lowtag_Bits)-1)
45 #define LowtagOf(obj) ((obj)&lowtag_Mask)
46 #define type_Bits 8
47 #define type_Mask ((1<<type_Bits)-1)
48
49 /* FIXME: There seems to be no reason that TypeOf, HeaderValue,
50  * Pointerp, PTR, CONS, SYMBOL, and FDEFN can't be defined
51  * as (possibly inline) functions instead of macros. */
52
53 #define TypeOf(obj) ((obj)&type_Mask)
54 #define HeaderValue(obj) ((unsigned long) ((obj)>>type_Bits))
55
56 #define Pointerp(obj) ((obj) & 0x01)
57 #define PTR(obj) ((unsigned long)((obj)&~lowtag_Mask))
58
59 #define CONS(obj) ((struct cons *)((obj)-type_ListPointer))
60 #define SYMBOL(obj) ((struct symbol *)((obj)-type_OtherPointer))
61 #define FDEFN(obj) ((struct fdefn *)((obj)-type_OtherPointer))
62
63 /* KLUDGE: These are in theory machine-dependent and OS-dependent, but
64  * in practice the "foo int" definitions work for all the machines
65  * that SBCL runs on as of 0.6.7. If we port to the Alpha or some
66  * other non-32-bit machine we'll probably need real machine-dependent
67  * and OS-dependent definitions again. */
68 #if ((defined alpha) && !(defined __linux__))
69 #error No u32,s32 definitions for this platform.  Write some.
70 #else
71 /* int happens to be 4 bytes on linux/alpha.  long is longer. */
72 typedef unsigned int u32;
73 typedef signed int s32;
74 #define LOW_WORD(c) ((long)(c) & 0xFFFFFFFFL)
75 #endif
76
77 typedef u32 lispobj;
78
79 /* FIXME: There seems to be no reason that make_fixnum and fixnum_value
80  * can't be implemented as (possibly inline) functions. */
81 #define make_fixnum(n) ((lispobj)((n)<<2))
82 #define fixnum_value(n) (((long)n)>>2)
83
84 /* Too bad ANSI C doesn't define "bool" as C++ does.. */
85 typedef int boolean;
86
87 /* FIXME: There seems to be no reason that SymbolValue, SetSymbolValue,
88  * and SymbolFunction can't be defined as (possibly inline) functions
89  * instead of macros. */
90
91 #define SymbolValue(sym) \
92     (((struct symbol *)((sym)-type_OtherPointer))->value)
93 #define SetSymbolValue(sym,val) \
94     (((struct symbol *)((sym)-type_OtherPointer))->value = (val))
95
96 /* This only works for static symbols. */
97 /* FIXME: should be called StaticSymbolFunction, right? */
98 #define SymbolFunction(sym) \
99     (((struct fdefn *)(SymbolValue(sym)-type_OtherPointer))->function)
100
101 /* KLUDGE: As far as I can tell there's no ANSI C way of saying
102  * "this function never returns". This is the way that you do it
103  * in GCC later than version 2.7 or so. If you are using some 
104  * compiler that doesn't understand this, you could could just
105  * change it to "typedef void never_returns" and nothing would
106  * break, you might just get a few more bytes of compiled code or
107  * a few more compiler warnings. -- WHN 2000-10-21 */
108 typedef volatile void never_returns;
109
110 #endif /* _SBCL_RUNTIME_H_ */