mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-09 14:32:07 -05:00
Keep "waiting reporter name" on the stack frame.
Also add highlighting for inputs.
This commit is contained in:
parent
7ef3807b18
commit
d15c93af05
2 changed files with 13 additions and 9 deletions
|
@ -10,10 +10,9 @@ var DEBUG_BLOCK_CALLS = true;
|
||||||
* Execute a block.
|
* Execute a block.
|
||||||
* @param {!Sequencer} sequencer Which sequencer is executing.
|
* @param {!Sequencer} sequencer Which sequencer is executing.
|
||||||
* @param {!Thread} thread Thread which to read and execute.
|
* @param {!Thread} thread Thread which to read and execute.
|
||||||
* @param {string=} opt_waitingInputName If evaluating an input, its name.
|
|
||||||
* @return {?Any} Reported value, if available immediately.
|
* @return {?Any} Reported value, if available immediately.
|
||||||
*/
|
*/
|
||||||
var execute = function (sequencer, thread, opt_waitingInputName) {
|
var execute = function (sequencer, thread) {
|
||||||
var runtime = sequencer.runtime;
|
var runtime = sequencer.runtime;
|
||||||
|
|
||||||
// Current block to execute is the one on the top of the stack.
|
// Current block to execute is the one on the top of the stack.
|
||||||
|
@ -48,14 +47,18 @@ var execute = function (sequencer, thread, opt_waitingInputName) {
|
||||||
if (DEBUG_BLOCK_CALLS) {
|
if (DEBUG_BLOCK_CALLS) {
|
||||||
console.time('Yielding reporter evaluation');
|
console.time('Yielding reporter evaluation');
|
||||||
}
|
}
|
||||||
var result = execute(sequencer, thread, inputName);
|
runtime.glowBlock(inputBlockId, true);
|
||||||
|
var result = execute(sequencer, thread);
|
||||||
// Did the reporter yield?
|
// Did the reporter yield?
|
||||||
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`.
|
||||||
|
currentStackFrame.waitingReporter = inputName;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
runtime.glowBlock(inputBlockId, false);
|
||||||
thread.popStack();
|
thread.popStack();
|
||||||
argValues[inputName] = result;
|
argValues[inputName] = result;
|
||||||
}
|
}
|
||||||
|
@ -84,12 +87,11 @@ var execute = function (sequencer, thread, opt_waitingInputName) {
|
||||||
sequencer.proceedThread(thread);
|
sequencer.proceedThread(thread);
|
||||||
},
|
},
|
||||||
report: function(reportedValue) {
|
report: function(reportedValue) {
|
||||||
thread.pushReportedValue(opt_waitingInputName, reportedValue);
|
|
||||||
if (DEBUG_BLOCK_CALLS) {
|
if (DEBUG_BLOCK_CALLS) {
|
||||||
console.log('Reported: ', reportedValue,
|
console.log('Reported: ', reportedValue);
|
||||||
' for ', opt_waitingInputName);
|
|
||||||
console.timeEnd('Yielding reporter evaluation');
|
console.timeEnd('Yielding reporter evaluation');
|
||||||
}
|
}
|
||||||
|
thread.pushReportedValue(reportedValue);
|
||||||
sequencer.proceedThread(thread);
|
sequencer.proceedThread(thread);
|
||||||
},
|
},
|
||||||
timeout: thread.addTimeout.bind(thread),
|
timeout: thread.addTimeout.bind(thread),
|
||||||
|
|
|
@ -71,6 +71,7 @@ Thread.prototype.pushStack = function (blockId) {
|
||||||
if (this.stack.length > this.stackFrames.length) {
|
if (this.stack.length > this.stackFrames.length) {
|
||||||
this.stackFrames.push({
|
this.stackFrames.push({
|
||||||
reported: {}, // Collects reported input values.
|
reported: {}, // Collects reported input values.
|
||||||
|
waitingReporter: null, // Name of waiting reporter.
|
||||||
executionContext: {} // A context passed to block implementations.
|
executionContext: {} // A context passed to block implementations.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -104,13 +105,14 @@ Thread.prototype.peekStackFrame = function () {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push a reported value to the parent of the current stack frame.
|
* Push a reported value to the parent of the current stack frame.
|
||||||
* @param {!string} inputName Name of input reported.
|
|
||||||
* @param {!Any} value Reported value to push.
|
* @param {!Any} value Reported value to push.
|
||||||
*/
|
*/
|
||||||
Thread.prototype.pushReportedValue = function (inputName, value) {
|
Thread.prototype.pushReportedValue = function (value) {
|
||||||
var parentStackFrame = this.stackFrames[this.stackFrames.length - 2];
|
var parentStackFrame = this.stackFrames[this.stackFrames.length - 2];
|
||||||
if (parentStackFrame) {
|
if (parentStackFrame) {
|
||||||
parentStackFrame.reported[inputName] = value;
|
var waitingReporter = parentStackFrame.waitingReporter;
|
||||||
|
parentStackFrame.reported[waitingReporter] = value;
|
||||||
|
parentStackFrame.waitingReporter = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue