(macro-declaration-function): Move from subr.el.
[emacs.git] / lisp / emacs-lisp / byte-run.el
blob60fc862676d79420e73298e595f8429336b960f8
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>
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., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, 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))))
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.
61 (fset 'inline 'progn)
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))
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)))
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)))
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))
98 `(prog1
99 (defun ,name ,arglist ,@body)
100 (eval-and-compile
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)))
115 function)
117 (defun make-obsolete-variable (variable new &optional when)
118 "Make the byte-compiler warn that VARIABLE is obsolete.
119 The warning will say that NEW should be used instead.
120 If NEW is a string, that is the `use instead' message.
121 If provided, WHEN should be a string indicating when the variable
122 was first made obsolete, for example a date or a release number."
123 (interactive
124 (list
125 (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t)))
126 (if (equal str "") (error ""))
127 (intern str))
128 (car (read-from-string (read-string "Obsoletion replacement: ")))))
129 (put variable 'byte-obsolete-variable (cons new when))
130 variable)
132 (defmacro dont-compile (&rest body)
133 "Like `progn', but the body always runs interpreted (not compiled).
134 If you think you need this, you're probably making a mistake somewhere."
135 (declare (debug t) (indent 0))
136 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
139 ;;; interface to evaluating things at compile time and/or load time
140 ;;; these macro must come after any uses of them in this file, as their
141 ;;; definition in the file overrides the magic definitions on the
142 ;;; byte-compile-macro-environment.
144 (defmacro eval-when-compile (&rest body)
145 "Like `progn', but evaluates the body at compile time.
146 The result of the body appears to the compiler as a quoted constant."
147 (declare (debug t) (indent 0))
148 ;; Not necessary because we have it in b-c-initial-macro-environment
149 ;; (list 'quote (eval (cons 'progn body)))
150 (cons 'progn body))
152 (defmacro eval-and-compile (&rest body)
153 "Like `progn', but evaluates the body at compile time and at load time."
154 (declare (debug t) (indent 0))
155 ;; Remember, it's magic.
156 (cons 'progn body))
158 (put 'with-no-warnings 'lisp-indent-function 0)
159 (defun with-no-warnings (&rest body)
160 "Like `progn', but prevents compiler warnings in the body."
161 ;; The implementation for the interpreter is basically trivial.
162 (car (last body)))
165 ;;; I nuked this because it's not a good idea for users to think of using it.
166 ;;; These options are a matter of installation preference, and have nothing to
167 ;;; with particular source files; it's a mistake to suggest to users
168 ;;; they should associate these with particular source files.
169 ;;; There is hardly any reason to change these parameters, anyway.
170 ;;; --rms.
172 ;; (put 'byte-compiler-options 'lisp-indent-function 0)
173 ;; (defmacro byte-compiler-options (&rest args)
174 ;; "Set some compilation-parameters for this file. This will affect only the
175 ;; file in which it appears; this does nothing when evaluated, and when loaded
176 ;; from a .el file.
178 ;; Each argument to this macro must be a list of a key and a value.
180 ;; Keys: Values: Corresponding variable:
182 ;; verbose t, nil byte-compile-verbose
183 ;; optimize t, nil, source, byte byte-compile-optimize
184 ;; warnings list of warnings byte-compile-warnings
185 ;; Legal elements: (callargs redefine free-vars unresolved)
186 ;; file-format emacs18, emacs19 byte-compile-compatibility
188 ;; For example, this might appear at the top of a source file:
190 ;; (byte-compiler-options
191 ;; (optimize t)
192 ;; (warnings (- free-vars)) ; Don't warn about free variables
193 ;; (file-format emacs19))"
194 ;; nil)
196 ;;; arch-tag: 76f8328a-1f66-4df2-9b6d-5c3666dc05e9
197 ;;; byte-run.el ends here