annotate lisp/bytecomp/bytecomp-runtime.el @ 0:376386a54a3c r19-14

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