|
|
|
|
|
by amasad
3114 days ago
|
|
First of all big fan of Pyret. And I (the author) did something similar in the past and I totally agree it's the way to go. What I did is exploded every JavaScript program on statements, wrapped function calls with thunks, and then converted the program and every function to a generator and inserted a yield statement between every other statement. See https://amasad.me/js-debugger It worked well enough and was able to build a couple of demos on top of it (last time I checked chrome broke some of my demos so try them on other browsers). However, I think it's quite a hack and that the proper solution would be to build a JS VM. There are still issues to be worked out there like the problem that you can't instrument native code (say an event handler, or built-in functions) and that there are things that are inherently synchronous in the browser that you can't make async (e.g. event bubbling). However, one of Repl.it's goal is to support every language ever existed so building and maintaining our own virtual machines would be quite an undertaking for our 3 person team. What I'm hoping for is that we sometime soon leverage WASM to compile down an existing JS VM. |
|
Early on we also implemented a similar generator approach to what you described (as well as CPS). We found that it mostly worked, but had a few drawbacks. Specifically, generators change the type of instrumented functions, which makes it difficult to implement constructors and prototype inheritance, and they also break tail calls in environments that support them. More importantly for practical concerns, we found it to be much slower (at least 2x-3x) than the solution we came up with.
Again, happy to share more information with you!