Urgent.News

What's breaking now, across thousands of outlets.

Tech

Writing the Cyclone Scheme Compiler (2017)

This write-up offers a high-level overview of the various components of the Cyclone compiler and their development. Before diving in, the author thanks the many contributors to the Scheme community, as Cyclone is based on the latest revision of the Scheme language and makes use of existing code where possible. The compiler's architecture is similar to other modern compilers: it takes an input file of Scheme code from the command line, parses it into an abstract syntax tree (AST), and then applies a series of source-to-source transformations to optimize the code and make it easier to compile to C. These transformations include macro expansion, expansion of macros, optimizations, and restructuring/relabeling the code to prepare it for generating C. The author was inspired by Marc Feeley's 90-minute Scheme to C compiler, which demonstrates compiling Scheme to C using source-to-source transformations, including closure and continuation-passing-style (CPS) conversions.

Some of the challenges in compiling to C include Scheme's tail-calls, first-class continuations, closures of indefinite extent, and automatic memory management (garbage collection). To overcome these challenges, the Cyclone compiler uses a series of transformations to remove powerful features not provided by C, add constructs required by the C code, and restructure/relabel the code.

The final code can be compiled directly to C. The author also notes the use of the Nanopass Framework, which is designed to make writing a compiler with many small passes over the code easier, although Nanopass itself is written in R6RS and could not be used for this project. The transformations follow a pattern of recursively examining an expression, with a short example showing the code structure.

The Nanopass Framework and the Cyclone compiler's use of the 90-minute compiler as inspiration are key to the development of Cyclone.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at justinethier.github.io →

More in Tech

More from Saturday 3 October →