Contents | Prev | Next | Index


Access from Java Programs

All Java classes and its members, as generated by Pascal, can be imported and accessed by third party Java software as long as they stick to the naming conventions and parameter passing rules which are described below.

A Canterbury Pascal program or unit is compiled into a single Java source file which contains a single class of the same name. All record or class types declared in the Pascal program or unit are mapped to separate Java source files, each one containing a corresponding Java class of the name <program-name>_<class-name>.

Example: Given the Pascal unit

program Example;
  ....
type MYREC = record .... end;
  ....
end.

the Pascal compiler generates the following 2 files:

  1. Example.java 
  2. Example_MYREC.java

Pascal procedures are mapped to corresponding class methods in the Java output class. Canterbury Pascal supports class definitions with field and method members similar to Borland Object Pascal. If a Pascal method is declared with the VIRTUAL or OVERRIDE keyword then it is mapped to a normal virtual Java method of the same name. If the Pascal method is declared with the CLASS keyword then it is mapped to a Java static method of the same name. Otherwise, if it is a static Pascal method (the default) then it is mapped to a virtual Java method, but its name is changed to the unique identifier <class-name>_<method-name>, e.g. a method called 'Foo' in class 'AnyClass' becomes a Java method of the name 'AnyClass_Foo'.

Value parameters for procedures and methods are directly mapped to Java's value parameters using the corresponding Java types. If they are of structured types then the called method creates local copies. Variable parameters which are structured are mapped to Java reference parameters. Unstructured variable parameters are always wrapped in special Java classes which are then passed by reference. The name of these special wrapper classes is an identifier of the form SYSTEM_P<Unstructured-type-id>. Such a wrapper class has exactly one field with the name val and of the same unstructured type. And it has one constructor accepting a value parameter of the same unstructured type. For example, in order to pass a Java value xval of type double to a Pascal procedure whose formal type is declared as a VAR-parameter, the following Java code is required: 

double xval = 3.1415;
SYSTEM_PDOUBLE px = new SYSTEM_PDOUBLE(xval);
<pascal-unit-id>.<pascal-proc-id>( px );
xval = px.val;

The following 2 tables list all value and variable parameter types for Pascal and their corresponding Java equivalents:

 
Pascal value parameter
Java parameter
CHAR char
BOOLEAN boolean
SHORTINT byte
BYTE byte
SMALLINT short
WORD short
LONGINT int
LONGWORD int
INTEGER int
CARDINAL int
SYSTEM.HUGEINT long
SINGLE float
DOUBLE double
<enumeration-type-id> int
POINTER java.lang.Object
STRING java.lang.StringBuffer
<record-type-id> <record-type-id>
<class-type-id> <unit-id>_<class-type-id>
<array-type-id> <element-type-id>[]<...>[]
<set-type-id> byte[]
<pointer-type-id> pointee <record-type-id> or <element-type-id>[]<...>[]

 

Pascal variable parameter
Java parameter
CHAR SYSTEM_PCHAR
BOOLEAN SYSTEM_PBOOLEAN
SHORTINT SYSTEM_PSHORTINT
BYTE SYSTEM_PBYTE
SMALLINT SYSTEM_PSMALLINT
WORD SYSTEM_PWORD
LONGINT SYSTEM_PLONGINT
LONGWORD SYSTEM_PLONGWORD
INTEGER SYSTEM_PLONGINT
CARDINAL SYSTEM_PLONGWORD
SYSTEM.HUGEINT SYSTEM_PHUGEINT
SINGLE SYSTEM_PSINGLE
DOUBLE SYSTEM_PDOUBLE
<enumeration-type-id> SYSTEM_PLONGINT
POINTER SYSTEM_PPOINTER
STRING java.lang.StringBuffer
<record-type-id> <record-type-id>
<class-type-id> <unit-id>_<class-type-id>
<array-type-id> <element-type>[]<...>[]
<set-type-id> byte[]
<pointer-type-id> SYSTEM_PPOINTER
untyped java.lang.Object


Contents | Prev | Next | Index

Canterbury Pascal for Java  (Last documentation update Apr 19, 2000)
Copyright © 1998 Mill Hill & Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to mhc@webcom.com