(easy-mmode-define-navigation): Put `definition-name' properties on the
[emacs.git] / lisp / emacs-lisp / byte-run.el
blob1ebc8f765fa850d8a4e813a605544249c779809f
1 ;;; byte-run.el --- byte-compiler support for inlining
3 ;; Copyright (C) 1992, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 ;; Author: Jamie Zawinski <jwz@lucid.com>
6 ;; Hallvard Furuseth <hbf@ulrik.uio.no>
7 ;; Maintainer: FSF
8 ;; Keywords: internal
10 ;; This file is part of GNU Emacs.
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.
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.
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., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;;; Commentary:
29 ;; interface to selectively inlining functions.
30 ;; This only happens when source-code optimization is turned on.
32 ;;; Code:
34 ;; We define macro-declaration-function here because it is needed to
35 ;; handle declarations in macro definitions and this is the first file
36 ;; loaded by loadup.el that uses declarations in macros.
38 (defun macro-declaration-function (macro decl)
39 "Process a declaration found in a macro definition.
40 This is set as the value of the variable `macro-declaration-function'.
41 MACRO is the name of the macro being defined.
42 DECL is a list `(declare ...)' containing the declarations.
43 The return value of this function is not used."
44 ;; We can't use `dolist' or `cadr' yet for bootstrapping reasons.
45 (let (d)
46 ;; Ignore the first element of `decl' (it's always `declare').
47 (while (setq decl (cdr decl))
48 (setq d (car decl))
49 (cond ((and (consp d) (eq (car d) 'indent))
50 (put macro 'lisp-indent-function (car (cdr d))))
51 ((and (consp d) (eq (car d) 'debug))
52 (put macro 'edebug-form-spec (car (cdr d))))
53 ((and (consp d) (eq (car d) 'doc-string))
54 (put macro 'doc-string-elt (car (cdr d))))
56 (message "Unknown declaration %s" d))))))
58 (setq macro-declaration-function 'macro-declaration-function)
61 ;; Redefined in byte-optimize.el.
62 ;; This is not documented--it's not clear that we should promote it.
63 (fset 'inline 'progn)
64 (put 'inline 'lisp-indent-function 0)
66 ;;; Interface to inline functions.
68 ;; (defmacro proclaim-inline (&rest fns)
69 ;; "Cause the named functions to be open-coded when called from compiled code.
70 ;; They will only be compiled open-coded when byte-compile-optimize is true."
71 ;; (cons 'eval-and-compile
72 ;; (mapcar '(lambda (x)
73 ;; (or (memq (get x 'byte-optimizer)
74 ;; '(nil byte-compile-inline-expand))
75 ;; (error
76 ;; "%s already has a byte-optimizer, can't make it inline"
77 ;; x))
78 ;; (list 'put (list 'quote x)
79 ;; ''byte-optimizer ''byte-compile-inline-expand))
80 ;; fns)))
82 ;; (defmacro proclaim-notinline (&rest fns)
83 ;; "Cause the named functions to no longer be open-coded."
84 ;; (cons 'eval-and-compile
85 ;; (mapcar '(lambda (x)
86 ;; (if (eq (get x 'byte-optimizer) 'byte-compile-inline-expand)
87 ;; (put x 'byte-optimizer nil))
88 ;; (list 'if (list 'eq (list 'get (list 'quote x) ''byte-optimizer)
89 ;; ''byte-compile-inline-expand)
90 ;; (list 'put x ''byte-optimizer nil)))
91 ;; fns)))
93 ;; This has a special byte-hunk-handler in bytecomp.el.
94 (defmacro defsubst (name arglist &rest body)
95 "Define an inline function. The syntax is just like that of `defun'."
96 (declare (debug defun))
97 (or (memq (get name 'byte-optimizer)
98 '(nil byte-compile-inline-expand))
99 (error "`%s' is a primitive" name))
100 `(prog1
101 (defun ,name ,arglist ,@body)
102 (eval-and-compile
103 (put ',name 'byte-optimizer 'byte-compile-inline-expand))))
105 (defun make-obsolete (obsolete-name current-name &optional when)
106 "Make the byte-compiler warn that OBSOLETE-NAME is obsolete.
107 The warning will say that CURRENT-NAME should be used instead.
108 If CURRENT-NAME is a string, that is the `use instead' message.
109 If provided, WHEN should be a string indicating when the function
110 was first made obsolete, for example a date or a release number."
111 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
112 (let ((handler (get obsolete-name 'byte-compile)))
113 (if (eq 'byte-compile-obsolete handler)
114 (setq handler (nth 1 (get obsolete-name 'byte-obsolete-info)))
115 (put obsolete-name 'byte-compile 'byte-compile-obsolete))
116 (put obsolete-name 'byte-obsolete-info (list current-name handler when)))
117 obsolete-name)
119 (defmacro define-obsolete-function-alias (obsolete-name current-name
120 &optional when docstring)
121 "Set OBSOLETE-NAME's function definition to CURRENT-NAME and mark it obsolete.
123 \(define-obsolete-function-alias 'old-fun 'new-fun \"22.1\" \"old-fun's doc.\")
125 is equivalent to the following two lines of code:
127 \(defalias 'old-fun 'new-fun \"old-fun's doc.\")
128 \(make-obsolete 'old-fun 'new-fun \"22.1\")
130 See the docstrings of `defalias' and `make-obsolete' for more details."
131 (declare (doc-string 4))
132 `(progn
133 (defalias ,obsolete-name ,current-name ,docstring)
134 (make-obsolete ,obsolete-name ,current-name ,when)))
136 (defun make-obsolete-variable (obsolete-name current-name &optional when)
137 "Make the byte-compiler warn that OBSOLETE-NAME is obsolete.
138 The warning will say that CURRENT-NAME should be used instead.
139 If CURRENT-NAME is a string, that is the `use instead' message.
140 If provided, WHEN should be a string indicating when the variable
141 was first made obsolete, for example a date or a release number."
142 (interactive
143 (list
144 (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t)))
145 (if (equal str "") (error ""))
146 (intern str))
147 (car (read-from-string (read-string "Obsoletion replacement: ")))))
148 (put obsolete-name 'byte-obsolete-variable (cons current-name when))
149 obsolete-name)
151 (defmacro define-obsolete-variable-alias (obsolete-name current-name
152 &optional when docstring)
153 "Make OBSOLETE-NAME a variable alias for CURRENT-NAME and mark it obsolete.
155 \(define-obsolete-variable-alias 'old-var 'new-var \"22.1\" \"old-var's doc.\")
157 is equivalent to the following two lines of code:
159 \(defvaralias 'old-var 'new-var \"old-var's doc.\")
160 \(make-obsolete-variable 'old-var 'new-var \"22.1\")
162 See the docstrings of `defvaralias' and `make-obsolete-variable' or
163 Info node `(elisp)Variable Aliases' for more details."
164 (declare (doc-string 4))
165 `(progn
166 (defvaralias ,obsolete-name ,current-name ,docstring)
167 (make-obsolete-variable ,obsolete-name ,current-name ,when)))
169 (defmacro dont-compile (&rest body)
170 "Like `progn', but the body always runs interpreted (not compiled).
171 If you think you need this, you're probably making a mistake somewhere."
172 (declare (debug t) (indent 0))
173 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
176 ;; interface to evaluating things at compile time and/or load time
177 ;; these macro must come after any uses of them in this file, as their
178 ;; definition in the file overrides the magic definitions on the
179 ;; byte-compile-macro-environment.
181 (defmacro eval-when-compile (&rest body)
182 "Like `progn', but evaluates the body at compile time if you're compiling.
183 Thus, the result of the body appears to the compiler as a quoted constant.
184 In interpreted code, this is entirely equivalent to `progn'."
185 (declare (debug t) (indent 0))
186 ;; Not necessary because we have it in b-c-initial-macro-environment
187 ;; (list 'quote (eval (cons 'progn body)))
188 (cons 'progn body))
190 (defmacro eval-and-compile (&rest body)
191 "Like `progn', but evaluates the body at compile time and at load time."
192 (declare (debug t) (indent 0))
193 ;; Remember, it's magic.
194 (cons 'progn body))
196 (put 'with-no-warnings 'lisp-indent-function 0)
197 (defun with-no-warnings (&rest body)
198 "Like `progn', but prevents compiler warnings in the body."
199 ;; The implementation for the interpreter is basically trivial.
200 (car (last body)))
203 ;; I nuked this because it's not a good idea for users to think of using it.
204 ;; These options are a matter of installation preference, and have nothing to
205 ;; with particular source files; it's a mistake to suggest to users
206 ;; they should associate these with particular source files.
207 ;; There is hardly any reason to change these parameters, anyway.
208 ;; --rms.
210 ;; (put 'byte-compiler-options 'lisp-indent-function 0)
211 ;; (defmacro byte-compiler-options (&rest args)
212 ;; "Set some compilation-parameters for this file. This will affect only the
213 ;; file in which it appears; this does nothing when evaluated, and when loaded
214 ;; from a .el file.
216 ;; Each argument to this macro must be a list of a key and a value.
218 ;; Keys: Values: Corresponding variable:
220 ;; verbose t, nil byte-compile-verbose
221 ;; optimize t, nil, source, byte byte-compile-optimize
222 ;; warnings list of warnings byte-compile-warnings
223 ;; Legal elements: (callargs redefine free-vars unresolved)
224 ;; file-format emacs18, emacs19 byte-compile-compatibility
226 ;; For example, this might appear at the top of a source file:
228 ;; (byte-compiler-options
229 ;; (optimize t)
230 ;; (warnings (- free-vars)) ; Don't warn about free variables
231 ;; (file-format emacs19))"
232 ;; nil)
234 ;; arch-tag: 76f8328a-1f66-4df2-9b6d-5c3666dc05e9
235 ;;; byte-run.el ends here