Sujet : Re: question about linker
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 04. Dec 2024, 16:46:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vipthe$umjj$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : Mozilla Thunderbird
On 04/12/2024 12:29, Waldek Hebisch wrote:
Bart <bc@freeuk.com> wrote:
You've never used my scheme.
Your scheme, not. But you should understand that when speaking
about module systems C is an outlier, having almost no support
for modules. Some languages, like C++ and Lisp go half way,
providing namespaces but rest is up to programmer. Other do
more. By now classis is _logical_ separation into interface
and implementation, which seem to be absent from your system.
It is there, but at a different boundary.
My language is intended for whole program compilation. There are no interfaces between modules (that is, a file listing the exports of a module, separately from the implementation).
Because the compiler can see (and will compile) the actual implementation
Such interface files exist between programs, which usually means between a main program and the libraries it uses, which are generally dynamically loaded.
To that end, when compiling a set of modules into a library, the compiler can generate a suitable interface file (I used to call them exports files).
This part is poorly developed, as it is little used, but it can create such files for my two languages, and /could/ generate them for C. There, it would take the form of a header file.
Example library, called fred.m:
export func add3(int a,b,c)int =
a+b+c
end
Create the DLL and interface:
c:\mapps>mm -dll fred
Compiling fred.m to fred.dll
Writing exports file to fred_lib.m
The interface file produced (fred_lib.m):
importdllfred =
func add3(i64 a,b,c) => i64
end
The C version would be:
extern i64 add3(i64, i64, i64);
Back to my version, I can use that DLL like this:
module fred_lib
proc main =
println add3(10,20,30)
end
Compile and run that:
c:\mapps>mm -r test
Compiling test.m to test.(run)
60
As a bonus, this simple example will also run unchanged in my dynamic scripting language; I just need to change the file extensions. So I can trivially create native-code functions to call from dynamic code.
But in practice, more work is needed.