mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-22 22:12:28 -05:00
Simplifications of execute
ordering
and always cache returned reporter values in currentStackFrame.reported.
This commit is contained in:
parent
d15c93af05
commit
bed3e28c02
1 changed files with 16 additions and 18 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue