comparison man/lispref/compile.texi @ 1103:80d9ab2e9855

[xemacs-hg @ 2002-11-12 03:57:44 by stephent] byte compile options Info <87u1inwifn.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Tue, 12 Nov 2002 03:57:48 +0000
parents 1ccc32a20af4
children 4b7e0ff1958a
comparison
equal deleted inserted replaced
1102:30118fdc4f1f 1103:80d9ab2e9855
39 byte compilation. 39 byte compilation.
40 40
41 @menu 41 @menu
42 * Speed of Byte-Code:: An example of speedup from byte compilation. 42 * Speed of Byte-Code:: An example of speedup from byte compilation.
43 * Compilation Functions:: Byte compilation functions. 43 * Compilation Functions:: Byte compilation functions.
44 * Compilation Options:: Controlling the byte compiler's behavior.
44 * Docs and Compilation:: Dynamic loading of documentation strings. 45 * Docs and Compilation:: Dynamic loading of documentation strings.
45 * Dynamic Loading:: Dynamic loading of individual functions. 46 * Dynamic Loading:: Dynamic loading of individual functions.
46 * Eval During Compile:: Code to be evaluated when you compile. 47 * Eval During Compile:: Code to be evaluated when you compile.
47 * Compiled-Function Objects:: The data type used for byte-compiled functions. 48 * Compiled-Function Objects:: The data type used for byte-compiled functions.
48 * Disassembly:: Disassembling byte-code; how to read byte-code. 49 * Disassembly:: Disassembling byte-code; how to read byte-code.
253 command line. 254 command line.
254 @end defun 255 @end defun
255 256
256 @c XEmacs feature 257 @c XEmacs feature
257 @defvar byte-recompile-directory-ignore-errors-p 258 @defvar byte-recompile-directory-ignore-errors-p
258 If non-@code{nil}, this specifies that @code{byte-recompile-directory} 259 When non-@code{nil}, @code{byte-recompile-directory} will continue
259 will continue compiling even when an error occurs in a file. This is 260 compiling even when an error occurs in a file. Default: @code{nil}, but
260 normally @code{nil}, but is bound to @code{t} by 261 bound to @code{t} by @code{batch-byte-recompile-directory}.
261 @code{batch-byte-recompile-directory}. 262 @end defvar
262 @end defvar 263
264 @c XEmacs feature (?)
265 @defvar byte-recompile-directory-recursively
266 When non-@code{nil}, @code{byte-recompile-directory} will recurse on
267 subdirectories. Default: @code{t}.
268 @end defvar
269
263 270
264 @defun byte-code instructions constants stack-depth 271 @defun byte-code instructions constants stack-depth
265 @cindex byte-code interpreter 272 @cindex byte-code interpreter
266 This function actually interprets byte-code. 273 This function actually interprets byte-code.
267 Don't call this function yourself. Only the byte compiler knows how to 274 Don't call this function yourself. Only the byte compiler knows how to
271 part of a compiled-function object, and only rarely due to an explicit 278 part of a compiled-function object, and only rarely due to an explicit
272 call to @code{byte-code}. A byte-compiled function was once actually 279 call to @code{byte-code}. A byte-compiled function was once actually
273 defined with a body that calls @code{byte-code}, but in recent versions 280 defined with a body that calls @code{byte-code}, but in recent versions
274 of Emacs @code{byte-code} is only used to run isolated fragments of lisp 281 of Emacs @code{byte-code} is only used to run isolated fragments of lisp
275 code without an associated argument list. 282 code without an associated argument list.
283 @end defun
284
285 @node Compilation Options
286 @section Options for the Byte Compiler
287 @cindex compilation options
288
289 Warning: this node is a quick draft based on docstrings. There may be
290 inaccuracies, as the docstrings occasionally disagree with each other.
291 This has not been checked yet.
292
293 The byte compiler and optimizer are controlled by the following
294 variables. The @code{byte-compiler-options} macro described below
295 provides a convenient way to set most of them on a file-by-file basis.
296
297 @defvar emacs-lisp-file-regexp
298 Regexp which matches Emacs Lisp source files.
299 You may want to redefine @code{byte-compile-dest-file} if you change
300 this. Default: @code{"\\.el$"}.
301 @end defvar
302
303 @defun byte-compile-dest-file filename
304 Convert an Emacs Lisp source file name to a compiled file name. This
305 function may be redefined by the user, if necessary, for compatibility
306 with @code{emacs-lisp-file-regexp}.
307 @end defun
308
309 @c ;; This can be the 'byte-compile property of any symbol.
310 @c (autoload 'byte-compile-inline-expand "byte-optimize")
311
312 @defvar byte-compile-verbose
313 When non-@code{nil}, print messages describing progress of
314 byte-compiler. Default: @code{t} if interactive on a not-too-slow
315 terminal (see @code{search-slow-speed}), otherwise @code{nil}.
316 @end defvar
317
318 @defvar byte-optimize
319 Level of optimization in the byte compiler.
320
321 @table @code
322 @item nil
323 Do no optimization.
324
325 @item t
326 Do all optimizations.
327
328 @item source
329 Do optimizations manipulating the source code only.
330
331 @item byte
332 Do optimizations manipulating the byte code (actually, LAP code) only.
333 @end table
334 Default: @code{t}.
335 @end defvar
336
337 @defvar byte-compile-delete-errors
338 When non-@code{nil}, the optimizer may delete forms that may signal an
339 error if that is the only change in the function's behavior.
340 This includes variable references and calls to functions such as
341 @code{car}.
342 Default: @code{t}.
343 @end defvar
344
345 @defvar byte-optimize-log nil
346 When non-@code{nil}, the byte-compiler logs optimizations into
347 @file{*Compile-Log*}.
348
349 @table @code
350 @item nil
351 Log no optimization.
352
353 @item t
354 Log all optimizations.
355
356 @item source
357 Log optimizations manipulating the source code only.
358
359 @item byte
360 Log optimizations manipulating the byte code (actually, LAP code) only.
361 @end table
362 Default: @code{nil}.
363 @end defvar
364
365 @defvar byte-compile-error-on-warn
366 When non-@code{nil}, the byte-compiler reports warnings with @code{error}.
367 Default: @code{nil}.
368 @end defvar
369
370 @defvar byte-compile-default-warnings
371 The warnings used when @code{byte-compile-warnings} is @code{t}. Called
372 @code{byte-compile-warning-types} in GNU Emacs.
373 Default: @code{(redefine callargs subr-callargs free-vars unresolved
374 unused-vars obsolete)}.
375 @end defvar
376
377 @defvar byte-compile-warnings
378
379 List of warnings that the compiler should issue (@code{t} for the
380 default set). Elements of the list may be:
381
382 @table @code
383 @item free-vars
384 References to variables not in the current lexical scope.
385
386 @item unused-vars
387 References to non-global variables bound but not referenced.
388
389 @item unresolved
390 Calls to unknown functions.
391
392 @item callargs
393 Lambda calls with args that don't match the definition.
394
395 @item subr-callargs
396 Calls to subrs with args that don't match the definition.
397
398 @item redefine
399 Function cell redefined from a macro to a lambda or vice
400 versa, or redefined to take a different number of arguments.
401
402 @item obsolete
403 Use of an obsolete function or variable.
404
405 @item pedantic
406 Warn of use of compatible symbols.
407 @end table
408
409 The default set is specified by @code{byte-compile-default-warnings} and
410 normally encompasses all possible warnings.
411
412 See also the macro @code{byte-compiler-options}. Default: @code{t}.
413 @end defvar
414
415 The compiler can generate a call graph, which gives information about
416 which functions call which functions.
417
418 @defvar byte-compile-generate-call-tree
419 When non-@code{nil}, the compiler generates a call graph. This records
420 functions that were called and from where. If the value is @code{t},
421 compilation displays the call graph when it finishes. If the value is
422 neither @code{t} nor @code{nil}, compilation asks you whether to display
423 the graph.
424
425 The call tree only lists functions called, not macros used. Those
426 functions which the byte-code interpreter knows about directly
427 (@code{eq}, @code{cons}, etc.) are not reported.
428
429 The call tree also lists those functions which are not known to be called
430 (that is, to which no calls have been compiled). Functions which can be
431 invoked interactively are excluded from this list. Default: @code{nil}.
432 @end defvar
433
434 @defvar byte-compile-call-tree nil
435
436 Alist of functions and their call tree, used internally.
437 Each element takes the form
438
439 (@var{function} @var{callers} @var{calls})
440
441 where @var{callers} is a list of functions that call @var{function}, and
442 @var{calls} is a list of functions for which calls were generated while
443 compiling @var{function}.
444 @end defvar
445
446 @defvar byte-compile-call-tree-sort
447 When non-@code{nil}, sort the call tree. The values @code{name},
448 @code{callers}, @code{calls}, and @code{calls+callers} specify different
449 fields to sort on.") Default: @code{name}.
450 @end defvar
451
452 @code{byte-compile-overwrite-file} controls treatment of existing
453 compiled files.
454
455 @defvar byte-compile-overwrite-file
456 When non-@code{nil}, do not preserve backups of @file{.elc}s.
457 Precisely, if @code{nil}, old @file{.elc} files are deleted before the
458 new one is saved, and @file{.elc} files will have the same modes as the
459 corresponding @file{.el} file. Otherwise, existing @file{.elc} files
460 will simply be overwritten, and the existing modes will not be changed.
461 If this variable is @code{nil}, then an @file{.elc} file which is a
462 symbolic link will be turned into a normal file, instead of the file
463 which the link points to being overwritten. Default: @code{t}.
464 @end defvar
465
466 Variables controlling recompiling directories are described elsewhere
467 @xref{Compilation Functions}. They are
468 @code{byte-recompile-directory-ignore-errors-p} and
469 @code{byte-recompile-directory-recursively}.
470
471 The dynamic loading features are described elsewhere. These are
472 controlled by the variables @code{byte-compile-dynamic} (@pxref{Dynamic
473 Loading}) and @code{byte-compile-dynamic-docstrings} (@pxref{Docs and
474 Compilation}).
475
476 The byte compiler is a relatively recent development, and has evolved
477 significantly over the period covering Emacs versions 19 and 20. The
478 following variables control use of newer functionality by the byte
479 compiler. These are rarely needed since the release of XEmacs 21.
480
481 Another set of compatibility issues arises between Mule and non-Mule
482 XEmacsen; there are no known compatibility issues specific to the byte
483 compiler. There are also compatibility issues between XEmacs and GNU
484 Emacs's versions of the byte compiler. While almost all of the byte
485 codes are the same, and code compiled by one version often runs
486 perfectly well on the other, this is very dangerous, and can result in
487 crashes or data loss. Always recompile your Lisp when moving between
488 XEmacs and GNU Emacs.
489
490 @defvar byte-compile-single-version nil
491 When non-@code{nil}, the choice of emacs version (v19 or v20) byte-codes
492 will be hard-coded into bytecomp when it compiles itself. If the
493 compiler itself is compiled with optimization, this causes a speedup.
494 Default: @code{nil}.
495 @end defvar
496
497 @defvar byte-compile-emacs19-compatibility
498 When non-@code{nil} generate output that can run in Emacs 19.
499 Default: @code{nil} when Emacs version is 20 or above, otherwise
500 @code{t}.
501 @end defvar
502
503 @defvar byte-compile-print-gensym
504 When non-@code{nil}, the compiler may generate code that creates unique
505 symbols at run-time. This is achieved by printing uninterned symbols
506 using the @code{#:@var{}} notation, so that they will be read uninterned
507 when run.
508
509 With this feature, code that uses uninterned symbols in macros will
510 not be runnable under pre-21.0 XEmacsen.
511
512 Default: When @code{byte-compile-emacs19-compatibility} is non-nil, this
513 variable is ignored and considered to be @code{nil}. Otherwise
514 @code{t}.
515 @end defvar
516
517 @defvar byte-compile-new-bytecodes
518 This is completely ignored. For backwards compatibility.
519 @end defvar
520
521 @defun byte-compiler-options &rest args
522 Set some compilation-parameters for this file.
523 This will affect only the file in which it appears; this does nothing when
524 evaluated, or when loaded from a @file{.el} file.
525
526 Each argument to this macro must be a list of a key and a value.
527 (#### Need to check whether the newer variables are settable here.)
528
529 @example
530 Keys: Values: Corresponding variable:
531
532 verbose t, nil byte-compile-verbose
533 optimize t, nil, source, byte byte-optimize
534 warnings list of warnings byte-compile-warnings
535 file-format emacs19, emacs20 byte-compile-emacs19-compatibility
536 @end example
537
538 The value specified with the @code{warnings}option must be a list,
539 containing some subset of the following flags:
540
541 @example
542 free-vars references to variables not in the current lexical scope.
543 unused-vars references to non-global variables bound but not referenced.
544 unresolved calls to unknown functions.
545 callargs lambda calls with args that don't match the definition.
546 redefine function cell redefined from a macro to a lambda or vice
547 versa, or redefined to take a different number of arguments.
548 @end example
549
550 If the first element if the list is @code{+} or `@code{} then the
551 specified elements are added to or removed from the current set of
552 warnings, instead of the entire set of warnings being overwritten.
553 (#### Need to check whether the newer warnings are settable here.)
554
555 For example, something like this might appear at the top of a source file:
556
557 @example
558 (byte-compiler-options
559 (optimize t)
560 (warnings (- callargs)) ; Don't warn about arglist mismatch
561 (warnings (+ unused-vars)) ; Do warn about unused bindings
562 (file-format emacs19))
563 @end example
276 @end defun 564 @end defun
277 565
278 @node Docs and Compilation 566 @node Docs and Compilation
279 @section Documentation Strings and Compilation 567 @section Documentation Strings and Compilation
280 @cindex dynamic loading of documentation 568 @cindex dynamic loading of documentation
325 @end example 613 @end example
326 614
327 @defvar byte-compile-dynamic-docstrings 615 @defvar byte-compile-dynamic-docstrings
328 If this is non-@code{nil}, the byte compiler generates compiled files 616 If this is non-@code{nil}, the byte compiler generates compiled files
329 that are set up for dynamic loading of documentation strings. 617 that are set up for dynamic loading of documentation strings.
618 Default: t.
330 @end defvar 619 @end defvar
331 620
332 @cindex @samp{#@@@var{count}} 621 @cindex @samp{#@@@var{count}}
333 @cindex @samp{#$} 622 @cindex @samp{#$}
334 The dynamic documentation string feature writes compiled files that 623 The dynamic documentation string feature writes compiled files that
385 @end example 674 @end example
386 675
387 @defvar byte-compile-dynamic 676 @defvar byte-compile-dynamic
388 If this is non-@code{nil}, the byte compiler generates compiled files 677 If this is non-@code{nil}, the byte compiler generates compiled files
389 that are set up for dynamic function loading. 678 that are set up for dynamic function loading.
679 Default: nil.
390 @end defvar 680 @end defvar
391 681
392 @defun fetch-bytecode function 682 @defun fetch-bytecode function
393 This immediately finishes loading the definition of @var{function} from 683 This immediately finishes loading the definition of @var{function} from
394 its byte-compiled file, if it is not fully loaded already. The argument 684 its byte-compiled file, if it is not fully loaded already. The argument