From f38a1311460fb41db762f638320d817fd17c349f Mon Sep 17 00:00:00 2001 From: cat Date: Tue, 10 Feb 2026 02:10:58 +0200 Subject: [PATCH] More Arithmetic, Better sectioning of code --- machine.hpp | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/machine.hpp b/machine.hpp index 3f50cbc..2bafbad 100644 --- a/machine.hpp +++ b/machine.hpp @@ -31,6 +31,9 @@ enum : int { // Two Arguments IncrementBy, DecrementBy, + MultiplyBy, + DivideBy, + ModulusBy, SetTo, Print, @@ -57,21 +60,29 @@ private: void Execute(int command) { switch (State) { case NoCommand: - break; - - case IncrementBy: - memory[currentPosition] += command; - State = NoCommand; + processCommand(command); return; - case DecrementBy: - memory[currentPosition] -= command; - State = NoCommand; - return; + // Arithmatic case SetTo: memory[currentPosition] = command; - State = NoCommand; - return; + break; + case IncrementBy: + memory[currentPosition] += command; + break; + case DecrementBy: + memory[currentPosition] -= command; + break; + case MultiplyBy: + memory[currentPosition] *= command; + break; + case DivideBy: + memory[currentPosition] /= command; + break; + case ModulusBy: + memory[currentPosition] %= command; + break; + case Print: handlePrint(command); State = NoCommand; @@ -82,7 +93,14 @@ private: return; } - // State: NoCommand + // This is only called after multi-argument functions are done + if (State != NoCommand) { + State = NoCommand; + return; + } + } + + void processCommand(int command) { switch (command) { case MoveLeft: // Underflow wrap @@ -106,8 +124,12 @@ private: // Double Argument Commands case Print: + case SetTo: case IncrementBy: case DecrementBy: + case MultiplyBy: + case DivideBy: + case ModulusBy: State = static_cast(command); return;