source: trunk/minix/man/man7/ACK.7@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

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