Update nextBlock to be set before primitive call

This commit is contained in:
Tim Mickel 2016-05-02 15:35:29 -04:00
parent 7eef10ef8c
commit 3eeccf1970

View file

@ -58,10 +58,16 @@ Sequencer.prototype.stepThreads = function (threads) {
* @param {!Thread} thread Thread object to step * @param {!Thread} thread Thread object to step
*/ */
Sequencer.prototype.stepThread = function (thread) { Sequencer.prototype.stepThread = function (thread) {
var opcode = this.runtime._getOpcode(thread.nextBlock); // Save the current block and set the nextBlock.
// If the primitive would like to do control flow,
// it can overwrite nextBlock.
var currentBlock = thread.nextBlock;
thread.nextBlock = this.runtime._getNextBlock(thread.nextBlock);
var opcode = this.runtime._getOpcode(currentBlock);
if (!opcode) { if (!opcode) {
console.warn('Could not get opcode for block: ' + thread.nextBlock); console.warn('Could not get opcode for block: ' + currentBlock);
} }
else { else {
var blockFunction = this.runtime.getOpcodeFunction(opcode); var blockFunction = this.runtime.getOpcodeFunction(opcode);
@ -79,7 +85,6 @@ Sequencer.prototype.stepThread = function (thread) {
} }
} }
thread.nextBlock = this.runtime._getNextBlock(thread.nextBlock);
}; };
module.exports = Sequencer; module.exports = Sequencer;