Re: Get address of label?

2010-12-26 Thread Heywood Floyd
Thank you bearophile and Simen for your replies! Very helpful! I'll keep looking into it... BR /HF bearophile Wrote: Simen kjaeraas: Essentially, mark the switch as final, and cover every option. Likely, the optimizer does that for you if you cover every option but don't mark the

Get address of label?

2010-12-25 Thread Heywood Floyd
Is this possible somehow: int op(int r, int i) { static auto tbl = [add, sub, mul]; goto tbl[i % 3]; add: r++; goto end; sub: r--;

Re: Get address of label?

2010-12-25 Thread Simen kjaeraas
Heywood Floyd soul...@gmail.com wrote: Is this possible somehow: int op(int r, int i) { static auto tbl = [add, sub, mul]; goto tbl[i % 3]; add: r++; goto end; sub: r--; goto end; mul:

Re: Get address of label?

2010-12-25 Thread bearophile
Heywood Floyd: Is this possible somehow: In this simple case Simen kjaeraas has shown you a solution. But in general D-DMD doesn't support computed gotos yet. I have asked for them some times, in some different ways. I guess they will added as a non-standard D exception, hopefully with the

Re: Get address of label?

2010-12-25 Thread Heywood Floyd
Thanks for the answer! Ok, hm, how about this then: auto opTable = [op_add, op_cmp, op_end]; //etc. ubyte[] eval(ubyte[] prog) { int ip = 0, sp = 0; ubyte[4096] stack; next: goto opTable[prog[ip++]

Re: Get address of label?

2010-12-25 Thread Simen kjaeraas
Heywood Floyd soul...@gmail.com wrote: Thanks for the answer! Ok, hm, how about this then: auto opTable = [op_add, op_cmp, op_end]; //etc. ubyte[] eval(ubyte[] prog) { int ip = 0, sp = 0; ubyte[4096] stack; next: