(using-unix-filesystems):
[emacs.git] / lisp / byte-run.el
blob8d5595a8b0a76b6e935151adcd617e3355e31c85
1 ;;; byte-run.el --- byte-compiler support for inlining
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
5 ;; Author: Jamie Zawinski <jwz@lucid.com>
6 ;; Hallvard Furuseth <hbf@ulrik.uio.no>
7 ;; Keywords: internal
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;;; Commentary:
27 ;;; interface to selectively inlining functions.
28 ;;; This only happens when source-code optimization is turned on.
30 ;;; Code:
32 ;; Redefined in byte-optimize.el.
33 ;; This is not documented--it's not clear that we should promote it.
34 (fset 'inline 'progn)
35 (put 'inline 'lisp-indent-hook 0)
38 ;;; Interface to inline functions.
40 ;; (defmacro proclaim-inline (&rest fns)
41 ;; "Cause the named functions to be open-coded when called from compiled code.
42 ;; They will only be compiled open-coded when byte-compile-optimize is true."
43 ;; (cons 'eval-and-compile
44 ;; (mapcar '(lambda (x)
45 ;; (or (memq (get x 'byte-optimizer)
46 ;; '(nil byte-compile-inline-expand))
47 ;; (error
48 ;; "%s already has a byte-optimizer, can't make it inline"
49 ;; x))
50 ;; (list 'put (list 'quote x)
51 ;; ''byte-optimizer ''byte-compile-inline-expand))
52 ;; fns)))
54 ;; (defmacro proclaim-notinline (&rest fns)
55 ;; "Cause the named functions to no longer be open-coded."
56 ;; (cons 'eval-and-compile
57 ;; (mapcar '(lambda (x)
58 ;; (if (eq (get x 'byte-optimizer) 'byte-compile-inline-expand)
59 ;; (put x 'byte-optimizer nil))
60 ;; (list 'if (list 'eq (list 'get (list 'quote x) ''byte-optimizer)
61 ;; ''byte-compile-inline-expand)
62 ;; (list 'put x ''byte-optimizer nil)))
63 ;; fns)))
65 ;; This has a special byte-hunk-handler in bytecomp.el.
66 (defmacro defsubst (name arglist &rest body)
67 "Define an inline function. The syntax is just like that of `defun'."
68 (or (memq (get name 'byte-optimizer)
69 '(nil byte-compile-inline-expand))
70 (error "`%s' is a primitive" name))
71 (list 'prog1
72 (cons 'defun (cons name (cons arglist body)))
73 (list 'eval-and-compile
74 (list 'put (list 'quote name)
75 ''byte-optimizer ''byte-compile-inline-expand))))
77 (defun make-obsolete (fn new)
78 "Make the byte-compiler warn that FUNCTION is obsolete.
79 The warning will say that NEW should be used instead.
80 If NEW is a string, that is the `use instead' message."
81 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
82 (let ((handler (get fn 'byte-compile)))
83 (if (eq 'byte-compile-obsolete handler)
84 (setcar (get fn 'byte-obsolete-info) new)
85 (put fn 'byte-obsolete-info (cons new handler))
86 (put fn 'byte-compile 'byte-compile-obsolete)))
87 fn)
89 (defun make-obsolete-variable (var new)
90 "Make the byte-compiler warn that VARIABLE is obsolete,
91 and NEW should be used instead. If NEW is a string, then that is the
92 `use instead' message."
93 (interactive
94 (list
95 (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t)))
96 (if (equal str "") (error ""))
97 (intern str))
98 (car (read-from-string (read-string "Obsoletion replacement: ")))))
99 (put var 'byte-obsolete-variable new)
100 var)
102 (put 'dont-compile 'lisp-indent-hook 0)
103 (defmacro dont-compile (&rest body)
104 "Like `progn', but the body always runs interpreted (not compiled).
105 If you think you need this, you're probably making a mistake somewhere."
106 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
109 ;;; interface to evaluating things at compile time and/or load time
110 ;;; these macro must come after any uses of them in this file, as their
111 ;;; definition in the file overrides the magic definitions on the
112 ;;; byte-compile-macro-environment.
114 (put 'eval-when-compile 'lisp-indent-hook 0)
115 (defmacro eval-when-compile (&rest body)
116 "Like `progn', but evaluates the body at compile time.
117 The result of the body appears to the compiler as a quoted constant."
118 ;; Not necessary because we have it in b-c-initial-macro-environment
119 ;; (list 'quote (eval (cons 'progn body)))
120 (cons 'progn body))
122 (put 'eval-and-compile 'lisp-indent-hook 0)
123 (defmacro eval-and-compile (&rest body)
124 "Like `progn', but evaluates the body at compile time and at load time."
125 ;; Remember, it's magic.
126 (cons 'progn body))
129 ;;; I nuked this because it's not a good idea for users to think of using it.
130 ;;; These options are a matter of installation preference, and have nothing to
131 ;;; with particular source files; it's a mistake to suggest to users
132 ;;; they should associate these with particular source files.
133 ;;; There is hardly any reason to change these parameters, anyway.
134 ;;; --rms.
136 ;; (put 'byte-compiler-options 'lisp-indent-hook 0)
137 ;; (defmacro byte-compiler-options (&rest args)
138 ;; "Set some compilation-parameters for this file. This will affect only the
139 ;; file in which it appears; this does nothing when evaluated, and when loaded
140 ;; from a .el file.
142 ;; Each argument to this macro must be a list of a key and a value.
144 ;; Keys: Values: Corresponding variable:
146 ;; verbose t, nil byte-compile-verbose
147 ;; optimize t, nil, source, byte byte-compile-optimize
148 ;; warnings list of warnings byte-compile-warnings
149 ;; Legal elements: (callargs redefine free-vars unresolved)
150 ;; file-format emacs18, emacs19 byte-compile-compatibility
152 ;; For example, this might appear at the top of a source file:
154 ;; (byte-compiler-options
155 ;; (optimize t)
156 ;; (warnings (- free-vars)) ; Don't warn about free variables
157 ;; (file-format emacs19))"
158 ;; nil)
160 ;;; byte-run.el ends here