Note: The mercurial server is disabled at the moment while I investigate whether it can run with an acceptably low CPU load – Mike.
Solutions and hints (Compilers)
Jump to navigation
Jump to search
- Solutions for the tutorial problems are given at the end of the collected problem sheets.
- Solutions for the lab exercises.
- Diff listings for the solutions: Lab 1, Lab 2, Lab 3, Lab 4.
What might go wrong?
Some hints about how to deal with error messages that might arise are written in the Lab exercises section of the FAQ page. Some more explicit hints:
- In Lab 1, it's important to keep straight the difference between the number of arms in a
case
statement and the total number of labels. Where several labels are attached to the same arm, these numbers will be different. In theCASEJUMP
instruction that the compiler generates, we need oneCASEARM
item in the list for each label, and the number of items given in theCASEJUMP
instruction itself should agree with this. Getting this wrong would lead to a segmentation fault at runtime or an illegal instruction, but I have added a sanity check to theKeiko
module that outputs code so that the error is caught earlier. - In Lab 2, it's important to get the scaling of subscripts right. Typical errors would include failing to multiply subscripts for an integer array by 4, and later failing to replace the 4 by 1 when subscripting a Boolean array.
- In Lab 3, there's a certain temptation when writing code to follow the static link to write a recursion in OCaml that does not terminate – I think because of an off-by one error. The result of this is a stack overflow in the compiler.
- In Lab 4, the use of the text-to-text preprocessor
nodexp
(which implements the<BINOP, t1, t2>
notation for operator trees) provokes a bug in the OCaml compiler that leads to garbled error messages when it tries to show which source line is at fault. To get round this, there's a wrapper programocamlwrap
(written in TCL, sorry) that is silently invoked from the Makefile. It runs the OCaml compiler in such a way that it doesn't try to show the source line following an error, and then the wrapper steps in and shows the source line itself. All being well, you won't notice this, but participants may become puzzled if the mechanism goes wrong, or if they try to use their own Linux machines without installing TCL.