improv.doc 2.6 KB

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