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