Compiling

This section describes some of the issues you will need to consider when compiling:

Compiling Procedures and Functions

System Limits

Using the ..LOCALS Compiler Directive

Compiling Procedures and Functions

There are three ways procedures and functions can be compiled:

Using .RUN with a Filename

Compiling Automatically

Compiling with Interactive Mode

Using .RUN with a Filename

Procedures and functions can be compiled using the executive command .RUN. The format of this command is:

.RUN file1, file2, ..., file11

From one to eleven files, each containing one or more program units, can be compiled with the .RUN command. Consult the (Undefined variable: pvwave.waveur) for more information on the .RUN command.

Compiling Automatically

Generally, however, you create a procedure or function file with a filename that matches the actual procedure or function name. When a program unit is compiled, PV-WAVE saves the results, which are in the PATH of the compiled code in PV-WAVE’s memory. This eliminates the need to recompile each time the program unit is called.. The procedure or function automatically compiles when first called. For example, a function named CUBE which calculates the cube of a number has the file name cube.pro. The file looks like this:

FUNCTION CUBE, NUMBER
RETURN, NUMBER ^ 3
END

When the function is initially used within a PV‑WAVE session the file is compiled. A compilation message displays on the screen. For example, using the function for the first time at the WAVE> prompt results in:

WAVE> z = cube(4) & print, z
% Compiled module: CUBE
64

If you change the source file of a routine that is compiled and saved in memory, then you have to explicitly recompile it with .RUN or .RNEW.

Compiling with Interactive Mode

You can enter the procedure or function text directly at the keyboard using .RUN. Rather than executing statements immediately after they are entered, PV‑WAVE compiles the program unit as a whole.

Procedure and function definition statements cannot be entered in single statement mode but must be prefaced by either .RUN or .RNEW.

The first non-empty line the compiler reads determines the type of the program unit: procedure, function, or main program. If the first non-empty line is not a procedure or function definition, the program unit is assumed to be a main program.

The name of the procedure or function is given by the identifier following the keyword Pro or Function. If a program unit with the same name is already compiled, it is replaced by the newer program unit.

Note Regarding Functions

User-defined functions must be compiled using the .RUN command before the first reference to the function is made. There only exception is:

As discussed previously in Compiling Automatically, if the filename is the same as the function name and is located in the current working directory or in !Path, the file, and every procedure and function in the file automatically compiles.

Otherwise the function must be compiled using .RUN because the compiler is unable to distinguish between a reference to a subscripted variable and a call to a presently undefined user function with the same name. For example, in the statement:

A = XYZ(5)

it is impossible for PV-WAVE to tell if XYZ is an array or a function by context alone.

Always compile, or arrange in the .pro file, the lowest-level (those that call no other functions) first, then higher-level functions, and finally procedures. PV‑WAVE searches the current directory and then the !Path for function definitions when encountering references that may either be a function call or a subscripted variable.

System Limits

When a program is compiled (using .RUN, for example) internal instruction codes are stored in the code area, and symbols for variables, common blocks, and keywords are strored in the data area. If these areas become full, the compile is halted, and you will see one of the following messages:

Program code area full.
Program data area full.

Methods of handling these errors are discussed in the following sections.

Program Code Area Full

This indicates that the code area (a block of memory allocated for use by the compiler to store instruction codes) has been exceeded. As a result, the compile cannot be completed. The method used to correct this condition depends on the type of program you are compiling.