Things to learn during this stage that you should remember:
The techniques used to implement reference counting via the redefinition
also smart pointers.
The intermediate translation is stored in an
guarantee it is released (
delete) at the end of the run.
The class template
misc::ref provides reference counting smart
pointers to ease the memory management. It is used to handle nodes of
the intermediate representation, especially because during
TC-6 some rewriting might transform this tree into an
DAG, in which case memory deallocation is complex.
C++ features the
union keyword, inherited from C. Not only is
union not type safe, it also forbids class members. Some people
have worked hard to implement
union à la C++, i.e., with type
safety, polymorphism etc. These union are called “discriminated
unions” or “variants” to follow the vocabulary introduced by Caml.
See the papers from Andrei Alexandrescu:
Discriminated Unions (i),
Discriminated Unions (ii),
Generic: Discriminated Unions (iii) for an introduction to the techniques. We
I (Akim) strongly encourage you to read these enlightening articles.
The C++ standard specifies that unless specified, default
implementations of the copy constructor and assignment operator must be
provided by the compiler. There are some pitfalls though, clearly
exhibited in the implementation of
misc::ref. You must be able
to explain these pitfalls.
C++ allows several kinds of entities to be used as template parameters.
The most well known kind is “type”: you frequently parameterize class
templates with types via ‘template <typename T>’ or ‘template
<class T>’. But you may also parameterize with a class template. The
temp module heavily uses this feature: understand it, and be
ready to write similar code.
You must be able to explain how templates are “compiled”. In
addition, you know how to explicitly instantiate templates, and explain
what it can be used for. The implementation of
is based on these ideas.
See the corresponding rule in File Conventions for some
explanations on this topic.
C++ supports covariance of the method return type. This feature is
crucial to implement methods such as
clone, as in
frame::Access::clone(). Understand return type covariance.
The ‘Ix’, ‘Cx’, ‘Nx’, and ‘Ex’ classes delay computation to address context-depend issues in a context independent way.
In this project, the AST is composed of different classes related by inheritance (as if the kinds of the nodes were class members). Here, the nodes are members of a single class, but their nature is specified by the object itself (as if the kinds of the nodes were object members).
The implementation of recursion and automatic variables.
Reaching non local variables.