Executing pure D at compile-time

janderson askme at me.com
Thu Feb 8 08:50:18 PST 2007


kris wrote:
> Following on from the "Regex Redux thread, it seems to me there's an 
> easy way to execute pure D at compile-time. A few elements are needed:
> 
> 1) the ability to describe a compile-time function call
> 2) the facility to pass arguments to it, and recieve a return value
> 3) a means of identifiying the D code to execute
> 4) a manner in which the pure D is executed
> 5) a mechanism for ensuring the executed code is docile
>  
> Thoughts?
> 
> - Kris
> 

I like this approach (essentially its what I was suggesting in a 
previous thread).  This would be an very powerful addition to D.  How 
would it determine 5 when you can create objects.  I'm guessing each 
method in the class would need to be labeled extension. All the compiler 
would do is validate that "extension" is true (like a constant), 
otherwise not compile.

As for naming I prefer the term "compiletime".


My last thought on the matter which I haven't posted was a slightly 
different one (take it or leave it).   Why not extend the template 
syntax so that it looks like every day D code.

First I would get rid of the static if, its inside a template, that 
should be able to be figured out.  Next I would add case statements and 
for loops.  Also compile time variables (int float, arrays, associative 
arrays).  Because these are in a template they would be detected as 
compile time.  However that wouldn't be nearly as powerful because you 
have no way to reuse code and you can't create new objects.



More information about the Digitalmars-d mailing list