X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fgeneric%2Futils.lisp;h=7095f61f079ace77542c03953145b703b9fbec5c;hb=63f714af62d0ccdb9d4a793ab0245b036c3d8531;hp=f690caa1ddb9d521bee9cfa9d7609feab0bbc2cd;hpb=f43f136f9b3ff6cae501e850fa67b2183317e212;p=sbcl.git diff --git a/src/compiler/generic/utils.lisp b/src/compiler/generic/utils.lisp index f690caa..7095f61 100644 --- a/src/compiler/generic/utils.lisp +++ b/src/compiler/generic/utils.lisp @@ -1,4 +1,5 @@ -;;;; utility functions needed by the back end to generate code +;;;; utility functions and macros needed by the back end to generate +;;;; code ;;;; This software is part of the SBCL system. See the README file for ;;;; more information. @@ -13,9 +14,9 @@ ;;; Make a fixnum out of NUM. (I.e. shift by two bits if it will fit.) (defun fixnumize (num) - (if (<= #x-20000000 num #x1fffffff) - (ash num 2) - (error "~D is too big for a fixnum." num))) + (if (fixnump num) + (ash num (1- n-lowtag-bits)) + (error "~W is too big for a fixnum." num))) ;;;; routines for dealing with static symbols @@ -27,11 +28,11 @@ (defun static-symbol-offset (symbol) (if symbol (let ((posn (position symbol *static-symbols*))) - (unless posn (error "~S is not a static symbol." symbol)) - (+ (* posn (pad-data-block symbol-size)) - (pad-data-block (1- symbol-size)) - other-pointer-lowtag - (- list-pointer-lowtag))) + (unless posn (error "~S is not a static symbol." symbol)) + (+ (* posn (pad-data-block symbol-size)) + (pad-data-block (1- symbol-size)) + other-pointer-lowtag + (- list-pointer-lowtag))) 0)) ;;; Given a byte offset, OFFSET, return the appropriate static symbol. @@ -39,18 +40,18 @@ (if (zerop offset) nil (multiple-value-bind (n rem) - (truncate (+ offset list-pointer-lowtag (- other-pointer-lowtag) - (- (pad-data-block (1- symbol-size)))) - (pad-data-block symbol-size)) - (unless (and (zerop rem) (<= 0 n (1- (length *static-symbols*)))) - (error "The byte offset ~D is not valid." offset)) - (elt *static-symbols* n)))) + (truncate (+ offset list-pointer-lowtag (- other-pointer-lowtag) + (- (pad-data-block (1- symbol-size)))) + (pad-data-block symbol-size)) + (unless (and (zerop rem) (<= 0 n (1- (length *static-symbols*)))) + (error "The byte offset ~W is not valid." offset)) + (elt *static-symbols* n)))) ;;; Return the (byte) offset from NIL to the start of the fdefn object ;;; for the static function NAME. (defun static-fun-offset (name) (let ((static-syms (length *static-symbols*)) - (static-fun-index (position name *static-funs*))) + (static-fun-index (position name *static-funs*))) (unless static-fun-index (error "~S isn't a static function." name)) (+ (* static-syms (pad-data-block symbol-size)) @@ -58,3 +59,19 @@ (- list-pointer-lowtag) (* static-fun-index (pad-data-block fdefn-size)) (* fdefn-raw-addr-slot n-word-bytes)))) + +;;; Various error-code generating helpers +(defvar *adjustable-vectors* nil) + +(defmacro with-adjustable-vector ((var) &rest body) + `(let ((,var (or (pop *adjustable-vectors*) + (make-array 16 + :element-type '(unsigned-byte 8) + :fill-pointer 0 + :adjustable t)))) + (declare (type (vector (unsigned-byte 8) 16) ,var)) + (setf (fill-pointer ,var) 0) + (unwind-protect + (progn + ,@body) + (push ,var *adjustable-vectors*))))