annotate lisp/bytecomp.el @ 826:6728e641994e

[xemacs-hg @ 2002-05-05 11:30:15 by ben] syntax cache, 8-bit-format, lots of code cleanup README.packages: Update info about --package-path. i.c: Create an inheritable event and pass it on to XEmacs, so that ^C can be handled properly. Intercept ^C and signal the event. "Stop Build" in VC++ now works. bytecomp-runtime.el: Doc string changes. compat.el: Some attempts to redo this to make it truly useful and fix the "multiple versions interacting with each other" problem. Not yet done. Currently doesn't work. files.el: Use with-obsolete-variable to avoid warnings in new revert-buffer code. xemacs.mak: Split up CFLAGS into a version without flags specifying the C library. The problem seems to be that minitar depends on zlib, which depends specifically on libc.lib, not on any of the other C libraries. Unless you compile with libc.lib, you get errors -- specifically, no _errno in the other libraries, which must make it something other than an int. (#### But this doesn't seem to obtain in XEmacs, which also uses zlib, and can be linked with any of the C libraries. Maybe zlib is used differently and doesn't need errno, or maybe XEmacs provides an int errno; ... I don't understand. Makefile.in.in: Fix so that packages are around when testing. abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, casetab.h, charset.h, chartab.c, chartab.h, cmds.c, console-msw.h, console-stream.c, console-x.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dialog-msw.c, dialog-x.c, dired-msw.c, dired.c, doc.c, doprnt.c, dumper.c, editfns.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, events.h, extents.c, extents.h, faces.c, file-coding.c, file-coding.h, fileio.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, frame.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-msw.h, glyphs-x.c, glyphs.c, glyphs.h, gui-msw.c, gui-x.c, gui.h, gutter.h, hash.h, indent.c, insdel.c, intl-win32.c, intl.c, keymap.c, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, marker.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, nas.c, objects-msw.c, objects-x.c, opaque.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, process.h, profile.c, rangetab.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, regex.h, scrollbar-msw.c, search.c, select-x.c, specifier.c, specifier.h, symbols.c, symsinit.h, syntax.c, syntax.h, syswindows.h, tests.c, text.c, text.h, tooltalk.c, ui-byhand.c, ui-gtk.c, unicode.c, win32.c, window.c: Another big Ben patch. -- FUNCTIONALITY CHANGES: add partial support for 8-bit-fixed, 16-bit-fixed, and 32-bit-fixed formats. not quite done yet. (in particular, needs functions to actually convert the buffer.) NOTE: lots of changes to regex.c here. also, many new *_fmt() inline funs that take an Internal_Format argument. redo syntax cache code. make the cache per-buffer; keep the cache valid across calls to functions that use it. also keep it valid across insertions/deletions and extent changes, as much as is possible. eliminate the junky regex-reentrancy code by passing in the relevant lisp info to the regex routines as local vars. add general mechanism in extents code for signalling extent changes. fix numerous problems with the case-table implementation; yoshiki never properly transferred many algorithms from old-style to new-style case tables. redo char tables to support a default argument, so that mapping only occurs over changed args. change many chartab functions to accept Lisp_Object instead of Lisp_Char_Table *. comment out the code in font-lock.c by default, because font-lock.el no longer uses it. we should consider eliminating it entirely. Don't output bell as ^G in console-stream when not a TTY. add -mswindows-termination-handle to interface with i.c, so we can properly kill a build. add more error-checking to buffer/string macros. add some additional buffer_or_string_() funs. -- INTERFACE CHANGES AFFECTING MORE CODE: switch the arguments of write_c_string and friends to be consistent with write_fmt_string, which must have printcharfun first. change BI_* macros to BYTE_* for increased clarity; similarly for bi_* local vars. change VOID_TO_LISP to be a one-argument function. eliminate no-longer-needed CVOID_TO_LISP. -- char/string macro changes: rename MAKE_CHAR() to make_emchar() for slightly less confusion with make_char(). (The former generates an Emchar, the latter a Lisp object. Conceivably we should rename make_char() -> wrap_char() and similarly for make_int(), make_float().) Similar changes for other *CHAR* macros -- we now consistently use names with `emchar' whenever we are working with Emchars. Any remaining name with just `char' always refers to a Lisp object. rename macros with XSTRING_* to string_* except for those that reference actual fields in the Lisp_String object, following conventions used elsewhere. rename set_string_{data,length} macros (the only ones to work with a Lisp_String_* instead of a Lisp_Object) to set_lispstringp_* to make the difference clear. try to be consistent about caps vs. lowercase in macro/inline-fun names for chars and such, which wasn't the case before. we now reserve caps either for XFOO_ macros that reference object fields (e.g. XSTRING_DATA) or for things that have non-function semantics, e.g. directly modifying an arg (BREAKUP_EMCHAR) or evaluating an arg (any arg) more than once. otherwise, use lowercase. here is a summary of most of the macros/inline funs changed by all of the above changes: BYTE_*_P -> byte_*_p XSTRING_BYTE -> string_byte set_string_data/length -> set_lispstringp_data/length XSTRING_CHAR_LENGTH -> string_char_length XSTRING_CHAR -> string_emchar INTBYTE_FIRST_BYTE_P -> intbyte_first_byte_p INTBYTE_LEADING_BYTE_P -> intbyte_leading_byte_p charptr_copy_char -> charptr_copy_emchar LEADING_BYTE_* -> leading_byte_* CHAR_* -> EMCHAR_* *_CHAR_* -> *_EMCHAR_* *_CHAR -> *_EMCHAR CHARSET_BY_ -> charset_by_* BYTE_SHIFT_JIS* -> byte_shift_jis* BYTE_BIG5* -> byte_big5* REP_BYTES_BY_FIRST_BYTE -> rep_bytes_by_first_byte char_to_unicode -> emchar_to_unicode valid_char_p -> valid_emchar_p Change intbyte_strcmp -> qxestrcmp_c (duplicated functionality). -- INTERFACE CHANGES AFFECTING LESS CODE: use DECLARE_INLINE_HEADER in various places. remove '#ifdef emacs' from XEmacs-only files. eliminate CHAR_TABLE_VALUE(), which duplicated the functionality of get_char_table(). add BUFFER_TEXT_LOOP to simplify iterations over buffer text. define typedefs for signed and unsigned types of fixed sizes (INT_32_BIT, UINT_32_BIT, etc.). create ALIGN_FOR_TYPE as a higher-level interface onto ALIGN_SIZE; fix code to use it. add charptr_emchar_len to return the text length of the character pointed to by a ptr; use it in place of charcount_to_bytecount(..., 1). add emchar_len to return the text length of a given character. add types Bytexpos and Charxpos to generalize Bytebpos/Bytecount and Charbpos/Charcount, in code (particularly, the extents code and redisplay code) that works with either kind of index. rename redisplay struct params with names such as `charbpos' to e.g. `charpos' when they are e.g. a Charxpos, not a Charbpos. eliminate xxDEFUN in place of DEFUN; no longer necessary with changes awhile back to doc.c. split up big ugly combined list of EXFUNs in lisp.h on a file-by-file basis, since other prototypes are similarly split. rewrite some "*_UNSAFE" macros as inline funs and eliminate the _UNSAFE suffix. move most string code from lisp.h to text.h; the string code and text.h code is now intertwined in such a fashion that they need to be in the same place and partially interleaved. (you can't create forward references for inline funs) automated/lisp-tests.el, automated/symbol-tests.el, automated/test-harness.el: Fix test harness to output FAIL messages to stderr when in batch mode. Fix up some problems in lisp-tests/symbol-tests that were causing spurious failures.
author ben
date Sun, 05 May 2002 11:33:57 +0000
parents 943eaba38521
children 70921960b980
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; bytecomp.el --- compilation of Lisp code into byte code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;;; Copyright (C) 1985-1987, 1991-1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ;;; Copyright (C) 1996 Ben Wing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
6 ;; Authors: Jamie Zawinski <jwz@jwz.org>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Hallvard Furuseth <hbf@ulrik.uio.no>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
8 ;; Ben Wing <ben@xemacs.org>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
9 ;; Martin Buchholz <martin@xemacs.org>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
10 ;; Richard Stallman <rms@gnu.org>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
11 ;; Keywords: internal lisp
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
12
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
13 (defconst byte-compile-version "2.27 XEmacs; 2000-09-12.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;; along with XEmacs; see the file COPYING. If not, write to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;;; Synched up with: FSF 19.30.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;; The Emacs Lisp byte compiler. This crunches lisp source into a
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
37 ;; sort of p-code (`bytecode') which takes up less space and can be
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
38 ;; interpreted faster. First, the source code forms are converted to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
39 ;; an intermediate form, `lapcode' [`LAP' == `Lisp Assembly Program']
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
40 ;; which is much easier to manipulate than bytecode. Then the lapcode
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
41 ;; is converted to bytecode, which can be considered to be actual
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
42 ;; machine language. Optimizations can occur at either the source
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
43 ;; level or the lapcode level.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
44
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
45 ;; The user entry points are byte-compile-file,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 ;; byte-recompile-directory and byte-compile-buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 ;;; ========================================================================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 ;;; Entry points:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 ;;; byte-recompile-directory, byte-compile-file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 ;;; batch-byte-compile, batch-byte-recompile-directory,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 ;;; byte-compile, compile-defun,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 ;;; display-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 ;;; RMS says:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 ;;; (byte-compile-buffer and byte-compile-and-load-file were turned off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 ;;; because they are not terribly useful and get in the way of completion.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 ;;; But I'm leaving them. --ben
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 ;;; This version of the byte compiler has the following improvements:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 ;;; + optimization of compiled code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 ;;; - removal of unreachable code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 ;;; - removal of calls to side-effectless functions whose return-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 ;;; is unused;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 ;;; - compile-time evaluation of safe constant forms, such as (consp nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 ;;; and (ash 1 6);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 ;;; - open-coding of literal lambdas;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 ;;; - peephole optimization of emitted code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 ;;; - trivial functions are left uncompiled for speed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 ;;; + support for inline functions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 ;;; + compile-time evaluation of arbitrary expressions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 ;;; + compile-time warning messages for:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 ;;; - functions being redefined with incompatible arglists;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 ;;; - functions being redefined as macros, or vice-versa;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 ;;; - functions or macros defined multiple times in the same file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 ;;; - functions being called with the incorrect number of arguments;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 ;;; - functions being called which are not defined globally, in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 ;;; file, or as autoloads;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 ;;; - assignment and reference of undeclared free variables;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 ;;; - various syntax errors;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 ;;; + correct compilation of nested defuns, defmacros, defvars and defsubsts;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 ;;; + correct compilation of top-level uses of macros;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 ;;; + the ability to generate a histogram of functions called.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 ;;; User customization variables:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 ;;; byte-compile-verbose Whether to report the function currently being
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 ;;; compiled in the minibuffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 ;;; byte-optimize Whether to do optimizations; this may be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 ;;; t, nil, 'source, or 'byte;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 ;;; byte-optimize-log Whether to report (in excruciating detail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 ;;; exactly which optimizations have been made.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 ;;; This may be t, nil, 'source, or 'byte;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 ;;; byte-compile-error-on-warn Whether to stop compilation when a warning is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 ;;; produced;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 ;;; byte-compile-delete-errors Whether the optimizer may delete calls or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 ;;; variable references that are side-effect-free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 ;;; except that they may return an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 ;;; byte-compile-generate-call-tree Whether to generate a histogram of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 ;;; function calls. This can be useful for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 ;;; finding unused functions, as well as simple
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 ;;; performance metering.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 ;;; byte-compile-warnings List of warnings to issue, or t. May contain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 ;;; 'free-vars (references to variables not in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 ;;; current lexical scope)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 ;;; 'unused-vars (non-global variables bound but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 ;;; not referenced)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 ;;; 'unresolved (calls to unknown functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ;;; 'callargs (lambda calls with args that don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 ;;; match the lambda's definition)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ;;; 'subr-callargs (calls to subrs with args that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ;;; don't match the subr's definition)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ;;; 'redefine (function cell redefined from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ;;; a macro to a lambda or vice versa,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ;;; or redefined to take other args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ;;; 'obsolete (obsolete variables and functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ;;; 'pedantic (references to Emacs-compatible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ;;; symbols)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ;;; byte-compile-emacs19-compatibility Whether the compiler should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 ;;; generate .elc files which can be loaded into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 ;;; generic emacs 19.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 ;;; emacs-lisp-file-regexp Regexp for the extension of source-files;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
124 ;;; see also the function `byte-compile-dest-file'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 ;;; byte-compile-overwrite-file If nil, delete old .elc files before saving.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 ;;; Most of the above parameters can also be set on a file-by-file basis; see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 ;;; the documentation of the `byte-compiler-options' macro.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 ;;; New Features:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 ;;; o The form `defsubst' is just like `defun', except that the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 ;;; generated will be open-coded in compiled code which uses it. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 ;;; means that no function call will be generated, it will simply be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 ;;; spliced in. Lisp functions calls are very slow, so this can be a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 ;;; big win.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 ;;; You can generally accomplish the same thing with `defmacro', but in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 ;;; that case, the defined procedure can't be used as an argument to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 ;;; mapcar, etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 ;;; o You can make a given function be inline even if it has already been
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 ;;; defined with `defun' by using the `proclaim-inline' form like so:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 ;;; (proclaim-inline my-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 ;;; This is, in fact, exactly what `defsubst' does. To make a function no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 ;;; longer be inline, you must use `proclaim-notinline'. Beware that if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 ;;; you define a function with `defsubst' and later redefine it with
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
148 ;;; `defun', it will still be open-coded until you use `proclaim-notinline'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 ;;; o You can also open-code one particular call to a function without
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 ;;; open-coding all calls. Use the 'inline' form to do this, like so:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 ;;; (inline (foo 1 2 3)) ;; `foo' will be open-coded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 ;;; or...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 ;;; (inline ;; `foo' and `baz' will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 ;;; (foo 1 2 3 (bar 5)) ;; open-coded, but `bar' will not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 ;;; (baz 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 ;;; o It is possible to open-code a function in the same file it is defined
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 ;;; in without having to load that file before compiling it. the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 ;;; byte-compiler has been modified to remember function definitions in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 ;;; the compilation environment in the same way that it remembers macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 ;;; definitions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 ;;; o Forms like ((lambda ...) ...) are open-coded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 ;;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
167 ;;; o The form `eval-when-compile' is like `progn', except that the body
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 ;;; is evaluated at compile-time. When it appears at top-level, this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 ;;; is analogous to the Common Lisp idiom (eval-when (compile) ...).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 ;;; When it does not appear at top-level, it is similar to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 ;;; Common Lisp #. reader macro (but not in interpreted code).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 ;;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
173 ;;; o The form `eval-and-compile' is similar to `eval-when-compile',
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
174 ;;; but the whole form is evalled both at compile-time and at run-time.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 ;;; o The command M-x byte-compile-and-load-file does what you'd think.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 ;;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
178 ;;; o The command `compile-defun' is analogous to `eval-defun'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 ;;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
180 ;;; o If you run `byte-compile-file' on a filename which is visited in a
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 ;;; buffer, and that buffer is modified, you are asked whether you want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 ;;; to save the buffer before compiling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 ;;; o You can add this to /etc/magic to make file(1) recognize the files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 ;;; generated by this compiler:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 ;;;
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 549
diff changeset
187 ;;; 0 string ;ELC XEmacs Lisp compiled file,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 ;;; >4 byte x version %d
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 ;;; TO DO:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 ;;; o Should implement declarations and proclamations, notably special,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 ;;; unspecial, and ignore. Do this in such a way as to not break cl.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 ;;; o The bound-but-not-used warnings are not issued for variables whose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 ;;; bindings were established in the arglist, due to the lack of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 ;;; ignore declaration. Once ignore exists, this should be turned on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 ;;; o Warn about functions and variables defined but not used?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 ;;; Maybe add some kind of `export' declaration for this?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 ;;; (With interactive functions being automatically exported?)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 ;;; o Any reference to a variable, even one which is a no-op, will cause
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 ;;; the warning not to be given. Possibly we could use the for-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 ;;; flag to determine when this reference is useless; possibly more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 ;;; complex flow analysis would be necessary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 ;;; o If the optimizer deletes a variable reference, we might be left with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 ;;; a bound-but-not-referenced warning. Generally this is ok, but not if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 ;;; it's a synergistic result of macroexpansion. Need some way to note
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 ;;; that a varref is being optimized away? Of course it would be nice to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 ;;; optimize away the binding too, someday, but it's unsafe today.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 ;;; o (See byte-optimize.el for the optimization TODO list.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (require 'backquote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (or (fboundp 'defsubst)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 ;; This really ought to be loaded already!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 (load-library "bytecomp-runtime"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (eval-when-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (defvar byte-compile-single-version nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 "If this is true, the choice of emacs version (v19 or v20) byte-codes will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 be hard-coded into bytecomp when it compiles itself. If the compiler itself
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 is compiled with optimization, this causes a speedup.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (byte-compile-single-version
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 (defmacro byte-compile-single-version () t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 (defmacro byte-compile-version-cond (cond) (list 'quote (eval cond))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (defmacro byte-compile-single-version () nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (defmacro byte-compile-version-cond (cond) cond)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
232 (defvar emacs-lisp-file-regexp "\\.el$"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 "*Regexp which matches Emacs Lisp source files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 You may want to redefine `byte-compile-dest-file' if you change this.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 ;; This enables file name handlers such as jka-compr
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 ;; to remove parts of the file name that should not be copied
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 ;; through to the output file name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (defun byte-compiler-base-file-name (filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (let ((handler (find-file-name-handler filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 'byte-compiler-base-file-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (if handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (funcall handler 'byte-compiler-base-file-name filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 filename)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (unless (fboundp 'byte-compile-dest-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 ;; The user may want to redefine this along with emacs-lisp-file-regexp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 ;; so only define it if it is undefined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (defun byte-compile-dest-file (filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 "Convert an Emacs Lisp source file name to a compiled file name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (setq filename (byte-compiler-base-file-name filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (setq filename (file-name-sans-versions filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 (if (string-match emacs-lisp-file-regexp filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (concat (substring filename 0 (match-beginning 0)) ".elc")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (concat filename ".elc"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 ;; This can be the 'byte-compile property of any symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (autoload 'byte-compile-inline-expand "byte-optimize")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 ;; This is the entrypoint to the lapcode optimizer pass1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (autoload 'byte-optimize-form "byte-optimize")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 ;; This is the entrypoint to the lapcode optimizer pass2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (autoload 'byte-optimize-lapcode "byte-optimize")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (autoload 'byte-compile-unfold-lambda "byte-optimize")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 ;; This is the entry point to the decompiler, which is used by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 ;; disassembler. The disassembler just requires 'byte-compile, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 ;; that doesn't define this function, so this seems to be a reasonable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 ;; thing to do.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (autoload 'byte-decompile-bytecode "byte-optimize")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (defvar byte-compile-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (and (not noninteractive) (> (device-baud-rate) search-slow-speed))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 "*Non-nil means print messages describing progress of byte-compiler.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (defvar byte-compile-emacs19-compatibility
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (not (emacs-version>= 20))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 "*Non-nil means generate output that can run in Emacs 19.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (defvar byte-compile-print-gensym t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 "*Non-nil means generate code that creates unique symbols at run-time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 This is achieved by printing uninterned symbols using the `#:SYMBOL'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 notation, so that they will be read uninterned when run.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 With this feature, code that uses uninterned symbols in macros will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 not be runnable under pre-21.0 XEmacsen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 When `byte-compile-emacs19-compatibility' is non-nil, this variable is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 ignored and considered to be nil.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 (defvar byte-optimize t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 "*Enables optimization in the byte compiler.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 nil means don't do any optimization.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 t means do all optimizations.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 `source' means do source-level optimizations only.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 `byte' means do code-level optimizations only.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (defvar byte-compile-delete-errors t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 "*If non-nil, the optimizer may delete forms that may signal an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 This includes variable references and calls to functions such as `car'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 ;; XEmacs addition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (defvar byte-compile-new-bytecodes nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 "This is completely ignored. It is only around for backwards
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 compatibility.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 ;; FSF enables byte-compile-dynamic-docstrings but not byte-compile-dynamic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 ;; by default. This would be a reasonable conservative approach except
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 ;; for the fact that if you enable either of these, you get incompatible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 ;; byte code that can't be read by XEmacs 19.13 or before or FSF 19.28 or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 ;; before.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 ;; Therefore, neither is enabled for 19.14. Both are enabled for 20.0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 ;; because we have no reason to be conservative about changing the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 ;; way things work. (Ben)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 ;; However, I don't think that defaulting byte-compile-dynamic to nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 ;; is a compatibility issue - rather it is a performance issue.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 ;; Therefore I am setting byte-compile-dynamic back to nil. (mrb)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 (defvar byte-compile-dynamic nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 "*If non-nil, compile function bodies so they load lazily.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 They are hidden comments in the compiled file, and brought into core when the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 function is called.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 To enable this option, make it a file-local variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 in the source file you want it to apply to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 For example, add -*-byte-compile-dynamic: t;-*- on the first line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 When this option is true, if you load the compiled file and then move it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 the functions you loaded will not be able to run.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (defvar byte-compile-dynamic-docstrings (emacs-version>= 20)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 "*If non-nil, compile doc strings for lazy access.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 We bury the doc strings of functions and variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 inside comments in the file, and bring them into core only when they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 are actually needed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 When this option is true, if you load the compiled file and then move it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 you won't be able to find the documentation of anything in that file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 To disable this option for a certain file, make it a file-local variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 in the source file. For example, add this to the first line:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 -*-byte-compile-dynamic-docstrings:nil;-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 You can also set the variable globally.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 This option is enabled by default because it reduces Emacs memory usage.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (defvar byte-optimize-log nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 "*If true, the byte-compiler will log its optimizations into *Compile-Log*.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 If this is 'source, then only source-level optimizations will be logged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 If it is 'byte, then only byte-level optimizations will be logged.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (defvar byte-compile-error-on-warn nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 "*If true, the byte-compiler reports warnings with `error'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 ;; byte-compile-warning-types in FSF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (defvar byte-compile-default-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 '(redefine callargs subr-callargs free-vars unresolved unused-vars obsolete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 "*The warnings used when byte-compile-warnings is t.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (defvar byte-compile-warnings t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 "*List of warnings that the compiler should issue (t for the default set).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 Elements of the list may be:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 free-vars references to variables not in the current lexical scope.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 unused-vars references to non-global variables bound but not referenced.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 unresolved calls to unknown functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 callargs lambda calls with args that don't match the definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 subr-callargs calls to subrs with args that don't match the definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 redefine function cell redefined from a macro to a lambda or vice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 versa, or redefined to take a different number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 obsolete use of an obsolete function or variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 pedantic warn of use of compatible symbols.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 The default set is specified by `byte-compile-default-warnings' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 normally encompasses all possible warnings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 See also the macro `byte-compiler-options'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 (defvar byte-compile-generate-call-tree nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 "*Non-nil means collect call-graph information when compiling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 This records functions that were called and from where.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 If the value is t, compilation displays the call graph when it finishes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 If the value is neither t nor nil, compilation asks you whether to display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 the graph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 The call tree only lists functions called, not macros used. Those functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 which the byte-code interpreter knows about directly (eq, cons, etc.) are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 not reported.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 The call tree also lists those functions which are not known to be called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 \(that is, to which no calls have been compiled). Functions which can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 invoked interactively are excluded from this list.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (defconst byte-compile-call-tree nil "Alist of functions and their call tree.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 Each element looks like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 \(FUNCTION CALLERS CALLS\)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 where CALLERS is a list of functions that call FUNCTION, and CALLS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 is a list of functions for which calls were generated while compiling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 FUNCTION.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (defvar byte-compile-call-tree-sort 'name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 "*If non-nil, sort the call tree.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 The values `name', `callers', `calls', `calls+callers'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 specify different fields to sort on.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (defvar byte-compile-overwrite-file t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 "If nil, old .elc files are deleted before the new is saved, and .elc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 files will have the same modes as the corresponding .el file. Otherwise,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 existing .elc files will simply be overwritten, and the existing modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 will not be changed. If this variable is nil, then an .elc file which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 is a symbolic link will be turned into a normal file, instead of the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 which the link points to being overwritten.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 (defvar byte-recompile-directory-ignore-errors-p nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 "If true, then `byte-recompile-directory' will continue compiling even
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 when an error occurs in a file. This is bound to t by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 `batch-byte-recompile-directory'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
424 (defvar byte-recompile-ignore-uncompilable-mule-files t
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
425 "If non-nil, `byte-recompile-*' ignores non-ASCII .el files in a non-Mule
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
426 XEmacs. This assumes that such files have a -*- coding: ??? -*- magic
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
427 cookie in their first line or a ;;;###coding system: magic cookie
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
428 early in the file.")
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
429
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (defvar byte-recompile-directory-recursively t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 "*If true, then `byte-recompile-directory' will recurse on subdirectories.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 (defvar byte-compile-constants nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 "list of all constants encountered during compilation of this form")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 (defvar byte-compile-variables nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 "list of all variables encountered during compilation of this form")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (defvar byte-compile-bound-variables nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 "Alist of variables bound in the context of the current form,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 that is, the current lexical environment. This list lives partly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 on the specbind stack. The cdr of each cell is an integer bitmask.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (defconst byte-compile-referenced-bit 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (defconst byte-compile-assigned-bit 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 (defconst byte-compile-arglist-bit 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (defconst byte-compile-global-bit 8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 (defvar byte-compile-free-references)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 (defvar byte-compile-free-assignments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 (defvar byte-compiler-error-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
452 ;;; A form of eval that includes the currently defined macro definitions.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
453 ;;; This helps implement the promise made in the Lispref:
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
454 ;;;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
455 ;;; "If a file being compiled contains a `defmacro' form, the macro is
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
456 ;;; defined temporarily for the rest of the compilation of that file."
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
457 (defun byte-compile-eval (form)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
458 (let ((save-macro-environment nil))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
459 (unwind-protect
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
460 (loop for (sym . def) in byte-compile-macro-environment do
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
461 (push
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
462 (if (fboundp sym) (cons sym (symbol-function sym)) sym)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
463 save-macro-environment)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
464 (fset sym (cons 'macro def))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
465 finally return (eval form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
466 (dolist (elt save-macro-environment)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
467 (if (symbolp elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
468 (fmakunbound elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
469 (fset (car elt) (cdr elt)))))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
470
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 (defconst byte-compile-initial-macro-environment
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
472 '((byte-compiler-options . (lambda (&rest forms)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
473 (apply 'byte-compiler-options-handler forms)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
474 (eval-when-compile . (lambda (&rest body)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
475 (list 'quote (byte-compile-eval (cons 'progn body)))))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
476 (eval-and-compile . (lambda (&rest body)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
477 (byte-compile-eval (cons 'progn body))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
478 (cons 'progn body))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 "The default macro-environment passed to macroexpand by the compiler.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 Placing a macro here will cause a macro to have different semantics when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 expanded by the compiler as when expanded by the interpreter.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 (defvar byte-compile-macro-environment byte-compile-initial-macro-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 "Alist of macros defined in the file being compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 Each element looks like (MACRONAME . DEFINITION). It is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 \(MACRONAME . nil) when a macro is redefined as a function.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 (defvar byte-compile-function-environment nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 "Alist of functions defined in the file being compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 This is so we can inline them when necessary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 Each element looks like (FUNCTIONNAME . DEFINITION). It is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 \(FUNCTIONNAME . nil) when a function is redefined as a macro.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 (defvar byte-compile-autoload-environment nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 "Alist of functions and macros defined by autoload in the file being compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 This is so we can suppress warnings about calls to these functions, even though
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 they do not have `real' definitions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 Each element looks like (FUNCTIONNAME . CALL-TO-AUTOLOAD).")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 (defvar byte-compile-unresolved-functions nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 "Alist of undefined functions to which calls have been compiled (used for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 warnings when the function is later defined with incorrect args).")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 (defvar byte-compile-file-domain) ; domain of file being compiled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (defvar byte-compile-tag-number 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 (defvar byte-compile-output nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 "Alist describing contents to put in byte code string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 Each element is (INDEX . VALUE)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 (defvar byte-compile-depth 0 "Current depth of execution stack.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 (defvar byte-compile-maxdepth 0 "Maximum depth of execution stack.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 ;;; The byte codes; this information is duplicated in bytecode.c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 (defconst byte-code-vector nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 "An array containing byte-code names indexed by byte-code values.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (defconst byte-stack+-info nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 "An array with the stack adjustment for each byte-code.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 (defmacro byte-defop (opcode stack-adjust opname &optional docstring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 ;; This is a speed-hack for building the byte-code-vector at compile-time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 ;; We fill in the vector at macroexpand-time, and then after the last call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 ;; to byte-defop, we write the vector out as a constant instead of writing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 ;; out a bunch of calls to aset.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 ;; Actually, we don't fill in the vector itself, because that could make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 ;; it problematic to compile big changes to this compiler; we store the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 ;; values on its plist, and remove them later in -extrude.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 (let ((v1 (or (get 'byte-code-vector 'tmp-compile-time-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 (put 'byte-code-vector 'tmp-compile-time-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (make-vector 256 nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (v2 (or (get 'byte-stack+-info 'tmp-compile-time-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 (put 'byte-stack+-info 'tmp-compile-time-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 (make-vector 256 nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 (aset v1 opcode opname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 (aset v2 opcode stack-adjust))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 (if docstring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 (list 'defconst opname opcode (concat "Byte code opcode " docstring "."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (list 'defconst opname opcode)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 (defmacro byte-extrude-byte-code-vectors ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (prog1 (list 'setq 'byte-code-vector
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (get 'byte-code-vector 'tmp-compile-time-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 'byte-stack+-info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 (get 'byte-stack+-info 'tmp-compile-time-value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 (remprop 'byte-code-vector 'tmp-compile-time-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 (remprop 'byte-stack+-info 'tmp-compile-time-value)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 ;; unused: 0-7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 ;; These opcodes are special in that they pack their argument into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 ;; opcode word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 (byte-defop 8 1 byte-varref "for variable reference")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 (byte-defop 16 -1 byte-varset "for setting a variable")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 (byte-defop 24 -1 byte-varbind "for binding a variable")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 (byte-defop 32 0 byte-call "for calling a function")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 (byte-defop 40 0 byte-unbind "for unbinding special bindings")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 ;; codes 8-47 are consumed by the preceding opcodes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 ;; unused: 48-55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 (byte-defop 56 -1 byte-nth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 (byte-defop 57 0 byte-symbolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 (byte-defop 58 0 byte-consp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 (byte-defop 59 0 byte-stringp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 (byte-defop 60 0 byte-listp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 (byte-defop 61 -1 byte-old-eq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 (byte-defop 62 -1 byte-old-memq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 (byte-defop 63 0 byte-not)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 (byte-defop 64 0 byte-car)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 (byte-defop 65 0 byte-cdr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 (byte-defop 66 -1 byte-cons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 (byte-defop 67 0 byte-list1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 (byte-defop 68 -1 byte-list2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 (byte-defop 69 -2 byte-list3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 (byte-defop 70 -3 byte-list4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 (byte-defop 71 0 byte-length)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 (byte-defop 72 -1 byte-aref)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 (byte-defop 73 -2 byte-aset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 (byte-defop 74 0 byte-symbol-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 (byte-defop 75 0 byte-symbol-function) ; this was commented out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 (byte-defop 76 -1 byte-set)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 (byte-defop 77 -1 byte-fset) ; this was commented out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 (byte-defop 78 -1 byte-get)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 (byte-defop 79 -2 byte-substring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 (byte-defop 80 -1 byte-concat2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 (byte-defop 81 -2 byte-concat3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 (byte-defop 82 -3 byte-concat4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 (byte-defop 83 0 byte-sub1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 (byte-defop 84 0 byte-add1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 (byte-defop 85 -1 byte-eqlsign)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 (byte-defop 86 -1 byte-gtr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 (byte-defop 87 -1 byte-lss)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 (byte-defop 88 -1 byte-leq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 (byte-defop 89 -1 byte-geq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 (byte-defop 90 -1 byte-diff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 (byte-defop 91 0 byte-negate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 (byte-defop 92 -1 byte-plus)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (byte-defop 93 -1 byte-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 (byte-defop 94 -1 byte-min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (byte-defop 95 -1 byte-mult)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 (byte-defop 96 1 byte-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 (byte-defop 97 -1 byte-eq) ; new as of v20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 (byte-defop 98 0 byte-goto-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 (byte-defop 99 0 byte-insert)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 (byte-defop 100 1 byte-point-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 (byte-defop 101 1 byte-point-min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 (byte-defop 102 0 byte-char-after)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 (byte-defop 103 1 byte-following-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 (byte-defop 104 1 byte-preceding-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 (byte-defop 105 1 byte-current-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 (byte-defop 106 0 byte-indent-to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 (byte-defop 107 -1 byte-equal) ; new as of v20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 (byte-defop 108 1 byte-eolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 (byte-defop 109 1 byte-eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 (byte-defop 110 1 byte-bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 (byte-defop 111 1 byte-bobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 (byte-defop 112 1 byte-current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 (byte-defop 113 0 byte-set-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 (byte-defop 114 0 byte-save-current-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 "To make a binding to record the current buffer.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 ;;(byte-defop 114 1 byte-read-char-OBSOLETE) ;obsolete as of v19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 (byte-defop 115 -1 byte-memq) ; new as of v20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 (byte-defop 116 1 byte-interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 (byte-defop 117 0 byte-forward-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 (byte-defop 118 0 byte-forward-word)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 (byte-defop 119 -1 byte-skip-chars-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 (byte-defop 120 -1 byte-skip-chars-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 (byte-defop 121 0 byte-forward-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 (byte-defop 122 0 byte-char-syntax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 (byte-defop 123 -1 byte-buffer-substring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 (byte-defop 124 -1 byte-delete-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 (byte-defop 125 -1 byte-narrow-to-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 (byte-defop 126 1 byte-widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 (byte-defop 127 0 byte-end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 ;; unused: 128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 ;; These store their argument in the next two bytes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 (byte-defop 129 1 byte-constant2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 "for reference to a constant with vector index >= byte-constant-limit")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 (byte-defop 130 0 byte-goto "for unconditional jump")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (byte-defop 131 -1 byte-goto-if-nil "to pop value and jump if it's nil")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 (byte-defop 132 -1 byte-goto-if-not-nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 "to pop value and jump if it's not nil")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 (byte-defop 133 -1 byte-goto-if-nil-else-pop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 "to examine top-of-stack, jump and don't pop it if it's nil,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 otherwise pop it")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 (byte-defop 134 -1 byte-goto-if-not-nil-else-pop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 "to examine top-of-stack, jump and don't pop it if it's non-nil,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 otherwise pop it")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 (byte-defop 135 -1 byte-return "to pop a value and return it from `byte-code'")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (byte-defop 136 -1 byte-discard "to discard one value from stack")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 (byte-defop 137 1 byte-dup "to duplicate the top of the stack")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 (byte-defop 138 0 byte-save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 "to make a binding to record the buffer, point and mark")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 (byte-defop 139 0 byte-save-window-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 "to make a binding to record entire window configuration")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 (byte-defop 140 0 byte-save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 "to make a binding to record the current buffer clipping restrictions")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 (byte-defop 141 -1 byte-catch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 "for catch. Takes, on stack, the tag and an expression for the body")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 (byte-defop 142 -1 byte-unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 "for unwind-protect. Takes, on stack, an expression for the unwind-action")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 ;; For condition-case. Takes, on stack, the variable to bind,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 ;; an expression for the body, and a list of clauses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 (byte-defop 143 -2 byte-condition-case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 ;; For entry to with-output-to-temp-buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 ;; Takes, on stack, the buffer name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 ;; Binds standard-output and does some other things.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 ;; Returns with temp buffer on the stack in place of buffer name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 (byte-defop 144 0 byte-temp-output-buffer-setup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 ;; For exit from with-output-to-temp-buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 ;; Expects the temp buffer on the stack underneath value to return.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 ;; Pops them both, then pushes the value back on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 ;; Unbinds standard-output and makes the temp buffer visible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 (byte-defop 145 -1 byte-temp-output-buffer-show)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 ;; To unbind back to the beginning of this frame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 ;; Not used yet, but will be needed for tail-recursion elimination.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 (byte-defop 146 0 byte-unbind-all)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 (byte-defop 147 -2 byte-set-marker)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 (byte-defop 148 0 byte-match-beginning)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 (byte-defop 149 0 byte-match-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 (byte-defop 150 0 byte-upcase)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 (byte-defop 151 0 byte-downcase)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 (byte-defop 152 -1 byte-string=)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 (byte-defop 153 -1 byte-string<)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 (byte-defop 154 -1 byte-old-equal)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 (byte-defop 155 -1 byte-nthcdr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 (byte-defop 156 -1 byte-elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 (byte-defop 157 -1 byte-old-member)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 (byte-defop 158 -1 byte-old-assq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 (byte-defop 159 0 byte-nreverse)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 (byte-defop 160 -1 byte-setcar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 (byte-defop 161 -1 byte-setcdr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 (byte-defop 162 0 byte-car-safe)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 (byte-defop 163 0 byte-cdr-safe)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 (byte-defop 164 -1 byte-nconc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 (byte-defop 165 -1 byte-quo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 (byte-defop 166 -1 byte-rem)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 (byte-defop 167 0 byte-numberp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 (byte-defop 168 0 byte-integerp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 ;; unused: 169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 ;; These are not present in FSF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 (byte-defop 170 0 byte-rel-goto)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 (byte-defop 171 -1 byte-rel-goto-if-nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 (byte-defop 172 -1 byte-rel-goto-if-not-nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 (byte-defop 173 -1 byte-rel-goto-if-nil-else-pop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 (byte-defop 174 -1 byte-rel-goto-if-not-nil-else-pop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 (byte-defop 175 nil byte-listN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 (byte-defop 176 nil byte-concatN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 (byte-defop 177 nil byte-insertN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 ;; unused: 178-181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 ;; these ops are new to v20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 (byte-defop 182 -1 byte-member)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 (byte-defop 183 -1 byte-assq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 ;; unused: 184-191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 (byte-defop 192 1 byte-constant "for reference to a constant")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 ;; codes 193-255 are consumed by byte-constant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 (defconst byte-constant-limit 64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 "Exclusive maximum index usable in the `byte-constant' opcode.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
742 (defconst byte-goto-ops
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
743 '(byte-goto byte-goto-if-nil byte-goto-if-not-nil
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
744 byte-goto-if-nil-else-pop
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
745 byte-goto-if-not-nil-else-pop)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 "List of byte-codes whose offset is a pc.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 (defconst byte-goto-always-pop-ops
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
749 '(byte-goto-if-nil byte-goto-if-not-nil))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 (defconst byte-rel-goto-ops
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
752 '(byte-rel-goto byte-rel-goto-if-nil byte-rel-goto-if-not-nil
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
753 byte-rel-goto-if-nil-else-pop byte-rel-goto-if-not-nil-else-pop)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 "byte-codes for relative jumps.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 (byte-extrude-byte-code-vectors)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 ;;; lapcode generator
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 ;;; the byte-compiler now does source -> lapcode -> bytecode instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 ;;; source -> bytecode, because it's a lot easier to make optimizations
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 ;;; on lapcode than on bytecode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 ;;; Elements of the lapcode list are of the form (<instruction> . <parameter>)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 ;;; where instruction is a symbol naming a byte-code instruction,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 ;;; and parameter is an argument to that instruction, if any.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 ;;; The instruction can be the pseudo-op TAG, which means that this position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 ;;; in the instruction stream is a target of a goto. (car PARAMETER) will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 ;;; the PC for this location, and the whole instruction "(TAG pc)" will be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 ;;; parameter for some goto op.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 ;;; If the operation is varbind, varref, varset or push-constant, then the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 ;;; parameter is (variable/constant . index_in_constant_vector).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 ;;; First, the source code is macroexpanded and optimized in various ways.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 ;;; Then the resultant code is compiled into lapcode. Another set of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 ;;; optimizations are then run over the lapcode. Then the variables and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 ;;; constants referenced by the lapcode are collected and placed in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 ;;; constants-vector. (This happens now so that variables referenced by dead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 ;;; code don't consume space.) And finally, the lapcode is transformed into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 ;;; compacted byte-code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 ;;; A distinction is made between variables and constants because the variable-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 ;;; referencing instructions are more sensitive to the variables being near the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 ;;; front of the constants-vector than the constant-referencing instructions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 ;;; Also, this lets us notice references to free variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 (defun byte-compile-lapcode (lap)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 "Turns lapcode into bytecode. The lapcode is destroyed."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 ;; Lapcode modifications: changes the ID of a tag to be the tag's PC.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 (let ((pc 0) ; Program counter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 op off ; Operation & offset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 (bytes '()) ; Put the output bytes here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 (patchlist nil) ; List of tags and goto's to patch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 rest rel tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 (while lap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 (setq op (car (car lap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 off (cdr (car lap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 (cond ((not (symbolp op))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 (error "Non-symbolic opcode `%s'" op))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 ((eq op 'TAG)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 (setcar off pc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 (push off patchlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 ((memq op byte-goto-ops)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 (setq pc (+ pc 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 (setq bytes (cons (cons pc (cdr off))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 (cons nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 (cons (symbol-value op) bytes))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 (push bytes patchlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 (setq bytes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 (cond ((cond ((consp off)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 ;; Variable or constant reference
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 (setq off (cdr off))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 (eq op 'byte-constant)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 (cond ((< off byte-constant-limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 (setq pc (1+ pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 (cons (+ byte-constant off) bytes))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 (setq pc (+ 3 pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 (cons (lsh off -8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 (cons (logand off 255)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 (cons byte-constant2 bytes))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 ((and (<= byte-listN (symbol-value op))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 (<= (symbol-value op) byte-insertN))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 (setq pc (+ 2 pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 (cons off (cons (symbol-value op) bytes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 ((< off 6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 (setq pc (1+ pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 (cons (+ (symbol-value op) off) bytes))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 ((< off 256)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 (setq pc (+ 2 pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 (cons off (cons (+ (symbol-value op) 6) bytes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 (setq pc (+ 3 pc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 (cons (lsh off -8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 (cons (logand off 255)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 (cons (+ (symbol-value op) 7)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 bytes))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 (setq lap (cdr lap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 ;;(if (not (= pc (length bytes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 ;; (error "Compiler error: pc mismatch - %s %s" pc (length bytes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 (cond (t ;; starting with Emacs 19.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 ;; Make relative jumps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 (setq patchlist (nreverse patchlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 (while (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 (setq off 0) ; PC change because of deleted bytes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 (setq rest patchlist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 (setq tmp (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 (and (consp (car tmp)) ; Jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 (prog1 (null (nth 1 tmp)) ; Absolute jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 (setq tmp (car tmp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 (setq rel (- (car (cdr tmp)) (car tmp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 (and (<= -129 rel) (< rel 128)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 ;; Convert to relative jump.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 (setcdr (car rest) (cdr (cdr (car rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 (setcar (cdr (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 (+ (car (cdr (car rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 (- byte-rel-goto byte-goto)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 (setq off (1- off))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 (setcar tmp (+ (car tmp) off)) ; Adjust PC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 ;; If optimizing, repeat until no change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 (and byte-optimize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 (not (zerop off)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 ;; Patch PC into jumps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 (let (bytes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 (while patchlist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 (setq bytes (car patchlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 (cond ((atom (car bytes))) ; Tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 ((nth 1 bytes) ; Relative jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 (setcar bytes (+ (- (car (cdr (car bytes))) (car (car bytes)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 128)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 (t ; Absolute jump
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 (setq pc (car (cdr (car bytes)))) ; Pick PC from tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 (setcar (cdr bytes) (logand pc 255))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 (setcar bytes (lsh pc -8))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 (setq patchlist (cdr patchlist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 (concat (nreverse bytes))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 ;;; byte compiler messages
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 (defvar byte-compile-current-form nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 (defvar byte-compile-current-file nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 (defvar byte-compile-dest-file nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 (defmacro byte-compile-log (format-string &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 `(when (and byte-optimize (memq byte-optimize-log '(t source)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 (let ((print-escape-newlines t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 (print-level 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 (print-length 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 (byte-compile-log-1 (format ,format-string ,@args)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 (defconst byte-compile-last-warned-form 'nothing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 ;; Log a message STRING in *Compile-Log*.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 ;; Also log the current function and file if not already done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 (defun byte-compile-log-1 (string &optional fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 (let* ((this-form (or byte-compile-current-form "toplevel forms"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 (while-compiling-msg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 (when (or byte-compile-current-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 (not (eq this-form byte-compile-last-warned-form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 (format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 "While compiling %s%s:"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 this-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 ((stringp byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 (concat " in file " byte-compile-current-file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 ((bufferp byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 (concat " in buffer "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 (buffer-name byte-compile-current-file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 (""))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 (if noninteractive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 (when while-compiling-msg (message "%s" while-compiling-msg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 (message " %s" string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 (with-current-buffer (get-buffer-create "*Compile-Log*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 (when byte-compile-current-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 (when (> (point-max) (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 (insert "\n\^L\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 (insert (current-time-string) "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 (when while-compiling-msg (insert while-compiling-msg "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 (insert " " string "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 (when (and fill (not (string-match "\n" string)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 (let ((fill-prefix " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 (fill-column 78))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 (fill-paragraph nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 (setq byte-compile-current-file nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 (setq byte-compile-last-warned-form this-form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 ;; Log the start of a file in *Compile-Log*, and mark it as done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 ;; But do nothing in batch mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 (defun byte-compile-log-file ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 (when (and byte-compile-current-file (not noninteractive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 (with-current-buffer (get-buffer-create "*Compile-Log*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 (when (> (point-max) (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 (insert "\n\^L\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 (insert "Compiling "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 (if (stringp byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 (concat "file " byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 (concat "buffer " (buffer-name byte-compile-current-file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 " at " (current-time-string) "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 (setq byte-compile-current-file nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
952 (defvar byte-compile-inbuffer)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
953 (defvar byte-compile-outbuffer)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
954
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 (defun byte-compile-warn (format &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 (setq format (apply 'format format args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 (if byte-compile-error-on-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 (error "%s" format) ; byte-compile-file catches and logs it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 (byte-compile-log-1 (concat "** " format) t)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
960
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
961 ;; This was a first attempt to add line numbers to the
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
962 ;; byte-compilation output. Unfortunately, it doesn't work
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
963 ;; perfectly: it reports the line number at the end of the form
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
964 ;; (which may be an entire function), rather than the line number
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
965 ;; of the actual problem. Doing this right is hard because we
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
966 ;; currently use the built-in Lisp parser to parse the entire form
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
967 ;; at once. What we basically need is a whole separate parser
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
968 ;; that annotates its output with line numbers. For example, we
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
969 ;; might modify the parser in lread.c so that, with the right
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
970 ;; option set, it replaces every Lisp object contained in the
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
971 ;; structure it returns with a cons of that object and the line
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
972 ;; number it was found on (determined by counting newlines,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
973 ;; starting from some arbitrary point). You then have two
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
974 ;; options: (a) Modify the byte compiler so that everything that
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
975 ;; compiles a form deals with the new annotated form rather than
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
976 ;; the old one, or (b) The byte compiler saves this structure
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
977 ;; while converting it into a normal structure that's given to the
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
978 ;; various form handlers, which need no (or less) modification.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
979 ;; In the former case, finding the line number is trivial because
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
980 ;; it's in the form. In the latter case, finding the line number
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
981 ;; depends on having a unique Lisp object that can be looked up in
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
982 ;; the annotated structure -- i.e. a list, vector, or string.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
983 ;; You'd have to look at the various places where errors are spit
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
984 ;; out (not very many, really), and make sure that such a unique
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
985 ;; object is available. Then you do a depth-first search through
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
986 ;; the annotated structure to find the object.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
987 ;;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
988 ;; An alternative way of doing (b) that's probably much more
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
989 ;; efficient (and easier to implement) is simply to have the
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
990 ;; parser in lread.c annotate every unique object using a separate
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
991 ;; hash table. This also eliminates the need for a search to find
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
992 ;; the line number. In order to be fine-grained enough to get at
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
993 ;; every symbol in a form -- e.g. if we want to pinpoint a
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
994 ;; particular undefined variable in a function call -- we need to
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
995 ;; annotate every cons, not just each list. We still have
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
996 ;; (probably unimportant) problems with vectors, since all we have
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
997 ;; is the start of the vector. If we cared about this, we could
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
998 ;; store in the hash table a list of the line numbers for each
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
999 ;; item in the vector, not just its start.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1000 ;;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1001 ;; --ben
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1002
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1003 ; (byte-compile-log-1 (concat "** line: "
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1004 ; (save-excursion
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1005 ; (set-buffer byte-compile-inbuffer)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1006 ; (int-to-string (line-number)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1007 ; " "
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1008 ; format) t)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 ;;; RMS says:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 ;;; It is useless to flash warnings too fast to be read.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 ;;; Besides, they will all be shown at the end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 ;;; and comments out the next two lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 (or noninteractive ; already written on stdout.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 (message "Warning: %s" format))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 ;;; This function should be used to report errors that have halted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 ;;; compilation of the current file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 (defun byte-compile-report-error (error-info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 (setq byte-compiler-error-flag t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 (byte-compile-log-1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 (concat "!! "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 (format (if (cdr error-info) "%s (%s)" "%s")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 (get (car error-info) 'error-message)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1024 (prin1-to-string (cdr error-info)))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1025 (if stack-trace-on-error
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1026 (backtrace nil t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 ;;; Used by make-obsolete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 (defun byte-compile-obsolete (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 (let ((new (get (car form) 'byte-obsolete-info)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 (if (memq 'obsolete byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 (byte-compile-warn "%s is an obsolete function; %s" (car form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 (if (stringp (car new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 (car new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 (format "use %s instead." (car new)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 (funcall (or (cdr new) 'byte-compile-normal-call) form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 ;;; Used by make-obsolete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 (defun byte-compile-compatible (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 (let ((new (get (car form) 'byte-compatible-info)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (if (memq 'pedantic byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 (byte-compile-warn "%s is provided for compatibility; %s" (car form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 (if (stringp (car new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 (car new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 (format "use %s instead." (car new)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (funcall (or (cdr new) 'byte-compile-normal-call) form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 ;; Compiler options
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 (defconst byte-compiler-legal-options
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 '((optimize byte-optimize (t nil source byte) val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 (file-format byte-compile-emacs19-compatibility (emacs19 emacs20)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 (eq val 'emacs19))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 (delete-errors byte-compile-delete-errors (t nil) val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 (verbose byte-compile-verbose (t nil) val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 (new-bytecodes byte-compile-new-bytecodes (t nil) val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 (warnings byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 ((callargs subr-callargs redefine free-vars unused-vars unresolved))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 val)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 ;; XEmacs addition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 (defconst byte-compiler-obsolete-options
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 '((new-bytecodes t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 ;; Inhibit v19/v20 selectors if the version is hardcoded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 ;; #### This should print a warning if the user tries to change something
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 ;; than can't be changed because the running compiler doesn't support it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 ((byte-compile-single-version)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 (setcar (cdr (cdr (assq 'file-format byte-compiler-legal-options)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 (if (byte-compile-version-cond byte-compile-emacs19-compatibility)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 '(emacs19) '(emacs20)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 ;; now we can copy it.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1075 (setq byte-compiler-legal-options byte-compiler-legal-options)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 (defun byte-compiler-options-handler (&rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 (let (key val desc choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 (if (or (atom (car args)) (nthcdr 2 (car args)) (null (cdr (car args))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 (error "malformed byte-compiler-option %s" (car args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 (setq key (car (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 val (car (cdr (car args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 desc (assq key byte-compiler-legal-options))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 (or desc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 (error "unknown byte-compiler option %s" key))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 (if (assq key byte-compiler-obsolete-options)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 (byte-compile-warn "%s is an obsolete byte-compiler option." key))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 (setq choices (nth 2 desc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 (if (consp (car choices))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 (let* (this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 (handler 'cons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 (var (nth 1 desc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 (ret (and (memq (car val) '(+ -))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 (copy-sequence (if (eq t (symbol-value var))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 (car choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 (symbol-value var))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 (setq choices (car choices))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 (while val
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 (setq this (car val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 (cond ((memq this choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 (setq ret (funcall handler this ret)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 ((eq this '+) (setq handler 'cons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 ((eq this '-) (setq handler 'delq))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 ((error "%s only accepts %s." key choices)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 (setq val (cdr val)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 (set (nth 1 desc) ret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 (or (memq val choices)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 (error "%s must be one of %s." key choices))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 (set (nth 1 desc) (eval (nth 3 desc))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 (setq args (cdr args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 ;;; sanity-checking arglists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 (defun byte-compile-fdefinition (name macro-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 (let* ((list (if (memq macro-p '(nil subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 byte-compile-function-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 byte-compile-macro-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 (env (cdr (assq name list))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 (or env
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 (let ((fn name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 (while (and (symbolp fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 (fboundp fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 (or (symbolp (symbol-function fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 (consp (symbol-function fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 (and (not macro-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 (compiled-function-p (symbol-function fn)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 (and (eq macro-p 'subr) (subrp fn))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 (setq fn (symbol-function fn)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 (if (or (and (not macro-p) (compiled-function-p fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 (and (eq macro-p 'subr) (subrp fn)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 fn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 (and (consp fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 (not (eq macro-p 'subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 (if (eq 'macro (car fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 (cdr fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 (if macro-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 (if (eq 'autoload (car fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 fn)))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 (defun byte-compile-arglist-signature (arglist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 (let ((args 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 opts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 restp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 (while arglist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 (cond ((eq (car arglist) '&optional)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 (or opts (setq opts 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 ((eq (car arglist) '&rest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 (if (cdr arglist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 (setq restp t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 arglist nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 (if opts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 (setq opts (1+ opts))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 (setq args (1+ args)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 (setq arglist (cdr arglist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 (cons args (if restp nil (if opts (+ args opts) args)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 (defun byte-compile-arglist-signatures-congruent-p (old new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 (not (or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 (> (car new) (car old)) ; requires more args now
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 (and (null (cdr old)) ; tooks rest-args, doesn't any more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 (cdr new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 (and (cdr new) (cdr old) ; can't take as many args now
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 (< (cdr new) (cdr old)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 (defun byte-compile-arglist-signature-string (signature)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 (cond ((null (cdr signature))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 (format "%d+" (car signature)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 ((= (car signature) (cdr signature))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 (format "%d" (car signature)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 (t (format "%d-%d" (car signature) (cdr signature)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 ;; Warn if the form is calling a function with the wrong number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 (defun byte-compile-callargs-warn (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 (let* ((def (or (byte-compile-fdefinition (car form) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 (byte-compile-fdefinition (car form) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 (sig (and def (byte-compile-arglist-signature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 (if (eq 'lambda (car-safe def))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 (nth 1 def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 (if (compiled-function-p def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 (compiled-function-arglist def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 '(&rest def))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 (ncall (length (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 (if (and (null def)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 (fboundp 'subr-min-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 (setq def (byte-compile-fdefinition (car form) 'subr)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 (setq sig (cons (subr-min-args def) (subr-max-args def))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 (if sig
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 (if (or (< ncall (car sig))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 (and (cdr sig) (> ncall (cdr sig))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 "%s called with %d argument%s, but %s %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 (car form) ncall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 (if (= 1 ncall) "" "s")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 (if (< ncall (car sig))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 "requires"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 "accepts only")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 (byte-compile-arglist-signature-string sig)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 (or (fboundp (car form)) ; might be a subr or autoload.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 ;; ## this doesn't work with recursion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 (eq (car form) byte-compile-current-form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 ;; It's a currently-undefined function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 ;; Remember number of args in call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 (let ((cons (assq (car form) byte-compile-unresolved-functions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 (n (length (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 (if cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 (or (memq n (cdr cons))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 (setcdr cons (cons n (cdr cons))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 (setq byte-compile-unresolved-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 (cons (list (car form) n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 byte-compile-unresolved-functions))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 ;; Warn if the function or macro is being redefined with a different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 ;; number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 (defun byte-compile-arglist-warn (form macrop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 (let ((old (byte-compile-fdefinition (nth 1 form) macrop)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 (if old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 (let ((sig1 (byte-compile-arglist-signature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 (if (eq 'lambda (car-safe old))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 (nth 1 old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 (if (compiled-function-p old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 (compiled-function-arglist old)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 '(&rest def)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 (sig2 (byte-compile-arglist-signature (nth 2 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 (or (byte-compile-arglist-signatures-congruent-p sig1 sig2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 (byte-compile-warn "%s %s used to take %s %s, now takes %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 (if (eq (car form) 'defun) "function" "macro")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 (nth 1 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 (byte-compile-arglist-signature-string sig1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 (if (equal sig1 '(1 . 1)) "argument" "arguments")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 (byte-compile-arglist-signature-string sig2))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 ;; This is the first definition. See if previous calls are compatible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 (let ((calls (assq (nth 1 form) byte-compile-unresolved-functions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 nums sig min max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 (if calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 (setq sig (byte-compile-arglist-signature (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 nums (sort (copy-sequence (cdr calls)) (function <))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 min (car nums)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 max (car (nreverse nums)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 (if (or (< min (car sig))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 (and (cdr sig) (> max (cdr sig))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 "%s being defined to take %s%s, but was previously called with %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 (nth 1 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 (byte-compile-arglist-signature-string sig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 (if (equal sig '(1 . 1)) " arg" " args")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 (byte-compile-arglist-signature-string (cons min max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 (setq byte-compile-unresolved-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 (delq calls byte-compile-unresolved-functions)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 ;; If we have compiled any calls to functions which are not known to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 ;; defined, issue a warning enumerating them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 ;; `unresolved' in the list `byte-compile-warnings' disables this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 (defun byte-compile-warn-about-unresolved-functions (&optional msg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 (if (memq 'unresolved byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 (let ((byte-compile-current-form (or msg "the end of the data")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 ;; First delete the autoloads from the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 (if byte-compile-autoload-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 (let ((rest byte-compile-unresolved-functions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 (if (assq (car (car rest)) byte-compile-autoload-environment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 (setq byte-compile-unresolved-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 (delq (car rest) byte-compile-unresolved-functions)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 (setq rest (cdr rest)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 ;; Now warn.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 (if (cdr byte-compile-unresolved-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 (let* ((str "The following functions are not known to be defined: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 (L (+ (length str) 5))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 (rest (reverse byte-compile-unresolved-functions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 (setq s (symbol-name (car (car rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 L (+ L (length s) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 rest (cdr rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 (if (<= L (1- fill-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 (setq str (concat str " " s (and rest ",")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 (setq str (concat str "\n " s (and rest ","))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 L (+ (length s) 4))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 (byte-compile-warn "%s" str))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 (if byte-compile-unresolved-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 (byte-compile-warn "the function %s is not known to be defined."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 (car (car byte-compile-unresolved-functions)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 (defun byte-compile-defvar-p (var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 ;; Whether the byte compiler thinks that non-lexical references to this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 ;; variable are ok.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 (or (globally-boundp var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 (let ((rest byte-compile-bound-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 (while (and rest var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 (if (and (eq var (car-safe (car rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 (not (= 0 (logand (cdr (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 byte-compile-global-bit))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 (setq var nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 ;; if var is nil at this point, it's a defvar in this file.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1307 (not var))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1308 ;; Perhaps (eval-when-compile (defvar foo))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1309 (and (boundp 'current-load-list)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1310 (memq var current-load-list))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 ;;; If we have compiled bindings of variables which have no referents, warn.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 (defun byte-compile-warn-about-unused-variables ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 (let ((rest byte-compile-bound-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 (unreferenced '())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 cell)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 (while (and rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 ;; only warn about variables whose lifetime is now ending,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 ;; that is, variables from the lexical scope that is now
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 ;; terminating. (Think nested lets.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 (not (eq (car rest) 'new-scope)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 (setq cell (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 (if (and (= 0 (logand byte-compile-referenced-bit (cdr cell)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 ;; Don't warn about declared-but-unused arguments,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 ;; for two reasons: first, the arglist structure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 ;; might be imposed by external forces, and we don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 ;; have (declare (ignore x)) yet; and second, inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 ;; expansion produces forms like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 ;; ((lambda (arg) (byte-code "..." [arg])) x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 ;; which we can't (ok, well, don't) recognize as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 ;; containing a reference to arg, so every inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 ;; expansion would generate a warning. (If we had
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 ;; `ignore' then inline expansion could emit an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 ;; ignore declaration.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 (= 0 (logand byte-compile-arglist-bit (cdr cell)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 ;; Don't warn about defvars because this is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 ;; legitimate special binding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 (not (byte-compile-defvar-p (car cell))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 (setq unreferenced (cons (car cell) unreferenced)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 (setq unreferenced (nreverse unreferenced))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 (while unreferenced
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 (format "variable %s bound but not referenced" (car unreferenced)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 (setq unreferenced (cdr unreferenced)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 (defmacro byte-compile-constant-symbol-p (symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 `(or (keywordp ,symbol) (memq ,symbol '(nil t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 (defmacro byte-compile-constp (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 ;; Returns non-nil if FORM is a constant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 `(cond ((consp ,form) (eq (car ,form) 'quote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 ((symbolp ,form) (byte-compile-constant-symbol-p ,form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 (t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 (defmacro byte-compile-close-variables (&rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 `(let
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 (;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 ;; Close over these variables to encapsulate the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 ;; compilation state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 (byte-compile-macro-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 ;; Copy it because the compiler may patch into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 ;; macroenvironment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 (copy-alist byte-compile-initial-macro-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 (byte-compile-function-environment nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 (byte-compile-autoload-environment nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 (byte-compile-unresolved-functions nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 (byte-compile-bound-variables nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 (byte-compile-free-references nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 (byte-compile-free-assignments nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 ;; Close over these variables so that `byte-compiler-options'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 ;; can change them on a per-file basis.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 (byte-compile-verbose byte-compile-verbose)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 (byte-optimize byte-optimize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 (byte-compile-emacs19-compatibility
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 byte-compile-emacs19-compatibility)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 (byte-compile-dynamic byte-compile-dynamic)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 (byte-compile-dynamic-docstrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 byte-compile-dynamic-docstrings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 (byte-compile-warnings (if (eq byte-compile-warnings t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 byte-compile-default-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 byte-compile-warnings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 (byte-compile-file-domain nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 (prog1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 (progn ,@body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 (if (memq 'unused-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 ;; done compiling in this scope, warn now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 (byte-compile-warn-about-unused-variables)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 (defmacro displaying-byte-compile-warnings (&rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 `(let* ((byte-compile-log-buffer (get-buffer-create "*Compile-Log*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 (byte-compile-point-max-prev (point-max byte-compile-log-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 ;; Log the file name or buffer name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 (byte-compile-log-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 ;; Record how much is logged now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 ;; We will display the log buffer if anything more is logged
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 ;; before the end of BODY.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 (defvar byte-compile-warnings-beginning)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 (let ((byte-compile-warnings-beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 (if (boundp 'byte-compile-warnings-beginning)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 byte-compile-warnings-beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 (point-max byte-compile-log-buffer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 (unwind-protect
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1411 (call-with-condition-handler
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1412 #'(lambda (error-info)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1413 (byte-compile-report-error error-info))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1414 #'(lambda ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1415 (progn ,@body)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 ;; Always set point in log to start of interesting output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 (with-current-buffer byte-compile-log-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 (let ((show-begin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 (progn (goto-char byte-compile-point-max-prev)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 (skip-chars-forward "\^L\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 ;; If there were compilation warnings, display them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 (if temp-buffer-show-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 (let ((show-buffer (get-buffer-create "*Compile-Log-Show*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 ;; Always clean show-buffer, even when not displaying it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 ;; so that misleading previous messages aren't left around.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 (with-current-buffer show-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 (setq buffer-read-only nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 (erase-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 (copy-to-buffer show-buffer show-begin (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 (when (< byte-compile-warnings-beginning (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 (funcall temp-buffer-show-function show-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 (when (< byte-compile-warnings-beginning (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 (select-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 (prog1 (selected-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 (select-window (display-buffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 (goto-char show-begin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 (recenter 1)))))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 (defun byte-force-recompile (directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 "Recompile every `.el' file in DIRECTORY that already has a `.elc' file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 Files in subdirectories of DIRECTORY are processed also."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 (interactive "DByte force recompile (directory): ")
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1446 (byte-recompile-directory directory nil nil t))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 (defun byte-recompile-directory (directory &optional arg norecursion force)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 "Recompile every `.el' file in DIRECTORY that needs recompilation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 This is if a `.elc' file exists but is older than the `.el' file.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1452 Files in subdirectories of DIRECTORY are also processed unless
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1453 optional argument NORECURSION is non-nil.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 If the `.elc' file does not exist, normally the `.el' file is *not* compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 But a prefix argument (optional second arg) means ask user,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 for each such `.el' file, whether to compile it. Prefix argument 0 means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 don't ask and compile the file anyway.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 A nonzero prefix argument also means ask about each subdirectory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1462 If the fourth optional argument FORCE is non-nil,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 recompile every `.el' file that already has a `.elc' file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 (interactive "DByte recompile directory: \nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 (setq arg (prefix-numeric-value arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 (if noninteractive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 (save-some-buffers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 (redraw-modeline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 (let ((directories (list (expand-file-name directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 (file-count 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 (dir-count 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 last-dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 (displaying-byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 (while directories
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 (setq directory (file-name-as-directory (car directories)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 (or noninteractive (message "Checking %s..." directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 (let ((files (directory-files directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 source dest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 (while files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 (setq source (expand-file-name (car files) directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 (if (and (not (member (car files) '("." ".." "RCS" "CVS" "SCCS")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 ;; Stay away from directory back-links, etc:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 (not (file-symlink-p source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 (file-directory-p source)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 byte-recompile-directory-recursively)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 ;; This file is a subdirectory. Handle them differently.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 (if (or (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 (eq arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 (y-or-n-p (concat "Check " source "? ")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 (setq directories
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 (nconc directories (list source))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 ;; It is an ordinary file. Decide whether to compile it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 (if (and (string-match emacs-lisp-file-regexp source)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 (not (auto-save-file-name-p source))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1497 ;; make sure not a mule file we can't handle.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1498 (or (not byte-recompile-ignore-uncompilable-mule-files)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1499 (featurep 'mule)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1500 (not (find-coding-system-magic-cookie-in-file
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1501 source)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 (setq dest (byte-compile-dest-file source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 (if (file-exists-p dest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 ;; File was already compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 (or force (file-newer-than-file-p source dest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 ;; No compiled file exists yet.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 (and arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 (or (eq 0 arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 (y-or-n-p (concat "Compile " source "? "))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 (progn ;(if (and noninteractive (not byte-compile-verbose))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 ; (message "Compiling %s..." source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 ; we do this in byte-compile-file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 (if byte-recompile-directory-ignore-errors-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 (batch-byte-compile-1 source)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 (byte-compile-file source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 (or noninteractive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 (message "Checking %s..." directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 (setq file-count (1+ file-count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 (if (not (eq last-dir directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 (setq last-dir directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 dir-count (1+ dir-count)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 (setq files (cdr files))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 (setq directories (cdr directories))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 (message "Done (Total of %d file%s compiled%s)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 file-count (if (= file-count 1) "" "s")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 (if (> dir-count 1) (format " in %d directories" dir-count) ""))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 (defun byte-recompile-file (filename &optional force)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 "Recompile a file of Lisp code named FILENAME if it needs recompilation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 This is if the `.elc' file exists but is older than the `.el' file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 If the `.elc' file does not exist, normally the `.el' file is *not*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 compiled. But a prefix argument (optional second arg) means ask user
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 whether to compile it. Prefix argument 0 don't ask and recompile anyway."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 (interactive "fByte recompile file: \nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 (let ((dest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 (if (and (string-match emacs-lisp-file-regexp filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 (not (auto-save-file-name-p filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 (setq dest (byte-compile-dest-file filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 (if (file-exists-p dest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 (file-newer-than-file-p filename dest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 (and force
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 (or (eq 0 force)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1546 (y-or-n-p (concat "Compile " filename "? ")))))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1547 (or (not byte-recompile-ignore-uncompilable-mule-files)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1548 (featurep 'mule)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 446
diff changeset
1549 (not (find-coding-system-magic-cookie-in-file filename))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 (byte-compile-file filename))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 (defun byte-compile-file (filename &optional load)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 "Compile a file of Lisp code named FILENAME into a file of byte code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 The output file's name is made by appending `c' to the end of FILENAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 With prefix arg (noninteractively: 2nd arg), load the file after compiling."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 ;; (interactive "fByte compile file: \nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 (let ((file buffer-file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 (file-name nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 (file-dir nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 (and file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 (eq (cdr (assq 'major-mode (buffer-local-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 'emacs-lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 (setq file-name (file-name-nondirectory file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 file-dir (file-name-directory file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 (list (read-file-name (if current-prefix-arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 "Byte compile and load file: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 "Byte compile file: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 file-dir nil nil file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 current-prefix-arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 ;; Expand now so we get the current buffer's defaults
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 (setq filename (expand-file-name filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 ;; If we're compiling a file that's in a buffer and is modified, offer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 ;; to save it first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 (or noninteractive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 (let ((b (get-file-buffer (expand-file-name filename))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 (if (and b (buffer-modified-p b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 (y-or-n-p (format "save buffer %s first? " (buffer-name b))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 (save-excursion (set-buffer b) (save-buffer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 (if (or noninteractive byte-compile-verbose) ; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 (message "Compiling %s..." filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 (let (;;(byte-compile-current-file (file-name-nondirectory filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 (byte-compile-current-file filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 target-file input-buffer output-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 byte-compile-dest-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 (setq target-file (byte-compile-dest-file filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 (setq byte-compile-dest-file target-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 (setq input-buffer (get-buffer-create " *Compiler Input*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 (set-buffer input-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 (insert-file-contents filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 ;; Run hooks including the uncompression hook.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 ;; If they change the file name, then change it for the output also.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 (let ((buffer-file-name filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 (default-major-mode 'emacs-lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 (enable-local-eval nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 (normal-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 (setq filename buffer-file-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 (setq byte-compiler-error-flag nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 ;; It is important that input-buffer not be current at this call,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 ;; so that the value of point set in input-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 ;; within byte-compile-from-buffer lingers in that buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 (setq output-buffer (byte-compile-from-buffer input-buffer filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 (if byte-compiler-error-flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 (if byte-compile-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 (message "Compiling %s...done" filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 (kill-buffer input-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 (set-buffer output-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 (insert "\n") ; aaah, unix.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 (setq target-file (byte-compile-dest-file filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 (unless byte-compile-overwrite-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 (ignore-file-errors (delete-file target-file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 (if (file-writable-p target-file)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1621 (write-region 1 (point-max) target-file)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 ;; This is just to give a better error message than write-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 (signal 'file-error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 (list "Opening output file"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 (if (file-exists-p target-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 "cannot overwrite file"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 "directory not writable or nonexistent")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 target-file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 (or byte-compile-overwrite-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 (set-file-modes target-file (file-modes filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 (error nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 (kill-buffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 (if (and byte-compile-generate-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 (or (eq t byte-compile-generate-call-tree)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 (y-or-n-p (format "Report call tree for %s? " filename))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 (display-call-tree filename)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 (if load
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 (load target-file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 ;; RMS comments the next two out.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 (defun byte-compile-and-load-file (&optional filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 "Compile a file of Lisp code named FILENAME into a file of byte code,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 and then load it. The output file's name is made by appending \"c\" to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 the end of FILENAME."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 (if filename ; I don't get it, (interactive-p) doesn't always work
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 (byte-compile-file filename t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 (let ((current-prefix-arg '(4)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 (call-interactively 'byte-compile-file))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 (defun byte-compile-buffer (&optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 "Byte-compile and evaluate contents of BUFFER (default: the current buffer)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 (interactive "bByte compile buffer: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 (setq buffer (if buffer (get-buffer buffer) (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 (message "Compiling %s..." buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 (let* ((filename (or (buffer-file-name buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 (prin1-to-string buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 (byte-compile-current-file buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 (byte-compile-from-buffer buffer filename t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 (message "Compiling %s...done" buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 ;;; compiling a single function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 (defun compile-defun (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 "Compile and evaluate the current top-level form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 Print the result in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 With argument, insert value in current buffer after the form."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 (end-of-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 (beginning-of-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 (let* ((byte-compile-current-file (buffer-file-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 (load-file-name (buffer-file-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 (byte-compile-last-warned-form 'nothing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 (value (eval (displaying-byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 (byte-compile-sexp (read (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 "toplevel forms")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 (cond (arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 (message "Compiling from buffer... done.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 (prin1 value (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 (insert "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 ((message "%s" (prin1-to-string value)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 (defun byte-compile-from-buffer (byte-compile-inbuffer filename &optional eval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 ;; buffer --> output-buffer, or buffer --> eval form, return nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 (let (byte-compile-outbuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 ;; Prevent truncation of flonums and lists as we read and print them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 (float-output-format nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 (case-fold-search nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 (print-length nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 (print-level nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 ;; Simulate entry to byte-compile-top-level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 (byte-compile-constants nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 (byte-compile-variables nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 (byte-compile-tag-number 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 (byte-compile-depth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 (byte-compile-maxdepth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 (byte-compile-output nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 ;; #### This is bound in b-c-close-variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 ;; (byte-compile-warnings (if (eq byte-compile-warnings t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 ;; byte-compile-warning-types
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 ;; byte-compile-warnings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 (byte-compile-close-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 (setq byte-compile-outbuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 (set-buffer (get-buffer-create " *Compiler Output*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 ;; (emacs-lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 (setq case-fold-search nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 (and filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 (not eval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 (byte-compile-insert-header filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 byte-compile-inbuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 byte-compile-outbuffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 ;; This is a kludge. Some operating systems (OS/2, DOS) need to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 ;; write files containing binary information specially.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 ;; Under most circumstances, such files will be in binary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 ;; overwrite mode, so those OS's use that flag to guess how
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 ;; they should write their data. Advise them that .elc files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 ;; need to be written carefully.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 (setq overwrite-mode 'overwrite-mode-binary))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 (displaying-byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 (set-buffer byte-compile-inbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 (goto-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 ;; Compile the forms from the input buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 (while (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 (while (progn (skip-chars-forward " \t\n\^L")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 (looking-at ";"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 (not (eobp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 (byte-compile-file-form (read byte-compile-inbuffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 ;; Compile pending forms at end of file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 (byte-compile-flush-pending)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 (byte-compile-warn-about-unresolved-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 ;; Should we always do this? When calling multiple files, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 ;; would be useful to delay this warning until all have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 ;; been compiled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 (setq byte-compile-unresolved-functions nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 (set-buffer byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 (goto-char (point-min))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 (if (not eval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 byte-compile-outbuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 (let (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 (while (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 (progn (setq form (read byte-compile-outbuffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 (end-of-file nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 (eval form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 (kill-buffer byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 (defun byte-compile-insert-header (filename byte-compile-inbuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 (set-buffer byte-compile-inbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 (let ((dynamic-docstrings byte-compile-dynamic-docstrings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 (set-buffer byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 (goto-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 ;; The magic number of .elc files is ";ELC", or 0x3B454C43. After that is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 ;; the file-format version number (19 or 20) as a byte, followed by some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 ;; nulls. The primary motivation for doing this is to get some binary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 ;; characters up in the first line of the file so that `diff' will simply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 ;; say "Binary files differ" instead of actually doing a diff of two .elc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 ;; files. An extra benefit is that you can add this to /etc/magic:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 ;;
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 549
diff changeset
1779 ;; 0 string ;ELC XEmacs Lisp compiled file,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 ;; >4 byte x version %d
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 (insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 ";ELC"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 (if (byte-compile-version-cond byte-compile-emacs19-compatibility) 19 20)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 "\000\000\000\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 (insert ";;; compiled by "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 (or (and (boundp 'user-mail-address) user-mail-address)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 (concat (user-login-name) "@" (system-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 " on "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 (current-time-string) "\n;;; from file " filename "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 (insert ";;; emacs version " emacs-version ".\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 (insert ";;; bytecomp version " byte-compile-version "\n;;; "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 ((eq byte-optimize 'source) "source-level optimization only")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 ((eq byte-optimize 'byte) "byte-level optimization only")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 (byte-optimize "optimization is on")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 (t "optimization is off"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 (if (byte-compile-version-cond byte-compile-emacs19-compatibility)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 "; compiled with Emacs 19 compatibility.\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 ".\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 (if (not (byte-compile-version-cond byte-compile-emacs19-compatibility))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 (insert ";;; this file uses opcodes which do not exist in Emacs 19.\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 ;; Have to check if emacs-version is bound so that this works
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 ;; in files loaded early in loadup.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 "\n(if (and (boundp 'emacs-version)\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 "\t (or (and (boundp 'epoch::version) epoch::version)\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 "\t (string-lessp emacs-version \"20\")))\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 " (error \"`"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 ;; prin1-to-string is used to quote backslashes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 (substring (prin1-to-string (file-name-nondirectory filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 1 -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 "' was compiled for Emacs 20\"))\n\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 (insert "(or (boundp 'current-load-list) (setq current-load-list nil))\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 (if (and (byte-compile-version-cond byte-compile-emacs19-compatibility)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 dynamic-docstrings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 (insert ";;; this file uses opcodes which do not exist prior to\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 ";;; XEmacs 19.14/GNU Emacs 19.29 or later."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 ;; Have to check if emacs-version is bound so that this works
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 ;; in files loaded early in loadup.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 "\n(if (and (boundp 'emacs-version)\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 "\t (or (and (boundp 'epoch::version) epoch::version)\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 "\t (and (not (string-match \"XEmacs\" emacs-version))\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 "\t (string-lessp emacs-version \"19.29\"))\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 "\t (string-lessp emacs-version \"19.14\")))\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 " (error \"`"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 ;; prin1-to-string is used to quote backslashes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 (substring (prin1-to-string (file-name-nondirectory filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 1 -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 "' was compiled for XEmacs 19.14/Emacs 19.29 or later\"))\n\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 ;; back in the inbuffer; determine and set the coding system for the .elc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 ;; file if under Mule. If there are any extended characters in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 ;; input file, use `escape-quoted' to make sure that both binary and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 ;; extended characters are output properly and distinguished properly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 ;; Otherwise, use `raw-text' for maximum portability with non-Mule
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 ;; Emacsen.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1841 (if (or (featurep '(not mule)) ;; Don't scan buffer if we are not muleized
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1842 (save-excursion
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1843 (set-buffer byte-compile-inbuffer)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1844 (goto-char (point-min))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1845 ;; mrb- There must be a better way than skip-chars-forward
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1846 (skip-chars-forward (concat (char-to-string 0) "-"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1847 (char-to-string 255)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1848 (eq (point) (point-max))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1849 (setq buffer-file-coding-system 'raw-text-unix)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1850 (insert "(require 'mule)\n;;;###coding system: escape-quoted\n")
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1851 (setq buffer-file-coding-system 'escape-quoted)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1852 ;; #### Lazy loading not yet implemented for MULE files
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1853 ;; mrb - Fix this someday.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1854 (save-excursion
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1855 (set-buffer byte-compile-inbuffer)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1856 (setq byte-compile-dynamic nil
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1857 byte-compile-dynamic-docstrings nil))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1858 ;;(external-debugging-output (prin1-to-string (buffer-local-variables))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
1859 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 (defun byte-compile-output-file-form (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 ;; writes the given form to the output buffer, being careful of docstrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 ;; in defun, defmacro, defvar, defconst and autoload because make-docfile is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 ;; so amazingly stupid.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 ;; defalias calls are output directly by byte-compile-file-form-defmumble;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 ;; it does not pay to first build the defalias in defmumble and then parse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 ;; it here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 (if (and (memq (car-safe form) '(defun defmacro defvar defconst autoload))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 (stringp (nth 3 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 (byte-compile-output-docform nil nil '("\n(" 3 ")") form nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 (eq (car form) 'autoload))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 (let ((print-escape-newlines t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 (print-length nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 (print-level nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 (print-readably t) ; print #[] for bytecode, 'x for (quote x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 (print-gensym (if (and byte-compile-print-gensym
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 (not byte-compile-emacs19-compatibility))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 (princ "\n" byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 (prin1 form byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 (defun byte-compile-output-docform (preface name info form specindex quoted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 "Print a form with a doc string. INFO is (prefix doc-index postfix).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 If PREFACE and NAME are non-nil, print them too,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 before INFO and the FORM but after the doc string itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 If SPECINDEX is non-nil, it is the index in FORM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 of the function bytecode string. In that case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 we output that argument and the following argument (the constants vector)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 together, for lazy loading.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 QUOTED says that we have to put a quote before the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 list that represents a doc string reference.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 `autoload' needs that."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 ;; We need to examine byte-compile-dynamic-docstrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 ;; in the input buffer (now current), not in the output buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 (let ((dynamic-docstrings byte-compile-dynamic-docstrings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 (set-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 (prog1 (current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 (set-buffer byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 (let (position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 ;; Insert the doc string, and make it a comment with #@LENGTH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 (and (>= (nth 1 info) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 dynamic-docstrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 ;; Make the doc string start at beginning of line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 ;; for make-docfile's sake.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 (insert "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 (setq position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 (byte-compile-output-as-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 (nth (nth 1 info) form) nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 ;; If the doc string starts with * (a user variable),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 ;; negate POSITION.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 (if (and (stringp (nth (nth 1 info) form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 (> (length (nth (nth 1 info) form)) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 (char= (aref (nth (nth 1 info) form) 0) ?*))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 (setq position (- position)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 (if preface
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 (insert preface)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 (prin1 name byte-compile-outbuffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 (insert (car info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 (let ((print-escape-newlines t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 (print-readably t) ; print #[] for bytecode, 'x for (quote x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 ;; Use a cons cell to say that we want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 ;; print-gensym-alist not to be cleared between calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 ;; to print functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 (print-gensym (if (and byte-compile-print-gensym
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 (not byte-compile-emacs19-compatibility))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 '(t) nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 print-gensym-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 (index 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 (prin1 (car form) byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 (while (setq form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 (setq index (1+ index))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 (insert " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 (cond ((and (numberp specindex) (= index specindex))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 (let ((position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 (byte-compile-output-as-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 (cons (car form) (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 (princ (format "(#$ . %d) nil" position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 (setq form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 (setq index (1+ index))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 ((= index (nth 1 info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 (if position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 (princ (format (if quoted "'(#$ . %d)" "(#$ . %d)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 (let ((print-escape-newlines nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 (goto-char (prog1 (1+ (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 (prin1 (car form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 byte-compile-outbuffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 (insert "\\\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 (goto-char (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 (prin1 (car form) byte-compile-outbuffer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 (insert (nth 2 info))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 (defvar for-effect) ; ## Kludge! This should be an arg, not a special.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 (defun byte-compile-keep-pending (form &optional handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 (if (memq byte-optimize '(t source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 (setq form (byte-optimize-form form t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 (if handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 (let ((for-effect t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 ;; To avoid consing up monstrously large forms at load time, we split
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 ;; the output regularly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 (and (memq (car-safe form) '(fset defalias define-function))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 (nthcdr 300 byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 (byte-compile-flush-pending))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 (funcall handler form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 (when for-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 (byte-compile-discard)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 (byte-compile-form form t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 (defun byte-compile-flush-pending ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 (if byte-compile-output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 (let ((form (byte-compile-out-toplevel t 'file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 (cond ((eq (car-safe form) 'progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 (mapcar 'byte-compile-output-file-form (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 (form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 (byte-compile-output-file-form form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 (setq byte-compile-constants nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 byte-compile-variables nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 byte-compile-depth 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 byte-compile-maxdepth 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 byte-compile-output nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 (defun byte-compile-file-form (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 (let ((byte-compile-current-form nil) ; close over this for warnings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 ((not (consp form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 (byte-compile-keep-pending form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 ((and (symbolp (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003 (setq handler (get (car form) 'byte-hunk-handler)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 (cond ((setq form (funcall handler form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 (byte-compile-flush-pending)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 (byte-compile-output-file-form form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 ((eq form (setq form (macroexpand form byte-compile-macro-environment)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 (byte-compile-keep-pending form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010 (byte-compile-file-form form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012 ;; Functions and variables with doc strings must be output separately,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 ;; so make-docfile can recognize them. Most other things can be output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 ;; as byte-code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 (put 'defsubst 'byte-hunk-handler 'byte-compile-file-form-defsubst)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 (defun byte-compile-file-form-defsubst (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 (cond ((assq (nth 1 form) byte-compile-unresolved-functions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 (setq byte-compile-current-form (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 (byte-compile-warn "defsubst %s was used before it was defined"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022 (byte-compile-file-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 (macroexpand form byte-compile-macro-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 ;; Return nil so the form is not output twice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 (put 'autoload 'byte-hunk-handler 'byte-compile-file-form-autoload)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 (defun byte-compile-file-form-autoload (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 ;; If this is an autoload of a macro, and all arguments are constants (that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031 ;; is, there is no hairy computation going on here) then evaluate the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 ;; at compile-time. This is so that we can make use of macros which we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033 ;; have autoloaded from the file being compiled. Normal function autoloads
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034 ;; are not automatically evaluated at compile time, because there's not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 ;; much point to it (so why bother cluttering up the compile-time namespace.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 ;; If this is an autoload of a function, then record its definition in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 ;; byte-compile-autoload-environment to suppress any `not known to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 ;; defined' warnings at the end of this file (this only matters for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 ;; functions which are autoloaded and compiled in the same file, if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 ;; autoload already exists in the compilation environment, we wouldn't have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 ;; warned anyway.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 (let* ((name (if (byte-compile-constp (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 (eval (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 ;; In v19, the 5th arg to autoload can be t, nil, 'macro, or 'keymap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 (macrop (and (byte-compile-constp (nth 5 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 (memq (eval (nth 5 form)) '(t macro))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 ;; (functionp (and (byte-compile-constp (nth 5 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 ;; (eq 'nil (eval (nth 5 form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 (if (and macrop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 (let ((form form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 ;; all forms are constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 (while (if (setq form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 (byte-compile-constp (car form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 (null form)))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
2058 ;; eval the macro autoload into the compilation environment
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 (eval form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 (if name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 (let ((old (assq name byte-compile-autoload-environment)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 (cond (old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 (if (memq 'redefine byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 (byte-compile-warn "multiple autoloads for %s" name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066 (setcdr old form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 ;; We only use the names in the autoload environment, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 ;; it might be useful to have the bodies some day.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 (setq byte-compile-autoload-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 (cons (cons name form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072 byte-compile-autoload-environment)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 ;; Now output the form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 (if (stringp (nth 3 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077 ;; No doc string, so we can compile this as a normal form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 (byte-compile-keep-pending form 'byte-compile-normal-call)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2080 (put 'defvar 'byte-hunk-handler 'byte-compile-file-form-defvar-or-defconst)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2081 (put 'defconst 'byte-hunk-handler 'byte-compile-file-form-defvar-or-defconst)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2082 (defun byte-compile-file-form-defvar-or-defconst (form)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2083 ;; (defvar|defconst VAR [VALUE [DOCSTRING]])
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 (if (> (length form) 4)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2085 (byte-compile-warn
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2086 "%s %s called with %d arguments, but accepts only %s"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2087 (car form) (nth 1 form) (length (cdr form)) 3))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 (if (and (> (length form) 3) (not (stringp (nth 3 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 (byte-compile-warn "Third arg to %s %s is not a string: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090 (car form) (nth 1 form) (nth 3 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 (if (null (nth 3 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 ;; Since there is no doc string, we can compile this as a normal form,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 ;; and not do a file-boundary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 (byte-compile-keep-pending form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 (if (memq 'free-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 (setq byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 (cons (cons (nth 1 form) byte-compile-global-bit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 byte-compile-bound-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 (cond ((consp (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 (setq form (copy-sequence form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 (setcar (cdr (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 (byte-compile-top-level (nth 2 form) nil 'file))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 ;; The following turns out not to be necessary, since we emit a call to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105 ;; defvar, which can hack Vfile_domain by itself!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2107 ;; If a file domain has been set, emit (put 'VAR 'variable-domain ...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2108 ;; after this defvar.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109 ; (if byte-compile-file-domain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110 ; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 ; ;; Actually, this will emit the (put ...) before the (defvar ...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2112 ; ;; but I don't think that can matter in this case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113 ; (byte-compile-keep-pending
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2114 ; (list 'put (list 'quote (nth 1 form)) ''variable-domain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 ; (list 'quote byte-compile-file-domain)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2118 (put 'require 'byte-hunk-handler 'byte-compile-file-form-eval-boundary)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119 (defun byte-compile-file-form-eval-boundary (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 (eval form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 (byte-compile-keep-pending form 'byte-compile-normal-call))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 (put 'progn 'byte-hunk-handler 'byte-compile-file-form-progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 (put 'prog1 'byte-hunk-handler 'byte-compile-file-form-progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 (put 'prog2 'byte-hunk-handler 'byte-compile-file-form-progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 (defun byte-compile-file-form-progn (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 (mapcar 'byte-compile-file-form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 ;; Return nil so the forms are not output twice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131 ;; This handler is not necessary, but it makes the output from dont-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2132 ;; and similar macros cleaner.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133 (put 'eval 'byte-hunk-handler 'byte-compile-file-form-eval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134 (defun byte-compile-file-form-eval (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135 (if (eq (car-safe (nth 1 form)) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136 (nth 1 (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2137 (byte-compile-keep-pending form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139 (put 'defun 'byte-hunk-handler 'byte-compile-file-form-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 (defun byte-compile-file-form-defun (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141 (byte-compile-file-form-defmumble form nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 (put 'defmacro 'byte-hunk-handler 'byte-compile-file-form-defmacro)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 (defun byte-compile-file-form-defmacro (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 (byte-compile-file-form-defmumble form t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 (defun byte-compile-compiled-obj-to-list (obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 ;; #### this is fairly disgusting. Rewrite the code instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 ;; so that it doesn't create compiled objects in the first place!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 ;; Much better than creating them and then "uncreating" them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 ;; like this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 (read (concat "("
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153 (substring (let ((print-readably t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 (print-gensym
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 (if (and byte-compile-print-gensym
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 (not byte-compile-emacs19-compatibility))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 '(t) nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 (print-gensym-alist nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 (prin1-to-string obj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160 2 -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161 ")")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 (defun byte-compile-file-form-defmumble (form macrop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 (let* ((name (car (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 (this-kind (if macrop 'byte-compile-macro-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 'byte-compile-function-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 (that-kind (if macrop 'byte-compile-function-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168 'byte-compile-macro-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 (this-one (assq name (symbol-value this-kind)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170 (that-one (assq name (symbol-value that-kind)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 (byte-compile-free-references nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172 (byte-compile-free-assignments nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 ;; When a function or macro is defined, add it to the call tree so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 ;; we can tell when functions are not used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 (if byte-compile-generate-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 (or (assq name byte-compile-call-tree)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 (setq byte-compile-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 (cons (list name nil nil) byte-compile-call-tree))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 (setq byte-compile-current-form name) ; for warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 (when (memq 'redefine byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 (byte-compile-arglist-warn form macrop))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 (defvar filename) ; #### filename used free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 (when byte-compile-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 (message "Compiling %s... (%s)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 (if filename (file-name-nondirectory filename) "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 (cond (that-one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 (when (and (memq 'redefine byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 ;; hack hack: don't warn when compiling the stubs in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 ;; bytecomp-runtime...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 (not (assq (nth 1 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 byte-compile-initial-macro-environment)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 "%s defined multiple times, as both function and macro"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 (setcdr that-one nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199 (this-one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 (when (and (memq 'redefine byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 ;; hack: don't warn when compiling the magic internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 ;; byte-compiler macros in bytecomp-runtime.el...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 (not (assq (nth 1 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 byte-compile-initial-macro-environment)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 (byte-compile-warn "%s %s defined multiple times in this file"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 (if macrop "macro" "function")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 ((and (fboundp name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 (or (subrp (symbol-function name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 (eq (car-safe (symbol-function name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 (if macrop 'lambda 'macro))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 (if (memq 'redefine byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 (byte-compile-warn "%s %s being redefined as a %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214 (if (subrp (symbol-function name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 "subr"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 (if macrop "function" "macro"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 (nth 1 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2218 (if macrop "macro" "function")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219 ;; shadow existing definition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220 (set this-kind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221 (cons (cons name nil) (symbol-value this-kind)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 (let ((body (nthcdr 3 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 (if (and (stringp (car body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 (symbolp (car-safe (cdr-safe body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 (car-safe (cdr-safe body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 (stringp (car-safe (cdr-safe (cdr-safe body)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 (byte-compile-warn "Probable `\"' without `\\' in doc string of %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 (let* ((new-one (byte-compile-lambda (cons 'lambda (nthcdr 2 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230 (code (byte-compile-byte-code-maker new-one)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 (if this-one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 (setcdr this-one new-one)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2233 (set this-kind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2234 (cons (cons name new-one) (symbol-value this-kind))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 (if (and (stringp (nth 3 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 (eq 'quote (car-safe code))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 (eq 'lambda (car-safe (nth 1 code))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 (cons (car form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 (cons name (cdr (nth 1 code))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 (byte-compile-flush-pending)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241 (if (not (stringp (nth 3 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242 ;; No doc string. Provide -1 as the "doc string index"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 ;; so that no element will be treated as a doc string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 (byte-compile-output-docform
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 "\n(defalias '"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 (cond ((atom code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 (if macrop '(" '(macro . #[" -1 "])") '(" #[" -1 "]")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 ((eq (car code) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 (setq code new-one)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 (if macrop '(" '(macro " -1 ")") '(" '(" -1 ")")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 ((if macrop '(" (cons 'macro (" -1 "))") '(" (" -1 ")"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253 ;; FSF just calls `(append code nil)' here but that relies
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 ;; on horrible C kludges in concat() that accept byte-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 ;; compiled objects and pretend they're vectors.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 (if (compiled-function-p code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 (byte-compile-compiled-obj-to-list code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 (append code nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 (and (atom code) byte-compile-dynamic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 ;; Output the form by hand, that's much simpler than having
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263 ;; b-c-output-file-form analyze the defalias.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 (byte-compile-output-docform
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265 "\n(defalias '"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 (cond ((atom code) ; compiled-function-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 (if macrop '(" '(macro . #[" 4 "])") '(" #[" 4 "]")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 ((eq (car code) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 (setq code new-one)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 (if macrop '(" '(macro " 2 ")") '(" '(" 2 ")")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 ((if macrop '(" (cons 'macro (" 5 "))") '(" (" 5 ")"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 ;; The result of byte-compile-byte-code-maker is either a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 ;; compiled-function object, or a list of some kind. If it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 ;; not a cons, we must coerce it into a list of the elements
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 ;; to be printed to the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277 (if (consp code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278 code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 (nconc (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 (compiled-function-arglist code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 (compiled-function-instructions code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 (compiled-function-constants code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 (compiled-function-stack-depth code))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 (let ((doc (documentation code t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 (if doc (list doc)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 (if (commandp code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 (list (nth 1 (compiled-function-interactive code))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 (and (atom code) byte-compile-dynamic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 (princ ")" byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 ;; Print Lisp object EXP in the output file, inside a comment,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 ;; and return the file position it will have.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 ;; If QUOTED is non-nil, print with quoting; otherwise, print without quoting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 (defun byte-compile-output-as-comment (exp quoted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 (let ((position (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 (set-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 (prog1 (current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 (set-buffer byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303 ;; Insert EXP, and make it a comment with #@LENGTH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 (insert " ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 (if quoted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 (prin1 exp byte-compile-outbuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 (princ exp byte-compile-outbuffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 (goto-char position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 ;; Quote certain special characters as needed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 ;; get_doc_string in doc.c does the unquoting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 (while (search-forward "\^A" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 (replace-match "\^A\^A" t t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 (goto-char position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 (while (search-forward "\000" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 (replace-match "\^A0" t t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316 (goto-char position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 (while (search-forward "\037" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 (replace-match "\^A_" t t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 (insert "\037")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 (goto-char position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 (insert "#@" (format "%d" (- (point-max) position)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 ;; Save the file position of the object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 ;; Note we should add 1 to skip the space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 ;; that we inserted before the actual doc string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 ;; and subtract 1 to convert from an 1-origin Emacs position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 ;; to a file position; they cancel.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 (setq position (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 (goto-char (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 position))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 ;; The `domain' declaration. This is legal only at top-level in a file, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 ;; should generally be the first form in the file. It is not legal inside
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 ;; function bodies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 (put 'domain 'byte-hunk-handler 'byte-compile-file-form-domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340 (defun byte-compile-file-form-domain (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 (if (not (null (cdr (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 (byte-compile-warn "domain used with too many arguments: %s" form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 (let ((domain (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344 (or (null domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 (stringp domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348 "argument to `domain' declaration must be a literal string: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350 (setq domain nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 (setq byte-compile-file-domain domain))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352 (byte-compile-keep-pending form 'byte-compile-normal-call))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 (defun byte-compile-domain (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 (byte-compile-warn "The `domain' declaration is legal only at top-level: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 (let ((print-escape-newlines t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 (print-level 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 (print-length 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359 (prin1-to-string form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 (byte-compile-normal-call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 (list 'signal ''error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 (list 'quote (list "`domain' used inside a function" form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364 ;; This is part of bytecomp.el in 19.35:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365 (put 'custom-declare-variable 'byte-hunk-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 'byte-compile-file-form-custom-declare-variable)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 (defun byte-compile-file-form-custom-declare-variable (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368 (if (memq 'free-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 (setq byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370 (cons (cons (nth 1 (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 byte-compile-global-bit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 byte-compile-bound-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 (defun byte-compile (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378 "If FORM is a symbol, byte-compile its function definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 If FORM is a lambda or a macro, byte-compile it as a function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 (displaying-byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 (byte-compile-close-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 (let* ((fun (if (symbolp form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 (and (fboundp form) (symbol-function form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 (macro (eq (car-safe fun) 'macro)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 (if macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 (setq fun (cdr fun)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 (cond ((eq (car-safe fun) 'lambda)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389 (setq fun (if macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 (cons 'macro (byte-compile-lambda fun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 (byte-compile-lambda fun)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 (if (symbolp form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 (defalias form fun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 fun)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 (defun byte-compile-sexp (sexp &optional msg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 "Compile and return SEXP."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 (displaying-byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 (byte-compile-close-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 (prog1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 (byte-compile-top-level sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 (byte-compile-warn-about-unresolved-functions msg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 ;; Given a function made by byte-compile-lambda, make a form which produces it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 (defun byte-compile-byte-code-maker (fun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 ;; ## atom is faster than compiled-func-p.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 ((atom fun) ; compiled-function-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 fun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 ;; b-c-lambda didn't produce a compiled-function, so it must be a trivial
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 ;; function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413 ((let (tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 (if (and (setq tmp (assq 'byte-code (cdr-safe (cdr fun))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 (null (cdr (memq tmp fun))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 ;; Generate a make-byte-code call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 (let* ((interactive (assq 'interactive (cdr (cdr fun)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 (nconc (list 'make-byte-code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 (list 'quote (nth 1 fun)) ;arglist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420 (nth 1 tmp) ;instructions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 (nth 2 tmp) ;constants
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 (nth 3 tmp)) ;stack-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 (cond ((stringp (nth 2 fun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424 (list (nth 2 fun))) ;docstring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 (list nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2427 (cond (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 (list (if (or (null (nth 1 interactive))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429 (stringp (nth 1 interactive)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430 (nth 1 interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 ;; Interactive spec is a list or a variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 ;; (if it is correct).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433 (list 'quote (nth 1 interactive))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 ;; a non-compiled function (probably trivial)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435 (list 'quote fun))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 ;; Byte-compile a lambda-expression and return a valid function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 ;; The value is usually a compiled function but may be the original
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 ;; lambda-expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 (defun byte-compile-lambda (fun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 (or (eq 'lambda (car-safe fun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 (error "not a lambda -- %s" (prin1-to-string fun)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 (let* ((arglist (nth 1 fun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 (byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445 (let ((new-bindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 (mapcar #'(lambda (x) (cons x byte-compile-arglist-bit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 (and (memq 'free-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 (delq '&rest (delq '&optional
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 (copy-sequence arglist)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 (nconc new-bindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 (cons 'new-scope byte-compile-bound-variables))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 (body (cdr (cdr fun)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 (doc (if (stringp (car body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 (prog1 (car body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 (setq body (cdr body)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 (int (assq 'interactive body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 (dolist (arg arglist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 (cond ((not (symbolp arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 (byte-compile-warn "non-symbol in arglist: %S" arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 ((byte-compile-constant-symbol-p arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 (byte-compile-warn "constant symbol in arglist: %s" arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 ((and (char= ?\& (aref (symbol-name arg) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 (not (eq arg '&optional))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 (not (eq arg '&rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 (byte-compile-warn "unrecognized `&' keyword in arglist: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 (cond (int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 ;; Skip (interactive) if it is in front (the most usual location).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 (if (eq int (car body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 (setq body (cdr body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 (cond ((consp (cdr int))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 (if (cdr (cdr int))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 (byte-compile-warn "malformed interactive spec: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 (prin1-to-string int)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 ;; If the interactive spec is a call to `list',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 ;; don't compile it, because `call-interactively'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 ;; looks at the args of `list'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 (let ((form (nth 1 int)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 (while (or (eq (car-safe form) 'let)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 (eq (car-safe form) 'let*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 (eq (car-safe form) 'save-excursion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482 (while (consp (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 (setq form (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 (setq form (car form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 (or (eq (car-safe form) 'list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 (setq int (list 'interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 (byte-compile-top-level (nth 1 int)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 ((cdr int)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 (byte-compile-warn "malformed interactive spec: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 (prin1-to-string int))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 (let ((compiled (byte-compile-top-level (cons 'progn body) nil 'lambda)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 (if (memq 'unused-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 ;; done compiling in this scope, warn now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 (byte-compile-warn-about-unused-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 (if (eq 'byte-code (car-safe compiled))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 (apply 'make-byte-code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 (append (list arglist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 ;; byte-string, constants-vector, stack depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 (cdr compiled)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 ;; optionally, the doc string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 (if (or doc int)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502 (list doc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503 ;; optionally, the interactive spec.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 (if int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 (list (nth 1 int)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 (setq compiled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 (nconc (if int (list int))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 (cond ((eq (car-safe compiled) 'progn) (cdr compiled))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509 (compiled (list compiled)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 (nconc (list 'lambda arglist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 (if (or doc (stringp (car compiled)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 (cons doc (cond (compiled)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 (body (list nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 compiled))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 (defun byte-compile-constants-vector ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 ;; Builds the constants-vector from the current variables and constants.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 ;; This modifies the constants from (const . nil) to (const . offset).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 ;; To keep the byte-codes to look up the vector as short as possible:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520 ;; First 6 elements are vars, as there are one-byte varref codes for those.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 ;; Next up to byte-constant-limit are constants, still with one-byte codes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 ;; Next variables again, to get 2-byte codes for variable lookup.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 ;; The rest of the constants and variables need 3-byte byte-codes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 (let* ((i -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 (rest (nreverse byte-compile-variables)) ; nreverse because the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 (other (nreverse byte-compile-constants)) ; vars often are used most.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 ret tmp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 (limits '(5 ; Use the 1-byte varref codes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 63 ; 1-constlim ; 1-byte byte-constant codes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 255 ; 2-byte varref codes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531 65535)) ; 3-byte codes for the rest.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 (while (or rest other)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 (setq limit (car limits))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535 (while (and rest (not (eq i limit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 (if (setq tmp (assq (car (car rest)) ret))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 (setcdr (car rest) (cdr tmp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538 (setcdr (car rest) (setq i (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 (setq ret (cons (car rest) ret)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 (setq limits (cdr limits)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 rest (prog1 other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 (setq other rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 (apply 'vector (nreverse (mapcar 'car ret)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 ;; Given an expression FORM, compile it and return an equivalent byte-code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 ;; expression (a call to the function byte-code).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 (defun byte-compile-top-level (form &optional for-effect output-type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 ;; OUTPUT-TYPE advises about how form is expected to be used:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 ;; 'eval or nil -> a single form,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 ;; 'progn or t -> a list of forms,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 ;; 'lambda -> body of a lambda,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 ;; 'file -> used at file-level.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 (let ((byte-compile-constants nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 (byte-compile-variables nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 (byte-compile-tag-number 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 (byte-compile-depth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 (byte-compile-maxdepth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 (byte-compile-output nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 (if (memq byte-optimize '(t source))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 (setq form (byte-optimize-form form for-effect)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 (while (and (eq (car-safe form) 'progn) (null (cdr (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 (setq form (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 (if (and (eq 'byte-code (car-safe form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 (not (memq byte-optimize '(t byte)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 (stringp (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 (vectorp (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 (natnump (nth 3 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570 (byte-compile-form form for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 (byte-compile-out-toplevel for-effect output-type))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 (defun byte-compile-out-toplevel (&optional for-effect output-type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574 (if for-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575 ;; The stack is empty. Push a value to be returned from (byte-code ..).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 (if (eq (car (car byte-compile-output)) 'byte-discard)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577 (setq byte-compile-output (cdr byte-compile-output))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 (byte-compile-push-constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 ;; Push any constant - preferably one which already is used, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 ;; a number or symbol - ie not some big sequence. The return value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581 ;; isn't returned, but it would be a shame if some textually large
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 ;; constant was not optimized away because we chose to return it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 (and (not (assq nil byte-compile-constants)) ; Nil is often there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 (let ((tmp (reverse byte-compile-constants)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 (while (and tmp (not (or (symbolp (car (car tmp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 (numberp (car (car tmp))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 (setq tmp (cdr tmp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 (car (car tmp)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 (byte-compile-out 'byte-return 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 (setq byte-compile-output (nreverse byte-compile-output))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 (if (memq byte-optimize '(t byte))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 (setq byte-compile-output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 (byte-optimize-lapcode byte-compile-output for-effect)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 ;; Decompile trivial functions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 ;; only constants and variables, or a single funcall except in lambdas.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597 ;; Except for Lisp_Compiled objects, forms like (foo "hi")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2598 ;; are still quicker than (byte-code "..." [foo "hi"] 2).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599 ;; Note that even (quote foo) must be parsed just as any subr by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 ;; interpreter, so quote should be compiled into byte-code in some contexts.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 ;; What to leave uncompiled:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 ;; lambda -> never. we used to leave it uncompiled if the body was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 ;; a single atom, but that causes confusion if the docstring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604 ;; uses the (file . pos) syntax. Besides, now that we have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 ;; the Lisp_Compiled type, the compiled form is faster.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 ;; eval -> atom, quote or (function atom atom atom)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 ;; progn -> as <<same-as-eval>> or (progn <<same-as-eval>> atom)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 ;; file -> as progn, but takes both quotes and atoms, and longer forms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609 (let (rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2610 (maycall (not (eq output-type 'lambda))) ; t if we may make a funcall.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 tmp body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 ;; #### This should be split out into byte-compile-nontrivial-function-p.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 ((or (eq output-type 'lambda)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 (nthcdr (if (eq output-type 'file) 50 8) byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 (assq 'TAG byte-compile-output) ; Not necessary, but speeds up a bit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 (not (setq tmp (assq 'byte-return byte-compile-output)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 (setq rest (nreverse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 (cdr (memq tmp (reverse byte-compile-output)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 (while (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622 ((memq (car (car rest)) '(byte-varref byte-constant))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623 (setq tmp (car (cdr (car rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624 (if (if (eq (car (car rest)) 'byte-constant)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625 (or (consp tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 (and (symbolp tmp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627 (not (byte-compile-constant-symbol-p tmp)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 (if maycall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 (setq body (cons (list 'quote tmp) body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 (setq body (cons tmp body))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 ((and maycall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 ;; Allow a funcall if at most one atom follows it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 (null (nthcdr 3 rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 (setq tmp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 ;; XEmacs change for rms funs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 (or (and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 (byte-compile-version-cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 byte-compile-emacs19-compatibility)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 (get (car (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 'byte-opcode19-invert))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 (get (car (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 'byte-opcode-invert)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 (or (null (cdr rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 (and (memq output-type '(file progn t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 (cdr (cdr rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 (eq (car (nth 1 rest)) 'byte-discard)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 (progn (setq rest (cdr rest)) t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 (setq maycall nil) ; Only allow one real function call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 (setq body (nreverse body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 (setq body (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 (if (and (eq tmp 'funcall)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 (eq (car-safe (car body)) 'quote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 (cons (nth 1 (car body)) (cdr body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 (cons tmp body))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 (or (eq output-type 'file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656 (not (delq nil (mapcar 'consp (cdr (car body))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 (let ((byte-compile-vector (byte-compile-constants-vector)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 (list 'byte-code (byte-compile-lapcode byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 byte-compile-vector byte-compile-maxdepth)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 ;; it's a trivial function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663 ((cdr body) (cons 'progn (nreverse body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 ((car body)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 ;; Given BODY, compile it and return a new body.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 (defun byte-compile-top-level-body (body &optional for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668 (setq body (byte-compile-top-level (cons 'progn body) for-effect t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669 (cond ((eq (car-safe body) 'progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670 (cdr body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671 (body
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 (list body))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 ;; This is the recursive entry point for compiling each subform of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 ;; expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 ;; If for-effect is non-nil, byte-compile-form will output a byte-discard
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 ;; before terminating (ie. no value will be left on the stack).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 ;; A byte-compile handler may, when for-effect is non-nil, choose output code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 ;; which does not leave a value on the stack, and then set for-effect to nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680 ;; (to prevent byte-compile-form from outputting the byte-discard).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 ;; If a handler wants to call another handler, it should do so via
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 ;; byte-compile-form, or take extreme care to handle for-effect correctly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 ;; (Use byte-compile-form-do-effect to reset the for-effect flag too.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 (defun byte-compile-form (form &optional for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 (setq form (macroexpand form byte-compile-macro-environment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687 (cond ((not (consp form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 (cond ((or (not (symbolp form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 (byte-compile-constant-symbol-p form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 (byte-compile-constant form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 ((and for-effect byte-compile-delete-errors)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 (t (byte-compile-variable-ref 'byte-varref form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2694 ((symbolp (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2695 (let* ((fn (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 (handler (get fn 'byte-compile)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 (if (memq fn '(t nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 (byte-compile-warn "%s called as a function" fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 (if (and handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 (or (not (byte-compile-version-cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 byte-compile-emacs19-compatibility))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 (not (get (get fn 'byte-opcode) 'emacs20-opcode))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 (funcall handler form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 (if (memq 'callargs byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 (byte-compile-callargs-warn form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 (byte-compile-normal-call form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 ((and (or (compiled-function-p (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 (eq (car-safe (car form)) 'lambda))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 ;; if the form comes out the same way it went in, that's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710 ;; because it was malformed, and we couldn't unfold it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 (not (eq form (setq form (byte-compile-unfold-lambda form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712 (byte-compile-form form for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714 ((byte-compile-normal-call form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 (when for-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 (byte-compile-discard)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 (defun byte-compile-normal-call (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 (if byte-compile-generate-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 (byte-compile-annotate-call-tree form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 (byte-compile-push-constant (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722 (mapcar 'byte-compile-form (cdr form)) ; wasteful, but faster.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 (byte-compile-out 'byte-call (length (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 ;; kludge added to XEmacs to work around the bogosities of a nonlexical lisp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 (or (fboundp 'globally-boundp) (fset 'globally-boundp 'boundp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 (defun byte-compile-variable-ref (base-op var &optional varbind-flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729 (if (or (not (symbolp var)) (byte-compile-constant-symbol-p var))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 (case base-op
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 (byte-varref "Variable reference to %s %s")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 (byte-varset "Attempt to set %s %s")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 (byte-varbind "Attempt to let-bind %s %s"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 (if (symbolp var) "constant symbol" "non-symbol")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737 (if (and (get var 'byte-obsolete-variable)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 (memq 'obsolete byte-compile-warnings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739 (let ((ob (get var 'byte-obsolete-variable)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 (byte-compile-warn "%s is an obsolete variable; %s" var
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 (if (stringp ob)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 ob
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 (format "use %s instead." ob)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744 (if (and (get var 'byte-compatible-variable)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2745 (memq 'pedantic byte-compile-warnings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 (let ((ob (get var 'byte-compatible-variable)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 (byte-compile-warn "%s is provided for compatibility; %s" var
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 (if (stringp ob)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 ob
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 (format "use %s instead." ob)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 (if (memq 'free-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 (if (eq base-op 'byte-varbind)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 (setq byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 (cons (cons var (or varbind-flags 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755 byte-compile-bound-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 (or (globally-boundp var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2757 (let ((cell (assq var byte-compile-bound-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 (if cell (setcdr cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 (logior (cdr cell)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 (if (eq base-op 'byte-varset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 byte-compile-assigned-bit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762 byte-compile-referenced-bit)))))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2763 (and (boundp 'current-load-list)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2764 (memq var current-load-list))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 (if (eq base-op 'byte-varset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 (or (memq var byte-compile-free-assignments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 (byte-compile-warn "assignment to free variable %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770 (setq byte-compile-free-assignments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2771 (cons var byte-compile-free-assignments))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2772 (or (memq var byte-compile-free-references)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 (byte-compile-warn "reference to free variable %s" var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775 (setq byte-compile-free-references
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 (cons var byte-compile-free-references)))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777 (let ((tmp (assq var byte-compile-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 (or tmp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 (setq tmp (list var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780 byte-compile-variables (cons tmp byte-compile-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 (byte-compile-out base-op tmp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783 (defmacro byte-compile-get-constant (const)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784 `(or (if (stringp ,const)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 (assoc ,const byte-compile-constants)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786 (assq ,const byte-compile-constants))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 (car (setq byte-compile-constants
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 (cons (list ,const) byte-compile-constants)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 ;; Use this when the value of a form is a constant. This obeys for-effect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 (defun byte-compile-constant (const)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 (if for-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 (setq for-effect nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 (byte-compile-out 'byte-constant (byte-compile-get-constant const))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796 ;; Use this for a constant that is not the value of its containing form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 ;; This ignores for-effect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798 (defun byte-compile-push-constant (const)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799 (let ((for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 (inline (byte-compile-constant const))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 ;; Compile those primitive ordinary functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804 ;; which have special byte codes just for speed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 (defmacro byte-defop-compiler (function &optional compile-handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 ;; add a compiler-form for FUNCTION.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2808 ;; If FUNCTION is a symbol, then the variable "byte-SYMBOL" must name
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2809 ;; the opcode to be used. If is a list, the first element
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 ;; is the function and the second element is the bytecode-symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 ;; COMPILE-HANDLER is the function to use to compile this byte-op, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 ;; may be the abbreviations 0, 1, 2, 3, 0-1, 1-2, 2-3, 0+1, 1+1, 2+1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 ;; 0-1+1, 1-2+1, 2-3+1, 0+2, or 1+2. If it is nil, then the handler is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 ;; "byte-compile-SYMBOL."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 (let (opcode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 (if (symbolp function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 (setq opcode (intern (concat "byte-" (symbol-name function))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818 (setq opcode (car (cdr function))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819 function (car function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 (let ((fnform
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 (list 'put (list 'quote function) ''byte-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 (list 'quote
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 (or (cdr (assq compile-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 '((0 . byte-compile-no-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 (1 . byte-compile-one-arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 (2 . byte-compile-two-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 (3 . byte-compile-three-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 (0-1 . byte-compile-zero-or-one-arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 (1-2 . byte-compile-one-or-two-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 (2-3 . byte-compile-two-or-three-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 (0+1 . byte-compile-no-args-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 (1+1 . byte-compile-one-arg-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 (2+1 . byte-compile-two-args-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 (0-1+1 . byte-compile-zero-or-one-arg-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 (1-2+1 . byte-compile-one-or-two-args-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 (2-3+1 . byte-compile-two-or-three-args-with-one-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 (0+2 . byte-compile-no-args-with-two-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838 (1+2 . byte-compile-one-arg-with-two-extra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 compile-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 (intern (concat "byte-compile-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 (symbol-name function))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 (if opcode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 (list 'progn fnform
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 (list 'put (list 'quote function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 ''byte-opcode (list 'quote opcode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 (list 'put (list 'quote opcode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 ''byte-opcode-invert (list 'quote function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 fnform))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 (defmacro byte-defop-compiler20 (function &optional compile-handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 ;; Just like byte-defop-compiler, but defines an opcode that will only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 ;; be used when byte-compile-emacs19-compatibility is false.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 (if (and (byte-compile-single-version)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 byte-compile-emacs19-compatibility)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 ;; #### instead of doing nothing, this should do some remprops,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 ;; #### to protect against the case where a single-version compiler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 ;; #### is loaded into a world that has contained a multi-version one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 (list 'progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 (list 'put
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 (list 'quote
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 (or (car (cdr-safe function))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 (intern (concat "byte-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 (symbol-name (or (car-safe function) function))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 ''emacs20-opcode t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 (list 'byte-defop-compiler function compile-handler))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 ;; XEmacs addition:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 (defmacro byte-defop-compiler-rmsfun (function &optional compile-handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 ;; for functions like `eq' that compile into different opcodes depending
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 ;; on the Emacs version: byte-old-eq for v19, byte-eq for v20.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 (let ((opcode (intern (concat "byte-" (symbol-name function))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 (opcode19 (intern (concat "byte-old-" (symbol-name function))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876 (fnform
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 (list 'put (list 'quote function) ''byte-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 (list 'quote
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 (or (cdr (assq compile-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 '((2 . byte-compile-two-args-19->20)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 compile-handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 (intern (concat "byte-compile-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 (symbol-name function))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 (list 'progn fnform
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 (list 'put (list 'quote function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 ''byte-opcode (list 'quote opcode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 (list 'put (list 'quote function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 ''byte-opcode19 (list 'quote opcode19))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890 (list 'put (list 'quote opcode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891 ''byte-opcode-invert (list 'quote function))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 (list 'put (list 'quote opcode19)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 ''byte-opcode19-invert (list 'quote function)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 (defmacro byte-defop-compiler-1 (function &optional compile-handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 (list 'byte-defop-compiler (list function nil) compile-handler))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899 (put 'byte-call 'byte-opcode-invert 'funcall)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 (put 'byte-list1 'byte-opcode-invert 'list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 (put 'byte-list2 'byte-opcode-invert 'list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 (put 'byte-list3 'byte-opcode-invert 'list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 (put 'byte-list4 'byte-opcode-invert 'list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 (put 'byte-listN 'byte-opcode-invert 'list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 (put 'byte-concat2 'byte-opcode-invert 'concat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 (put 'byte-concat3 'byte-opcode-invert 'concat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907 (put 'byte-concat4 'byte-opcode-invert 'concat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 (put 'byte-concatN 'byte-opcode-invert 'concat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 (put 'byte-insertN 'byte-opcode-invert 'insert)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 ;; How old is this stuff? -slb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 ;(byte-defop-compiler (dot byte-point) 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 ;(byte-defop-compiler (dot-max byte-point-max) 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 ;(byte-defop-compiler (dot-min byte-point-min) 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 (byte-defop-compiler point 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 (byte-defop-compiler-rmsfun eq 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 (byte-defop-compiler point-max 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 (byte-defop-compiler point-min 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 (byte-defop-compiler following-char 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 (byte-defop-compiler preceding-char 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 (byte-defop-compiler current-column 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 ;; FSF has special function here; generalized here by the 1+2 stuff.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 (byte-defop-compiler (indent-to-column byte-indent-to) 1+2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 (byte-defop-compiler indent-to 1+2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 (byte-defop-compiler-rmsfun equal 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 (byte-defop-compiler eolp 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 (byte-defop-compiler eobp 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 (byte-defop-compiler bolp 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 (byte-defop-compiler bobp 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 (byte-defop-compiler current-buffer 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 ;;(byte-defop-compiler read-char 0) ;; obsolete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 (byte-defop-compiler-rmsfun memq 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 (byte-defop-compiler interactive-p 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 (byte-defop-compiler widen 0+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 (byte-defop-compiler end-of-line 0-1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 (byte-defop-compiler forward-char 0-1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 (byte-defop-compiler forward-line 0-1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 (byte-defop-compiler symbolp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 (byte-defop-compiler consp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 (byte-defop-compiler stringp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 (byte-defop-compiler listp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 (byte-defop-compiler not 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 (byte-defop-compiler (null byte-not) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 (byte-defop-compiler car 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 (byte-defop-compiler cdr 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 (byte-defop-compiler length 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 (byte-defop-compiler symbol-value 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 (byte-defop-compiler symbol-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 (byte-defop-compiler (1+ byte-add1) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 (byte-defop-compiler (1- byte-sub1) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 (byte-defop-compiler goto-char 1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 (byte-defop-compiler char-after 0-1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 (byte-defop-compiler set-buffer 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 ;;(byte-defop-compiler set-mark 1) ;; obsolete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 (byte-defop-compiler forward-word 1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 (byte-defop-compiler char-syntax 1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 (byte-defop-compiler nreverse 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 (byte-defop-compiler car-safe 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 (byte-defop-compiler cdr-safe 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 (byte-defop-compiler numberp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 (byte-defop-compiler integerp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 (byte-defop-compiler skip-chars-forward 1-2+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 (byte-defop-compiler skip-chars-backward 1-2+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 (byte-defop-compiler (eql byte-eq) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 (byte-defop-compiler20 old-eq 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 (byte-defop-compiler20 old-memq 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 (byte-defop-compiler cons 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 (byte-defop-compiler aref 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 (byte-defop-compiler get 2+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 (byte-defop-compiler nth 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 (byte-defop-compiler substring 2-3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972 (byte-defop-compiler (move-marker byte-set-marker) 2-3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 (byte-defop-compiler set-marker 2-3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 (byte-defop-compiler match-beginning 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 (byte-defop-compiler match-end 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 (byte-defop-compiler upcase 1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 (byte-defop-compiler downcase 1+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 (byte-defop-compiler string= 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 (byte-defop-compiler string< 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 (byte-defop-compiler (string-equal byte-string=) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 (byte-defop-compiler (string-lessp byte-string<) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 (byte-defop-compiler20 old-equal 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 (byte-defop-compiler nthcdr 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 (byte-defop-compiler elt 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985 (byte-defop-compiler20 old-member 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 (byte-defop-compiler20 old-assq 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 (byte-defop-compiler (rplaca byte-setcar) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 (byte-defop-compiler (rplacd byte-setcdr) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 (byte-defop-compiler setcar 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 (byte-defop-compiler setcdr 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 (byte-defop-compiler delete-region 2+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 (byte-defop-compiler narrow-to-region 2+1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 (byte-defop-compiler (% byte-rem) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 (byte-defop-compiler aset 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 (byte-defop-compiler-rmsfun member 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 (byte-defop-compiler-rmsfun assq 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 ;;####(byte-defop-compiler move-to-column 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 (byte-defop-compiler-1 interactive byte-compile-noop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 (byte-defop-compiler-1 domain byte-compile-domain)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 ;; As of GNU Emacs 19.18 and Lucid Emacs 19.8, mod and % are different: `%'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 ;; means integral remainder and may have a negative result; `mod' is always
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 ;; positive, and accepts floating point args. All code which uses `mod' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 ;; requires the new interpretation must be compiled with bytecomp version 2.18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 ;; or newer, or the emitted code will run the byte-code for `%' instead of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 ;; actual call to `mod'. So be careful of compiling new code with an old
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 ;; compiler. Note also that `%' is more efficient than `mod' because the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 ;; former is byte-coded and the latter is not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 ;;(byte-defop-compiler (mod byte-rem) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 (defun byte-compile-subr-wrong-args (form n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 (when (memq 'subr-callargs byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 (byte-compile-warn "%s called with %d arg%s, but requires %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 (car form) (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 (if (= 1 (length (cdr form))) "" "s") n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 ;; get run-time wrong-number-of-args error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 (defun byte-compile-no-args (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 (0 (byte-compile-out (get (car form) 'byte-opcode) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 (t (byte-compile-subr-wrong-args form "none"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 (defun byte-compile-one-arg (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 (1 (byte-compile-form (car (cdr form))) ;; Push the argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 (byte-compile-out (get (car form) 'byte-opcode) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 (t (byte-compile-subr-wrong-args form 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 (defun byte-compile-two-args (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 (2 (byte-compile-form (nth 1 form)) ;; Push the arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 (byte-compile-form (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 (byte-compile-out (get (car form) 'byte-opcode) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 (t (byte-compile-subr-wrong-args form 2))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040 (defun byte-compile-three-args (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3041 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3042 (3 (byte-compile-form (nth 1 form)) ;; Push the arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043 (byte-compile-form (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 (byte-compile-form (nth 3 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045 (byte-compile-out (get (car form) 'byte-opcode) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046 (t (byte-compile-subr-wrong-args form 3))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3048 (defun byte-compile-zero-or-one-arg (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050 (0 (byte-compile-one-arg (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3051 (1 (byte-compile-one-arg form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3052 (t (byte-compile-subr-wrong-args form "0-1"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 (defun byte-compile-one-or-two-args (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 (1 (byte-compile-two-args (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 (2 (byte-compile-two-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058 (t (byte-compile-subr-wrong-args form "1-2"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 (defun byte-compile-two-or-three-args (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3061 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3062 (2 (byte-compile-three-args (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 (3 (byte-compile-three-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 (t (byte-compile-subr-wrong-args form "2-3"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 ;; from Ben Wing <ben@xemacs.org>: some inlined functions have extra
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067 ;; optional args added to them in XEmacs 19.12. Changing the byte
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068 ;; interpreter to deal with these args would be wrong and cause
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069 ;; incompatibility, so we generate non-inlined calls for those cases.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 ;; Without the following functions, spurious warnings will be generated;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3071 ;; however, they would still compile correctly because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3072 ;; `byte-compile-subr-wrong-args' also converts the call to non-inlined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3074 (defun byte-compile-no-args-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 (0 (byte-compile-no-args form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3077 (1 (if (eq nil (nth 1 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3078 (byte-compile-no-args (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3079 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 (t (byte-compile-subr-wrong-args form "0-1"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 (defun byte-compile-one-arg-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 (1 (byte-compile-one-arg form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3085 (2 (if (eq nil (nth 2 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3086 (byte-compile-one-arg (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3087 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 (t (byte-compile-subr-wrong-args form "1-2"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 (defun byte-compile-two-args-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 (2 (byte-compile-two-args form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3093 (3 (if (eq nil (nth 3 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3094 (byte-compile-two-args (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3095 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096 (t (byte-compile-subr-wrong-args form "2-3"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098 (defun byte-compile-zero-or-one-arg-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 (0 (byte-compile-one-arg (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 (1 (byte-compile-one-arg form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3102 (2 (if (eq nil (nth 2 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3103 (byte-compile-one-arg (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3104 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3105 (t (byte-compile-subr-wrong-args form "0-2"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107 (defun byte-compile-one-or-two-args-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 (1 (byte-compile-two-args (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 (2 (byte-compile-two-args form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3111 (3 (if (eq nil (nth 3 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3112 (byte-compile-two-args (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3113 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114 (t (byte-compile-subr-wrong-args form "1-3"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 (defun byte-compile-two-or-three-args-with-one-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3118 (2 (byte-compile-three-args (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119 (3 (byte-compile-three-args form))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3120 (4 (if (eq nil (nth 4 form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3121 (byte-compile-three-args (butlast form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3122 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123 (t (byte-compile-subr-wrong-args form "2-4"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 (defun byte-compile-no-args-with-two-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 (0 (byte-compile-no-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128 ((1 2) (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129 (t (byte-compile-subr-wrong-args form "0-2"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 (defun byte-compile-one-arg-with-two-extra (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 (1 (byte-compile-one-arg form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 ((2 3) (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135 (t (byte-compile-subr-wrong-args form "1-3"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137 ;; XEmacs: used for functions that have a different opcode in v19 than v20.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3138 ;; this includes `eq', `equal', and other old-ified functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139 (defun byte-compile-two-args-19->20 (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3140 (if (not (= (length form) 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 (byte-compile-subr-wrong-args form 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 (byte-compile-form (car (cdr form))) ;; Push the arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 (byte-compile-form (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 (if (byte-compile-version-cond byte-compile-emacs19-compatibility)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 (byte-compile-out (get (car form) 'byte-opcode19) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 (byte-compile-out (get (car form) 'byte-opcode) 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3148 (defun byte-compile-noop (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 (byte-compile-constant nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 (defun byte-compile-discard ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152 (byte-compile-out 'byte-discard 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3154 (defun byte-compile-max (form)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3155 (let ((args (cdr form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3156 (case (length args)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3157 (0 (byte-compile-subr-wrong-args form "1 or more"))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3158 (1 (byte-compile-form (car args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3159 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3160 (byte-compile-out 'byte-dup 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3161 (byte-compile-out 'byte-max 0)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 (t (byte-compile-form (car args))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3163 (dolist (elt (cdr args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3164 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3165 (byte-compile-out 'byte-max 0))))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3166
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3167 (defun byte-compile-min (form)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3168 (let ((args (cdr form)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3169 (case (length args)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3170 (0 (byte-compile-subr-wrong-args form "1 or more"))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3171 (1 (byte-compile-form (car args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3172 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3173 (byte-compile-out 'byte-dup 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3174 (byte-compile-out 'byte-min 0)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3175 (t (byte-compile-form (car args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3176 (dolist (elt (cdr args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3177 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3178 (byte-compile-out 'byte-min 0))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181 ;; more complicated compiler macros
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 (byte-defop-compiler list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 (byte-defop-compiler concat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185 (byte-defop-compiler fset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 (byte-defop-compiler insert)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 (byte-defop-compiler-1 function byte-compile-function-form)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3188 (byte-defop-compiler max)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3189 (byte-defop-compiler min)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3190 (byte-defop-compiler (+ byte-plus) byte-compile-plus)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3191 (byte-defop-compiler-1 - byte-compile-minus)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3192 (byte-defop-compiler (* byte-mult) byte-compile-mult)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3193 (byte-defop-compiler (/ byte-quo) byte-compile-quo)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 (byte-defop-compiler nconc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195 (byte-defop-compiler-1 beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 (byte-defop-compiler (= byte-eqlsign) byte-compile-arithcompare)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 (byte-defop-compiler (< byte-lss) byte-compile-arithcompare)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199 (byte-defop-compiler (> byte-gtr) byte-compile-arithcompare)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 (byte-defop-compiler (<= byte-leq) byte-compile-arithcompare)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 (byte-defop-compiler (>= byte-geq) byte-compile-arithcompare)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 (defun byte-compile-arithcompare (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 (0 (byte-compile-subr-wrong-args form "1 or more"))
549
2b0ea82d329f [xemacs-hg @ 2001-05-21 01:54:03 by martinb]
martinb
parents: 502
diff changeset
3206 (1 (if byte-compile-delete-errors
2b0ea82d329f [xemacs-hg @ 2001-05-21 01:54:03 by martinb]
martinb
parents: 502
diff changeset
3207 (byte-compile-constant t)
2b0ea82d329f [xemacs-hg @ 2001-05-21 01:54:03 by martinb]
martinb
parents: 502
diff changeset
3208 (byte-compile-normal-call form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209 (2 (byte-compile-two-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210 (t (byte-compile-normal-call form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 (byte-defop-compiler /= byte-compile-/=)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214 (defun byte-compile-/= (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216 (0 (byte-compile-subr-wrong-args form "1 or more"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 (1 (byte-compile-constant t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218 ;; optimize (/= X Y) to (not (= X Y))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3219 (2 (byte-compile-form-do-effect `(not (= ,@(cdr form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220 (t (byte-compile-normal-call form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 ;; buffer-substring now has its own function. This used to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 ;; 2+1, but now all args are optional.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 (byte-defop-compiler buffer-substring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 (defun byte-compile-buffer-substring (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227 ;; buffer-substring used to take exactly two args, but now takes 0-3.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228 ;; convert 0-2 to two args and use special bytecode operand.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229 ;; convert 3 args to a normal call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 (case (length (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231 (0 (byte-compile-two-args (append form '(nil nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 (1 (byte-compile-two-args (append form '(nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233 (2 (byte-compile-two-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 (3 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 (t (byte-compile-subr-wrong-args form "0-3"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237 (defun byte-compile-list (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 (let* ((args (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 (nargs (length args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 ((= nargs 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 (byte-compile-constant nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 ((< nargs 5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 (mapcar 'byte-compile-form args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 (byte-compile-out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 (aref [byte-list1 byte-list2 byte-list3 byte-list4] (1- nargs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248 ((< nargs 256)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 (mapcar 'byte-compile-form args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 (byte-compile-out 'byte-listN nargs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 (t (byte-compile-normal-call form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 (defun byte-compile-concat (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254 (let* ((args (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 (nargs (length args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256 ;; Concat of one arg is not a no-op if arg is not a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3257 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 ((memq nargs '(2 3 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 (mapcar 'byte-compile-form args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 (byte-compile-out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 (aref [byte-concat2 byte-concat3 byte-concat4] (- nargs 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263 ((eq nargs 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 (byte-compile-form ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265 ((< nargs 256)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 (mapcar 'byte-compile-form args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 (byte-compile-out 'byte-concatN nargs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 ((byte-compile-normal-call form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3270 (defun byte-compile-plus (form)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3271 (let ((args (cdr form)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3272 (case (length args)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3273 (0 (byte-compile-constant 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3274 (1 (byte-compile-plus (append form '(0))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3275 (t (byte-compile-form (car args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3276 (dolist (elt (cdr args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3277 (case elt
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3278 (0 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3279 (byte-compile-constant 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3280 (byte-compile-out 'byte-plus 0)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3281 (+1 (byte-compile-out 'byte-add1 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3282 (-1 (byte-compile-out 'byte-sub1 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3283 (t
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3284 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3285 (byte-compile-out 'byte-plus 0))))))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3286
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 (defun byte-compile-minus (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 (let ((args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289 (case (length args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 (0 (byte-compile-subr-wrong-args form "1 or more"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 (1 (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 (byte-compile-out 'byte-negate 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 (t (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 (dolist (elt (cdr args))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3295 (case elt
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3296 (0 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3297 (byte-compile-constant 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3298 (byte-compile-out 'byte-diff 0)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3299 (+1 (byte-compile-out 'byte-sub1 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3300 (-1 (byte-compile-out 'byte-add1 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3301 (t
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3302 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3303 (byte-compile-out 'byte-diff 0))))))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3304
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3305 (defun byte-compile-mult (form)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3306 (let ((args (cdr form)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3307 (case (length args)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3308 (0 (byte-compile-constant 1))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3309 (1 (byte-compile-mult (append form '(1))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3310 (t (byte-compile-form (car args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3311 (dolist (elt (cdr args))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3312 (case elt
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3313 (1 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3314 (byte-compile-constant 1)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3315 (byte-compile-out 'byte-mult 0)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3316 (-1 (byte-compile-out 'byte-negate 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3317 (2 (byte-compile-out 'byte-dup 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3318 (byte-compile-out 'byte-plus 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3319 (t
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3320 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3321 (byte-compile-out 'byte-mult 0))))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 (defun byte-compile-quo (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 (let ((args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 (case (length args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 (0 (byte-compile-subr-wrong-args form "1 or more"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327 (1 (byte-compile-constant 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328 (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 (byte-compile-out 'byte-quo 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330 (t (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331 (dolist (elt (cdr args))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3332 (case elt
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3333 (+1 (when (not byte-compile-delete-errors)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3334 (byte-compile-constant 1)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3335 (byte-compile-out 'byte-quo 0)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3336 (-1 (byte-compile-out 'byte-negate 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3337 (t
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3338 (when (and (numberp elt) (= elt 0))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3339 (byte-compile-warn "Attempt to divide by zero: %s" form))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3340 (byte-compile-form elt)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3341 (byte-compile-out 'byte-quo 0))))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 (defun byte-compile-nconc (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 (let ((args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3345 (case (length args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346 (0 (byte-compile-constant nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3347 ;; nconc of one arg is a noop, even if that arg isn't a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348 (1 (byte-compile-form (car args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349 (t (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3350 (dolist (elt (cdr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3351 (byte-compile-form elt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 (byte-compile-out 'byte-nconc 0))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 (defun byte-compile-fset (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 ;; warn about forms like (fset 'foo '(lambda () ...))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356 ;; (where the lambda expression is non-trivial...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 ;; Except don't warn if the first argument is 'make-byte-code, because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358 ;; I'm sick of getting mail asking me whether that warning is a problem.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 (let ((fn (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360 body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361 (when (and (eq (car-safe fn) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362 (eq (car-safe (setq fn (nth 1 fn))) 'lambda)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3363 (not (eq (car-safe (cdr-safe (nth 1 form))) 'make-byte-code)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3364 (setq body (cdr (cdr fn)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3365 (if (stringp (car body)) (setq body (cdr body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3366 (if (eq 'interactive (car-safe (car body))) (setq body (cdr body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3367 (if (and (consp (car body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368 (not (eq 'byte-code (car (car body)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370 "A quoted lambda form is the second argument of fset. This is probably
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371 not what you want, as that lambda cannot be compiled. Consider using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372 the syntax (function (lambda (...) ...)) instead."))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373 (byte-compile-two-args form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 (defun byte-compile-funarg (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376 ;; (mapcar '(lambda (x) ..) ..) ==> (mapcar (function (lambda (x) ..)) ..)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377 ;; for cases where it's guaranteed that first arg will be used as a lambda.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 (byte-compile-normal-call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379 (let ((fn (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380 (if (and (eq (car-safe fn) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381 (eq (car-safe (nth 1 fn)) 'lambda))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382 (cons (car form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383 (cons (cons 'function (cdr fn))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 (cdr (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 ;; (function foo) must compile like 'foo, not like (symbol-function 'foo).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3388 ;; Otherwise it will be incompatible with the interpreter,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 ;; and (funcall (function foo)) will lose with autoloads.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391 (defun byte-compile-function-form (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392 (byte-compile-constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3393 (cond ((symbolp (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394 (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 ((byte-compile-lambda (nth 1 form))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 (defun byte-compile-insert (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398 (cond ((null (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399 (byte-compile-constant nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 ((<= (length form) 256)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401 (mapcar 'byte-compile-form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 (if (cdr (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403 (byte-compile-out 'byte-insertN (length (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404 (byte-compile-out 'byte-insert 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405 ((memq t (mapcar 'consp (cdr (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 ;; We can split it; there is no function call after inserting 1st arg.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409 (while (setq form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 (byte-compile-form (car form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 (byte-compile-out 'byte-insert 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 (when (cdr form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413 (byte-compile-discard))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 ;; alas, the old (pre-19.12, and all existing versions of FSFmacs 19)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416 ;; byte compiler will generate incorrect code for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 ;; (beginning-of-line nil buffer) because it buggily doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418 ;; check the number of arguments passed to beginning-of-line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420 (defun byte-compile-beginning-of-line (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421 (let ((len (length form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422 (cond ((> len 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 (byte-compile-subr-wrong-args form "0-2"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424 ((or (= len 3) (not (byte-compile-constp (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 (byte-compile-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 (list 'forward-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 (if (integerp (setq form (or (eval (nth 1 form)) 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430 (1- form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 "Non-numeric arg to beginning-of-line: %s" form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433 (list '1- (list 'quote form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435 (byte-compile-constant nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 (byte-defop-compiler set)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 (byte-defop-compiler-1 setq)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440 (byte-defop-compiler-1 set-default)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441 (byte-defop-compiler-1 setq-default)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443 (byte-defop-compiler-1 quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 (byte-defop-compiler-1 quote-form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446 (defun byte-compile-setq (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447 (let ((args (cdr form)) var val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3448 (if (null args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3449 ;; (setq), with no arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3450 (byte-compile-form nil for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 (setq var (pop args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3453 (if (null args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454 ;; Odd number of args? Let `set' get the error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455 (byte-compile-form `(set ',var) for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 (setq val (pop args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3457 (if (keywordp var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3458 ;; (setq :foo ':foo) compatibility kludge
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3459 (byte-compile-form `(set ',var ,val) (if args t for-effect))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3460 (byte-compile-form val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3461 (unless (or args for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462 (byte-compile-out 'byte-dup 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3463 (byte-compile-variable-ref 'byte-varset var))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3464 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3466 (defun byte-compile-set (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3467 ;; Compile (set 'foo x) as (setq foo x) for trivially better code and so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3468 ;; that we get applicable warnings. Compile everything else (including
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3469 ;; malformed calls) like a normal 2-arg byte-coded function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3470 (let ((symform (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3471 (valform (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3472 sym)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3473 (if (and (= (length form) 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3474 (= (safe-length symform) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3475 (eq (car symform) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3476 (symbolp (setq sym (car (cdr symform))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3477 (not (byte-compile-constant-symbol-p sym)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3478 (byte-compile-setq `(setq ,sym ,valform))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479 (byte-compile-two-args form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 (defun byte-compile-setq-default (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 (let ((args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 (if (null args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3484 ;; (setq-default), with no arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3485 (byte-compile-form nil for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3486 ;; emit multiple calls to `set-default' if necessary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 (while args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488 (byte-compile-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489 ;; Odd number of args? Let `set-default' get the error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 `(set-default ',(pop args) ,@(if args (list (pop args)) nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491 (if args t for-effect)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495 (defun byte-compile-set-default (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 (let* ((args (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497 (nargs (length args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 (var (car args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 (when (and (= (safe-length var) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 (eq (car var) 'quote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 (let ((sym (nth 1 var)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3503 ((not (symbolp sym))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3504 (byte-compile-warn "Attempt to set-globally non-symbol %s" sym))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3505 ((byte-compile-constant-symbol-p sym)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506 (byte-compile-warn "Attempt to set-globally constant symbol %s" sym))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507 ((let ((cell (assq sym byte-compile-bound-variables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 (and cell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509 (setcdr cell (logior (cdr cell) byte-compile-assigned-bit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 ;; notice calls to set-default/setq-default for variables which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3512 ;; have not been declared with defvar/defconst.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3513 ((globally-boundp sym)) ; OK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 ((not (memq 'free-vars byte-compile-warnings))) ; warnings suppressed?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 ((memq sym byte-compile-free-assignments)) ; already warned about sym
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517 (byte-compile-warn "assignment to free variable %s" sym)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 (push sym byte-compile-free-assignments)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 (if (= nargs 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520 ;; now emit a normal call to set-default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 (byte-compile-normal-call form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522 (byte-compile-subr-wrong-args form 2))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 (defun byte-compile-quote (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 (byte-compile-constant (car (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 (defun byte-compile-quote-form (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529 (byte-compile-constant (byte-compile-top-level (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532 ;;; control structures
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534 (defun byte-compile-body (body &optional for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3535 (while (cdr body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3536 (byte-compile-form (car body) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3537 (setq body (cdr body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538 (byte-compile-form (car body) for-effect))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540 (proclaim-inline byte-compile-body-do-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 (defun byte-compile-body-do-effect (body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542 (byte-compile-body body for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3545 (proclaim-inline byte-compile-form-do-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546 (defun byte-compile-form-do-effect (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547 (byte-compile-form form for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550 (byte-defop-compiler-1 inline byte-compile-progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551 (byte-defop-compiler-1 progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3552 (byte-defop-compiler-1 prog1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 (byte-defop-compiler-1 prog2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3554 (byte-defop-compiler-1 if)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 (byte-defop-compiler-1 cond)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556 (byte-defop-compiler-1 and)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 (byte-defop-compiler-1 or)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 (byte-defop-compiler-1 while)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559 (byte-defop-compiler-1 funcall)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 (byte-defop-compiler-1 apply byte-compile-funarg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 (byte-defop-compiler-1 mapcar byte-compile-funarg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 (byte-defop-compiler-1 mapatoms byte-compile-funarg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 (byte-defop-compiler-1 mapconcat byte-compile-funarg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564 (byte-defop-compiler-1 let)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 (byte-defop-compiler-1 let*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567 (defun byte-compile-progn (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3568 (byte-compile-body-do-effect (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570 (defun byte-compile-prog1 (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 (setq form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 (byte-compile-form-do-effect (pop form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573 (byte-compile-body form t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 (defun byte-compile-prog2 (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 (setq form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 (byte-compile-form (pop form) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 (byte-compile-form-do-effect (pop form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 (byte-compile-body form t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 (defmacro byte-compile-goto-if (cond discard tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 `(byte-compile-goto
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583 (if ,cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 (if ,discard 'byte-goto-if-not-nil 'byte-goto-if-not-nil-else-pop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 (if ,discard 'byte-goto-if-nil 'byte-goto-if-nil-else-pop))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586 ,tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3588 (defun byte-compile-if (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 (byte-compile-form (car (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 (if (null (nthcdr 3 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591 ;; No else-forms
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592 (let ((donetag (byte-compile-make-tag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 (byte-compile-goto-if nil for-effect donetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594 (byte-compile-form (nth 2 form) for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 (byte-compile-out-tag donetag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 (let ((donetag (byte-compile-make-tag)) (elsetag (byte-compile-make-tag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 (byte-compile-goto 'byte-goto-if-nil elsetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598 (byte-compile-form (nth 2 form) for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 (byte-compile-goto 'byte-goto donetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 (byte-compile-out-tag elsetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 (byte-compile-body (cdr (cdr (cdr form))) for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 (byte-compile-out-tag donetag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 (setq for-effect nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 (defun byte-compile-cond (clauses)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 (let ((donetag (byte-compile-make-tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 nexttag clause)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 (while (setq clauses (cdr clauses))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 (setq clause (car clauses))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610 (cond ((or (eq (car clause) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 (and (eq (car-safe (car clause)) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 (car-safe (cdr-safe (car clause)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 ;; Unconditional clause
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 (setq clause (cons t clause)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 clauses nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 ((cdr clauses)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 (byte-compile-form (car clause))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618 (if (null (cdr clause))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619 ;; First clause is a singleton.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 (byte-compile-goto-if t for-effect donetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3621 (setq nexttag (byte-compile-make-tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 (byte-compile-goto 'byte-goto-if-nil nexttag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 (byte-compile-body (cdr clause) for-effect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624 (byte-compile-goto 'byte-goto donetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625 (byte-compile-out-tag nexttag)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626 ;; Last clause
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 (and (cdr clause) (not (eq (car clause) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628 (progn (byte-compile-form (car clause))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 (byte-compile-goto-if nil for-effect donetag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630 (setq clause (cdr clause))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 (byte-compile-body-do-effect clause)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3632 (byte-compile-out-tag donetag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3634 (defun byte-compile-and (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3635 (let ((failtag (byte-compile-make-tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3636 (args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3637 (if (null args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3638 (byte-compile-form-do-effect t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3639 (while (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3640 (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3641 (byte-compile-goto-if nil for-effect failtag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3642 (setq args (cdr args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643 (byte-compile-form-do-effect (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 (byte-compile-out-tag failtag))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3646 (defun byte-compile-or (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647 (let ((wintag (byte-compile-make-tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3648 (args (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649 (if (null args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3650 (byte-compile-form-do-effect nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651 (while (cdr args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 (byte-compile-form (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3653 (byte-compile-goto-if t for-effect wintag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3654 (setq args (cdr args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3655 (byte-compile-form-do-effect (car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3656 (byte-compile-out-tag wintag))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3658 (defun byte-compile-while (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3659 (let ((endtag (byte-compile-make-tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3660 (looptag (byte-compile-make-tag)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3661 (byte-compile-out-tag looptag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3662 (byte-compile-form (car (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3663 (byte-compile-goto-if nil for-effect endtag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3664 (byte-compile-body (cdr (cdr form)) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3665 (byte-compile-goto 'byte-goto looptag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3666 (byte-compile-out-tag endtag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3667 (setq for-effect nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3669 (defun byte-compile-funcall (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3670 (mapcar 'byte-compile-form (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3671 (byte-compile-out 'byte-call (length (cdr (cdr form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3674 (defun byte-compile-let (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3675 ;; First compute the binding values in the old scope.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3676 (let ((varlist (car (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3677 (while varlist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3678 (if (consp (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3679 (byte-compile-form (car (cdr (car varlist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3680 (byte-compile-push-constant nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3681 (setq varlist (cdr varlist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3682 (let ((byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3683 (cons 'new-scope byte-compile-bound-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3684 (varlist (reverse (car (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3685 (extra-flags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3686 ;; If this let is of the form (let (...) (byte-code ...))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687 ;; then assume that it is the result of a transformation of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3688 ;; ((lambda (...) (byte-code ... )) ...) and thus compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3689 ;; the variable bindings as if they were arglist bindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3690 ;; (which matters for what warnings.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3691 (if (eq 'byte-code (car-safe (nth 2 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3692 byte-compile-arglist-bit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3694 (while varlist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3695 (byte-compile-variable-ref 'byte-varbind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3696 (if (consp (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3697 (car (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3698 (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3699 extra-flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3700 (setq varlist (cdr varlist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3701 (byte-compile-body-do-effect (cdr (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3702 (if (memq 'unused-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3703 ;; done compiling in this scope, warn now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3704 (byte-compile-warn-about-unused-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3705 (byte-compile-out 'byte-unbind (length (car (cdr form))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3707 (defun byte-compile-let* (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3708 (let ((byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3709 (cons 'new-scope byte-compile-bound-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3710 (varlist (copy-sequence (car (cdr form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3711 (while varlist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3712 (if (atom (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3713 (byte-compile-push-constant nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714 (byte-compile-form (car (cdr (car varlist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3715 (setcar varlist (car (car varlist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3716 (byte-compile-variable-ref 'byte-varbind (car varlist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3717 (setq varlist (cdr varlist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3718 (byte-compile-body-do-effect (cdr (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3719 (if (memq 'unused-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3720 ;; done compiling in this scope, warn now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3721 (byte-compile-warn-about-unused-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3722 (byte-compile-out 'byte-unbind (length (car (cdr form))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3725 ;;(byte-defop-compiler-1 /= byte-compile-negated)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3726 (byte-defop-compiler-1 atom byte-compile-negated)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3727 (byte-defop-compiler-1 nlistp byte-compile-negated)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3729 ;;(put '/= 'byte-compile-negated-op '=)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3730 (put 'atom 'byte-compile-negated-op 'consp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3731 (put 'nlistp 'byte-compile-negated-op 'listp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3733 (defun byte-compile-negated (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3734 (byte-compile-form-do-effect (byte-compile-negation-optimizer form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3735
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 ;; Even when optimization is off, atom is optimized to (not (consp ...)).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3737 (defun byte-compile-negation-optimizer (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3738 ;; an optimizer for forms where <form1> is less efficient than (not <form2>)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3739 (list 'not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3740 (cons (or (get (car form) 'byte-compile-negated-op)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3741 (error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3742 "Compiler error: `%s' has no `byte-compile-negated-op' property"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3743 (car form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3744 (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3746 ;;; other tricky macro-like special-forms
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3748 (byte-defop-compiler-1 catch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3749 (byte-defop-compiler-1 unwind-protect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3750 (byte-defop-compiler-1 condition-case)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3751 (byte-defop-compiler-1 save-excursion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3752 (byte-defop-compiler-1 save-current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3753 (byte-defop-compiler-1 save-restriction)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3754 (byte-defop-compiler-1 save-window-excursion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3755 (byte-defop-compiler-1 with-output-to-temp-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3756 ;; no track-mouse.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3758 (defun byte-compile-catch (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3759 (byte-compile-form (car (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3760 (byte-compile-push-constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3761 (byte-compile-top-level (cons 'progn (cdr (cdr form))) for-effect))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3762 (byte-compile-out 'byte-catch 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3763
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3764 (defun byte-compile-unwind-protect (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3765 (byte-compile-push-constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3766 (byte-compile-top-level-body (cdr (cdr form)) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3767 (byte-compile-out 'byte-unwind-protect 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3768 (byte-compile-form-do-effect (car (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3769 (byte-compile-out 'byte-unbind 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3770
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3771 ;;(defun byte-compile-track-mouse (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3772 ;; (byte-compile-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3773 ;; (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3774 ;; 'funcall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3775 ;; (list 'quote
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3776 ;; (list 'lambda nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3777 ;; (cons 'track-mouse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3778 ;; (byte-compile-top-level-body (cdr form))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3780 (defun byte-compile-condition-case (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3781 (let* ((var (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3782 (byte-compile-bound-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3783 (if var
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3784 (cons (cons var 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3785 (cons 'new-scope byte-compile-bound-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3786 (cons 'new-scope byte-compile-bound-variables))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3787 (or (symbolp var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3788 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3789 "%s is not a variable-name or nil (in condition-case)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3790 (prin1-to-string var)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3791 (byte-compile-push-constant var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3792 (byte-compile-push-constant (byte-compile-top-level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3793 (nth 2 form) for-effect))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3794 (let ((clauses (cdr (cdr (cdr form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3795 compiled-clauses)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3796 (while clauses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3797 (let* ((clause (car clauses))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3798 (condition (car clause)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3799 (cond ((not (or (symbolp condition)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3800 (and (listp condition)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3801 (let ((syms condition) (ok t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3802 (while syms
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3803 (if (not (symbolp (car syms)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3804 (setq ok nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3805 (setq syms (cdr syms)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3806 ok))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3807 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3808 "%s is not a symbol naming a condition or a list of such (in condition-case)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3809 (prin1-to-string condition)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3810 ;; ((not (or (eq condition 't)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3811 ;; (and (stringp (get condition 'error-message))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3812 ;; (consp (get condition 'error-conditions)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3813 ;; (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3814 ;; "%s is not a known condition name (in condition-case)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3815 ;; condition))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3816 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3817 (setq compiled-clauses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3818 (cons (cons condition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3819 (byte-compile-top-level-body
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3820 (cdr clause) for-effect))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3821 compiled-clauses)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3822 (setq clauses (cdr clauses)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3823 (byte-compile-push-constant (nreverse compiled-clauses)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3824 (if (memq 'unused-vars byte-compile-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3825 ;; done compiling in this scope, warn now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3826 (byte-compile-warn-about-unused-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3827 (byte-compile-out 'byte-condition-case 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3830 (defun byte-compile-save-excursion (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3831 (byte-compile-out 'byte-save-excursion 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3832 (byte-compile-body-do-effect (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3833 (byte-compile-out 'byte-unbind 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3835 (defun byte-compile-save-restriction (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3836 (byte-compile-out 'byte-save-restriction 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3837 (byte-compile-body-do-effect (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3838 (byte-compile-out 'byte-unbind 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3840 (defun byte-compile-save-current-buffer (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3841 (if (byte-compile-version-cond byte-compile-emacs19-compatibility)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3842 ;; `save-current-buffer' special form is not available in XEmacs 19.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3843 (byte-compile-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3844 `(let ((_byte_compiler_save_buffer_emulation_closure_ (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3845 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3846 (progn ,@(cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3847 (and (buffer-live-p _byte_compiler_save_buffer_emulation_closure_)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3848 (set-buffer _byte_compiler_save_buffer_emulation_closure_)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3849 (byte-compile-out 'byte-save-current-buffer 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3850 (byte-compile-body-do-effect (cdr form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3851 (byte-compile-out 'byte-unbind 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3852
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3853 (defun byte-compile-save-window-excursion (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3854 (byte-compile-push-constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3855 (byte-compile-top-level-body (cdr form) for-effect))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3856 (byte-compile-out 'byte-save-window-excursion 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3857
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3858 (defun byte-compile-with-output-to-temp-buffer (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3859 (byte-compile-form (car (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3860 (byte-compile-out 'byte-temp-output-buffer-setup 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3861 (byte-compile-body (cdr (cdr form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3862 (byte-compile-out 'byte-temp-output-buffer-show 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3864
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3865 ;;; top-level forms elsewhere
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3867 (byte-defop-compiler-1 defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3868 (byte-defop-compiler-1 defmacro)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3869 (byte-defop-compiler-1 defvar)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3870 (byte-defop-compiler-1 defvar byte-compile-defvar-or-defconst)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3871 (byte-defop-compiler-1 defconst byte-compile-defvar-or-defconst)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3872 (byte-defop-compiler-1 autoload)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3873 ;; According to Mly this can go now that lambda is a macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3874 ;(byte-defop-compiler-1 lambda byte-compile-lambda-form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3875 (byte-defop-compiler-1 defalias)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3876 (byte-defop-compiler-1 define-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3878 (defun byte-compile-defun (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3879 ;; This is not used for file-level defuns with doc strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3880 (byte-compile-two-args ; Use this to avoid byte-compile-fset's warning.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3881 (list 'fset (list 'quote (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3882 (byte-compile-byte-code-maker
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3883 (byte-compile-lambda (cons 'lambda (cdr (cdr form)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3884 (byte-compile-discard)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3885 (byte-compile-constant (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3886
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3887 (defun byte-compile-defmacro (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3888 ;; This is not used for file-level defmacros with doc strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3889 (byte-compile-body-do-effect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3890 (list (list 'fset (list 'quote (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3891 (let ((code (byte-compile-byte-code-maker
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3892 (byte-compile-lambda
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3893 (cons 'lambda (cdr (cdr form)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3894 (if (eq (car-safe code) 'make-byte-code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3895 (list 'cons ''macro code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3896 (list 'quote (cons 'macro (eval code))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3897 (list 'quote (nth 1 form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3898
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3899 (defun byte-compile-defvar-or-defconst (form)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3900 ;; This is not used for file-level defvar/defconsts with doc strings:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3901 ;; byte-compile-file-form-defvar-or-defconst will be used in that case.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3902 ;; (defvar|defconst VAR [VALUE [DOCSTRING]])
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3903 (let ((fun (nth 0 form))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3904 (var (nth 1 form))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3905 (value (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3906 (string (nth 3 form)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3907 (when (> (length form) 4)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3908 (byte-compile-warn
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3909 "%s %s called with %d arguments, but accepts only %s"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3910 fun var (length (cdr form)) 3))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3911 (when (memq 'free-vars byte-compile-warnings)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3912 (push (cons var byte-compile-global-bit) byte-compile-bound-variables))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3913 (byte-compile-body-do-effect
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3914 (list
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3915 ;; Put the defined variable in this library's load-history entry
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3916 ;; just as a real defvar would, but only in top-level forms with values.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3917 (when (and (> (length form) 2)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3918 (null byte-compile-current-form))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3919 `(push ',var current-load-list))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3920 (when (> (length form) 3)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3921 (when (and string (not (stringp string)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3922 (byte-compile-warn "Third arg to %s %s is not a string: %s"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3923 fun var string))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3924 `(put ',var 'variable-documentation ,string))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3925 (if (cdr (cdr form)) ; `value' provided
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3926 (if (eq fun 'defconst)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3927 ;; `defconst' sets `var' unconditionally.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3928 `(setq ,var ,value)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3929 ;; `defvar' sets `var' only when unbound.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3930 `(if (not (boundp ',var)) (setq ,var ,value))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3931 `',var))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3932
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3933 (defun byte-compile-autoload (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3934 (and (byte-compile-constp (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3935 (byte-compile-constp (nth 5 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3936 (memq (eval (nth 5 form)) '(t macro)) ; macro-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3937 (not (fboundp (eval (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3938 (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3939 "The compiler ignores `autoload' except at top level. You should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3940 probably put the autoload of the macro `%s' at top-level."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3941 (eval (nth 1 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3942 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3944 ;; Lambda's in valid places are handled as special cases by various code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3945 ;; The ones that remain are errors.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3946 ;; According to Mly this can go now that lambda is a macro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3947 ;(defun byte-compile-lambda-form (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3948 ; (byte-compile-warn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3949 ; "`lambda' used in function position is invalid: probably you mean #'%s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3950 ; (let ((print-escape-newlines t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3951 ; (print-level 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3952 ; (print-length 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3953 ; (prin1-to-string form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3954 ; (byte-compile-normal-call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3955 ; (list 'signal ''error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3956 ; (list 'quote (list "`lambda' used in function position" form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3957
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3958 ;; Compile normally, but deal with warnings for the function being defined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3959 (defun byte-compile-defalias (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3960 (if (and (consp (cdr form)) (consp (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3961 (eq (car (nth 1 form)) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3962 (consp (cdr (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3963 (symbolp (nth 1 (nth 1 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3964 (consp (nthcdr 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3965 (consp (nth 2 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3966 (eq (car (nth 2 form)) 'quote)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3967 (consp (cdr (nth 2 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3968 (symbolp (nth 1 (nth 2 form))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3969 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3970 (byte-compile-defalias-warn (nth 1 (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3971 (nth 1 (nth 2 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3972 (setq byte-compile-function-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3973 (cons (cons (nth 1 (nth 1 form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3974 (nth 1 (nth 2 form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3975 byte-compile-function-environment))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3976 (byte-compile-normal-call form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3977
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3978 (defun byte-compile-define-function (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3979 (byte-compile-defalias form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3981 ;; Turn off warnings about prior calls to the function being defalias'd.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3982 ;; This could be smarter and compare those calls with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3983 ;; the function it is being aliased to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3984 (defun byte-compile-defalias-warn (new alias)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3985 (let ((calls (assq new byte-compile-unresolved-functions)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3986 (if calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3987 (setq byte-compile-unresolved-functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3988 (delq calls byte-compile-unresolved-functions)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3989
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3990 ;;; tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3992 ;; Note: Most operations will strip off the 'TAG, but it speeds up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3993 ;; optimization to have the 'TAG as a part of the tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3994 ;; Tags will be (TAG . (tag-number . stack-depth)).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3995 (defun byte-compile-make-tag ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3996 (list 'TAG (setq byte-compile-tag-number (1+ byte-compile-tag-number))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3997
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3999 (defun byte-compile-out-tag (tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4000 (push tag byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4001 (if (cdr (cdr tag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4002 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4003 ;; ## remove this someday
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4004 (and byte-compile-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4005 (not (= (cdr (cdr tag)) byte-compile-depth))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4006 (error "Compiler bug: depth conflict at tag %d" (car (cdr tag))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4007 (setq byte-compile-depth (cdr (cdr tag))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4008 (setcdr (cdr tag) byte-compile-depth)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4010 (defun byte-compile-goto (opcode tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4011 (push (cons opcode tag) byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4012 (setcdr (cdr tag) (if (memq opcode byte-goto-always-pop-ops)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4013 (1- byte-compile-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4014 byte-compile-depth))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4015 (setq byte-compile-depth (and (not (eq opcode 'byte-goto))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4016 (1- byte-compile-depth))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4017
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4018 (defun byte-compile-out (opcode offset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4019 (push (cons opcode offset) byte-compile-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4020 (case opcode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4021 (byte-call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4022 (setq byte-compile-depth (- byte-compile-depth offset)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4023 (byte-return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4024 ;; This is actually an unnecessary case, because there should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4025 ;; no more opcodes behind byte-return.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4026 (setq byte-compile-depth nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4027 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4028 (setq byte-compile-depth (+ byte-compile-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4029 (or (aref byte-stack+-info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4030 (symbol-value opcode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4031 (- (1- offset))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4032 byte-compile-maxdepth (max byte-compile-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4033 byte-compile-maxdepth))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4034 ;;(if (< byte-compile-depth 0) (error "Compiler error: stack underflow"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4035 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4037
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4038 ;;; call tree stuff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4039
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4040 (defun byte-compile-annotate-call-tree (form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4041 (let (entry)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4042 ;; annotate the current call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4043 (if (setq entry (assq (car form) byte-compile-call-tree))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4044 (or (memq byte-compile-current-form (nth 1 entry)) ;callers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4045 (setcar (cdr entry)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4046 (cons byte-compile-current-form (nth 1 entry))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4047 (push (list (car form) (list byte-compile-current-form) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4048 byte-compile-call-tree))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4049 ;; annotate the current function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4050 (if (setq entry (assq byte-compile-current-form byte-compile-call-tree))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4051 (or (memq (car form) (nth 2 entry)) ;called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4052 (setcar (cdr (cdr entry))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4053 (cons (car form) (nth 2 entry))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4054 (push (list byte-compile-current-form nil (list (car form)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4055 byte-compile-call-tree))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4056
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4057 ;; Renamed from byte-compile-report-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4058 ;; to avoid interfering with completion of byte-compile-file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4059 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4060 (defun display-call-tree (&optional filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4061 "Display a call graph of a specified file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4062 This lists which functions have been called, what functions called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4063 them, and what functions they call. The list includes all functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4064 whose definitions have been compiled in this Emacs session, as well as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4065 all functions called by those functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4066
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4067 The call graph does not include macros, inline functions, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4068 primitives that the byte-code interpreter knows about directly \(eq,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4069 cons, etc.\).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4070
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4071 The call tree also lists those functions which are not known to be called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4072 \(that is, to which no calls have been compiled\), and which cannot be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4073 invoked interactively."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4074 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4075 (message "Generating call tree...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4076 (with-output-to-temp-buffer "*Call-Tree*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4077 (set-buffer "*Call-Tree*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4078 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4079 (message "Generating call tree... (sorting on %s)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4080 byte-compile-call-tree-sort)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4081 (insert "Call tree for "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4082 (cond ((null byte-compile-current-file) (or filename "???"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4083 ((stringp byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4084 byte-compile-current-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4085 (t (buffer-name byte-compile-current-file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4086 " sorted on "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4087 (prin1-to-string byte-compile-call-tree-sort)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4088 ":\n\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4089 (if byte-compile-call-tree-sort
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4090 (setq byte-compile-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4091 (sort byte-compile-call-tree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4092 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4093 ((eq byte-compile-call-tree-sort 'callers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4094 #'(lambda (x y) (< (length (nth 1 x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4095 (length (nth 1 y)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4096 ((eq byte-compile-call-tree-sort 'calls)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4097 #'(lambda (x y) (< (length (nth 2 x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4098 (length (nth 2 y)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4099 ((eq byte-compile-call-tree-sort 'calls+callers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4100 #'(lambda (x y) (< (+ (length (nth 1 x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4101 (length (nth 2 x)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4102 (+ (length (nth 1 y))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4103 (length (nth 2 y))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4104 ((eq byte-compile-call-tree-sort 'name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4105 #'(lambda (x y) (string< (car x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4106 (car y))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4107 (t (error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4108 "`byte-compile-call-tree-sort': `%s' - unknown sort mode"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4109 byte-compile-call-tree-sort))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4110 (message "Generating call tree...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4111 (let ((rest byte-compile-call-tree)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4112 (b (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4113 f p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4114 callers calls)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4115 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4116 (prin1 (car (car rest)) b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4117 (setq callers (nth 1 (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4118 calls (nth 2 (car rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4119 (insert "\t"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4120 (cond ((not (fboundp (setq f (car (car rest)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4121 (if (null f)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4122 " <top level>";; shouldn't insert nil then, actually -sk
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4123 " <not defined>"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4124 ((subrp (setq f (symbol-function f)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4125 " <subr>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4126 ((symbolp f)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4127 (format " ==> %s" f))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4128 ((compiled-function-p f)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4129 "<compiled function>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4130 ((not (consp f))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4131 "<malformed function>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4132 ((eq 'macro (car f))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4133 (if (or (compiled-function-p (cdr f))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4134 (assq 'byte-code (cdr (cdr (cdr f)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4135 " <compiled macro>"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4136 " <macro>"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4137 ((assq 'byte-code (cdr (cdr f)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4138 "<compiled lambda>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4139 ((eq 'lambda (car f))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4140 "<function>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4141 (t "???"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4142 (format " (%d callers + %d calls = %d)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4143 ;; Does the optimizer eliminate common subexpressions?-sk
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4144 (length callers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4145 (length calls)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4146 (+ (length callers) (length calls)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4147 "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4148 (if callers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4149 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4150 (insert " called by:\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4151 (setq p (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4152 (insert " " (if (car callers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4153 (mapconcat 'symbol-name callers ", ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4154 "<top level>"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4155 (let ((fill-prefix " "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4156 (fill-region-as-paragraph p (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4157 (if calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4158 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4159 (insert " calls:\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4160 (setq p (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4161 (insert " " (mapconcat 'symbol-name calls ", "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4162 (let ((fill-prefix " "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4163 (fill-region-as-paragraph p (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4164 (insert "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4165 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4167 (message "Generating call tree...(finding uncalled functions...)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4168 (setq rest byte-compile-call-tree)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4169 (let ((uncalled nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4170 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4171 (or (nth 1 (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4172 (null (setq f (car (car rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4173 (byte-compile-fdefinition f t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4174 (commandp (byte-compile-fdefinition f nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4175 (setq uncalled (cons f uncalled)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4176 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4177 (if uncalled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4178 (let ((fill-prefix " "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4179 (insert "Noninteractive functions not known to be called:\n ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4180 (setq p (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4181 (insert (mapconcat 'symbol-name (nreverse uncalled) ", "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4182 (fill-region-as-paragraph p (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4183 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4184 (message "Generating call tree...done.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4185 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4188 ;;; by crl@newton.purdue.edu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4189 ;;; Only works noninteractively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4190 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4191 (defun batch-byte-compile ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4192 "Run `byte-compile-file' on the files remaining on the command line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4193 Use this from the command line, with `-batch';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4194 it won't work in an interactive Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4195 Each file is processed even if an error occurred previously.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
4196 For example, invoke \"xemacs -batch -f batch-byte-compile $emacs/ ~/*.el\"."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4197 ;; command-line-args-left is what is left of the command line (from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4198 ;; startup.el)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4199 (defvar command-line-args-left) ;Avoid 'free variable' warning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4200 (if (not noninteractive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4201 (error "`batch-byte-compile' is to be used only with -batch"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4202 (let ((error nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4203 (while command-line-args-left
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4204 (if (null (batch-byte-compile-one-file))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4205 (setq error t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4206 (message "Done")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4207 (kill-emacs (if error 1 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4208
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4209 ;;;###autoload
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4210 (defun batch-byte-compile-one-file ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4211 "Run `byte-compile-file' on a single file remaining on the command line.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4212 Use this from the command line, with `-batch';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4213 it won't work in an interactive Emacs."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4214 ;; command-line-args-left is what is left of the command line (from
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4215 ;; startup.el)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4216 (defvar command-line-args-left) ;Avoid 'free variable' warning
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4217 (if (not noninteractive)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4218 (error "`batch-byte-compile-one-file' is to be used only with -batch"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4219 (let (error
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4220 (file-to-process (car command-line-args-left)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4221 (setq command-line-args-left (cdr command-line-args-left))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4222 (if (file-directory-p (expand-file-name file-to-process))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4223 (let ((files (directory-files file-to-process))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4224 source dest)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4225 (while files
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4226 (if (and (string-match emacs-lisp-file-regexp (car files))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4227 (not (auto-save-file-name-p (car files)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4228 (setq source (expand-file-name
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4229 (car files)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4230 file-to-process))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4231 (setq dest (byte-compile-dest-file source))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4232 (file-exists-p dest)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4233 (file-newer-than-file-p source dest))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4234 (if (null (batch-byte-compile-1 source))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4235 (setq error t)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4236 (setq files (cdr files)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4237 (null error))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4238 (batch-byte-compile-1 file-to-process))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4239
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4240 (defun batch-byte-compile-1 (file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4241 (condition-case err
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4242 (progn (byte-compile-file file) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4243 (error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4244 (princ ">>Error occurred processing ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4245 (princ file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4246 (princ ": ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4247 (if (fboundp 'display-error) ; XEmacs 19.8+
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4248 (display-error err nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4249 (princ (or (get (car err) 'error-message) (car err)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4250 (mapcar #'(lambda (x) (princ " ") (prin1 x)) (cdr err)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4251 (princ "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4252 nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4253
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4254 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4255 (defun batch-byte-recompile-directory-norecurse ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4256 "Same as `batch-byte-recompile-directory' but without recursion."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4257 (setq byte-recompile-directory-recursively nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4258 (batch-byte-recompile-directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4260 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4261 (defun batch-byte-recompile-directory ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4262 "Runs `byte-recompile-directory' on the dirs remaining on the command line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4263 Must be used only with `-batch', and kills Emacs on completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4264 For example, invoke `xemacs -batch -f batch-byte-recompile-directory .'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4265 ;; command-line-args-left is what is left of the command line (startup.el)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4266 (defvar command-line-args-left) ;Avoid 'free variable' warning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4267 (if (not noninteractive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4268 (error "batch-byte-recompile-directory is to be used only with -batch"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4269 (or command-line-args-left
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4270 (setq command-line-args-left '(".")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4271 (let ((byte-recompile-directory-ignore-errors-p t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4272 (while command-line-args-left
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4273 (byte-recompile-directory (car command-line-args-left))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4274 (setq command-line-args-left (cdr command-line-args-left))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4275 (kill-emacs 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4277 (make-obsolete 'elisp-compile-defun 'compile-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4278 (make-obsolete 'byte-compile-report-call-tree 'display-call-tree)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4280 ;; other make-obsolete calls in obsolete.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4282 (provide 'byte-compile)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4283 (provide 'bytecomp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4286 ;;; report metering (see the hacks in bytecode.c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4288 (if (boundp 'byte-code-meter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4289 (defun byte-compile-report-ops ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4290 (defvar byte-code-meter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4291 (with-output-to-temp-buffer "*Meter*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4292 (set-buffer "*Meter*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4293 (let ((i 0) n op off)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4294 (while (< i 256)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4295 (setq n (aref (aref byte-code-meter 0) i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4296 off nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4297 (if t ;(not (zerop n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4298 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4299 (setq op i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4300 (setq off nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4301 (cond ((< op byte-nth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4302 (setq off (logand op 7))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4303 (setq op (logand op 248)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4304 ((>= op byte-constant)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4305 (setq off (- op byte-constant)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4306 op byte-constant)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4307 (setq op (aref byte-code-vector op))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4308 (insert (format "%-4d" i))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4309 (insert (symbol-name op))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4310 (if off (insert " [" (int-to-string off) "]"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4311 (indent-to 40)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4312 (insert (int-to-string n) "\n")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4313 (setq i (1+ i)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4316 ;; To avoid "lisp nesting exceeds max-lisp-eval-depth" when bytecomp compiles
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4317 ;; itself, compile some of its most used recursive functions (at load time).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4318 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4319 (eval-when-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4320 (or (compiled-function-p (symbol-function 'byte-compile-form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4321 (assq 'byte-code (symbol-function 'byte-compile-form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4322 (let ((byte-optimize nil) ; do it fast
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4323 (byte-compile-warnings nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4324 (mapcar #'(lambda (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4325 (or noninteractive (message "compiling %s..." x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4326 (byte-compile x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4327 (or noninteractive (message "compiling %s...done" x)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4328 '(byte-compile-normal-call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4329 byte-compile-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4330 byte-compile-body
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4331 ;; Inserted some more than necessary, to speed it up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4332 byte-compile-top-level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4333 byte-compile-out-toplevel
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4334 byte-compile-constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4335 byte-compile-variable-ref))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4336 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4338 ;;; bytecomp.el ends here