From e1d38c4f361441007430a621d6df5a4c1896bf96 Mon Sep 17 00:00:00 2001 From: JothamWong <45916998+JothamWong@users.noreply.github.com> Date: Tue, 9 Apr 2024 15:54:18 +0800 Subject: [PATCH] Make runThread throw an error --- src/vm/oogavm-errors.ts | 6 ++++++ src/vm/oogavm-scheduler.ts | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/vm/oogavm-errors.ts b/src/vm/oogavm-errors.ts index 059d7aa..778f1af 100644 --- a/src/vm/oogavm-errors.ts +++ b/src/vm/oogavm-errors.ts @@ -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); diff --git a/src/vm/oogavm-scheduler.ts b/src/vm/oogavm-scheduler.ts index dd26491..87740e7 100644 --- a/src/vm/oogavm-scheduler.ts +++ b/src/vm/oogavm-scheduler.ts @@ -1,3 +1,5 @@ +import { RuntimeError } from './oogavm-errors.js'; + export type ThreadId = number; export interface Scheduler { @@ -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()!;