It’s coming to an end… I’m pretty happy with the DIP now and the proof-of-concept implementation is done. I used some workarounds to get linkage done, but all in all, almost every aspect of the DIP is implemented. You can experiment, or as Andrei has coined:
DESTROY!
If you’re intrigued, but rather new to D compiler development (as I was up until very recently) and you want to play around with it, but have no clue how, here’s what I do to test my implementation:
- Install DMD.
- Clone https://github.com/Bolpat/dmd/
- Checkout branch
PrimaryTypeSyntax
- In a shell, navigate to the
dmd/compiler/src
directory. - Compile the new compiler:
dmd -m64 -i dmd/main.d -of=../../dmd.exe -Jdmd/res -J../..
- Copy, hardlink, or move the executable (
..\..\dmd.exe
on Windows) to the DMD installation folder under the namedmd-pts
:copy /Y ..\..\dmd.exe C:\D\dmd2\windows\bin64\dmd-pts.exe > NUL
Assuming the DMD bin64
folder is in your PATH
, compile and run your tests using the newly compiled compiler, e.g.: dmd-pts -run hello_primary_type_syntax.d
The only part that’s missing is semantically applying linkage in template lambdas that aren’t alias declarations. (Yes, it’s that specific; linkage for non-template lambdas works, and in alias declarations, linkage also always works.) For a concrete example of what fails:
template t(alias fun)
{
static assert(is(typeof(fun!int) : extern(C) int function(int))); // FIXME
}
alias _ = t!(function extern(C) (x) => x);
// ~~~~~~~~~
// currently ignored :(
The reason is twofold: For TypeFunction
it seems its linkage
is generally ignored by the rest of the compiler and while I can barely manage to fumble around with the parser, I don’t see myself addressing this. It would make implementing linkage almost as easy as ref
, which was pretty easy. Working around that, I used LinkDeclaration
, which goes well for non-template lambdas as they end up having a type (one that’s not void
), and it works very well for alias declarations because those can become a LinkDeclaration
. Only template lambdas that aren’t the right-hand side of an alias are an issue. The parser requires those to be an Expression
, any would do, but a FuncExp
is the most reasonable one. The issue is, a FuncExp
must either wrap a FuncLiteralDeclaration
or a TemplateDeclaration
with exactly one member which must be a FuncLiteralDeclaration
. That’s not much leeway. And using a DeclarationExp
does not work either, also using a CommaExp
where I declare the thing and reference it doesn’t work. Maybe someone more experienced with the compiler has an idea…