On 05/29/2014 06:53 PM, Dylan Knutson wrote:
...
Is there anything so radically different in D than these other
languages, that prevents the implementation of a run-of-the-mill VM to
eval D code?
No. (In fact, I've written a naive but mostly complete byte code
interpreter in half a week or so last year, as part of an ongoing
recreational D front end implementation effort.)
It just seems strange to me that it's such a problem when
this is basically solved by all scripting languages. And I'm really not
trying to downplay the difficulty in implementing CTFE in D, but rather
just figure out why it's so hard to implement in comparison.
CTFE is somewhat intertwined with semantic analysis, which makes it a
little harder to specify/implement than usual interpreters. However, the
performance problem is mostly a structural issue of the current
implementation: DMDs CTFE interpreter gradually grew out of its constant
folder in some kind of best effort fashion as far as I understand.
It is feasible to do everything in the usual fashion and occasionally
just pause or restart interpretation at well-defined points where it
needs to interface with semantic analysis.