comparison lisp/emacs-lisp/bytecomp.el @ 27824:52c0cae80495

Change old backquote syntax. (byte-compile-const-symbol-p): New function. (byte-compile-constp, byte-compile-out-toplevel) (byte-compile-form, byte-compile-form, byte-compile-variable-ref): Use it.
author Dave Love <fx@gnu.org>
date Wed, 23 Feb 2000 12:29:05 +0000
parents 2f7978218574
children 8082575fec24
comparison
equal deleted inserted replaced
27823:08c25ce52bef 27824:52c0cae80495
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 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985, 1986, 1987, 1992, 1994, 1998, 2000
4 ;; Free Software Foundation, Inc.
4 5
5 ;; Author: Jamie Zawinski <jwz@lucid.com> 6 ;; Author: Jamie Zawinski <jwz@lucid.com>
6 ;; Hallvard Furuseth <hbf@ulrik.uio.no> 7 ;; Hallvard Furuseth <hbf@ulrik.uio.no>
7 ;; Maintainer: FSF 8 ;; Maintainer: FSF
8 ;; Keywords: lisp 9 ;; Keywords: lisp
9 10
10 ;;; This version incorporates changes up to version 2.10 of the 11 ;;; This version incorporates changes up to version 2.10 of the
11 ;;; Zawinski-Furuseth compiler. 12 ;;; Zawinski-Furuseth compiler.
12 (defconst byte-compile-version "$Revision: 2.61 $") 13 (defconst byte-compile-version "$Revision: 2.62 $")
13 14
14 ;; This file is part of GNU Emacs. 15 ;; This file is part of GNU Emacs.
15 16
16 ;; GNU Emacs is free software; you can redistribute it and/or modify 17 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by 18 ;; it under the terms of the GNU General Public License as published by
1090 (byte-compile-warn "the function %s is not known to be defined." 1091 (byte-compile-warn "the function %s is not known to be defined."
1091 (car (car byte-compile-unresolved-functions))))))) 1092 (car (car byte-compile-unresolved-functions)))))))
1092 nil) 1093 nil)
1093 1094
1094 1095
1096 (defsubst byte-compile-const-symbol-p (symbol)
1097 (or (memq symbol '(nil t))
1098 (keywordp symbol)))
1099
1095 (defmacro byte-compile-constp (form) 1100 (defmacro byte-compile-constp (form)
1096 ;; Returns non-nil if FORM is a constant. 1101 ;; Returns non-nil if FORM is a constant.
1097 (` (cond ((consp (, form)) (eq (car (, form)) 'quote)) 1102 `(cond ((consp ,form) (eq (car ,form) 'quote))
1098 ((not (symbolp (, form)))) 1103 ((not (symbolp ,form)))
1099 ((keywordp (, form))) 1104 ((byte-compile-const-symbol-p ,form))))
1100 ((memq (, form) '(nil t))))))
1101 1105
1102 (defmacro byte-compile-close-variables (&rest body) 1106 (defmacro byte-compile-close-variables (&rest body)
1103 (cons 'let 1107 (cons 'let
1104 (cons '(;; 1108 (cons '(;;
1105 ;; Close over these variables to encapsulate the 1109 ;; Close over these variables to encapsulate the
2211 ((memq (car (car rest)) '(byte-varref byte-constant)) 2215 ((memq (car (car rest)) '(byte-varref byte-constant))
2212 (setq tmp (car (cdr (car rest)))) 2216 (setq tmp (car (cdr (car rest))))
2213 (if (if (eq (car (car rest)) 'byte-constant) 2217 (if (if (eq (car (car rest)) 'byte-constant)
2214 (or (consp tmp) 2218 (or (consp tmp)
2215 (and (symbolp tmp) 2219 (and (symbolp tmp)
2216 (not (memq tmp '(nil t)))))) 2220 (not (byte-compile-const-symbol-p tmp)))))
2217 (if maycall 2221 (if maycall
2218 (setq body (cons (list 'quote tmp) body))) 2222 (setq body (cons (list 'quote tmp) body)))
2219 (setq body (cons tmp body)))) 2223 (setq body (cons tmp body))))
2220 ((and maycall 2224 ((and maycall
2221 ;; Allow a funcall if at most one atom follows it. 2225 ;; Allow a funcall if at most one atom follows it.
2264 ;; (Use byte-compile-form-do-effect to reset the for-effect flag too.) 2268 ;; (Use byte-compile-form-do-effect to reset the for-effect flag too.)
2265 ;; 2269 ;;
2266 (defun byte-compile-form (form &optional for-effect) 2270 (defun byte-compile-form (form &optional for-effect)
2267 (setq form (macroexpand form byte-compile-macro-environment)) 2271 (setq form (macroexpand form byte-compile-macro-environment))
2268 (cond ((not (consp form)) 2272 (cond ((not (consp form))
2269 (cond ((or (not (symbolp form)) (memq form '(nil t))) 2273 (cond ((or (not (symbolp form)) (byte-compile-const-symbol-p form))
2270 (byte-compile-constant form)) 2274 (byte-compile-constant form))
2271 ((and for-effect byte-compile-delete-errors) 2275 ((and for-effect byte-compile-delete-errors)
2272 (setq for-effect nil)) 2276 (setq for-effect nil))
2273 (t (byte-compile-variable-ref 'byte-varref form)))) 2277 (t (byte-compile-variable-ref 'byte-varref form))))
2274 ((symbolp (car form)) 2278 ((symbolp (car form))
2275 (let* ((fn (car form)) 2279 (let* ((fn (car form))
2276 (handler (get fn 'byte-compile))) 2280 (handler (get fn 'byte-compile)))
2277 (if (memq fn '(t nil)) 2281 (if (byte-compile-const-symbol-p fn)
2278 (byte-compile-warn "%s called as a function" fn)) 2282 (byte-compile-warn "%s called as a function" fn))
2279 (if (and handler 2283 (if (and handler
2280 (or (not (byte-compile-version-cond 2284 (or (not (byte-compile-version-cond
2281 byte-compile-compatibility)) 2285 byte-compile-compatibility))
2282 (not (get (get fn 'byte-opcode) 'emacs19-opcode)))) 2286 (not (get (get fn 'byte-opcode) 'emacs19-opcode))))
2301 (byte-compile-push-constant (car form)) 2305 (byte-compile-push-constant (car form))
2302 (mapcar 'byte-compile-form (cdr form)) ; wasteful, but faster. 2306 (mapcar 'byte-compile-form (cdr form)) ; wasteful, but faster.
2303 (byte-compile-out 'byte-call (length (cdr form)))) 2307 (byte-compile-out 'byte-call (length (cdr form))))
2304 2308
2305 (defun byte-compile-variable-ref (base-op var) 2309 (defun byte-compile-variable-ref (base-op var)
2306 (if (or (not (symbolp var)) (memq var '(nil t))) 2310 (if (or (not (symbolp var)) (byte-compile-const-symbol-p var))
2307 (byte-compile-warn (if (eq base-op 'byte-varbind) 2311 (byte-compile-warn (if (eq base-op 'byte-varbind)
2308 "Attempt to let-bind %s %s" 2312 "Attempt to let-bind %s %s"
2309 "Variable reference to %s %s") 2313 "Variable reference to %s %s")
2310 (if (symbolp var) "constant" "nonvariable") 2314 (if (symbolp var) "constant" "nonvariable")
2311 (prin1-to-string var)) 2315 (prin1-to-string var))
2338 (setq tmp (list var) 2342 (setq tmp (list var)
2339 byte-compile-variables (cons tmp byte-compile-variables))) 2343 byte-compile-variables (cons tmp byte-compile-variables)))
2340 (byte-compile-out base-op tmp))) 2344 (byte-compile-out base-op tmp)))
2341 2345
2342 (defmacro byte-compile-get-constant (const) 2346 (defmacro byte-compile-get-constant (const)
2343 (` (or (if (stringp (, const)) 2347 `(or (if (stringp ,const)
2344 (assoc (, const) byte-compile-constants) 2348 (assoc ,const byte-compile-constants)
2345 (assq (, const) byte-compile-constants)) 2349 (assq ,const byte-compile-constants))
2346 (car (setq byte-compile-constants 2350 (car (setq byte-compile-constants
2347 (cons (list (, const)) byte-compile-constants)))))) 2351 (cons (list ,const) byte-compile-constants)))))
2348 2352
2349 ;; Use this when the value of a form is a constant. This obeys for-effect. 2353 ;; Use this when the value of a form is a constant. This obeys for-effect.
2350 (defun byte-compile-constant (const) 2354 (defun byte-compile-constant (const)
2351 (if for-effect 2355 (if for-effect
2352 (setq for-effect nil) 2356 (setq for-effect nil)
2866 (byte-compile-form (nth 1 form) t) 2870 (byte-compile-form (nth 1 form) t)
2867 (byte-compile-form-do-effect (nth 2 form)) 2871 (byte-compile-form-do-effect (nth 2 form))
2868 (byte-compile-body (cdr (cdr (cdr form))) t)) 2872 (byte-compile-body (cdr (cdr (cdr form))) t))
2869 2873
2870 (defmacro byte-compile-goto-if (cond discard tag) 2874 (defmacro byte-compile-goto-if (cond discard tag)
2871 (` (byte-compile-goto 2875 `(byte-compile-goto
2872 (if (, cond) 2876 (if ,cond
2873 (if (, discard) 'byte-goto-if-not-nil 'byte-goto-if-not-nil-else-pop) 2877 (if ,discard 'byte-goto-if-not-nil 'byte-goto-if-not-nil-else-pop)
2874 (if (, discard) 'byte-goto-if-nil 'byte-goto-if-nil-else-pop)) 2878 (if ,discard 'byte-goto-if-nil 'byte-goto-if-nil-else-pop))
2875 (, tag)))) 2879 ,tag))
2876 2880
2877 (defun byte-compile-if (form) 2881 (defun byte-compile-if (form)
2878 (byte-compile-form (car (cdr form))) 2882 (byte-compile-form (car (cdr form)))
2879 (if (null (nthcdr 3 form)) 2883 (if (null (nthcdr 3 form))
2880 ;; No else-forms 2884 ;; No else-forms