Compiling to Heap for CTFE

Chad J gamerChad at _spamIsBad_gmail.com
Tue Dec 18 07:53:27 PST 2007


Craig Black wrote:
> Currently, CTFE only supports a subset of the language, and it relies on 
> the compiler acting as an interpreter, which is slow.  It just occured 
> to me that if we could compile code to the heap, there would be no need 
> for a CTFE interpreter.  CTFE code could be compiled to the heap and 
> executed at full speed.  Further, all the features of D would be 
> available at compile time.
> 
> Thoughts?
> 
> -Craig

In response to concerns about cross-compilation and security concerns:

Perhaps if D had a VM then we could do it?  At compile time, compile all 
of the CTFE code to bytecode, and interpret it.  The intrepreter would 
be compiled by whatever is compiling the compiler, so it should make 
cross-compiling easier.  Also, the VM and compiler can sandbox the CTFE 
code.  Bytecode interpretation is not native speed execution, but 
probably close enough, and this approach allows use of D's high level 
features.

Only problem is, that would be a lot of work.  It involves writing a D 
backend for the bytecode, implementing security restrictions, and maybe 
even implementing the VM itself (if we can't find a ready-made one).



More information about the Digitalmars-d mailing list