b97a15f9102316949301c196d22df65014d6bff0
[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 /* KLUDGE: These are in theory machine-dependent and OS-dependent, but
41  * in practice the "foo int" definitions work for all the machines
42  * that SBCL runs on as of 0.6.7. If we port to the Alpha or some
43  * other non-32-bit machine we'll probably need real machine-dependent
44  * and OS-dependent definitions again. */
45 /* even on alpha, int happens to be 4 bytes.  long is longer. */
46 /* FIXME: these names really shouldn't reflect their length and this
47    is not quite right for some of the FFI stuff */
48 typedef unsigned long u64;
49 typedef signed long s64;
50 typedef unsigned int u32;
51 typedef signed int s32;
52
53 /* this is an integral type the same length as a machine pointer */
54 typedef unsigned long pointer_sized_uint_t ;
55
56 #include <sys/types.h>
57
58 #if defined(LISP_FEATURE_SB_THREAD)
59 #include <pthread.h>
60 typedef pthread_t os_thread_t;
61 #else
62 typedef pid_t os_thread_t;
63 #endif
64
65 /* FIXME: we do things this way because of the alpha32 port.  once
66    alpha64 has arrived, all this nastiness can go away */
67 #if 64 == N_WORD_BITS
68 #define LOW_WORD(c) ((pointer_sized_uint_t)c)
69 typedef unsigned long lispobj;
70 #else
71 #define LOW_WORD(c) ((long)(c) & 0xFFFFFFFFL)
72 /* fake it on alpha32 */
73 typedef unsigned int lispobj;
74 #endif
75
76 static inline int
77 lowtag_of(lispobj obj) {
78     return obj & LOWTAG_MASK;
79 }
80
81 static inline int
82 widetag_of(lispobj obj) {
83     return obj & WIDETAG_MASK;
84 }
85
86 static inline unsigned long
87 HeaderValue(lispobj obj)
88 {
89   return obj >> N_WIDETAG_BITS;
90 }
91
92 static inline struct cons *
93 CONS(lispobj obj)
94 {
95   return (struct cons *)(obj - LIST_POINTER_LOWTAG);
96 }
97
98 static inline struct symbol *
99 SYMBOL(lispobj obj)
100 {
101   return (struct symbol *)(obj - OTHER_POINTER_LOWTAG);
102 }
103
104 static inline struct fdefn *
105 FDEFN(lispobj obj)
106 {
107   return (struct fdefn *)(obj - OTHER_POINTER_LOWTAG);
108 }
109
110 /* Is the Lisp object obj something with pointer nature (as opposed to
111  * e.g. a fixnum or character or unbound marker)? */
112 static inline int
113 is_lisp_pointer(lispobj obj)
114 {
115     return obj & 1;
116 }
117
118 /* Convert from a lispobj with type bits to a native (ordinary
119  * C/assembly) pointer to the beginning of the object. */
120 static inline lispobj *
121 native_pointer(lispobj obj)
122 {
123     return (lispobj *) ((pointer_sized_uint_t) (obj & ~LOWTAG_MASK));
124 }
125 /* inverse operation: create a suitably tagged lispobj from a native
126  * pointer or integer.  Needs to be a macro due to the tedious C type
127  * system */
128 #define make_lispobj(o,low_tag) ((lispobj)(LOW_WORD(o)|low_tag))
129
130 /* FIXME: There seems to be no reason that make_fixnum and fixnum_value
131  * can't be implemented as (possibly inline) functions. */
132 #define make_fixnum(n) ((lispobj)((n)<<N_FIXNUM_TAG_BITS))
133 #define fixnum_value(n) (((long)n)>>N_FIXNUM_TAG_BITS)
134
135 /* Too bad ANSI C doesn't define "bool" as C++ does.. */
136 typedef int boolean;
137
138 /* This only works for static symbols. */
139 /* FIXME: should be called StaticSymbolFunction, right? */
140 #define SymbolFunction(sym) \
141     (((struct fdefn *)(native_pointer(SymbolValue(sym,0))))->fun)
142
143 /* KLUDGE: As far as I can tell there's no ANSI C way of saying
144  * "this function never returns". This is the way that you do it
145  * in GCC later than version 2.7 or so. If you are using some
146  * compiler that doesn't understand this, you could could just
147  * change it to "typedef void never_returns" and nothing would
148  * break, though you might get a few more bytes of compiled code or
149  * a few more compiler warnings. -- WHN 2000-10-21 */
150 typedef volatile void never_returns;
151
152 #endif /* _SBCL_RUNTIME_H_ */