(reduce, fill, replace, remove*, remove-if, remove-if-not, delete*, delete-if,
[bpt/emacs.git] / lisp / emacs-lisp / byte-run.el
CommitLineData
5e046f6d
JB
1;;; byte-run.el --- byte-compiler support for inlining
2
3fdfb09c 3;; Copyright (C) 1992, 2004, 2005 Free Software Foundation, Inc.
5e046f6d
JB
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
623374a5
LK
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.
37
38(defun macro-declaration-function (macro decl)
39 "Process a declaration found in a macro definition.
40This is set as the value of the variable `macro-declaration-function'.
41MACRO is the name of the macro being defined.
42DECL is a list `(declare ...)' containing the declarations.
43The 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 (t
54 (message "Unknown declaration %s" d))))))
55
56(setq macro-declaration-function 'macro-declaration-function)
57
58\f
5e046f6d
JB
59;; Redefined in byte-optimize.el.
60;; This is not documented--it's not clear that we should promote it.
61(fset 'inline 'progn)
3fdfb09c 62(put 'inline 'lisp-indent-function 0)
5e046f6d 63
5e046f6d
JB
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'."
66599b54 94 (declare (debug defun))
5e046f6d
JB
95 (or (memq (get name 'byte-optimizer)
96 '(nil byte-compile-inline-expand))
97 (error "`%s' is a primitive" name))
66599b54
SM
98 `(prog1
99 (defun ,name ,arglist ,@body)
100 (eval-and-compile
101 (put ',name 'byte-optimizer 'byte-compile-inline-expand))))
5e046f6d 102
506b7753 103(defun make-obsolete (function new &optional when)
5e046f6d
JB
104 "Make the byte-compiler warn that FUNCTION is obsolete.
105The warning will say that NEW should be used instead.
106If NEW is a string, that is the `use instead' message.
107If provided, WHEN should be a string indicating when the function
108was first made obsolete, for example a date or a release number."
109 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
506b7753 110 (let ((handler (get function 'byte-compile)))
5e046f6d 111 (if (eq 'byte-compile-obsolete handler)
506b7753
JB
112 (setq handler (nth 1 (get function 'byte-obsolete-info)))
113 (put function 'byte-compile 'byte-compile-obsolete))
114 (put function 'byte-obsolete-info (list new handler when)))
115 function)
5e046f6d 116
0448b476
NR
117(defmacro define-obsolete-function-alias (function new
118 &optional when docstring)
342ef03d
LT
119 "Set FUNCTION's function definition to NEW and mark it obsolete.
120
121\(define-obsolete-function-alias 'old-fun 'new-fun \"22.1\" \"old-fun's doc.\")
122
123is equivalent to the following two lines of code:
124
125\(defalias 'old-fun 'new-fun \"old-fun's doc.\")
126\(make-obsolete 'old-fun 'new-fun \"22.1\")
127
128See the docstrings of `defalias' and `make-obsolete' for more details."
0448b476
NR
129 `(progn
130 (defalias ,function ,new ,docstring)
131 (make-obsolete ,function ,new ,when)))
132
506b7753 133(defun make-obsolete-variable (variable new &optional when)
7ab91c5f
JB
134 "Make the byte-compiler warn that VARIABLE is obsolete.
135The warning will say that NEW should be used instead.
136If NEW is a string, that is the `use instead' message.
5e046f6d
JB
137If provided, WHEN should be a string indicating when the variable
138was first made obsolete, for example a date or a release number."
139 (interactive
140 (list
141 (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t)))
142 (if (equal str "") (error ""))
143 (intern str))
144 (car (read-from-string (read-string "Obsoletion replacement: ")))))
506b7753
JB
145 (put variable 'byte-obsolete-variable (cons new when))
146 variable)
5e046f6d 147
f7f8f37a
NR
148(defmacro define-obsolete-variable-alias (variable new
149 &optional when docstring)
342ef03d
LT
150 "Make VARIABLE a variable alias for NEW and mark it obsolete.
151
152\(define-obsolete-variable-alias 'old-var 'new-var \"22.1\" \"old-var's doc.\")
153
154is equivalent to the following two lines of code:
155
156\(defvaralias 'old-var 'new-var \"old-var's doc.\")
157\(make-obsolete-variable 'old-var 'new-var \"22.1\")
158
159See the docstrings of `defvaralias' and `make-obsolete-variable' or
160Info node `(elisp)Variable Aliases' for more details."
f7f8f37a
NR
161 `(progn
162 (defvaralias ,variable ,new ,docstring)
163 (make-obsolete-variable ,variable ,new ,when)))
164
5e046f6d
JB
165(defmacro dont-compile (&rest body)
166 "Like `progn', but the body always runs interpreted (not compiled).
167If you think you need this, you're probably making a mistake somewhere."
623374a5 168 (declare (debug t) (indent 0))
5e046f6d
JB
169 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
170
171\f
172;;; interface to evaluating things at compile time and/or load time
173;;; these macro must come after any uses of them in this file, as their
174;;; definition in the file overrides the magic definitions on the
175;;; byte-compile-macro-environment.
176
5e046f6d 177(defmacro eval-when-compile (&rest body)
8cd567b8
RS
178 "Like `progn', but evaluates the body at compile time if you're compiling.
179Thus, the result of the body appears to the compiler as a quoted constant.
180In interpreted code, this is entirely equivalent to `progn'."
623374a5 181 (declare (debug t) (indent 0))
5e046f6d
JB
182 ;; Not necessary because we have it in b-c-initial-macro-environment
183 ;; (list 'quote (eval (cons 'progn body)))
184 (cons 'progn body))
185
5e046f6d
JB
186(defmacro eval-and-compile (&rest body)
187 "Like `progn', but evaluates the body at compile time and at load time."
623374a5 188 (declare (debug t) (indent 0))
5e046f6d
JB
189 ;; Remember, it's magic.
190 (cons 'progn body))
191
3fdfb09c 192(put 'with-no-warnings 'lisp-indent-function 0)
ae122ad2 193(defun with-no-warnings (&rest body)
5e046f6d
JB
194 "Like `progn', but prevents compiler warnings in the body."
195 ;; The implementation for the interpreter is basically trivial.
ae122ad2 196 (car (last body)))
5e046f6d
JB
197
198\f
199;;; I nuked this because it's not a good idea for users to think of using it.
200;;; These options are a matter of installation preference, and have nothing to
201;;; with particular source files; it's a mistake to suggest to users
202;;; they should associate these with particular source files.
203;;; There is hardly any reason to change these parameters, anyway.
204;;; --rms.
205
3fdfb09c 206;; (put 'byte-compiler-options 'lisp-indent-function 0)
5e046f6d
JB
207;; (defmacro byte-compiler-options (&rest args)
208;; "Set some compilation-parameters for this file. This will affect only the
209;; file in which it appears; this does nothing when evaluated, and when loaded
210;; from a .el file.
211;;
212;; Each argument to this macro must be a list of a key and a value.
213;;
214;; Keys: Values: Corresponding variable:
215;;
216;; verbose t, nil byte-compile-verbose
217;; optimize t, nil, source, byte byte-compile-optimize
218;; warnings list of warnings byte-compile-warnings
219;; Legal elements: (callargs redefine free-vars unresolved)
220;; file-format emacs18, emacs19 byte-compile-compatibility
221;;
222;; For example, this might appear at the top of a source file:
223;;
224;; (byte-compiler-options
225;; (optimize t)
226;; (warnings (- free-vars)) ; Don't warn about free variables
227;; (file-format emacs19))"
228;; nil)
229
ab5796a9 230;;; arch-tag: 76f8328a-1f66-4df2-9b6d-5c3666dc05e9
5e046f6d 231;;; byte-run.el ends here