Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pascal Runtime Library

Similar presentations


Presentation on theme: "Pascal Runtime Library"— Presentation transcript:

1 Pascal Runtime Library
By Ren Wan and Kevin Masterson

2 What is the Runtime Library (RTL)?
Source of the RTL Compiling the RTL How do you use the RTL? From Jasmin code Assemble Jasmin source Into JVM .class file Run the program Finally!

3 What is the Runtime Library?
Classes that a Pascal source program compiled by our compiler will need in order to execute at runtime. Helper functions/classes too complicated to write out in Jasmin source file (.j).

4 Source of the RTL PascalRuntimeException RangeChecker PaddedString
IWrap, RWrap, CWrap, BWrap Cloner RunTimer PascalTextIn

5 PascalRuntimeException

6 RangeChecker

7 PaddedString Pascal strings are arrays of fixed size
Java strings are dynamically-sized

8 IWrap, RWrap, CWrap, BWrap
In Java, all parameters are passed by value For a structured parameter (objects and arrays), Java passes the address of the object by value Passing a structured parameter can be used to simulate Pascal’s VAR parameter keyword Wrap each intrinsic Java type into an object which holds the value when passing to a function by reference (VAR) Need a different wrapper for each intrinsic Java type (int, float, char, and boolean)

9 IWrap

10 RWrap

11 CWrap

12 BWrap

13 Cloner Since Java passes the address of a structured parameter object by value, changes to the object are visible in the calling function (same reason we use the previous wrapper classes) If we need to pass a Pascal parameter by value (where the type is structured, like arrays and strings), we want to make sure the function can’t change the object. Make a copy of the object before passing

14 Cloner

15 RunTimer

16 PascalTextIn Handles input of text in types which Pascal’s read()/readln() functions use. Integer Real Boolean Character Uses PascalScanner class and Source class from compiler frontend Same syntax for Pascal source and Pascal runtime input

17 PascalTextIn

18 PascalTextIn readInteger

19 PascalTextIn readReal

20 PascalTextIn readBoolean

21 PascalTextIn readChar

22 PascalTextIn

23 PascalTextIn

24 PascalTextIn

25 Compiling the RTL Create .jar file with all the compiled runtime .class files jar -cvf <jarfile.jar> <files to put inside> Be sure to include all files required for PascalScanner, including Token and Message classes

26 The Command jar -cvf PascalRTL.jar *Wrap.class Cloner.class PaddedString.class PascalRuntimeException.class PascalTextIn.class RangeChecker.class RunTimer.class wci/frontend/EofToken.class wci/frontend/Scanner.class wci/frontend/Source.class wci/frontend/Token.class wci/frontend/TokenType.class wci/frontend/pascal/PascalScanner.class wci/frontend/pascal/PascalToken.class wci/frontend/pascal/PascalTokenType.class wci/frontend/pascal/tokens/*.class wci/message/*.class

27 How Do You Use the RTL? Once the RTL is loaded into the JVM, its features are accessed just like any other class/object in Jasmin

28 RangeChecker

29 PaddedString

30 *Wrap Inside Function

31 *Wrap At Call-site

32 Cloner

33 PascalTextIn

34 Assemble Jasmin Source
Jasmin is available as an executable Java .jar file To run an executable .jar file, java -jar <jar file> <args to main()> To run Jasmin to compile a .j file, java -jar jasmin.jar range1.j Compiled .class file is created in same folder as the Jasmin .j source file range1.class in same folder as range1.j

35 Run the Program Two components to include when running
Runtime Library (PascalRTL.jar) Compiled Pascal file (range1.class) To include the contents of a .jar file when running Java code, java -classpath .;<.jar file> <.class files> Our example: java -classpath .;PascalRTL.jar range1.class

36 Pascal Runtime Library
Ren Wan Kevin Masterson


Download ppt "Pascal Runtime Library"

Similar presentations


Ads by Google