Skip to content

Commit

Permalink
Make runThread throw an error
Browse files Browse the repository at this point in the history
  • Loading branch information
JothamWong committed Apr 9, 2024
1 parent ed0aa37 commit e1d38c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/vm/oogavm-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export class HeapDeadError extends OogaError {
}
}

export class RuntimeError extends OogaError {
constructor(msg: string) {
super(msg);
}
}

export class CompilerError extends OogaError {
constructor(msg: string) {
super(msg);
Expand Down
5 changes: 3 additions & 2 deletions src/vm/oogavm-scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RuntimeError } from './oogavm-errors.js';

export type ThreadId = number;

export interface Scheduler {
Expand Down Expand Up @@ -65,9 +67,8 @@ export class RoundRobinScheduler implements Scheduler {
}

runThread(): [ThreadId, number] | null {
// Arnav: When will this be 0? This will cause a crash because the callee assumes the tuple result
if (this._idleThreads.length === 0) {
return null;
throw new RuntimeError("Expected a thread but nothing.");
} else {
// The ! is a non-null assertion operator
const nextThread = this._idleThreads.shift()!;
Expand Down

0 comments on commit e1d38c4

Please sign in to comment.