From e5bf002e951b62d917b34f39ede5185b2a6202e4 Mon Sep 17 00:00:00 2001 From: Jesse Hines Date: Sat, 30 Nov 2024 20:24:50 -0500 Subject: [PATCH] Add isBreak method --- src/simulator/simulator.ts | 4 ++++ tests/simulator.test.ts | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/simulator/simulator.ts b/src/simulator/simulator.ts index 4d1f59f..f353785 100644 --- a/src/simulator/simulator.ts +++ b/src/simulator/simulator.ts @@ -190,6 +190,10 @@ export class Simulator { return !!this.control.ecall.toNumber() } + isBreak(): boolean { + return this.control.ecall.toNumber() == 2 + } + /** Runs the simulator until the end of the code. */ run() { while (!this.isDone()) this.tick() diff --git a/tests/simulator.test.ts b/tests/simulator.test.ts index 5d13011..c3344ad 100644 --- a/tests/simulator.test.ts +++ b/tests/simulator.test.ts @@ -401,6 +401,8 @@ describe("Syscalls", () => { ` let sim = testCode(code) expect(sim.control.ecall.toNumber()).to.equal(0) + expect(sim.isSyscall()).to.equal(false) + expect(sim.isBreak()).to.equal(false) }) it('ecall', () => { @@ -410,6 +412,8 @@ describe("Syscalls", () => { ` let sim = testCode(code) expect(sim.control.ecall.toNumber()).to.equal(1) + expect(sim.isSyscall()).to.equal(true) + expect(sim.isBreak()).to.equal(false) }) it('ebreak', () => { @@ -419,5 +423,7 @@ describe("Syscalls", () => { ` let sim = testCode(code) expect(sim.control.ecall.toNumber()).to.equal(2) + expect(sim.isSyscall()).to.equal(true) + expect(sim.isBreak()).to.equal(true) }) })