google/traceur-compiler — pull request #699 by arv (2014-01-24 05:20:23+00:00)
Title: Generator use try stack runtime

By using a stack to keep track of try/catch/finally we can move a lot of logic from the generated code to a runtime function. This allows the codegen to become significantly smaller.

```js
function* f() {
try {
yield 1;
} catch (ex) {
yield ex;
}
}
```

Before:
```js
function f() {
var ex;
var $that = this,
$arguments = arguments,
innerFunction = function($ctx) {
while (true) switch ($ctx.state) {
case 0:
$ctx.state = 2;
return 1;
case 2:
if ($ctx.action == 1) {
$ctx.action = 0;
throw $ctx.sent;
}
$ctx.state = 4;
break;
case 9:
ex = $ctx.storedException;
$ctx.state = 5;
break;
case 5:
$ctx.state = 6;
return ex;
case 6:
if ($ctx.action == 1) {
$ctx.action = 0;
throw $ctx.sent;
}
$ctx.state = 4;
break;
case 4:
$ctx.state = -2;
case -2:
return $ctx;
case -3:
throw $ctx.storedException;
default:
throw "traceur compiler bug: invalid state in state machine: " + $ctx.state;
}
},
moveNext = function($ctx) {
while (true) {
try {
return innerFunction($ctx);
} catch (ex) {
$ctx.storedException = ex;
switch ($ctx.state) {
case 2:
$ctx.state = 9;
break;
default:
$ctx.GState = 3;
$ctx.state = -2;
throw $ctx.storedException;
}
}
}
};
return $traceurRuntime.generatorWrap(moveNext);
}
```

After:
```js
function f() {
var ex;
var $that = this,
$arguments = arguments;
return $traceurRuntime.generatorWrap(function($ctx) {
while (true) switch ($ctx.state) {
case 0:
$ctx.pushTry(9, null);
$ctx.state = 12;
break;
case 12:
$ctx.state = 2;
return 1;
case 2:
if ($ctx.action == 1) {
$ctx.action = 0;
throw $ctx.sent;
}
$ctx.state = 4;
break;
case 4:
$ctx.popTry();
$ctx.state = 14;
break;
case 9:
$ctx.popTry();
ex = $ctx.storedException;
$ctx.state = 5;
break;
case 5:
$ctx.state = 6;
return ex;
case 6:
if ($ctx.action == 1) {
$ctx.action = 0;
throw $ctx.sent;
}
$ctx.state = 14;
break;
case 14:
$ctx.state = -2;
case -2:
return $ctx;
case -3:
throw $ctx.storedException;
default:
throw "traceur compiler bug: invalid state in state machine: " + $ctx.state;
}
});
}
```