Skip to content

Commit

Permalink
Pause support :3
Browse files Browse the repository at this point in the history
  • Loading branch information
AshimeeAlt committed Nov 6, 2024
1 parent da952f8 commit 23d948d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/compiler/jsexecute.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ const executeInCompatibilityLayer = function*(inputs, blockFunction, isWarp, use
return '';
}
while (thread.status === 2 /* STATUS_YIELD */ || thread.status === 3 /* STATUS_YIELD_TICK */) {
while (
thread.status === 2 /* STATUS_YIELD */ ||
thread.status === 3 /* STATUS_YIELD_TICK */
) {
// Yielded threads will run next iteration.
if (thread.status === 2 /* STATUS_YIELD */) {
thread.status = 0; // STATUS_RUNNING
Expand Down Expand Up @@ -631,7 +634,9 @@ runtimeFunctions.yieldThenCallGenerator = `const yieldThenCallGenerator = functi
*/
const execute = thread => {
globalState.thread = thread;
thread.generator.next();
if (thread.status !== 5 /* STATUS_PAUSED */) {
thread.generator.next();
}
};

const threadStack = [];
Expand Down
4 changes: 4 additions & 0 deletions src/engine/sequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class Sequencer {
stoppedThread = true;
continue;
}
if (activeThread.status === Thread.STATUS_PAUSED) {
// The thread is paused so no need to do any logic <3
continue;
}
if (activeThread.status === Thread.STATUS_YIELD_TICK &&
!ranFirstTick) {
// Clear single-tick yield from the last call of `stepThreads`.
Expand Down
9 changes: 9 additions & 0 deletions src/engine/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ class Thread {
return 4; // used by compiler
}

/**
* Thread status for a single-tick yield. This will not be cleared when the
* thread is resumed.
* @const
*/
static get STATUS_PAUSED () {
return 5; // used by compiler
}

/**
* @param {Target} target The target running the thread.
* @param {string} topBlock ID of the thread's top block.
Expand Down

0 comments on commit 23d948d

Please sign in to comment.