Simplifications of execute ordering

and always cache returned reporter values in currentStackFrame.reported.
This commit is contained in:
Tim Mickel 2016-06-17 17:18:44 -04:00
parent d15c93af05
commit bed3e28c02

View file

@ -21,6 +21,17 @@ var execute = function (sequencer, thread) {
var opcode = runtime.blocks.getOpcode(currentBlockId);
if (!opcode) {
console.warn('Could not get opcode for block: ' + currentBlockId);
return;
}
var blockFunction = runtime.getOpcodeFunction(opcode);
if (!blockFunction) {
console.warn('Could not get implementation for opcode: ' + opcode);
return;
}
// Generate values for arguments (inputs).
var argValues = {};
@ -36,11 +47,7 @@ var execute = function (sequencer, thread) {
var input = inputs[inputName];
var inputBlockId = input.block;
// Is there a value for this input waiting in the stack frame?
if (currentStackFrame.reported &&
currentStackFrame.reported[inputName]) {
// Use that value.
argValues[inputName] = currentStackFrame.reported[inputName];
} else {
if (!currentStackFrame.reported[inputName]) {
// Otherwise, we need to evaluate the block.
// Push to the stack to evaluate this input.
thread.pushStack(inputBlockId);
@ -50,29 +57,20 @@ var execute = function (sequencer, thread) {
runtime.glowBlock(inputBlockId, true);
var result = execute(sequencer, thread);
// Did the reporter yield?
currentStackFrame.waitingReporter = inputName;
if (thread.status === Thread.STATUS_YIELD) {
// Reporter yielded; don't pop stack and wait for it to unyield.
// The value will be populated once the reporter unyields,
// and passed up to the currentStackFrame on next execution.
// Save name of this input to be filled by child `util.report`.
currentStackFrame.waitingReporter = inputName;
return;
}
runtime.glowBlock(inputBlockId, false);
thread.popStack();
thread.pushReportedValue(result);
argValues[inputName] = result;
thread.popStack();
}
}
if (!opcode) {
console.warn('Could not get opcode for block: ' + currentBlockId);
return;
}
var blockFunction = runtime.getOpcodeFunction(opcode);
if (!blockFunction) {
console.warn('Could not get implementation for opcode: ' + opcode);
return;
argValues[inputName] = currentStackFrame.reported[inputName];
}
if (DEBUG_BLOCK_CALLS) {