CL3 to CPS/L3 Translation

Introduction

For this second assignment — the first graded one — you have to implement the translation of CL3 to CPS/L3 presented in the lecture.

You should proceed in two steps: first implement the “simple” variant, and once it works, implement the optimized one.

Initial setup

To start working on this assignment, you should download the Zip archive containing our skeleton. Notice that it also contains the solution to last week’s assignment.

The top-level directory in this archive is called l3, and not l3-warmup like last week. The idea is that you should keep your solution to the warmup assignment in l3-warmup and use the contents of this week’s archive as the starting point of the rest of the project. In particular, if you’re using git to manage your project, we recommend creating a new repository with the contents of this week’s archive, and use it until the end of the semester.

Overview

If you explore our new skeleton, you will first notice that it contains a complete version of the L3 parser in L3Parser.scala, as well as a working int-print function in integers.l3. We suggest that you spend some time comparing your solution to ours.

Apart from our solution, our repository contains some stubs for this second assignment. In particular, notice that the definition of the compiler back-end in Main.scala does not run CL3Interpreter anymore. Rather, it first runs the phase CL3ToCPSTranslator — that you will have to implement — and then an interpreter for the CPS language called HighCPSInterpreter.

Also, you may notice that between translation and interpretation, there is an additional (optional) step, called treeChecker. Its purpose is to go through your generated CPS tree, check that all names are defined exactly once, and emit useful warnings in case they are not. Take advantage of this output to track any bugs you may have in the translation.

The focus of this assignment is of course the CL3ToCPSTranslator phase, located in the file of the same name. Right now, it is basically empty. In the beginning of the lab, we will develop together a skeleton for the code, and give a few illustrative examples. Your presence during the lab session is therefore strongly recommended!

Testing and submission

When you are done editing, you can run the tests using sbt’s test command, as described in the previous assignment.

Once everything is working, you should submit your solution to our server. Notice that you can submit several times if you want, only the latest submission will be taken into account. However, it is impossible to submit once the deadline is over, so make sure to submit often, even if your solution is not yet complete! In particular, for this assignment, we strongly recommend that you do one submission once the simple version of the translation works.

To create the archive of your project, use sbt’s packageSrc command. This will create an archive of the sources of your compiler, called l3c_3-2024-sources.jar in the target/scala-3.3.1 directory. This is the file that you should submit to our submission server.

Grading

A total of 80 points are assigned to this project part, out of a total of 500 for the whole semester. Your submission will be graded based on:

  1. its correctness, i.e. whether it passes all the functional tests that were made available to you,
  2. its completeness, i.e. whether you covered all the cases as required, and implemented the optimized version of the translation, correctly handling all the cases.

The style of your code will be evaluated, but not graded for this assignment. Please pay attention to the style remarks that are made to you, however, as starting with the fourth assignment, style will be graded.