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.
14 (defun fixnumize (num)
16 "Make a fixnum out of NUM. (i.e. shift by two bits if it will fit.)"
17 (if (<= #x-20000000 num #x1fffffff)
19 (error "~D is too big for a fixnum." num)))
21 ;;;; routines for dealing with static symbols
23 (defun static-symbol-p (symbol)
25 (and (member symbol *static-symbols*) t)))
27 (defun static-symbol-offset (symbol)
29 "the byte offset of the static symbol SYMBOL"
31 (let ((posn (position symbol *static-symbols*)))
32 (unless posn (error "~S is not a static symbol." symbol))
33 (+ (* posn (pad-data-block symbol-size))
34 (pad-data-block (1- symbol-size))
36 (- list-pointer-type)))
39 (defun offset-static-symbol (offset)
41 "Given a byte offset, OFFSET, return the appropriate static symbol."
44 (multiple-value-bind (n rem)
45 (truncate (+ offset list-pointer-type (- other-pointer-type)
46 (- (pad-data-block (1- symbol-size))))
47 (pad-data-block symbol-size))
48 (unless (and (zerop rem) (<= 0 n (1- (length *static-symbols*))))
49 (error "The byte offset ~D is not valid." offset))
50 (elt *static-symbols* n))))
52 (defun static-function-offset (name)
54 "Return the (byte) offset from NIL to the start of the fdefn object
55 for the static function NAME."
56 (let ((static-syms (length *static-symbols*))
57 (static-function-index (position name *static-functions*)))
58 (unless static-function-index
59 (error "~S isn't a static function." name))
60 (+ (* static-syms (pad-data-block symbol-size))
61 (pad-data-block (1- symbol-size))
63 (* static-function-index (pad-data-block fdefn-size))
64 (* fdefn-raw-addr-slot word-bytes))))