Lecture 14: More Memory Management & While Loops & Nested Functions

Eelco Visser
Lecture | PDF
December 09, 2021

Memory Management

In this lecture we continue the previous lecture on memory managagement in which we study memory safety, automated memory management, and several garbage collection algorithms. See the previous lecture for the slides.

While Loops

We extend the study of control-flow statements by looking at the translation of while loops. Loops do not need additional constructs in the intermediate language since the can be expressed using (conditional) jumps. But register allocation for loops requires the extension of liveness analysis to compute a fixpoint of the analysis results.

Dynamic Rules in Stratego

To express context-sensitive transformations, Stratego provides dynamic rewrite rules. We provide several examples that are useful in your compiler.

Nested Functions

We then discuss code generation for functions, including:

  • The definition of a calling convention and that translates to building up a call frame.
  • Renaming of functions and variables in order to get a program with unique names in order to deal with shadowing of names.
  • The treatment of nested functions by adding a static link as extra parameter to nested functions, in order to provide access to variables in the call frame of an enclosing function. We show discuss a number of critical examples that point out issues to take into account. We illustrate a program transformation that makes explicit the number of static links to traverse in order to access the relevant call frame.
  • A challenge to exend ChocoPy with functions as first-class citizens.

Slides