1 ;;; byte-run.el --- byte-compiler support for inlining
3 ;; Copyright (C) 1992, 2004, 2005 Free Software Foundation, Inc.
5 ;; Author: Jamie Zawinski <jwz@lucid.com>
6 ;; Hallvard Furuseth <hbf@ulrik.uio.no>
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)
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., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; interface to selectively inlining functions.
30 ;; This only happens when source-code optimization is turned on.
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.
46 ;; Ignore the first element of `decl' (it's always `declare').
47 (while (setq decl
(cdr 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
))))
54 (message "Unknown declaration %s" d
))))))
56 (setq macro-declaration-function
'macro-declaration-function
)
59 ;; Redefined in byte-optimize.el.
60 ;; This is not documented--it's not clear that we should promote it.
62 (put 'inline
'lisp-indent-function
0)
64 ;;; Interface to inline functions.
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))
74 ;; "%s already has a byte-optimizer, can't make it inline"
76 ;; (list 'put (list 'quote x)
77 ;; ''byte-optimizer ''byte-compile-inline-expand))
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)))
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'."
94 (declare (debug defun
))
95 (or (memq (get name
'byte-optimizer
)
96 '(nil byte-compile-inline-expand
))
97 (error "`%s' is a primitive" name
))
99 (defun ,name
,arglist
,@body
)
101 (put ',name
'byte-optimizer
'byte-compile-inline-expand
))))
103 (defun make-obsolete (function new
&optional when
)
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: ")
110 (let ((handler (get function
'byte-compile
)))
111 (if (eq 'byte-compile-obsolete handler
)
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
)))
117 (defmacro define-obsolete-function-alias
(function new
118 &optional when docstring
)
119 "Set FUNCTION's function definition to NEW and mark it obsolete.
121 \(define-obsolete-function-alias 'old-fun 'new-fun \"22.1\" \"old-fun's doc.\")
123 is equivalent to the following two lines of code:
125 \(defalias 'old-fun 'new-fun \"old-fun's doc.\")
126 \(make-obsolete 'old-fun 'new-fun \"22.1\")
128 See the docstrings of `defalias' and `make-obsolete' for more details."
130 (defalias ,function
,new
,docstring
)
131 (make-obsolete ,function
,new
,when
)))
133 (defun make-obsolete-variable (variable new
&optional when
)
134 "Make the byte-compiler warn that VARIABLE is obsolete.
135 The warning will say that NEW should be used instead.
136 If NEW is a string, that is the `use instead' message.
137 If provided, WHEN should be a string indicating when the variable
138 was first made obsolete, for example a date or a release number."
141 (let ((str (completing-read "Make variable obsolete: " obarray
'boundp t
)))
142 (if (equal str
"") (error ""))
144 (car (read-from-string (read-string "Obsoletion replacement: ")))))
145 (put variable
'byte-obsolete-variable
(cons new when
))
148 (defmacro define-obsolete-variable-alias
(variable new
149 &optional when docstring
)
150 "Make VARIABLE a variable alias for NEW and mark it obsolete.
152 \(define-obsolete-variable-alias 'old-var 'new-var \"22.1\" \"old-var's doc.\")
154 is equivalent to the following two lines of code:
156 \(defvaralias 'old-var 'new-var \"old-var's doc.\")
157 \(make-obsolete-variable 'old-var 'new-var \"22.1\")
159 See the docstrings of `defvaralias' and `make-obsolete-variable' or
160 Info node `(elisp)Variable Aliases' for more details."
162 (defvaralias ,variable
,new
,docstring
)
163 (make-obsolete-variable ,variable
,new
,when
)))
165 (defmacro dont-compile
(&rest body
)
166 "Like `progn', but the body always runs interpreted (not compiled).
167 If you think you need this, you're probably making a mistake somewhere."
168 (declare (debug t
) (indent 0))
169 (list 'eval
(list 'quote
(if (cdr body
) (cons 'progn body
) (car body
)))))
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.
177 (defmacro eval-when-compile
(&rest body
)
178 "Like `progn', but evaluates the body at compile time if you're compiling.
179 Thus, the result of the body appears to the compiler as a quoted constant.
180 In interpreted code, this is entirely equivalent to `progn'."
181 (declare (debug t
) (indent 0))
182 ;; Not necessary because we have it in b-c-initial-macro-environment
183 ;; (list 'quote (eval (cons 'progn body)))
186 (defmacro eval-and-compile
(&rest body
)
187 "Like `progn', but evaluates the body at compile time and at load time."
188 (declare (debug t
) (indent 0))
189 ;; Remember, it's magic.
192 (put 'with-no-warnings
'lisp-indent-function
0)
193 (defun with-no-warnings (&rest body
)
194 "Like `progn', but prevents compiler warnings in the body."
195 ;; The implementation for the interpreter is basically trivial.
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.
206 ;; (put 'byte-compiler-options 'lisp-indent-function 0)
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
212 ;; Each argument to this macro must be a list of a key and a value.
214 ;; Keys: Values: Corresponding variable:
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
222 ;; For example, this might appear at the top of a source file:
224 ;; (byte-compiler-options
226 ;; (warnings (- free-vars)) ; Don't warn about free variables
227 ;; (file-format emacs19))"
230 ;;; arch-tag: 76f8328a-1f66-4df2-9b6d-5c3666dc05e9
231 ;;; byte-run.el ends here