Skip to content

Instantly share code, notes, and snippets.

@Sunjammer
Created December 10, 2016 03:42
Show Gist options
  • Save Sunjammer/3cc26143f212c43c6acc5a7899180a75 to your computer and use it in GitHub Desktop.
Save Sunjammer/3cc26143f212c43c6acc5a7899180a75 to your computer and use it in GitHub Desktop.
JS code generation bug?
//stack is an inline property performing array access
function popStack():Int
{
var v = memory[STACK_OFFSET + stack - 1];
stack--;
return v;
}
//The produced code moves the decrement of stack in a way that makes the return value invalid
popStack: function() {
this.memory[4] -= 1;
return this.memory[384 + this.memory[4] - 1];
}
//Introducing a trace statement to force order fixes this
function popStack():Int
{
var v = memory[STACK_OFFSET + stack - 1];
trace("Popping");
stack--;
return v;
}
popStack: function() {
var v = this.memory[384 + this.memory[4] - 1];
console.log("Popping");
this.memory[4] -= 1;
return v;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment