PASCAL FOR PDP 11 UNDER RSX/IAS =============================== This document is intended as a supplement to the book Pascal User Manual and Report by Jensen and Wirth (Second Edition, Springer Verlag, 1975). It describes the "Swedish" implemen- tation of Pascal under the PDP-11 operating systems RSX-11M and IAS. 7-DEC-79 - 1 - Contents -------- 1 Usage of the PASCAL compiler 1.1 How to compile 1.2 How to link 1.3 How to run a PASCAL program 2 Extensions 2.1 Character set and special symbols 2.2 Identifiers 2.3 The PROGRAM statement 2.4 Standard constants 2.5 Standard types 2.6 Standard files 2.7 The extended CASE statement 2.8 The LOOP statement 2.9 Standard procedures 2.10 Standard functions 2.11 Procedures and functions as parameters 2.12 Separate compilation 2.13 String parameters 2.14 Structured function results 2.15 Boundless array parameters 3 Restrictions 4 Compiler options 5 Representation Appendices A Character set B Special symbols C Reserved words D Standard procedures E Standard functions F Error codes G Options and switches H Additional procedures and functions 7-DEC-79 - 2 - 1 USAGE OF THE PASCAL COMPILER Usage under RSX-11M is described. The author is not familiar with IAS, and therefore IAS procedures are left out. 1.1 How to compile The compiler is activated in the standard way: >PAS ,, = The file specifications follow RSX standard, i.e. dev:[p,pn]file.ext/sw. Default values are dev: SY0: [p,pn] fetched from user terminal table .ext .OBJ, .LST, .CXP or .PAS respectively The default dev: and [p,pn] for the LST and CXP files are implied from the specifications on the preceeding file specifications. Switches corresponding to most so called options ( see chapter 4 ) can be given. Only one letter is significant, /E is equivalent to /EIS. Switches can be negated through - or NO, ex. /-R or /NORR. Most switches apply to the object file, only /U (spool) /LW (line width), /PW (page width) and /W (warnings) should be placed on the list file specification. Default values may differ from installation to installation since they are chosen at compiler generation time. Four switches not corresponding to options exist. /U on the list file tells whether the file should be spooled after compilation or not; default: /-U (no spool). /PW:n and /LW:n on the list file can redefine the page and line widths. De- faults selected at compiler generation time. /AA:n defines which level of predefined identifiers to use (See ch. 4.). Eg. PAS EX,EX/U=EX PAS EX, EX, EX = EX PAS T.OBJ,L=DK1:[200,200]EX2.PAS PAS EX3/AA:1,L=EX3 Object and list files are optional. 7-DEC-79 - 3 - Eg. PAS EX2=EX2 PAS ,EX3=EX3 Four error signals can be generated at this point. All cause immediate exit from the compiler: - FILE NOT FOUND if there is no file with the given name - FILE SPECIFICATION ERROR if '=' is not found or if no source filename is given - SWITCH ERROR if an illegal switch is given - ERROR OPENING OUTPUT FILE if an I/O error is encountered in creating any of the output files 7-DEC-79 - 4 - 1.2 How to link Pascal programs Pascal programs are linked by the normal linker: TKB (or FTB). It is used as for all object modules >TKB ,,= The file names are given as above, and only the object file(s) are mandatory. Dynamic memory is reserved according to the compilation report of the main program. If more sto- rage is needed, the size of the task can be extended. Eg. >TKB TKB>EX4,EX4=EX4 TKB>/ ENTER OPTIONS: TKB>EXTTSK=4000 ; add 4000 words (decimal) TKB>// TKB option TSKVEC=$P.VEC can be specified. In that case, a fatal error will also give an octal dump of the heap and stacks of the task. The dump is done with the PMD facility if installed. 1.3 How to execute a Pascal program The program is activated the ordinary way: >RUN EX4. The worskspace can be increased by INStall through the /INC switch. 7-DEC-79 - 5 - 2 EXTENSIONS 2.1 Character set and special symbols Many installations have character sets with the bracket sym- bols replaced with national characters. In order to make it easy to write readable programs it was necessary to allow a special symbol combination as well. New special symbols are: (. left bracket .) right bracket (* start of comment *) end of comment # <> (* not equal *) & and ! or 2.2 Identifiers Identifiers of up to 10 characters in length are recognized distinctively. Any characters beyond 10 are ignored. Lower case characters are treated as upper case. 2.3 The PROGRAM statement A Pascal program must as a first statement have: PROGRAM ; The first six characters in the program name may be the same as the first six of a procedure or function. The parameter list may be empty, or give one or more of INPUT, OUTPUT and TTY. When a file is mentioned it is equivalent to a declara- tion of a textfile of the same name. For files not mentioned no space will be reserved. The file TTY is treated in a spe- cial way, and is bound to the user's terminal (TI: in RSX/IAS). The initial state of TTY is eoln(TTY) = true and no characters automatically input. 7-DEC-79 - 6 - Eg. PROGRAM COPY ( INPUT, OUTPUT ); PROGRAM DIALOG ( TTY ); PROGRAM INTROVERT; 2.4 Standard constants For deflevel (/AA) >= 2 some standard constants are prede- clared. The integer constants are defined as CONST MAXINT = 077777B (* 32767 *); MININT = 100000B (* -32768 *); ALFALENG = 10; The real constants are defined as: CONST MAXREAL = 1.7014111E+38; MINREAL = 1.5224277E-39; SMALLREAL = 1.1983428E-7; They represent the absolutely greatest and smallest reals, and SMALLREAL is the smallest value that makes 1.0+SMALLREAL <> 1.0 . 2.5 Standard types For deflevel (/AA) >= 2 the standard type TEXT is prede- clared as TYPE TEXT = FILE OF CHAR; To allow characters of full ASCII or eightbit code, ASCII and BYTE are defined as TYPE ASCII = CHR(0) .. CHR(177B) ; TYPE BYTE = CHR(0) .. CHR(377B) ; For deflevel >= 3 a standard type for RSX/IAS file handling is predeclared as TYPE IOSPEC = (RANDOM,UPDATE,APPEND,TEMPORARY,INSERT, SHARED,SPOOL,BLOCK); 7-DEC-79 - 7 - It is used in reset/rewrite, see 2.9.4 below. 2.6 Standard files In addition to the standard textfiles INPUT and OUTPUT the standard textfile TTY is available. This file is used to communicate with the user's terminal (TI: of RSX/IAS). This file can be opened only through the program statement. The specification of TTY in the program statement actually causes the declaration of two textfile variables, TTY and TTYIN, for terminal output and input respectively. However, for I/O procedures and functions related to input, the use of TTY as the file variable will be automatically interpret- ed as a reference to TTYIN. For example, READ(TTY,X) is the same as READ(TTYIN,X). When the file variable is omitted from the parameter list of standard I/O procedures such as read and write, the standard files will be assumed in the following way. For output pro- cedures, OUTPUT is assumed if present in the program state- ment, otherwise TTY if present; for input procedures, INPUT is assumed if present in the program statement, otherwise TTY if present. In separatly compiled procedures, standard file TTY is ava- ilable as the default file. Note that external procedures that use TTY for I/O can only be used with main programs that have TTY specified in the program statement. 2.7 The extended CASE statement The CASE statement may be extended with the case OTHERS. The statement associated with OTHERS will be executed if the ex- pression of the CASE statement does not evaluate to one of the explicitly given case labels. Syntax: 7-DEC-79 - 8 - ::= CASE OF { ; } END ::= : ! ::= { , } ! OTHERS Example: VAR X: CHAR; ... CASE X OF 'A': P(X); 'B': Q(X); ... OTHERS: Z(X) END; 2.8 The LOOP statement The LOOP statement is an additional control statement which combines the effects of WHILE and REPEAT statements. Syntax: ::= LOOP EXIT IF ; END ::= { ; } The expression must result in a Boolean value. 2.9 Standard procedures 2.9.1 DATE and TIME The procedure DATE( ) assigns the current date in the format '19yy-mm-dd' to the parameter which must be of type PACKED ARRAY [1..10] OF CHAR. The procedure TIME( ) assigns the daytime in the format 'hh:mm:ss.t' to the parameter which must be of type PACKED ARRAY [1..10] OF CHAR. 7-DEC-79 - 9 - 2.9.2 MARK and RELEASE There is no procedure DISPOSE but the pair MARK and RELEASE takes care of deallocation when a nested structure is used. MARK puts a mark in the heap and RELEASE releases all sto- rage above the topmost mark in the heap. They have no param- eters, but for compatibility with the PASREL compiler on DEC10 they may be called with one (unused) parameter. 2.9.3 HALT The procedure HALT can be used to help debug Pascal pro- grams. A call of HALT gives a dump of the stack and heap, and exit from the program. The dump is done through the PMD (Post Mortem Dump) facility if installed. 2.9.4 RESET and REWRITE The standard procedures RESET(f) and REWRITE(f) have been extended with up to 5 new parameters. These make it possible to use almost all of the RSX/IAS file system, but two pro- perties are fixed: - all files are accessed in locate mode, - textfiles ( files of char, ascii or byte ) use records of variable length with one line per record, all other files use records of fixed length. The new call format is: RESET(f,filename,dir,dev,ioselect) and REWRITE(f,filename,dir,dev,ioselect) Only as many parameters as necessary need be present. They must be declared as: f: FILE OF ; filename: ARRAY OF CHAR or string constant to give an external file name. Examples: 'SOURCE.PAS','TEXT;3' or a string variable containing 'FILE2.EX '. The length is insignificant. If the name is 7-DEC-79 - 10 - shorter than the string, the string must be filled with trailing blanks. dir: ARRAY OF CHAR or string constant to give a file directory. Example: '(40,13)','[200,200]'. The parentheses are automaticaly translated to brackets. The length is insignificant. If the directory name is shorter than the string, the string must be filled with trailing blanks. dev: ARRAY OF CHAR or string constant to give device name. Example: 'SY:','LP0:'. The length is insignificant. If the device name is shorter than the string, the string must be filled with trailing blanks. ioselect: SET OF IOSPEC; IOSPEC is predeclared if DEFLEVEL >= 3. Otherwise it can be declared as TYPE IOSPEC = (RANDOM,UPDATE,APPEND TEMPORARY,INSERT,SHARED,SPOOL,BLOCK); The keywords mean (cf RSX/IAS): RANDOM the records of the file may be fetched in random order, UPDATE an existing file shall be changed. APPEND an existing file shall be appended, TEMPORARY a temporary file shall be used, INSERT together with UPDATE this condition gives that the file shall not be truncated if written into, SHARED the file is opened in such a way that other tasks may open it too, SPOOL this textfile shall, when closed, be handed over to the print spooler for printing on the line printer, BLOCK enables blockwise read and write. Only one file element is read or written, even if more than one can be contained in one block. QIO is used directly, so this is not exactly as READ and WRITE of RSX/IAS. For both RESET and REWRITE, f is the only mandatory parame- ter. The other parameters have default values if left out in 7-DEC-79 - 11 - a call: filename: the internal name of the file variable dir: default uic from RSX-11M dev: 'SY0:' ( Selectable at compiler generation ) iospec: [] the empty set Example: RESET(F) is equivalent to RESET(F,'F',,'SY0:',[]) 2.9.5 BREAK and PAGE The procedure PAGE( ) inserts a form feed in the given file. It may be called without parameter in which case it is assumed to be the standard file OUTPUT if present in the PROGRAM statement, otherwise TTY if present. The procedure BREAK can be called without a parameter or with one textfile parameter. If no parameter is specified and TTY is present in the program statement, or if the file parameter is TTY then the current line buffer is written without carriage return added. Thereby, a later input from TTY can be given on the same line. If the file is not TTY, break is equivalent to writeln. 2.9.6 GET and PUT The standard procedures GET and PUT can take a second param- eter of type integer. This parameter has effect only if RAN- DOM or BLOCK was specified when opening the file. In case of RANDOM, it is the number of the record to be input from the file (GET) or written to the file (PUT). If the file was opened with BLOCK in ioselect, one file element is trans- ferred to or from the block with the given number. Notice that since locate mode is used why it is necessary to locate a random record with GET before PUT can be used. 7-DEC-79 - 12 - 2.9.7 READ and WRITE The standard procedures READ and WRITE are generalized to allow all types of files. READ is extended to allow direct read of an array of char- acters. The array is filled from the current line buffer. If enough characters are not left in the buffer, spaces are in- serted. When reading integers or reals, spaces preceding the number are skipped. Trailing spaces are also skipped (but see also option $H below) until eof or not space, but for TTY only until eoln or not space. The procedures WRITE and WRITELN have been extended to allow output of integers in octal representation. The format is: WRITE (..., I:m:O, K:m,...) where I will be written in octal, K will be written in deci- mal and m is the minimum field width expression as described in the user manual. 7-DEC-79 - 13 - 2.9.8 NEW (on variant records) When a NEW is performed to allocate a record that has vari- ants and if one or more variant selectors are supplied as parameters to NEW then the corresponding tag field(s), if any, will be assigned the given selector value(s). Eg. type Ttyp = (V1,V2,V3); smallrectyp = record i: integer; case b: boolean of FALSE: ( j: ... ); TRUE: ( k: ... ) end; bigrectyp = record a: sometype; case t: Ttyp of V1: ( ... ); V2: ( ... ); V3: ( a3: integer; b3: smallrectyp ); end; var p: ^bigrectyp; begin : new ( p ); { Allocates space for largest variant of bigrectyp } : new ( p, V2 ); { Allocates just enough space for V2 variant. p^.t = V2 } : new ( p, V3, TRUE ); { p^.t = V3 and p^.b3.b = TRUE } 7-DEC-79 - 14 - 2.9.9 NEW (on arrays) When a NEW is performed to allocate an array, space is nor- mally provided to accomodate the entire array as declared. An optional parameter can, however, be specified in the NEW to allocate only a portion of the array. Eg. type atyp = array [0..10] of anytype; var a: ^atyp; begin new ( a: i ); In this example, only enough space for i+1 elements will be allocated. The expression i must be of a type compatible with the index type of the array and represents the maximum index useable in the allocated array. 7-DEC-79 - 15 - 2.10 Standard functions 2.10.1 RUNTIME The function RUNTIME returns an integer giving the daytime in seconds modulo 8 hours (RSX/IAS doesn't measure CPU time). 2.10.2 TWOPOW and SPLITREAL The function TWOPOW():REAL gives as re- sult the real 2**. The function SPLITREAL(, ):REAL returns the binary exponent of the real ex- pression in the integer variable and gives as result a real with binary exponent zero but the same mantissa as the ex- pression. 2.10.3 IORESULT The function IORESULT():INTEGER returns an integer va- lue indicating the result of the last operation on the given file. Result = +1 if OK and <0 if error. The error codes are those returned from RSX/IAS. For further details see RSX/IAS manuals. A few error codes are added, see appendix F. 2.10.4 ORD The ORD function can also take a pointer or a set (16 ele- ments or less) as an argument. The integer result will be the 16 bit representation of the argument. 7-DEC-79 - 16 - 2.11 Procedures and functions as parameters In this implementation of Pascal it is necessary to declare the formal parameters of a formal procedure or function. At the declaration of a formal procedure or function no iden- tifier is required for its formal parameters, only the type(s) of the argument(s) must be specified. The declaration of "formal formal parameters" is necessary for the compiler to check the actual procedure- and function-parameters with respect to their parameters and types. This avoids a considerable overhead of parameter- and type-checking at runtime of a Pascal program. Example: PROGRAM INTEGRATION; FUNCTION INTEGRATE ( FUNCTION F (REAL):REAL; LOWBOUND, HIGHBOUND, DELTA: REAL ): REAL; (* BODY *) ... FUNCTION SINUS ( ARG: REAL ): REAL; BEGIN SINUS := SIN( ARG ); END; BEGIN WRITELN( INTEGRATE( SINUS, 0, 3.14, 0.01 ); END. Note that external procedures and functions not written in Pascal and standard procedures and functions must not be used as actual parameters to formal procedures or functions since they obey different parameter conventions. 2.12 Separate compilation It is possible to compile one or more procedures without a main program. In that case, no program statement is allowed and the source file must begin with an option comment stat- ing M-. For further details see paragraph 4.9 below. Separately compiled procedures and functions can be accessed if they are declared with the procedure body replaced by EX- TERN. Fortran and assembler-written routines can also be ac- cessed if their parameter transport follows Pascal standard or Fortran. In the latter case the procedure body should be 7-DEC-79 - 17 - replaced by EXTERN( FORTRAN ). If the external name contains '$' or '.' it can be given as a string constant. Eg. EXTERN( FORTRAN, '$TEST' ) Global variables can be shared between the main program and separately compiled procedure/functions. This is done in the procedure by declaring the shared variables before the par- ameter statement. Because there can be no checking across separate compilations, it is the programmer's responsibility for ensuring that these variables are declared in exactly the same way in both the main program and the procedure. Good use can be made here of the compiler's include facility or of a separate inlcude preprocessor. Example: Main program Separate Procedure ------------ ------------------ program main; {$m-} type type atyp = ... atyp = ... ctyp = ... var { global } var a: atyp; a: atyp; b: integer; b: integer; c: ctyp; procedure proc; procedure proc; extern; var { local } begin { main } x: ... : y: ... : begin { proc } : : 7-DEC-79 - 18 - 2.13 String parameters Arbitrary length character strings can be passed as parame- ters to procedures and functions. These "string paramaters" are declared using the word STRING. Eg. PROCEDURE PA (...; STRING A,B,...; ...); Both character arrays and string constants of any length can be supplied as arguments for string parameters and can be modified by the procedure. Use caution here because a con- stant can be modified. Within a procedure that is using string parameters, these will always be treated as arrays of characters with the first character at subscript 0. The standard function SIZE can be used to obtain the actual length of the passed string. Eg. CONST C = 'NAMED CONSTANT'; VAR V = ARRAY [1..8] OF CHAR; PROCEDURE P ( STRING S ); BEGIN IF SIZE(S) >= 5 THEN CH := S[4] END; BEGIN P(C); P('STRING'); V := 'VARIABLE'; P(V) END. Note that there are only two ways in which string paramaters can be used: as an actual parameter to another procedure/function or to access a single character in the string. Currently, the compiler will not give errors when a string parameter is used in other ways. A substring specification can be used as an actual parameter for a paramater that has been declared as a string para- mater. A substring specification has the form: 7-DEC-79 - 19 - A [ n..m ] where A is an array of characters or a formal string parame- ter and n and m are expressions of a type that is compatible with the subscript type of A. The values of n and m define the bounds of the substring of A. Substrings can also be used as parameters to the standard procedures WRITE, WRITELN, READ, REWRITE and RESET. 2.14 Structured function results The result of a function is not limited to scalar, subrange or pointer types. The result can be of any structured type also. 2.15 Boundless array parameters The declaration of the type of a formal array parameter can be made so that the dimensions of the actual parameter are passed at run time. Eg. procedure P ( var a: array [integer,integer] of atyp ); 7-DEC-79 - 20 - 3 RESTRICTIONS 3.1 Reserved words The following words are also reserved: LOOP EXIT OTHERS EXTERN FORWARD 3.2 Packed structures Packed data structures are only implemented for character arrays (always packed, two char's per word) and for Boolean arrays (packing optional, one Boolean per bit). The proce- dures PACK and UNPACK are not implemented. 3.3 GOTO statement The GOTO statement is restricted to allow only local GOTO's. 3.4 SET size The representation of sets is chosen so that a set may have at most 64 members. 3.5 File declarations A file that is declared in a procedure must be explicitly closed (if it is open) within that procedure. See procedure CLOSEF in appendix H. 7-DEC-79 - 21 - 3.6 Parameter transmission Standard procedures or functions or external Fortran rou- tines may not be passed as actual parameters. 3.7 Definition level 0 and 1 The compiler can be generated with a predeclaration level of 0, 1, 2 or 3. The level can also be chosen at compile time through the switch /AA:n on the object file specification, see point 4.1 below. Level 1 is exactly standard Pascal, level 0 is restricted to give the compiler more workspace (no arithmetic functions). 7-DEC-79 - 22 - 4 COMPILER OPTIONS AND SWITCHES When compiling a Pascal program it is possible to select some special features called options. All option switches have default values. Some can be changed dynamically and some may be set only before the first statement. Option switches are turned on and off through comments beginning with '$' ( =chr(44B)) followed by one or more option selec- tors, separated by commas. Each option selector consists of one letter followed by '+' or '-'. Example: (*$L+,C-,M+*). The default values listed below may be changed at compiler generation time. Most option switches can also be set with command line switches. These override all selecting of the same option in the source code. The switches follow RSX/IAS standard but only one character is significant. Eg. /EI/-CC/MM . 4.1 Predeclaration level: A The compiler always has some names predeclared, i.e. IN- TEGER, TRUE etc. All names occupy data space when the com- piler is run. For large programs, and for compatibility rea- sons it can be of interest to reduce the number of prede- clared types, functions etc. to a minimum or to standard Pascal. The predeclaration level is selected at compiler generation time, but can be reset for a single compilation through the command line switch /A followed by an unsigned integer. Examples: /AA:1, /A0 . Level Restriction (-) or extension (+) 0 - arithmetic functions ( sin, cos etc. ) 1 standard Pascal 2 + maxint,minint,maxreal,minreal,smallreal + text,ascii,byte,alfaleng 3 + ( 2 ), + iospec 7-DEC-79 - 23 - 4.2 Listing of generated code: C This switch can be changed dynamically. When C+ is in ef- fect, statement addresses (octal) will be included on the program listing and the symbolic generated code will be out- put to the CXP file (ie. 3rd output file spec on command line) if any was specified. Default: C-. 4.3 Extended instruction set, EIS: E The compiler generates MUL and DIV instructions if option E+ is selected, otherwise these operations are performed through subroutines. (E+ is implied by F+ or G+) 4.4 Floating point processor, FPP: F The floating point hardware for PDP 11 model 45 and up can be used if option F is selected. 4.5 Floating instruction set, FIS: G The PDP 11/35 and 40 floating point hardware can be used if option G is selected. 4.6 Error handling and conversion selection: H When a Pascal program is executed certain errors can occur, i.e. index out of bounds. See appendix F for a complete list. They are grouped into three categories: messages, warnings and fatal errors. Message and warning printouts can be suppressed, and it is possible to continue execution after warnings and even after errors. It is also possible to choose to skip spaces after reading integers and reals in addition to just before. The choices are made through an in- teger following H+. The value is the sum of any of the fol- 7-DEC-79 - 24 - lowing selections: Value Meaning 1 print warnings 2 continue after warning 4 continue after fatal error 8 print messages 16 skip spaces after read integer/real Example: (*$H+19*). Default 3 = print warnings and continue after warnings. H is not selectable through a command line switch. 4.7 Program listing: L Listing of the source program may be switched on and off during compilation. Default: L+. If no listing at all is wanted, the listfile specification can be omitted from the command line. There is no corresponding command line switch. 4.8 Line width: L The maximum number of characters printed per line is select- able in the same way as the page width (P). The line split- ting can occur in the middle of a Pascal symbol. Example: /LW:72, /L132. Default: /L132. 4.9 Main program: M It is possible to compile a set of procedures and functions separately. In this case, no PROGRAM statement and no main program may be given, and the source text must begin with an option selection of M-. The last procedure or function should end with a period (.) instead of a semicolon (;). Default: M+. 7-DEC-79 - 25 - 4.10 Page width: P It is possible to select the maximum number of lines printed per page through a switch on the list file specification. Normally a suitable page width is selected at compiler gen- eration time Example: /PW:50, /P29 4.11 Page eject: P There are two ways to force the compiler to start on a new page after the current line. The character form feed and the option P+ both give this effect. P+ is reset afterwards. 4.12 Frequency measurement: Q It is possible to get the compiler to insert instructions in the generated code that count the number of times the code is executed. The measuring points are inserted before the first beginning of a statement in each line of the source code. Example, (**) = measuring point: (**) for i:=1 to 5 do (**) a[i]:=0; (**) if i=3 then (**) x:=2.0 else (**) x:=0.0; This option must be selected before the program statement, but may be switched on and off after the program statement. After execution of a program compiled with Q+ or /Q, a file of name .FQV is produced. It contains the measuring information in a form ready for printing (i.e. PIP EX.FQV/SP). If R- is selected only the beginnings of procedures and functions are measured, and if both R- and T- are in effect no measuring at all is performed. It is also necessary that the program statement include OUTPUT. 7-DEC-79 - 26 - Note that the storage for the execution counts is in-line with the code being executed. As such, frequency measuring destroys the read-only nature of the generated code. 4.13 Runtime checks: R and T The compiler can generate checks of dynamic storage and stack allocation at procedure and function entry and calls of NEW. Default: T+. Checks of assignment to subrange variables and of array in- dices are not generated if option R- is selected. Default: R+. 4.14 Trace: S The compiler will generate calls to a runtime routine that will display the current statement address on the TI: termi- nal. The trace points are at each source line where a state- ment begins. The option may be switched on/off at any point in the program or selected on the command line. Default: S-. 4.15 Spool listfile: U The listfile is normally not spooled. It will automatically be printed if the switch /U is given on the listfile specif- ication in the command line. 4.16 Object module version: V The object modules that are generated can get version infor- mation, which the linker will print on the map. The version identifier consists of up to six alfanumeric characters after V+. Example: (*$V+PAS500*). There is no /V switch in the command line. 7-DEC-79 - 27 - 4.17 Warning suppression: W Error messages classified as warnings may be suppressed by selecting option W-. Warning error numbers are > 900. Default: W+. 4.18 Conditional compilation: X and Z It is possible to write test statements which generate code only if option X+ is selected. Default: X-. The conditional parts of the code must be enclosed in a spe- cial option parenthesis, (*$Z+*) (*$Z-*). 4.19 Object module splitting: Y The generated object code can be split into several object modules (in one file) through insertion of option Y+ in the source text. All procedure bodies whose compilation start with Y+ in effect will become separate object modules in the object file. This option is implemented to allow large pro- grams to be overlaid in PDP 11. Default: Y-. 7-DEC-79 - 28 - 5 REPRESENTATION 5.1 Scalars Integers, booleans and characters occupy one word each. Reals occupy two words with one sign bit, one exponent sign bit, seven exponent bits and a mantissa of 23 bits plus one bit hidden. Sets of up to 16 members occupy one word and sets of up to 64 members occupy four words. 5.2 Arrays Character arrays are always packed two characters per word. Booleans, in unpacked arrays, occupy one word each, in packed arrays, one bit each, that is, 16 per word. 5.3 Files See also RSX/IAS I/O Operations Reference Manual. Files are represented as fixed length record files except textfiles which have variable length records, one line per record. They are used in locate mode. File descriptor blocks are al- located in the stack and a file declaration thus reserves 108 bytes plus the size of one record of the file. For textfiles, the maximum line length is 132 characters for which a buffer is reserved. 5.4 Stack and heap The stack and heap are given a contiguous area in which the stack grows from one end and the heap from the other. Dynam- ic storage is allocated on the heap while static variables and parameters are placed on the stack. This area is a psec- tion named 999999 and which is thus normally allocated at the end of the task image. Runtime errors will occur if it is not placed there. There are two ways of extending the heap/stack space: 7-DEC-79 - 29 - 1. with the EXTSCT option at build time, or 2. by task extension, specified at build, install or run time. 7-DEC-79 - 30 - 5.5 Parameter transmission A Pascal program has a special stack for allocation of data and for parameter transmission. The Pascal stack is accessed through register R5. The first parameter is pushed first and the last item pushed is a special link word. This link is used for accessing variables at intermediate levels and is of no value to assembler routines. An assembler routine, de- clared in a Pascal program as: function A ( i, j: integer; c: char; var x: xtyp; string s ); extern; will receive a stack as follows: R5+14: reserved for result (functions only) R5+12: value of i R5+10: value of j R5+8: value of c R5+6: address of x R5+4: address of first character of s R5+2: length of s in bytes R5: link Each parameter occupies an area large enough to hold its va- lue, ie. entire arrays and records are copied to the stack. However, for parameters declared with the VAR attribute, on- ly the address of the actual parameter is transmitted. For arrays, the address given is the address of a hypothetical zeroth element of the array (this can be odd for character arrays). The link and all parameters must be removed from the stack before return (by RTS PC). For functions, an area for the result is reserved on the stack before the parameters are pushed. At return, R5 will thus point to this area. Assembler routines called from Pascal can alter registers 0, 1 and 2 but must preserve registers 3, 4 and 5. 7-DEC-79 - 31 - APPENDICES ========== A. Character set The compiler accepts all ASCII characters in the source in- put. Lower case characters will be listed as such but will be treated as uppercase except in strings. Two control char- acters are recognized, HT (tab) and FF (formfeed); all oth- ers are converted to SP (space). The formfeed character forces the listing to a new page. Comments can be enclosed in braces: {...}. For historical reasons, comments may be enclosed in percent and backslash characters ( eg. %Comment\) as well as (*...*) and {...}. In Pascal programs, character variables can take on any va- lue from chr(0) to chr(377B). However, since sets are limit- ed to 64 elements, only a limited range of characters can be elements of a set of characters. This range is encircled in the following table. 0 1 2 3 4 5 6 7 00 NUL SOH STX ETX EOT ENQ ACK BEL 01 BS HT LF VT FF CR SO SI 02 DLE DC1 DC2 DC3 DC4 NAK SYN ETB 03 CAN EM SUB ESC FS GS RS US -------------------------------------------- I 04 SP ! " # $ % & ' I I 05 ( ) * + , - . / I I 06 0 1 2 3 4 5 6 7 I I 07 8 9 : ; < = > ? I I 10 @ A B C D E F G I I 11 H I J K L M N O I I 12 P Q R S T U V W I I 13 X Y Z [ \ ] ^ _ I -------------------------------------------- 14 ` a b c d e f g 15 h i j k l m n o 16 p q r s t u v w 17 x y z { | } ~ DEL 7-DEC-79 - 32 - B. Special symbols Table of special symbols with their meaning. Stand- Altern- Meaning ard ative := assignment + with one operand: identity - with one operand: negation + with two operands: addition - with two operands: subtraction * multiplication / real division div integer division mod remainder = equal <> # not equal < less > greater <= less or equal, set inclusion >= greater or equal, set inclusion in set membership not negation or ! disjunction and & conjunction or ! set union - set difference and & set intersection (* % { start of comment *) \ } end of comment . end of program , comma : colon ; statement separator ' string delimiter ( left parenthesis ) right parenthesis [ (. left bracket set constructor ] .) right bracket set constructor ^ pointer constructor $ option constructor 7-DEC-79 - 33 - C. Reserved words The following words are reserved: if do of to in or end for var div mod set and not then else with goto loop case type file exit begin until while array label const others repeat record downto packed extern forward function procedure 7-DEC-79 - 34 - D. Standard procedures This is a list of standard procedures, with an indication of parameter types. Input/output: RESET(FILE, STRING, STRING, STRING, SET) REWRITE(FILE, STRING, STRING, STRING, SET) GET(FILE) GET(FILE,INTEGER) PUT(FILE) PUT(FILE,INTEGER) PAGE([FILE]) READ([FILE,] INTEGER or REAL or CHAR or STRING, ... ) READLN([FILE,] INTEGER or REAL or CHAR or STRING, ... ) WRITE([FILE,] INTEGER or REAL or CHAR or BOOLEAN or STRING, ... ) WRITELN([FILE,] INTEGER or REAL or CHAR or BOOLEAN or STRING, ... ) BREAK Where FILE is optional, the standard text file INPUT or OUTPUT will be implied by default if it has been declared (ie. in the program statement). Otherwise, the text file TTY will be assumed if it has been de- clared. If none of these have been declared then an error will be flagged. Execution control: HALT Administration of dynamic storage: NEW(POINTER,variant selector, ... ) MARK RELEASE Miscellaneous: DATE(STRING) ( array [1..10] of char ) TIME(STRING) ( array [1..10] of char ) 7-DEC-79 - 35 - E. Standard functions This is a list of standard functions with an indication of parameter types. Mathematical functions: ABS(INTEGER or REAL):INTEGER or REAL COS(INTEGER or REAL):REAL EXP(INTEGER or REAL):REAL LN(INTEGER or REAL):REAL SIN(INTEGER or REAL):REAL SQR(INTEGER or REAL):INTEGER or REAL SQRT(INTEGER or REAL):REAL Conversion routines: ROUND(REAL):INTEGER TRUNC(REAL):INTEGER CHR(INTEGER):CHAR ORD(any type occupying one word): integer; Miscellaneous: ODD(INTEGER):BOOLEAN EOF([FILE]):BOOLEAN EOLN([FILE]):BOOLEAN IORESULT([FILE]):INTEGER PRED(any scalar except REAL):same as argument SUCC(any scalar except REAL):same as argument RUNTIME:INTEGER SPLITREAL(REAL,INTEGER):REAL TWOPOW(INTEGER):REAL SIZE (STRINGPARM):INTEGER 7-DEC-79 - 36 - F. Error codes F.1 Compile-time errors 1 error in simple type 2 identifier expected 3 error in value part 4 ')' expected 5 ':' expected 6 illegal symbol 7 error in parameter list 8 'of' expected 9 '(' expected 10 error in type 11 '[' expected 12 ']' expected 13 'end' expected 14 ';' expected 15 integer expected 16 '=' expected 17 'begin' expected 18 error in declaration part 19 error in field list 20 ',' expected 21 constant expected 22 'program' expected 23 standard files only 'input', 'output', 'tty' 50 error in constant 51 ':=' expected 52 'then' expected 53 'until' expected 54 'do' expected 55 'to'/'downto' expected 56 'if' expected 57 'exit' expected 58 error in factor 59 error in variable 101 identifier declared twice 102 low bound must not be greater than high round 103 identifier is not of appropriate class 104 identifier not declared 105 sign not allowed 106 number expected 7-DEC-79 - 37 - 107 incompatible subrange type 108 file not allowed here 109 type must not be real 110 tag field must be scalar or subrange 111 incompatible with tag field type 112 index type must not be real 113 index type must be scalar or subrange 114 base type must not be real 115 base type must be scalar or subrange 116 error in type of standard procedure parameter 117 unsatisfied forward reference 118 forward referenced type identifier in variable declaration 119 forward declared: repetition of parameter list not allowed 120 function result type must not be files 121 file value parameter not allowed 122 forward declared function: repetition of result type not allowed 123 missing result type in function declaration 124 fixed format for real only 125 error in type of standard function parameter 126 number of parameters does not agree with declaration 127 illegal parameter substitution 128 result type of parameter function does not agree with declaration 129 type conflict of operands 130 left operand of set membership test is not scalar or right operand is not of set type 131 tests on equality allowed only 132 strict inclusion not allowed 133 file comparison not allowed 134 illegal type of operand(s) 135 type of operand must be boolean 136 set element type must be scalar or subrange 137 set element types not compatible 138 type of variable is not array 139 index type is not compatible with declaration 140 type of variable is not record 141 type of variable must be file or pointer 142 illegal parameter substitution 143 illegal type of loop control variable 144 illegal type of expression 7-DEC-79 - 38 - 145 type conflict 146 assignment of files not allowed 147 label type incompatible with selecting expression 148 subrange bounds must be scalar 149 index type must not be integer 150 assignment to standard function not allowed 151 assignment to formal function is not allowed 152 no such field in this record 153 type error in read 154 actual parameter must be a variable 155 control variable must not be formal 156 multiply defined case label 157 too many cases in case statement 158 missing corresponding variant declaration 159 real and string tag fields not implemented 160 previous declaration was not forward 161 again forward declared 162 slice variant separator is colon 163 missing variant in declaration 164 missing slice variant in declaration 165 multiply defined label 166 multiply declared label 167 undeclared label 168 undefined label 169 error in tag field 170 variant must have the same type as tag field 180 standard file not in program statement 181 'input', 'output' or 'tty' missing in program statement 182 parameters to external Fortran routines must be var parameters 183 body not allowed when not main 184 assignment to function only in its body 201 error in real constant: digit expected 202 string constant contains 'eol' 203 integer constant exceeds range 204 8 or 9 in octal number 205 real constant exceeds range 206 octal output format for integers only 250 too many nested scopes of identifiers 251 too many nested procedures and/or functions 7-DEC-79 - 39 - 253 too much code produced 254 too many string/set/real constants in this procedure 255 too many errors in this source line 399 not implemented 400 compiler error 600 indextype of boundless array must be of scalar type (but not of type real) 601 colon in parameter list must be followed by identifier or array symbol 602 boundless arrays must be var specified 603 standard functions/procedures are not allowed as actual procedure parameters 604 ordinal numbers of setelements must lie in the range 0..63, or ' '..'_' for characters 605 the set variables in an expression do not have the same base type 606 base types of sets are incompatible 607 colon is missing in the specification of parameters of a formal procedure/function (warning only) 608 error in parameter specification 609 fortran routines are not allowed as actual procedure parameters 610 integer constants required as actual parameters 612 parameter list structure of formal and actual procedure are not the same 617 parameter must have stringparm form 626 only string parameters allowed as parameter to size function 900-999 warnings only 900 undeclared label 901 unused declared label 902 undefined option switch 920 program statement missing ('input' and 'output' assumed) 930 OUTPUT must be present to allow frequency measurement 7-DEC-79 - 40 - 931 too many procedures with the first 6 characters in their names equal 940 source code "include" nesting > 3 not allowed 7-DEC-79 - 41 - F.2 Runtime errors Runtime error messages are written on the terminal, and ap- pear in the form PASRUN -- ERROR nn. (mmmmmm) vvvvv. where nn = error number, see list below mmmmmm = line address where error occured (octal). vvvvv = offending value ( error 12 only ). The line address is not correct if the error appears in a part of the program where the runtime check option R is switched off (R-). In such a case, the displayed line ad- dress will be that of the last executed statement where R+ was in effect or the address of the last entered procedure where T+ was in effect. Only a short error message with no numbers will be written if there is insuficient R6 stack space to build the complete message. It is possible to redefine the error handling at compiler generation time, or in the source code through the option H (see 4.6). Normal actions for the three classes of error are: F: Fatal errors. Continuation of the program is normally not possible or useful, and the program is therefore terminated. W: Warnings. After having printed the error message, the program will continue execution. See the comments. M: Messages. Conversion errors are normally only signalled through IORESULT, but messages can be printed. Execution continues afterwards. 7-DEC-79 - 42 - RUNTIME ERROR SUMMARY --------------------- Number Kind of operation Comments ------ ----------------- -------- Class ----- 10 F Procedure entry or Stack overruns heap dynamic allocation or heap overruns stack Too much code + data, or error(s) in program (40 words left) 11 F Same as 10 Hardware stack overflow (20 words left) 12 F Assignment or Subrange overflow indexing in array Index out of bounds 20 F Integer division An attempt was made or modulo to divide by 0 21 F Integer division Divisor was -32768 or modulo (most negative number) 23 F Integer multiplication First operand = -32768 30 W All real operations Exponent overflow MAXREAL assumed 31 W All real operations Exponent underflow Floating zero taken 33 F Trunc or round Floating number too large 34 F Real division Attempt to divide by 0 40 M Read integer No digits after sign, zero taken 41 M Read integer Number too large, 77777B taken 42 M Read real or integer Too many digits 7-DEC-79 - 43 - 44 M Read real No char's read, floating zero taken 50 W Exponentiation Exponent overflow MAXREAL taken 51 F Square root Square root of negative 60 F Substring parameter Substring range out of bounds 61 F Indexing in substring Index out of bounds 66 F Read or get Attempt to read beyond end of file F.3 Result codes after I/O operations The result codes received by IORESULT are the RSX/IAS codes. Six new codes are added: -101 too many files (RESET/REWRITE) -102 file not opened (GET/PUT) -103 too many digits (read integer or real exponent, MAXINT taken) -104 no digits read (read integer or real exponent, zero taken) -105 integer overflow (read integer: MAXINT taken, read exponent: MAXREAL taken) -106 no digits read and "." or "E" not found (read real, 0.0 taken) 7-DEC-79 - 44 - G. Options and switches All default values can be changed at compiler generation. The values listed are from the distribution set. Name Default Option/switch used for A 3 Predeclaration level (switch only) B C - Printing of octal relative addresses D - Debug ( not implemented yet ) E - EIS F - FPP G - FIS H 3 Runtime error handling (option only) I J K L + Listing on/off (option only) 132 Line width ( switch only ) M + Main program N O P - Page eject ( option only ) 55 Page width ( switch only ) Q - Frequency measurements R + Runtime checks of indexbounds etc. S - Trace T + Runtime checks of stack/heap overflow U - Spool listfile ( switch only ) V Object module version W + Print compiler warning messages X - Conditional compilation Y - Object module splitting Z Conditional compilation 7-DEC-79 - 45 - H. ADDITIONAL PROCEDURES AND FUNCTIONS The following procedures and functions are available in SYSLIB/PASLIB and can be used if declared as: procedure GCML ( var s: line; var len: integer ); extern; (* type line = array [1..80] of char . Returns the MCR command line in s and its length in len. *) procedure closef ( var f: ); extern; (* closes the external file associated with the file parameter *) procedure attach ( var f: ); extern; (* issues a QIO with IO.ATT to the file *) procedure detach ( var f: ); extern; (* issues a QIO with IO.DET to the file *) 7-DEC-79 - 46 -