mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Remove VM-locking yield mode per discussion
This commit is contained in:
parent
9a7ab57f6f
commit
6daee9a70e
4 changed files with 2 additions and 44 deletions
|
@ -78,11 +78,10 @@ Scratch3OperatorsBlocks.prototype.not = function (args) {
|
||||||
return Boolean(!args.OPERAND);
|
return Boolean(!args.OPERAND);
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3OperatorsBlocks.prototype.random = function (args, util) {
|
Scratch3OperatorsBlocks.prototype.random = function (args) {
|
||||||
// As a demo, this implementation of random returns after 1 second of yield.
|
// As a demo, this implementation of random returns after 1 second of yield.
|
||||||
// @todo Match Scratch 2.0 implementation with int-truncation.
|
// @todo Match Scratch 2.0 implementation with int-truncation.
|
||||||
// See: http://bit.ly/1Qc0GzC
|
// See: http://bit.ly/1Qc0GzC
|
||||||
util.yieldAndBlock();
|
|
||||||
var examplePromise = new Promise(function(resolve) {
|
var examplePromise = new Promise(function(resolve) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var res = (Math.random() * (args.TO - args.FROM)) + args.FROM;
|
var res = (Math.random() * (args.TO - args.FROM)) + args.FROM;
|
||||||
|
|
|
@ -74,7 +74,6 @@ var execute = function (sequencer, thread) {
|
||||||
var primitiveReportedValue = null;
|
var primitiveReportedValue = null;
|
||||||
primitiveReportedValue = blockFunction(argValues, {
|
primitiveReportedValue = blockFunction(argValues, {
|
||||||
yield: thread.yield.bind(thread),
|
yield: thread.yield.bind(thread),
|
||||||
yieldAndBlock: thread.yieldAndBlock.bind(thread),
|
|
||||||
done: function() {
|
done: function() {
|
||||||
sequencer.proceedThread(thread);
|
sequencer.proceedThread(thread);
|
||||||
},
|
},
|
||||||
|
|
|
@ -32,13 +32,6 @@ Sequencer.WORK_TIME = 10;
|
||||||
Sequencer.prototype.stepThreads = function (threads) {
|
Sequencer.prototype.stepThreads = function (threads) {
|
||||||
// Start counting toward WORK_TIME
|
// Start counting toward WORK_TIME
|
||||||
this.timer.start();
|
this.timer.start();
|
||||||
// Check for a blocking thread.
|
|
||||||
var blockingThread = this.getBlockingThread_(threads);
|
|
||||||
if (blockingThread) {
|
|
||||||
// Attempt to resolve any timeouts, but otherwise stop stepping.
|
|
||||||
blockingThread.resolveTimeouts();
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
// List of threads which have been killed by this step.
|
// List of threads which have been killed by this step.
|
||||||
var inactiveThreads = [];
|
var inactiveThreads = [];
|
||||||
// If all of the threads are yielding, we should yield.
|
// If all of the threads are yielding, we should yield.
|
||||||
|
@ -70,10 +63,6 @@ Sequencer.prototype.stepThreads = function (threads) {
|
||||||
activeThread.status = Thread.STATUS_RUNNING;
|
activeThread.status = Thread.STATUS_RUNNING;
|
||||||
// @todo Deal with the return value
|
// @todo Deal with the return value
|
||||||
}
|
}
|
||||||
// Has the thread gone into "blocking" mode? If so, stop stepping.
|
|
||||||
if (activeThread.status === Thread.STATUS_YIELD_BLOCK) {
|
|
||||||
return inactiveThreads;
|
|
||||||
}
|
|
||||||
if (activeThread.stack.length === 0 &&
|
if (activeThread.stack.length === 0 &&
|
||||||
activeThread.status === Thread.STATUS_DONE) {
|
activeThread.status === Thread.STATUS_DONE) {
|
||||||
// Finished with this thread - tell runtime to clean it up.
|
// Finished with this thread - tell runtime to clean it up.
|
||||||
|
@ -89,20 +78,6 @@ Sequencer.prototype.stepThreads = function (threads) {
|
||||||
return inactiveThreads;
|
return inactiveThreads;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the thread blocking all other threads, if one exists.
|
|
||||||
* @param {Array.<Thread>} threads List of which threads to check.
|
|
||||||
* @return {?Thread} The blocking thread if one exists.
|
|
||||||
*/
|
|
||||||
Sequencer.prototype.getBlockingThread_ = function (threads) {
|
|
||||||
for (var i = 0; i < threads.length; i++) {
|
|
||||||
if (threads[i].status === Thread.STATUS_YIELD_BLOCK) {
|
|
||||||
return threads[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Step the requested thread
|
* Step the requested thread
|
||||||
* @param {!Thread} thread Thread object to step
|
* @param {!Thread} thread Thread object to step
|
||||||
|
|
|
@ -52,21 +52,13 @@ Thread.STATUS_RUNNING = 0;
|
||||||
*/
|
*/
|
||||||
Thread.STATUS_YIELD = 1;
|
Thread.STATUS_YIELD = 1;
|
||||||
|
|
||||||
/**
|
|
||||||
* Thread status for a yielded thread that should block all other threads.
|
|
||||||
* This is desirable when an asynchronous capability should appear to take
|
|
||||||
* a synchronous amount of time (e.g., color touching color).
|
|
||||||
* @const
|
|
||||||
*/
|
|
||||||
Thread.STATUS_YIELD_BLOCK = 2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 moved to this state when the interpreter
|
||||||
* can proceed with execution.
|
* can proceed with execution.
|
||||||
* @const
|
* @const
|
||||||
*/
|
*/
|
||||||
Thread.STATUS_DONE = 3;
|
Thread.STATUS_DONE = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push stack and update stack frames appropriately.
|
* Push stack and update stack frames appropriately.
|
||||||
|
@ -139,13 +131,6 @@ Thread.prototype.yield = function () {
|
||||||
this.status = Thread.STATUS_YIELD;
|
this.status = Thread.STATUS_YIELD;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Yields the thread and blocks other threads until unyielded.
|
|
||||||
*/
|
|
||||||
Thread.prototype.yieldAndBlock = function () {
|
|
||||||
this.status = Thread.STATUS_YIELD_BLOCK;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an execution-synced timeouts for this thread.
|
* Add an execution-synced timeouts for this thread.
|
||||||
* See also: util/yieldtimers.js:timeout
|
* See also: util/yieldtimers.js:timeout
|
||||||
|
|
Loading…
Reference in a new issue