mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Simplify logic for Thread status
This commit is contained in:
parent
ab6e0d3839
commit
ec4567aa8a
2 changed files with 15 additions and 16 deletions
|
@ -134,17 +134,10 @@ Sequencer.prototype.stepToReporter = function (thread, blockId, inputName) {
|
||||||
currentStackFrame.waitingReporter = inputName;
|
currentStackFrame.waitingReporter = inputName;
|
||||||
// Actually execute the block.
|
// Actually execute the block.
|
||||||
this.startThread(thread);
|
this.startThread(thread);
|
||||||
if (thread.status === Thread.STATUS_YIELD ||
|
// If a reporter yielded, caller must wait for it to unyield.
|
||||||
thread.status === Thread.STATUS_YIELD_BLOCK) {
|
// The value will be populated once the reporter unyields,
|
||||||
// Reporter yielded; caller must wait for it to unyield.
|
// and passed up to the currentStackFrame on next execution.
|
||||||
// The value will be populated once the reporter unyields,
|
return thread.status === Thread.STATUS_YIELD;
|
||||||
// and passed up to the currentStackFrame on next execution.
|
|
||||||
return true;
|
|
||||||
} else if (thread.status === Thread.STATUS_DONE) {
|
|
||||||
// Reporter finished, mark the thread as running.
|
|
||||||
thread.status = Thread.STATUS_RUNNING;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,7 +148,8 @@ Sequencer.prototype.proceedThread = function (thread) {
|
||||||
var currentBlockId = thread.peekStack();
|
var currentBlockId = thread.peekStack();
|
||||||
// Mark the status as done and proceed to the next block.
|
// Mark the status as done and proceed to the next block.
|
||||||
this.runtime.glowBlock(currentBlockId, false);
|
this.runtime.glowBlock(currentBlockId, false);
|
||||||
thread.status = Thread.STATUS_DONE;
|
// If the block was yielding, move back to running state.
|
||||||
|
thread.status = Thread.STATUS_RUNNING;
|
||||||
// Pop from the stack - finished this level of execution.
|
// Pop from the stack - finished this level of execution.
|
||||||
thread.popStack();
|
thread.popStack();
|
||||||
// Push next connected block, if there is one.
|
// Push next connected block, if there is one.
|
||||||
|
@ -167,6 +161,10 @@ Sequencer.prototype.proceedThread = function (thread) {
|
||||||
while (thread.peekStack() === null && thread.stack.length > 0) {
|
while (thread.peekStack() === null && thread.stack.length > 0) {
|
||||||
thread.popStack();
|
thread.popStack();
|
||||||
}
|
}
|
||||||
|
// If we still can't find a next block to run, mark the thread as done.
|
||||||
|
if (thread.peekStack() === null) {
|
||||||
|
thread.status = Thread.STATUS_DONE;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Sequencer;
|
module.exports = Sequencer;
|
||||||
|
|
|
@ -32,22 +32,23 @@ function Thread (firstBlock) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread status for initialized or running thread.
|
* Thread status for initialized or running thread.
|
||||||
* Threads are in this state when the primitive is called for the first time.
|
* This is the default state for a thread - execution should run normally,
|
||||||
|
* stepping from block to block.
|
||||||
* @const
|
* @const
|
||||||
*/
|
*/
|
||||||
Thread.STATUS_RUNNING = 0;
|
Thread.STATUS_RUNNING = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread status for a yielded thread.
|
* Thread status for a yielded thread.
|
||||||
* Threads are in this state when a primitive has yielded.
|
* Threads are in this state when a primitive has yielded; execution is paused
|
||||||
|
* until the relevant primitive unyields.
|
||||||
* @const
|
* @const
|
||||||
*/
|
*/
|
||||||
Thread.STATUS_YIELD = 1;
|
Thread.STATUS_YIELD = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread status for a finished/done thread.
|
* Thread status for a finished/done thread.
|
||||||
* Thread is moved to this state when the interpreter
|
* Thread is in this state when there are no more blocks to execute.
|
||||||
* can proceed with execution.
|
|
||||||
* @const
|
* @const
|
||||||
*/
|
*/
|
||||||
Thread.STATUS_DONE = 2;
|
Thread.STATUS_DONE = 2;
|
||||||
|
|
Loading…
Reference in a new issue