Mercurial > emacs
comparison lisp/emacs-lisp/bytecomp.el @ 86003:e33327200372
* emacs-lisp/byte-opt.el (byte-optimize-featurep): Optimize
(featurep 'emacs) to t.
* emacs-lisp/bytecomp.el (byte-compile-find-bound-condition): New
function.
(byte-compile-maybe-guarded): Use it to also look for bound
symbols inside `and' forms. Comment out non-working code that was
trying to avoid warnings for XEmacs code.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Sat, 10 Nov 2007 08:05:15 +0000 |
parents | 89ba7e228a5b |
children | fadd23918501 880960b70474 |
comparison
equal
deleted
inserted
replaced
86002:613df1ba1584 | 86003:e33327200372 |
---|---|
3490 (if ,cond | 3490 (if ,cond |
3491 (if ,discard 'byte-goto-if-not-nil 'byte-goto-if-not-nil-else-pop) | 3491 (if ,discard 'byte-goto-if-not-nil 'byte-goto-if-not-nil-else-pop) |
3492 (if ,discard 'byte-goto-if-nil 'byte-goto-if-nil-else-pop)) | 3492 (if ,discard 'byte-goto-if-nil 'byte-goto-if-nil-else-pop)) |
3493 ,tag)) | 3493 ,tag)) |
3494 | 3494 |
3495 ;; Return the list of items in CONDITION-PARAM that match PRED-LIST. | |
3496 ;; Only return items that are not in ONLY-IF-NOT-PRESENT. | |
3497 (defun byte-compile-find-bound-condition (condition-param | |
3498 pred-list | |
3499 &optional only-if-not-present) | |
3500 (let ((result nil) | |
3501 (nth-one nil) | |
3502 (cond-list | |
3503 (if (memq (car-safe condition-param) pred-list) | |
3504 ;; The condition appears by itself. | |
3505 (list condition-param) | |
3506 ;; If the condition is an `and', look for matches among the | |
3507 ;; `and' arguments. | |
3508 (when (eq 'and (car-safe condition-param)) | |
3509 (cdr condition-param))))) | |
3510 | |
3511 (dolist (crt cond-list) | |
3512 (when (and (memq (car-safe crt) pred-list) | |
3513 (eq 'quote (car-safe (setq nth-one (nth 1 crt)))) | |
3514 ;; Ignore if the symbol is already on the unresolved | |
3515 ;; list. | |
3516 (not (assq (nth 1 nth-one) ; the relevant symbol | |
3517 only-if-not-present))) | |
3518 (push (nth 1 (nth 1 crt)) result))) | |
3519 result)) | |
3520 | |
3495 (defmacro byte-compile-maybe-guarded (condition &rest body) | 3521 (defmacro byte-compile-maybe-guarded (condition &rest body) |
3496 "Execute forms in BODY, potentially guarded by CONDITION. | 3522 "Execute forms in BODY, potentially guarded by CONDITION. |
3497 CONDITION is a variable whose value is a test in an `if' or `cond'. | 3523 CONDITION is a variable whose value is a test in an `if' or `cond'. |
3498 BODY is the code to compile first arm of the if or the body of the | 3524 BODY is the code to compile first arm of the if or the body of the |
3499 cond clause. If CONDITION's value is of the form (fboundp 'foo) | 3525 cond clause. If CONDITION's value is of the form (fboundp 'foo) |
3501 being undefined will be suppressed. | 3527 being undefined will be suppressed. |
3502 | 3528 |
3503 If CONDITION's value is (not (featurep 'emacs)) or (featurep 'xemacs), | 3529 If CONDITION's value is (not (featurep 'emacs)) or (featurep 'xemacs), |
3504 that suppresses all warnings during execution of BODY." | 3530 that suppresses all warnings during execution of BODY." |
3505 (declare (indent 1) (debug t)) | 3531 (declare (indent 1) (debug t)) |
3506 `(let* ((fbound | 3532 `(let* ((fbound-list (byte-compile-find-bound-condition |
3507 (if (eq 'fboundp (car-safe ,condition)) | 3533 ,condition (list 'fboundp) |
3508 (and (eq 'quote (car-safe (nth 1 ,condition))) | 3534 byte-compile-unresolved-functions)) |
3509 ;; Ignore if the symbol is already on the | 3535 (bound-list (byte-compile-find-bound-condition |
3510 ;; unresolved list. | 3536 ,condition (list 'boundp 'default-boundp))) |
3511 (not (assq (nth 1 (nth 1 ,condition)) ; the relevant symbol | |
3512 byte-compile-unresolved-functions)) | |
3513 (nth 1 (nth 1 ,condition))))) | |
3514 (bound (if (or (eq 'boundp (car-safe ,condition)) | |
3515 (eq 'default-boundp (car-safe ,condition))) | |
3516 (and (eq 'quote (car-safe (nth 1 ,condition))) | |
3517 (nth 1 (nth 1 ,condition))))) | |
3518 ;; Maybe add to the bound list. | 3537 ;; Maybe add to the bound list. |
3519 (byte-compile-bound-variables | 3538 (byte-compile-bound-variables |
3520 (if bound | 3539 (if bound-list |
3521 (cons bound byte-compile-bound-variables) | 3540 (append bound-list byte-compile-bound-variables) |
3522 byte-compile-bound-variables)) | 3541 byte-compile-bound-variables)) |
3523 ;; Suppress all warnings, for code not used in Emacs. | 3542 ;; Suppress all warnings, for code not used in Emacs. |
3524 (byte-compile-warnings | 3543 ;; FIXME: by the time this is executed the `featurep' |
3525 (if (member ,condition '((featurep 'xemacs) | 3544 ;; emacs/xemacs tests have been optimized away, so this is |
3526 (not (featurep 'emacs)))) | 3545 ;; not doing anything useful here, is should probably be |
3527 nil byte-compile-warnings))) | 3546 ;; moved to a different place. |
3547 ;; (byte-compile-warnings | |
3548 ;; (if (member ,condition '((featurep 'xemacs) | |
3549 ;; (not (featurep 'emacs)))) | |
3550 ;; nil byte-compile-warnings)) | |
3551 ) | |
3528 (unwind-protect | 3552 (unwind-protect |
3529 (progn ,@body) | 3553 (progn ,@body) |
3530 ;; Maybe remove the function symbol from the unresolved list. | 3554 ;; Maybe remove the function symbol from the unresolved list. |
3531 (if fbound | 3555 (dolist (fbound fbound-list) |
3556 (when fbound | |
3532 (setq byte-compile-unresolved-functions | 3557 (setq byte-compile-unresolved-functions |
3533 (delq (assq fbound byte-compile-unresolved-functions) | 3558 (delq (assq fbound byte-compile-unresolved-functions) |
3534 byte-compile-unresolved-functions)))))) | 3559 byte-compile-unresolved-functions))))))) |
3535 | 3560 |
3536 (defun byte-compile-if (form) | 3561 (defun byte-compile-if (form) |
3537 (byte-compile-form (car (cdr form))) | 3562 (byte-compile-form (car (cdr form))) |
3538 ;; Check whether we have `(if (fboundp ...' or `(if (boundp ...' | 3563 ;; Check whether we have `(if (fboundp ...' or `(if (boundp ...' |
3539 ;; and avoid warnings about the relevent symbols in the consequent. | 3564 ;; and avoid warnings about the relevent symbols in the consequent. |