• Keine Ergebnisse gefunden

SOURCE FILE CONTROL

Im Dokument Pascal Reference (Seite 172-188)

IF I 0 THEN BEGIN

SOURCE FILE CONTROL

A small group of metacommands provide some measure of control over the use of the source file during compilation. These commands are listed in Table 17-5 and described in more detail below.

Table 17-5.

Name

$IF <constant>

$THEN <textl>

$ELSE <text2>

Source File Control.

Description

Allows conditional compil-ation of <textl> source if

<constant> is greater than zero.

$INCLUDE:'<filename>' Switches compilation from the current source file to the source file named.

$INCONST: <identifier> Allows interactive setting of constant values at com-pile time.

$MESSAGE: ' <text> ' Displays message on the video to indicate which version of a program is compiling.

$PUSH Saves the current value of all metacommands.

$POP Restores the saved value of all metacommands.

Because the compiler keeps one look-ahead symbol, it actually processes metacommands that follow a symbol before it processes the symbol itself.

This characteristic of the compiler can be a factor in cases such as the following:

CONST 0

=

1:

{$IF 0 $THEN}

{o is undefined in the $IF.}

CONST 0

=

1: DUMMY 0:

{$IF 0 $THEN}

{Now 0 is defined.}

X := p"':

{$NILCK+}

{NILCK applies to p'" here.}

X := p"':

{NILCK doesn't apply to P.}

{$NILCK-}

{$IF <constant> $THEN} <text> {$END}

Allows for conditional compilation of a source text. If the value of the constant is greater than zero, then source text following the $IF is processed: otherwise i t is not.

An $IF $THEN $ELSE construction is also available, as in the following example:

{$IF MSDOS $THEN}

SECTOR

=

S12:

{$ELSE}

SECTOR S128:

{$END}

To simulate an $IFNOT construction, use the following form of the metacommand:

$IF <constant>

$ELSE <text>

$END

$ INCLUDE

$INCONST

The constant can be a literal number or constant identifier. The text between $THEN, $ELSE, and $END is arbitrary; i t can include line breaks, comments, other metacom-mands (including nested $IFs), etc.

Any metacommands wi thin skipped text are ignored, except, of course, corresponding $ELSE or $END metacommands.

Examples using the metaconditional:

{$IF FPCHIP $THEN}

CODEGEN (FADDCALL,Tl,LEFTP) {$END}

{$IF COMPSYS $ELSE}

IF USERSYS THEN DOITTOIT {$END}

Allows the compiler to switch proc-essing from the current source to the file named. When the end of the file that was included is reached, the compiler switches back to the original source and con-tinues compilation. Resumption of compilation in the original source file begins with the line of source text that follows the line in which the $INCLUDE occurred. Therefore, the $ INCLUDE metacommand should always be last on a line.

Allows you to enter the values of the constants (such as those used in $IFs) at compile time, rather than editing the source. This is useful when you use metacondi-tionals to compile a version of a source for a particular environ-ment, customer, target processor,

$MESSAGE

$PUSH and $POP

Enter the desired parameter, for example, 1984:

Inconst: Year = 1984

The response is presumed to be of type WORD. The effect is to declare a constant identifier named YEAR with the' value 1984. This interactive setting of the constant YEAR is equivalent to the constant declaration:

CONST YEAR

=

1984;

except that the metacornrnand can be given anywhere in the program.

Allows you to send messages to the video display during compilation.

This is particularly useful if you use metaconditiona1s extensively, for example, and need to know which version of a program is being compiled.

Example of the $MESSAGE metacom-mand:

{$MESSAGE: 'Message on screenl'}

Allow you to create a meta-environment that you can store with

$PUSH and invoke with $POP. $PUSH and $POP are useful in $INCLUDE files for saving and restoring the metacornrnands in the main source

file.

LISTING FILE CONTROL

The metacomrnands listed in Table 17-6 and described in this subsection allow you to format the listing file as you wish. Listing file format, itself, is discussed in the subsection by that name.

Table 17-6. Listing File Control Metacommands.

Metacomrnand Description

$LINESIZE: <n> Sets the width of listing.

Default is 131.

$LIST+ Turns on or off the source listing. Errors are always listed.

$OCODE+ Turns on the disassembled object code listing.

$PAGE+ Skips to the next page.

$PAGE:<n>

$PAGEIF:<n>

$PAGESIZE:<n>

$SKIP:<n>

Line number is not reset.

Sets the page number for the next page (does not skip to next page).

Skips to the next page if less than n lines are left on the current page.

Sets the page length of a listing in lines. Default is 55.

Skips n lines or to the end of page.

$LINESIZE:<n> Sets the maximum length of lines in the listing file. Default is 131.

$LIST+ Turns on the source listing.

Except for $LIST-, metacommands themselves appear in the listing.

The format of the listing file is described in the subsection,

IIListing File Format, II below.

$OCODE+ Turns on the symbolic listing of the generated code to the object listing file. This listing looks like an assembly listing, with code addresses and operation mnemonics.

The symbolic listing will not be

$PAGEIF:<n> Conditionally performs $PAGE+, if the current line number of the

$SYMTAB+ If on at the end of a procedure, function, or compiland, sends information about its variables to the listing file (for example, see lines 14 and 17 in the sample listing file in the subsection,

"Listing File Format"). The left columns contain the following:

o the offset to the variable from the frame pointer (for vari-ables in procedures and

functions)

o the offset to the variable in the fixed memory area (for main program and STATIC variables) o the length of the variable A leading plus or minus sign indi-cates the sign of a frame offset.

The first line of the $SYMTAB listing contains the offset to the return address, from the top of the frame (zero for the main program).

It also contains the length of the frame, from the framepointer to the end including front end temporary variables. Code generator tempo-rary variables are not included.

For functions, the second line con-tains the offset, length, and type of the value returned by the functions. The remaining lines list the variables, including their type and attribute keywords, as shown in Table 17-7.

$TITLE:'<title>'

Table 17-7. Symbol Table Notation.

Keyword Meaning

Public Has the PUBLIC attribute Extern Has the EXTERN attribute Origin Has the ORIGIN attribute Static Has the STATIC attribute Const Has the READONLY attribute Value Occurs in a VALUE section ValueP Is a value parameter

VarP Is a VAR or CONST parameter VarsP Is a VARS or CONSTS parameter ProcP Is a procedural parameter Segmen Uses segmented addressing Regist Parameter passed in register

LISTING FILE FORMAT

Listing file format is controlled by including various metacornrnands within the program.

The following discussion of listing file format is

Symtab 16 Offset Length Variable - BAR

$SUBTITLE, respectively. I f these metacommands appear on the first source line, they take effect

The fourth line of the listing contains the column labels. The contents of the first three columns are as follows:

The JG column Contains flag characters generated for your information. Jump flags, which appear under the J, can contain one of the following characters:

+ forward jump (BREAK or GOTO a label not yet encountered)

*

backward jump (CYCLE or GOTO a label already encountered) other jumps (RETURN or a mix-ture of jumps)

Codes for local to function) under G:

global variables (not the current procedure or appear in the column assignment

variable

to a nonlocal / passing a nonlocal variable as

a reference parameter

% a combination of the two

The IC column Contains information about the current nesting levels.

The digit under "I" refers to the identifier (scope) level, which changes with procedure and function declarations, as well as with record declarations and WITH statements.

The value in the C column is incre-mented each time control passes to a nested statement: conversely, this value is decremented each time accidentally commented out or skipped due to an $IF and $END identify run-time errors.

Two kinds of compiler messages appear in the recommended. The metacommand $BRAVE+ sends error and warning messages to the video display (as well

Sometimes, the compiler does not detect an error until after the listing of the following line. In this case, the error message line number is not in sequence. Tabs are allowed in the source and are passed on to the listing unchanged. If the tab spacing is every eight columns, the error pointer (A) is generally correct. However, an error pointer near the end of a line can be displaced if the following line has tabs.

If the compiler encounters an error from which it cannot recover, it gives the message "Compiler Cannot Continue!". This message appears if any of the following occur:

o The keyword PROGRAM INTERFACE, or MODULE) program, module, or missing.

(or is not

unit

IMPLEMENTATION, found, or the identifier is o The compiler encounters an unexpected

end-of-file.

o The compiler finds too many errors: the maxi-mum number of errors per page is set with the

$ERRORS metacommand (the default is 25).

o The identifier scope becomes too deeply nested. The maximum level to which procedures can be statically nested is 15.

When the compiler is unable to continue, for what-ever reason, it simply writes the rest of the program to the listing file with very little error checking.

18 USING THE PASCAL COMPILER

You run a Pascal program by first compiling its one or more source modules, using the Linker to link the resul ting object files with the Pascal library, and invoking the resulting run file. The run file is usually invoked through the Executive.

The Pascal compiler translates your Pascal source programs into object modules. The compiler provides a source listing, error messages, and a number of compiler metacommands to aid in program development and debugging.

The compiler comes with a set of object libraries to be linked with your code. These libraries pro-vide complete run-time support for input/output, arithmetic functions, and inline code execution by the optional 8087 Numeric Data Processor that is available with some workstations. When you link your program, the Linker automatically accesses these libraries when necessary. (The run-time libraries are discussed in Section 19, "Run Time and Debugging.")

Using the Linker, you can also combine Pascal object modules with those of other languages, for example FORTRAN, to facilitate writing applica-tions that need different languages for different parts.

Pascal supports systems programming by providing access to all operating system services, such as direct (random) access to disk files, interrupt handling, and process creation. Calls also extend the range of services needed by the commercial application programmer: DAM, ISAM, Sort/Merge, and the Forms Run Time.

COMPILING, LINKING, AND RUNNING PASCAL: OVERVIEW To create and execute a Pascal program,

1. Create and edit the source file. You can use the Editor or the Word Processor to create the source file.

2. Compile the program. The compiler flags syntax errors as it reads your source file.

You can place compiler controls called meta-commands within your program to generate diagnostic calls for run-time errors. If com-pilation is successful, the compiler creates a relocatable object file.

3. Use the Linker to link compiled object files with the run-time library. A compiled object file is not executable and must be linked with one or more run-time libraries, using the Linker. Separately compiled subroutines in other languages or assembly language programs can also be linked to your program at this time. The Linker produces an executable file called a run file.

4. Use the Executive Run command to execute the resul ting run file. (AI ternati vely, you can use the Executive command New Command to create a special command that you can use to execute your run file.)

Repeat this successfully errors.

process compiled,

until your linked, and

program has run without Since compiler metacommands can slow your program down, once the program runs without errors, remove or comment out any metacommands that are no longer necessary, then recompile, relink, and rerun your program.

Im Dokument Pascal Reference (Seite 172-188)