Skip to content

compile file and macroexpansion

Masataro Asai edited this page Feb 20, 2018 · 2 revisions

Reading strings/files and invoking the compiler

Needless to say, sbcl is an ANSI compliant common lisp. So the first part of the compiler is read-ing and compileing the source code, or compile-file source code (which is almost equivalent).

sbcl's compile-file has :block-compile keyword option inherited from cmucl, but this option is currently disabled. Block compilation is a method that inlines functions within a certain range of the code surrounded by (declaim (start-block name)) ... (declaim (end-block api)). The reason this was disabled is discussed here. Without inlining, it forces passing/returning float values only in the boxed (tagged) representation which is slow. There are several ways to achieve the same functionality: inlining or using labels.

Compile INPUT-FILE, producing a corresponding fasl file and
returning its filename.

  :PRINT
     If true, a message per non-macroexpanded top level form is printed
     to *STANDARD-OUTPUT*. Top level forms that whose subforms are
     processed as top level forms (eg. EVAL-WHEN, MACROLET, PROGN) receive
     no such message, but their subforms do.

     As an extension to ANSI, if :PRINT is :top-level-forms, a message
     per top level form after macroexpansion is printed to *STANDARD-OUTPUT*.
     For example, compiling an IN-PACKAGE form will result in a message about
     a top level SETQ in addition to the message about the IN-PACKAGE form'
     itself.

     Both forms of reporting obey the SB-EXT:*COMPILER-PRINT-VARIABLE-ALIST*.

  :BLOCK-COMPILE
     Though COMPILE-FILE accepts an additional :BLOCK-COMPILE
     argument, it is not currently supported. (non-standard)

  :TRACE-FILE
     If given, internal data structures are dumped to the specified
     file, or if a value of T is given, to a file of *.trace type
     derived from the input file name. (non-standard)

  :EMIT-CFASL
     (Experimental). If true, outputs the toplevel compile-time effects
     of this file into a separate .cfasl file.

macro expansion

  • macroexpand [ANSI]
  • macroexpand-1 [ANSI]
  • compiler-macroexpand [ANSI]

Note that macroexpansion is intertwined with other compiler internals, such as ir1-transform. This observation follows from the fact that the &environment variable recognizes the variables types, including the inferred ones.