X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fgeneric%2Futils.lisp;h=38fa31cd57452ab83c6140ef2a2fb75c0c7af069;hb=cd2c70c8b5d4dcc62b968f5a9bedd3c9c8698e82;hp=cd08569462c53f88e070d32667c125d00fdf9a64;hpb=50305b602c3953440af716137a56f50cd204375d;p=sbcl.git diff --git a/src/compiler/generic/utils.lisp b/src/compiler/generic/utils.lisp index cd08569..38fa31c 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. @@ -11,12 +12,11 @@ (in-package "SB!VM") +;;; Make a fixnum out of NUM. (I.e. shift by two bits if it will fit.) (defun fixnumize (num) - #!+sb-doc - "Make a fixnum out of NUM. (i.e. shift by two bits if it will fit.)" (if (<= #x-20000000 num #x1fffffff) (ash num 2) - (error "~D is too big for a fixnum." num))) + (error "~W is too big for a fixnum." num))) ;;;; routines for dealing with static symbols @@ -24,9 +24,8 @@ (or (null symbol) (and (member symbol *static-symbols*) t))) +;;; the byte offset of the static symbol SYMBOL (defun static-symbol-offset (symbol) - #!+sb-doc - "the byte offset of the static symbol SYMBOL" (if symbol (let ((posn (position symbol *static-symbols*))) (unless posn (error "~S is not a static symbol." symbol)) @@ -36,9 +35,8 @@ (- list-pointer-lowtag))) 0)) +;;; Given a byte offset, OFFSET, return the appropriate static symbol. (defun offset-static-symbol (offset) - #!+sb-doc - "Given a byte offset, OFFSET, return the appropriate static symbol." (if (zerop offset) nil (multiple-value-bind (n rem) @@ -46,19 +44,34 @@ (- (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)) + (error "The byte offset ~W is not valid." offset)) (elt *static-symbols* n)))) -(defun static-function-offset (name) - #!+sb-doc - "Return the (byte) offset from NIL to the start of the fdefn object - for the static function NAME." +;;; 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-function-index (position name *static-functions*))) - (unless static-function-index + (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)) (pad-data-block (1- symbol-size)) (- list-pointer-lowtag) - (* static-function-index (pad-data-block fdefn-size)) + (* 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*))))