From 0a60d5f585870c6e1af81de25beb8aa1667d8822 Mon Sep 17 00:00:00 2001 From: eck Date: Mon, 8 May 1989 10:04:50 +0000 Subject: [PATCH] updated for new pascal compiler --- doc/pcref.doc | 1024 ++++++++++++++++--------------------------------- 1 file changed, 336 insertions(+), 688 deletions(-) diff --git a/doc/pcref.doc b/doc/pcref.doc index 532ce07b6..9058efad1 100644 --- a/doc/pcref.doc +++ b/doc/pcref.doc @@ -14,24 +14,33 @@ .tr ~ . TITLE .de TL -.sp 15 +.sp 10 .ce \\fB\\$1\\fR +.sp 10 .. . AUTHOR .de AU -.sp 15 .ce by .sp 2 .ce \\$1 .. +. OTHER AUTHOR +.de OA +.sp 2 +.ce +(revised) +.sp 2 +.ce +\\$1 +.. . DATE .de DA -.sp 3 +.sp 1 .ce -( Dated \\$1 ) +( \\$1 ) .. . INSTITUTE .de VU @@ -99,19 +108,7 @@ Amsterdam .de IT .sp .in 0 -\\fBISO~\\$1:\\fR~\\ -.. -. IMPLEMENTATION 1 -.de I1 -.IS -.ti -3 -1.~\\ -.. -. IMPLEMENTATION 2 -.de I2 -.sp -.ti -3 -2.~\\ +\\fBBS~\\$1:\\fR~\\ .. .de CS .br @@ -122,10 +119,14 @@ Amsterdam .TL "Amsterdam Compiler Kit-Pascal reference manual" .AU "Johan W. Stevenson" .DA "January 4, 1983" +.OA "Hans van Eck" +.DA "May 1, 1989" .VU .CH "Introduction" -This document refers to the (March 1980) ISO standard proposal for Pascal [1]. -Ack-Pascal complies with the requirements of this proposal almost completely. +This document refers to the (1982) BSI standard for Pascal [1]. +Ack-Pascal complies with the requirements of level 1 of BS 6192: 1982, with +the exceptions as listed in this document. +.PP The standard requires an accompanying document describing the implementation-defined and implementation-dependent features, the reaction on errors and the extensions to standard Pascal. @@ -137,84 +138,41 @@ the list of options recognized by the compiler. The Ack-Pascal compiler produces code for an EM machine as defined in [2]. It is up to the implementor of the EM machine to decide whether errors like integer overflow, undefined operand and range bound error are recognized or not. -For these errors the reaction of some known implementations is given. .PP There does not (yet) exist a hardware EM machine. Therefore, EM programs must be interpreted, or translated into instructions for a target machine. -For the following implementations the behavior is documented: -.I1 -an interpreter running on a PDP-11. -Normally the interpreter performs some tests to detect undefined -integers, integer overflow, range errors, etc. -However, an option of the interpreter is to skip these tests. -Another option is to perform some extra tests -to check for instance the number of actual parameter -words against the number expected by -the called procedure. -We will refer to these modes of operation as 'test all', 'test on' and 'test off'. -.I2 -a translator into PDP-11 instructions. +The Ack-Pascal compiler is currently available for use with the VAX, +Motorola MC68020, Motorola MC68000, +PDP-11, and Intel 8086 code-generators. +For the 8086, MC68000, and MC68020, +floating point emulation is used. This is made available with the \fI-fp\fP +option, which must be passed to \fIack\fP[3]. .IE .CH "Implementation-defined features" -For each implementation-defined feature mentioned in the ISO standard +For each implementation-defined feature mentioned in the BSI standard we give the section number, the quotation from that section and the definition. First we quote the definition of implementation-defined: .DS -Those parts of the language which may differ between processors, but which -will be defined for any particular processor. +Possibly differing between processors, but defined for any particular +processor. .DE .IT 6.1.7 -Each string-character shall denote an implementation-defined value of char-type. +Each string-character shall denote an implementation-defined value of the +required char-type. .IS All 7-bits ASCII characters except linefeed LF (10) are allowed. -Note that an apostrophe ' must be doubled within a string. .IE .IT 6.4.2.2 The values of type real shall be an implementation-defined subset -of the real numbers denoted as specified by 6.1.5. +of the real numbers denoted as specified by 6.1.5 bu signed real. .IS The format of reals is not defined in EM. -Even the size of reals depends on the implementation. -The compiler can be instructed, by the f-option, to use a different +Even the size of reals depends on the EM-implementation. +The compiler can be instructed, by the V-option, to use a different size for real values. The size of reals is preset by the calling program \fIack\fP -[4] to -the proper size. -For each implementation of EM the following constants must be defined: - epbase: the base for the exponent part - epprec: the precision of the fraction - epemin: the minimum exponent - epemax: the maximum exponent -.br -These constants must be chosen so that zero and all numbers with -exponent e in the range -.EQ - epemin <= e <= epemax -.EN -and fraction-parts of the form -.EQ - f = +_ f\d1\u.b\u-1\d + ... + f\depprec\u.b\u-epprec\d -.EN -where -.EQ - f\di\u = 0,...,epbase-1 and f\d1\u <> 0 -.EN -are possible values for reals. -All other values of type real are considered illegal. -(See [3] for more information about these constants). -.br -For the known EM implementations these constants are: -.I1 -epbase = 2 -.br -epprec = 24 -.br -epemin = -127 -.br -epemax = +127 -.I2 -ditto +[3] to the proper size. .IE .IT 6.4.2.2 The type char shall be the enumeration of a set of implementation-defined @@ -230,33 +188,17 @@ starting at zero. .IS The normal ASCII ordering is used: ord('0')=48, ord('A')=65, ord('a')=97, etc. .IE -.IT 6.4.3.4 -The largest and smallest values of integer-type -permitted as numbers of a value -of a set-type shall be implementation-defined. +.IT 6.6.5.2 +The post-assertions imply corresponding activities on the external entities, +if any, to which the file-variables are bound. These activities, and the +point at which they are actually performed, shall be +implementation-defined. .IS -The smallest value is 0. The largest value is default 15, but can be -changed by using the i-option of the compiler up to a maximum -of 32767. -The compiler allocates as many bits for set-type variables as are necessary -to store all possible values of the host-type of the base-type of the set, -rounded up to the nearest multiple of 16. -If 8 bits are sufficient then only -8 bits are used if part of a packed structure. -Thus, the variable s, declared by -.EQ - var s: set of '0'..'9'; -.EN -will contain 128 bits, not 10 or 16. -These 128 bits are stored in 16 bytes, both for packed and unpacked sets. -If the host-type of the base-type is integer, then the -number of bits depends on the i-option. -The programmer may specify how many bits to allocate for these sets. -The default is 16, the maximum is 32767. -The effective number of bits is rounded up to the next multiple of 16, or up -to 8 if the number of bits is less than or equal to 8. -Note that the use of set-constructors for sets with more than 256 elements -is far less efficient than for smaller sets. +The reading and writing writing of objects on files is buffered. +This means that when a program terminates abnormally, IO may be +unfinished. Terminal IO is unbuffered. +Files are closed whenever they are rewritten or reset, or on +program termination. .IT 6.7.2.2 The predefined constant maxint shall be of integer-type and shall denote an implementation-defined value, that satisfies the following conditions: @@ -264,7 +206,7 @@ an implementation-defined value, that satisfies the following conditions: .in +5 .ti -4 (a)~All integral values in the closed interval from -maxint to +maxint -shall be values in the integer-type. +shall be values of the integer-type. .ti -4 (b)~Any monadic operation performed on an integer value in this interval shall be correctly performed according to the mathematical rules for @@ -282,49 +224,49 @@ integer arithmetic. The representation of integers in EM is a \fIn\fP*8-bit word using two's complement arithmetic. Where \fIn\fP is called wordsize. -The compiler can only generate code for EM with wordsize 2. -Thus always: -.EQ - maxint = 32767 -.EN -Because the number -32768 may be used to indicate 'undefined', the -range of available integers depends on the EM implementation: -.I1 -\*(ON-32767..+32767. -.br -\*(OF-32768..+32767. -.I2 --32768..+32767. +The range of available integers depends on the EM implementation: +For 2-byte machines, the integers range from -32767 to +32767. For 4-byte +machines, the integers range from -2147483647 to 2147483647. +The number -maxint-1 may be used to indicate 'undefined'. .IE -.IT 6.9.4.2 +.IT 6.7.2.2 +The result of the real arithmetic operators and functions shall be +approximations to the corresponding mathematical results. The accuracy of +this approximation shall be implementation-defined +.IS +Since EM doesn't specify floating point format, it is not possible to +specify the accuracy. When the floating point emulation is used, and the +default size of reals is 8 bytes, the accuracy is 11 bits for the exponent, +and 53 bits for the mantissa. This gives an accuracy of about 16 digits, +and exponents ranging from -309 to +307. +.IE +.IT 6.9.3.1 The default TotalWidth values for integer, Boolean and real types shall be implementation-defined. .IS The defaults are: - integer 6 + integer 6 for 2-byte machines, 11 for 4-byte machines Boolean 5 - real 13 -.IT 6.9.4.5.1 + real 14 +.IT 6.9.3.4.1 ExpDigits, the number of digits written in an exponent part of a real, shall be implementation-defined. .IS -ExpDigits is defined as -.EQ - ceil(log10(log10(2 ** epemax))) -.EN -For the current implementations this evaluates to 2. -.IT 6.9.4.5.1 +ExpDigits is defined as 3. This is sufficient for all implementations +currently available. When the representation would need more than 3 +digits, then the string '***' replaces the exponent. +.IT 6.9.3.4.1 The character written as part of the representation of a real to indicate the beginning of the exponent part shall be implementation-defined, either 'E' or 'e'. .IS The exponent part starts with 'e'. -.IT 6.9.4.6 +.IT 6.9.3.5 The case of the characters written as representation of the Boolean values shall be implementation-defined. .IS The representations of true and false are 'true' and 'false'. -.IT 6.9.6 +.IT 6.9.5 The effect caused by the standard procedure page on a text file shall be implementation-defined. .IS @@ -353,7 +295,7 @@ is opened for reading or writing by a call to the standard procedures reset or rewrite. This gives the programmer the opportunity to manipulate the list of string arguments using the external procedures argc, argv and argshift -available in libpc [7]. +available in libpc [6]. .IT 6.10 The effect of an explicit use of reset or rewrite on the standard textfiles input or output shall be implementation-defined. @@ -361,88 +303,14 @@ on the standard textfiles input or output shall be implementation-defined. The procedures reset and rewrite are no-ops if applied to input or output. .CH "Implementation-dependent features" -For each implementation-dependent feature mentioned in the ISO standard draft, +For each implementation-dependent feature mentioned in the BSI standard, we give the section number, the quotation from that section and the way this feature is treated by the Ack-Pascal system. First we quote the definition of 'implementation-dependent': .DS -Those parts of the language which may differ between processors, -and for which there need not be a definition for a particular processor. +Possibly differing between processors and not necessarily defined for any +particular processor. .DE -.IT 5.1.1 -The method for reporting errors or warnings shall be implementation-dependent. -.IS -The error handling is treated in a following chapter. -.IE -.IT 6.1.4 -Other implementation-dependent directives may be defined. -.IS -Except for the required directive 'forward' the Ack-Pascal compiler recognizes -only one directive: 'extern'. -This directive tells the compiler that the procedure block of this -procedure will not be present in the current program. -The code for the body of this procedure must be included at a later -stage of the compilation process. -.PP -This feature allows one to build libraries containing often used routines. -These routines do not have to be included in all the programs using them. -Maintenance is much simpler if there is only one library module to be -changed instead of many Pascal programs. -.PP -Another advantage is that these library modules may be written in a different -language, for instance C or the EM assembly language. -This is useful if you want to use some specific EM instructions not generated -by the Pascal compiler. Examples are the system call routines and some -floating point conversion routines. -Another motive could be the optimization of some time-critical program parts. -.PP -The use of external routines, however, is dangerous. -The compiler normally checks for the correct number and type of parameters -when a procedure is called and for the result type of functions. -If an external routine is called these checks are not sufficient, -because the compiler can not check whether the procedure heading of the -external routine as given in the Pascal program matches the actual routine -implementation. -It should be the loader's task to check this. -However, the current loaders are not that smart. -Another solution is to check at run time, at least the number of words -for parameters. Some EM implementations check this: -.I1 -\*(ALthe number of words passed as parameters is checked, but this will not catch all faulty cases. -.br -\*(ONnot checked. -.I2 -not checked. -.IE -.PP -For those who wish the use the interface between C and Pascal we -give an incomplete list of corresponding formal parameters in C and Pascal. -.sp 1 -.TS -l l. -Pascal C -a:integer int a -a:char int a -a:boolean int a -a:real double a -a:^type type *a -var a:type type *a -procedure a(pars) struct { - void (*a)() ; - char *static_link ; - } -function a(pars):type struct { - type (*a)() ; - char *static_link ; - } -.TE -The Pascal runtime system uses the following algorithm when calling -function/procedures passed as parameters. -.TS -l l. -if ( static_link ) (*a)(static_link,pars) ; -else (*a)(pars) ; -.TE .IT 6.7.2.1 The order of evaluation of the operands of a dyadic operator shall be implementation-dependent. @@ -461,7 +329,6 @@ Some peculiar evaluations exist for the following cases: 1.~\ the modulo operation is performed by a library routine to check for negative values of the right operand. -.IE .sp .ti -3 2.~\ @@ -481,7 +348,6 @@ compute set2+set1 .CS test set2 and set2+set1 for equality .IE -This is the only case where the right-hand side is computed first. .sp .ti -3 3.~\ @@ -500,6 +366,7 @@ compute set1+set2 .CS test set1 and set1+set2 for equality .IE +.IE .IT 6.7.3 The order of evaluation, accessing and binding of the actual-parameters for functions @@ -507,12 +374,9 @@ shall be implementation-dependent. .IS The order of evaluation is from right to left. .IT 6.8.2.2 -If access to the variable in an assignment-statement involves the indexing of an array -and/or a reference to a field within a variant of a record -and/or the de-referencing of a pointer-variable -and/or a reference to a buffer-variable, -the decision whether these actions precede or follow the evaluation -of the expression shall be implementation-dependent. +The decision as to the order of accessing the variable and evaluating +the expression in an assignment-statement, shall be +implementation-dependent. .IS The expression is evaluated first. .IT 6.8.2.3 @@ -520,7 +384,7 @@ The order of evaluation and binding of the actual-parameters for procedures shall be implementation-dependent. .IS The same as for functions. -.IT 6.9.6 +.IT 6.9.5 The effect of inspecting a text file to which the page procedure was applied during generation is implementation-dependent. @@ -542,74 +406,22 @@ programs involved in the compilation process. Errors of the third class are the errors as defined in the standard by: .DS An error is a violation by a program of the requirements of this standard -such that detection normally requires execution of the program. +that a processor is permitted to leave undetected. .DE .SH "Compiler errors" -The error messages (and the listing) are not generated by the compiler itself. -The compiler only detects errors and writes the errors in condensed form on -an intermediate file. -Each error in condensed form contains: -.IS -.CS -an optional error message parameter (identifier or number). -.CS -an error number -.CS -a line number -.CS -a column number. -.IE +Error are written on the standard error output. Each line has the form: +.br +, line : +.br Every time the compiler detects an error that does not have influence on the code produced by the compiler or on the syntax decisions, a warning messages is given. If only warnings are generated, compilation proceeds and probably results in a correctly compiled program. .PP -The intermediate error file is read by the interface program -\fIack\fP [4], -that produces the error messages. -It uses an other file, the error message file, -to find an error script line. -Whenever this error script line contains the character '%', the error messages -parameter is substituted. -For negative error numbers the message constructed is prepended with 'Warning: '. -.PP -Sometimes the compiler produces several errors for the same file position -(line number, column number). -Only the first of these messages is given, because the others are probably -directly caused by the first one. -If the first one is a warning while one of its successors for that position -is a fatal message, then the warning is promoted to a fatal one. -However, parameterized messages are always given. -.PP -The error messages and listing come in three flavors, selected by flags -given to \fIack\fP [4]: -.in +10 -.sp -.ti -8 -default:no listing, one line per error giving the file name -of the Pascal source file, the line number and the error messages. -.sp -.ti -8 --e:~~~~~for each erroneous line a listing of the line and its predecessor. -The next line contains one or more characters '^' pointing to the -places where an error is detected. -For each error on that line a message follows. -.sp -.ti -8 --E:~~~~~same as for '-e', except that all source lines are listed, -even if the program is perfect. -.IE -.IE -.SH "Other errors detected at compilation time" -Two main categories: file system problems and table overflow. -Problems with the file system may be caused by protection (you may not read -or create files) or by space problems (no space left on device; out of inodes; -too many processes). -Table overflow problems are often caused by peculiar source programs: -very long procedures or functions, a lot of strings. -Table overflow problems can sometimes be cured -by giving a flag (-sl when producing e.out files) to \fIack\fP [4]. +Sometimes the compiler produces several errors for the same line. They are +only shown up to a maximum of 5 errors per line. Warning are also shown up +to a maximum of 5 per line. .PP Extensive treatment of these errors is outside the scope of this manual. .SH "Runtime errors" @@ -617,19 +429,11 @@ Errors detected at run time cause an error message to be generated on the diagnostic output stream (UNIX file descriptor 2). The message consists of the name of the program followed by a message describing the error, possibly followed by the source line number. -Unless the l-option is turned off, the compiler generates code to keep track +Unless the -L-option is turned on, the compiler generates code to keep track of which source line causes which EM instructions to be generated. It depends on the EM implementation whether these LIN instructions -are skipped or executed: -.I1 -LIN instructions are always executed. The old line number is saved and -restored whenever a procedure or function is called. -All error messages contain this line number, except when the l-option -was turned off. -.I2 -same as above, but line numbers are not saved when procedures and functions -are called. -.IE +are skipped or executed. +.PP For each error mentioned in the standard we give the section number, the quotation from that section and the way it is processed by the Pascal-compiler or runtime system. @@ -646,15 +450,7 @@ These errors are marked as non-fatal, all others as fatal. A list of errors with trap number between 0 and 63 (EM errors) can be found in [2]. -Errors with trap number between 64 and 127 (Pascal errors) are listed in [8]. -.IT 6.4.3.3 -It shall be an error if any field-identifier defined within a variant -is used in a field-designator unless the value of the tag-field -is associated with that variant. -.IS -This error is not detected. -Sometimes this feature is used to achieve easy type conversion. -However, using record variants this way is dangerous, error prone and not portable. +Errors with trap number between 64 and 127 (Pascal errors) are listed in [7]. .IT 6.4.6 It shall be an error if a value of type T2 must be assignment-compatible with type T1, while @@ -668,16 +464,12 @@ Array subscripting is done using the EM array instructions. These instructions have three arguments: the array base address, the index and the address of the array descriptor. An array descriptor describes one dimension by three values: -the element size, the lower bound on the index and the number of elements -minus one. -It depends on the EM implementation whether these bounds are checked: -.I1 -\*(ONchecked (array bound error, trap 0, non-fatal). +the lower bound on the index, the number of elements minus one and the +element-size. +It depends on the EM implementation whether these bounds are checked. Since +most implementations don't, an extra compiler flag is added to force these +checks. .br -\*(OFnot checked -.I2 -not checked. -.IE The other places where assignment-compatibility is required are: .IS .CS @@ -690,7 +482,7 @@ procedures read and readln the final value of the for-statement .IE For these places the compiler generates an EM range check instruction, except -when the r-option is turned off, or when the range of values of T2 +when the R-option is turned on, or when the range of values of T2 is enclosed in the range of T1. If the expression consists of a single variable and if that variable is of a subrange type, @@ -702,14 +494,7 @@ If a constant is assigned, then the EM optimizer removes the range check instruction, except when the value is out of bounds. .PP It depends on the EM implementation whether the range check instruction -is executed or skipped: -.I1 -\*(ONchecked (range bound error, trap 1, non-fatal). -.br -\*(OFskipped -.I2 -skipped -.IE +is executed or skipped. .IT 6.4.6 It shall be an error if a value of type T2 must be assignment-compatible with type T1, while T1 and T2 are compatible @@ -718,10 +503,17 @@ is not in the closed interval specified by the base-type of the type T1. .IS This error is not detected. +.IT 6.5.3.3 +It shall be an error if a component of a variant-part of a variant, +where the selector of the variant-part is not a field, +is accessed unless the variant is active for the entirety of each +reference and access to each component of the variant. +.IS +This error is not detected. .IT 6.5.4 It shall be an error if -the pointer-variable has a nil-value or is undefined at the time -it is de-referenced. +the pointer-variable of an identified-variable either denotes a +nil-value or is undefined. .IS The EM definition does not specify the binary representation of pointer values, so that it is not possible to choose an otherwise illegal @@ -730,60 +522,28 @@ Rather arbitrary the compiler uses the integer value zero to represent NIL. For all current implementations this does not cause problems. .PP The size of pointers depends on the implementation and is -preset in the compiler by \fIack\fP [4]. -The compiler can be instructed, by the p-option, to use -any size for pointer objects. +preset in the compiler by \fIack\fP [3]. +The compiler can be instructed, by the V-option, to use +another size for pointer objects. NIL is represented here by the appropriate number of zero words. .PP It depends on the EM implementation whether de-referencing of a pointer -with value NIL causes an error: -.I1 -\*(ONfor every de-reference the pointer value is checked to be legal. -The value NIL is always illegal. -Objects addressed by a NIL pointer always cause an error, except -when they are part of some extraordinary sized structure -(bad pointer, trap 22, fatal). -.br -\*(OFde-referencing for fetching will not cause -an error to occur. -However, if the pointer value is used for a store operation, -a segmentation violation probably results (memory fault, trap 21, fatal). -(Note: this is only true if the interpreter is executed with coinciding -address spaces and protected text part. The interpreter must therefore -be loaded with the '-n' option of the UNIX loader [5]). -.I2 -de-referencing for a fetch operation will not cause an error. -A store operation probably causes an error if the '-n' flag is -specified to \fIack\fP [4] or ld [5] while loading your program. +with value NIL causes an error. .IE -Some implementations of EM initialize all memory cells for newly -created variables with a constant that probably causes an error if that variable -is not initialized with a value of its own type before use. -For each implementation we give whether memory cells are initialized, -with what value, and whether this value causes an error if de-referenced. -.I1 -each memory word is initialized with the bit representation 1000000000000000, -representing -32768 in 2's complement notation. -For most small and medium sized programs this value will cause a segmentation -violation (memory fault, trap 21, fatal). -.I2 -no initialization. -Whenever a pointer is de-referenced, without being properly initialized, -a segmentation violation (memory fault, trap 21, fatal) -or 'bus error' are possible. -.IE -.IT 6.5.5 -It shall be an error if the value of a file-variable f is altered -while the buffer-variable is an actual variable parameter, or -an element of the record-variable-list of a with-statement, or both. +.IT 6.5.4 +It shall be an error to remove the identifying-value of an identified +variable from its pointer-type when a reference to the variable exists. .IS -This error is not detected +When the identified variable is an element of the record-variable-list of +a with_statement, a warning is given at compile-time. Otherwise, this error +is not detected. .IT 6.5.5 -It shall be an error if the value of a file-variable f is altered -by an assignment-statement which contains the buffer-variable f^ in -its left-hand side. +It shall be an error to alter the value of a file-variable f when a +reference to the buffer-variable f^ exists. .IS -This error is not detected. +When f is altered when it is an element of the record-variable-list of a +with-statement, a warning is given. When a buffer-variable is used as a +variable-parameter, an error is given. This is done at compile-time. .IT 6.6.5.2 It shall be an error if the stated pre-assertion does not hold immediately @@ -874,7 +634,7 @@ read error, trap 103, fatal: .br unlikely to happen. Probably caused by hardware problems or by errors elsewhere in your program that destroyed -the file information maintained by the run time system. +the file information maintained by the run time system. .ti -5 truncated, trap 99, fatal: .br @@ -889,16 +649,26 @@ file element is out of range (0..127). Only for text files. .in -10 .IT 6.6.5.3 -It shall be an error to change any variant-part of a variable -allocated by the form new(p,c1,...,cn) from the variant specified. +It shall be an error if a variant of a variant-part within the new +variable becomes active and a different variant of the variant-part is +one of the specified variants. .IS This error is not detected. .IT 6.6.5.3 -It shall be an error if a variable to be disposed had been allocated -using the form new(p,c1,...,cn) with more variants specified than -specified to dispose. +It shall be an error to use dispose(q) if the identifying variable has been +allocated using the form new(p,c1,...,cn). .IS -This error can cause more memory to be freed then was allocated. +This error is not detected. However, this error can cause more memory +to be freed then was allocated. +Dispose causes a fatal trap 73 when memory already on the free +list is freed again. +.IT 6.6.5.3 +It shall be an error to use dispose(q,k1,...,km) if the identifying +variable has been allocated using the form new(p,c1,...,cn) and m is not +equal to n. +.IS +This error is not detected. However, this error can cause more memory +to be freed then was allocated. Dispose causes a fatal trap 73 when memory already on the free list is freed again. .IT 6.6.5.3 @@ -912,95 +682,65 @@ nil-value or is undefined. .IS The same comments apply as for de-referencing NIL or undefined pointers. .IT 6.6.5.3 -It shall be an error if a variable that is identified by the pointer parameter -of dispose (or a component thereof) is currently either an actual -variable parameter, or an element of the record-variable-list of a -with-statement, or both. -.IS -This error is not detected. -.IT 6.6.5.3 -It shall be an error if a referenced-variable created using the second form -of new is used in its entirety -as an operand in an expression, or as the variable in an assignment-statement -or as an actual-parameter. +It shall be an error if a variable created using the second form of new is +accessed by the identified variable of the variable-access of a factor, +of an assignment-statement, or of an actual-parameter. .IS This error is not detected. .IT 6.6.6.2 -It shall be an error if the mathematical defined result of an -arithmetic function would fall outside the set of values -of the indicated result. +It shall be an error if the value of sqr(x) does not exist. .IS -Except for the errors for undefined arguments, -the following errors may occur for the arithmetic functions: -.in +16 -.ti -11 -abs(x):~~~~none. -.ti -11 -sqr(x):~~~~real underflow, trap 5, non-fatal; -.br -real overflow, trap 4, non-fatal -.ti -11 -sin(x):~~~~real underflow, trap 5, non-fatal -.ti -11 -cos(x):~~~~real underflow, trap 5, non-fatal -.ti -11 -exp(x):~~~~error in exp, trap 65, non-fatal (if x>10000); -.br -real underflow, trap 5, non-fatal; -.br -real overflow, trap 4, non-fatal -.ti -11 -ln(x):~~~~~error in ln, trap 66, non-fatal ( if x<=0) -.ti -11 -sqrt(x):~~~error in sqrt, trap 67, non-fatal (if x<0) -.ti -11 -arctan(x):~real underflow, trap 5, non-fatal; -.br -real overflow, trap 4, non-fatal -.in -16 -.IE +This error is detected for real-type arguments (real overflow, +trap 4, non-fatal). .IT 6.6.6.2 -It shall be an error if x in ln(x) is not greater than zero. +It shall be an error if x in ln(x) is smaller than or equal to 0. .IS -See above. +This error is detected (error in ln, trap 66, non-fatal) .IT 6.6.6.2 -It shall be an error if x in sqrt(x) is negative. +It shall be an error if x in sqrt(x) is smaller than 0. .IS -See above. -.IT 6.6.6.2 +This error is detected (error in sqrt, trap 67, non-fatal) +.sp +In addition to these errors, overflow in the expression exp(x) is +detected (error in exp, trap 65, non-fatal; real overflow, trap 4, non-fatal) +.sp +.IT 6.6.6.3 It shall be an error if the integer value of trunc(x) does not exist. .IS -This error is detected (conversion error, trap 10, non-fatal). -.IT 6.6.6.2 +It depends on the implementations whether this error is detected. +The floating-point emulation detects this error (conversion error, +trap 10, non-fatal). +.IT 6.6.6.3 It shall be an error if the integer value of round(x) does not exist. .IS -This error is detected (conversion error, trap 10, non-fatal). -.IT 6.6.6.2 +It depends on the implementations whether this error is detected. +The floating-point emulation detects this error (conversion error, +trap 10, non-fatal). +.IT 6.6.6.4 It shall be an error if the integer value of ord(x) does not exist. .IS This error can not occur, because the compiler will not allow such ordinal types. -.IT 6.6.6.2 +.IT 6.6.6.4 It shall be an error if the character value of chr(x) does not exist. .IS -Except when the r-option is turned off, the compiler generates an EM +Except when the R-option is off, the compiler generates an EM range check instruction. The effect of this instruction depends on the -EM implementation as described before. -.IT 6.6.6.2 +EM implementation. +.IT 6.6.6.4 It shall be an error if the value of succ(x) does not exist. .IS Same comments as for chr(x). -.IT 6.6.6.2 +.IT 6.6.6.4 It shall be an error if the value of pred(x) does not exist. .IS Same comments as for chr(x). .IT 6.6.6.5 -It shall be an error if -f in eof(f) is undefined. +It shall be an error if f in eof(f) is undefined. .IS This error is detected (file not yet open, trap 72, fatal). .IT 6.6.6.5 @@ -1016,101 +756,24 @@ not readable, trap 97, fatal; end of file, trap 98, fatal. .IE .IT 6.7.1 -It shall be an error if any variable or function used as an operand in an expression is -undefined at the time of its use. +It shall be an error if a variable-access used as an operand +in an expression is undefined at the time of its use. .IS -Detection of undefined operands is only possible if there is at least one bit -representation that is not allowed as legal value. -The set of legal values depends on the type of the operand. -To detect undefined operands, all newly created variables must be assigned -a value illegal for the type of the created variable. -The compiler itself does not generate code to initialize newly created variables. -Instead, the compiler generates code to allocate some new memory cells. -It is up to the EM implementation to initialize these memory cells. -However, the EM machine does not know the types of the variables for which -memory cells are allocated. -Therefore, the best an EM implementation can do is to initialize with a value -that is illegal for the most common types of operands. -.PP -For all current EM implementations we will describe whether memory cells -are initialized, which value is used to initialize, for each operand type -whether that value is illegal, and for all operations on all operand -types whether that value is detected as undefined. -.I1 -\*(ONnew memory words are initialized with -32768. -Assignment of this value is always allowed. Errors may occur -whenever undefined operands are used in operations. -.br -.ul -integer: --32768 is illegal. All arithmetic operations (except unary +) cause -an error (undefined integer, trap 8, non-fatal). -Relational operations do not, except for IN when the left operand is undefined. -Printing of -32768 using write is allowed. -.br -.ul -real: -the bit representation of a real, caused by initializing the constituent -memory words with -32768, is illegal. -All arithmetic and relational operations (except unary +) cause an error -(real undefined, trap 9, non-fatal). -Printing causes the same error. -.br -.ul -char: -the value -32768 is illegal. For objects of type 'packed array[] of char' -half the characters will have the value chr(0), which is legal, and the -others will have the value chr(128), outside the valid ASCII range. -The relational operators, however, do not cause an error. -.br -.ul -Boolean: -the value -32768 is illegal. For objects of type 'packed array[] of boolean' -half the booleans will have the value false, while the others have the value v, -where ord(v) = 128, naturally illegal. -However, the Boolean and relational operations do not cause an error. -.br -.ul -set: -undefined operands of type set can not be distinguished from -properly initialized ones. -The set and relational operations, therefore, can never cause an error. -However, if one forgets to initialize a set of character, then spurious -characters like '/', '?', 'O', '_' and 'o' appear. -.sp -\*(OFnew memory cells are initialized with -32768. -The only cases where this value causes an error are when -an undefined operand of type real is used in an arithmetic or relational -operation (except unary +) or when an undefined real is used as an -argument to a standard function. -.I2 -Newly created memory cells are not initialized and therefore -they have a random value. -.IT 6.7.1 -It shall be an error if -the value of any member denoted by any member-designator of the -set-constructor is outside the implementation-defined limits. +The compiler performs some limited checks to see if identifiers are +used before they are set. Since it can not always be sure (one could, for +instance, jump out of a loop), only a warning is generated. When an +expression contains a function-call, an error occur if the +function is not assigned at run-time. +.IT 6.7.2.2 +A term of the form x/y shall be an error if y is zero. .IS -This error is detected (set bound error, trap 2, non-fatal). -.IT 6.7.1 -It shall be an error if -the possible types of an set-constructor do not permit it -to assume a suitable type. -.IS -The compiler allocates as many bits as are necessary to store all -elements of the host-type of the base-type of the set, not the -base-type itself. -Therefore, all possible errors can be detected at compile time. +It depends on the EM implementation whether this error is detected. On some +machines, a trap may occur. .IT 6.7.2.2 It shall be an error if j is zero in 'i div j'. .IS -It depends on the EM implementation whether this error is detected: -.I1 -\*(ONdetected (divide by 0, trap 6, non-fatal). -.br -\*(OFnot detected. -.I2 -not detected. +It depends on the EM implementation whether this error is detected. On some +machines, a trap may occur. .IE .IT 6.7.2.2 It shall be an error if @@ -1122,70 +785,113 @@ It shall be an error if the result of any operation on integer operands is not performed according to the mathematical rules for integer arithmetic. .IS -The reaction depends on the EM implementation: -.I1 -\*(ONerror detected if -.EQ - (result >= 32768) or (result < -32768). -.EN -(integer overflow, trap 3, non-fatal). -Note that if the result is -32768 the use of this value in further operations -may cause an error. -.br -\*(OFnot detected. -.I2 -not detected. +The reaction depends on the EM implementation. Most implementations, +however, will not notice integer overflow. .IT 6.8.3.5 -It shall be an error if none of the case-constants is equal to the value of the -case-index upon entry to the case-statement. +It shall be an error if none of the case-constants is equal to the +value of the case-index upon entry to the case-statement. .IS This error is detected (case error, trap 20, fatal). -.IT 6.8.3.9 -It shall be an error if the final-value of a for-statement is not -assignment-compatible with the control-variable when the -initial-value is assigned to the control-variable. -.IS -It is detected if the control variable leaves -its allowed range of values while stepping -from initial to final value. -This is equivalent with the requirements if the -for-statement is not terminated before -the final value is reached. -.IT 6.9.2 -It shall be an error if the sequence of characters read looking for an integer does not -form a signed-integer as specified in 6.1.5. +.IT 6.9.1 +It shall be an error if the sequence of characters read looking for an +integer does not form a signed-integer as specified in 6.1.5. .IS This error is detected (digit expected, trap 105, non-fatal). -.IT 6.9.2 -It shall be an error if the sequence of characters read looking for a real does not -form a signed-number as specified in 6.1.5. +.IT 6.9.1 +It shall be an error if the sequence of characters read looking for a +real does not form a signed-number as specified in 6.1.5. .IS This error is detected (digit expected, trap 105, non-fatal). -.IT 6.9.2 -It shall be an error if read is applied to f while f is undefined or -not opened for reading. +.IT 6.9.1 +When read is applied to f, it shall be an error if the buffer-variable f^ +is undefined or the pre-assertions for get do not hold. .IS This error is detected (see get(f)). -.IT 6.9.4 -It shall be an error if write is applied to f while f is undefined or -not opened for writing. +.IT 6.9.3 +When write is applied to a textfile f, it shall be an error if f is +undefined or f is opened for reading. .IS -This error is detected (see put(f)). -.IT 6.9.4 -It shall be an error if TotalWidth or FracDigits as specified in -write or writeln procedure calls are less than one. +This error is detected (see put(f)). Furthermore, this error is also +detected when f is not a textfile. +.IT 6.9.3.1 +The values of TotalWidth or FracDigits shall be greater than or equal to +one; it shall be an error if either value is less then one. .IS -This error is not detected. Moreover, it is considered an extension to -allow zero or negative values. -.IT 6.9.6 -It shall be an error if page is applied to f while f is undefined or -not opened for writing. +When either value is less than zero, an error (illegal field width, trap +75, non-fatal) occurs. Zero values are allowed, in order to maintain some +compatibility with the old Ack-Pascal compiler. +.IT 6.9.5 +It shall be an error if the pre-assertion required for writeln(f) doe not +hold prior to the invocation of page(f); .IS This error is detected (see put(f)). .CH "Extensions to the standard" .IS .ti -3 1.~\ +External routines +.sp +Except for the required directive 'forward' the Ack-Pascal compiler recognizes +the directive 'extern'. +This directive tells the compiler that the procedure block of this +procedure will not be present in the current program. +The code for the body of this procedure must be included at a later +stage of the compilation process. +.PP +This feature allows one to build libraries containing often used routines. +These routines do not have to be included in all the programs using them. +Maintenance is much simpler if there is only one library module to be +changed instead of many Pascal programs. +.PP +Another advantage is that these library modules may be written in a different +language, for instance C or the EM assembly language. +This is useful if you want to use some specific EM instructions not generated +by the Pascal compiler. Examples are the system call routines and some +floating point conversion routines. +Another motive could be the optimization of some time-critical program parts. +.PP +The use of external routines, however, is dangerous. +The compiler normally checks for the correct number and type of parameters +when a procedure is called and for the result type of functions. +If an external routine is called these checks are not sufficient, +because the compiler can not check whether the procedure heading of the +external routine as given in the Pascal program matches the actual routine +implementation. +It should be the loader's task to check this. +However, the current loaders are not that smart. +Another solution is to check at run time, at least the number of words +for parameters. Some EM implementations check this. +.PP +For those who wish the use the interface between C and Pascal we +give an incomplete list of corresponding formal parameters in C and Pascal. +.sp 1 +.TS +l l. +Pascal C +a:integer int a +a:char int a +a:boolean int a +a:real double a +a:^type type *a +var a:type type *a +procedure a(pars) struct { + void (*a)() ; + char *static_link ; + } +function a(pars):type struct { + type (*a)() ; + char *static_link ; + } +.TE +The Pascal runtime system uses the following algorithm when calling +function/procedures passed as parameters. +.TS +l l. +if ( static_link ) (*a)(static_link,pars) ; +else (*a)(pars) ; +.TE +.ti -3 +2.~\ Separate compilation. .sp The compiler is able to (separately) compile a collection of declarations, @@ -1211,12 +917,12 @@ directive 'extern' you may use procedures and functions declared in other units. .sp .ti -3 -2.~\ +3.~\ Assertions. .sp -The Ack-Pascal compiler recognizes an additional statement, the assertion. -Assertions can be used as an aid in debugging and documentation. -The syntax is: +When the s-option is off, Ack-Pascal compiler recognizes an additional +statement, the assertion. Assertions can be used as an aid in debugging +and documentation. The syntax is: .EQ assertion = 'assert' Boolean-expression .EN @@ -1232,12 +938,15 @@ An assertion causes an error if the Boolean-expression is false. That is its only purpose. It does not change any of the variables, at least it should not. Therefore, do not use functions with side-effects in the Boolean-expression. -If the a-option is turned off, then assertions are skipped by the +If the a-option is turned on, then assertions are skipped by the compiler. 'assert' is not a word-symbol (keyword) and may be used as identifier. -However, assignment to a variable and calling of a procedure with that name will be impossible. +However, assignment to a variable and calling of a procedure with that +name will be impossible. +If the s-option is turned on, the compiler will not know a thing about +assertions, so using assertions will then give a parse error. .sp .ti -3 -3.~\ +4.~\ Additional procedures. .sp Three additional standard procedures are available: @@ -1247,7 +956,7 @@ Three additional standard procedures are available: halt:~~~a call of this procedure is equivalent to jumping to the end of your program. It is always the last statement executed. The exit status of the program may be supplied -as optional argument. +as optional argument. If not, it will be zero. .ti -8 release: .ti -8 @@ -1263,7 +972,7 @@ Never use mark and release together with dispose! .sp .in -10 .ti -3 -4.~\ +5.~\ UNIX interfacing. .sp If the c-option is turned on, then some special features are available @@ -1285,55 +994,54 @@ constants and variables of type 'string'. String objects may not be allocated on the heap and string pointers may not be de-referenced. Still these strings are very useful in combination with external routines. -The procedure write is extended to print these zero-terminated strings correctly. +The procedure write is extended to print these zero-terminated +strings correctly. .sp .ti -3 -5.~\ +6.~\ Double length (32 bit) integers. .sp -If the d-option is turned on, then the additional type 'long' is known to the compiler. -Long variables have integer values in the range -2147483647..+2147483647. -Long constants may be declared. +If the d-option is turned on, then the additional type 'long' is known +to the compiler. +By default, long variables have integer values in the +range -2147483647..+2147483647, but this can be changed with the -V option +(if the backend can support this). +Long constants can not be declared. +Longs can not be used as control-variables. It is not allowed to form subranges of type long. All operations allowed on integers are also allowed on longs and are indicated by the same operators: '+', '-', '*', '/', 'div', 'mod'. -The procedures read and write have been extended to handle long arguments correctly. +The procedures read and write have been extended to handle long +arguments correctly. It is possible to read longs from a file of integers +and vice-versa, but only if longs and integers have the same size. The default width for longs is 11. -The standard procedures 'abs' and 'sqr' have been extended to work on long arguments. +The standard procedures 'abs' and 'sqr' have been extended to work +on long arguments. Conversion from integer to long, long to real, -real to long and long to integer are automatic, like the conversion from integer to real. +real to long and long to integer are automatic, like the conversion +from integer to real. These conversions may cause a .IS conversion error, trap 10, non-fatal .IE -This last error is only detected in implementation 1, with 'test on'. -Note that all current implementations use target -machine floating point instructions -to perform some of the long operations. -.sp -.ti -3 -6.~\ -Underscore as letter. -.sp -The character '_' may be used in forming identifiers, if the u-option is turned on. .sp .ti -3 7.~\ -Zero field width in write. +Underscore as letter. .sp -Zero or negative TotalWidth arguments to write -are allowed. -No characters are written for character, string or Boolean type arguments then. -A zero or negative FracDigits argument for fixed-point representation of reals causes the -fraction and the character '.' to be suppressed. +The character '_' may be used in forming identifiers, if the u- or U-option +is turned on. It is forbidden to start identifiers with underscores, since +this may cause name-clashes with run-time routines. .sp .ti -3 8.~\ -Alternate symbol representation. +Zero field width in write. .sp -The comment delimiters '(*' and '*)' are recognized and treated like '{' and '}'. -The other alternate representations of symbols are not recognized. +Zero TotalWidth arguments are allowed. No characters are written for +character, string or Boolean type arguments then. A zero FracDigits +argument for fixed-point representation of reals causes the fraction and +the character '.' to be suppressed. .sp .ti -3 9.~\ @@ -1348,29 +1056,11 @@ C style comments, /*......*/, are removed by the C preprocessor, thus C comments inside Pascal programs are also removed when they are fed through the preprocessor. .CH "Deviations from the standard" -Ack-Pascal deviates from the (March 1980) standard proposal in the following ways: +Ack-Pascal deviates from the standard proposal in the following ways: .IS .ti -3 1.~\ -Only the first 8 characters of identifiers are significant, -as requested by all standard proposals prior to March 1980. -In that proposal, however, the sentence -.DS -"A conforming program should not have its meaning altered -by the truncation of its identifiers to eight characters -or the truncation of its labels to four digits." -.DE -is missing. -.sp -.ti -3 -2.~\ -The character sequences 'procedur', 'procedur8', 'functionXyZ' etc. are -all erroneously classified as the word-symbols 'procedure' and 'function'. -.sp -.ti -3 -3.~\ -Standard procedures and functions are not allowed as parameters in Ack-Pascal, -conforming to all previous standard proposals. +Standard procedures and functions are not allowed as parameters in Ack-Pascal. You can obtain the same result with negligible loss of performance by declaring some user routines like: .EQ @@ -1381,12 +1071,9 @@ by declaring some user routines like: .EN .sp .ti -3 -4.~\ -The scope of identifiers and labels should start at the beginning of the block -in which these identifiers or labels are declared. -The Ack-Pascal compiler, as most other one pass compilers, deviates in this respect, -because the scope of variables and labels start -at their defining-point. +2.~\ +The standard procedures read, readln, write and writeln are implemented as +word-symbols, and can therefore not be redeclared. .CH "Compiler options" Some options of the compiler may be controlled by using "{$....}". Each option consists of a lower case letter followed by +, - or an unsigned @@ -1414,17 +1101,11 @@ this option, if on, allows you to use variables of type 'long'. Default -. .sp .ti -8 -f~~\ -the size of reals can be changed by this option. should be specified in 8-bit bytes. -The default in most implementations is 8, but other values can -occur. -.sp -.ti -8 i~~\ with this flag the setsize for a set of integers can be manipulated. The number must be the number of bits per set. -The default value is 16, just fitting in one word on the PDP and many other minis. +The default value is wordsize-1. .sp .ti -8 l~+/-~~~\ @@ -1432,14 +1113,10 @@ if + then code is inserted to keep track of the source line number. When this flag is switched on and off, an incorrect line number may appear if the error occurs in a part of your program for which this flag is off. These same line numbers are used for the profile, flow and count options -of the EM interpreter em [6]. +of the EM interpreter em [5]. Default +. .sp .ti -8 -p~~the size of pointers can be changed by this option. should be specified in bytes. -Default 2 in most implementations. -.sp -.ti -8 r~+/-~~~\ if + then code is inserted to check subrange variables against lower and upper subrange limits. @@ -1453,46 +1130,29 @@ it will generate a warning. Default -. .sp .ti -8 t~+/-~~~\ -if + then each time a procedure is entered, the routine 'procentry' -is called. -The compiler checks this flag just before the first symbol that follows the -first 'begin' of the body of the procedure. -Also, when the procedure exits, then the procedure 'procexit' is called -if the t flag is on just before the last 'end' of the procedure body. -Both 'procentry' and 'procexit' have a packed array of 8 characters as a parameter. -Default procedures are present in the run time library. +if + then each time a procedure is entered, the routine 'procentry' is +called, and each time a procedure exits, the procedure 'procexit' is +called. Both 'procentry' and 'procexit' have a 'string' as parameter. This +means that when a user specifies his or her own procedures, the c-option +must be used. Default procedures are present in the run time library. Default -. .sp .ti -8 u~+/-~~~\ -if + then the character '_' is treated like a lower case letter, +if + then the character '_' is treated like a letter, so that it may be used in identifiers. -Procedure and function identifiers starting with an underscore may cause problems, -because they may collide with library routine names. +Procedure and function identifiers are not allowed to start with an +underscore because they may collide with library routine names. Default -. .in 0 .sp -Seven of these flags (c, d, f, i, p, s and u) are only effective when they appear -before the 'program' symbol. The others may be switched on and off. +Some of these flags (c, d, i, s, u, C and U) are only effective when +they appear before the 'program' symbol. The others may be switched +on and off. .PP -A second method of passing options to the compiler ia available. -This method uses the file on which the compact EM code will be written. -The compiler starts reading from this file scanning for options -in the same format as used normally, except for the comment delimiters and -the dollar sign. -All options found on the file override the options set in your program. -Note that the compact code file must always exist before the compiler is called. -.PP -The user interface program \fIack\fP[4] -takes care of creating this file normally -and also writes one of its options onto this file. -The user can specify, for instance, without changing any character in its -Pascal program, that the compiler must include code for -procedure/function tracing. -.PP -Another very powerful debugging tool is the knowledge that inaccessible -statements and useless tests are removed by the EM optimizer. -For instance, a statement like: +A very powerful debugging tool is the knowledge that inaccessible statements +and useless tests are removed by the EM optimizer. For instance, a +statement like: .sp .nf if debug then @@ -1514,13 +1174,7 @@ in order of decreasing index. .in +5 .ti -5 [1]~~\ -ISO standard proposal ISO/TC97/SC5-N462, dated February 1979. -The same proposal, in slightly modified form, can be found in: -A.M.Addyman e.a., "A draft description of Pascal", -Software, practice and experience, May 1979. -An improved version, received March 1980, -is followed as much as possible for the -current Ack-Pascal. +BSI standard BS 6192: 1982 (ISO 7185). .sp .ti -5 [2]~~\ @@ -1530,26 +1184,20 @@ Informatica rapport IR-81. .sp .ti -5 [3]~~\ -W.S.Brown, S.I.Feldman, "Environment parameters and basic functions -for floating-point computation", -Bell Laboratories CSTR #72. -.sp -.ti -5 -[4]~~\ UNIX manual ack(I). .sp .ti -5 -[5]~~\ +[4]~~\ UNIX manual ld(I). .sp .ti -5 -[6]~~\ +[5]~~\ UNIX manual em(I). .sp .ti -5 -[7]~~\ +[6]~~\ UNIX manual libpc(VII) .sp .ti -5 -[8]~~\ +[7]~~\ UNIX manual pc_prlib(VII)