wiki:CompilationPhases

Version 4 (modified by ehuelsmann, 12 years ago) (diff)

--

Compilation phases

The compiler makes 3 passes for a full compilation:

  • precompile (applies to both the compiler and interpreter)
  • p1
  • p2

The precompiler

The precompiler does a number of source code transforms which are semantically equal, in order to reduce the number of permutations the compiler should accomodate for. By no means the list below is limitative, but these are the ones I found so far:

  • expansion of multiple SETF pairs into separate SETF statements
  • the same for SETQ
  • expansion of lambda expressions in the operator position into explicit FUNCALLs

Compilation phase 1: p1

Honestly, I have no idea what the difference is between p1 and p2, except for what is specified below.

Compilation phase 2: p2

This phase creates byte code output.

It does this by:

  1. Using the outcomes from p1
  2. Breaking down forms into small pieces
  3. Creating java 'instructions' from the small pieces

The generated instructions differ from byte code in so far that they are not stored in arrays of octets, but instead in an array (or list) of 'instruction'-structures.

Byte code munging phase

This phase does byte code calculations

  1. Analyzing the byte code, deleting unused branches (jvm.lisp::OPTIMIZE-CODE)
  2. Optimize byte code by walking the byte codes, replacing inefficient sequences with more efficient ones
  3. Translating the instructions from the instructions array to an array with byte-codes (octets)
  4. Writing out a file according to the format specified for .class files