Next: , Previous: The interpreter, Up: Top


7 The Compiler

The ECL compiler translates a Lisp program stored in a source file into a C program, invokes the C compiler to compile the C program, and then generates an object file, called fasl file (or o-file because of the actual filetype). The compiled program in a fasl file is loaded by the function load.

Ordinarily, the object program generated by the ECL compiler scarcely does runtime error-checking for runtime efficiency. In addition, Lisp functions in the same source file are linked together and some system functions are open-coded in-line. To control runtime error checking, supply appropriate optimize declarations (see Section 7.1).

The ECL compiler processes the eval-when special form exactly as specified in [see Steele:84] (see Section 5.3.3 of [see Steele:84]).

The ECL compiler is invoked by the functions compile-file, compile, and disassemble described below. In addition, the ECL compiler may be invoked directly by the Shell commands ecl. This command requires the file name of the source file as its argument. ecl simply adds .lsp to the file name argument to obtain the full name of the source file.

        $ ecl filename

has the same effect as the compiler invocation (compile-file filename) from within ECL, and

        $ ecl -C filename

has the same effects as (compile-file filename :c-file t :h-file t :data-file t).

— Function: compile-file pathname &key :output-file :verbose :print :c-file :h-file :data-file

compile-file compiles the Lisp program stored in the file specified by pathname, and generates a binary file. If :verbose is true, a message indicating what file is being compiled is printed. If :print is true, information about top-level forms in the file being compiled is printed. compile-file generates the following temporary files:

Temporary File Contents
c-file C version of the Lisp program
h-file The include file referenced in the c-file
data-file The Lisp data to be used at load time

If files of these names already exist, the old files will be deleted first. Usually, these intermediate files are automatically deleted after execution of compile-file.

The input-file is determined in the usual manner (see Section 2.9), except that, if the filetype is not specified, then the default filetype .lsp will be used. The keyword parameter :output-file defines the default directory and the default name to be applied to the output files (i.e., the fasl file and the temporary files). :output-file itself defaults to input-pathname. That is, if :output-file is not supplied, then the directory and the name of the input file will be used as the default directory and the default name for the output files. The file types of the output files are fixed as follows.

Output File Filetype
fasl file .o
c-file .c
h-file .h
data-file .data

Each output file can be specified by the corresponding keyword parameter. If the value of the keyword parameter is (), then the output file will be deleted after execution of compile-file. If the value of the keyword parameter is T, then the output file will be left in the default directory under the default name. Otherwise, the output file will be left in the directory under the name specified by the keyword parameter. The default value of :output-file is T, and the default values of :c-file, ::h-file, and :data-file are all ().

(compile-file 'foo)
The source file is FOO.lsp and the fasl file is FOO.o both in the current directory.
(compile-file 'foo.lish)
The source file is FOO.LISH and the fasl file is FOO.o'.
(compile-file "/usr/mas/foo" :output-file "/usr/tai/baa")
The source file is foo.lsp in the directory /usr/mas, and the fasl file is baa.o in the directory /usr/tai.

— Function: compile name code &optional definition

If definition is not supplied, name should be the name of a not-yet-compiled function. In this case, compile compiles the function, replaces the previous definition of name with the compiled function,and returns name. If definition is supplied, it should be a lambda-expression to be compiled and name should be a symbol. If name is a non-() symbol, then compile installs the compiled function as the function definition of name and returns name. If name is (), then compile simply returns the compiled function.

The ECL compiler is essentially a file compiler, and forms to be compiled are supposed to be stored in a file. Thus compile actually creates a source file which contains the form designated by the arguments. Then compile calls compile-file to get a fasl file, which is then loaded into ECL. The source file and the fasl file are given the names gazonk.lsp and gazonk.fasl, respectively. These files are not deleted automatically after the execution of compile.

— Function: disassemble &optional thing &key :h-file :data-file

This function does not actually disassemble. It always calls the ECL compiler and prints the contents of the c-file, i.e., the C-language code, generated by the ECL compiler. If thing is not supplied, or if it is (), then the previously compiled form by disassemble will be compiled again. If thing is a symbol other than (), then it must be the name of a not-yet-compiled function, whose definition is to be compiled. In this case, it is an error if the name is associated with a special form or a macro. If thing is a lambda-expression (lambda lambda-list . body), then disassemble first creates a function definition (defun gazonk lambda-list . body) and this definition is compiled. (The function name gazonk has no special meanings. Indeed, the displayed code is essentially independent of the function name.) Otherwise, thing itself will be compiled as a top-level form. In any case, disassemble does not install the compiled function. disassemble returns no value.

No intermediate h-file is created if the keyword parameter :h-file is () or if :h-file is not supplied. Otherwise, an intermediate h-file is created under the name specified by :h-file. Similarly, the intermediate data-file is specified by the keyword parameter :data-file.