HP OpenVMS Systems Documentation |
HP Pascal for OpenVMS
|
Previous | Contents | Index |
This chapter describes how HP Pascal passes parameters and calls routines. It discusses the following topics:
Programs compiled by the HP Pascal compiler conform to the OpenVMS calling standard. This standard describes how parameters are passed, how function values are returned, and how routines receive and return control. Because HP Pascal conforms to the calling standard, you can call and pass parameters to routines written in other Hewlett-Packard languages from HP Pascal programs.
Each time a routine is called, the HP Pascal compiler constructs a parameter list.
On OpenVMS I64 systems, the parameters are a sequence of quadword (8-byte) entries. The first 8 integer parameters are located in integer registers designated as R32 to R39; the first 8 floating-point parameters are located in floating-point registers designated as F8 to F15. Information about the parameter list is passed in the argument information register (R25). The first byte of the register specifies the parameter count. Arguments beyond 8 are passed on the stack starting at offset +16.
On OpenVMS Alpha systems, the parameters are a sequence of quadword (8-byte) entries. The first 6 integer parameters are located in integer registers designated as R16 to R21; the first 6 floating-point parameters are located in floating-point registers designated as F16 to F21. Information about the parameter list is passed in the argument information register (R25). The first byte of the register specifies the parameter count. Arguments beyond 6 are passed on the top of the stack.
On OpenVMS VAX systems, the parameters are a sequence of longword (4-byte) entries pointed to by the array pointer (AP). The first byte of the first entry in the list is a parameter count, which indicates how many parameters follow in the list.
The form in which the parameters in the list are represented is
determined by the passing mechanisms you specify in the formal
parameter list and the values you pass in the actual parameter list.
The parameter list contains the actual parameters passed to the routine.
5.1.2 Function Return Values
In HP Pascal, a function returns to the calling block the value that was assigned to its identifier during execution. HP Pascal chooses one of three methods for returning this value. The method chosen depends on the amount of storage required for values of the type returned, as follows:
Note that functions that require the use of an extra parameter can have
no more than 254 parameters; functions that store their results in
registers can have 255 parameters.
5.1.3 Contents of the Call Stack
The OpenVMS I64 and OpenVMS Alpha system conventions define three types of procedures. The calling process does not need to know what type it is calling; the compiler chooses which type to generate based on the requirements of the procedure.
On OpenVMS I64 systems, the types of procedures are:
On OpenVMS I64 systems, the compiler determines the exact contents of the memory stack frame, but all memory stack frames have common characteristics:
On OpenVMS Alpha systems, the types of procedures are:
If a stack frame is required, it consists of a fixed part (which is known at compile time) and an optional variable part.
The compiler determines the exact contents of the stack frame, but all stack frames have common characteristics:
Each time a routine is called by an HP Pascal program on an OpenVMS VAX system, the hardware creates a call frame structure on the call stack. The call frame for each active routine contains the following:
When execution of a routine ceases, the system uses the frame pointer in the call frame of the current routine to locate the frame of the previous routine. The system then removes the call frame of the current routine from the stack.
The frame pointer of calling routines is stored in an implementation-defined register. If, however, you declare a routine with the UNBOUND attribute, the system does not assume that the frame pointer of the calling routine is stored in a register and there is no link between the calling and the called routines. As a result, an unbound routine has the following restrictions:
By default, routines declared at program or module level and all other routines declared with the INITIALIZE, GLOBAL, or EXTERNAL attributes have the characteristics of unbound routines. Routines passed by the immediate value mechanism must be UNBOUND.
Asynchronous system trap routines (ASTs) and RMS completion routines must have both the ASYNCHRONOUS and UNBOUND attributes. Because they are asynchronous, such routines can access only volatile variables, predeclared routines, and other asynchronous routines. Note that the HP Pascal run-time system does not permit a program and an asynchronous routine (such as an AST) to access the same file simultaneously.
Parameter-passing semantics describe how parameters behave when passed between the calling and called routine. HP Pascal passes parameter values by the following methods:
By default, HP Pascal passes arguments using value semantics.
The way in which an argument specifies how the actual data to be passed by the called routine is defined by the parameter-passing mechanism. In compliance with the OpenVMS calling standard, HP Pascal supports the basic parameter-passing mechanisms, shown in Table 5-1.
Mechanism | Description |
---|---|
By immediate value | The argument contains the value of the data item. |
By reference | The argument contains the address of the data to be used by the routine. |
By descriptor | The argument contains the address of a descriptor, which describes type of the data and its location. |
By default, HP Pascal uses the by reference mechanism to pass all actual parameters except those that correspond to conformant parameters and undiscriminated schema parameters, in which case the by descriptor mechanism is used. Table 5-2 describes the syntax you use in HP Pascal to obtain the desired parameter-passing mechanism.
Mechanism | Syntax Used by HP Pascal |
---|---|
By immediate value | %IMMED or [IMMEDIATE] |
By reference | Default for nonconformant and nonschema parameters or %REF |
By descriptor | Default for conformant and schema parameters or %DESCR, %STDESCR, [CLASS_S],[CLASS_A], or [CLASS_NCA] |
A mechanism specifier usually appears before the name of a formal parameter, or if a passing attribute is used it appears in the attribute list of the formal parameter. However, in HP Pascal, a mechanism specifier can also appear before the name of an actual parameter. In the latter case, the specifier overrides the type, passing semantics, passing mechanism, and the number of formal parameters specified in the formal parameter declaration.
The by immediate value passing mechanism passes a copy of a value instead of the address. HP Pascal provides the %IMMED foreign passing mechanism and the IMMEDIATE attribute in order to pass a parameter by immediate value. You cannot use variable semantics with the by immediate value passing mechanism.
On OpenVMS I64 and OpenVMS Alpha systems, values that are less than or equal to 64 bits in size can be passed by immediate value.
On OpenVMS VAX systems, values that are less than or equal to 32 bits
in size can be passed by immediate value.
5.3.2 By Reference
The by reference mechanism passes the address of the parameter to the called routine. This is the default parameter-passing mechanism for non-conformant and non-schematic parameters.
When using the by reference mechanism, the type of passing semantics used depends on the use of the VAR keyword. If the formal parameter name is preceded by the reserved word VAR, variable semantics is used; otherwise, value semantics is used.
In addition to using the defaults, the HP Pascal compiler provides
the %REF foreign passing mechanism and the REFERENCE attribute, which
has more than one interpretation for the passing semantics depending on
the data item represented by the actual parameter. This allows you to
have the called routine use either variable semantics or true foreign
semantics. The mechanism specifier appears before the name of a formal
parameter. The parameter passing attribute appears in the attribute
list of the formal parameter.
5.3.3 By Descriptor
There are several types of descriptors. Each descriptor contains a value that identifies the descriptor's type. The called routine then uses the information held in the descriptor to identify its type and size. This is the default parameter-passing mechanism for conformant and schematic parameters.
When you use one of the HP Pascal by descriptor mechanisms, the compiler passes the address of a string, array, or scalar descriptor. The HP Pascal compiler generates the descriptor supplying the necessary information.
HP Pascal provides three attributes for the by descriptor passing mechanism: [CLASS_S], [CLASS_A], and [CLASS_NCA]. With these three attributes, the type of passing semantics used for the by descriptor argument depends on the use of the VAR keyword. If the formal parameter name is preceded by the reserved word VAR, variable semantics is used; otherwise, value semantics is used. The parameter-passing attribute appears in the attribute list of the formal parameters.
Sometimes you may want to choose either variable semantics or true foreign semantics. In these cases, the HP Pascal compiler provides two foreign passing mechanism specifiers, %DESCR and %STDESCR. These specifiers have more than one interpretation for the passing semantics depending on the data type of the actual parameter. The mechanism specifier appears before the name of a formal parameter.
Table 5-3 lists the class and type of descriptor generated for parameters that can be passed using the by descriptor mechanism.
Parameter Type | Descriptor Class and Type | ||
---|---|---|---|
%DESCR | %STDESCR | Value or VAR Semantics | |
Ordinal | DSC$K_CLASS_S 1 | --- | --- |
SINGLE |
DSC$K_CLASS_S,
DSC$K_DTYPE_F, DSC$K_DTYPE_FS |
--- | --- |
DOUBLE |
DSC$K_CLASS_S,
DSC$K_DTYPE_D, DSC$K_DTYPE_G, DSC$K_DTYPE_FT |
--- | --- |
QUADRUPLE |
DSC$K_CLASS_S
DSC$K_DTYPE_H/_FX 6 |
--- | --- |
RECORD | --- | --- | --- |
ARRAY | DSC$K_CLASS_A/_NCA 2,5 |
DSC$K_CLASS_S
DSC$K_DTYPE_T 3 |
--- |
ARRAY OF
VARYING OF CHAR |
DSC$K_CLASS_VSA
DSC$K_DTYPE_VT |
--- | --- |
Conformant
ARRAY |
DSC$K_CLASS_A/_NCA 2,5 |
DSC$K_CLASS_S
DSC$K_DTYPE_T 3 |
DSC$K_CLASS_A/_NCA 2,5 |
Conformant
ARRAY OF VARYING OF CHAR 4 |
DSC$K_CLASS_VSA
DSC$K_DTYPE_VT |
--- |
DSC$K_CLASS_VSA
DSC$K_DTYPE_VT |
VARYING OF
CHAR |
DSC$K_CLASS_VS
DSC$K_DTYPE_VT |
--- | --- |
Conformant
VARYING OF CHAR |
DSC$K_CLASS_VS
DSC$K_DTYPE_VT |
--- |
DSC$K_CLASS_VS
DSC$K_DTYPE_VT |
STRING | --- | --- |
DSC$K_CLASS_VS
DSC$K_DTYPE_VT |
Schema
name |
--- | --- | Internal HP Pascal descriptor |
Discriminated
schema |
--- | --- | --- |
SET |
DSC$K_CLASS_S
DSC$K_DTYPE_Z |
--- | --- |
FILE |
DSC$K_CLASS_S
DSC$K_DTYPE_Z |
--- | |
Pointer |
DSC$K_CLASS_S
DSC$K_DTYPE_LU |
--- | --- |
PROCEDURE or
FUNCTION |
DSC$K_CLASS_S
DSC$K_DTYPE_BPV |
--- |
Bound procedure
value by reference |
CLASS_A | CLASS_NCA | CLASS_S | |
Ordinal | --- | --- | DSC$K_CLASS_S 1 |
SINGLE | --- | --- |
DSC$K_CLASS_S,
DSC$K_DTYPE_F, DSC$K_DTYPE_FS |
DOUBLE | --- | --- |
DSC$K_CLASS_S,
DSC$K_DTYPE_D, DSC$K_DTYPE_G, DSC$K_DTYPE_FT |
QUADRUPLE | --- | --- |
DSC$K_CLASS_S
DSC$K_DTYPE_H/_FX 6 |
RECORD | --- | --- | --- |
ARRAY | DSC$K_CLASS_A 2 | DSC$K_CLASS_NCA 2 |
DSC$K_CLASS_S
DSC$K_DTYPE_T 3 |
ARRAY OF
VARYING OF CHAR |
--- | --- | --- |
Conformant
ARRAY |
DSC$K_CLASS_A 2 | DSC$K_CLASS_NCA 2 |
DSC$K_CLASS_S
DSC$K_DTYPE_T 3 |
Conformant
ARRAY OF VARYING OF CHAR 4 |
--- | --- | --- |
VARYING OF
CHAR |
--- | --- | --- |
Conformant
VARYING OF CHAR |
--- | --- | --- |
STRING | --- | --- | --- |
Schema
name |
--- | --- | --- |
Discriminated
schema |
--- | --- | --- |
SET | --- | --- |
DSC$K_CLASS_S
DSC$K_DTYPE_Z |
FILE | --- | --- |
DSC$K_CLASS_S
DSC$K_DTYPE_Z |
Pointer | --- | --- |
DSC$K_CLASS_S
DSC$K_DTYPE_LU |
PROCEDURE or
FUNCTION |
--- | --- | --- |
Previous | Next | Contents | Index |