comparison lisp/emacs-lisp/bytecomp.el @ 83353:532e0a9335a9

Merged in changes from CVS trunk. Plus added lisp/term tweaks. Patches applied: * lorentey@elte.hu--2004/emacs--cvs-trunk--0--base-0 tag of miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-474 * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-1 Add CVS metadata files. * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-2 Update from CVS. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-393
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 04 Sep 2005 03:48:17 +0000
parents 6c13700d1c13 5b1a238fcbb4
children b31326248cf6
comparison
equal deleted inserted replaced
83352:b258b3492423 83353:532e0a9335a9
1 ;;; bytecomp.el --- compilation of Lisp code into byte code 1 ;;; bytecomp.el --- compilation of Lisp code into byte code
2 2
3 ;; Copyright (C) 1985, 1986, 1987, 1992, 1994, 1998, 2000, 2001, 2002, 3 ;; Copyright (C) 1985, 1986, 1987, 1992, 1994, 1998, 2000, 2001, 2002,
4 ;; 2003, 2004, 2005 Free Software Foundation, Inc. 4 ;; 2003, 2004, 2005 Free Software Foundation, Inc.
5 5
6 ;; Author: Jamie Zawinski <jwz@lucid.com> 6 ;; Author: Jamie Zawinski <jwz@lucid.com>
7 ;; Hallvard Furuseth <hbf@ulrik.uio.no> 7 ;; Hallvard Furuseth <hbf@ulrik.uio.no>
8 ;; Maintainer: FSF 8 ;; Maintainer: FSF
9 ;; Keywords: lisp 9 ;; Keywords: lisp
356 (const obsolete) (const noruntime) 356 (const obsolete) (const noruntime)
357 (const cl-functions) (const interactive-only)))) 357 (const cl-functions) (const interactive-only))))
358 358
359 (defvar byte-compile-interactive-only-functions 359 (defvar byte-compile-interactive-only-functions
360 '(beginning-of-buffer end-of-buffer replace-string replace-regexp 360 '(beginning-of-buffer end-of-buffer replace-string replace-regexp
361 insert-file) 361 insert-file insert-buffer insert-file-literally)
362 "List of commands that are not meant to be called from Lisp.") 362 "List of commands that are not meant to be called from Lisp.")
363 363
364 (defvar byte-compile-not-obsolete-var nil 364 (defvar byte-compile-not-obsolete-var nil
365 "If non-nil, this is a variable that shouldn't be reported as obsolete.") 365 "If non-nil, this is a variable that shouldn't be reported as obsolete.")
366 366
3349 (if ,discard 'byte-goto-if-nil 'byte-goto-if-nil-else-pop)) 3349 (if ,discard 'byte-goto-if-nil 'byte-goto-if-nil-else-pop))
3350 ,tag)) 3350 ,tag))
3351 3351
3352 (defmacro byte-compile-maybe-guarded (condition &rest body) 3352 (defmacro byte-compile-maybe-guarded (condition &rest body)
3353 "Execute forms in BODY, potentially guarded by CONDITION. 3353 "Execute forms in BODY, potentially guarded by CONDITION.
3354 CONDITION is the test in an `if' form or in a `cond' clause. 3354 CONDITION is a variable whose value is a test in an `if' or `cond'.
3355 BODY is to compile the first arm of the if or the body of the 3355 BODY is the code to compile first arm of the if or the body of the
3356 cond clause. If CONDITION is of the form `(foundp 'foo)' 3356 cond clause. If CONDITION's value is of the form (fboundp 'foo)
3357 or `(boundp 'foo)', the relevant warnings from BODY about foo 3357 or (boundp 'foo), the relevant warnings from BODY about foo's
3358 being undefined will be suppressed." 3358 being undefined will be suppressed.
3359
3360 If CONDITION's value is (not (featurep 'emacs)) or (featurep 'xemacs),
3361 that suppresses all warnings during execution of BODY."
3359 (declare (indent 1) (debug t)) 3362 (declare (indent 1) (debug t))
3360 `(let* ((fbound 3363 `(let* ((fbound
3361 (if (eq 'fboundp (car-safe ,condition)) 3364 (if (eq 'fboundp (car-safe ,condition))
3362 (and (eq 'quote (car-safe (nth 1 ,condition))) 3365 (and (eq 'quote (car-safe (nth 1 ,condition)))
3363 ;; Ignore if the symbol is already on the 3366 ;; Ignore if the symbol is already on the
3371 (nth 1 (nth 1 ,condition))))) 3374 (nth 1 (nth 1 ,condition)))))
3372 ;; Maybe add to the bound list. 3375 ;; Maybe add to the bound list.
3373 (byte-compile-bound-variables 3376 (byte-compile-bound-variables
3374 (if bound 3377 (if bound
3375 (cons bound byte-compile-bound-variables) 3378 (cons bound byte-compile-bound-variables)
3376 byte-compile-bound-variables))) 3379 byte-compile-bound-variables))
3377 (progn ,@body) 3380 ;; Suppress all warnings, for code not used in Emacs.
3378 ;; Maybe remove the function symbol from the unresolved list. 3381 (byte-compile-warnings
3379 (if fbound 3382 (if (member ,condition '((featurep 'xemacs)
3380 (setq byte-compile-unresolved-functions 3383 (not (featurep 'emacs))))
3381 (delq (assq fbound byte-compile-unresolved-functions) 3384 nil byte-compile-warnings)))
3382 byte-compile-unresolved-functions))))) 3385 (unwind-protect
3386 (progn ,@body)
3387 ;; Maybe remove the function symbol from the unresolved list.
3388 (if fbound
3389 (setq byte-compile-unresolved-functions
3390 (delq (assq fbound byte-compile-unresolved-functions)
3391 byte-compile-unresolved-functions))))))
3383 3392
3384 (defun byte-compile-if (form) 3393 (defun byte-compile-if (form)
3385 (byte-compile-form (car (cdr form))) 3394 (byte-compile-form (car (cdr form)))
3386 ;; Check whether we have `(if (fboundp ...' or `(if (boundp ...' 3395 ;; Check whether we have `(if (fboundp ...' or `(if (boundp ...'
3387 ;; and avoid warnings about the relevent symbols in the consequent. 3396 ;; and avoid warnings about the relevent symbols in the consequent.
3398 (byte-compile-goto 'byte-goto-if-nil elsetag) 3407 (byte-compile-goto 'byte-goto-if-nil elsetag)
3399 (byte-compile-maybe-guarded clause 3408 (byte-compile-maybe-guarded clause
3400 (byte-compile-form (nth 2 form) for-effect)) 3409 (byte-compile-form (nth 2 form) for-effect))
3401 (byte-compile-goto 'byte-goto donetag) 3410 (byte-compile-goto 'byte-goto donetag)
3402 (byte-compile-out-tag elsetag) 3411 (byte-compile-out-tag elsetag)
3403 (byte-compile-body (cdr (cdr (cdr form))) for-effect) 3412 (byte-compile-maybe-guarded (list 'not clause)
3413 (byte-compile-body (cdr (cdr (cdr form))) for-effect))
3404 (byte-compile-out-tag donetag)))) 3414 (byte-compile-out-tag donetag))))
3405 (setq for-effect nil)) 3415 (setq for-effect nil))
3406 3416
3407 (defun byte-compile-cond (clauses) 3417 (defun byte-compile-cond (clauses)
3408 (let ((donetag (byte-compile-make-tag)) 3418 (let ((donetag (byte-compile-make-tag))
3418 ((cdr clauses) 3428 ((cdr clauses)
3419 (byte-compile-form (car clause)) 3429 (byte-compile-form (car clause))
3420 (if (null (cdr clause)) 3430 (if (null (cdr clause))
3421 ;; First clause is a singleton. 3431 ;; First clause is a singleton.
3422 (byte-compile-goto-if t for-effect donetag) 3432 (byte-compile-goto-if t for-effect donetag)
3423 (setq nexttag (byte-compile-make-tag)) 3433 (setq nexttag (byte-compile-make-tag))
3424 (byte-compile-goto 'byte-goto-if-nil nexttag) 3434 (byte-compile-goto 'byte-goto-if-nil nexttag)
3425 (byte-compile-maybe-guarded (car clause) 3435 (byte-compile-maybe-guarded (car clause)
3426 (byte-compile-body (cdr clause) for-effect)) 3436 (byte-compile-body (cdr clause) for-effect))
3427 (byte-compile-goto 'byte-goto donetag) 3437 (byte-compile-goto 'byte-goto donetag)
3428 (byte-compile-out-tag nexttag))))) 3438 (byte-compile-out-tag nexttag)))))
3429 ;; Last clause 3439 ;; Last clause
3430 (let ((guard (car clause))) 3440 (let ((guard (car clause)))
3431 (and (cdr clause) (not (eq guard t)) 3441 (and (cdr clause) (not (eq guard t))
3432 (progn (byte-compile-form guard) 3442 (progn (byte-compile-form guard)
3433 (byte-compile-goto-if nil for-effect donetag) 3443 (byte-compile-goto-if nil for-effect donetag)
3439 (defun byte-compile-and (form) 3449 (defun byte-compile-and (form)
3440 (let ((failtag (byte-compile-make-tag)) 3450 (let ((failtag (byte-compile-make-tag))
3441 (args (cdr form))) 3451 (args (cdr form)))
3442 (if (null args) 3452 (if (null args)
3443 (byte-compile-form-do-effect t) 3453 (byte-compile-form-do-effect t)
3444 (while (cdr args) 3454 (byte-compile-and-recursion args failtag))))
3445 (byte-compile-form (car args)) 3455
3456 ;; Handle compilation of a nontrivial `and' call.
3457 ;; We use tail recursion so we can use byte-compile-maybe-guarded.
3458 (defun byte-compile-and-recursion (rest failtag)
3459 (if (cdr rest)
3460 (progn
3461 (byte-compile-form (car rest))
3446 (byte-compile-goto-if nil for-effect failtag) 3462 (byte-compile-goto-if nil for-effect failtag)
3447 (setq args (cdr args))) 3463 (byte-compile-maybe-guarded (car rest)
3448 (byte-compile-form-do-effect (car args)) 3464 (byte-compile-and-recursion (cdr rest) failtag)))
3449 (byte-compile-out-tag failtag)))) 3465 (byte-compile-form-do-effect (car rest))
3466 (byte-compile-out-tag failtag)))
3450 3467
3451 (defun byte-compile-or (form) 3468 (defun byte-compile-or (form)
3452 (let ((wintag (byte-compile-make-tag)) 3469 (let ((wintag (byte-compile-make-tag))
3453 (args (cdr form))) 3470 (args (cdr form)))
3454 (if (null args) 3471 (if (null args)
3455 (byte-compile-form-do-effect nil) 3472 (byte-compile-form-do-effect nil)
3456 (while (cdr args) 3473 (byte-compile-or-recursion args wintag))))
3457 (byte-compile-form (car args)) 3474
3475 ;; Handle compilation of a nontrivial `or' call.
3476 ;; We use tail recursion so we can use byte-compile-maybe-guarded.
3477 (defun byte-compile-or-recursion (rest wintag)
3478 (if (cdr rest)
3479 (progn
3480 (byte-compile-form (car rest))
3458 (byte-compile-goto-if t for-effect wintag) 3481 (byte-compile-goto-if t for-effect wintag)
3459 (setq args (cdr args))) 3482 (byte-compile-maybe-guarded (list 'not (car rest))
3460 (byte-compile-form-do-effect (car args)) 3483 (byte-compile-or-recursion (cdr rest) wintag)))
3461 (byte-compile-out-tag wintag)))) 3484 (byte-compile-form-do-effect (car rest))
3485 (byte-compile-out-tag wintag)))
3462 3486
3463 (defun byte-compile-while (form) 3487 (defun byte-compile-while (form)
3464 (let ((endtag (byte-compile-make-tag)) 3488 (let ((endtag (byte-compile-make-tag))
3465 (looptag (byte-compile-make-tag))) 3489 (looptag (byte-compile-make-tag)))
3466 (byte-compile-out-tag looptag) 3490 (byte-compile-out-tag looptag)
3764 3788
3765 (byte-defop-compiler-1 with-no-warnings byte-compile-no-warnings) 3789 (byte-defop-compiler-1 with-no-warnings byte-compile-no-warnings)
3766 (defun byte-compile-no-warnings (form) 3790 (defun byte-compile-no-warnings (form)
3767 (let (byte-compile-warnings) 3791 (let (byte-compile-warnings)
3768 (byte-compile-form (cons 'progn (cdr form))))) 3792 (byte-compile-form (cons 'progn (cdr form)))))
3793
3794 ;; Warn about misuses of make-variable-buffer-local.
3795 (byte-defop-compiler-1 make-variable-buffer-local byte-compile-make-variable-buffer-local)
3796 (defun byte-compile-make-variable-buffer-local (form)
3797 (if (eq (car-safe (car-safe (cdr-safe form))) 'quote)
3798 (byte-compile-warn
3799 "`make-variable-buffer-local' should be called at toplevel"))
3800 (byte-compile-normal-call form))
3801 (put 'make-variable-buffer-local
3802 'byte-hunk-handler 'byte-compile-form-make-variable-buffer-local)
3803 (defun byte-compile-form-make-variable-buffer-local (form)
3804 (byte-compile-keep-pending form 'byte-compile-normal-call))
3805
3769 3806
3770 ;;; tags 3807 ;;; tags
3771 3808
3772 ;; Note: Most operations will strip off the 'TAG, but it speeds up 3809 ;; Note: Most operations will strip off the 'TAG, but it speeds up
3773 ;; optimization to have the 'TAG as a part of the tag. 3810 ;; optimization to have the 'TAG as a part of the tag.