mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-29 23:49:21 -04:00
Simplify execution by removing nextBlock
Everything is managed by the stack, including what the execute() function does.
This commit is contained in:
parent
2cd6bf93bb
commit
526a260101
4 changed files with 70 additions and 57 deletions
src/engine
|
@ -9,11 +9,7 @@ function Thread (firstBlock) {
|
|||
* @type {!string}
|
||||
*/
|
||||
this.topBlock = firstBlock;
|
||||
/**
|
||||
* ID of next block that the thread will execute, or null if none.
|
||||
* @type {?string}
|
||||
*/
|
||||
this.nextBlock = firstBlock;
|
||||
|
||||
/**
|
||||
* Stack for the thread. When the sequencer enters a control structure,
|
||||
* the block is pushed onto the stack so we know where to exit.
|
||||
|
@ -38,12 +34,6 @@ function Thread (firstBlock) {
|
|||
* @type {number}
|
||||
*/
|
||||
this.yieldTimerId = -1;
|
||||
|
||||
/**
|
||||
* Whether the thread has switched stack in the course of execution.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.switchedStack = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +73,7 @@ Thread.prototype.pushStack = function (blockId) {
|
|||
|
||||
/**
|
||||
* Pop last block on the stack and its stack frame.
|
||||
* @returns {string} Block ID popped from the stack.
|
||||
* @return {string} Block ID popped from the stack.
|
||||
*/
|
||||
Thread.prototype.popStack = function () {
|
||||
this.stackFrames.pop();
|
||||
|
@ -91,10 +81,19 @@ Thread.prototype.popStack = function () {
|
|||
};
|
||||
|
||||
/**
|
||||
* Get last stack frame.
|
||||
* Get top stack item.
|
||||
* @return {?string} Block ID on top of stack.
|
||||
*/
|
||||
Thread.prototype.peekStack = function () {
|
||||
return this.stack[this.stack.length - 1];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get top stack frame.
|
||||
* @return {?Object} Last stack frame stored on this thread.
|
||||
*/
|
||||
Thread.prototype.getLastStackFrame = function () {
|
||||
Thread.prototype.peekStackFrame = function () {
|
||||
return this.stackFrames[this.stackFrames.length - 1];
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue