• No results found

The CALL Statement.

In document hal s language specification pdf (Page 106-110)

DECLARE X ARRAY(2,3) SCALAR;

SUBBIT 33 TO 64 (P) bits 33 through 64 of the machine representation of P look like a 32-bit variable

7.4 The CALL Statement.

The CALL statement is used to invoke execution of a procedure. The PROCEDURE block may be in the same <compilation> as the CALL statement or external to it.

SYNTAX:

Figure 7-4 CALL statement - #47 SEMANTIC RULES:

1. CALL <label> invokes execution of a procedure with name <label>.

2. If a <procedure block> with name <label> appears in such a name scope that <label> is known to the CALL statement, then CALL <label> invokes that block.

3. If a <procedure block> is declared inside a DO…END group, it may only be invoked by a CALL statement contained in the same DO…END group.

4. If no such <procedure block> exists, then the <procedure block> is assumed to be external to the <compilation> containing the CALL statement. A <procedure

template> for that <procedure block> must therefore be present in the <compilation> (see Section 3.6).

5. Each of the <expression>s is an “input argument” of the procedure call.

6. Each of the <variable>s is an “assign argument” of the procedure call. Only assign arguments may have their values changed by the procedure. If <variable> is subscripted, it must be restricted in form to the following:

• No component subscripting for bit and character types.

• If component subscripting is present, <variable> must be subscripted so as to yield a single (unarrayed) element of the <variable>.

• If no component subscripting is present, but array subscripting is, then all arrayness must be subscripted away.

basic statement : label CALL 47 ) ; , example:

CALL EPSILON (A * B) ASSIGN (C); label ( , 23 expression ASSIGN ( variable ) 20

7. Assign arguments are “call-by-reference”. Input arguments are either “call-by- reference” or “call-by-value”11.

8. Each assign argument must match its corresponding procedure block assign parameter exactly in type, precision, dimension, arrayness, structure tree

organization, and REMOTE12 attribute, as applicable. CHARACTER lengths are an exception; they must be declared CHARACTER(*). The reason is that character types are of varying length and the actual length is available at execution. If an assignment argument has the LOCK attribute, then the following must apply:

• If it is of lock group N, then the corresponding assign parameter must be of lock group N, or *.

• If it is of lock group *, then the corresponding parameter must also be of group *. 9. Bit type identifiers (non-NAME, non-arrayed) may not be used as assign arguments of

a CALL statement when they are part of structure variables and have DENSE attributes. All other types of structure terminals with the DENSE attribute may be used as ASSIGN arguments. See Sections 4.3 and 4.5 for further explanation of the DENSE attribute. Note, however, that an entire structure with the DENSE attribute may be passed provided that template matching rules are observed.

10. For input arguments, the following relaxation of rules 8 and 9 are permitted: • precisions need not match;

• lengths of bit arguments need not match (If the input parameter is not the same length as the input argument, the latter is left truncated or left padded with binary zeros as necessary. Length mismatch is not allowed for arrayed bit parameters.); • CHARACTER arguments must be declared CHARACTER(*);

• implicit integer to scalar and scalar to integer conversions are allowed;

• implicit integer and scalar to character conversions are allowed (This conversion is not allowed for arrayed CHARACTER parameters.);

• matching of the attributes DENSE and REMOTE is not required. (The REMOTE keyword is ignored on non-NAME input parameters.) Input arguments may be viewed as being assigned to their respective input parameters on invocation of the procedure. The rules applicable in the above relaxations thus parallel the relevant assignment rules given in Section 7.3.

11. If an assign argument is a structure terminal or a minor structure node (but not if it is a major structure) and if the structure possesses multiple copies, then the number of copies must be reduced to one by subscripting.

11. In this context “call-by-reference” means the arguments are pointed to directly. “Call-by-value” means the value of an input argument, at the invocation of a procedure, is made available to the procedure.

Figure 7-5 CALL ASSIGN Example 7.5 The RETURN Statement.

The RETURN statement is used to cause return of execution from a TASK, PROGRAM, PROCEDURE, or FUNCTION block. In the case of the FUNCTION block it also

specifies an expression whose value is to be returned. SYNTAX:

Figure 7-6 RETURN statement - #48 GENERAL SEMANTIC RULES:

1. The effect of the RETURN statement is to cause normal exit (return of execution) from a TASK, PROGRAM, PROCEDURE, or FUNCTION block (also see the CLOSE statement, Section 3.7.4).

2. <expression> may only appear in a RETURN statement of a <function>. Its value is the returned value of the function, and is evaluated prior to returning.

Example: STRUCTURE Z: 1 A, 2 C CHARACTER(80), 2 B VECTOR, 1 D INTEGER; DECLARE ZZ Z-STRUCTURE(20); . . . .

CALL X ASSIGN (ZZ, ZZ.A, ZZ.A.B, ZZ.A1)

↑ ↑

legal illegal legal

basic statement expression : 48

example: DONE: RETURN ZETA; ; RETURN

3. <expression> must match the function definition in type and dimension, with the following exceptions:

• the lengths of bit expressions need not match;

• the lengths of character expressions need not match;

• implicit integer to scalar and scalar to integer conversions are allowed; • implicit integer and scalar to character conversions are allowed.

The return of the function values may be viewed as the assignment of the <expres- sion> to the function name. The rules applicable in the above exceptions thus paral- lel the relevant assignment rules given in Section 7.3.

4. <expression> must always appear in RETURN statements of <function block>s. Execution must always end on logically reaching a RETURN statement of such a block, and not by logically reaching the delimiting CLOSE statement.

In document hal s language specification pdf (Page 106-110)