Homework # 9
due Tuesday, April 13, 4:00 PM

Book Exercises

Please complete Exercise 4 (page 357), all 18 pieces, and Exercise 6 (page 384).

Simulating Parameter Passing Modes

We can simulate parameter passing by keeping track of the caller activation frame. For this part of the Homework, you will simulate parameter passing to a simple function:


void test(Node n, int val) {
  n = n.next;
  val = val + 10;
}
You will use an interface Parameter which has methods to ``get'' and ``set'' the parameter as well as a method to ``complete'' the parameter by performing any copy-back operation (for example, for value-result parameters).

The test case, will set up a simple situation, create instances of the interface (see below) and then call the function which simulates the above function (using ``set'' and ``get'' calls). We provide the harness, all you need to do is implement the exception class and each of the following cases:

0
call-by-value
1
call-by-value-result in which the result lvalue is determined at the time of the call. (This test case is implemented for you.)
2
call-by-value-result in which the result lvalue is computed after the call, at the point where the result is assigned.
3
call-by-reference (lvalues computed at time of call);
4
call-by-name
5
call-by-value with no assignment permitted (Ada's ``in'' mode for scalars).
6
call-by-result with no ability to read (Ada's ``out'' mode for scalars).
Normally, one cannot make an instance of an interface or an abstract class, but if any missing implementations are provided at the creation point, one can do so. A further advantage is that the bodies of the new methods may access ``final'' variables in scope. See the partial implementation provided in ParameterTest.java in the src/homework9 directory. This directory also has files for each of the following classes:
Parameter
The interface for parameter simulation.
AbstractParameter
An abstract class with help for printing parameters.
MyFrame
A simple structure defining the frame of the caller. All it has is the binding for the local variable node.
Node
A simple linked list node structure.
The output of running the test (test.out) is also provided.

Submitting Your Work

You submit your program work by putting it in the homework9 directory in your AFS class volume. You may do all your work in this directory, or you may wish to do your work in a different directory and copy things when correct into this directory. In any case, you will lose permission to write things in this directory after the deadline, which is 4:00pm on Tuesday, April 13th. In other words, you must be done before lecture starts.

The homework9 directory should include the following:

We expect you will have the other files of the assignment as well (unchanged).


About this document



John Tang Boyland
2004-04-06