1 ;;;; utility functions and macros needed by the back end to generate
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
15 ;;; Make a fixnum out of NUM. (I.e. shift by two bits if it will fit.)
16 (defun fixnumize (num)
18 (ash num (1- n-lowtag-bits))
19 (error "~W 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 ;;; the byte offset of the static symbol SYMBOL
28 (defun static-symbol-offset (symbol)
30 (let ((posn (position symbol *static-symbols*)))
31 (unless posn (error "~S is not a static symbol." symbol))
32 (+ (* posn (pad-data-block symbol-size))
33 (pad-data-block (1- symbol-size))
35 (- list-pointer-lowtag)))
38 ;;; Given a byte offset, OFFSET, return the appropriate static symbol.
39 (defun offset-static-symbol (offset)
42 (multiple-value-bind (n rem)
43 (truncate (+ offset list-pointer-lowtag (- other-pointer-lowtag)
44 (- (pad-data-block (1- symbol-size))))
45 (pad-data-block symbol-size))
46 (unless (and (zerop rem) (<= 0 n (1- (length *static-symbols*))))
47 (error "The byte offset ~W is not valid." offset))
48 (elt *static-symbols* n))))
50 ;;; Return the (byte) offset from NIL to the start of the fdefn object
51 ;;; for the static function NAME.
52 (defun static-fun-offset (name)
53 (let ((static-syms (length *static-symbols*))
54 (static-fun-index (position name *static-funs*)))
55 (unless static-fun-index
56 (error "~S isn't a static function." name))
57 (+ (* static-syms (pad-data-block symbol-size))
58 (pad-data-block (1- symbol-size))
59 (- list-pointer-lowtag)
60 (* static-fun-index (pad-data-block fdefn-size))
61 (* fdefn-raw-addr-slot n-word-bytes))))
63 ;;; Various error-code generating helpers
64 (defvar *adjustable-vectors* nil)
66 (defmacro with-adjustable-vector ((var) &rest body)
67 `(let ((,var (or (pop *adjustable-vectors*)
69 :element-type '(unsigned-byte 8)
72 (declare (type (vector (unsigned-byte 8) 16) ,var))
73 (setf (fill-pointer ,var) 0)
77 (push ,var *adjustable-vectors*))))