Mixins and compile-time coding

janderson askme at me.com
Tue Feb 6 09:32:26 PST 2007


Here's a suggestion that I actually sent a couple of of years ago that 
actually make sense now with the new mixin stuff.  What if you could 
plugin dlls into DMD that would be run at compile time.  The requirement 
of use would be that the input parameters would be constant.


ie

importplugin("perl");

mixin(Perl("perl code"));

//In the Perl dll
char[] Perl(char[] source)
{
  ...
}

Of course the other option would be to compile the Perl code on the fly. 
    Parhaps you could have "char[] str = static func()" or something (ie 
prefix calls to these functions with static).

of course templates could be used to represent almost anything but I 
find them hard to read when they start to try to do something weird.

The only downside I see is that people could write really slow dlls 
which would slow down compile time.  It probably would be a good idea 
for DMD to actually printout how much time is spent in each on of these 
processes (ie point its finger).

If this technique where to be enabled, we would be able to take all the 
string handling routines in the standard lib and use them now.

-Joel



More information about the Digitalmars-d mailing list