Assignment 11

In this assignment, you will implement a garbage collector to manage the memory allocation for the Lacs language.

In Transformations.scala, in the Assignment 6 version of the addEntryExit method, the prologue currently saves the address of the parameter chunk being passed in using the allocated register into the savedParamPtr register, and then it allocates the frame for the procedure, either on the stack or on the heap. When we implement the garbage collector, the process of allocating a chunk on the heap will overwrite the savedParamPtr register, so the address of the incoming parameters would be lost. One solution to this is to always allocate a temporary frame for the procedure on the stack first. Then, after the address of the parameters has been written to the paramPtr variable in the frame, the prologue can allocate a new frame on the heap, copy the frame from the stack into the one on the heap, and pop the temporary frame from the stack. Implement this solution in the addEntryExit method, and check that your compiler still passes the Marmoset tests for Assignments 5, 6 and 10. If your compiler previously did not pass all of the tests for those assignments, check that it still passes the same tests that it used to pass.

In MemoryManagement.scala, review the comments of the Chunk class, and ensure that your implementation of the methods variableToOffset, read, write, and initialize is consistent with what the comments say about Assignment 11.

Implement copyChunk in MemoryManagement.scala if you did not do so already as part of the bonus of Assignment 6.

In MemoryManagement.scala, in the GarbageCollector object, complete the implementations of:

  1. allocate
  2. collectGarbage
  3. procedures

You can find the specification of the Lacs language here.