Executing pure D at compile-time - Someone needs to write a D interpreter using templates!

Chad J gamerChad at _spamIsBad_gmail.com
Thu Feb 8 13:21:49 PST 2007


Tom S wrote:
> Chad J wrote:
> 
>> Hmmm, why doesn't someone write a D interpreter using templates?
> 
> 
> 
> I'd say it's impractical with the current implementation of templates. 
> Each template instantiation is remembered. You can't just run stuff and 
> forget about it. Think, hundreds of megs of ram to 'interpret' a simple 
> program. That's one of the reasons why ctrace runs so bloody slow :P
> 
> 
> -- 
> Tomasz Stachowiak

Yeah.  This seems to be a big problem with D templates though - they are 
getting pushed far enough nowadays that their unoptimized implementation 
is just not enough.  Perhaps we need the D compiler to be a bit more 
wise about how it instantiates templates.  It should probably consider 
discarding some templates early (particularly those that lack member 
functions/classes/structs/whatever), since some of these are unlikely to 
be instantiated again. Or maybe by default it should just not remember 
templates at all.  Then it could unroll some of the common tail 
recursion.  I also hear it generates object code while instantiating - 
baaad, it should probably do that lazily.  These improvements should 
help template metaprogramming in general, not just to create weird stuff 
like a D interpreter in metacode :)



More information about the Digitalmars-d mailing list