Move stepping logic for reporters to sequencer

This commit is contained in:
Tim Mickel 2016-06-20 15:04:28 -04:00
parent f802faa461
commit c63747e61b
2 changed files with 33 additions and 17 deletions
src/engine

View file

@ -48,24 +48,13 @@ var execute = function (sequencer, thread) {
// Is there no value for this input waiting in the stack frame?
if (typeof currentStackFrame.reported[inputName] === 'undefined') {
// If there's not, we need to evaluate the block.
// Push to the stack to evaluate this input.
thread.pushStack(inputBlockId);
if (DEBUG_BLOCK_CALLS) {
console.time('Reporter evaluation');
}
runtime.glowBlock(inputBlockId, true);
// Save name of input for `Thread.pushReportedValue`.
currentStackFrame.waitingReporter = inputName;
execute(sequencer, thread);
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.
var reporterYielded = (
sequencer.stepToReporter(thread, inputBlockId, inputName)
);
// If the reporter yielded, return immediately;
// it needs time to finish and report its value.
if (reporterYielded) {
return;
} else {
// Reporter finished right away; pop the stack.
runtime.glowBlock(inputBlockId, false);
thread.popStack();
}
}
argValues[inputName] = currentStackFrame.reported[inputName];