Conclusions


For the most part, the objectives of the Component Pascal project were well realized. The compiler, except for the small issues discussed earlier, implements the language accurately and produces good-quality, verifiable code. The compiler is written in Component Pascal and compiles itself successfully. It started off as about 20,000 lines of code in its initial form, but has been steadily growing as more special-case code is added to improve code quality. There are a number of utilities and other tools that are distributed with the compiler.

Compatibility Extensions

As hinted at the beginning of the appendix, some optional language extensions were added to Component Pascal to allow full access to the facilities of the base class libraries. The most important of these is the facility to declare that record types implement defined interfaces. There is also a limited level of access to the exception-handling facilities of the runtime environment. This last enhancement is almost a necessity, as many library methods signal failure by throwing an exception that the caller is expected to catch.

For example, we might wish to declare that the Circle type not only extends the abstract base type Figure but also implements an interface type ClosedFig . This interface might offer a method getArea that other extensions of Figure , such as Parabola , do not possess. The extended syntax is given in Listing E.3.

Listing E.3
 type         Circle = record (Figure + ClosedFig)                          x, y, radius : REAL;                  end; 

Of course, it is insufficient to simply introduce new syntactic mechanisms unless the compiler enforces the semantics that come as part of the package. In this case, the compiler allows programs to contract to provide certain implementation features that are not normally part of Component Pascal programs. The compiler must enforce such contracts by, for example, rejecting the program in Listing E.3 if it does not define an acceptable getArea function bound to the Circle type.

Another necessity to facilitate use of the base class libraries is some way of invoking constructors with arguments. Component Pascal itself has only the "no-arg" constructors that are implicitly invoked by Component Pascal's new() function. In Component Pascal one typically first creates the object and then sets any fields, as required. However, this is impossible for some library classes, as certain fields of the object may be marked initonly and can be set only by the constructor. The solution in this case is for the program to access the constructor as though it were a value-returning object factory function. Of course, the compiler knows from the metadata that the call is actually to a constructor and is, therefore, able to generate correct code.

A final, and somewhat controversial, extension was to enhance the symbol table mechanisms of the language to allow access to name -overloaded methods from the libraries. This extension is controversial because Component Pascal does not allow method overloading, and it may be argued that programmers accessing overloaded methods from within a non-overloaded language may be more prone to making errors. On balance, it was decided that this language extension was less problematic than the alternative of defining tables of name translations.

All of these language extensions are optional. The compiler may be run so as to recognize the standard language, or it may be run so as to allow the compatibility extensions described here.

As well as being useful as a production compiler, the Component Pascal compiler is used as a vehicle for research on language implementation. There are ongoing projects that use the compiler for research in the implementation of generics ( parametric polymorphism ) and use the metadata facilities in unusual ways.

Performance

The quality of the code produced by the Component Pascal compiler is comparable to that from Microsoft's C# compiler. It even outperforms C# in one special case: At the time of writing, the Component Pascal compiler's implementation of multidimensional arrays outperforms the library-based multidimensional code used by C#. Unfortunately, future versions of C# will undoubtedly reverse the situation by inlining the library code.

In both cases, because of the great (and improving) technology of the just-in-time compilers, the final code quality is often very close to that of the best native-code compilers.

Notes

The wider issues of mapping particular programming language constructs to the CLR are dealt with in the book Compiling for the .NET CommonzLanguage Runtime by John Gough (Prentice-Hall, 2002). The figures in this appendix are reprinted, with permission, from that book.

As noted, Gardens Point Component Pascal is an open source compiler. Various distributions of the compiler, including all the source code, are available from http://www.plasrc.qut.edu.au/ComponentPascal.

The official definition of the Component Pascal language may be obtained from Oberon Microsystems at the URL http://www.oberon.ch/resources. This site also has some interesting discussion papers regarding the design of the language.



Programming in the .NET Environment
Programming in the .NET Environment
ISBN: 0201770180
EAN: 2147483647
Year: 2002
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net