Java programs are compiled to Java class files. These class files are system independent files that can be run on a Java Virtual Machine (JVM). If it would be possible to compile other programming languages to Java class files it would provide us with a way to test the security of the JVM and a way to make programs written in this language system independent.
This document describes an attempt to compile programs written in the Pascal programming language to Java class files. It describes how various elements of Pascal can be compiled to Java bytecode. After reading this you should have an idea about how to compile and how not to compile Pascal programs to Java class files.
This document is divided into two parts: Part I describes the JVM and part II describes the actual project and contains chapters describing how I compiled Pascal programs to Java class files.
Part I contains chapters 2 to 5. The Java Virtual Machine's types and runtime data areas are described in chapter 2. Chapter 3 describes the Java class file format. Chapter 4 gives an overview of the JVM instruction set. Chapter 5 describes how field and method descriptors are structured.
Part II contains chapters 6 to 12. Chapter 6 describes the goal of the project and gives an overview of the problems faced during the project and their solutions. Chapter 7 describes how I decided to store the class file in the compiler. How to compile an empty Pascal program is described in chapter 8. In chapter 9 is described how to compile variable and constant declarations and procedure declarations. How statements are compiled is described in chapter 10. Chapter 11 describes how to compile some of the main elements of Pascal I did not implement in the compiler. Chapter 12 contains some final remarks.
Finally, appendix A shows an example Pascal program that is compiled by the compiler and the class file it is compiled into.
Most of the specifics of the Java Virtual Machine described in this document can be found in [JVM].