Feature request: one-statement functions without brackets

Dan murpsoft at hotmail.com
Tue Apr 3 11:48:37 PDT 2007


I most definitely am not *for* semicolon removal/insertion.  I've been working on the JavaScript Engine, and I've used JavaScript for a long time.  I can tell you that *sometimes* implementing it is worse than always doing so.  You become aware of semicolons moreso than with C/C++/C#/D languages where you can ignore them if you automatically type them in all the time like I do.

I *am* for allowing the removal of {} for for/function when there's only one statement.

I *am* for expression jacking some things.  Yes, a switch expression is more complicated than a statement.  It has been done before though, and it's not that much worse.  Also, it gets handled by the compiler and won't affect switches that aren't expressions.

Internally, and I'm writing this terribly sub-optimally, you're saying:

// let EDX = x, AL = table offset, ECX = instruction*;

mov ECX, AL[$]; // load up the jump table
and ECX, 0x12; // sanity mask
jmp [ECX]; // jump into the jump table
mov EDX, 4; // x = switch(y){ case 3: 4; case 5: 1; case ... case ...}
jmp _out;
mov EDX, 1;
jmp _out;
...

So you're just assigning things to a variable, and passing that variable out.  Syntactic sugar for:

switch(y){
  case 3:  x = 4;
  case 5: x = 1;
 ..
}

Which can sort of be optimized to do some cool stuff later, and theoretically you could use EFLAGS in interesting ways throughout.





More information about the Digitalmars-d mailing list