CS 3520 Homework 10   - Due November 27

Start with this code. Turn in a single interpreter/compiler with all of the revisions requested below.

Exercise 10.1, Lexical addresses

The initial translation-of-expression converts send expressions to use a method index, and removes unnecessary cast expressions.

It does not translate identifiers to lexical indices, even through the language grammar and interpreter have been extended already with a lexvar form.

Modify translation-of-expression so that it converts any variable expression to an equivalent lexvar expression. You may need to extend the implementation of type environments.

You can test your change using run-time-tests, which runs list-program with and without translation. (The results should be the same!)

Exercise 10.2, Object creation

The given interpreter implements new by finding the instanitated class in a run-time class environment, then extracting the class's field count.

Add an object-creation form to the language that contains directly the number of fields in the class, so the interpreter need not find the class at run time.

Implement the added form in eval-expression.

Change translation-of-expression so that it translates new expressions to the added form.

Exercise 10.3, Finding Initialize

Although the initial translator converts send expressions to use a method index, the implementation of new still finds initialize by name at run time.

Modify your object-creation form from 11.2 so that it also contains a method index for initialize.

Modify the implementation of the form in eval-expression to use the index.

Exercise 10.4, Finding Classes

Although methods are found by index, the translations of both new and send still find class information by name in the run-time class environment. Partly, this is because object records contain class names.

Modify the implementation of the static class environment so that it can find an index for a class name.

Modify the implementation of the run-time class environment so that it can find a class record by index.

Modify the object record so that it contains a class index as well as a class name.

Modify the new form that uses method indices so that it contains a class index as well as a class name.

Exercise 10.5, Super Calls

The super form uses the environment to find the identity of the superclass at run time (via %super), but the superclass is actually known statically.

Add a super-call form to the language that contains the class index and method index for the target of the super call.

Implement the added form in eval-expression.

Change translation-of-expression so that it translates super expressions to the added form.

Exercise 10.6, Extra Transformations (Optional)

Invent and implement other meaning-preserving transformations for extra credit. Transformations that speed up a large class of useful programs will receive the most credit.

When implementing extra transformations, supply a function named extra-credit that takes no arguments and returns a string. The string should provide a brief description of your extra transformations, which will help the graders identify the potential for extra credit.


Last update: Tuesday, November 13th, 2001
mflatt@cs.utah.edu