Mercurial > hg > xemacs-beta
annotate lisp/bytecomp-runtime.el @ 5630:f5315ccbf005
Cons less, be more careful about always using the environment, #'macroexpand
2011-12-30 Aidan Kehoe <kehoea@parhasard.net>
* eval.c (Fmacroexpand):
Don't cons if ENVIRONMENT is the same object as
byte-compile-macro-environment.
Always look up symbol- and other macros in the (possibly modified)
byte-compile-macro-environment, not the supplied ENVIRONMENT.
byte-compile-macro-environment reflects ENVIRONMENT, so that's OK
and preferred.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Fri, 30 Dec 2011 12:43:52 +0000 |
parents | 5f4f92a31875 |
children |
rev | line source |
---|---|
428 | 1 ;;; bytecomp-runtime.el --- byte-compiler support for inlining |
2 | |
3 ;; Copyright (C) 1992, 1997 Free Software Foundation, Inc. | |
4949
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
4 ;; Copyright (C) 2002, 2010 Ben Wing. |
428 | 5 |
6 ;; Author: Jamie Zawinski <jwz@jwz.org> | |
7 ;; Author: Hallvard Furuseth <hbf@ulrik.uio.no> | |
8 ;; Maintainer: XEmacs Development Team | |
9 ;; Keywords: internal, dumped | |
10 | |
11 ;; This file is part of XEmacs. | |
12 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
13 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
14 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
15 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
16 ;; option) any later version. |
428 | 17 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
18 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
19 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
20 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
21 ;; for more details. |
428 | 22 |
23 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
24 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 25 |
26 ;;; Synched up with: FSF 19.30. | |
27 | |
28 ;;; Commentary: | |
29 | |
30 ;; This file is dumped with XEmacs. | |
31 | |
32 ;; The code in this file should always be loaded, because it defines things | |
33 ;; like "defsubst" which should work interpreted as well. The code in | |
34 ;; bytecomp.el and byte-optimize.el can be loaded as needed. | |
35 | |
36 ;; interface to selectively inlining functions. | |
37 ;; This only happens when source-code optimization is turned on. | |
38 | |
39 ;;; Code: | |
40 | |
5506
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
41 ;; We define macro-declaration-function here because it is needed to |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
42 ;; handle declarations in macro definitions and this is the first file |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
43 ;; loaded by loadup.el that uses declarations in macros. |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
44 (defun macro-declaration-function (macro decl) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
45 "Process a declaration found in a macro definition. |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
46 This is set as the value of the variable `macro-declaration-function'. |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
47 MACRO is the name of the macro being defined. |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
48 DECL is a list `(declare ...)' containing the declarations. |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
49 The return value of this function is not used. |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
50 |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
51 XEmacs; any forms handed to the function described by the variable |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
52 `macro-declaration-function' will also (eventually) be handled by the |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
53 `declare' macro; see its documentation for further details of this." |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
54 ;; We can't use `dolist' or `cadr' yet for bootstrapping reasons. |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
55 (let (d) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
56 ;; Ignore the first element of `decl' (it's always `declare'). |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
57 (while (setq decl (cdr decl)) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
58 (setq d (car decl)) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
59 (if (and (consp d) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
60 (listp (cdr d)) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
61 (null (cdr (cdr d)))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
62 (cond ((eq (car d) 'indent) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
63 (put macro 'lisp-indent-function (car (cdr d)))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
64 ((eq (car d) 'debug) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
65 (put macro 'edebug-form-spec (car (cdr d)))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
66 ((eq (car d) 'doc-string) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
67 ;;; #### XEmacs; not sure that this does anything sensible. |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
68 (put macro 'doc-string-elt (car (cdr d)))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
69 ;; XEmacs; don't warn about the known XEmacs declarations. |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
70 ((memq (car d) '(special inline notinline optimize warn))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
71 (t |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
72 (message "Unknown declaration %s" d))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
73 (message "Invalid declaration %s" d))))) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
74 |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
75 (setq macro-declaration-function 'macro-declaration-function) |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
76 |
b0d87f92e60b
Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
77 |
428 | 78 ;; Redefined in byte-optimize.el. |
79 ;; This is not documented--it's not clear that we should promote it. | |
80 (fset 'inline 'progn) | |
81 (put 'inline 'lisp-indent-hook 0) | |
82 | |
83 | |
84 ;;; Interface to inline functions. | |
85 | |
86 ;; FSF comments the next two out, but I see no reason to do so. --ben | |
87 (defmacro proclaim-inline (&rest fns) | |
88 "Cause the named functions to be open-coded when called from compiled code. | |
89 They will only be compiled open-coded when `byte-optimize' is true." | |
90 (cons 'eval-and-compile | |
5264
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
91 (mapcan |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
92 #'(lambda (x) |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
93 `((or (memq (get ',x 'byte-optimizer) |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
94 '(nil byte-compile-inline-expand)) |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
95 (error |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
96 "%s already has a byte-optimizer, can't make it inline" |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
97 ',x)) |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
98 (put ',x 'byte-optimizer 'byte-compile-inline-expand))) |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
99 fns))) |
428 | 100 |
101 | |
102 (defmacro proclaim-notinline (&rest fns) | |
103 "Cause the named functions to no longer be open-coded." | |
104 (cons 'eval-and-compile | |
5264
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
105 (mapcan |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
106 #'(lambda (x) |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
107 `((if (eq (get ',x 'byte-optimizer) |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
108 'byte-compile-inline-expand) |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
109 (put ',x 'byte-optimizer nil)))) |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
110 fns))) |
428 | 111 |
112 ;; This has a special byte-hunk-handler in bytecomp.el. | |
113 (defmacro defsubst (name arglist &rest body) | |
114 "Define an inline function. The syntax is just like that of `defun'." | |
115 (or (memq (get name 'byte-optimizer) | |
116 '(nil byte-compile-inline-expand)) | |
117 (error "`%s' is a primitive" name)) | |
118 (list 'prog1 | |
119 (cons 'defun (cons name (cons arglist body))) | |
120 (list 'proclaim-inline name))) | |
121 ; Instead of the above line, FSF has this: | |
122 ; (list 'eval-and-compile | |
123 ; (list 'put (list 'quote name) | |
124 ; ''byte-optimizer ''byte-compile-inline-expand)))) | |
125 | |
2444 | 126 (defun make-obsolete (fn new &optional when) |
991 | 127 "Make the byte-compiler warn that function FN is obsolete. |
428 | 128 The warning will say that NEW should be used instead. |
2444 | 129 If NEW is a string, that is the `use instead' message. |
130 If provided, WHEN should be a string indicating when the function | |
131 was first made obsolete, for example a date or a release number." | |
428 | 132 (interactive "aMake function obsolete: \nxObsoletion replacement: ") |
133 (let ((handler (get fn 'byte-compile))) | |
134 (if (eq 'byte-compile-obsolete handler) | |
135 (setcar (get fn 'byte-obsolete-info) new) | |
136 (put fn 'byte-obsolete-info (cons new handler)) | |
137 (put fn 'byte-compile 'byte-compile-obsolete))) | |
138 fn) | |
139 | |
2444 | 140 (defun make-obsolete-variable (var new &optional when) |
991 | 141 "Make the byte-compiler warn that variable VAR is obsolete, |
428 | 142 and NEW should be used instead. If NEW is a string, then that is the |
2444 | 143 `use instead' message. |
144 If provided, WHEN should be a string indicating when the variable | |
145 was first made obsolete, for example a date or a release number." | |
428 | 146 (interactive |
147 (list | |
148 (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t))) | |
149 (if (equal str "") (error "")) | |
150 (intern str)) | |
151 (car (read-from-string (read-string "Obsoletion replacement: "))))) | |
152 (put var 'byte-obsolete-variable new) | |
153 var) | |
154 | |
155 ;; By overwhelming demand, we separate out truly obsolete symbols from | |
156 ;; those that are present for GNU Emacs compatibility. | |
157 (defun make-compatible (fn new) | |
991 | 158 "Make the byte-compiler know that function FN is provided for compatibility. |
428 | 159 The warning will say that NEW should be used instead. |
160 If NEW is a string, that is the `use instead' message." | |
161 (interactive "aMake function compatible: \nxCompatible replacement: ") | |
162 (let ((handler (get fn 'byte-compile))) | |
163 (if (eq 'byte-compile-compatible handler) | |
164 (setcar (get fn 'byte-compatible-info) new) | |
165 (put fn 'byte-compatible-info (cons new handler)) | |
166 (put fn 'byte-compile 'byte-compile-compatible))) | |
167 fn) | |
168 | |
169 (defun make-compatible-variable (var new) | |
991 | 170 "Make the byte-compiler know that variable VAR is provided for compatibility, |
428 | 171 and NEW should be used instead. If NEW is a string, then that is the |
172 `use instead' message." | |
173 (interactive | |
174 (list | |
175 (let ((str (completing-read "Make variable compatible: " | |
176 obarray 'boundp t))) | |
177 (if (equal str "") (error "")) | |
178 (intern str)) | |
179 (car (read-from-string (read-string "Compatible replacement: "))))) | |
180 (put var 'byte-compatible-variable new) | |
181 var) | |
182 | |
183 (put 'dont-compile 'lisp-indent-hook 0) | |
184 (defmacro dont-compile (&rest body) | |
185 "Like `progn', but the body always runs interpreted (not compiled). | |
186 If you think you need this, you're probably making a mistake somewhere." | |
187 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body))))) | |
188 | |
189 | |
190 ;;; interface to evaluating things at compile time and/or load time | |
191 ;;; these macro must come after any uses of them in this file, as their | |
192 ;;; definition in the file overrides the magic definitions on the | |
193 ;;; byte-compile-macro-environment. | |
194 | |
195 (put 'eval-when-compile 'lisp-indent-hook 0) | |
196 (defmacro eval-when-compile (&rest body) | |
5264
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
197 "Like `progn', but evaluates BODY at compile time, and when interpeted. |
428 | 198 The result of the body appears to the compiler as a quoted constant." |
199 ;; Not necessary because we have it in b-c-initial-macro-environment | |
200 ;; (list 'quote (eval (cons 'progn body))) | |
201 (cons 'progn body)) | |
202 | |
203 (put 'eval-and-compile 'lisp-indent-hook 0) | |
204 (defmacro eval-and-compile (&rest body) | |
5264
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
205 "Like `progn', but evaluates the body at compile time and at load time, |
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4949
diff
changeset
|
206 and when interpreted." |
428 | 207 ;; Remember, it's magic. |
208 (cons 'progn body)) | |
209 | |
210 ;;; From Emacs 20. | |
211 (put 'eval-when-feature 'lisp-indent-hook 1) | |
212 (defmacro eval-when-feature (feature &rest body) | |
213 "Run the body forms when FEATURE is featurep, be it now or later. | |
214 Called (eval-when-feature (FEATURE [. FILENAME]) BODYFORMS...). | |
215 If (featurep 'FEATURE), evals now; otherwise adds an elt to | |
216 `after-load-alist' (which see), using FEATURE as filename if FILENAME is nil." | |
217 (let ((file (or (cdr feature) (symbol-name (car feature))))) | |
218 `(let ((bodythunk #'(lambda () ,@body))) | |
219 (if (featurep ',(car feature)) | |
220 (funcall bodythunk) | |
221 (setq after-load-alist (cons '(,file . (list 'lambda '() bodythunk)) | |
222 after-load-alist)))))) | |
502 | 223 |
224 | |
225 | |
226 ;;; Functions to cleanly eliminate warnings about undefined functions | |
227 ;;; or variables when the code knows what it's doing. These macros DO | |
228 ;;; NOT rely on any byte-compiler changes, and thus can be copied into | |
229 ;;; a package and used within it. | |
230 | |
231 ;; NOTE: As a result of the above requirement, the macros rely on | |
232 ;; "tricks" to get the warnings suppressed. A cleaner way, of course, | |
233 ;; would be to extend the byte compiler to provide a proper interface. | |
234 | |
235 ;; #### Should we require an unquoted symbol rather than a quoted one, | |
236 ;; as we currently do? The quoting gets no generality, as `eval' is | |
237 ;; called at compile time. But most functions and macros want quoted | |
238 ;; arguments, and I find it extremely confusing to deal with cases | |
239 ;; such as `throw' requiring a quoted argument but `block' an unquoted | |
240 ;; one. | |
241 | |
242 (put 'with-boundp 'lisp-indent-function 1) | |
771 | 243 (defmacro with-boundp (variables &rest body) |
244 "Evaluate BODY, but do not issue bytecomp warnings about VARIABLES undefined. | |
245 VARIABLES can be a symbol or a list of symbols and must be quoted. When | |
246 compiling this file, the warnings `reference to free variable VARIABLE' and | |
247 `assignment to free variable VARIABLE' will not occur anywhere in BODY, for | |
248 any of the listed variables. This is a clean way to avoid such warnings. | |
776 | 249 |
250 See also `if-boundp', `when-boundp', and `and-boundp' (ways to | |
251 conditionalize on a variable being bound and avoid warnings), | |
252 `declare-boundp' (issue a variable call without warnings), and | |
253 `globally-declare-boundp' (avoid warnings throughout a file about a | |
254 variable)." | |
771 | 255 (setq variables (eval variables)) |
256 (unless (consp variables) | |
257 (setq variables (list variables))) | |
502 | 258 `(progn |
771 | 259 (declare (special ,@variables)) |
502 | 260 ,@body)) |
261 | |
262 (put 'if-boundp 'lisp-indent-function 2) | |
771 | 263 (defmacro if-boundp (variable then &rest else) |
264 "Equivalent to (if (boundp VARIABLE) THEN ELSE) but handles bytecomp warnings. | |
265 VARIABLE should be a quoted symbol. When compiling this file, the warnings | |
266 `reference to free variable VARIABLE' and `assignment to free variable | |
267 VARIABLE' will not occur anywhere in the if-statement. This is a clean way | |
776 | 268 to avoid such warnings. See also `with-boundp' and friends." |
771 | 269 `(with-boundp ,variable |
270 (if (boundp ,variable) ,then ,@else))) | |
502 | 271 |
771 | 272 (put 'when-boundp 'lisp-indent-function 1) |
273 (defmacro when-boundp (variable &rest body) | |
274 "Equivalent to (when (boundp VARIABLE) BODY) but handles bytecomp warnings. | |
275 VARIABLE should be a quoted symbol. When compiling this file, the warnings | |
276 `reference to free variable VARIABLE' and `assignment to free variable | |
277 VARIABLE' will not occur anywhere in the when-statement. This is a clean | |
776 | 278 way to avoid such warnings. See also `with-boundp' and friends." |
771 | 279 `(with-boundp ,variable |
280 (when (boundp ,variable) ,@body))) | |
281 | |
776 | 282 (put 'and-boundp 'lisp-indent-function 1) |
283 (defmacro and-boundp (variable &rest args) | |
284 "Equivalent to (and (boundp VARIABLE) ARGS) but handles bytecomp warnings. | |
285 VARIABLE should be a quoted symbol. When compiling this file, the warnings | |
286 `reference to free variable VARIABLE' and `assignment to free variable | |
287 VARIABLE' will not occur anywhere in the and-statement. This is a clean | |
288 way to avoid such warnings. See also `with-boundp' and friends." | |
289 `(with-boundp ,variable | |
290 (and (boundp ,variable) ,@args))) | |
291 | |
771 | 292 (defmacro declare-boundp (variable) |
293 "Evaluate VARIABLE without bytecomp warnings about the symbol. | |
294 | |
502 | 295 Sample usage is |
296 | |
297 (declare-boundp gpm-minor-mode) | |
298 | |
299 which is equivalent to | |
300 | |
771 | 301 (with-boundp 'gpm-minor-mode |
776 | 302 gpm-minor-mode) |
303 | |
304 See also `with-boundp' and friends." | |
771 | 305 `(with-boundp ',variable ,variable)) |
502 | 306 |
771 | 307 (defmacro globally-declare-boundp (variables) |
308 "Declare that all free uses of VARIABLES in this file are valid. | |
309 VARIABLES can be a symbol or a list of symbols and must be quoted. | |
502 | 310 |
771 | 311 When compiling this file, the warnings `reference to free variable |
312 VARIABLE' and `assignment to free variable VARIABLE' will not occur | |
313 regardless of where references to VARIABLE occur in the file. | |
502 | 314 |
776 | 315 In general, you should *NOT* use this; use `with-boundp' or its friends to |
316 wrap individual uses, as necessary. That way, you're more likely to | |
317 remember to put in the explicit checks for the variable's existence that | |
318 are usually necessary. However, `globally-declare-boundp' is better in | |
319 some circumstances, such as when writing an ELisp package that makes | |
320 integral use of optionally-compiled-in functionality (typically, an | |
321 interface onto a system library) and checks for the existence of the | |
322 functionality at some entry point to the package. See | |
323 `globally-declare-fboundp' for more information." | |
771 | 324 (setq variables (eval variables)) |
325 (if (not (consp variables)) | |
326 (setq variables (list variables))) | |
502 | 327 `(progn |
328 ;; (defvar FOO) has no side effects. | |
771 | 329 ,@(mapcar #'(lambda (sym) `(defvar ,sym)) variables))) |
502 | 330 |
331 (defun byte-compile-with-fboundp (form) | |
332 (byte-compile-form (cons 'progn (cdr (cdr form)))) | |
333 ;; Unfortunately, byte-compile-unresolved-functions is used not only | |
334 ;; for unresolved-function warnings, but also in connection with the | |
335 ;; following warnings: | |
336 | |
337 ;; "defsubst %s was used before it was defined" | |
338 ;; "%s being defined to take %s%s, but was previously called with %s" | |
339 | |
340 ;; By hacking byte-compile-unresolved-functions like this, we | |
341 ;; effectively disable these warnings. But code should not be using | |
342 ;; `with-fboundp' with a function defined later on in the same | |
343 ;; file, so this is not a big deal. | |
344 | |
345 (let ((symbols (eval (car (cdr form))))) | |
346 (unless (consp symbols) | |
347 (setq symbols (list symbols))) | |
5363
311f6817efc2
Remove various redundant wrapper lambdas, core lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
348 (setq symbols (mapcar #'list symbols)) |
502 | 349 (setq byte-compile-unresolved-functions |
350 (set-difference byte-compile-unresolved-functions symbols | |
351 :key #'car)) | |
352 )) | |
353 | |
354 ;; EEEEEEEEVIL hack. We need to create our own byte-compilation | |
355 ;; method so that the proper variables are bound while compilation | |
356 ;; takes place (which is when the warnings get noticed and batched | |
357 ;; up). What we really want to do is make `with-fboundp' a macro | |
358 ;; that simply `progn's its BODY; but GOD DAMN IT, macros can't have | |
359 ;; their own byte-compilation methods! So we make `with-fboundp' a | |
360 ;; macro calling `with-fboundp-1', which is cleverly aliased to | |
361 ;; progn. This way we can put a byte-compilation method on | |
362 ;; `with-fboundp-1', and when interpreting, progn will duly skip | |
363 ;; the first, quoted argument, i.e. the symbol name. (We could make | |
364 ;; `with-fboundp-1' a regular function, but then we'd have to thunk | |
365 ;; BODY and eval it at runtime. We could probably just do this using | |
366 ;; (apply 'progn BODY), but the existing method is more obviously | |
367 ;; guaranteed to work.) | |
368 ;; | |
369 ;; In defense, cl-macs.el does a very similar thing with | |
370 ;; `cl-block-wrapper'. | |
371 | |
372 (put 'with-fboundp-1 'byte-compile 'byte-compile-with-fboundp) | |
373 (defalias 'with-fboundp-1 'progn) | |
374 | |
375 (put 'with-fboundp 'lisp-indent-function 1) | |
771 | 376 (defmacro with-fboundp (functions &rest body) |
377 "Evaluate BODY, but do not issue bytecomp warnings about FUNCTIONS undefined. | |
378 FUNCTIONS can be a symbol or a list of symbols and must be quoted. When | |
379 compiling this file, the warning `the function FUNCTION is not known to be | |
380 defined' will not occur anywhere in BODY, for any of the listed functions. | |
776 | 381 This is a clean way to avoid such warnings. |
382 | |
383 See also `if-fboundp', `when-fboundp', and `and-fboundp' (ways to | |
384 conditionalize on a function being bound and avoid warnings), | |
385 `declare-fboundp' (issue a function call without warnings), and | |
386 `globally-declare-fboundp' (avoid warnings throughout a file about a | |
387 function)." | |
771 | 388 `(with-fboundp-1 ,functions ,@body)) |
502 | 389 |
390 (put 'if-fboundp 'lisp-indent-function 2) | |
771 | 391 (defmacro if-fboundp (function then &rest else) |
392 "Equivalent to (if (fboundp FUNCTION) THEN ELSE) but handles bytecomp warnings. | |
393 FUNCTION should be a quoted symbol. When compiling this file, the warning | |
394 `the function FUNCTION is not known to be defined' will not occur anywhere | |
395 in the if-statement. This is a clean way to avoid such warnings. See also | |
776 | 396 `with-fboundp' and friends." |
771 | 397 `(with-fboundp ,function |
398 (if (fboundp ,function) ,then ,@else))) | |
399 | |
400 (put 'when-fboundp 'lisp-indent-function 1) | |
401 (defmacro when-fboundp (function &rest body) | |
402 "Equivalent to (when (fboundp FUNCTION) BODY) but handles bytecomp warnings. | |
403 FUNCTION should be a quoted symbol. When compiling this file, the warning | |
404 `the function FUNCTION is not known to be defined' will not occur anywhere | |
776 | 405 in the when-statement. This is a clean way to avoid such warnings. See also |
406 `with-fboundp' and friends." | |
771 | 407 `(with-fboundp ,function |
408 (when (fboundp ,function) ,@body))) | |
502 | 409 |
776 | 410 (put 'and-fboundp 'lisp-indent-function 1) |
411 (defmacro and-fboundp (function &rest args) | |
412 "Equivalent to (and (fboundp FUNCTION) ARGS) but handles bytecomp warnings. | |
413 FUNCTION should be a quoted symbol. When compiling this file, the warning | |
414 `the function FUNCTION is not known to be defined' will not occur anywhere | |
415 in the and-statement. This is a clean way to avoid such warnings. See also | |
416 `with-fboundp' and friends." | |
417 `(with-fboundp ,function | |
418 (and (fboundp ,function) ,@args))) | |
419 | |
502 | 420 (defmacro declare-fboundp (form) |
421 "Execute FORM (a function call) without bytecomp warnings about the call. | |
422 Sample usage is | |
423 | |
424 (declare-fboundp (x-keysym-on-keyboard-sans-modifiers-p 'backspace)) | |
425 | |
426 which is equivalent to | |
427 | |
428 (with-fboundp 'x-keysym-on-keyboard-sans-modifiers-p | |
776 | 429 (x-keysym-on-keyboard-sans-modifiers-p 'backspace)) |
430 | |
431 See also `with-fboundp' and friends." | |
502 | 432 `(with-fboundp ',(car form) ,form)) |
433 | |
771 | 434 (defmacro globally-declare-fboundp (functions) |
435 "Declare that all calls to function FUNCTIONS in this file are valid. | |
436 FUNCTIONS can be a symbol or a list of symbols and must be quoted. | |
502 | 437 |
771 | 438 When compiling this file, the warning `the function FUNCTION is not known |
439 to be defined' will not occur regardless of where calls to FUNCTION occur | |
440 in the file. | |
502 | 441 |
776 | 442 In general, you should *NOT* use this; use `with-fboundp' or its friends to |
443 wrap individual uses, as necessary. That way, you're more likely to | |
444 remember to put in the explicit checks for the function's existence that | |
445 are usually necessary. However, `globally-declare-fboundp' is better in | |
446 some circumstances, such as when writing an ELisp package that makes | |
447 integral use of optionally-compiled-in functionality (typically, an | |
448 interface onto a system library) and checks for the existence of the | |
449 functionality at some entry point to the package. The file `ldap.el' is a | |
450 good example: It provides a layer on top of the optional LDAP ELisp | |
451 primitives, makes calls to them throughout its code, and verifies the | |
452 presence of LDAP support at load time. Putting calls to `declare-fboundp' | |
453 throughout the code would be a major annoyance." | |
502 | 454 (when (cl-compiling-file) |
771 | 455 (setq functions (eval functions)) |
456 (if (not (consp functions)) | |
457 (setq functions (list functions))) | |
502 | 458 ;; Another hack. This works because the autoload environment is |
459 ;; currently used ONLY to suppress warnings, and the actual | |
460 ;; autoload definition is not used. (NOTE: With this definition, | |
461 ;; we will get spurious "multiple autoloads for %s" warnings if we | |
771 | 462 ;; have an autoload later in the file for any functions in FUNCTIONS. |
502 | 463 ;; This is not something that code should ever do, though.) |
464 (setq byte-compile-autoload-environment | |
5363
311f6817efc2
Remove various redundant wrapper lambdas, core lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
465 (append (mapcar #'list functions) |
502 | 466 byte-compile-autoload-environment))) |
467 nil) | |
468 | |
469 (defun byte-compile-with-byte-compiler-warnings-suppressed (form) | |
470 (let ((byte-compile-warnings byte-compile-warnings) | |
471 (types (car (cdr form)))) | |
472 (unless (consp types) | |
473 (setq types (list types))) | |
474 (if (eq byte-compile-warnings t) | |
475 (setq byte-compile-warnings byte-compile-default-warnings)) | |
476 (setq byte-compile-warnings (set-difference byte-compile-warnings types)) | |
477 (byte-compile-form (cons 'progn (cdr (cdr form)))))) | |
478 | |
479 ;; Same hack here as with `with-fboundp'. | |
480 (put 'with-byte-compiler-warnings-suppressed-1 'byte-compile | |
481 'byte-compile-with-byte-compiler-warnings-suppressed) | |
482 (defalias 'with-byte-compiler-warnings-suppressed-1 'progn) | |
483 | |
484 (put 'with-byte-compiler-warnings-suppressed 'lisp-indent-function 1) | |
485 (defmacro with-byte-compiler-warnings-suppressed (type &rest body) | |
486 "Evaluate BODY, but do not issue bytecomp warnings TYPE. | |
487 TYPE should be one of `redefine', `callargs', `subr-callargs', | |
488 `free-vars', `unresolved', `unused-vars', `obsolete', or `pedantic', | |
489 or a list of one or more of these symbols. (See `byte-compile-warnings'.) | |
490 TYPE must be quoted. | |
491 | |
492 NOTE: You should *NOT* under normal circumstances be using this! | |
493 There are better ways of avoiding most of these warnings. In particular: | |
494 | |
495 -- use (declare (special ...)) if you are making use of | |
496 dynamically-scoped variables. | |
776 | 497 -- use `with-fboundp' and friends to avoid warnings about undefined functions |
771 | 498 when you know the function actually exists. |
776 | 499 -- use `with-boundp' and friends to avoid warnings about undefined variables |
771 | 500 when you know the variable actually exists. |
502 | 501 -- use `with-obsolete-variable' or `with-obsolete-function' if you |
502 are purposely using such a variable or function." | |
503 `(with-byte-compiler-warnings-suppressed-1 ,type ,@body)) | |
504 | |
505 ;; #### These should be more clever. You could (e.g.) try fletting | |
506 ;; `byte-compile-obsolete' or temporarily removing the obsolete info | |
507 ;; from the symbol and putting it back with an unwind-protect. (Or | |
508 ;; better, modify the byte-compiler to provide a proper solution, and | |
509 ;; fix these macros to use it if available, or fall back on the way | |
510 ;; below. Remember, these definitions need to work with an unchanged | |
511 ;; byte compiler so that they can be copied and used in packages.) | |
512 | |
513 (put 'with-obsolete-variable 'lisp-indent-function 1) | |
514 (defmacro with-obsolete-variable (symbol &rest body) | |
515 "Evaluate BODY but do not warn about usage of obsolete variable SYMBOL. | |
826 | 516 SYMBOL must be quoted and can be a list of SYMBOLS. See also |
517 `with-obsolete-function'." | |
502 | 518 `(with-byte-compiler-warnings-suppressed 'obsolete ,@body)) |
519 | |
520 (put 'with-obsolete-function 'lisp-indent-function 1) | |
521 (defmacro with-obsolete-function (symbol &rest body) | |
522 "Evaluate BODY but do not warn about usage of obsolete function SYMBOL. | |
826 | 523 SYMBOL must be quoted and can be a list of SYMBOLS. See also |
524 `with-obsolete-variable'." | |
502 | 525 `(with-byte-compiler-warnings-suppressed 'obsolete ,@body)) |
428 | 526 |
527 | |
4949
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
528 |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
529 (defmacro error-unless-tests-match (test &optional source) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
530 "Signal an error unless TEST matches when being compiled and loaded. |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
531 This is for use in a file that will be byte-compiled. Unless TEST has the |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
532 same nilness or non-nilness when the file is compiled and loaded, an error |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
533 will be signalled. SOURCE is the name of the source file." |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
534 (let ((source (eval source))) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
535 `(unless (eq (not ,test) ,(not (eval test))) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
536 (error ,(format "This file was compiled with `%s' %s, |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
537 but it was %s when run. This file needs to be compiled with |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
538 the same value for the expression as when it is run. Please delete |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
539 %s and rebuild." |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
540 test (if (eval test) "true" "false") |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
541 (if (eval test) "false" "true") |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
542 (cond |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
543 ((null source) "the .elc for this file") |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
544 ((string-match "\.elc$" source) source) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
545 ((string-match "\.el$" source) (concat source "c")) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
546 (t (concat source ".elc")))))))) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
547 |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
548 (defun byte-compile-file-being-compiled () |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
549 "When byte-compiling a file, return the name of the file being compiled. |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
550 Return nil otherwise." |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
551 (or |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
552 ;;The first of these, but not the second, seems to work noninteractively; |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
553 ;;vice-versa interactively. This is because interactively a *Compile Log* |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
554 ;;buffer is created and byte-compile-log-1 inserts a "Compiling file ..." |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
555 ;;message into thelog buffer, and then sets byte-compile-current-file to |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
556 ;;nil to indicate that the message shouldn't be printed again. |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
557 (and-boundp 'byte-compile-current-file byte-compile-current-file) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
558 (and-boundp 'byte-compile-log-buffer |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
559 (with-current-buffer byte-compile-log-buffer |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
560 (save-excursion |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
561 (and (re-search-backward "Compiling file \\(.*\\) at " nil t) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
562 (match-string 1))))))) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
563 |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
564 |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
565 (defmacro compiled-if (test if &rest else) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
566 "Like a regular `if' statement but the TEST will be evalled at compile time. |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
567 If TEST doesn't match at compile time and load time, an error will be |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
568 signalled." |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
569 (let ((being-compiled (byte-compile-file-being-compiled))) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
570 `(progn |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
571 (error-unless-tests-match ,test ,being-compiled) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
572 ,(if (eval test) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
573 if |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
574 `(progn ,else))))) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
575 |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
576 (defmacro compiled-when (test &rest when) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
577 "Like a regular `when' statement but the TEST will be evalled at compile time. |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
578 See `compiled-if'." |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
579 `(compiled-if ,test (progn ,@when))) |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
580 |
018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
2444
diff
changeset
|
581 |
428 | 582 ;;; Interface to file-local byte-compiler parameters. |
583 ;;; Redefined in bytecomp.el. | |
584 | |
585 ;;; The great RMS speaketh: | |
586 ;;; | |
587 ;;; I nuked this because it's not a good idea for users to think of | |
588 ;;; using it. These options are a matter of installation preference, | |
589 ;;; and have nothing to do with particular source files; it's a | |
590 ;;; mistake to suggest to users that they should associate these with | |
591 ;;; particular source files. There is hardly any reason to change | |
592 ;;; these parameters, anyway. --rms. | |
593 ;;; | |
594 ;;; But I'll leave this stuff alone. --ben | |
595 | |
596 (put 'byte-compiler-options 'lisp-indent-hook 0) | |
597 (defmacro byte-compiler-options (&rest args) | |
598 "Set some compilation-parameters for this file. | |
599 This will affect only the file in which it appears; this does nothing when | |
600 evaluated, or when loaded from a .el file. | |
601 | |
602 Each argument to this macro must be a list of a key and a value. | |
603 | |
604 Keys: Values: Corresponding variable: | |
605 | |
606 verbose t, nil byte-compile-verbose | |
607 optimize t, nil, source, byte byte-optimize | |
608 warnings list of warnings byte-compile-warnings | |
609 file-format emacs19, emacs20 byte-compile-emacs19-compatibility | |
610 | |
611 The value specified with the `warnings' option must be a list, containing | |
612 some subset of the following flags: | |
613 | |
614 free-vars references to variables not in the current lexical scope. | |
615 unused-vars references to non-global variables bound but not referenced. | |
616 unresolved calls to unknown functions. | |
617 callargs lambda calls with args that don't match the definition. | |
502 | 618 subr-callargs calls to subrs with args that don't match the definition. |
428 | 619 redefine function cell redefined from a macro to a lambda or vice |
620 versa, or redefined to take a different number of arguments. | |
502 | 621 obsolete use of an obsolete function or variable. |
622 pedantic warn of use of compatible symbols. | |
428 | 623 |
624 If the first element if the list is `+' or `-' then the specified elements | |
625 are added to or removed from the current set of warnings, instead of the | |
626 entire set of warnings being overwritten. | |
627 | |
628 For example, something like this might appear at the top of a source file: | |
629 | |
630 (byte-compiler-options | |
631 (optimize t) | |
632 (warnings (- callargs)) ; Don't warn about arglist mismatch | |
633 (warnings (+ unused-vars)) ; Do warn about unused bindings | |
634 (file-format emacs19))" | |
635 nil) | |
636 | |
637 ;;; bytecomp-runtime.el ends here |