Changeset 11633
- Timestamp:
- 02/06/09 20:51:34 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/compiler-pass2.lisp
r11632 r11633 6207 6207 (list 'INTEGER 0 '*)) 6208 6208 6209 (defmacro when-args-integer (args typenames decls &body body)6210 "Checks types of the args provided, if all args are6211 integer, splits them into high/low bytes and invokes the body.6212 6213 args contains the arguments for which the type check is done.6214 typenames contains names of variables to which the type, low byte6215 and high byte of the provided arg is stored, to be used in6216 the body.6217 decls contains declarations used in the body, similar to let.6218 body is the body to invoke. "6219 (labels ((build-let-when (body args typenames)6220 (when args6221 (let ((type (third typenames))6222 (low (second typenames))6223 (high (first typenames)))6224 (setf body6225 `(let ((,type (derive-compiler-type ,(first args))))6226 (when (integer-type-p ,type)6227 (let ((,low (integer-type-low ,type))6228 (,high (integer-type-high ,type)))6229 ,body)))))6230 (let ((tmpbody6231 (build-let-when body (cdr args) (cdddr typenames))))6232 (if tmpbody6233 tmpbody6234 body)))))6235 (build-let-when6236 `(let (,@decls) ,@body)6237 (reverse args) (reverse typenames))))6238 6239 6209 6240 6210 (defmacro define-int-bounds-derivation (name (low1 high1 low2 high2) … … 6246 6216 (declare (ignorable ,low1 ,high1 ,low2 ,high2)) 6247 6217 ,@body))) 6248 6249 6218 6250 6219 (defun derive-integer-type (op type1 type2) … … 6280 6249 (double-float integer double-float) 6281 6250 (double-float single-float double-float)) 6251 ((ash) 6252 (integer integer ,#'derive-integer-type)) 6282 6253 ((min max) 6283 6254 (integer integer ,#'derive-integer-type) … … 6386 6357 (declaim (ftype (function (t) t) derive-type-max)) 6387 6358 (defun derive-type-max (form) 6388 (dolist (arg (cdr form) (make-compiler-type 'FIXNUM)) 6389 (unless (fixnum-type-p (derive-compiler-type arg)) 6390 (return t)))) 6359 (let ((op (car form)) 6360 (args (cdr form))) 6361 (flet ((combine (x y) 6362 (derive-type-numeric-op op x y))) 6363 (reduce #'combine (cdr args) 6364 :initial-value (car args))))) 6391 6365 6392 6366 (defknown derive-type-min (t) t) 6393 6367 (defun derive-type-min (form) 6394 (let ((args (cdr form)) 6395 (result-type t)) 6396 (when (= (length form) 3) 6397 (when-args-integer 6398 ((%car args) (%cadr args)) 6399 (type1 low1 high1 type2 low2 high2) 6400 (low high) 6401 (setf low (if (and low1 low2) 6402 (min low1 low2) 6403 nil) 6404 high (if (and high1 high2) 6405 (min high1 high2) 6406 nil)) 6407 (setf result-type (%make-integer-type low high)))) 6408 result-type)) 6368 (let ((op (car form)) 6369 (args (cdr form))) 6370 (flet ((combine (x y) 6371 (derive-type-numeric-op op x y))) 6372 (reduce #'combine (cdr args) 6373 :initial-value (car args))))) 6409 6374 6410 6375 ;; read-char &optional input-stream eof-error-p eof-value recursive-p => char … … 6415 6380 t)) 6416 6381 6382 6383 (define-int-bounds-derivation ash (low1 high1 low2 high2) 6384 (when (and low1 high1 low2 high2) 6385 (cond 6386 ((and (>= low1 0) (>= high1 0) (>= low2 0) (>= high2 0)) 6387 ;; Everything is non-negative. 6388 (values (ash low1 low2) 6389 (unless (<= 64 high2) 6390 (ash high1 high2)))) 6391 ((and (>= low1 0) (>= high1 0) (<= low2 0) (<= high2 0)) 6392 ;; Negative (or zero) second argument. 6393 (values (ash low1 low2) 6394 (ash high1 high2)))))) 6395 6417 6396 ;; ash integer count => shifted-integer 6418 6397 (defknown derive-type-ash (t) t) 6419 6398 (defun derive-type-ash (form) 6420 (let* ((args (cdr form)) 6421 (arg1 (first args)) 6422 (arg2 (second args)) 6423 (result-type 'INTEGER)) 6424 (when-args-integer 6425 (arg1 arg2) 6426 (type1 low1 high1 type2 low2 high2) 6427 () 6428 (when (and low1 high1 low2 high2) 6429 (cond ((fixnum-constant-value type2) 6430 (setf arg2 (fixnum-constant-value type2)) 6431 (cond ((<= -64 arg2 64) 6432 (setf result-type 6433 (list 'INTEGER (ash low1 arg2) (ash high1 arg2)))) 6434 ((minusp arg2) 6435 (setf result-type 6436 (list 'INTEGER 6437 (if (minusp low1) -1 0) 6438 (if (minusp high1) -1 0)))))) 6439 ((and (>= low1 0) (>= high1 0) (>= low2 0) (>= high2 0)) 6440 ;; Everything is non-negative. 6441 (setf result-type (list 'INTEGER 6442 (ash low1 low2) 6443 (if (<= 64 high2) 6444 '* (ash high1 high2))))) 6445 ((and (>= low1 0) (>= high1 0) (<= low2 0) (<= high2 0)) 6446 ;; Negative (or zero) second argument. 6447 (setf result-type (list 'INTEGER 6448 (ash low1 low2) 6449 (ash high1 high2))))))) 6450 (make-compiler-type result-type))) 6399 (derive-type-numeric-op (car form) 6400 (derive-compiler-type (cadr form)) 6401 (derive-compiler-type (caddr form)))) 6451 6402 6452 6403 (defknown derive-type (t) t)
Note: See TracChangeset
for help on using the changeset viewer.