Hi people.<div><br></div><div>I'd like to propose support for taking the address of code labels, and supporting variable goto statements.</div><div>This is a feature I have found extremely useful, implemented as a GCC specific extension.</div>
<div><br></div><div>I've used this to get great speedups and simplify code while writing emulators/vm's. Perhaps also useful in efficient state machine type code too...</div><div><br></div><div><br></div><div>Simple example:</div>
<div><br></div><div>void *opcodes[] = { &OP_ADDA, &OP_SUBA, &OP_MOVA, &OP_JMPA, &OP_etc... };</div><div><br></div><div>void exec()</div><div>{</div><div>  // begin execution</div><div>  goto opcodes[ pProgram[regs.PC++] ];</div>
<div><br></div><div>OP_ADDA:</div><div><div>  regs.A += pProgram[regs.PC++];</div><div>  goto opcodes[ pProgram[regs.PC++] ];</div></div><div><br></div><div>OP_SUBA:</div><div><div>  regs.A -= pProgram[regs.PC++];</div></div>
<div>  goto opcodes[ pProgram[regs.PC++] ];</div><div><div><br></div><div>OP_MOVA:</div></div><div>  regs.A = pProgram[regs.PC++];</div><div>  goto opcodes[ pProgram[regs.PC++] ];</div><div><div><br></div><div>OP_JMPA:</div>
</div><div>  regs.PC = regs.A;</div><div><div>  goto opcodes[ pProgram[regs.PC++] ];</div><div></div><div><br></div></div><div><div>OP_etc:</div></div><div>  ...</div><div><div>  goto opcodes[ pProgram[PC++] ];</div></div>
<div>}</div><div><br></div><div>Notice how this structure completely eliminates branch logic, control statements, etc.</div><div><br></div><div>Note, GCC code labels are void*, but in D, perhaps some special code label pointer type should be invented for type safety...</div>
<div>One may also expect that function pointers may also be implicitly cast to this generalised code pointer type, which might be useful in some code where a naked function pointer is used to implement some custom calling convention.</div>