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