Skip to content

Instantly share code, notes, and snippets.

@jlongster
Created May 26, 2016 05:00
Show Gist options
  • Save jlongster/67ba9177be2f4fb2971dfcf2d32db2ec to your computer and use it in GitHub Desktop.
Save jlongster/67ba9177be2f4fb2971dfcf2d32db2ec to your computer and use it in GitHub Desktop.
// This function:
function foo() {
var x = 5;
var y = 6;
debugger;
return x + y;
}
// Would be compiled to this function. Yes, it's a large transform,
// but it works surprisingly well even if the output JS is very large.
// Also, I hand-wrote the following code (to simplify it) so there
// might be minor errors. Take it as specific pseudo-code.
function foo() {
var $__next = 0, x, y;
try {
if(VM.doRestore) {
var $__frame = VM.popFrame();
$__next = $__frame.next;
var $__child = $__frame.child;
if($__child) {
$__frame.state.$__t1 = $__child.fn.call($__child.thisPtr);
}
x = $__frame.state.x;
y = $__frame.state.y;
}
while(1) {
if (VM.breakpoints[1][$__next] !== undefined)
throw new $ContinuationExc();
switch($__next) {
case 0:
x = 5;
$__next = 1;
break;
case 1:
y = 6;
$__next = 2;
break;
case 2:
$__next = 3;
throw new $ContinuationExc();
case 3:
return x + y;
}
}
}
catch(e) {
if(!(e instanceof $ContinuationExc))
e = new $ContinuationExc({ error: e })
e.pushFrame(new $Frame($__next, { x: x, y: y }));
throw e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment