Mercurial > emacs
annotate lisp/emacs-lisp/byte-run.el @ 61913:caa98288a9da
*** empty log message ***
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Thu, 28 Apr 2005 11:54:11 +0000 |
parents | a158628ce6ac |
children | 39ca2515a39d 08185296b491 |
rev | line source |
---|---|
51349 | 1 ;;; byte-run.el --- byte-compiler support for inlining |
2 | |
60580
a7bed417c2e6
Replace lisp-indent-hook with lisp-indent-function throughout.
Lute Kamstra <lute@gnu.org>
parents:
55405
diff
changeset
|
3 ;; Copyright (C) 1992, 2004, 2005 Free Software Foundation, Inc. |
51349 | 4 |
5 ;; Author: Jamie Zawinski <jwz@lucid.com> | |
6 ;; Hallvard Furuseth <hbf@ulrik.uio.no> | |
7 ;; Maintainer: FSF | |
8 ;; Keywords: internal | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; interface to selectively inlining functions. | |
30 ;; This only happens when source-code optimization is turned on. | |
31 | |
32 ;;; Code: | |
33 | |
60597
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
34 ;; We define macro-declaration-function here because it is needed to |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
35 ;; handle declarations in macro definitions and this is the first file |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
36 ;; loaded by loadup.el that uses declarations in macros. |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
37 |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
38 (defun macro-declaration-function (macro decl) |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
39 "Process a declaration found in a macro definition. |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
40 This is set as the value of the variable `macro-declaration-function'. |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
41 MACRO is the name of the macro being defined. |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
42 DECL is a list `(declare ...)' containing the declarations. |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
43 The return value of this function is not used." |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
44 ;; We can't use `dolist' or `cadr' yet for bootstrapping reasons. |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
45 (let (d) |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
46 ;; Ignore the first element of `decl' (it's always `declare'). |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
47 (while (setq decl (cdr decl)) |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
48 (setq d (car decl)) |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
49 (cond ((and (consp d) (eq (car d) 'indent)) |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
50 (put macro 'lisp-indent-function (car (cdr d)))) |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
51 ((and (consp d) (eq (car d) 'debug)) |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
52 (put macro 'edebug-form-spec (car (cdr d)))) |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
53 (t |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
54 (message "Unknown declaration %s" d)))))) |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
55 |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
56 (setq macro-declaration-function 'macro-declaration-function) |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
57 |
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
58 |
51349 | 59 ;; Redefined in byte-optimize.el. |
60 ;; This is not documented--it's not clear that we should promote it. | |
61 (fset 'inline 'progn) | |
60580
a7bed417c2e6
Replace lisp-indent-hook with lisp-indent-function throughout.
Lute Kamstra <lute@gnu.org>
parents:
55405
diff
changeset
|
62 (put 'inline 'lisp-indent-function 0) |
51349 | 63 |
64 ;;; Interface to inline functions. | |
65 | |
66 ;; (defmacro proclaim-inline (&rest fns) | |
67 ;; "Cause the named functions to be open-coded when called from compiled code. | |
68 ;; They will only be compiled open-coded when byte-compile-optimize is true." | |
69 ;; (cons 'eval-and-compile | |
70 ;; (mapcar '(lambda (x) | |
71 ;; (or (memq (get x 'byte-optimizer) | |
72 ;; '(nil byte-compile-inline-expand)) | |
73 ;; (error | |
74 ;; "%s already has a byte-optimizer, can't make it inline" | |
75 ;; x)) | |
76 ;; (list 'put (list 'quote x) | |
77 ;; ''byte-optimizer ''byte-compile-inline-expand)) | |
78 ;; fns))) | |
79 | |
80 ;; (defmacro proclaim-notinline (&rest fns) | |
81 ;; "Cause the named functions to no longer be open-coded." | |
82 ;; (cons 'eval-and-compile | |
83 ;; (mapcar '(lambda (x) | |
84 ;; (if (eq (get x 'byte-optimizer) 'byte-compile-inline-expand) | |
85 ;; (put x 'byte-optimizer nil)) | |
86 ;; (list 'if (list 'eq (list 'get (list 'quote x) ''byte-optimizer) | |
87 ;; ''byte-compile-inline-expand) | |
88 ;; (list 'put x ''byte-optimizer nil))) | |
89 ;; fns))) | |
90 | |
91 ;; This has a special byte-hunk-handler in bytecomp.el. | |
92 (defmacro defsubst (name arglist &rest body) | |
93 "Define an inline function. The syntax is just like that of `defun'." | |
54496
94bcfb39cf49
(defsubst): Add edebug spec and use backquote.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54413
diff
changeset
|
94 (declare (debug defun)) |
51349 | 95 (or (memq (get name 'byte-optimizer) |
96 '(nil byte-compile-inline-expand)) | |
97 (error "`%s' is a primitive" name)) | |
54496
94bcfb39cf49
(defsubst): Add edebug spec and use backquote.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54413
diff
changeset
|
98 `(prog1 |
94bcfb39cf49
(defsubst): Add edebug spec and use backquote.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54413
diff
changeset
|
99 (defun ,name ,arglist ,@body) |
94bcfb39cf49
(defsubst): Add edebug spec and use backquote.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54413
diff
changeset
|
100 (eval-and-compile |
94bcfb39cf49
(defsubst): Add edebug spec and use backquote.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54413
diff
changeset
|
101 (put ',name 'byte-optimizer 'byte-compile-inline-expand)))) |
51349 | 102 |
55405
79eecb3f0e5a
(make-obsolete, make-obsolete-variable): Make argument names match their use in
Juanma Barranquero <lekktu@gmail.com>
parents:
55041
diff
changeset
|
103 (defun make-obsolete (function new &optional when) |
51349 | 104 "Make the byte-compiler warn that FUNCTION is obsolete. |
105 The warning will say that NEW should be used instead. | |
106 If NEW is a string, that is the `use instead' message. | |
107 If provided, WHEN should be a string indicating when the function | |
108 was first made obsolete, for example a date or a release number." | |
109 (interactive "aMake function obsolete: \nxObsoletion replacement: ") | |
55405
79eecb3f0e5a
(make-obsolete, make-obsolete-variable): Make argument names match their use in
Juanma Barranquero <lekktu@gmail.com>
parents:
55041
diff
changeset
|
110 (let ((handler (get function 'byte-compile))) |
51349 | 111 (if (eq 'byte-compile-obsolete handler) |
55405
79eecb3f0e5a
(make-obsolete, make-obsolete-variable): Make argument names match their use in
Juanma Barranquero <lekktu@gmail.com>
parents:
55041
diff
changeset
|
112 (setq handler (nth 1 (get function 'byte-obsolete-info))) |
79eecb3f0e5a
(make-obsolete, make-obsolete-variable): Make argument names match their use in
Juanma Barranquero <lekktu@gmail.com>
parents:
55041
diff
changeset
|
113 (put function 'byte-compile 'byte-compile-obsolete)) |
79eecb3f0e5a
(make-obsolete, make-obsolete-variable): Make argument names match their use in
Juanma Barranquero <lekktu@gmail.com>
parents:
55041
diff
changeset
|
114 (put function 'byte-obsolete-info (list new handler when))) |
79eecb3f0e5a
(make-obsolete, make-obsolete-variable): Make argument names match their use in
Juanma Barranquero <lekktu@gmail.com>
parents:
55041
diff
changeset
|
115 function) |
51349 | 116 |
61843
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
117 (defmacro define-obsolete-function-alias (function new |
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
118 &optional when docstring) |
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
119 "Set FUNCTION's function definition to NEW and warn that FUNCTION is obsolete. |
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
120 If provided, WHEN should be a string indicating when FUNCTION was |
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
121 first made obsolete, for example a date or a release number. The |
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
122 optional argument DOCSTRING specifies the documentation string |
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
123 for FUNCTION; if DOCSTRING is omitted or nil, FUNCTION uses the |
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
124 documentation string of NEW unluess it already has one." |
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
125 `(progn |
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
126 (defalias ,function ,new ,docstring) |
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
127 (make-obsolete ,function ,new ,when))) |
a158628ce6ac
(define-obsolete-function-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
61730
diff
changeset
|
128 |
55405
79eecb3f0e5a
(make-obsolete, make-obsolete-variable): Make argument names match their use in
Juanma Barranquero <lekktu@gmail.com>
parents:
55041
diff
changeset
|
129 (defun make-obsolete-variable (variable new &optional when) |
54413
9d42c2c9095d
(make-obsolete-variable): Fix docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
130 "Make the byte-compiler warn that VARIABLE is obsolete. |
9d42c2c9095d
(make-obsolete-variable): Fix docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
131 The warning will say that NEW should be used instead. |
9d42c2c9095d
(make-obsolete-variable): Fix docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
132 If NEW is a string, that is the `use instead' message. |
51349 | 133 If provided, WHEN should be a string indicating when the variable |
134 was first made obsolete, for example a date or a release number." | |
135 (interactive | |
136 (list | |
137 (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t))) | |
138 (if (equal str "") (error "")) | |
139 (intern str)) | |
140 (car (read-from-string (read-string "Obsoletion replacement: "))))) | |
55405
79eecb3f0e5a
(make-obsolete, make-obsolete-variable): Make argument names match their use in
Juanma Barranquero <lekktu@gmail.com>
parents:
55041
diff
changeset
|
141 (put variable 'byte-obsolete-variable (cons new when)) |
79eecb3f0e5a
(make-obsolete, make-obsolete-variable): Make argument names match their use in
Juanma Barranquero <lekktu@gmail.com>
parents:
55041
diff
changeset
|
142 variable) |
51349 | 143 |
61730
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
144 (defmacro define-obsolete-variable-alias (variable new |
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
145 &optional when docstring) |
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
146 "Make VARIABLE a variable alias for NEW and warn that VARIABLE is obsolete. |
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
147 If provided, WHEN should be a string indicating when VARIABLE was |
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
148 first made obsolete, for example a date or a release number. The |
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
149 optional argument DOCSTRING specifies the documentation string |
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
150 for VARIABLE; if DOCSTRING is omitted or nil, VARIABLE uses the |
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
151 documentation string of NEW unless it already has one." |
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
152 `(progn |
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
153 (defvaralias ,variable ,new ,docstring) |
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
154 (make-obsolete-variable ,variable ,new ,when))) |
d4e4e1694bf8
(define-obsolete-variable-alias): New macro.
Nick Roberts <nickrob@snap.net.nz>
parents:
60597
diff
changeset
|
155 |
51349 | 156 (defmacro dont-compile (&rest body) |
157 "Like `progn', but the body always runs interpreted (not compiled). | |
158 If you think you need this, you're probably making a mistake somewhere." | |
60597
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
159 (declare (debug t) (indent 0)) |
51349 | 160 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body))))) |
161 | |
162 | |
163 ;;; interface to evaluating things at compile time and/or load time | |
164 ;;; these macro must come after any uses of them in this file, as their | |
165 ;;; definition in the file overrides the magic definitions on the | |
166 ;;; byte-compile-macro-environment. | |
167 | |
168 (defmacro eval-when-compile (&rest body) | |
169 "Like `progn', but evaluates the body at compile time. | |
170 The result of the body appears to the compiler as a quoted constant." | |
60597
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
171 (declare (debug t) (indent 0)) |
51349 | 172 ;; Not necessary because we have it in b-c-initial-macro-environment |
173 ;; (list 'quote (eval (cons 'progn body))) | |
174 (cons 'progn body)) | |
175 | |
176 (defmacro eval-and-compile (&rest body) | |
177 "Like `progn', but evaluates the body at compile time and at load time." | |
60597
e9f1d42f7fc0
(macro-declaration-function): Move from subr.el.
Lute Kamstra <lute@gnu.org>
parents:
60580
diff
changeset
|
178 (declare (debug t) (indent 0)) |
51349 | 179 ;; Remember, it's magic. |
180 (cons 'progn body)) | |
181 | |
60580
a7bed417c2e6
Replace lisp-indent-hook with lisp-indent-function throughout.
Lute Kamstra <lute@gnu.org>
parents:
55405
diff
changeset
|
182 (put 'with-no-warnings 'lisp-indent-function 0) |
55041
1376729a93a7
(with-no-warnings): Simplify: take all args as &rest arg.
Richard M. Stallman <rms@gnu.org>
parents:
54496
diff
changeset
|
183 (defun with-no-warnings (&rest body) |
51349 | 184 "Like `progn', but prevents compiler warnings in the body." |
185 ;; The implementation for the interpreter is basically trivial. | |
55041
1376729a93a7
(with-no-warnings): Simplify: take all args as &rest arg.
Richard M. Stallman <rms@gnu.org>
parents:
54496
diff
changeset
|
186 (car (last body))) |
51349 | 187 |
188 | |
189 ;;; I nuked this because it's not a good idea for users to think of using it. | |
190 ;;; These options are a matter of installation preference, and have nothing to | |
191 ;;; with particular source files; it's a mistake to suggest to users | |
192 ;;; they should associate these with particular source files. | |
193 ;;; There is hardly any reason to change these parameters, anyway. | |
194 ;;; --rms. | |
195 | |
60580
a7bed417c2e6
Replace lisp-indent-hook with lisp-indent-function throughout.
Lute Kamstra <lute@gnu.org>
parents:
55405
diff
changeset
|
196 ;; (put 'byte-compiler-options 'lisp-indent-function 0) |
51349 | 197 ;; (defmacro byte-compiler-options (&rest args) |
198 ;; "Set some compilation-parameters for this file. This will affect only the | |
199 ;; file in which it appears; this does nothing when evaluated, and when loaded | |
200 ;; from a .el file. | |
201 ;; | |
202 ;; Each argument to this macro must be a list of a key and a value. | |
203 ;; | |
204 ;; Keys: Values: Corresponding variable: | |
205 ;; | |
206 ;; verbose t, nil byte-compile-verbose | |
207 ;; optimize t, nil, source, byte byte-compile-optimize | |
208 ;; warnings list of warnings byte-compile-warnings | |
209 ;; Legal elements: (callargs redefine free-vars unresolved) | |
210 ;; file-format emacs18, emacs19 byte-compile-compatibility | |
211 ;; | |
212 ;; For example, this might appear at the top of a source file: | |
213 ;; | |
214 ;; (byte-compiler-options | |
215 ;; (optimize t) | |
216 ;; (warnings (- free-vars)) ; Don't warn about free variables | |
217 ;; (file-format emacs19))" | |
218 ;; nil) | |
219 | |
52401 | 220 ;;; arch-tag: 76f8328a-1f66-4df2-9b6d-5c3666dc05e9 |
51349 | 221 ;;; byte-run.el ends here |