Skip to content

Commit

Permalink
Add isBreak method
Browse files Browse the repository at this point in the history
  • Loading branch information
jesse-r-s-hines committed Dec 1, 2024
1 parent b433ae5 commit e5bf002
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/simulator/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions tests/simulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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)
})
})

0 comments on commit e5bf002

Please sign in to comment.