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