Two thoughts on GNU Pascal to discuss:
Based on previous experiences with another Pascal system, one of the most useful features was run-time checking (array bounds, sub-ranges, enumerated types, etc.). This often found problems in code without much effort. It could also be selectively be turned off for efficiency. With GNU Pascal we have C-style run-time checking (i.e. essentially no run-time error checking unless a wild pointer causes some type of exeception).
I'm wondering: 1. Would people find this a useful feature for GNU Pascal? 2. Would it be feasible to implement it in the compiler?
--------------------------------------
GNU Pascal converts the case-insensitive Pascal identifiers to symbols that are lower-case with the first letter capitalized. This has two implications: - in gdb you need to use the capitalized identifier which is not intuitive to users - you cannot call C routines that do not match the capitalized naming scheme.
The first issue can presumably be fixed in the debugger, but the second is more of a problem because I'd like to be able to call C code directly. I can see several approaches to solve this: 1 Make Pascal case sensitive (probably not an option since it would presumably not match the language spec) 2. Convert Pascal symnbols to all lowercase. You could then call C routines if they were all lowercase (which is the most common). 3. Have some extension to indicate C linkage (like C++ and some C compilers do). Maybe an extension or alternative to the EXTERNAL keyword.
Note, a side effect of capitalizing all identifiers in the lexical analyzer is that currently the compiler may report an error such as
foo.pas:1: parse error before `Error'
when the source code actually used the string 'ERROR'.
Hi!
Jeff Tranter wrote:
Based on previous experiences with another Pascal system, one of the most useful features was run-time checking (array bounds, sub-ranges, enumerated types, etc.). [...] I'm wondering:
- Would people find this a useful feature for GNU Pascal?
Yes.
- Would it be feasible to implement it in the compiler?
It is planned for after 2.1. See the GPC TODO list, http://fjf.gnu.de/gpc-todo_toc.html, for details.
If you want to help us implementing it, be welcome. :)
It could also be selectively be turned off for efficiency.
Yes, of course: With BP-compatible (*$R+*) or (*$R-*), command-line options --[no-]range-checking and associated compiler directives (*$[no-]range-checking *)
GNU Pascal converts the case-insensitive Pascal identifiers to symbols that are lower-case with the first letter capitalized. [...] 1 Make Pascal case sensitive (probably not an option since it would presumably not match the language spec)
This is not an option indeed.
- Convert Pascal symnbols to all lowercase. You could then call C routines if they were all lowercase (which is the most common).
This would cause a lot of name clashes with C library functions. For instance, a user program would not be allowed to declare a procedure `puts'.
- Have some extension to indicate C linkage (like C++ and
some C compilers do). Maybe an extension or alternative to the EXTERNAL keyword.
This already exists. See `info -f gpc -n "Other languages"'.
Procedure Foo; C; (* extern void foo ( void ); *)
Procedure FooBar; asmname 'FooBar'; (* extern void FooBar ( void ); *)
Note, a side effect of capitalizing all identifiers in the lexical analyzer is that currently the compiler may report an error such as
foo.pas:1: parse error before `Error'
when the source code actually used the string 'ERROR'.
I already thought of storing the first occurrence of a Pascal identifier for such messages, but right now I think that we have more important things to do.
Thanks for your input,
Peter