
6 Compiling Lisp Programs
compile function-or-method&optional function-definition&rest compiler-options
compile compiles an interpreted function or method in the current Lisp environment and replaces the interpreted function or method definition with the compiled version. For interpreted functions,compile produces a compiled function object from a lambda expression. The lambda expression is the argument function-definition if it is present; otherwise, the function definition of the symbol function-or-method is the relevant lambda expression.
compile specifies a function name, a method object, or the name of a method to be compiled.
compile returns that symbol. If the function-or-method argument isnil and the optional function-definition argument is supplied,compile returns the function object.
compile compiles the specified method and returns the method name.
method generic-function-name{qualifiers}*({specializer-name}*))
compiler-options. These keyword arguments affect only the specified compilation.
> (defun double (x) (+ x x)) DOUBLE> (compile 'double) DOUBLE
> (double 2) 4
> (funcall (compile nil '(lambda (x) (+ x x))) 3) 6
;;; Define the method ADD-ONE and create its associated ;;; generic function. > (defmethod add-one ((x number)) (+ x 1)) #<Standard-Method ADD-ONE (NUMBER)>
> (compile '(method add-one (number))) (METHOD ADD-ONE (NUMBER))
> (add-one 5) 6
compile-file, compiler-options, uncompile
compile-file input-pathname &key :output-file &rest compiler-options
compile-file produces binary files from Lisp source files. The compiled functions contained in the binary files become available for use when the binary files are loaded into Lisp.
*default-pathname-defaults* by using the Common Lisp functionmerge-pathnames.compile-file searches for a file that matches the given pathname.compile-file searches for source files by merging successive elements of*load-source-pathname-types* with the given pathname until it finds a match. If a source file does not exist,compile-file signals a continuable error and prompts for a new filename.:output-file keyword argument controls where the compiled code is written. If this argument is not specified or if its value isnil, the name of the output file is the pathname specified by the input-pathname argument with the following exception: the type component is taken from the first element of the list stored in the variable*load-binary-pathname-types*; the initial value of this element is.bin.
*load-binary-pathname-types*.
:output-file isnil.
compiler-options arguments can be any of the keyword-value pairs supplied to the functioncompiler-options. These keyword arguments affect only the specified compilation. The keyword arguments are extensions to Common Lisp.
compile, compiler-options; load, *load-binary-pathname-types*, *load-source-pathname-types* (in The Advanced User's Guide)
Syntax:compiled-function-p object
compiled-function-p is true if its argument is a compiled function object; otherwise, it is false.
> (compiled-function-p (symbol-function 'append)) Tcompiler-options Function> (compiled-function-p #'(lambda (x) x)) NIL
compiler-options &key :messages :file-messages :optimize-message :warnings :undef-warnings :show-optimizations :fast-entry :write-safety :read-safety :tail-merge :notinline :egc
compiler-options sets the default values of the keyword arguments to the functionscompile andcompile-file.
compiler-options::messagest sends messages to the standard output stream; otherwise, the value must specify a stream to which messages can be sent. The initial value isnil, which suppresses Compiler messages.
:file-messages"Reading source file...","Writing binary file...", and messages that give the current settings forspeed,safety,space, andcompilation-speed. A value ofnil means issue no file messages; otherwise, the value should specify a stream to which messages can be sent. The initial value ist, which sends the messages to the standard output stream.
:optimize-messagenil suppresses mode messages. A value of:terse allows terse messages. The initial value ist, which allows full optimization mode messages.
:warningsnil means issue no warnings; otherwise, the value must be eithert or a stream to which warnings can be sent. The initial value ist, which sends the warnings to the stream that is the value of the Common Lisp variable*error-output*.
:undef-warningsnil suppresses warnings. The initial value ist.
:show-optimizationsnil value shows optimization reports. The value:failure-only causes the Compiler to report only those optimizations that failed. The initial value isnil.
:fast-entrynil value means the Compiler does not insert checking in the compiled code. Calls to functions compiled in this manner are slightly faster. Settingsafety to 0 has the same effect on fast entry as setting:fast-entry tot. The initial value of:fast-entry isnil.
:write-safetynil value means the Compiler adds checking. Settingsafety to 2 has the same effect on write access as setting:write-safety tot. The initial value of:write-safety ist.
:read-safetynil value means the Compiler adds checking. Settingsafety to 3 has the same effect on read access as setting:read-safety tot. The initial value of:read-safety ist.
:tail-mergenil value causes the Compiler to convert tail-recursive calls to iterative constructions and to perform other types of tail call optimizations, such as tail merging, that eliminate the overhead of some function calls. Settingspeed to 3 has the same effect on tail merging as setting:tail-merge tot. The initial value of:tail-merge isnil.
:notinlinenil value, the Compiler behaves as if all functions have been declarednotinline; the compiled code uses procedure calls to functions rather than the machine-language code for the functions. Settingspeed to 0 has the same effect on in-line calls as setting:notinline tot. The initial value of:notinline isnil.
:egcnil value, the Compiler produces code that can be executed when ephemeral garbage collection is on. If the value isnil, the Compiler produces code that is incompatible with ephemeral garbage collection. Attempting to run such code when ephemeral garbage collection is already turned on signals a continuable error. The initial value of:egc ist. See Chapter 5, "Storage Management in Common Lisp" for more information about ephemeral garbage collection.
:target.:targetmips-little-endian
mips-big-endian:target option.
mips
compile, compile-file
Syntax:disassemble name-or-compiled-function
disassemble disassembles a compiled function and prints the resulting code on the standard output. It returnsnil.
*standard-output*.
Syntax:eval-when ({situation}*) {form}*
eval-when specifies when a particular body of code will be executed.
eval, the evaluator evaluates the form arguments at execution time.compile, the Compiler evaluates the form arguments at compilation time.load and the file containing theeval-when is compiled, then the forms are compiled; they are executed when the output file produced by the Compiler is loaded.eval-when. If no forms are executed,eval-when returnsnil.
> (setq test 3) 3uncompile Function> (eval-when (compile) (setq test 2)) NIL
> test 3
> (eval-when (eval) (setq test 2)) 2
> test 2
Syntax:uncompile name
uncompile replaces the compiled version of the specified function or macro with its original interpreted definition. The function or macro must have been compiled by a call to the functioncompile; otherwise, an error is signaled.
compile

Generated with Harlequin WebMaker