1 ;;;; utility functions needed by the back end to generate code
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
17 (defun fixnumize (num)
19 "Make a fixnum out of NUM. (i.e. shift by two bits if it will fit.)"
20 (if (<= #x-20000000 num #x1fffffff)
22 (error "~D is too big for a fixnum." num)))
24 ;;;; routines for dealing with static symbols
26 (defun static-symbol-p (symbol)
28 (and (member symbol *static-symbols*) t)))
30 (defun static-symbol-offset (symbol)
32 "the byte offset of the static symbol SYMBOL"
34 (let ((posn (position symbol *static-symbols*)))
35 (unless posn (error "~S is not a static symbol." symbol))
36 (+ (* posn (pad-data-block symbol-size))
37 (pad-data-block (1- symbol-size))
39 (- list-pointer-type)))
42 (defun offset-static-symbol (offset)
44 "Given a byte offset, OFFSET, return the appropriate static symbol."
47 (multiple-value-bind (n rem)
48 (truncate (+ offset list-pointer-type (- other-pointer-type)
49 (- (pad-data-block (1- symbol-size))))
50 (pad-data-block symbol-size))
51 (unless (and (zerop rem) (<= 0 n (1- (length *static-symbols*))))
52 (error "The byte offset ~D is not valid." offset))
53 (elt *static-symbols* n))))
55 (defun static-function-offset (name)
57 "Return the (byte) offset from NIL to the start of the fdefn object
58 for the static function NAME."
59 (let ((static-syms (length *static-symbols*))
60 (static-function-index (position name *static-functions*)))
61 (unless static-function-index
62 (error "~S isn't a static function." name))
63 (+ (* static-syms (pad-data-block symbol-size))
64 (pad-data-block (1- symbol-size))
66 (* static-function-index (pad-data-block fdefn-size))
67 (* fdefn-raw-addr-slot word-bytes))))