D as an extension language for C
Walter Bright
newshound2 at digitalmars.com
Sat May 13 18:09:33 UTC 2023
On 5/12/2023 3:07 PM, user wrote:
> Future: D as better assembly
It already is. D has a better assembler than Gnu, and VC doesn't even have an
assembler.
Perhaps I haven't clarified the purpose of ImportC.
D was designed from the beginning to leverage off of existing C code. D's
foreign function interface with C is excellent.
But D itself cannot read C .h files nor .c files (a capability that C++ has and
has used to great advantage). .h files must be laboriously converted to D. We've
done a lot of the usual system .h files conversions, such as core.stdc.stdio,
they are in druntime.
The Deimos project is to collect crowd-sourced conversions of C .h files.
The fundamental problem with hand conversions is they are tedious, boring work
that nobody wants to do. They also need redoing whenever the vendor of the .h
file changes them. As the D community grows, this simply does not scale.
Then there were three attempts at programmatic conversion of .h to .d files, one
written by me, one by Jacob, and one by Atila. Those brought us to 3rd base.
To do a home run, the compiler needs to understand C code directly - this is
ImportC.
Using D as an extension language for ImportC enabled me to easily get working a
number of C features (such as variadic arguments) that would otherwise have
required a fair chunk of explicit code to implement. Instead, I was able have it
use D's existing implementation code (which is non-trivial) in core.stdc.stdarg.
I.e. ImportC is an enabler of D use.
More information about the Digitalmars-d
mailing list