0
|
1 ;;; byte-run.el --- byte-compiler support for inlining
|
|
2
|
|
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Jamie Zawinski <jwz@lucid.com>
|
|
6 ;; Hallvard Furuseth <hbf@ulrik.uio.no>
|
|
7 ;; Keywords: internal
|
|
8
|
|
9 ;; The code in this file should always be loaded, because it defines things
|
|
10 ;; like "defsubst" which should work interpreted as well. The code in
|
|
11 ;; bytecomp.el and byte-optimize.el can be loaded as needed.
|
|
12 ;;
|
|
13 ;; This file is part of XEmacs.
|
|
14
|
|
15 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
16 ;; under the terms of the GNU General Public License as published by
|
|
17 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
18 ;; any later version.
|
|
19
|
|
20 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
23 ;; General Public License for more details.
|
|
24
|
|
25 ;; You should have received a copy of the GNU General Public License
|
16
|
26 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
28 ;; Boston, MA 02111-1307, USA.
|
0
|
29
|
|
30 ;;; Synched up with: FSF 19.30.
|
|
31
|
|
32 ;;; Commentary:
|
|
33
|
|
34 ;;; interface to selectively inlining functions.
|
|
35 ;;; This only happens when source-code optimization is turned on.
|
|
36
|
|
37 ;;; Code:
|
|
38
|
|
39 ;; Redefined in byte-optimize.el.
|
|
40 ;; This is not documented--it's not clear that we should promote it.
|
|
41 (fset 'inline 'progn)
|
|
42 (put 'inline 'lisp-indent-hook 0)
|
|
43
|
|
44
|
|
45 ;;; Interface to inline functions.
|
|
46
|
|
47 ;; FSF comments the next two out, but I see no reason to do so. --ben
|
|
48 (defmacro proclaim-inline (&rest fns)
|
|
49 "Cause the named functions to be open-coded when called from compiled code.
|
|
50 They will only be compiled open-coded when byte-optimize is true."
|
|
51 (cons 'eval-and-compile
|
|
52 (apply
|
|
53 'nconc
|
|
54 (mapcar
|
|
55 '(lambda (x)
|
|
56 (` ((or (memq (get '(, x) 'byte-optimizer)
|
|
57 '(nil byte-compile-inline-expand))
|
|
58 (error
|
|
59 "%s already has a byte-optimizer, can't make it inline"
|
|
60 '(, x)))
|
|
61 (put '(, x) 'byte-optimizer 'byte-compile-inline-expand))))
|
|
62 fns))))
|
|
63
|
|
64
|
|
65 (defmacro proclaim-notinline (&rest fns)
|
|
66 "Cause the named functions to no longer be open-coded."
|
|
67 (cons 'eval-and-compile
|
|
68 (apply
|
|
69 'nconc
|
|
70 (mapcar
|
|
71 '(lambda (x)
|
|
72 (` ((if (eq (get '(, x) 'byte-optimizer)
|
|
73 'byte-compile-inline-expand)
|
|
74 (put '(, x) 'byte-optimizer nil)))))
|
|
75 fns))))
|
|
76
|
|
77 ;; This has a special byte-hunk-handler in bytecomp.el.
|
|
78 (defmacro defsubst (name arglist &rest body)
|
|
79 "Define an inline function. The syntax is just like that of `defun'."
|
|
80 (or (memq (get name 'byte-optimizer)
|
|
81 '(nil byte-compile-inline-expand))
|
|
82 (error "`%s' is a primitive" name))
|
|
83 (list 'prog1
|
|
84 (cons 'defun (cons name (cons arglist body)))
|
|
85 (list 'proclaim-inline name)))
|
|
86 ; Instead of the above line, FSF has this:
|
|
87 ; (list 'eval-and-compile
|
|
88 ; (list 'put (list 'quote name)
|
|
89 ; ''byte-optimizer ''byte-compile-inline-expand))))
|
|
90
|
|
91 (defun make-obsolete (fn new)
|
|
92 "Make the byte-compiler warn that FUNCTION is obsolete.
|
|
93 The warning will say that NEW should be used instead.
|
|
94 If NEW is a string, that is the `use instead' message."
|
|
95 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
|
|
96 (let ((handler (get fn 'byte-compile)))
|
|
97 (if (eq 'byte-compile-obsolete handler)
|
|
98 (setcar (get fn 'byte-obsolete-info) new)
|
|
99 (put fn 'byte-obsolete-info (cons new handler))
|
|
100 (put fn 'byte-compile 'byte-compile-obsolete)))
|
|
101 fn)
|
|
102
|
|
103 (defun make-obsolete-variable (var new)
|
|
104 "Make the byte-compiler warn that VARIABLE is obsolete,
|
|
105 and NEW should be used instead. If NEW is a string, then that is the
|
|
106 `use instead' message."
|
|
107 (interactive
|
|
108 (list
|
|
109 (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t)))
|
|
110 (if (equal str "") (error ""))
|
|
111 (intern str))
|
|
112 (car (read-from-string (read-string "Obsoletion replacement: ")))))
|
|
113 (put var 'byte-obsolete-variable new)
|
|
114 var)
|
|
115
|
22
|
116 ;; By overwhelming demand, we separate out truly obsolete symbols from
|
|
117 ;; those that are present for GNU Emacs compatibility.
|
|
118 (defun make-compatible (fn new)
|
|
119 "Make the byte-compiler know that FUNCTION is provided for compatibility.
|
|
120 The warning will say that NEW should be used instead.
|
|
121 If NEW is a string, that is the `use instead' message."
|
|
122 (interactive "aMake function compatible: \nxCompatible replacement: ")
|
|
123 (let ((handler (get fn 'byte-compile)))
|
|
124 (if (eq 'byte-compile-compatible handler)
|
|
125 (setcar (get fn 'byte-compatible-info) new)
|
|
126 (put fn 'byte-compatible-info (cons new handler))
|
|
127 (put fn 'byte-compile 'byte-compile-compatible)))
|
|
128 fn)
|
|
129
|
|
130 (defun make-compatible-variable (var new)
|
|
131 "Make the byte-compiler know that VARIABLE is provided for compatibility.
|
|
132 and NEW should be used instead. If NEW is a string, then that is the
|
|
133 `use instead' message."
|
|
134 (interactive
|
|
135 (list
|
|
136 (let ((str (completing-read "Make variable compatible: "
|
|
137 obarray 'boundp t)))
|
|
138 (if (equal str "") (error ""))
|
|
139 (intern str))
|
|
140 (car (read-from-string (read-string "Compatible replacement: ")))))
|
|
141 (put var 'byte-compatible-variable new)
|
|
142 var)
|
|
143
|
0
|
144 (put 'dont-compile 'lisp-indent-hook 0)
|
|
145 (defmacro dont-compile (&rest body)
|
|
146 "Like `progn', but the body always runs interpreted (not compiled).
|
|
147 If you think you need this, you're probably making a mistake somewhere."
|
|
148 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
|
|
149
|
|
150
|
|
151 ;;; interface to evaluating things at compile time and/or load time
|
|
152 ;;; these macro must come after any uses of them in this file, as their
|
|
153 ;;; definition in the file overrides the magic definitions on the
|
|
154 ;;; byte-compile-macro-environment.
|
|
155
|
|
156 (put 'eval-when-compile 'lisp-indent-hook 0)
|
|
157 (defmacro eval-when-compile (&rest body)
|
|
158 "Like `progn', but evaluates the body at compile time.
|
|
159 The result of the body appears to the compiler as a quoted constant."
|
|
160 ;; Not necessary because we have it in b-c-initial-macro-environment
|
|
161 ;; (list 'quote (eval (cons 'progn body)))
|
|
162 (cons 'progn body))
|
|
163
|
|
164 (put 'eval-and-compile 'lisp-indent-hook 0)
|
|
165 (defmacro eval-and-compile (&rest body)
|
|
166 "Like `progn', but evaluates the body at compile time and at load time."
|
|
167 ;; Remember, it's magic.
|
|
168 (cons 'progn body))
|
|
169
|
|
170
|
|
171 ;;; Interface to file-local byte-compiler parameters.
|
|
172 ;;; Redefined in bytecomp.el.
|
|
173
|
|
174 ;;; The great RMS speaketh:
|
|
175 ;;;
|
2
|
176 ;;; I nuked this because it's not a good idea for users to think of
|
|
177 ;;; using it. These options are a matter of installation preference,
|
|
178 ;;; and have nothing to do with particular source files; it's a
|
|
179 ;;; mistake to suggest to users that they should associate these with
|
|
180 ;;; particular source files. There is hardly any reason to change
|
|
181 ;;; these parameters, anyway. --rms.
|
0
|
182 ;;;
|
|
183 ;;; But I'll leave this stuff alone. --ben
|
|
184
|
|
185 (put 'byte-compiler-options 'lisp-indent-hook 0)
|
|
186 (defmacro byte-compiler-options (&rest args)
|
|
187 "Set some compilation-parameters for this file.
|
|
188 This will affect only the file in which it appears; this does nothing when
|
2
|
189 evaluated, or when loaded from a .el file.
|
0
|
190
|
|
191 Each argument to this macro must be a list of a key and a value.
|
|
192
|
|
193 Keys: Values: Corresponding variable:
|
|
194
|
|
195 verbose t, nil byte-compile-verbose
|
|
196 optimize t, nil, source, byte byte-optimize
|
|
197 warnings list of warnings byte-compile-warnings
|
|
198 file-format emacs18, emacs19 byte-compile-emacs18-compatibility
|
|
199
|
|
200 The value specificed with the `warnings' option must be a list, containing
|
|
201 some subset of the following flags:
|
|
202
|
|
203 free-vars references to variables not in the current lexical scope.
|
|
204 unused-vars references to non-global variables bound but not referenced.
|
|
205 unresolved calls to unknown functions.
|
|
206 callargs lambda calls with args that don't match the definition.
|
|
207 redefine function cell redefined from a macro to a lambda or vice
|
|
208 versa, or redefined to take a different number of arguments.
|
|
209
|
|
210 If the first element if the list is `+' or `-' then the specified elements
|
|
211 are added to or removed from the current set of warnings, instead of the
|
|
212 entire set of warnings being overwritten.
|
|
213
|
|
214 For example, something like this might appear at the top of a source file:
|
|
215
|
|
216 (byte-compiler-options
|
|
217 (optimize t)
|
|
218 (warnings (- callargs)) ; Don't warn about arglist mismatch
|
|
219 (warnings (+ unused-vars)) ; Do warn about unused bindings
|
|
220 (file-format emacs19))"
|
|
221 nil)
|
|
222
|
|
223 ;;; bytecomp-runtime.el ends here
|