[9] | 1 | .TH ACK 7
|
---|
| 2 | .SH NAME
|
---|
| 3 | ACK \- Additional information on the Amsterdam Compiler Kit compilers
|
---|
| 4 | .SH DESCRIPTION
|
---|
| 5 | .de SP
|
---|
| 6 | .if t .sp 0.4
|
---|
| 7 | .if n .sp
|
---|
| 8 | ..
|
---|
| 9 | .de XS
|
---|
| 10 | .SP
|
---|
| 11 | .in +.5i
|
---|
| 12 | .nf
|
---|
| 13 | ..
|
---|
| 14 | .de XE
|
---|
| 15 | .fi
|
---|
| 16 | .in -.5i
|
---|
| 17 | .SP
|
---|
| 18 | ..
|
---|
| 19 | .de NS
|
---|
| 20 | .PP
|
---|
| 21 | .B ANS\ \\$1
|
---|
| 22 | ..
|
---|
| 23 | .de UX
|
---|
| 24 | \s-2UNIX\s+2
|
---|
| 25 | ..
|
---|
| 26 | .de MX
|
---|
| 27 | .if n MINIX 3
|
---|
| 28 | .if t \s-1MINIX 3\s-1
|
---|
| 29 | ..
|
---|
| 30 | .if n .ds Mx MINIX 3
|
---|
| 31 | .if t .ds Mx \s-1MINIX 3\s-1
|
---|
| 32 | .if n .ds Mp Minix-PC
|
---|
| 33 | .if t .ds Mx \s-2MINIX-PC\s+2
|
---|
| 34 | .if n .ds Mv Minix-vmd
|
---|
| 35 | .if t .ds Mv \s-1MINIX 3\s-1-vmd
|
---|
| 36 | .if n .ds Cw \fR
|
---|
| 37 | .if t .ds Cw \fC
|
---|
| 38 | .de CW
|
---|
| 39 | .if n .ft R
|
---|
| 40 | .if t .ft C
|
---|
| 41 | ..
|
---|
| 42 | .\"
|
---|
| 43 | These are the details on the Amsterdam Compiler Kit compilers for the
|
---|
| 44 | languages C, Modula-2, and Pascal. The design decisions that were made
|
---|
| 45 | where the respective standards allowed or mandated this, and the extensions
|
---|
| 46 | that were implemented.
|
---|
| 47 | .SH "ANSI C REPORT"
|
---|
| 48 | This section specifies the implementation-defined behavior of the ANSI-C
|
---|
| 49 | compiler as required by ANS X3.159-1989.
|
---|
| 50 | .NS A.6.3.1
|
---|
| 51 | .IP \(bu
|
---|
| 52 | Diagnostics are placed on the standard error output. They have the
|
---|
| 53 | following specification:
|
---|
| 54 | .XS
|
---|
| 55 | "<file>", line <nr>: [(<class>)] <diagnostic>
|
---|
| 56 | .XE
|
---|
| 57 | There are three classes of diagnostics: 'error', 'strict' and 'warning'.
|
---|
| 58 | When the class is 'error', the class specification is absent.
|
---|
| 59 | The class 'strict' is used for violations of the standard which are
|
---|
| 60 | not severe enough to stop compilation, for example the occurrence
|
---|
| 61 | of non white-space after an '#endif' preprocessing
|
---|
| 62 | directive. The class 'warning' is used for legal but dubious
|
---|
| 63 | constructions, for example the declaration of a structure-tag in a
|
---|
| 64 | parameter type list.
|
---|
| 65 | .NS A.6.3.2
|
---|
| 66 | .IP \(bu
|
---|
| 67 | The function 'main' can have zero or two parameters. When it has two
|
---|
| 68 | parameters, the first parameter is an integer specifying the number of
|
---|
| 69 | arguments on the command line (including the command). The second
|
---|
| 70 | parameter is a pointer to an array of pointers to the arguments
|
---|
| 71 | (as strings).
|
---|
| 72 | .IP \(bu
|
---|
| 73 | Interactive devices are terminals.
|
---|
| 74 | .NS A.6.3.3
|
---|
| 75 | .IP \(bu
|
---|
| 76 | The number of significant characters is 64.
|
---|
| 77 | Corresponding upper-case and lower-case letters are different.
|
---|
| 78 | .NS A.6.3.4
|
---|
| 79 | .IP \(bu
|
---|
| 80 | The compiler assumes ASCII-characters in both the source and execution
|
---|
| 81 | character set.
|
---|
| 82 | .IP \(bu
|
---|
| 83 | There are no multibyte characters.
|
---|
| 84 | .IP \(bu
|
---|
| 85 | There are 8 bits in a character.
|
---|
| 86 | .IP \(bu
|
---|
| 87 | Character constants that cannot be represented in 8 bits
|
---|
| 88 | are truncated.
|
---|
| 89 | .IP \(bu
|
---|
| 90 | Character constants that are more than 1 character wide will have the
|
---|
| 91 | first character specified in the least significant byte.
|
---|
| 92 | .IP \(bu
|
---|
| 93 | The only supported locale is 'C'.
|
---|
| 94 | .IP \(bu
|
---|
| 95 | A plain 'char' has the same range of values as 'signed char'.
|
---|
| 96 | .NS A.6.3.5
|
---|
| 97 | .IP \(bu
|
---|
| 98 | The i80x86 and 68000 both have a two's complement binary-number system.
|
---|
| 99 | Shorts are 2 bytes; ints are 2 bytes under 16-bits \*(Mp and 68000 \*(Mx, 4
|
---|
| 100 | bytes under 32-bits \*(Mp; longs occupy 4 bytes.
|
---|
| 101 | .IP \(bu
|
---|
| 102 | Converting an integer to a shorter signed integer is implemented by
|
---|
| 103 | ignoring the high-order byte(s) of the former.
|
---|
| 104 | Converting a unsigned integer to a signed integer of the same type is
|
---|
| 105 | only done in administration. This means that the bit-pattern remains
|
---|
| 106 | unchanged.
|
---|
| 107 | .IP \(bu
|
---|
| 108 | The result of bitwise operations on signed integers are what can be
|
---|
| 109 | expected on a two's complement machine.
|
---|
| 110 | .IP \(bu
|
---|
| 111 | When either operand is negative, the result of the / operator is the
|
---|
| 112 | largest integer less than or equal to the algebraic quotient.
|
---|
| 113 | The sign of the remainder on integer division is the sign of the
|
---|
| 114 | enumerator.
|
---|
| 115 | .IP \(bu
|
---|
| 116 | The right-shift of a negative value is negative.
|
---|
| 117 | .NS A.6.3.6
|
---|
| 118 | .IP \(bu
|
---|
| 119 | The compiler uses IEEE format for floating-point numbers.
|
---|
| 120 | High-precision floating-point is used for constant folding.
|
---|
| 121 | .IP \(bu
|
---|
| 122 | Truncation is done to the nearest floating-point number that can
|
---|
| 123 | be represented.
|
---|
| 124 | .NS A.6.3.7
|
---|
| 125 | .IP \(bu
|
---|
| 126 | The type of the sizeof-operator (also known as size_t) is 'unsigned int'.
|
---|
| 127 | .IP \(bu
|
---|
| 128 | Casting an integer to a pointer or vice versa has no effect in
|
---|
| 129 | bit-pattern when the sizes are equal. Otherwise the value will be
|
---|
| 130 | truncated or zero-extended (depending on the direction of the
|
---|
| 131 | conversion and the relative sizes).
|
---|
| 132 | .IP \(bu
|
---|
| 133 | The type of a 'ptrdiff_t' is 'int' on \*(Mp, and 'long' on the 68000
|
---|
| 134 | \*(Mx versions.
|
---|
| 135 | .NS A.6.3.8
|
---|
| 136 | .IP \(bu
|
---|
| 137 | Since the front end has only limited control over the registers, it can
|
---|
| 138 | only make it more likely that variables that are declared as
|
---|
| 139 | registers also end up in registers. The only things that can possibly be
|
---|
| 140 | put into registers are plain ints and pointers.
|
---|
| 141 | .NS A.6.3.9
|
---|
| 142 | .IP \(bu
|
---|
| 143 | When a member of a union object is accessed using a member of a
|
---|
| 144 | different type, the resulting value will usually be garbage. The
|
---|
| 145 | compiler makes no effort to catch these errors.
|
---|
| 146 | .IP \(bu
|
---|
| 147 | The alignment of types under 16-bit \*(Mp is 1 byte for characters and 2
|
---|
| 148 | bytes for all other types. Under other MINIX 3 versions 'int' and smaller
|
---|
| 149 | types are aligned to a multiple of their size, bigger scalar types are
|
---|
| 150 | aligned like 'int'. Arrays have the same alignment as their elements;
|
---|
| 151 | structs and unions are aligned like their field with the worst alignment.
|
---|
| 152 | .IP \(bu
|
---|
| 153 | A plain 'int' bit-field is taken as a 'signed int'. This means that
|
---|
| 154 | a field with a size 1 bit-field can only store the values 0 and \(mi1.
|
---|
| 155 | .IP \(bu
|
---|
| 156 | In bit-fields, high-order bits are allocated first.
|
---|
| 157 | .IP \(bu
|
---|
| 158 | An enum has the same size as a plain 'int'.
|
---|
| 159 | .NS A.6.3.10
|
---|
| 160 | .IP \(bu
|
---|
| 161 | An access to a volatile object is either a load or a store. Just
|
---|
| 162 | mentioning a volatile variable is not enough.
|
---|
| 163 | E.g. the statement 'x;' where x is declared volatile, does not
|
---|
| 164 | constitute an access. When a volatile object should be read, but its
|
---|
| 165 | value ignored, 'if (x);' should do the trick.
|
---|
| 166 | .NS A.6.3.11
|
---|
| 167 | .IP \(bu
|
---|
| 168 | There is no fixed limit on the number of declarators that may modify an
|
---|
| 169 | arithmetic, structure or union type, although specifying too many may
|
---|
| 170 | cause the compiler to run out of memory.
|
---|
| 171 | .NS A.6.3.12
|
---|
| 172 | .IP \(bu
|
---|
| 173 | The maximum number of cases in a switch-statement is in the order of
|
---|
| 174 | 1e9, although the compiler may run out of memory somewhat earlier.
|
---|
| 175 | .NS A.6.3.13
|
---|
| 176 | .IP \(bu
|
---|
| 177 | Since both the preprocessor and the compiler assume ASCII-characters,
|
---|
| 178 | a single character constant in a conditional-inclusion directive
|
---|
| 179 | matches the same value in the execution character set.
|
---|
| 180 | .IP \(bu
|
---|
| 181 | The preprocessor recognizes \fI\(enI...\fR command-line options. The
|
---|
| 182 | directories thus specified are searched first. After that, /usr/include is
|
---|
| 183 | visited.
|
---|
| 184 | .IP \(bu
|
---|
| 185 | Quoted names are first looked for in the directory in which the file
|
---|
| 186 | which does the include resides.
|
---|
| 187 | .IP \(bu
|
---|
| 188 | The characters in a h- or q- char-sequence are taken to be
|
---|
| 189 | .UX
|
---|
| 190 | paths.
|
---|
| 191 | .IP \(bu
|
---|
| 192 | Neither the front-end nor the preprocessor know any pragmas.
|
---|
| 193 | .IP \(bu
|
---|
| 194 | Since the compiler runs on
|
---|
| 195 | .MX ,
|
---|
| 196 | _\^_DATE_\^_ and _\^_TIME_\^_ will always be
|
---|
| 197 | defined.
|
---|
| 198 | .NS A.6.3.14
|
---|
| 199 | .IP \(bu
|
---|
| 200 | NULL is defined as ((void *)0). This in order to detect dubious
|
---|
| 201 | constructions like 'int x = NULL;'.
|
---|
| 202 | .IP \(bu
|
---|
| 203 | The diagnostic printed by 'assert' is as follows:
|
---|
| 204 | .XS
|
---|
| 205 | Assertion "<expr>" failed, file "<file>", line <line>
|
---|
| 206 | .XE
|
---|
| 207 | where <expr> is the argument to the assert macro, printed as string.
|
---|
| 208 | (the <file> and <line> should be clear)
|
---|
| 209 | .IP \(bu
|
---|
| 210 | The sets for character test macros for the C locale are as follows:
|
---|
| 211 | .XS
|
---|
| 212 | .ta +\w'isalnum 'u
|
---|
| 213 | \fBName Set\fR
|
---|
| 214 | \fIisalnum\fR 0-9A-Za-z
|
---|
| 215 | \fIisalpha\fR A-Za-z
|
---|
| 216 | \fIiscntrl\fR \e000-\e037\e177
|
---|
| 217 | \fIislower\fR a-z
|
---|
| 218 | \fIisupper\fR A-Z
|
---|
| 219 | \fIisprint\fR \e040-\e176
|
---|
| 220 | .DT
|
---|
| 221 | .XE
|
---|
| 222 | As an addition, there is an \fIisascii\fR macro, which tests whether a character
|
---|
| 223 | is an ASCII character. Characters in the range from \e000 to \e177 are ASCII
|
---|
| 224 | characters.
|
---|
| 225 | .IP \(bu
|
---|
| 226 | The behavior of ACK mathematical functions on domain error is as follows:
|
---|
| 227 | .XS
|
---|
| 228 | .ta +\w'log10 'u
|
---|
| 229 | \fBName Returns\fR
|
---|
| 230 | \fIasin\fR 0.0
|
---|
| 231 | \fIacos\fR 0.0
|
---|
| 232 | \fIatan2\fR 0.0
|
---|
| 233 | \fIfmod\fR 0.0
|
---|
| 234 | \fIlog\fR \(miHUGE_VAL
|
---|
| 235 | \fIlog10\fR \(miHUGE_VAL
|
---|
| 236 | \fIpow\fR 0.0
|
---|
| 237 | \fIsqrt\fR 0.0
|
---|
| 238 | .DT
|
---|
| 239 | .XE
|
---|
| 240 | \*(Mv uses the BSD4.4 C library and the Sun FDLIBM C math library instead
|
---|
| 241 | of the ACK library. See
|
---|
| 242 | .BR math (3)
|
---|
| 243 | for details about the math functions. The \*(Mv libraries offer at
|
---|
| 244 | least the same functionality as the ACK library.
|
---|
| 245 | .IP \(bu
|
---|
| 246 | Underflow range errors do not cause \fIerrno\fR to be set.
|
---|
| 247 | .IP \(bu
|
---|
| 248 | The function \fIfmod\fR returns 0.0 and sets \fIerrno\fR to EDOM when the second
|
---|
| 249 | argument is 0.0.
|
---|
| 250 | .IP \(bu
|
---|
| 251 | The set of signals for the \fIsignal\fR function is as described by
|
---|
| 252 | .BR sigaction (2).
|
---|
| 253 | .IP \(bu
|
---|
| 254 | A text-stream need not end in a new-line character.
|
---|
| 255 | .IP \(bu
|
---|
| 256 | White space characters before a new-line appear when read in.
|
---|
| 257 | .IP \(bu
|
---|
| 258 | There may be any number of null characters appended to a binary
|
---|
| 259 | stream.
|
---|
| 260 | .IP \(bu
|
---|
| 261 | The file position indicator of an append mode stream is initially
|
---|
| 262 | positioned at the beginning of the file.
|
---|
| 263 | .IP \(bu
|
---|
| 264 | A write on a text stream does not cause the associated file to be
|
---|
| 265 | truncated beyond that point.
|
---|
| 266 | .IP \(bu
|
---|
| 267 | The buffering intended by the standard is fully supported.
|
---|
| 268 | .IP \(bu
|
---|
| 269 | A zero-length file actually exists.
|
---|
| 270 | .IP \(bu
|
---|
| 271 | A file name can consist of any character, except for the '\e0' and
|
---|
| 272 | the '/'.
|
---|
| 273 | .IP \(bu
|
---|
| 274 | A file can be open multiple times.
|
---|
| 275 | .IP \(bu
|
---|
| 276 | When a \fIremove\fR is done on an open file, reading and writing behave
|
---|
| 277 | just as can be expected from a non-removed file. When the associated
|
---|
| 278 | stream is closed, however, all written data will be lost.
|
---|
| 279 | .IP \(bu
|
---|
| 280 | When a file exists prior to a call to \fIrename\fR, it is removed.
|
---|
| 281 | .IP \(bu
|
---|
| 282 | The %p conversion in \fIfprintf\fR has the same effect as %#x on \*(Mp and
|
---|
| 283 | %#lx on the 68000 versions of \*(Mx.
|
---|
| 284 | .IP \(bu
|
---|
| 285 | The %p conversion in \fIfscanf\fR has the same effect as %x on \*(Mp and
|
---|
| 286 | %lx on the 68000 versions of \*(Mx.
|
---|
| 287 | .IP \(bu
|
---|
| 288 | A \(mi character that is neither the first nor the last character in the
|
---|
| 289 | scanlist for %[ conversion is taken to be a range indicator. When the
|
---|
| 290 | first character has a higher ASCII-value than the second, the \(mi will
|
---|
| 291 | just be put into the scanlist.
|
---|
| 292 | .IP \(bu
|
---|
| 293 | The value of \fIerrno\fR when \fIfgetpos\fR or \fIftell\fR failed is that of \fIlseek\fR.
|
---|
| 294 | This means:
|
---|
| 295 | .XS
|
---|
| 296 | .ta +\w'ESPIPE 'u +\w'\- 'u
|
---|
| 297 | EBADF \- when the stream is not valid
|
---|
| 298 | ESPIPE \- when fildes is associated with a pipe
|
---|
| 299 | EINVAL \- the resulting file pointer would be negative
|
---|
| 300 | .XE
|
---|
| 301 | .IP \(bu
|
---|
| 302 | The messages generated by \fIperror\fR depend on the value of \fIerrno\fR.
|
---|
| 303 | The mapping of errors to strings is done by \fIstrerror\fR.
|
---|
| 304 | .IP \(bu
|
---|
| 305 | When the requested size is zero, \fImalloc\fR, \fIcalloc\fR and \fIrealloc\fR
|
---|
| 306 | return a null-pointer under \*(Mx. Under \*(Mv a unique non-null pointer is
|
---|
| 307 | returned.
|
---|
| 308 | .IP \(bu
|
---|
| 309 | When \fIabort\fR is called, output buffers will be flushed. Temporary files
|
---|
| 310 | (made with the \fItmpfile\fR function) will have disappeared when SIGABRT
|
---|
| 311 | is not caught or ignored.
|
---|
| 312 | .IP \(bu
|
---|
| 313 | The \fIexit\fR function returns the low-order eight bits of its argument
|
---|
| 314 | to the environment.
|
---|
| 315 | .IP \(bu
|
---|
| 316 | The predefined environment names are controlled by the user.
|
---|
| 317 | Setting environment variables is done through the \fIputenv\fR function.
|
---|
| 318 | This function accepts a pointer to char as its argument.
|
---|
| 319 | To set, for example, the environment variable TERM to a230 one writes
|
---|
| 320 | .XS
|
---|
| 321 | static char terminal[] = "TERM=a230";
|
---|
| 322 | putenv(terminal);
|
---|
| 323 | .XE
|
---|
| 324 | The argument to \fIputenv\fR is stored in an internal table, so malloc'ed
|
---|
| 325 | strings cannot be freed until another call to \fIputenv\fR (which sets the
|
---|
| 326 | same environment variable) is made. The argument to \fIputenv\fR must be
|
---|
| 327 | writable, which means that officially, the argument cannot be a string
|
---|
| 328 | constant.
|
---|
| 329 | The function returns 1 if it fails, 0 otherwise.
|
---|
| 330 | .LP
|
---|
| 331 | .IP \(bu
|
---|
| 332 | The argument to \fIsystem\fR is passed as argument to \fI/bin/sh \(enc\fR.
|
---|
| 333 | .IP \(bu
|
---|
| 334 | The strings returned by \fIstrerror\fR depend on \fIerrno\fR. They are
|
---|
| 335 | listed in
|
---|
| 336 | .BR intro (2).
|
---|
| 337 | Everything else causes \fIstrerror\fR to return "unknown error" under \*(Mx,
|
---|
| 338 | or the result of sprintf("Error %d", errno) under \*(Mv.
|
---|
| 339 | .IP \(bu
|
---|
| 340 | The local time zone is per default GMT. This can be
|
---|
| 341 | changed through the TZ environment variable, e.g. TZ=EST6.
|
---|
| 342 | See
|
---|
| 343 | .BR TZ (5).
|
---|
| 344 | .IP \(bu
|
---|
| 345 | The \fIclock\fR function returns the number of ticks since process
|
---|
| 346 | startup.
|
---|
| 347 | .SS References
|
---|
| 348 | .IP [1]
|
---|
| 349 | ANS X3.159-1989
|
---|
| 350 | .ft I
|
---|
| 351 | American National Standard for Information Systems -
|
---|
| 352 | Programming Language C
|
---|
| 353 | .ft R
|
---|
| 354 | .SH "THE MINIX MODULA-2 COMPILER"
|
---|
| 355 | This section describes the implementation-specific features of the
|
---|
| 356 | .MX
|
---|
| 357 | Modula-2 compiler.
|
---|
| 358 | It is not intended to teach Modula-2 programming.
|
---|
| 359 | For a description of the Modula-2 language,
|
---|
| 360 | the reader is referred to [1].
|
---|
| 361 | .SS "The language implemented"
|
---|
| 362 | .PP
|
---|
| 363 | This paragraph discusses the deviations from the Modula-2 language as described
|
---|
| 364 | in the 'Report on The Programming Language Modula-2',
|
---|
| 365 | as it appeared in [1],
|
---|
| 366 | from now on referred to as 'the Report'.
|
---|
| 367 | Also,
|
---|
| 368 | the Report sometimes leaves room for interpretation.
|
---|
| 369 | The section numbers
|
---|
| 370 | mentioned are the section numbers of the Report.
|
---|
| 371 | .SS "Syntax (section 2)"
|
---|
| 372 | .PP
|
---|
| 373 | The syntax recognized is that of the Report,
|
---|
| 374 | with some extensions to
|
---|
| 375 | also recognize the syntax of an earlier definition,
|
---|
| 376 | given in [2].
|
---|
| 377 | Only one compilation unit per file is accepted.
|
---|
| 378 | .SS "Vocabulary and Representation (section 3)"
|
---|
| 379 | .PP
|
---|
| 380 | The input '\*(Cw10..\fR' is parsed as two tokens: '\*(Cw10\fR' and '\*(Cw..\fR'.
|
---|
| 381 | .PP
|
---|
| 382 | The empty string \*(Cw""\fR has type
|
---|
| 383 | .XS
|
---|
| 384 | .CW
|
---|
| 385 | ARRAY [0 .. 0] OF CHAR
|
---|
| 386 | .ft P
|
---|
| 387 | .XE
|
---|
| 388 | and contains one character: \*(Cw0C\fR.
|
---|
| 389 | .PP
|
---|
| 390 | When the text of a comment starts with a '\*(Cw$\fR',
|
---|
| 391 | it may be a pragma.
|
---|
| 392 | Currently,
|
---|
| 393 | the following pragmas exist:
|
---|
| 394 | .nf
|
---|
| 395 | .SP
|
---|
| 396 | .CW
|
---|
| 397 | (*$F (F stands for Foreign) *)
|
---|
| 398 | (*$R[+|-] (Runtime checks, on or off, default on) *)
|
---|
| 399 | (*$A[+|-] (Array bound checks, on or off, default off) *)
|
---|
| 400 | (*$U (Allow for underscores within identifiers) *)
|
---|
| 401 | .ft P
|
---|
| 402 | .SP
|
---|
| 403 | .fi
|
---|
| 404 | The Foreign pragma is only meaningful in a \*(CwDEFINITION MODULE\fR,
|
---|
| 405 | and indicates that this
|
---|
| 406 | \*(CwDEFINITION MODULE\fR describes an interface to a module written in another
|
---|
| 407 | language (for instance C or Pascal).
|
---|
| 408 | Runtime checks that can be disabled are:
|
---|
| 409 | range checks,
|
---|
| 410 | \*(CwCARDINAL\fR overflow checks,
|
---|
| 411 | checks when assigning a \*(CwCARDINAL\fR to an \*(CwINTEGER\fR and vice versa,
|
---|
| 412 | and checks that \*(CwFOR\fR-loop control-variables are not changed
|
---|
| 413 | in the body of the loop.
|
---|
| 414 | Array bound checks can be enabled,
|
---|
| 415 | because many EM implementations do not
|
---|
| 416 | implement the array bound checking of the EM array instructions.
|
---|
| 417 | When enabled,
|
---|
| 418 | the compiler generates a check before generating an
|
---|
| 419 | EM array instruction.
|
---|
| 420 | Even when underscores are enabled,
|
---|
| 421 | they still may not start an identifier.
|
---|
| 422 | .PP
|
---|
| 423 | Constants of type \*(CwLONGINT\fR are integers with a suffix letter \*(CwD\fR
|
---|
| 424 | (for instance \*(Cw1987D\fR).
|
---|
| 425 | Constants of type \*(CwLONGREAL\fR have suffix \*(CwD\fR if a scale factor is missing,
|
---|
| 426 | or have \*(CwD\fR in place of \*(CwE\fR in the scale factor (f.i. \*(Cw1.0D\fR,
|
---|
| 427 | \*(Cw0.314D1\fR).
|
---|
| 428 | This addition was made,
|
---|
| 429 | because there was no way to indicate long constants,
|
---|
| 430 | and also because the addition was made in Wirth's newest Modula-2 compiler.
|
---|
| 431 | .SS "Declarations and scope rules (section 4)"
|
---|
| 432 | .PP
|
---|
| 433 | Standard identifiers are predeclared,
|
---|
| 434 | and valid in all
|
---|
| 435 | parts of a program.
|
---|
| 436 | They are called \fIpervasive\fR.
|
---|
| 437 | Unfortunately,
|
---|
| 438 | the Report does not state how this pervasiveness is accomplished.
|
---|
| 439 | However,
|
---|
| 440 | page 87 of [1] states: 'Standard identifiers are automatically
|
---|
| 441 | imported into all modules'.
|
---|
| 442 | Our implementation therefore allows
|
---|
| 443 | redeclarations of standard identifiers within procedures,
|
---|
| 444 | but not within
|
---|
| 445 | modules.
|
---|
| 446 | .SS "Constant expressions (section 5)"
|
---|
| 447 | .PP
|
---|
| 448 | Each operand of a constant expression must be a constant:
|
---|
| 449 | a string,
|
---|
| 450 | a number,
|
---|
| 451 | a set,
|
---|
| 452 | an enumeration literal,
|
---|
| 453 | a qualifier denoting a
|
---|
| 454 | constant expression,
|
---|
| 455 | a type transfer with a constant argument,
|
---|
| 456 | or one of the standard procedures
|
---|
| 457 | \*(CwABS\fR,
|
---|
| 458 | \*(CwCAP\fR,
|
---|
| 459 | \*(CwCHR\fR,
|
---|
| 460 | \*(CwLONG\fR,
|
---|
| 461 | \*(CwMAX\fR,
|
---|
| 462 | \*(CwMIN\fR,
|
---|
| 463 | \*(CwODD\fR,
|
---|
| 464 | \*(CwORD\fR,
|
---|
| 465 | \*(CwSIZE\fR,
|
---|
| 466 | \*(CwSHORT\fR,
|
---|
| 467 | \*(CwTSIZE\fR,
|
---|
| 468 | or \*(CwVAL\fR,
|
---|
| 469 | with constant argument(s);
|
---|
| 470 | \*(CwTSIZE\fR and \*(CwSIZE\fR may also have a variable as argument.
|
---|
| 471 | .SS "Type declarations (section 6)"
|
---|
| 472 | .LP
|
---|
| 473 | .ft I
|
---|
| 474 | 1. Basic types (section 6.1)
|
---|
| 475 | .PP
|
---|
| 476 | The type \*(CwCHAR\fR includes the ASCII character set as a subset.
|
---|
| 477 | Values range from
|
---|
| 478 | \*(Cw0C\fR to \*(Cw377C\fR,
|
---|
| 479 | not from \*(Cw0C\fR to \*(Cw177C\fR.
|
---|
| 480 | .LP
|
---|
| 481 | .ft I
|
---|
| 482 | 2. Enumerations (section 6.2)
|
---|
| 483 | .PP
|
---|
| 484 | The maximum number of enumeration literals in any one enumeration type
|
---|
| 485 | is \*(CwMAX(INTEGER)\fR.
|
---|
| 486 | .LP
|
---|
| 487 | .ft I
|
---|
| 488 | 3. Record types (section 6.5)
|
---|
| 489 | .PP
|
---|
| 490 | The syntax of variant sections in [1] is different from the one in [2].
|
---|
| 491 | Our implementation recognizes both,
|
---|
| 492 | giving a warning for the older one.
|
---|
| 493 | .LP
|
---|
| 494 | .ft I
|
---|
| 495 | 4. Set types (section 6.6)
|
---|
| 496 | .PP
|
---|
| 497 | The only limitation imposed by the compiler is that the base type of the
|
---|
| 498 | set must be a subrange type,
|
---|
| 499 | an enumeration type,
|
---|
| 500 | \*(CwCHAR\fR,
|
---|
| 501 | or \*(CwBOOLEAN\fR.
|
---|
| 502 | So,
|
---|
| 503 | the lower bound may be negative.
|
---|
| 504 | However,
|
---|
| 505 | if a negative lower bound is used,
|
---|
| 506 | the compiler gives a warning of the \fIrestricted\fR class.
|
---|
| 507 | .PP
|
---|
| 508 | The standard type \*(CwBITSET\fR is defined as
|
---|
| 509 | .XS
|
---|
| 510 | .CW
|
---|
| 511 | TYPE BITSET = SET OF [0 .. 8*SIZE(INTEGER)-1];
|
---|
| 512 | .ft P
|
---|
| 513 | .XE
|
---|
| 514 | .SS "Expressions (section 8)"
|
---|
| 515 | .LP
|
---|
| 516 | .ft I
|
---|
| 517 | 1. Operators (section 8.2)
|
---|
| 518 | .LP
|
---|
| 519 | .ft I
|
---|
| 520 | 1.1. Arithmetic operators (section 8.2.1)
|
---|
| 521 | .PP
|
---|
| 522 | The Report does not specify the priority of the unary
|
---|
| 523 | operators \*(Cw+\fR or \*(Cw-\fR:
|
---|
| 524 | It does not specify whether
|
---|
| 525 | .XS
|
---|
| 526 | .CW
|
---|
| 527 | - 1 + 1
|
---|
| 528 | .ft P
|
---|
| 529 | .XE
|
---|
| 530 | means
|
---|
| 531 | .XS
|
---|
| 532 | .CW
|
---|
| 533 | - (1 + 1)
|
---|
| 534 | .ft P
|
---|
| 535 | .XE
|
---|
| 536 | or
|
---|
| 537 | .XS
|
---|
| 538 | .CW
|
---|
| 539 | (-1) + 1
|
---|
| 540 | .ft P
|
---|
| 541 | .XE
|
---|
| 542 | The
|
---|
| 543 | .MX
|
---|
| 544 | Modula-2 compiler implements the second alternative.
|
---|
| 545 | .SS "Statements (section 9)"
|
---|
| 546 | .LP
|
---|
| 547 | .ft I
|
---|
| 548 | 1. Assignments (section 9.1)
|
---|
| 549 | .PP
|
---|
| 550 | The Report does not define the evaluation order in an assignment.
|
---|
| 551 | Our compiler certainly chooses an evaluation order,
|
---|
| 552 | but it is explicitly left undefined.
|
---|
| 553 | Therefore,
|
---|
| 554 | programs that depend on it may cease to work later.
|
---|
| 555 | .PP
|
---|
| 556 | The types \*(CwINTEGER\fR and \*(CwCARDINAL\fR are assignment-compatible with
|
---|
| 557 | \*(CwLONGINT\fR,
|
---|
| 558 | and \*(CwREAL\fR is assignment-compatible with \*(CwLONGREAL\fR.
|
---|
| 559 | .LP
|
---|
| 560 | .ft I
|
---|
| 561 | 2. Case statements (section 9.5)
|
---|
| 562 | .PP
|
---|
| 563 | The size of the type of the case-expression must be less than or equal to
|
---|
| 564 | the word-size.
|
---|
| 565 | .PP
|
---|
| 566 | The Report does not specify what happens if the value of the case-expression
|
---|
| 567 | does not occur as a label of any case,
|
---|
| 568 | and there is no \*(CwELSE\fR-part.
|
---|
| 569 | In our implementation,
|
---|
| 570 | this results in a runtime error.
|
---|
| 571 | .LP
|
---|
| 572 | .ft I
|
---|
| 573 | 3. For statements (section 9.8)
|
---|
| 574 | .PP
|
---|
| 575 | The Report does not specify the legal types for a control variable.
|
---|
| 576 | Our implementation allows the basic types (except \*(CwREAL\fR),
|
---|
| 577 | enumeration types,
|
---|
| 578 | and subranges.
|
---|
| 579 | A runtime warning is generated when the value of the control variable
|
---|
| 580 | is changed by the statement sequence that forms the body of the loop,
|
---|
| 581 | unless runtime checking is disabled.
|
---|
| 582 | .LP
|
---|
| 583 | .ft I
|
---|
| 584 | 4. Return and exit statements (section 9.11)
|
---|
| 585 | .PP
|
---|
| 586 | The Report does not specify which result-types are legal.
|
---|
| 587 | Our implementation allows any result type.
|
---|
| 588 | .SS "Procedure declarations (section 10)"
|
---|
| 589 | .PP
|
---|
| 590 | Function procedures must exit through a RETURN statement,
|
---|
| 591 | or a runtime error occurs.
|
---|
| 592 | .LP
|
---|
| 593 | .ft I
|
---|
| 594 | 1. Standard procedures (section 10.2)
|
---|
| 595 | .PP
|
---|
| 596 | Our implementation supports \*(CwNEW\fR and \*(CwDISPOSE\fR
|
---|
| 597 | for backwards compatibility,
|
---|
| 598 | but issues warnings for their use.
|
---|
| 599 | .PP
|
---|
| 600 | Also,
|
---|
| 601 | some new standard procedures were added,
|
---|
| 602 | similar to the new standard procedures in Wirth's newest compiler:
|
---|
| 603 | .IP \-
|
---|
| 604 | \*(CwLONG\fR converts an argument of type \*(CwINTEGER\fR or \*(CwREAL\fR to the
|
---|
| 605 | types \*(CwLONGINT\fR or \*(CwLONGREAL\fR.
|
---|
| 606 | .IP \-
|
---|
| 607 | \*(CwSHORT\fR performs the inverse transformation,
|
---|
| 608 | without range checks.
|
---|
| 609 | .IP \-
|
---|
| 610 | \*(CwFLOATD\fR is analogous to \*(CwFLOAT\fR,
|
---|
| 611 | but yields a result of type
|
---|
| 612 | \*(CwLONGREAL\fR.
|
---|
| 613 | .IP \-
|
---|
| 614 | \*(CwTRUNCD\fR is analogous to \*(CwTRUNC\fR,
|
---|
| 615 | but yields a result of type
|
---|
| 616 | \*(CwLONGINT\fR.
|
---|
| 617 | .SS "System-dependent facilities (section 12)"
|
---|
| 618 | .PP
|
---|
| 619 | The type \*(CwBYTE\fR is added to the \*(CwSYSTEM\fR module.
|
---|
| 620 | It occupies a storage unit of 8 bits.
|
---|
| 621 | \*(CwARRAY OF BYTE\fR has a similar effect to \*(CwARRAY OF WORD\fR,
|
---|
| 622 | but is safer.
|
---|
| 623 | In some obscure cases the \*(CwARRAY OF WORD\fR mechanism does not quite
|
---|
| 624 | work properly.
|
---|
| 625 | .PP
|
---|
| 626 | The procedure \*(CwIOTRANSFER\fR is not implemented.
|
---|
| 627 | .SS "Backwards compatibility"
|
---|
| 628 | .PP
|
---|
| 629 | Besides recognizing the language as described in [1],
|
---|
| 630 | the compiler recognizes most of the language described in [2],
|
---|
| 631 | for backwards compatibility.
|
---|
| 632 | It warns the user for old-fashioned
|
---|
| 633 | constructions (constructions that [1] does not allow).
|
---|
| 634 | If the \fI\(en3\fR option is passed to \fIm2\fR,
|
---|
| 635 | this backwards compatibility feature is disabled.
|
---|
| 636 | .SS "Compile time errors"
|
---|
| 637 | .PP
|
---|
| 638 | The compile time error messages are intended to be self-explanatory,
|
---|
| 639 | and not listed here.
|
---|
| 640 | The compiler also sometimes issues warnings,
|
---|
| 641 | recognizable by a warning-classification between parentheses.
|
---|
| 642 | There are 3 classifications:
|
---|
| 643 | .IP "(old-fashioned use)"
|
---|
| 644 | .br
|
---|
| 645 | These warnings are given on constructions that are not allowed by [1],
|
---|
| 646 | but are allowed by [2].
|
---|
| 647 | .IP (strict)
|
---|
| 648 | .br
|
---|
| 649 | These warnings are given on constructions that are supported by the
|
---|
| 650 | .MX
|
---|
| 651 | Modula-2 compiler,
|
---|
| 652 | but might not be supported by others.
|
---|
| 653 | Examples: functions returning structured types,
|
---|
| 654 | SET types of subranges with
|
---|
| 655 | negative lower bound.
|
---|
| 656 | .IP (warning)
|
---|
| 657 | .br
|
---|
| 658 | The other warnings,
|
---|
| 659 | such as warnings about variables that are never assigned,
|
---|
| 660 | never used,
|
---|
| 661 | etc.
|
---|
| 662 | .SS "Runtime errors"
|
---|
| 663 | .PP
|
---|
| 664 | The \fITraps\fR module enables the user to install his own runtime
|
---|
| 665 | error handler.
|
---|
| 666 | The default one just displays what happened and exits.
|
---|
| 667 | Basically,
|
---|
| 668 | a trap handler is just a procedure that takes an INTEGER as
|
---|
| 669 | parameter.
|
---|
| 670 | The INTEGER is the trap number.
|
---|
| 671 | This INTEGER can be one of the
|
---|
| 672 | EM trap numbers,
|
---|
| 673 | listed in [3],
|
---|
| 674 | or one of the numbers listed in the
|
---|
| 675 | \fITraps\fR definition module.
|
---|
| 676 | .PP
|
---|
| 677 | The following runtime errors may occur:
|
---|
| 678 | .IP "array bound error"
|
---|
| 679 | .br
|
---|
| 680 | This error is detected if the \fI\(enA\fR option is given to \fIm2\fR.
|
---|
| 681 | .IP "range bound error"
|
---|
| 682 | .br
|
---|
| 683 | Range bound errors are always detected,
|
---|
| 684 | unless runtime checks are disabled.
|
---|
| 685 | .IP "set bound error"
|
---|
| 686 | .IP "cardinal overflow"
|
---|
| 687 | .br
|
---|
| 688 | This error is detected,
|
---|
| 689 | unless runtime checks are disabled.
|
---|
| 690 | .IP "cardinal underflow"
|
---|
| 691 | .br
|
---|
| 692 | This error is detected,
|
---|
| 693 | unless runtime checks are disabled.
|
---|
| 694 | .IP "divide by 0"
|
---|
| 695 | .IP "divide by 0.0"
|
---|
| 696 | .IP "conversion error"
|
---|
| 697 | .br
|
---|
| 698 | This error occurs when assigning a negative value of type INTEGER to a
|
---|
| 699 | variable of type CARDINAL,
|
---|
| 700 | or when assigning a value of CARDINAL that is > MAX(INTEGER),
|
---|
| 701 | to a variable of type INTEGER.
|
---|
| 702 | It is detected,
|
---|
| 703 | unless runtime checking is disabled.
|
---|
| 704 | .IP "heap overflow"
|
---|
| 705 | .br
|
---|
| 706 | This might happen when ALLOCATE fails.
|
---|
| 707 | .IP "case error"
|
---|
| 708 | .br
|
---|
| 709 | This error occurs when non of the cases in a CASE statement are selected,
|
---|
| 710 | and the CASE statement has no ELSE part.
|
---|
| 711 | .IP "stack size of process too large"
|
---|
| 712 | .br
|
---|
| 713 | This is most likely to happen if the reserved space for a coroutine stack
|
---|
| 714 | is too small.
|
---|
| 715 | In this case,
|
---|
| 716 | increase the size of the area given to
|
---|
| 717 | \*(CwNEWPROCESS\fR.
|
---|
| 718 | It can also happen if the stack needed for the main
|
---|
| 719 | process is too large and there are coroutines.
|
---|
| 720 | In this case,
|
---|
| 721 | the only fix is to reduce the stack size needed by the main process,
|
---|
| 722 | f.i. by avoiding local arrays.
|
---|
| 723 | .IP "too many nested traps + handlers"
|
---|
| 724 | .br
|
---|
| 725 | This error can only occur when the user has installed his own trap handler.
|
---|
| 726 | It means that during execution of the trap handler another trap has occurred,
|
---|
| 727 | and that several times.
|
---|
| 728 | In some cases,
|
---|
| 729 | this is an error because of overflow of some internal tables.
|
---|
| 730 | .IP "no RETURN from function procedure"
|
---|
| 731 | .br
|
---|
| 732 | This error occurs when a function procedure does not return properly
|
---|
| 733 | ('falls' through).
|
---|
| 734 | .IP "illegal instruction"
|
---|
| 735 | .br
|
---|
| 736 | This error might occur when you use floating point operations on an
|
---|
| 737 | implementation that does not have floating point.
|
---|
| 738 | .PP
|
---|
| 739 | In addition,
|
---|
| 740 | some of the library modules may give error messages.
|
---|
| 741 | The \fBTraps\fR-module has a suitable mechanism for this.
|
---|
| 742 | .SS "The procedure call interface"
|
---|
| 743 | .PP
|
---|
| 744 | Parameters are pushed on the stack in reversed order.
|
---|
| 745 | For VAR parameters,
|
---|
| 746 | its address is passed,
|
---|
| 747 | for value parameters its value.
|
---|
| 748 | The only exception to this rule is with conformant arrays.
|
---|
| 749 | For conformant arrays,
|
---|
| 750 | the address is passed,
|
---|
| 751 | and an array descriptor is
|
---|
| 752 | passed.
|
---|
| 753 | The descriptor is an EM array descriptor.
|
---|
| 754 | It consists of three
|
---|
| 755 | fields: the lower bound (always 0),
|
---|
| 756 | upper bound \(mi lower bound,
|
---|
| 757 | and the size of the elements.
|
---|
| 758 | The descriptor is pushed first.
|
---|
| 759 | If the parameter is a value parameter,
|
---|
| 760 | the called routine must make sure
|
---|
| 761 | that its value is never changed,
|
---|
| 762 | for instance by making its own copy
|
---|
| 763 | of the array.
|
---|
| 764 | .PP
|
---|
| 765 | When the size of the return value of a function procedure is larger than
|
---|
| 766 | the maximum of \*(CwSIZE(LONGREAL)\fR and twice the pointer-size,
|
---|
| 767 | the caller reserves this space on the stack,
|
---|
| 768 | above the parameters.
|
---|
| 769 | Callee then stores
|
---|
| 770 | its result there,
|
---|
| 771 | and returns no other value.
|
---|
| 772 | .SS "The Modula-2 runtime library"
|
---|
| 773 | .PP
|
---|
| 774 | The definition modules of the modules available in the
|
---|
| 775 | .MX
|
---|
| 776 | Modula-2 runtime library reside in the directory \fI/usr/lib/ack/m2\fR.
|
---|
| 777 | .SS References
|
---|
| 778 | .IP [1]
|
---|
| 779 | Niklaus Wirth,
|
---|
| 780 | .ft I
|
---|
| 781 | Programming in Modula-2, third, corrected edition,
|
---|
| 782 | .ft R
|
---|
| 783 | Springer-Verlag, Berlin (1985)
|
---|
| 784 | .IP [2]
|
---|
| 785 | Niklaus Wirth,
|
---|
| 786 | .ft I
|
---|
| 787 | Programming in Modula-2,
|
---|
| 788 | .ft R
|
---|
| 789 | Stringer-Verlag, Berlin (1983)
|
---|
| 790 | .IP [3]
|
---|
| 791 | A.S.Tanenbaum, J.W.Stevenson, Hans van Staveren, E.G.Keizer,
|
---|
| 792 | .ft I
|
---|
| 793 | Description of a machine architecture for use with block structured languages,
|
---|
| 794 | .ft R
|
---|
| 795 | Informatica rapport IR-81, Vrije Universiteit, Amsterdam
|
---|
| 796 | .SH "THE MINIX PASCAL COMPILER"
|
---|
| 797 | .PP
|
---|
| 798 | .de IT
|
---|
| 799 | .PP
|
---|
| 800 | .B BS\ \\$1:
|
---|
| 801 | ..
|
---|
| 802 | .de IS
|
---|
| 803 | .PP
|
---|
| 804 | .in +.5i
|
---|
| 805 | ..
|
---|
| 806 | .PP
|
---|
| 807 | This section refers to the (1982) BSI standard for Pascal [1].
|
---|
| 808 | .MX
|
---|
| 809 | Pascal complies with the requirements of level 1 of BS 6192: 1982, with
|
---|
| 810 | the exceptions as listed in this section.
|
---|
| 811 | .PP
|
---|
| 812 | The standard requires an accompanying document describing the
|
---|
| 813 | implementation-defined and implementation-dependent features,
|
---|
| 814 | the reaction on errors and the extensions to standard Pascal.
|
---|
| 815 | These four items will be treated in the rest of this section.
|
---|
| 816 | .SS "Implementation-defined features"
|
---|
| 817 | .PP
|
---|
| 818 | For each implementation-defined feature mentioned in the BSI standard
|
---|
| 819 | we give the section number, the quotation from that section and the definition.
|
---|
| 820 | First we quote the definition of implementation-defined:
|
---|
| 821 | .PP
|
---|
| 822 | .RS
|
---|
| 823 | Possibly differing between processors, but defined for any particular
|
---|
| 824 | processor.
|
---|
| 825 | .RE
|
---|
| 826 | .IT 6.1.7
|
---|
| 827 | Each string-character shall denote an implementation-defined value of the
|
---|
| 828 | required char-type.
|
---|
| 829 | .IS
|
---|
| 830 | All 7-bit ASCII characters except linefeed LF (10) are allowed.
|
---|
| 831 | .IT 6.4.2.2
|
---|
| 832 | The values of type real shall be an implementation-defined subset
|
---|
| 833 | of the real numbers denoted as specified by 6.1.5 by the signed-real values.
|
---|
| 834 | .IS
|
---|
| 835 | The set of real values range from a low of \(mi1.7976931348623157e+308 to
|
---|
| 836 | a high of 1.7976931348623157e+308.
|
---|
| 837 | .IT 6.4.2.2
|
---|
| 838 | The type char shall be the enumeration of a set of implementation-defined
|
---|
| 839 | characters, some possibly without graphic representations.
|
---|
| 840 | .IS
|
---|
| 841 | The 7-bit ASCII character set is used, where LF (10) denotes the
|
---|
| 842 | end-of-line marker on text-files.
|
---|
| 843 | .IT 6.4.2.2
|
---|
| 844 | The ordinal numbers of the character values shall be values of integer-type,
|
---|
| 845 | that are implementation-defined, and that are determined by mapping
|
---|
| 846 | the character values on to consecutive non-negative integer values
|
---|
| 847 | starting at zero.
|
---|
| 848 | .IS
|
---|
| 849 | The normal ASCII ordering is used: ord('0')=48, ord('A')=65, ord('a')=97, etc.
|
---|
| 850 | .IT 6.6.5.2
|
---|
| 851 | The post-assertions imply corresponding activities on the external entities,
|
---|
| 852 | if any, to which the file-variables are bound.
|
---|
| 853 | These activities, and the
|
---|
| 854 | point at which they are actually performed, shall be
|
---|
| 855 | implementation-defined.
|
---|
| 856 | .IS
|
---|
| 857 | The reading and writing writing of objects on files is buffered.
|
---|
| 858 | This means that when a program terminates abnormally, I/O may be
|
---|
| 859 | unfinished.
|
---|
| 860 | Terminal I/O is unbuffered.
|
---|
| 861 | Files are closed whenever they are rewritten or reset, or on
|
---|
| 862 | program termination.
|
---|
| 863 | .IT 6.7.2.2
|
---|
| 864 | The predefined constant \fImaxint\fR shall be of integer-type and shall denote
|
---|
| 865 | an implementation-defined value, that satisfies the following conditions:
|
---|
| 866 | .IP (a)
|
---|
| 867 | All integral values in the closed interval from \fI\(mimaxint\fR to \fI+maxint\fR
|
---|
| 868 | shall be values of the integer-type.
|
---|
| 869 | .IP (b)
|
---|
| 870 | Any monadic operation performed on an integer value in this interval
|
---|
| 871 | shall be correctly performed according to the mathematical rules for
|
---|
| 872 | integer arithmetic.
|
---|
| 873 | .IP (c)
|
---|
| 874 | Any dyadic integer operation on two integer values in this same interval
|
---|
| 875 | shall be correctly performed according to the mathematical rules for
|
---|
| 876 | integer arithmetic, provided that the result is also in this interval.
|
---|
| 877 | .IP (d)
|
---|
| 878 | Any relational operation on two integer values in this same interval
|
---|
| 879 | shall be correctly performed according to the mathematical rules for
|
---|
| 880 | integer arithmetic.
|
---|
| 881 | .SP
|
---|
| 882 | The representation of integers under 16-bit \*(Mp or under 68000 \*(Mx
|
---|
| 883 | is a 16-bit word using two's complement arithmetic. The integers range
|
---|
| 884 | from \(mi32768 to +32767. Under 32-bit \*(Mp a 32-bit integer is used
|
---|
| 885 | ranging from \(mi2147483648 to +2147483647.
|
---|
| 886 | .IT 6.7.2.2
|
---|
| 887 | The result of the real arithmetic operators and functions shall be
|
---|
| 888 | approximations to the corresponding mathematical results.
|
---|
| 889 | The accuracy of
|
---|
| 890 | this approximation shall be implementation-defined
|
---|
| 891 | .IS
|
---|
| 892 | The default size of reals is 8 bytes, the accuracy is 11 bits for the exponent,
|
---|
| 893 | and 53 bits for the mantissa.
|
---|
| 894 | This gives an accuracy of about 16 digits.
|
---|
| 895 | and exponents ranging from \(mi307 to +307.
|
---|
| 896 | .IT 6.9.3.1
|
---|
| 897 | The default TotalWidth values for integer, Boolean and real types
|
---|
| 898 | shall be implementation-defined.
|
---|
| 899 | .IS
|
---|
| 900 | The defaults are:
|
---|
| 901 | .XS
|
---|
| 902 | .ta +\w'Boolean 'u +\w'14 'u
|
---|
| 903 | integer 6 (16-bit)
|
---|
| 904 | integer 11 (32-bit)
|
---|
| 905 | Boolean 5
|
---|
| 906 | real 14
|
---|
| 907 | .DT
|
---|
| 908 | .XE
|
---|
| 909 | .IT 6.9.3.4.1
|
---|
| 910 | ExpDigits, the number of digits written in an exponent part of a real,
|
---|
| 911 | shall be implementation-defined.
|
---|
| 912 | .IS
|
---|
| 913 | ExpDigits is defined as 3.
|
---|
| 914 | .IT 6.9.3.4.1
|
---|
| 915 | The character written as part of the representation of
|
---|
| 916 | a real to indicate the beginning of the exponent part shall be
|
---|
| 917 | implementation-defined, either 'E' or 'e'.
|
---|
| 918 | .IS
|
---|
| 919 | The exponent part starts with 'e'.
|
---|
| 920 | .IT 6.9.3.5
|
---|
| 921 | The case of the characters written as representation of the
|
---|
| 922 | Boolean values shall be implementation-defined.
|
---|
| 923 | .IS
|
---|
| 924 | The representations of true and false are 'true' and 'false'.
|
---|
| 925 | .IT 6.9.5
|
---|
| 926 | The effect caused by the standard procedure page
|
---|
| 927 | on a text file shall be implementation-defined.
|
---|
| 928 | .IS
|
---|
| 929 | The ASCII character form feed FF (12) is written.
|
---|
| 930 | .IT 6.10
|
---|
| 931 | The binding of the variables denoted by the program-parameters
|
---|
| 932 | to entities external to the program shall be implementation-defined if
|
---|
| 933 | the variable is of a file-type.
|
---|
| 934 | .IS
|
---|
| 935 | The program parameters must be files and all, except input and output,
|
---|
| 936 | must be declared as such in the program block.
|
---|
| 937 | .PP
|
---|
| 938 | The program parameters input and output, if specified, will correspond
|
---|
| 939 | with the UNIX streams 'standard input' and 'standard output'.
|
---|
| 940 | .PP
|
---|
| 941 | The other program parameters will be mapped to the argument strings
|
---|
| 942 | provided by the caller of this program.
|
---|
| 943 | The argument strings are supposed to be path names of the files to be
|
---|
| 944 | opened or created.
|
---|
| 945 | The order of the program parameters determines the mapping:
|
---|
| 946 | the first parameter is mapped onto the first argument string, etc.
|
---|
| 947 | Note that input and output are ignored in this mapping.
|
---|
| 948 | .PP
|
---|
| 949 | The mapping is recalculated each time a program parameter
|
---|
| 950 | is opened for reading or writing by a call to the standard procedures
|
---|
| 951 | reset or rewrite.
|
---|
| 952 | This gives the programmer the opportunity to manipulate the list
|
---|
| 953 | of string arguments using the external procedures argc, argv and argshift
|
---|
| 954 | available in the Pascal library.
|
---|
| 955 | .IT 6.10
|
---|
| 956 | The effect of an explicit use of reset or rewrite
|
---|
| 957 | on the standard text files input or output shall be implementation-defined.
|
---|
| 958 | .IS
|
---|
| 959 | The procedures reset and rewrite are no-ops
|
---|
| 960 | if applied to input or output.
|
---|
| 961 | .in 0
|
---|
| 962 | .SS "Implementation-dependent features"
|
---|
| 963 | .PP
|
---|
| 964 | For each implementation-dependent feature mentioned in the BSI standard,
|
---|
| 965 | we give the section number, the quotation from that section and the way
|
---|
| 966 | this feature is treated by the
|
---|
| 967 | .MX
|
---|
| 968 | Pascal system.
|
---|
| 969 | First we quote the definition of 'implementation-dependent':
|
---|
| 970 | .PP
|
---|
| 971 | .RS
|
---|
| 972 | Possibly differing between processors and not necessarily defined for any
|
---|
| 973 | particular processor.
|
---|
| 974 | .RE
|
---|
| 975 | .IT 6.7.2.1
|
---|
| 976 | The order of evaluation of the operands of a dyadic operator
|
---|
| 977 | shall be implementation-dependent.
|
---|
| 978 | .IS
|
---|
| 979 | Operands are always evaluated, so the program part
|
---|
| 980 | .XS
|
---|
| 981 | if (p<>nil) and (p^.value<>0) then
|
---|
| 982 | .XE
|
---|
| 983 | is probably incorrect.
|
---|
| 984 | .PP
|
---|
| 985 | The left-hand operand of a dyadic operator is almost always evaluated
|
---|
| 986 | before the right-hand side.
|
---|
| 987 | Some peculiar evaluations exist for the following cases:
|
---|
| 988 | .IP 1.
|
---|
| 989 | The modulo operation is performed by a library routine to
|
---|
| 990 | check for negative values of the right operand.
|
---|
| 991 | .IP 2.
|
---|
| 992 | The expression
|
---|
| 993 | .XS
|
---|
| 994 | set1 <= set2
|
---|
| 995 | .XE
|
---|
| 996 | where set1 and set2 are compatible set types is evaluated in the
|
---|
| 997 | following steps:
|
---|
| 998 | .XS
|
---|
| 999 | .ta +\w'\- 'u
|
---|
| 1000 | \- evaluate set2;
|
---|
| 1001 | \- evaluate set1;
|
---|
| 1002 | \- compute set2+set1;
|
---|
| 1003 | \- test set2 and set2+set1 for equality.
|
---|
| 1004 | .DT
|
---|
| 1005 | .XE
|
---|
| 1006 | .IP 3.
|
---|
| 1007 | The expression
|
---|
| 1008 | .XS
|
---|
| 1009 | set1 >= set2
|
---|
| 1010 | .XE
|
---|
| 1011 | where set1 and set2 are compatible set types is evaluated in the following steps:
|
---|
| 1012 | .XS
|
---|
| 1013 | .ta +\w'\- 'u
|
---|
| 1014 | \- evaluate set1;
|
---|
| 1015 | \- evaluate set2;
|
---|
| 1016 | \- compute set1+set2;
|
---|
| 1017 | \- test set1 and set1+set2 for equality.
|
---|
| 1018 | .DT
|
---|
| 1019 | .XE
|
---|
| 1020 | .IT 6.7.3
|
---|
| 1021 | The order of evaluation, accessing and binding
|
---|
| 1022 | of the actual-parameters for functions
|
---|
| 1023 | shall be implementation-dependent.
|
---|
| 1024 | .IS
|
---|
| 1025 | The order of evaluation is from right to left.
|
---|
| 1026 | .IT 6.8.2.2
|
---|
| 1027 | The decision as to the order of accessing the variable and evaluating
|
---|
| 1028 | the expression in an assignment-statement, shall be
|
---|
| 1029 | implementation-dependent.
|
---|
| 1030 | .IS
|
---|
| 1031 | The expression is evaluated first.
|
---|
| 1032 | .IT 6.8.2.3
|
---|
| 1033 | The order of evaluation and binding of the actual-parameters for procedures
|
---|
| 1034 | shall be implementation-dependent.
|
---|
| 1035 | .IS
|
---|
| 1036 | The same as for functions.
|
---|
| 1037 | .IT 6.9.5
|
---|
| 1038 | The effect of inspecting a text file to which the page
|
---|
| 1039 | procedure was applied during generation is
|
---|
| 1040 | implementation-dependent.
|
---|
| 1041 | .IS
|
---|
| 1042 | The formfeed character written by page is
|
---|
| 1043 | treated like a normal character, with ordinal value 12.
|
---|
| 1044 | .IT 6.10
|
---|
| 1045 | The binding of the variables denoted by the program-parameters
|
---|
| 1046 | to entities external to the program shall be implementation-dependent unless
|
---|
| 1047 | the variable is of a file-type.
|
---|
| 1048 | .IS
|
---|
| 1049 | Only variables of a file-type are allowed as program parameters.
|
---|
| 1050 | .in 0
|
---|
| 1051 | .SS "Error handling"
|
---|
| 1052 | .PP
|
---|
| 1053 | There are three classes of errors to be distinguished.
|
---|
| 1054 | In the first class are the error messages generated by the compiler.
|
---|
| 1055 | The second class consists of the occasional errors generated by the other
|
---|
| 1056 | programs involved in the compilation process.
|
---|
| 1057 | Errors of the third class are the errors as defined in the standard by:
|
---|
| 1058 | .PP
|
---|
| 1059 | .RS
|
---|
| 1060 | An error is a violation by a program of the requirements of this standard
|
---|
| 1061 | that a processor is permitted to leave undetected.
|
---|
| 1062 | .RE
|
---|
| 1063 | .LP
|
---|
| 1064 | .ft I
|
---|
| 1065 | Compiler errors
|
---|
| 1066 | .PP
|
---|
| 1067 | Error are written on the standard error output.
|
---|
| 1068 | Each line has the form:
|
---|
| 1069 | .XS
|
---|
| 1070 | <file>, line <number>: <description>
|
---|
| 1071 | .XE
|
---|
| 1072 | Every time the compiler detects an error that does not have influence
|
---|
| 1073 | on the code produced by the compiler or on the syntax decisions, a warning
|
---|
| 1074 | messages is given.
|
---|
| 1075 | If only warnings are generated, compilation proceeds and probably results
|
---|
| 1076 | in a correctly compiled program.
|
---|
| 1077 | .PP
|
---|
| 1078 | Sometimes the compiler produces several errors for the same line.
|
---|
| 1079 | They are only shown up to a maximum of 5 errors per line.
|
---|
| 1080 | Warning are also shown up to a maximum of 5 per line.
|
---|
| 1081 | .PP
|
---|
| 1082 | Extensive treatment of these errors is outside the scope of this manual.
|
---|
| 1083 | .LP
|
---|
| 1084 | .ft I
|
---|
| 1085 | Runtime errors
|
---|
| 1086 | .PP
|
---|
| 1087 | Errors detected at run time cause an error message to be generated on the
|
---|
| 1088 | diagnostic output stream (UNIX file descriptor 2).
|
---|
| 1089 | The message consists of the name of the program followed by a message
|
---|
| 1090 | describing the error, possibly followed by the source line number.
|
---|
| 1091 | Unless the \fI\(enn\fR option is turned on, the compiler generates code to keep track
|
---|
| 1092 | of which source line causes which instructions to be generated.
|
---|
| 1093 | .PP
|
---|
| 1094 | For each error mentioned in the standard we give the section number,
|
---|
| 1095 | the quotation from that section and the way it is processed by the
|
---|
| 1096 | Pascal-compiler or runtime system.
|
---|
| 1097 | .PP
|
---|
| 1098 | For detected errors the corresponding message
|
---|
| 1099 | and trap number are given.
|
---|
| 1100 | Trap numbers are useful for exception-handling routines.
|
---|
| 1101 | Normally, each error causes the program to terminate.
|
---|
| 1102 | By using exception-handling routines one can
|
---|
| 1103 | ignore errors or perform alternate actions.
|
---|
| 1104 | Only some of the errors can be ignored
|
---|
| 1105 | by restarting the failing instruction.
|
---|
| 1106 | These errors are marked as non-fatal,
|
---|
| 1107 | all others as fatal.
|
---|
| 1108 | A list of errors with trap number between 0 and 63
|
---|
| 1109 | (EM errors) can be found in [2].
|
---|
| 1110 | Errors with trap number between 64 and 127 (Pascal errors) are listed below.
|
---|
| 1111 | .IT 6.4.6
|
---|
| 1112 | It shall be an error if a value of type T2 must be
|
---|
| 1113 | assignment-compatible with type T1, while
|
---|
| 1114 | T1 and T2 are compatible ordinal-types and the value of
|
---|
| 1115 | type T2 is not in the closed interval specified by T1.
|
---|
| 1116 | .IS
|
---|
| 1117 | The compiler distinguishes between array-index expressions and the other
|
---|
| 1118 | places where assignment-compatibility is required.
|
---|
| 1119 | .PP
|
---|
| 1120 | Array subscripting errors are only detected when the 'A' option is used.
|
---|
| 1121 | In the other cases, a range bound error occurs when the value of type T2
|
---|
| 1122 | is not in the closed interval specified by T1, unless range checks are
|
---|
| 1123 | disabled.
|
---|
| 1124 | .IT 6.4.6
|
---|
| 1125 | It shall be an error if a value of type T2 must be
|
---|
| 1126 | assignment-compatible with type T1, while T1 and T2 are compatible
|
---|
| 1127 | set-types and any member of the value of type T2
|
---|
| 1128 | is not in the closed interval specified by the base-type
|
---|
| 1129 | of the type T1.
|
---|
| 1130 | .IS
|
---|
| 1131 | This error is not detected.
|
---|
| 1132 | .IT 6.5.3.3
|
---|
| 1133 | It shall be an error if a component of a variant-part of a variant,
|
---|
| 1134 | where the selector of the variant-part is not a field,
|
---|
| 1135 | is accessed unless the variant is active for the entirety of each
|
---|
| 1136 | reference and access to each component of the variant.
|
---|
| 1137 | .IS
|
---|
| 1138 | This error is not detected.
|
---|
| 1139 | .IT 6.5.4
|
---|
| 1140 | It shall be an error if
|
---|
| 1141 | the pointer-variable of an identified-variable either denotes a
|
---|
| 1142 | nil-value or is undefined.
|
---|
| 1143 | .IS
|
---|
| 1144 | This error is not detected.
|
---|
| 1145 | .IT 6.5.4
|
---|
| 1146 | It shall be an error to remove the identifying-value of an identified
|
---|
| 1147 | variable from its pointer-type when a reference to the variable exists.
|
---|
| 1148 | .IS
|
---|
| 1149 | When the identified variable is an element of the record-variable-list of
|
---|
| 1150 | a with-statement, a warning is given at compile-time.
|
---|
| 1151 | Otherwise, this error is not detected.
|
---|
| 1152 | .IT 6.5.5
|
---|
| 1153 | It shall be an error to alter the value of a file-variable f when a
|
---|
| 1154 | reference to the buffer-variable f^ exists.
|
---|
| 1155 | .IS
|
---|
| 1156 | When f is altered when it is an element of the record-variable-list of a
|
---|
| 1157 | with-statement, a warning is given.
|
---|
| 1158 | When a buffer-variable is used as a
|
---|
| 1159 | variable-parameter, an error is given.
|
---|
| 1160 | This is done at compile-time.
|
---|
| 1161 | .IT 6.6.5.2
|
---|
| 1162 | It shall be an error if
|
---|
| 1163 | the stated pre-assertion does not hold immediately
|
---|
| 1164 | prior to any use of the file handling procedures
|
---|
| 1165 | rewrite, put, reset and get.
|
---|
| 1166 | .IS
|
---|
| 1167 | For each of these four operations the pre-assertions
|
---|
| 1168 | can be reformulated as:
|
---|
| 1169 | .XS
|
---|
| 1170 | .ta +\w'rewrite(f): 'u
|
---|
| 1171 | rewrite(f): no pre-assertion.
|
---|
| 1172 | put(f): f is opened for writing and f^ is not undefined.
|
---|
| 1173 | reset(f): f exists.
|
---|
| 1174 | get(f): f is opened for reading and eof(f) is false.
|
---|
| 1175 | .DT
|
---|
| 1176 | .XE
|
---|
| 1177 | The following errors are detected for these operations:
|
---|
| 1178 | .SP
|
---|
| 1179 | rewrite(f):
|
---|
| 1180 | .in +6
|
---|
| 1181 | .ti -3
|
---|
| 1182 | more args expected, trap 64, fatal:
|
---|
| 1183 | .br
|
---|
| 1184 | f is a program-parameter and the corresponding
|
---|
| 1185 | file name is not supplied by the caller of the program.
|
---|
| 1186 | .ti -3
|
---|
| 1187 | rewrite error, trap 101, fatal:
|
---|
| 1188 | .br
|
---|
| 1189 | the caller of the program lacks the necessary
|
---|
| 1190 | access rights to create the file in the file system
|
---|
| 1191 | or operating system problems like table overflow
|
---|
| 1192 | prevent creation of the file.
|
---|
| 1193 | .in -6
|
---|
| 1194 | .SP
|
---|
| 1195 | put(f):
|
---|
| 1196 | .in +6
|
---|
| 1197 | .ti -3
|
---|
| 1198 | file not yet open, trap 72, fatal:
|
---|
| 1199 | .br
|
---|
| 1200 | reset or rewrite are never applied to the file.
|
---|
| 1201 | The checks performed by the run time system are not foolproof.
|
---|
| 1202 | .ti -3
|
---|
| 1203 | not writable, trap 96, fatal:
|
---|
| 1204 | .br
|
---|
| 1205 | f is opened for reading.
|
---|
| 1206 | .ti -3
|
---|
| 1207 | write error, trap 104, fatal:
|
---|
| 1208 | .br
|
---|
| 1209 | probably caused by file system problems.
|
---|
| 1210 | For instance, the file storage is exhausted.
|
---|
| 1211 | Because I/O is buffered to improve performance,
|
---|
| 1212 | it might happen that this error occurs if the
|
---|
| 1213 | file is closed.
|
---|
| 1214 | Files are closed whenever they are rewritten or reset, or on
|
---|
| 1215 | program termination.
|
---|
| 1216 | .in -6
|
---|
| 1217 | .SP
|
---|
| 1218 | reset(f):
|
---|
| 1219 | .in +6
|
---|
| 1220 | .ti -3
|
---|
| 1221 | more args expected, trap 64, fatal:
|
---|
| 1222 | .br
|
---|
| 1223 | same as for rewrite(f).
|
---|
| 1224 | .ti -3
|
---|
| 1225 | reset error, trap 100, fatal:
|
---|
| 1226 | .br
|
---|
| 1227 | f does not exist, or the caller has insufficient access rights, or
|
---|
| 1228 | operating system tables are exhausted.
|
---|
| 1229 | .in -6
|
---|
| 1230 | .SP
|
---|
| 1231 | get(f):
|
---|
| 1232 | .in +6
|
---|
| 1233 | .ti -3
|
---|
| 1234 | file not yet open, trap 72, fatal:
|
---|
| 1235 | .br
|
---|
| 1236 | as for put(f).
|
---|
| 1237 | .ti -3
|
---|
| 1238 | not readable, trap 97, fatal:
|
---|
| 1239 | .br
|
---|
| 1240 | f is opened for writing.
|
---|
| 1241 | .ti -3
|
---|
| 1242 | end of file, trap 98, fatal:
|
---|
| 1243 | .br
|
---|
| 1244 | eof(f) is true just before the call to get(f).
|
---|
| 1245 | .ti -3
|
---|
| 1246 | read error, trap 103, fatal:
|
---|
| 1247 | .br
|
---|
| 1248 | unlikely to happen.
|
---|
| 1249 | Probably caused by hardware problems
|
---|
| 1250 | or by errors elsewhere in your program that destroyed
|
---|
| 1251 | the file information maintained by the run time system.
|
---|
| 1252 | .ti -3
|
---|
| 1253 | truncated, trap 99, fatal:
|
---|
| 1254 | .br
|
---|
| 1255 | the file is not properly formed by an integer
|
---|
| 1256 | number of file elements.
|
---|
| 1257 | For instance, the size of a file of integer is odd.
|
---|
| 1258 | .ti -3
|
---|
| 1259 | non-ASCII char read, trap 106, non-fatal:
|
---|
| 1260 | .br
|
---|
| 1261 | the character value of the next character-type
|
---|
| 1262 | file element is out of range (0..127).
|
---|
| 1263 | Only for text files.
|
---|
| 1264 | .in -6
|
---|
| 1265 | .IT 6.6.5.3
|
---|
| 1266 | It shall be an error if a variant of a variant-part within the new
|
---|
| 1267 | variable becomes active and a different variant of the variant-part is
|
---|
| 1268 | one of the specified variants.
|
---|
| 1269 | .IS
|
---|
| 1270 | This error is not detected.
|
---|
| 1271 | .IT 6.6.5.3
|
---|
| 1272 | It shall be an error to use dispose(q) if the identifying variable has been
|
---|
| 1273 | allocated using the form new(p,c1,...,cn).
|
---|
| 1274 | .IS
|
---|
| 1275 | This error is not detected.
|
---|
| 1276 | However, this error can cause more memory
|
---|
| 1277 | to be freed then was allocated.
|
---|
| 1278 | Dispose causes a fatal trap 73 when memory already on the free
|
---|
| 1279 | list is freed again.
|
---|
| 1280 | .IT 6.6.5.3
|
---|
| 1281 | It shall be an error to use dispose(q,k1,...,km) if the identifying
|
---|
| 1282 | variable has been allocated using the form new(p,c1,...,cn) and m is not
|
---|
| 1283 | equal to n.
|
---|
| 1284 | .IS
|
---|
| 1285 | This error is not detected.
|
---|
| 1286 | However, this error can cause more memory
|
---|
| 1287 | to be freed then was allocated.
|
---|
| 1288 | Dispose causes a fatal trap 73 when memory already on the free
|
---|
| 1289 | list is freed again.
|
---|
| 1290 | .IT 6.6.5.3
|
---|
| 1291 | It shall be an error if the variants of a variable to be disposed
|
---|
| 1292 | are different from those specified by the case-constants to dispose.
|
---|
| 1293 | .IS
|
---|
| 1294 | This error is not detected.
|
---|
| 1295 | .IT 6.6.5.3
|
---|
| 1296 | It shall be an error if the value of the pointer parameter of dispose has
|
---|
| 1297 | nil-value or is undefined.
|
---|
| 1298 | .IS
|
---|
| 1299 | This error is detected for nil-value (dispose error, trap 73, fatal).
|
---|
| 1300 | .IT 6.6.5.3
|
---|
| 1301 | It shall be an error if a variable created using the second form of new is
|
---|
| 1302 | accessed by the identified variable of the variable-access of a factor,
|
---|
| 1303 | of an assignment-statement, or of an actual-parameter.
|
---|
| 1304 | .IS
|
---|
| 1305 | This error is not detected.
|
---|
| 1306 | .IT 6.6.6.2
|
---|
| 1307 | It shall be an error if the value of sqr(x) does not exist.
|
---|
| 1308 | .IS
|
---|
| 1309 | This error is detected for real-type arguments (real overflow,
|
---|
| 1310 | trap 4, non-fatal).
|
---|
| 1311 | .IT 6.6.6.2
|
---|
| 1312 | It shall be an error if x in ln(x) is smaller than or equal to 0.
|
---|
| 1313 | .IS
|
---|
| 1314 | This error is detected (error in ln, trap 66, non-fatal)
|
---|
| 1315 | .IT 6.6.6.2
|
---|
| 1316 | It shall be an error if x in sqrt(x) is smaller than 0.
|
---|
| 1317 | .IS
|
---|
| 1318 | This error is detected (error in sqrt, trap 67, non-fatal)
|
---|
| 1319 | .SP
|
---|
| 1320 | In addition to these errors, overflow in the expression exp(x) is
|
---|
| 1321 | detected (error in exp, trap 65, non-fatal; real overflow, trap 4, non-fatal)
|
---|
| 1322 | .IT 6.6.6.3
|
---|
| 1323 | It shall be an error if
|
---|
| 1324 | the integer value of trunc(x) does not exist.
|
---|
| 1325 | .IS
|
---|
| 1326 | This error is detected (conversion error, trap 10, non-fatal).
|
---|
| 1327 | .IT 6.6.6.3
|
---|
| 1328 | It shall be an error if
|
---|
| 1329 | the integer value of round(x) does not exist.
|
---|
| 1330 | .IS
|
---|
| 1331 | This error is detected (conversion error, trap 10, non-fatal).
|
---|
| 1332 | .IT 6.6.6.4
|
---|
| 1333 | It shall be an error if
|
---|
| 1334 | the integer value of ord(x) does not exist.
|
---|
| 1335 | .IS
|
---|
| 1336 | This error can not occur, because the compiler will not allow
|
---|
| 1337 | such ordinal types.
|
---|
| 1338 | .IT 6.6.6.4
|
---|
| 1339 | It shall be an error if
|
---|
| 1340 | the character value of chr(x) does not exist.
|
---|
| 1341 | .IS
|
---|
| 1342 | This error is detected (range bound error, trap 1, non-fatal).
|
---|
| 1343 | .IT 6.6.6.4
|
---|
| 1344 | It shall be an error if the value of succ(x) does not exist.
|
---|
| 1345 | .IS
|
---|
| 1346 | Same comments as for chr(x).
|
---|
| 1347 | .IT 6.6.6.4
|
---|
| 1348 | It shall be an error if the value of pred(x) does not exist.
|
---|
| 1349 | .IS
|
---|
| 1350 | Same comments as for chr(x).
|
---|
| 1351 | .IT 6.6.6.5
|
---|
| 1352 | It shall be an error if f in eof(f) is undefined.
|
---|
| 1353 | .IS
|
---|
| 1354 | This error is detected (file not yet open, trap 72, fatal).
|
---|
| 1355 | .IT 6.6.6.5
|
---|
| 1356 | It shall be an error if
|
---|
| 1357 | f in eoln(f) is undefined, or if eof(f) is true at that time.
|
---|
| 1358 | .IS
|
---|
| 1359 | The following errors may occur:
|
---|
| 1360 | .IS
|
---|
| 1361 | file not yet open, trap 72, fatal;
|
---|
| 1362 | .br
|
---|
| 1363 | not readable, trap 97, fatal;
|
---|
| 1364 | .br
|
---|
| 1365 | end of file, trap 98, fatal.
|
---|
| 1366 | .IT 6.7.1
|
---|
| 1367 | It shall be an error if a variable-access used as an operand
|
---|
| 1368 | in an expression is undefined at the time of its use.
|
---|
| 1369 | .IS
|
---|
| 1370 | The compiler performs some limited checks to see if identifiers are
|
---|
| 1371 | used before they are set.
|
---|
| 1372 | Since it can not always be sure (one could, for
|
---|
| 1373 | instance, jump out of a loop), only a warning is generated.
|
---|
| 1374 | When an
|
---|
| 1375 | expression contains a function-call, an error occurs if the
|
---|
| 1376 | function is not assigned at run-time.
|
---|
| 1377 | .IT 6.7.2.2
|
---|
| 1378 | A term of the form x/y shall be an error if y is zero.
|
---|
| 1379 | .IS
|
---|
| 1380 | This error is detected (divide by 0.0, trap 7, non-fatal).
|
---|
| 1381 | .IT 6.7.2.2
|
---|
| 1382 | It shall be an error if j is zero in 'i div j'.
|
---|
| 1383 | .IS
|
---|
| 1384 | This error is detected (divide by 0, trap 6, non-fatal).
|
---|
| 1385 | .IT 6.7.2.2
|
---|
| 1386 | It shall be an error if
|
---|
| 1387 | j is zero or negative in i MOD j.
|
---|
| 1388 | .IS
|
---|
| 1389 | This error is detected (only positive j in 'i mod j', trap 71, non-fatal).
|
---|
| 1390 | .IT 6.7.2.2
|
---|
| 1391 | It shall be an error if the result of any operation on integer
|
---|
| 1392 | operands is not performed according to the mathematical
|
---|
| 1393 | rules for integer arithmetic.
|
---|
| 1394 | .IS
|
---|
| 1395 | This implementation does not detect integer overflow.
|
---|
| 1396 | .IT 6.8.3.5
|
---|
| 1397 | It shall be an error if none of the case-constants is equal to the
|
---|
| 1398 | value of the case-index upon entry to the case-statement.
|
---|
| 1399 | .IS
|
---|
| 1400 | This error is detected (case error, trap 20, fatal).
|
---|
| 1401 | .IT 6.9.1
|
---|
| 1402 | It shall be an error if the sequence of characters read looking for an
|
---|
| 1403 | integer does not form a signed-integer as specified in 6.1.5.
|
---|
| 1404 | .IS
|
---|
| 1405 | This error is detected (digit expected, trap 105, non-fatal).
|
---|
| 1406 | .IT 6.9.1
|
---|
| 1407 | It shall be an error if the sequence of characters read looking for a
|
---|
| 1408 | real does not form a signed-number as specified in 6.1.5.
|
---|
| 1409 | .IS
|
---|
| 1410 | This error is detected (digit expected, trap 105, non-fatal).
|
---|
| 1411 | .IT 6.9.1
|
---|
| 1412 | When read is applied to f, it shall be an error if the buffer-variable f^
|
---|
| 1413 | is undefined or the pre-assertions for get do not hold.
|
---|
| 1414 | .IS
|
---|
| 1415 | This error is detected (see get(f)).
|
---|
| 1416 | .IT 6.9.3
|
---|
| 1417 | When write is applied to a text file f, it shall be an error if f is
|
---|
| 1418 | undefined or f is opened for reading.
|
---|
| 1419 | .IS
|
---|
| 1420 | This error is detected (see put(f)).
|
---|
| 1421 | Furthermore, this error is also
|
---|
| 1422 | detected when f is not a text file.
|
---|
| 1423 | .IT 6.9.3.1
|
---|
| 1424 | The values of TotalWidth or FracDigits shall be greater than or equal to
|
---|
| 1425 | one; it shall be an error if either value is less then one.
|
---|
| 1426 | .IS
|
---|
| 1427 | When either value is less than zero, an error (illegal field width, trap
|
---|
| 1428 | 75, non-fatal) occurs.
|
---|
| 1429 | Zero values are allowed, in order to maintain some
|
---|
| 1430 | compatibility with the old
|
---|
| 1431 | .MX
|
---|
| 1432 | Pascal compiler.
|
---|
| 1433 | .IT 6.9.5
|
---|
| 1434 | It shall be an error if the pre-assertion required for writeln(f) doe not
|
---|
| 1435 | hold prior to the invocation of page(f);
|
---|
| 1436 | .IS
|
---|
| 1437 | This error is detected (see put(f)).
|
---|
| 1438 | .in 0
|
---|
| 1439 | .SS "Extensions to the standard"
|
---|
| 1440 | .LP
|
---|
| 1441 | .ft I
|
---|
| 1442 | 1. External routines
|
---|
| 1443 | .LP
|
---|
| 1444 | Except for the required directive 'forward' the
|
---|
| 1445 | .MX
|
---|
| 1446 | Pascal compiler recognizes
|
---|
| 1447 | the directive 'extern'.
|
---|
| 1448 | This directive tells the compiler that the procedure block of this
|
---|
| 1449 | procedure will not be present in the current program.
|
---|
| 1450 | The code for the body of this procedure must be included at a later
|
---|
| 1451 | stage of the compilation process.
|
---|
| 1452 | .PP
|
---|
| 1453 | This feature allows one to build libraries containing often used routines.
|
---|
| 1454 | These routines do not have to be included in all the programs using them.
|
---|
| 1455 | Maintenance is much simpler if there is only one library module to be
|
---|
| 1456 | changed instead of many Pascal programs.
|
---|
| 1457 | .PP
|
---|
| 1458 | Another advantage is that these library modules may be written in a different
|
---|
| 1459 | language, for instance C.
|
---|
| 1460 | .PP
|
---|
| 1461 | The use of external routines, however, is dangerous.
|
---|
| 1462 | The compiler normally checks for the correct number and type of parameters
|
---|
| 1463 | when a procedure is called and for the result type of functions.
|
---|
| 1464 | If an external routine is called these checks are not sufficient,
|
---|
| 1465 | because the compiler can not check whether the procedure heading of the
|
---|
| 1466 | external routine as given in the Pascal program matches the actual routine
|
---|
| 1467 | implementation.
|
---|
| 1468 | It should be the loader's task to check this.
|
---|
| 1469 | However, the current loaders are not that smart.
|
---|
| 1470 | .PP
|
---|
| 1471 | For those who wish the use the interface between C and Pascal we
|
---|
| 1472 | give an incomplete list of corresponding formal parameters in C and Pascal.
|
---|
| 1473 | .SP
|
---|
| 1474 | .XS
|
---|
| 1475 | .ta +\w'function a(pars):type 'u
|
---|
| 1476 | \fBPascal C\fR
|
---|
| 1477 | a:integer int a
|
---|
| 1478 | a:char int a
|
---|
| 1479 | a:boolean int a
|
---|
| 1480 | a:real double a
|
---|
| 1481 | a:^type type *a
|
---|
| 1482 | var a:type type *a
|
---|
| 1483 | procedure a(pars) struct {
|
---|
| 1484 | void (*a)() ;
|
---|
| 1485 | char *static_link ;
|
---|
| 1486 | }
|
---|
| 1487 | function a(pars):type struct {
|
---|
| 1488 | type (*a)() ;
|
---|
| 1489 | char *static_link ;
|
---|
| 1490 | }
|
---|
| 1491 | .DT
|
---|
| 1492 | .XE
|
---|
| 1493 | The Pascal runtime system uses the following algorithm when calling
|
---|
| 1494 | function/procedures passed as parameters.
|
---|
| 1495 | .XS
|
---|
| 1496 | if (static_link) {
|
---|
| 1497 | (*a)(static_link, pars);
|
---|
| 1498 | } else {
|
---|
| 1499 | (*a)(pars);
|
---|
| 1500 | }
|
---|
| 1501 | .XE
|
---|
| 1502 | .LP
|
---|
| 1503 | .ft I
|
---|
| 1504 | 2. Separate compilation.
|
---|
| 1505 | .LP
|
---|
| 1506 | The compiler is able to (separately) compile a collection of declarations,
|
---|
| 1507 | procedures and functions to form a library.
|
---|
| 1508 | The library may be linked with the main program, compiled later.
|
---|
| 1509 | The syntax of these modules is
|
---|
| 1510 | .XS
|
---|
| 1511 | .in +\w'module = 'u
|
---|
| 1512 | .ti -\w'module = 'u
|
---|
| 1513 | module = [constant-definition-part]
|
---|
| 1514 | [type-definition-part]
|
---|
| 1515 | [var-declaration-part]
|
---|
| 1516 | [procedure-and-function-declaration-part]
|
---|
| 1517 | .in -\w'module = 'u
|
---|
| 1518 | .XE
|
---|
| 1519 | The compiler accepts a program or a module:
|
---|
| 1520 | .XS
|
---|
| 1521 | unit = program | module
|
---|
| 1522 | .XE
|
---|
| 1523 | All variables declared outside a module must be imported
|
---|
| 1524 | by parameters, even the files input and output.
|
---|
| 1525 | Access to a variable declared in a module is only possible
|
---|
| 1526 | using the procedures and functions declared in that same module.
|
---|
| 1527 | By giving the correct procedure/function heading followed by the
|
---|
| 1528 | directive 'extern' you may use procedures and functions declared in
|
---|
| 1529 | other units.
|
---|
| 1530 | .LP
|
---|
| 1531 | .ft I
|
---|
| 1532 | 3. Assertions.
|
---|
| 1533 | .LP
|
---|
| 1534 | When the s-option is off,
|
---|
| 1535 | .MX
|
---|
| 1536 | Pascal compiler recognizes an additional
|
---|
| 1537 | statement, the assertion.
|
---|
| 1538 | Assertions can be used as an aid in debugging
|
---|
| 1539 | and documentation.
|
---|
| 1540 | The syntax is:
|
---|
| 1541 | .XS
|
---|
| 1542 | assertion = 'assert' Boolean-expression
|
---|
| 1543 | .XE
|
---|
| 1544 | An assertion is a simple-statement, so
|
---|
| 1545 | .XS
|
---|
| 1546 | .in +\w'simple-statement = ['u
|
---|
| 1547 | .ti -\w'simple-statement = ['u
|
---|
| 1548 | simple-statement = [assignment-statement |
|
---|
| 1549 | procedure-statement |
|
---|
| 1550 | goto-statement |
|
---|
| 1551 | assertion
|
---|
| 1552 | .in -\w'['u
|
---|
| 1553 | ]
|
---|
| 1554 | .in -\w'simple-statement = 'u
|
---|
| 1555 | .XE
|
---|
| 1556 | An assertion causes an error if the Boolean-expression is false.
|
---|
| 1557 | That is its only purpose.
|
---|
| 1558 | It does not change any of the variables, at least it should not.
|
---|
| 1559 | Therefore, do not use functions with side-effects in the Boolean-expression.
|
---|
| 1560 | If the a-option is turned on, then assertions are skipped by the
|
---|
| 1561 | compiler. 'assert' is not a word-symbol (keyword) and may be used as identifier.
|
---|
| 1562 | However, assignment to a variable and calling of a procedure with that
|
---|
| 1563 | name will be impossible.
|
---|
| 1564 | If the s-option is turned on, the compiler will not know a thing about
|
---|
| 1565 | assertions, so using assertions will then give a parse error.
|
---|
| 1566 | .LP
|
---|
| 1567 | .ft I
|
---|
| 1568 | 4. Additional procedures.
|
---|
| 1569 | .LP
|
---|
| 1570 | Three additional standard procedures are available:
|
---|
| 1571 | .IP "halt:"
|
---|
| 1572 | a call of this procedure is equivalent to jumping to the
|
---|
| 1573 | end of your program.
|
---|
| 1574 | It is always the last statement executed.
|
---|
| 1575 | The exit status of the program may be supplied
|
---|
| 1576 | as optional argument.
|
---|
| 1577 | If not, it will be zero.
|
---|
| 1578 | .IP release:
|
---|
| 1579 | .IP mark:
|
---|
| 1580 | for most applications it is sufficient to use the heap as second stack.
|
---|
| 1581 | Mark and release are suited for this type of use, more suited than dispose.
|
---|
| 1582 | mark(p), with p of type pointer, stores the current value of the
|
---|
| 1583 | heap pointer in p. release(p), with p initialized by a call
|
---|
| 1584 | of mark(p), restores the heap pointer to its old value.
|
---|
| 1585 | All the heap objects, created by calls of new between the call of
|
---|
| 1586 | mark and the call of release, are removed and the space they used
|
---|
| 1587 | can be reallocated.
|
---|
| 1588 | Never use mark and release together with dispose!
|
---|
| 1589 | .RE
|
---|
| 1590 | .LP
|
---|
| 1591 | .ft I
|
---|
| 1592 | 5. UNIX interfacing.
|
---|
| 1593 | .LP
|
---|
| 1594 | If the c-option is turned on, then some special features are available
|
---|
| 1595 | to simplify an interface with the UNIX environment.
|
---|
| 1596 | First of all, the compiler allows you to use a different type
|
---|
| 1597 | of string constants.
|
---|
| 1598 | These string constants are delimited by double quotes ('"').
|
---|
| 1599 | To put a double quote into these strings, you must repeat the double quote,
|
---|
| 1600 | like the single quote in normal string constants.
|
---|
| 1601 | These special string constants are terminated by a zero byte (chr(0)).
|
---|
| 1602 | The type of these constants is a pointer to a packed array of characters,
|
---|
| 1603 | with lower bound 1 and unknown upper bound.
|
---|
| 1604 | .br
|
---|
| 1605 | Secondly, the compiler predefines a new type identifier 'string' denoting
|
---|
| 1606 | this just described string type.
|
---|
| 1607 | .PP
|
---|
| 1608 | The only thing you can do with these features is declaration of
|
---|
| 1609 | constants and variables of type 'string'.
|
---|
| 1610 | String objects may not be allocated on the heap and string pointers
|
---|
| 1611 | may not be de-referenced.
|
---|
| 1612 | Still these strings are very useful in combination with external routines.
|
---|
| 1613 | The procedure write is extended to print these zero-terminated
|
---|
| 1614 | strings correctly.
|
---|
| 1615 | .LP
|
---|
| 1616 | .ft I
|
---|
| 1617 | 6. Double length (32 bit) integers.
|
---|
| 1618 | .LP
|
---|
| 1619 | If the d-option is turned on, then the additional type 'long' is known
|
---|
| 1620 | to the compiler.
|
---|
| 1621 | Long variables have integer values in the
|
---|
| 1622 | range \(mi2147483648 .. +2147483647.
|
---|
| 1623 | Long constants can not be declared.
|
---|
| 1624 | Longs can not be used as control-variables.
|
---|
| 1625 | It is not allowed to form subranges of type long.
|
---|
| 1626 | All operations allowed on integers are also
|
---|
| 1627 | allowed on longs and are indicated by the same
|
---|
| 1628 | operators: '+', '-', '*', '/', 'div', 'mod'.
|
---|
| 1629 | The procedures read and write have been extended to handle long
|
---|
| 1630 | arguments correctly.
|
---|
| 1631 | It is possible to read longs from a file of integers
|
---|
| 1632 | and vice-versa, but only if longs and integers have the same size.
|
---|
| 1633 | The default width for longs is 11.
|
---|
| 1634 | The standard procedures 'abs' and 'sqr' have been extended to work
|
---|
| 1635 | on long arguments.
|
---|
| 1636 | Conversion from integer to long, long to real,
|
---|
| 1637 | real to long and long to integer are automatic, like the conversion
|
---|
| 1638 | from integer to real.
|
---|
| 1639 | These conversions may cause a
|
---|
| 1640 | .PP
|
---|
| 1641 | .RS
|
---|
| 1642 | conversion error, trap 10, non-fatal
|
---|
| 1643 | .RE
|
---|
| 1644 | .LP
|
---|
| 1645 | .ft I
|
---|
| 1646 | 7. Underscore as letter.
|
---|
| 1647 | .LP
|
---|
| 1648 | The character '_' may be used in forming identifiers, if the u- or U-option
|
---|
| 1649 | is turned on.
|
---|
| 1650 | It is forbidden to start identifiers with underscores, since
|
---|
| 1651 | this may cause name-clashes with run-time routines.
|
---|
| 1652 | .LP
|
---|
| 1653 | .ft I
|
---|
| 1654 | 8. Zero field width in write.
|
---|
| 1655 | .LP
|
---|
| 1656 | Zero TotalWidth arguments are allowed.
|
---|
| 1657 | In this case, no characters are written for
|
---|
| 1658 | character, string or Boolean type arguments.
|
---|
| 1659 | A zero FracDigits
|
---|
| 1660 | argument for fixed-point representation of reals causes the fraction and
|
---|
| 1661 | the character '.' to be suppressed.
|
---|
| 1662 | .LP
|
---|
| 1663 | .ft I
|
---|
| 1664 | 9. Pre-processing.
|
---|
| 1665 | .LP
|
---|
| 1666 | If the very first character of a file containing a Pascal
|
---|
| 1667 | program is the sharp ('#', ASCII 23(hex)) the file is preprocessed
|
---|
| 1668 | in the same way as C programs.
|
---|
| 1669 | Lines beginning with a '#' are taken as preprocessor command lines
|
---|
| 1670 | and not fed to the Pascal compiler proper.
|
---|
| 1671 | C style comments, /*......*/, are removed by the C preprocessor,
|
---|
| 1672 | thus C comments inside Pascal programs are also removed when they
|
---|
| 1673 | are fed through the preprocessor.
|
---|
| 1674 | .in 0
|
---|
| 1675 | .SS "Deviations from the standard"
|
---|
| 1676 | .PP
|
---|
| 1677 | .MX
|
---|
| 1678 | Pascal deviates from the standard in the following ways:
|
---|
| 1679 | .IP 1.
|
---|
| 1680 | Standard procedures and functions are not allowed as parameters in
|
---|
| 1681 | .MX
|
---|
| 1682 | Pascal.
|
---|
| 1683 | You can obtain the same result with negligible loss of performance
|
---|
| 1684 | by declaring some user routines like:
|
---|
| 1685 | .XS
|
---|
| 1686 | .CW
|
---|
| 1687 | function sine(x:real):real;
|
---|
| 1688 | begin
|
---|
| 1689 | sine:=sin(x)
|
---|
| 1690 | end;
|
---|
| 1691 | .ft R
|
---|
| 1692 | .XE
|
---|
| 1693 | .IP 2.
|
---|
| 1694 | The standard procedures read, readln, write and writeln are implemented as
|
---|
| 1695 | word-symbols, and can therefore not be redeclared.
|
---|
| 1696 | .SS "Compiler options"
|
---|
| 1697 | .PP
|
---|
| 1698 | Some options of the compiler may be controlled by using '{$....}'.
|
---|
| 1699 | Each option consists of a lower case letter followed by +, \(mi or an unsigned
|
---|
| 1700 | number.
|
---|
| 1701 | Options are separated by commas.
|
---|
| 1702 | The following options exist:
|
---|
| 1703 | .IP a+/\(mi
|
---|
| 1704 | This option switches assertions on and off.
|
---|
| 1705 | If this option is on, then code is included to test these assertions
|
---|
| 1706 | at run time.
|
---|
| 1707 | Default +.
|
---|
| 1708 | .IP c+/\(mi
|
---|
| 1709 | This option, if on, allows you to use C-type string constants
|
---|
| 1710 | surrounded by double quotes.
|
---|
| 1711 | Moreover, a new type identifier 'string' is predefined.
|
---|
| 1712 | Default \(mi.
|
---|
| 1713 | .IP d+/\(mi
|
---|
| 1714 | This option, if on, allows you to use variables of type 'long'.
|
---|
| 1715 | Default \(mi.
|
---|
| 1716 | .IP i<num>
|
---|
| 1717 | .br
|
---|
| 1718 | With this flag the setsize for a set of integers can be
|
---|
| 1719 | manipulated.
|
---|
| 1720 | The number must be the number of bits per set.
|
---|
| 1721 | The default value is 16.
|
---|
| 1722 | .IP l+/\(mi
|
---|
| 1723 | If + then code is inserted to keep track of the source line number.
|
---|
| 1724 | When this flag is switched on and off, an incorrect line number may appear
|
---|
| 1725 | if the error occurs in a part of your program for which this flag is off.
|
---|
| 1726 | Default +.
|
---|
| 1727 | .IP r+/\(mi
|
---|
| 1728 | If + then code is inserted to check subrange variables against
|
---|
| 1729 | lower and upper subrange limits.
|
---|
| 1730 | Default +.
|
---|
| 1731 | .IP s+/\(mi
|
---|
| 1732 | If + then the compiler will hunt for places in your program
|
---|
| 1733 | where non-standard features are used, and for each place found
|
---|
| 1734 | it will generate a warning.
|
---|
| 1735 | Default \(mi.
|
---|
| 1736 | .IP t+/\(mi
|
---|
| 1737 | If + then each time a procedure is entered, the routine 'procentry' is
|
---|
| 1738 | called, and each time a procedure exits, the procedure 'procexit' is
|
---|
| 1739 | called.
|
---|
| 1740 | Both 'procentry' and 'procexit' have a 'string' as parameter.
|
---|
| 1741 | This means that when a user specifies his or her own procedures, the c-option
|
---|
| 1742 | must be used.
|
---|
| 1743 | Default procedures are present in the run time library.
|
---|
| 1744 | Default \(mi.
|
---|
| 1745 | .IP u+/\(mi
|
---|
| 1746 | If + then the character '_' is treated like a letter,
|
---|
| 1747 | so that it may be used in identifiers.
|
---|
| 1748 | Procedure and function identifiers are not allowed to start with an
|
---|
| 1749 | underscore because they may collide with library routine names.
|
---|
| 1750 | Default \(mi.
|
---|
| 1751 | .PP
|
---|
| 1752 | Some of these flags (c, d, i, s, u, C and U) are only effective when
|
---|
| 1753 | they appear before the 'program' symbol.
|
---|
| 1754 | The others may be switched
|
---|
| 1755 | on and off.
|
---|
| 1756 | .PP
|
---|
| 1757 | A very powerful debugging tool is the knowledge that inaccessible statements
|
---|
| 1758 | and useless tests are removed by the optimizer.
|
---|
| 1759 | For instance, a statement like:
|
---|
| 1760 | .XS
|
---|
| 1761 | .CW
|
---|
| 1762 | if debug then
|
---|
| 1763 | writeln('initialization done');
|
---|
| 1764 | .ft R
|
---|
| 1765 | .XE
|
---|
| 1766 | is completely removed by the optimizer if debug is a constant with
|
---|
| 1767 | value false.
|
---|
| 1768 | The first line is removed if debug is a constant with value true.
|
---|
| 1769 | Of course, if debug is a variable nothing can be removed.
|
---|
| 1770 | .SS "Library routines"
|
---|
| 1771 | .PP
|
---|
| 1772 | The following library of external routines for Pascal programs is available:
|
---|
| 1773 | .nf
|
---|
| 1774 | .SP
|
---|
| 1775 | .CW
|
---|
| 1776 | .ta 12n
|
---|
| 1777 | const bufsize = ?;
|
---|
| 1778 | type br1 = 1..bufsize;
|
---|
| 1779 | br2 = 0..bufsize;
|
---|
| 1780 | br3 = -1..bufsize;
|
---|
| 1781 | ok = -1..0;
|
---|
| 1782 | buf = packed array[br1] of char;
|
---|
| 1783 | alfa = packed array[1..8] of char;
|
---|
| 1784 | string = ^packed array[1..?] of char;
|
---|
| 1785 | filetype = file of ?;
|
---|
| 1786 | long = ?;
|
---|
| 1787 | .SP
|
---|
| 1788 | {all routines must be declared extern}
|
---|
| 1789 | .SP
|
---|
| 1790 | function argc:integer;
|
---|
| 1791 | function argv(i:integer):string;
|
---|
| 1792 | function environ(i:integer):string;
|
---|
| 1793 | procedure argshift;
|
---|
| 1794 | .SP
|
---|
| 1795 | procedure buff(var f:filetype);
|
---|
| 1796 | procedure nobuff(var f:filetype);
|
---|
| 1797 | procedure notext(var f:text);
|
---|
| 1798 | procedure diag(var f:text);
|
---|
| 1799 | procedure pcreat(var f:text; s:string);
|
---|
| 1800 | procedure popen(var f:text; s:string);
|
---|
| 1801 | procedure pclose(var f:filetype);
|
---|
| 1802 | .SP
|
---|
| 1803 | procedure trap(err:integer);
|
---|
| 1804 | procedure encaps(procedure p; procedure q(n:integer));
|
---|
| 1805 | .SP
|
---|
| 1806 | function perrno:integer;
|
---|
| 1807 | function uread(fd:integer; var b:buf; len:br1):br3;
|
---|
| 1808 | function uwrite(fd:integer; var b:buf; len:br1):br3;
|
---|
| 1809 | .SP
|
---|
| 1810 | function strbuf(var b:buf):string;
|
---|
| 1811 | function strtobuf(s:string; var b:buf; len:br1):br2;
|
---|
| 1812 | function strlen(s:string):integer;
|
---|
| 1813 | function strfetch(s:string; i:integer):char;
|
---|
| 1814 | procedure strstore(s:string; i:integer; c:char);
|
---|
| 1815 | .SP
|
---|
| 1816 | function clock:integer;
|
---|
| 1817 | .fi
|
---|
| 1818 | .ft R
|
---|
| 1819 | .PP
|
---|
| 1820 | This library contains some often used external routines for Pascal programs.
|
---|
| 1821 | The routines can be divided into several categories:
|
---|
| 1822 | .PP
|
---|
| 1823 | .ti -2
|
---|
| 1824 | Argument control:
|
---|
| 1825 | .RS
|
---|
| 1826 | .IP argc 10
|
---|
| 1827 | Gives the number of arguments provided when the program is called.
|
---|
| 1828 | .IP argv
|
---|
| 1829 | Selects the specified argument from the argument list and returns a
|
---|
| 1830 | pointer to it.
|
---|
| 1831 | This pointer is nil if the index is out of bounds (<0 or >=argc).
|
---|
| 1832 | .IP environ
|
---|
| 1833 | Returns a pointer to the i-th environment string (i>=0).
|
---|
| 1834 | Returns nil
|
---|
| 1835 | if i is beyond the end of the environment list (UNIX version 7).
|
---|
| 1836 | .IP argshift
|
---|
| 1837 | Effectively deletes the first argument from the argument list.
|
---|
| 1838 | Its function is equivalent to \fIshift\fR in the UNIX shell: argv[2] becomes
|
---|
| 1839 | argv[1], argv[3] becomes argv[2], etc.
|
---|
| 1840 | It is a useful procedure to skip optional flag arguments.
|
---|
| 1841 | Note that the matching of arguments and files
|
---|
| 1842 | is done at the time a file is opened by a call to reset or rewrite.
|
---|
| 1843 | .PP
|
---|
| 1844 | .ti -2
|
---|
| 1845 | Additional file handling routines:
|
---|
| 1846 | .IP buff
|
---|
| 1847 | Turn on buffering of a file.
|
---|
| 1848 | Not very useful, because all
|
---|
| 1849 | files are buffered except standard output to a terminal and diagnostic output.
|
---|
| 1850 | Input files are always buffered.
|
---|
| 1851 | .IP nobuff
|
---|
| 1852 | Turn off buffering of an output file.
|
---|
| 1853 | It causes the current contents of the
|
---|
| 1854 | buffer to be flushed.
|
---|
| 1855 | .IP notext
|
---|
| 1856 | Only useful for input files.
|
---|
| 1857 | End of line characters are not replaced by a space and character codes out of
|
---|
| 1858 | the ASCII range (0..127) do not cause an error message.
|
---|
| 1859 | .IP diag
|
---|
| 1860 | Initialize a file for output on the diagnostic output stream (fd=2).
|
---|
| 1861 | Output is not buffered.
|
---|
| 1862 | .IP pcreat
|
---|
| 1863 | The same as rewrite(f), except that you must provide the file name yourself.
|
---|
| 1864 | The name must be zero terminated.
|
---|
| 1865 | Only text files are allowed.
|
---|
| 1866 | .IP popen
|
---|
| 1867 | The same as reset(f), except that you must provide the file name yourself.
|
---|
| 1868 | The name must be zero terminated.
|
---|
| 1869 | Only text files are allowed.
|
---|
| 1870 | .IP pclose
|
---|
| 1871 | Gives you the opportunity to close files hidden in records or arrays.
|
---|
| 1872 | All other files are closed automatically.
|
---|
| 1873 | .PP
|
---|
| 1874 | .ti -2
|
---|
| 1875 | String handling:
|
---|
| 1876 | .IP strbuf
|
---|
| 1877 | Type conversion from character array to string.
|
---|
| 1878 | It is your own responsibility that the string is zero terminated.
|
---|
| 1879 | .IP strtobuf
|
---|
| 1880 | Copy string into buffer until the string terminating zero byte
|
---|
| 1881 | is found or until the buffer if full, whatever comes first.
|
---|
| 1882 | The zero byte is also copied.
|
---|
| 1883 | The number of copied characters, excluding the zero byte, is returned.
|
---|
| 1884 | So if
|
---|
| 1885 | the result is equal to the buffer length, then the end of buffer is reached
|
---|
| 1886 | before the end of string.
|
---|
| 1887 | .IP strlen
|
---|
| 1888 | Returns the string length excluding the terminating zero byte.
|
---|
| 1889 | .IP strfetch
|
---|
| 1890 | Fetches the i-th character from a string.
|
---|
| 1891 | There is no check against the string length.
|
---|
| 1892 | .IP strstore
|
---|
| 1893 | Stores a character in a string.
|
---|
| 1894 | There is no check against
|
---|
| 1895 | string length, so this is a dangerous procedure.
|
---|
| 1896 | .PP
|
---|
| 1897 | .ti -2
|
---|
| 1898 | Trap handling:
|
---|
| 1899 | .PP
|
---|
| 1900 | These routines allow you to handle almost all
|
---|
| 1901 | the possible error situations yourself.
|
---|
| 1902 | You may define your own trap handler, replacing the
|
---|
| 1903 | default handler that produces an error message and quits.
|
---|
| 1904 | You may also generate traps yourself.
|
---|
| 1905 | .IP trap
|
---|
| 1906 | Trap generates the trap passed as argument (0..252).
|
---|
| 1907 | The trap numbers 128..252 may be used freely.
|
---|
| 1908 | The others are reserved.
|
---|
| 1909 | .IP encaps
|
---|
| 1910 | Encapsulate the execution of \fIp\fR with the trap handler \fIq\fR.
|
---|
| 1911 | Encaps replaces the previous trap handler by \fIq\fR, calls \fIp\fR
|
---|
| 1912 | and restores
|
---|
| 1913 | the previous handler when \fIp\fR returns.
|
---|
| 1914 | If, during the execution of \fIp\fR, a trap occurs,
|
---|
| 1915 | then \fIq\fR is called with the trap number as parameter.
|
---|
| 1916 | For the duration of \fIq\fR the previous trap handler is restored, so that
|
---|
| 1917 | you may handle only some of the errors in \fIq\fR.
|
---|
| 1918 | All the other errors must
|
---|
| 1919 | then be raised again by a call to \fItrap\fR.
|
---|
| 1920 | .br
|
---|
| 1921 | Encapsulations may be nested: you may encapsulate a procedure while executing
|
---|
| 1922 | an encapsulated routine.
|
---|
| 1923 | .br
|
---|
| 1924 | Jumping out of an encapsulated procedure (non-local goto) is dangerous,
|
---|
| 1925 | because the previous trap handler must be restored.
|
---|
| 1926 | Therefore, you may only jump out of procedure \fIp\fR from inside \fIq\fR and
|
---|
| 1927 | you may only jump out of one level of encapsulation.
|
---|
| 1928 | If you want to exit several levels of encapsulation, use traps.
|
---|
| 1929 | See pc_prlib(7) for lists of trap numbers
|
---|
| 1930 | for EM machine errors and Pascal run time system errors.
|
---|
| 1931 | Note that \fIp\fR may not have parameters.
|
---|
| 1932 | .PP
|
---|
| 1933 | .ti -2
|
---|
| 1934 | UNIX system calls:
|
---|
| 1935 | .IP uread
|
---|
| 1936 | Equal to the read system call.
|
---|
| 1937 | Its normal name is blocked by the standard Pascal routine read.
|
---|
| 1938 | .IP uwrite
|
---|
| 1939 | As above but for write(2).
|
---|
| 1940 | .IP perrno
|
---|
| 1941 | Because external data references are not possible in Pascal,
|
---|
| 1942 | this routine returns the global variable \fIerrno\fR, indicating the result of
|
---|
| 1943 | the last system call.
|
---|
| 1944 | .PP
|
---|
| 1945 | .ti -2
|
---|
| 1946 | Miscellaneous:
|
---|
| 1947 | .IP clock
|
---|
| 1948 | Return the number of ticks of user and system time consumed by the program.
|
---|
| 1949 | .PP
|
---|
| 1950 | The following program presents an example of how these routines can be used.
|
---|
| 1951 | This program is equivalent to the UNIX command cat(1).
|
---|
| 1952 | .nf
|
---|
| 1953 | .SP
|
---|
| 1954 | .CW
|
---|
| 1955 | {$c+}
|
---|
| 1956 | .CW
|
---|
| 1957 | program cat(input,inp,output);
|
---|
| 1958 | .CW
|
---|
| 1959 | var inp:text;
|
---|
| 1960 | .CW
|
---|
| 1961 | s:string;
|
---|
| 1962 | .SP
|
---|
| 1963 | .CW
|
---|
| 1964 | function argc:integer; extern;
|
---|
| 1965 | .CW
|
---|
| 1966 | function argv(i:integer):string; extern;
|
---|
| 1967 | .CW
|
---|
| 1968 | procedure argshift; extern;
|
---|
| 1969 | .CW
|
---|
| 1970 | function strlen(s:string):integer; extern;
|
---|
| 1971 | .CW
|
---|
| 1972 | function strfetch(s:string; i:integer):char; extern;
|
---|
| 1973 | .SP
|
---|
| 1974 | .CW
|
---|
| 1975 | procedure copy(var fi:text);
|
---|
| 1976 | .CW
|
---|
| 1977 | var c:char;
|
---|
| 1978 | .CW
|
---|
| 1979 | begin reset(fi);
|
---|
| 1980 | .CW
|
---|
| 1981 | while not eof(fi) do
|
---|
| 1982 | .CW
|
---|
| 1983 | begin
|
---|
| 1984 | .CW
|
---|
| 1985 | while not eoln(fi) do
|
---|
| 1986 | .CW
|
---|
| 1987 | begin
|
---|
| 1988 | .CW
|
---|
| 1989 | read(fi,c);
|
---|
| 1990 | .CW
|
---|
| 1991 | write(c)
|
---|
| 1992 | .CW
|
---|
| 1993 | end;
|
---|
| 1994 | .CW
|
---|
| 1995 | readln(fi);
|
---|
| 1996 | .CW
|
---|
| 1997 | writeln
|
---|
| 1998 | .CW
|
---|
| 1999 | end
|
---|
| 2000 | .CW
|
---|
| 2001 | end;
|
---|
| 2002 | .SP
|
---|
| 2003 | .CW
|
---|
| 2004 | begin {main}
|
---|
| 2005 | .CW
|
---|
| 2006 | if argc = 1 then
|
---|
| 2007 | .CW
|
---|
| 2008 | copy(input)
|
---|
| 2009 | .CW
|
---|
| 2010 | else
|
---|
| 2011 | .CW
|
---|
| 2012 | repeat
|
---|
| 2013 | .CW
|
---|
| 2014 | s := argv(1);
|
---|
| 2015 | .CW
|
---|
| 2016 | if (strlen(s) = 1) and (strfetch(s,1) = '-')
|
---|
| 2017 | .CW
|
---|
| 2018 | then copy(input)
|
---|
| 2019 | .CW
|
---|
| 2020 | else copy(inp);
|
---|
| 2021 | .CW
|
---|
| 2022 | argshift;
|
---|
| 2023 | .CW
|
---|
| 2024 | until argc <= 1;
|
---|
| 2025 | .CW
|
---|
| 2026 | end.
|
---|
| 2027 | .fi
|
---|
| 2028 | .ft R
|
---|
| 2029 | .PP
|
---|
| 2030 | Another example gives some idea of the way to manage trap handling:
|
---|
| 2031 | .nf
|
---|
| 2032 | .SP
|
---|
| 2033 | .CW
|
---|
| 2034 | program bigreal(output);
|
---|
| 2035 | .CW
|
---|
| 2036 | const EFOVFL=4;
|
---|
| 2037 | .CW
|
---|
| 2038 | var trapped:boolean;
|
---|
| 2039 | .CW
|
---|
| 2040 | .SP
|
---|
| 2041 | .CW
|
---|
| 2042 | procedure encaps(procedure p; procedure q(n:integer)); extern;
|
---|
| 2043 | .CW
|
---|
| 2044 | procedure trap(n:integer); extern;
|
---|
| 2045 | .CW
|
---|
| 2046 | .SP
|
---|
| 2047 | .CW
|
---|
| 2048 | procedure traphandler(n:integer);
|
---|
| 2049 | .CW
|
---|
| 2050 | begin if n=EFOVFL then trapped:=true else trap(n) end;
|
---|
| 2051 | .CW
|
---|
| 2052 | .SP
|
---|
| 2053 | .CW
|
---|
| 2054 | procedure work;
|
---|
| 2055 | .CW
|
---|
| 2056 | var i,j:real;
|
---|
| 2057 | .CW
|
---|
| 2058 | begin trapped:=false; i:=1;
|
---|
| 2059 | .CW
|
---|
| 2060 | while not trapped do
|
---|
| 2061 | .CW
|
---|
| 2062 | begin j:=i; i:=i*2 end;
|
---|
| 2063 | .CW
|
---|
| 2064 | writeln('bigreal = ',j);
|
---|
| 2065 | .CW
|
---|
| 2066 | end;
|
---|
| 2067 | .CW
|
---|
| 2068 | .SP
|
---|
| 2069 | .CW
|
---|
| 2070 | begin
|
---|
| 2071 | .CW
|
---|
| 2072 | encaps(work,traphandler);
|
---|
| 2073 | .CW
|
---|
| 2074 | end.
|
---|
| 2075 | .fi
|
---|
| 2076 | .ft R
|
---|
| 2077 | .PP
|
---|
| 2078 | Two routines may cause fatal error messages to be generated.
|
---|
| 2079 | These are:
|
---|
| 2080 | .IP pcreat
|
---|
| 2081 | Rewrite error (trap 77) if the file cannot be created.
|
---|
| 2082 | .IP popen
|
---|
| 2083 | Reset error (trap 76) if the file cannot be opened for reading
|
---|
| 2084 | .SS References
|
---|
| 2085 | .IP [1]
|
---|
| 2086 | BSI standard BS 6192: 1982 (ISO 7185).
|
---|
| 2087 | .IP [2]
|
---|
| 2088 | A.S.Tanenbaum, J.W.Stevenson, Hans van Staveren, E.G.Keizer,
|
---|
| 2089 | "Description of a machine architecture for use with block structured languages",
|
---|
| 2090 | Informatica rapport IR-81.
|
---|