digitalmars.D - Feature Request: Label assignment / type
- Joe Pusdesris (17/17) Nov 16 2007 I think it would be very useful to have a label type. This way labels c...
- Janice Caron (3/5) Nov 16 2007 You mean we haven't got rid of goto yet?
- Janice Caron (4/6) Nov 16 2007 What's faster than what is for the compiler to figure out, not the
- Leandro Lucarella (15/22) Nov 17 2007 Yeah! That's the kind of thoughts (this and the "goto is evil") that wil...
- TomD (6/27) Nov 17 2007 Wow, assigned goto, alive in FORTRAN IV, buried in FORTRAN 77,
- Joe Pusdesris (4/6) Nov 17 2007 I just find it easier for things like jump tables and to specify a point...
- Janice Caron (20/23) Nov 17 2007 switch statement often compile to jump tables. Or at least, they did
- Bill Baxter (16/47) Nov 17 2007 Perfect hashes can/are also be used for that, no?
- Jarrett Billingsley (4/18) Nov 17 2007 You can see the code for it in dmd/src/phobos/internal/switch.d. It jus...
- Bill Baxter (4/25) Nov 17 2007 Cool. Thanks for the info. Good to know it's at least smarter than a
- Joe Pusdesris (5/37) Nov 17 2007 Oh, wow, sticking a switch of a string in a while loop then changing th...
- Paul Findlay (3/7) Nov 18 2007 So many cache misses... hope it won't run on a Pentium 4
- BCS (3/31) Nov 17 2007 in this case much of the benefit of the Label variable goto can be had i...
I think it would be very useful to have a label type. This way labels could be assigned and passed around, opening up some flexability. An example of it's usefulness would be in constructing and manipulating a jump table or navigating subroutines without calling a function. A goto is a lot faster than a function call. Possible syntax: someLabel: ... Label l = someLabel; ... goto l; Possible problems: Difficulties would arise with limiting the variable to contain it within the current scope. I suppose some aspects of this are possible with -inline, but I think this feature would be useful nonetheless. Some feedback would be appreciated.
Nov 16 2007
On 11/17/07, Joe Pusdesris <deformative0 gmail.com> wrote:A goto is a lot faster than a function call.You mean we haven't got rid of goto yet? Please let's not do anything which encourages it!
Nov 16 2007
On 11/17/07, Joe Pusdesris <deformative0 gmail.com> wrote:A goto is a lot faster than a function call.What's faster than what is for the compiler to figure out, not the programmer. The programmer should state intent. The compiler should figure out the fastest way to make it run.
Nov 16 2007
Janice Caron, el 17 de noviembre a las 07:56 me escribiste:On 11/17/07, Joe Pusdesris <deformative0 gmail.com> wrote:Yeah! That's the kind of thoughts (this and the "goto is evil") that will lead D to be a real system-programming language =) D is beautiful because both Java and C programmers can be happy (the former using it allmost without knowing anything about pointer or low-level stuff and the latter because all kind of low level tricks can be done easily and elegantly). I think label type is a good idea, after all labels are just pointers. -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ .------------------------------------------------------------------------, \ GPG: 5F5A8D05 // F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05 / '--------------------------------------------------------------------' DETIENEN A PADRE, MADRE, TIOS Y ABUELOS: TODOS DEPRAVADOS -- Crónica TVA goto is a lot faster than a function call.What's faster than what is for the compiler to figure out, not the programmer. The programmer should state intent. The compiler should figure out the fastest way to make it run.
Nov 17 2007
Joe Pusdesris Wrote:I think it would be very useful to have a label type. This way labels could be assigned and passed around, opening up some flexability. An example of it's usefulness would be in constructing and manipulating a jump table or navigating subroutines without calling a function. A goto is a lot faster than a function call. Possible syntax: someLabel: ... Label l = someLabel; ... goto l; Possible problems: Difficulties would arise with limiting the variable to contain it within the current scope. I suppose some aspects of this are possible with -inline, but I think this feature would be useful nonetheless. Some feedback would be appreciated.Wow, assigned goto, alive in FORTRAN IV, buried in FORTRAN 77, coming back a zombie. Obfuscation is, as far as I can tell, not too high on Walter's list. Ciao Tom
Nov 17 2007
Joe Pusdesris wrote:I suppose some aspects of this are possible with -inline, but I think this feature would be useful nonetheless.I just find it easier for things like jump tables and to specify a point to return to after finishing a block, but if no one else likes it that's cool too.
Nov 17 2007
On 11/17/07, Joe Pusdesris <deformative0 gmail.com> wrote:I just find it easier for things like jump tables and to specify a point to return to after finishing a block, but if no one else likes it that's cool too.switch statement often compile to jump tables. Or at least, they did in C - I've no idea what the D compiler does. So instead of Label a = label2; goto a; label1: /* stuff */ label2: /* stuff */ you do enum Label { label1, label2 }; Label a = label2; switch (a) { case label1: /* stuff */ case label2: /* stuff */ } It all boils down to the same thing.
Nov 17 2007
Janice Caron wrote:On 11/17/07, Joe Pusdesris <deformative0 gmail.com> wrote:Perfect hashes can/are also be used for that, no? I'm curious how DMD handles string switches. switch(name) { case "bob": break; case "betty": break; case "barney": break; ... } I imagine something clever is possible to make that really efficient. But I wouldn't be surprised if it generated code similar to a regular if-then-else. --bbI just find it easier for things like jump tables and to specify a point to return to after finishing a block, but if no one else likes it that's cool too.switch statement often compile to jump tables. Or at least, they did in C - I've no idea what the D compiler does. So instead of Label a = label2; goto a; label1: /* stuff */ label2: /* stuff */ you do enum Label { label1, label2 }; Label a = label2; switch (a) { case label1: /* stuff */ case label2: /* stuff */ } It all boils down to the same thing.
Nov 17 2007
"Bill Baxter" <dnewsgroup billbaxter.com> wrote in message news:fhnd3k$s31$1 digitalmars.com...Perfect hashes can/are also be used for that, no? I'm curious how DMD handles string switches. switch(name) { case "bob": break; case "betty": break; case "barney": break; ... } I imagine something clever is possible to make that really efficient. But I wouldn't be surprised if it generated code similar to a regular if-then-else.You can see the code for it in dmd/src/phobos/internal/switch.d. It just does a binary search on a sorted array.
Nov 17 2007
Jarrett Billingsley wrote:"Bill Baxter" <dnewsgroup billbaxter.com> wrote in message news:fhnd3k$s31$1 digitalmars.com...Cool. Thanks for the info. Good to know it's at least smarter than a straight if-then-else. --bbPerfect hashes can/are also be used for that, no? I'm curious how DMD handles string switches. switch(name) { case "bob": break; case "betty": break; case "barney": break; ... } I imagine something clever is possible to make that really efficient. But I wouldn't be surprised if it generated code similar to a regular if-then-else.You can see the code for it in dmd/src/phobos/internal/switch.d. It just does a binary search on a sorted array.
Nov 17 2007
Janice Caron wrote:On 11/17/07, Joe Pusdesris <deformative0 gmail.com> wrote:Oh, wow, sticking a switch of a string in a while loop then changing the string did not even occur to me. That works great. Then to make additions to it at runtime, the default statement could lookup the string in an associative array and get a delegate to execute.I just find it easier for things like jump tables and to specify a point to return to after finishing a block, but if no one else likes it that's cool too.switch statement often compile to jump tables. Or at least, they did in C - I've no idea what the D compiler does. So instead of Label a = label2; goto a; label1: /* stuff */ label2: /* stuff */ you do enum Label { label1, label2 }; Label a = label2; switch (a) { case label1: /* stuff */ case label2: /* stuff */ } It all boils down to the same thing.
Nov 17 2007
Joe Pusdesris wrote:Oh, wow, sticking a switch of a string in a while loop then changing the string did not even occur to me. That works great. Then to make additions to it at runtime, the default statement could lookup the string in an associative array and get a delegate to execute.So many cache misses... hope it won't run on a Pentium 4 - Paul
Nov 18 2007
Reply to Janice,On 11/17/07, Joe Pusdesris <deformative0 gmail.com> wrote:in this case much of the benefit of the Label variable goto can be had if "goto case NonConst;" was allowed. The const version is.I just find it easier for things like jump tables and to specify a point to return to after finishing a block, but if no one else likes it that's cool too.switch statement often compile to jump tables. Or at least, they did in C - I've no idea what the D compiler does. So instead of Label a = label2; goto a; label1: /* stuff */ label2: /* stuff */ you do enum Label { label1, label2 }; Label a = label2; switch (a) { case label1: /* stuff */ case label2: /* stuff */ } It all boils down to the same thing.
Nov 17 2007