0.8.9.43:
[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 */ /* Enable low-level debugging output? */
19
20 #ifdef QSHOW
21 #define FSHOW(args) fprintf args
22 #define SHOW(string) FSHOW((stderr, "/%s\n", string))
23 #else
24 #define FSHOW(args)
25 #define SHOW(string)
26 #endif
27
28 /* Enable extra-verbose low-level debugging output for signals? (You
29  * probably don't want this unless you're trying to debug very early
30  * cold boot on a new machine, or one where you've just messed up
31  * signal handling.)
32  *
33  * Note: It may be that doing this is fundamentally unsound, since it
34  * causes output from signal handlers, and the i/o libraries aren't
35  * necessarily reentrant. But it can still be very convenient for
36  * figuring out what's going on when you have a signal handling
37  * problem.. */
38 #define QSHOW_SIGNALS 0
39
40 #define N_LOWTAG_BITS 3
41 #define LOWTAG_MASK ((1<<N_LOWTAG_BITS)-1)
42 #define N_WIDETAG_BITS 8
43 #define WIDETAG_MASK ((1<<N_WIDETAG_BITS)-1)
44
45 /* FIXME: Make HeaderValue, CONS, SYMBOL, and FDEFN into inline
46  * functions instead of macros. */
47
48 #define HeaderValue(obj) ((unsigned long) ((obj) >> N_WIDETAG_BITS))
49
50 #define CONS(obj) ((struct cons *)((obj)-LIST_POINTER_LOWTAG))
51 #define SYMBOL(obj) ((struct symbol *)((obj)-OTHER_POINTER_LOWTAG))
52 #define FDEFN(obj) ((struct fdefn *)((obj)-OTHER_POINTER_LOWTAG))
53
54 /* KLUDGE: These are in theory machine-dependent and OS-dependent, but
55  * in practice the "foo int" definitions work for all the machines
56  * that SBCL runs on as of 0.6.7. If we port to the Alpha or some
57  * other non-32-bit machine we'll probably need real machine-dependent
58  * and OS-dependent definitions again. */
59 /* even on alpha, int happens to be 4 bytes.  long is longer. */
60 typedef unsigned int u32;
61 typedef signed int s32;
62 #define LOW_WORD(c) ((long)(c) & 0xFFFFFFFFL)
63 /* this is an integral type the same length as a machine pointer */
64 typedef unsigned long pointer_sized_uint_t ;
65
66 typedef u32 lispobj;
67
68 static inline int
69 lowtag_of(lispobj obj) {
70     return obj & LOWTAG_MASK;
71 }
72
73 static inline int
74 widetag_of(lispobj obj) {
75     return obj & WIDETAG_MASK;
76 }
77
78 /* Is the Lisp object obj something with pointer nature (as opposed to
79  * e.g. a fixnum or character or unbound marker)? */
80 static inline int
81 is_lisp_pointer(lispobj obj)
82 {
83     return obj & 1;
84 }
85
86 /* Convert from a lispobj with type bits to a native (ordinary
87  * C/assembly) pointer to the beginning of the object. */
88 static inline lispobj *
89 native_pointer(lispobj obj)
90 {
91     return (lispobj *) ((pointer_sized_uint_t) (obj & ~LOWTAG_MASK));
92 }
93 /* inverse operation: create a suitably tagged lispobj from a native
94  * pointer or integer.  Needs to be a macro due to the tedious C type
95  * system */
96 #define make_lispobj(o,low_tag) ((lispobj)(LOW_WORD(o)|low_tag))
97
98 /* FIXME: There seems to be no reason that make_fixnum and fixnum_value
99  * can't be implemented as (possibly inline) functions. */
100 #define make_fixnum(n) ((lispobj)((n)<<2))
101 #define fixnum_value(n) (((long)n)>>2)
102
103 /* Too bad ANSI C doesn't define "bool" as C++ does.. */
104 typedef int boolean;
105
106 /* FIXME: There seems to be no reason that SymbolFunction can't be
107  * defined as (possibly inline) functions instead of macros. */
108
109 static inline lispobj SymbolValue(u32 sym, void *thread);
110 static inline void SetSymbolValue(u32 sym, lispobj val, void *thread);
111 /* This only works for static symbols. */
112 /* FIXME: should be called StaticSymbolFunction, right? */
113 #define SymbolFunction(sym) \
114     (((struct fdefn *)(native_pointer(SymbolValue(sym,0))))->fun)
115
116 /* KLUDGE: As far as I can tell there's no ANSI C way of saying
117  * "this function never returns". This is the way that you do it
118  * in GCC later than version 2.7 or so. If you are using some 
119  * compiler that doesn't understand this, you could could just
120  * change it to "typedef void never_returns" and nothing would
121  * break, though you might get a few more bytes of compiled code or
122  * a few more compiler warnings. -- WHN 2000-10-21 */
123 typedef volatile void never_returns;
124
125 #endif /* _SBCL_RUNTIME_H_ */