Mercurial > emacs
annotate lisp/byte-run.el @ 29193:eb1c9224a1c6
*** empty log message ***
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Thu, 25 May 2000 15:59:47 +0000 |
parents | cc3f3c1ea725 |
children | fa490904bee0 |
rev | line source |
---|---|
2229
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
957
diff
changeset
|
1 ;;; byte-run.el --- byte-compiler support for inlining |
757 | 2 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
3 ;; Copyright (C) 1992 Free Software Foundation, Inc. |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
5 ;; Author: Jamie Zawinski <jwz@lucid.com> |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
6 ;; Hallvard Furuseth <hbf@ulrik.uio.no> |
21045 | 7 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
8 ;; Keywords: internal |
757 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
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 | |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
14 ;; the Free Software Foundation; either version 2, or (at your option) |
757 | 15 ;; any later version. |
16 | |
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. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
14169 | 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. | |
757 | 26 |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
27 ;;; Commentary: |
757 | 28 |
14169 | 29 ;; interface to selectively inlining functions. |
30 ;; This only happens when source-code optimization is turned on. | |
757 | 31 |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
32 ;;; Code: |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
33 |
757 | 34 ;; Redefined in byte-optimize.el. |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
35 ;; This is not documented--it's not clear that we should promote it. |
757 | 36 (fset 'inline 'progn) |
37 (put 'inline 'lisp-indent-hook 0) | |
38 | |
39 | |
40 ;;; Interface to inline functions. | |
41 | |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
42 ;; (defmacro proclaim-inline (&rest fns) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
43 ;; "Cause the named functions to be open-coded when called from compiled code. |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
44 ;; They will only be compiled open-coded when byte-compile-optimize is true." |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
45 ;; (cons 'eval-and-compile |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
46 ;; (mapcar '(lambda (x) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
47 ;; (or (memq (get x 'byte-optimizer) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
48 ;; '(nil byte-compile-inline-expand)) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
49 ;; (error |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
50 ;; "%s already has a byte-optimizer, can't make it inline" |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
51 ;; x)) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
52 ;; (list 'put (list 'quote x) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
53 ;; ''byte-optimizer ''byte-compile-inline-expand)) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
54 ;; fns))) |
757 | 55 |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
56 ;; (defmacro proclaim-notinline (&rest fns) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
57 ;; "Cause the named functions to no longer be open-coded." |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
58 ;; (cons 'eval-and-compile |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
59 ;; (mapcar '(lambda (x) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
60 ;; (if (eq (get x 'byte-optimizer) 'byte-compile-inline-expand) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
61 ;; (put x 'byte-optimizer nil)) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
62 ;; (list 'if (list 'eq (list 'get (list 'quote x) ''byte-optimizer) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
63 ;; ''byte-compile-inline-expand) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
64 ;; (list 'put x ''byte-optimizer nil))) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
65 ;; fns))) |
757 | 66 |
67 ;; This has a special byte-hunk-handler in bytecomp.el. | |
68 (defmacro defsubst (name arglist &rest body) | |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
69 "Define an inline function. The syntax is just like that of `defun'." |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
70 (or (memq (get name 'byte-optimizer) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
71 '(nil byte-compile-inline-expand)) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
72 (error "`%s' is a primitive" name)) |
757 | 73 (list 'prog1 |
74 (cons 'defun (cons name (cons arglist body))) | |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
75 (list 'eval-and-compile |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
76 (list 'put (list 'quote name) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
77 ''byte-optimizer ''byte-compile-inline-expand)))) |
757 | 78 |
79 (defun make-obsolete (fn new) | |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
80 "Make the byte-compiler warn that FUNCTION is obsolete. |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
81 The warning will say that NEW should be used instead. |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
82 If NEW is a string, that is the `use instead' message." |
757 | 83 (interactive "aMake function obsolete: \nxObsoletion replacement: ") |
84 (let ((handler (get fn 'byte-compile))) | |
85 (if (eq 'byte-compile-obsolete handler) | |
86 (setcar (get fn 'byte-obsolete-info) new) | |
87 (put fn 'byte-obsolete-info (cons new handler)) | |
88 (put fn 'byte-compile 'byte-compile-obsolete))) | |
89 fn) | |
90 | |
957 | 91 (defun make-obsolete-variable (var new) |
92 "Make the byte-compiler warn that VARIABLE is obsolete, | |
93 and NEW should be used instead. If NEW is a string, then that is the | |
94 `use instead' message." | |
95 (interactive | |
96 (list | |
97 (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t))) | |
98 (if (equal str "") (error "")) | |
99 (intern str)) | |
100 (car (read-from-string (read-string "Obsoletion replacement: "))))) | |
101 (put var 'byte-obsolete-variable new) | |
102 var) | |
103 | |
757 | 104 (put 'dont-compile 'lisp-indent-hook 0) |
105 (defmacro dont-compile (&rest body) | |
957 | 106 "Like `progn', but the body always runs interpreted (not compiled). |
107 If you think you need this, you're probably making a mistake somewhere." | |
757 | 108 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body))))) |
109 | |
110 | |
111 ;;; interface to evaluating things at compile time and/or load time | |
112 ;;; these macro must come after any uses of them in this file, as their | |
113 ;;; definition in the file overrides the magic definitions on the | |
114 ;;; byte-compile-macro-environment. | |
115 | |
116 (put 'eval-when-compile 'lisp-indent-hook 0) | |
117 (defmacro eval-when-compile (&rest body) | |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
118 "Like `progn', but evaluates the body at compile time. |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
119 The result of the body appears to the compiler as a quoted constant." |
757 | 120 ;; Not necessary because we have it in b-c-initial-macro-environment |
121 ;; (list 'quote (eval (cons 'progn body))) | |
122 (cons 'progn body)) | |
123 | |
124 (put 'eval-and-compile 'lisp-indent-hook 0) | |
125 (defmacro eval-and-compile (&rest body) | |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
126 "Like `progn', but evaluates the body at compile time and at load time." |
757 | 127 ;; Remember, it's magic. |
128 (cons 'progn body)) | |
129 | |
130 | |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
131 ;;; I nuked this because it's not a good idea for users to think of using it. |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
132 ;;; These options are a matter of installation preference, and have nothing to |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
133 ;;; with particular source files; it's a mistake to suggest to users |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
134 ;;; they should associate these with particular source files. |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
135 ;;; There is hardly any reason to change these parameters, anyway. |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
136 ;;; --rms. |
757 | 137 |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
138 ;; (put 'byte-compiler-options 'lisp-indent-hook 0) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
139 ;; (defmacro byte-compiler-options (&rest args) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
140 ;; "Set some compilation-parameters for this file. This will affect only the |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
141 ;; file in which it appears; this does nothing when evaluated, and when loaded |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
142 ;; from a .el file. |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
143 ;; |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
144 ;; Each argument to this macro must be a list of a key and a value. |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
145 ;; |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
146 ;; Keys: Values: Corresponding variable: |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
147 ;; |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
148 ;; verbose t, nil byte-compile-verbose |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
149 ;; optimize t, nil, source, byte byte-compile-optimize |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
150 ;; warnings list of warnings byte-compile-warnings |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
151 ;; Legal elements: (callargs redefine free-vars unresolved) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
152 ;; file-format emacs18, emacs19 byte-compile-compatibility |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
153 ;; |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
154 ;; For example, this might appear at the top of a source file: |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
155 ;; |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
156 ;; (byte-compiler-options |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
157 ;; (optimize t) |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
158 ;; (warnings (- free-vars)) ; Don't warn about free variables |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
159 ;; (file-format emacs19))" |
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
160 ;; nil) |
757 | 161 |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
757
diff
changeset
|
162 ;;; byte-run.el ends here |