Frank Heckenbach frank@fjf.gnu.de wrote:
[...]
In order to allow the same identifier in different units/modules (which is required by both the Standard and Borland Pascal and which GPC currently doesn't support), we need to change the "name mangling", anyway.
Instead of "Foobar" for an identifier `FooBar' declared in a unit/module `Baz', we could probably use `baz.foobar' (or `baz$foobar'), all lower-case, without risking name clashes with the libc.
Since such routines should be calleable from programs with the declaration "baz.foobar", it might be that the dot notation would be preferable to the "$" notation (but of course, it might not make any difference to the compiler which notation is used internally).
For the external declarations, my suggestions is:
Procedure Foo; external; (* extern void foo ( void ); *)
(I.e., `external' will convert the name to lower-case, without the module name prefix.)
Procedure FooBar; external name 'FooBar'; (* extern void FooBar ( void ); *)
I've heard Delphi has something like this (`external' and `name'). Is it the same syntax, or what does it look like in Delphi?
Delphi has the same notation, with the same syntax as above, used in the context of *importing* routines from dynamic link libraries (DLLs). Normally the DLL's name will be in-between "external" and "name" -e.g.,
Procedure FooBar; external 'barfoo.dll' name 'FooBar';
A slightly similar notation also exists for *exporting* routines from DLLs, in which case it has to be used in a separate "EXPORTS" section at the end of the DLL source (instead of the point where the function is declared) - e.g.,
Library barfoo;
Procedure foobar; Begin // blah, blah End;
Function foofoo : integer; Begin Result := -22; End;
EXPORTS foobar name 'FooBar', foofoo index 1 name 'FooFOO'; // index is optional
Begin End.
I am not sure if (and if so, how) these should be supported by GPC.
Note: Identifiers exported in this way are case-sensitive when you want to import the DLL functions with the "name" declaration. This is not a Delphi thing but a Win32 thing, so GPC does not need to (and probably should not) seek to copy that behaviour. In any case, AFAIK, DLLs are only relevant to OS/2 and Win32, so this may not be an issue of serious concern.
BTW, we could then also have:
Procedure FooBar; name 'FooBar'; begin end;
to declare a Pascal procedure with a given internal name, instead of the "strange" form that is now necessary:
Procedure FooBar; asmname 'FooBar'; Procedure FooBar; begin end;
These are just ideas right now. Any comments?
Sounds like a good idea. But what about supporting a separate EXPORTS section in UNITs (and not just DLLs) - in which case all the "name" declarations can just be aggregated together at the end of the source file before the initialisation section? This might also have the advantage of preparing the ground to Delphi-style DLL writing for the platforms that support it, while also extending the facilities beyond the scope of DLLs. Just a thought ...
Best regards, The Chief -------- Dr. Abimbola A. Olowofoyeku (The African Chief) Email: laa12@keele.ac.uk Homepage: http://ourworld.compuserve.com/homepages/African_Chief/ Author of: Chief's Installer Pro v5.00 for Win32 ftp://ftp.simtel.net/pub/simtelnet/win95/install/chief500.zip