2 * This software is part of the SBCL system. See the README file for
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.
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_
18 #define QSHOW 0 /* Enable low-level debugging output? */
20 #define FSHOW(args) fprintf args
21 #define SHOW(string) FSHOW((stderr, "/%s\n", string))
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
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
37 #define QSHOW_SIGNALS 0
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)
44 /* FIXME: Make HeaderValue, CONS, SYMBOL, and FDEFN into inline
45 * functions instead of macros. */
47 #define HeaderValue(obj) ((unsigned long) ((obj) >> N_WIDETAG_BITS))
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))
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 /* even on alpha, int happens to be 4 bytes. long is longer. */
59 typedef unsigned int u32;
60 typedef signed int s32;
61 #define LOW_WORD(c) ((long)(c) & 0xFFFFFFFFL)
62 /* this is an integral type the same length as a machine pointer */
63 typedef unsigned long pointer_sized_uint_t ;
68 lowtag_of(lispobj obj) {
69 return obj & LOWTAG_MASK;
73 widetag_of(lispobj obj) {
74 return obj & WIDETAG_MASK;
77 /* Is the Lisp object obj something with pointer nature (as opposed to
78 * e.g. a fixnum or character or unbound marker)? */
80 is_lisp_pointer(lispobj obj)
85 /* Convert from a lispobj with type bits to a native (ordinary
86 * C/assembly) pointer to the beginning of the object. */
87 static inline lispobj *
88 native_pointer(lispobj obj)
90 return (lispobj *) ((pointer_sized_uint_t) (obj & ~LOWTAG_MASK));
92 /* inverse operation: create a suitably tagged lispobj from a native
93 * pointer or integer. Needs to be a macro due to the tedious C type
95 #define make_lispobj(o,low_tag) ((lispobj)(LOW_WORD(o)|low_tag))
97 /* FIXME: There seems to be no reason that make_fixnum and fixnum_value
98 * can't be implemented as (possibly inline) functions. */
99 #define make_fixnum(n) ((lispobj)((n)<<2))
100 #define fixnum_value(n) (((long)n)>>2)
102 /* Too bad ANSI C doesn't define "bool" as C++ does.. */
105 /* FIXME: There seems to be no reason that SymbolFunction can't be
106 * defined as (possibly inline) functions instead of macros. */
108 static inline lispobj SymbolValue(u32 sym, void *thread);
109 static inline void SetSymbolValue(u32 sym, lispobj val, void *thread);
110 /* This only works for static symbols. */
111 /* FIXME: should be called StaticSymbolFunction, right? */
112 #define SymbolFunction(sym) \
113 (((struct fdefn *)(native_pointer(SymbolValue(sym,0))))->fun)
115 /* KLUDGE: As far as I can tell there's no ANSI C way of saying
116 * "this function never returns". This is the way that you do it
117 * in GCC later than version 2.7 or so. If you are using some
118 * compiler that doesn't understand this, you could could just
119 * change it to "typedef void never_returns" and nothing would
120 * break, though you might get a few more bytes of compiled code or
121 * a few more compiler warnings. -- WHN 2000-10-21 */
122 typedef volatile void never_returns;
124 #endif /* _SBCL_RUNTIME_H_ */