From 37bb92f2960ed464650cc9b92ee17daaa9ec7bd5 Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 29 Aug 2023 10:42:36 -0400 Subject: [PATCH] cpu - Change to throw errors, instead of logging with console.error() --- src/cpu.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cpu.js b/src/cpu.js index 54df653..c66fa69 100644 --- a/src/cpu.js +++ b/src/cpu.js @@ -54,8 +54,8 @@ module.exports = class CPU { this._cycleStartCallbacks.forEach((fn) => fn()); if (this.IP >= this.memory.length) { - console.error('HALTING - IP greater than memory size'); // FIXME - halting the CPU should throw an error instead this.running = false; + throw new Error('HALTING - IP greater than memory size'); } else { this.instruction.opcode = this.memory[this.IP]; this.instruction.operand = this.memory[this.IP+1]; @@ -68,8 +68,8 @@ module.exports = class CPU { // Temporary limit as a lazy way to halt infinite loops if ((this._cycleLimit > 0) && this.dbg.cycleCounter >= this._cycleLimit) { - console.warn(' HALTING - reached cycle limit'); // FIXME - throw error instead this.running = false; + throw new Error(' HALTING - reached cycle limit'); } this._cycleEndCallbacks.forEach((fn) => fn()); @@ -292,8 +292,8 @@ module.exports = class CPU { flag_toggle: (flagNum) => { if (flagNum === null) { - console.error('Invalid flag number'); - process.exit(); // FIXME -- throw error instead + let info = this.dbg.sourceInfo[this.IP]; + throw new Error(`Invalid flag number: '${flagNum}' on line ${info.lineNumber}: ${info.source}`); } const flagName = this.flagNums[flagNum]; this.dbg.currentMnemonic = `FTG ${flagName}`;