Lecture 14: Nested Functions & Memory Management

Eelco Visser
Lecture | PDF
December 10, 2020

In this lecture we revisit 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.

Then we have a brief look at the compilation of control-flow statements and string constants, discuss boxed vs unboxed representations of primitive values, and discuss the execution environment of a language consisting of the implementation of built-in functions.

In the last part of the lecture we study memory safety, automated memory management, and several garbage collection algorithms.