Pristine Ack-5.5
[Ack-5.5.git] / doc / pascal / improv.doc
1 .sp 2
2 .NH
3 Improvements to the compiler
4 .nh
5 .sp
6 .LP
7 In consideration of portability, a restricted option could be implemented.
8 Under this option, the extensions and warnings should be considered as errors.
9
10
11 .LP
12 The restrictions imposed by the standard on the control variable of a
13 for-statment should be implemented (\fBISO 6.8.3.9\fR).
14
15 .LP
16 To check whether a function returns a valid result, the following algorithm
17 could be used. When a function is entered a hidden temporary variable of
18 type boolean is created. This variable is initialized with the value false.
19 The variable is set to true, when an assignment to the function name occurs.
20 On exit of the function a test is performed on the variable. If the value
21 of the variable is false, a run-time error occurs.
22 .br
23 Note: The check has to be done run-time.
24
25
26 .LP
27 The \fIundefined value\fR should be implemented. A problem arises with
28 local variables, for which space on the stack is allocated. A possible
29 solution would be to generate code for the initialization of the local
30 variables with the undefined value at the beginning of a procedure or
31 function.
32 .br
33 The implementation for the global variables is easy, because \fBbss\fR
34 blocks are used.
35
36
37 .LP
38 Closely related to the last point is the generation of warnings when
39 variables are never used or assigned. This is not yet implemented.
40
41
42 .LP
43 The error messages could specify more details about the errors occurred,
44 if some additional testing is done.
45
46 .bp
47 .LP
48 Every time the compiler detects sets with different base-types, a warning
49 is given. Sometimes this is superfluous.
50
51 .nf
52 \fBprogram\fR sets(output);
53 \fBtype\fR
54         week = (sunday, monday, tuesday, wednesday, thursday, friday, saturday);
55         workweek = monday..friday;
56 \fBvar\fR
57         s : \fBset of\fR workweek;
58         day : week;
59 \fBbegin\fR
60         day := monday;
61         s := [day];             (* warning *)
62         day := saturday;
63         s := [day];             (* warning *)
64 \fBend\fR.
65 .fi
66 The new compiler gives two warnings, the first one is redundant.
67
68
69 .LP
70 A nasty point in the compiler is the way the procedures \fIread, readln,
71 write\fR and \fIwriteln\fR are handled (see also section 2.2). They have
72 been added to the grammar. This implies that they can not be redefined as
73 opposed to the other required procedures and functions. They should be
74 removed from the grammar altogether. This could imply that more semantic
75 checks have to be performed.
76
77
78 .LP
79 No effort is made to detect possible run-time errors during compilation.
80 .br
81 E.g. a : \fBarray\fR[1..10] \fBof\fI something\fR, and the array selection
82 a[11] would occur.
83
84
85 .LP
86 Some assistance to implement the improvements mentioned above, can be
87 obtained from [PCV].