Open RealyUniqueName opened 6 years ago
It would be nice to look at what this generates in the end. For example, I think current Kotlin implementation would generate something like this:
// state-machine context
var __state = 0;
var __exceptionState = 2;
var __exception = null;
do {
try {
switch (__state) {
case 0:
__exceptionState = 1;
doSomething();
return;
case 1:
__exceptionState = 2;
var e = __exception;
if ((e is String)) {
catchString();
} else if ((e is Int)) {
catchInt();
} else {
catchDynamic();
}
return;
case 2: // default one: rethrow
throw __exception;
}
} catch (e:Dynamic) {
if (__exceptionState == 2)
throw e; // rethrow
__state = __exceptionState;
__exception = e;
}
} while (true);
It's pretty much the same as your snippet, except try..catch
is not getenerated, but state machine is executed inside of a try...catch
instead when entering corresponding state.
Source
Short legend for next snippet:
__ctx__
is a context of state machine (holds current variable values and other data)${id}
is a unique id for current transformationPreprocessed into: