When I have suggested to add "computed gotos" (similar to the ones of GCC) to 
D, Walter has answered that they need some work to be implemented, and they 
have limited usefulness, almost only to optimize interpreters.

But:
- D is a system language, so writing interpreters is an important application 
of it.
- I have found GCC computed gotos useful to speed up some of my code. Recently 
even the CPython has introduced their usage in the main interpreter loop.
- The GCC implementation of computed gotos is not standard for C and other 
compilers may not understand it (to solve this trouble in GNU C code you need 
to disable pieces of code, and this is less easy to do in D).

So even if computed gotos are not going to be implemented in DMD I suggest to:
1) Invent a syntax to represent and use them (probably the GCC syntax is good, 
because it's already known in C).
2) Make DMD understand this syntax, but refuse it at compile time (because DMD 
doesn't support computer gotos).
3) Define a new standard Predefined Version, like "computed_goto" or 
"Computed_goto" or something similar, that is defined if a D compiler supports 
them (so DMD doesn't define it), that allows to disable the code that contains 
the computed goto if a compiler doesn't support them.

This:
- Allows other D implementations, based on LLVM and GCC back-ends that already 
support computed gotos, to support such gotos in D code too;
- Allows the programmer to write two versions of a performance-critical routine 
with and without computed gotos, in a clean way just like is done for 
version(D_InlineAsm_X86){...}else{...}.
- Gives a single standard common syntax that all future D compilers may use, 
avoiding troubles caused by nonstandard syntax and implementations.

(Explicitly unimplemented features have a precedent in D, the array operations. 
The difference is that D may never implement computed gotos.)
(This an additive feature, so it may be left for D3 too.)

Bye,
bearophile

Reply via email to