Appendix E. Component Pascal on the CLR


John Gough

Appendix E credit: KJ Gough 2002.

This appendix deals with another of the Project~7 languages, Component Pascal, which we sometimes abbreviate as just CP. The resulting compiler is named Gardens Point Component Pascal and is available under an open source license. [1]

[1] The Gardens Point compilers are named in honor of the scenic spot on the Brisbane River where the Queensland University of Technology is located.

Unlike some other language projects, it was an explicit objective from the beginning that the compiler should implement the whole of the language with exact semantics, or as close to the exact semantics as the CLR permitted. Thus, it was not an option to "leave out" inconvenient parts of the language that did not map easily to the underlying primitives of the CLR. Neither was it an option to gratuitously make additions to the language simply on the basis that the CLR facilitated such constructs. It was intended that the project should be a significant test of the ability of the runtime to provide for languages with somewhat different features from Microsoft's own languages.

A fundamental decision that must be made for every new language on the CLI is whether to produce verifiable code. Languages whose definitions do not enforce a high level of type safety must either produce unverifiable code or enforce conformance to a type-safe subset of the language. Component Pascal is a type-safe language, and the choice was made to produce 100% verifiable code. The advantage of producing verifiable code is that users of such code enjoy stronger guarantees from harmful behavior. This may be a critical issue in applet-like scenarios.

The architecture of the compiler is conventional (Figure E.1). A scanner and parser build an abstract syntax tree for the whole compilation unit, and semantic checking is performed during attribution of this tree. Finally, a tree-walker writes a file containing the textual form of the Common Intermediate Language ( CIL ). The IL assembler ilasm is invoked to transform this file into a program executable file. As usual, the CIL form of the program is finally executed after being transformed by a just-in-time compiler at program load time.

Figure E.1. Architecture of the Gardens Point Component Pascal compiler

graphics/efig01.gif

As it turned out, it was possible to map the whole of the language to the CLR without compromising the exactness of the semantics, except in some minor points that are discussed later in this appendix. The final product does provide for some optional language extensions. These are included simply to allow components created using Component Pascal to interact more effectively with other components conforming to the Common Language Specification. The extensions include the implementation of interface types and some primitive support for structured exception handling.

This appendix discusses the issues involved in implementing a language such as Component Pascal on the CLR. This is not a trivial problem. Although the CLR was explicitly designed to support a wide range of languages, it was nevertheless necessary to implement a single object model that would suit most languages. Furthermore, the objective of producing verifiable code disallows certain tricks that would otherwise be available.



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