Closed LeifAndersen closed 3 years ago
I should mention that the program does run properly on the stopify home page. So it might be that I'm running it incorrectly?
It is definitely a Stopify bug, which should behave correctly regardless of runtime/compiler options.
An equivalent program works correctly on Ocelot:
https://code.ocelot-ide.org/?gist=arjunguha/aefe0f874a10db181eaa610a7c740fad
However, Ocelot does a bunch of other transformations that may be masking the problem.
Looks like the default estimator in Stopify is "velocity", and that the version that you're using is the same version that ElementaryJS uses:
Here is a variation of an example that Leif sent over email, which shows the same problem:
<script src="https://github.com/ocelot-ide/Stopify/releases/download/0.7.3/stopify-full.bundle.js"></script>
<script>
const prog = `
var i = 0;
debugger;
while(i < 10) {
console.log(i);
var G = i + 1;
i = G;
};`;
let runner = stopify.stopifyLocally(prog);
runner.g = {console};
runner.run(() => {
console.log(runner.g.G, runner.g.i);
console.log("DONE!");
});
</script>
If you pretty-print the code around the debugger, you see that the loop body translates to:
if ($__R.mode) {
G = $S.g.i + 1; // BUG HERE: the l-value should be $S.g.G, I believe
$S.g.i = $S.g.G
}
The bug is almost certainly in this file, which introduces the global object:
https://github.com/ocelot-ide/Stopify/blob/master/hygiene/ts/useGlobalObject.ts
I believe the problem is masked in Ocelot, because it wraps the entire program in a thunk (IIRC, though I forget why).
My guess is that loop bodies are considered "scopes" in Babel (which they are for let- and const- bound variables). So, the condition here is probably wrong:
https://github.com/ocelot-ide/Stopify/blob/master/hygiene/ts/useGlobalObject.ts#L91
The following program runs incorrectly in stopify:
It prints out
0
, and terminates.Oddly enough, this program works as expected:
Which prints out 0 through 9 and then terminates.
This is how I am running stopify:
I'm using the latest version of stopify in npm: (@stopify/stopify v0.7.3).
Finally, I'm pretty sure stopify thinks the program is actually terminating, and not just timing out because DONE also gets printed to the console.