0.pre7.58:
[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 #define N_LOWTAG_BITS 3
40 #define LOWTAG_MASK ((1<<N_LOWTAG_BITS)-1)
41 #define N_WIDETAG_BITS 8
42 #define WIDETAG_MASK ((1<<N_WIDETAG_BITS)-1)
43
44 /* FIXME: Make HeaderValue, CONS, SYMBOL, and FDEFN into inline
45  * functions instead of macros. */
46
47 #define HeaderValue(obj) ((unsigned long) ((obj) >> N_WIDETAG_BITS))
48
49 #define CONS(obj) ((struct cons *)((obj)-LIST_POINTER_LOWTAG))
50 #define SYMBOL(obj) ((struct symbol *)((obj)-OTHER_POINTER_LOWTAG))
51 #define FDEFN(obj) ((struct fdefn *)((obj)-OTHER_POINTER_LOWTAG))
52
53 /* KLUDGE: These are in theory machine-dependent and OS-dependent, but
54  * in practice the "foo int" definitions work for all the machines
55  * that SBCL runs on as of 0.6.7. If we port to the Alpha or some
56  * other non-32-bit machine we'll probably need real machine-dependent
57  * and OS-dependent definitions again. */
58 #if ((defined alpha) && !(defined __linux__))
59 #error No u32,s32 definitions for this platform.  Write some.
60 #else
61 /* int happens to be 4 bytes on linux/alpha.  long is longer. */
62 typedef unsigned int u32;
63 typedef signed int s32;
64 #define LOW_WORD(c) ((long)(c) & 0xFFFFFFFFL)
65 #endif
66
67 typedef u32 lispobj;
68
69 static inline int
70 lowtag_of(lispobj obj) {
71     return obj & LOWTAG_MASK;
72 }
73
74 static inline int
75 widetag_of(lispobj obj) {
76     return obj & WIDETAG_MASK;
77 }
78
79 /* Is the Lisp object obj something with pointer nature (as opposed to
80  * e.g. a fixnum or character or unbound marker)? */
81 static inline int
82 is_lisp_pointer(lispobj obj)
83 {
84     return obj & 1;
85 }
86
87 /* Convert from a lispobj with type bits to a native (ordinary
88  * C/assembly) pointer to the beginning of the object. */
89 static inline lispobj
90 native_pointer(lispobj obj)
91 {
92     return obj & ~LOWTAG_MASK;
93 }
94
95 /* FIXME: There seems to be no reason that make_fixnum and fixnum_value
96  * can't be implemented as (possibly inline) functions. */
97 #define make_fixnum(n) ((lispobj)((n)<<2))
98 #define fixnum_value(n) (((long)n)>>2)
99
100 /* Too bad ANSI C doesn't define "bool" as C++ does.. */
101 typedef int boolean;
102
103 /* FIXME: There seems to be no reason that SymbolValue, SetSymbolValue,
104  * and SymbolFunction can't be defined as (possibly inline) functions
105  * instead of macros. */
106
107 #define SymbolValue(sym) \
108     (((struct symbol *)((sym)-OTHER_POINTER_LOWTAG))->value)
109 #define SetSymbolValue(sym,val) \
110     (((struct symbol *)((sym)-OTHER_POINTER_LOWTAG))->value = (val))
111
112 /* This only works for static symbols. */
113 /* FIXME: should be called StaticSymbolFunction, right? */
114 #define SymbolFunction(sym) \
115     (((struct fdefn *)(SymbolValue(sym)-OTHER_POINTER_LOWTAG))->fun)
116
117 /* KLUDGE: As far as I can tell there's no ANSI C way of saying
118  * "this function never returns". This is the way that you do it
119  * in GCC later than version 2.7 or so. If you are using some 
120  * compiler that doesn't understand this, you could could just
121  * change it to "typedef void never_returns" and nothing would
122  * break, though you might get a few more bytes of compiled code or
123  * a few more compiler warnings. -- WHN 2000-10-21 */
124 typedef volatile void never_returns;
125
126 #endif /* _SBCL_RUNTIME_H_ */