Extending the TypeSystem
---------------------------
This document describes what is involved in writing an extension that modifies the behavior of the TypeSystem.
The TypeSystem of the polyglot compiler is structured so that all requests for type verification and name resolution are handled via the TypeSystem interface. The StandardTypeSystem implementation corresponds to an implementation that is intended to model Sun's behavior of typing rules as goverened by Java 1.2.
Extensions would modify the TypeSystem behavior for the following typical reasons:

- The extension would like to Modify the typing rules for java.
- The extension would like to include support for additional AST nodes. This may or may not necessitate modifying the TypeSystem. In general, modifications to PrimitiveType, or the addition of a new class type family that descends from Type (e.g., the addition of a FirstClassFunction type) requries changes to the StandardTypeSystem.

The first thing to note about TypeSystem extensions is that there can only be one TypeSystem in the compiler at any one time. This is because each Type has a pointer to the TypeSystem that it was instantiated under and also has methods to dispatch to the TypeSystem. Thus, with two different TypeSystems, one could get differing results from TypeSystem calls depending upon which Type the method call is made. There are no rules to govern how multiple TypeSystems interact, and because of this, we cannot have multiple TypeSystem implemenations during a particular compile.
The easiest way to modify the TypeSystem behavior is to extend the StandardTypeSystem and override the necessary methods to obtain the desired behavior. Then, you must instruct the TypeSystem to use the new implemention whenever the extension is used.
The TypeSystem is instantiated in polyglot.main.Main and then passed to polyglot.frontend.Compiler. So, to instantiate a Compiler with the new extension, Main.java must be instructed to create the new TypeSystem whenever using this Compiler modification. Currently the only way to do this is by editing Main.java. However, there was an initiative to create a standard modification description file that is required of any valid Compiler modification: ExtensionInfo.java. This file would have resided in the root of the extension's hierarchy and given instructions to polyglot.main.Main and
polyglot.frontend.Compiler to properly "install" the modifications. Then, the Compiler is notified of the new extension by passing the fully qualified package name of the new extension; the extension reads the ExtensionInfo file, and proceeds. Under this scenario, there is no need to modifyjltools.main.Main to instruct it of a new extension. Unfortunately, this cleaner solution is not yet available.