Note: I've just migrated to a different physical server to run Spivey's Corner,
with a new architecture, a new operating system, a new version of PHP, and an updated version of MediaWiki.
Please let me know if anything needs adjustment! – Mike

Laboratory exercises: Difference between revisions

From Compilers
Jump to navigation Jump to search
(Created page with "{{Compilers}} ''Solutions to the lab exercises are accessible to tutors and demonstrators on a private page.'' There are four lab...")
 
No edit summary
Line 1: Line 1:
{{Compilers}}
{{Compilers}}
''Solutions to the lab exercises are accessible to tutors and demonstrators on a [[Tutors:Laboratory exercises (Compilers)|private page]].''
''Solutions to the lab exercises are accessible to tutors and demonstrators on a [[Tutors:Laboratory exercises|private page]].''


There are four lab exercises for the course:
There are four lab exercises for the course:
Line 11: Line 11:
The lab exercises are described in Chapters 3, 5, 7 and 9 of the {{Doc|compilers|book|coursebook}}, with a separate {{Doc|compilers|lab0|set of instructions}} for Lab 0.  Listings of the chief modules you will need to change are provided in Appendix E of the book.
The lab exercises are described in Chapters 3, 5, 7 and 9 of the {{Doc|compilers|book|coursebook}}, with a separate {{Doc|compilers|lab0|set of instructions}} for Lab 0.  Listings of the chief modules you will need to change are provided in Appendix E of the book.


* A note about [[the nodexp tool (Compilers)|the nodexp tool]].
* A note about [[the nodexp tool]].
* A note about [[the pibake script (Compilers)|the pibake script]].
* A note about [[the pibake script]].


The lab materials are delivered using an anonymous Mercurial server in a way described in the instructions for Lab 1.  You can also browse the materials using the URL <code>http://spivey.oriel.ox.ac.uk/hg/compilers</code>, and there's a [[Mercurial cheat sheet (Compilers)|cheat sheet]] listing the commands you'll need to use.
The lab materials are delivered using an anonymous Mercurial server in a way described in the instructions for Lab 1.  You can also browse the materials using the URL <code>http://spivey.oriel.ox.ac.uk/hg/compilers</code>, and there's a [[Mercurial cheat sheet|cheat sheet]] listing the commands you'll need to use.


If you're already familiar with Git, then the same materials are accessible as a Git repository at @http://spivey.oriel.ox.ac.uk/git/compilers.git@.  If you're tempted to follow this route, be aware that the lab manual provides help only with Mercurial.
If you're already familiar with Git, then the same materials are accessible as a Git repository at @http://spivey.oriel.ox.ac.uk/git/compilers.git@.  If you're tempted to follow this route, be aware that the lab manual provides help only with Mercurial.
Line 39: Line 39:


==Using your own machine==
==Using your own machine==
Naturally enough, the computers in the Software Lab have been set up with all the software that is needed to do these exercises.  If you want to use your own machine, that is perfectly possible, and [[Software setup (Compilers)|another page]] gives suggestions for setting up the software you need.  You will probably wish to do this well before the end of term so that you are set up for the Christmas assignment.
Naturally enough, the computers in the Software Lab have been set up with all the software that is needed to do these exercises.  If you want to use your own machine, that is perfectly possible, and [[Software setup|another page]] gives suggestions for setting up the software you need.  You will probably wish to do this well before the end of term so that you are set up for the Christmas assignment.


==Safety net==
==Safety net==

Revision as of 21:31, 17 March 2020

Solutions to the lab exercises are accessible to tutors and demonstrators on a private page.

There are four lab exercises for the course:

  1. Implement control structures in a flowchart language.
  2. Add array access to a typed language
  3. Implement procedure calls, nested procedures and higher-order functions.
  4. Extend a code generator for the ARM to better exploit addressing modes.

Some of the exercises have optional parts that you may like to complete. It's more important, however, that you do at least the non-optional parts of all the labs, including the last one. In addition, there is an entirely optional Lab 0 that provides an introduction to compiling and running OCaml programs.

The lab exercises are described in Chapters 3, 5, 7 and 9 of the coursebook, with a separate set of instructions for Lab 0. Listings of the chief modules you will need to change are provided in Appendix E of the book.

The lab materials are delivered using an anonymous Mercurial server in a way described in the instructions for Lab 1. You can also browse the materials using the URL http://spivey.oriel.ox.ac.uk/hg/compilers, and there's a cheat sheet listing the commands you'll need to use.

If you're already familiar with Git, then the same materials are accessible as a Git repository at http://spivey.oriel.ox.ac.uk/git/compilers.git. If you're tempted to follow this route, be aware that the lab manual provides help only with Mercurial.

Quick start

Clone the Mercurial repository containing the materials by using the command,

$ hg clone http://spivey.oriel.ox.ac.uk/hg/compilers

This will make a directory called compilers containing all the materials.

Now change to the subdirectory compilers/keiko and build the interpreter for the Keiko machine:

$ (cd compilers/keiko; make)

(The parentheses here make the change of directory local to the command.)

Second, change to the subidrectory compilers/lib and build some utility modules that are common to all our compilers:

$ (cd compilers/lib; make)

Next, you can change to the subdirectory for one of the labs and build the initial version of it:

$ cd compilers/lab1
$ make

Finally, you can run regression tests on the resulting compiler:

$ make test

You'll find the first test gcd.p already passes. But the second test uses features that the lab asks you to implement, so it will fail until you've done the lab exercise. When your work is done, all tests will pass.

Using your own machine

Naturally enough, the computers in the Software Lab have been set up with all the software that is needed to do these exercises. If you want to use your own machine, that is perfectly possible, and another page gives suggestions for setting up the software you need. You will probably wish to do this well before the end of term so that you are set up for the Christmas assignment.

Safety net

Here, for safety's sake, is a tarball containing the same materials: [[[:Template:Resource]]/compilers/compilers.tar.gz compilers.tar.gz]. After downloading it, you can unpack it and create a Mercurial repository with the commands

$ tar xvfz compilers.tar.gz
$ cd compilers
$ hg init
$ hg add .
$ hg ci -m 'Initial revision'