The essence of compiling with continuations

  • Authors:
  • Cormac Flanagan;Amr Sabry;Bruce F. Duba;Matthias Felleisen

  • Affiliations:
  • Systems Research Center, Compaq;Indiana University;Seattle University;Northeastern University

  • Venue:
  • ACM SIGPLAN Notices - Best of PLDI 1979-1999
  • Year:
  • 2004

Quantified Score

Hi-index 0.00

Visualization

Abstract

In order to simplify the compilation process, many compilers for higher-order languages use the continuation-passing style (CPS) transformation in a first phase to generate an intermediate representation of the source program. The salient aspect of this intermediate form is that all procedures take an argument that represents the rest of the computation (the "continuation"). Since the naïve CPS transformation considerably increases the size of programs, CPS compilers perform reductions to produce a more compact intermediate representation. Although often implemented as a part of the CPS transformation, this step is conceptually a second phase. Finally, code generators for typical CPS compilers treat continuations specially in order to optimize the interpretation of continuation parameters.A thorough analysis of the abstract machine for CPS terms shows that the actions of the code generator invert the naïve CPS translation step. Put differently, the combined effect of the three phases is equivalent to a source-to-source transformation that simulates the compaction phase. Thus, fully developed CPS compilers do not need to employ the CPS transformation but can achieve the same results with a simple source-level transformation.